bootkit_scroll_painting_mbr_sprite_v1.asm
nikaroxanne_supersweet16bit-m4lw4r3/bootkits/bootkit_scroll_painting_mbr_sprite_v1.asm
bits 16
;.286			;masm specific
;.MODEL TINY		;masm specific

;******************************************************************************
;	COM Program that manipulates pixel values of command prompt 
;	by writing directly to VGA buffer
;	
;	To be used in DOSBOX (or similar) MS-DOS Emulator program 
;	Must be compiled with link16.exe (MASM32 preferably) 
;
;******************************************************************************

.CODE:
	org 100h

;******************************************************************************

SCREEN_MAX	equ	320*200
SCALED_SCREEN_MAX	equ	0x280
SCREEN_WIDTH	equ	0x140		;;320
SCALED_SCREEN_W	equ	0x20		;;320 / 10
MBRSPRITE_W		equ	0x100		;;320 / 10
SCREEN_HEIGHT	equ	0xC8		;;200
SCALED_SCREEN_H	equ	0x14		;;200 / 10 
VGA_PAL_INDEX	equ	0x3C8
VGA_PAL_DATA	equ	0x3C9
MBR_SIZE		equ 0x200
SCALE_MULTIPLIER equ 8
;******************************************************************************
;_start	PROC	NEAR ; masm

copy_mbr:
	mov ax, 0x201	;read one sector of disk
	mov	cx, 1
	mov dx, 0x80 	;from Side 0, drive C:
	lea bx, BUF		;to buffer BUF in DS
	int 13h


;******************************************************************************
;	Write back to hard disk drive C: sector 1 (MBR)
;******************************************************************************
	;mov ax,0x0301
	;mov bx,0x200
	;int 13h

vga_init:
	mov	ax,0xA000
	;mov	ax,0xB800
	mov	es,ax
	mov	dx,ax
	mov	di,0
	mov	ax, 0x13
	int	10h
	cld
	jmp paint_setup
;	jmp bmp_setup

;******************************************************************************
;	Palette routine adapted from "Symetrie" and "Atraktor" by Rrrola
;	 https://abaddon.hu/256b/colors.html 
;
;******************************************************************************
set_pal:
	salc				;set carry flag in al, if carry flag set, al=0
	mov	dx,VGA_PAL_INDEX	;
	out	dx, al
	inc	dx
	pal_1:
		or	ax,0011111100110011b
		push	ax
		shr	ax, 10
		out	dx,al
		mul	al
		shr	ax, 6
		out 	dx,al
		pop	ax
		out	dx,al
		inc	ax
		jnz	pal_1
	;jmp 	bmp_setup
paint_setup:
	;mov	cx, SCALED_SCREEN_W
	mov	cx, SCREEN_HEIGHT*SCALE_MULTIPLIER
	xor di, di
	paint_loop:
		push 	di
		push	cx
		mbr_paint:
			;lea si, BUF
			lea si, SkullBitmap
			push si
			mov bx, MBR_SIZE
			vga_mbr_y:
				push di
				mov dx, SCALED_SCREEN_W
				vga_mbr_x:
					mov ax, ds:[si]
					or al, es:[di]
					add al, 0x1
					mov es:[di], al 
					inc si
					inc di
					dec dx
					jnz vga_mbr_x
				pop di
				add di, 320*SCALE_MULTIPLIER
				dec bx
				jnz vga_mbr_y
			pop si
		pop		cx
		pop 	di
		add		di, MBRSPRITE_W
		dec 	cx
		jnz	paint_loop
	jmp key_check
	;jmp 	mbr_paint


;mbr_paint:
;	push es
;	push ds
;	lea si, BUF
;	mov bx, MBR_SIZE
;	vga_mbr_y:
;		push di
;		mov dx, SCALED_SCREEN_W
;		vga_mbr_x:
;			movsb
;			dec dx
;			jnz vga_mbr_x
;		pop di
;		add di, 320
;		dec bx
;		jnz vga_mbr_y
;	pop ds
;	pop es
;	mov ax, es:[di]
;	ret
	;jmp key_check
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;******************************************************************************
;Reads bitmap row,
;;copies new pixel values to VGA buffer 
;
;******************************************************************************


;bmp_setup:
;;	xor ax, ax
;;	mov	ds,ax
;	lea si, Bitmaptest
;	;mov bx, SCREEN_HEIGHT
;	mov bx, SCALED_SCREEN_MAX
;	;mov bx, SCREEN_HEIGHT*SCREEN_WIDTH
;;vga_y_block:
;;	push si
;	vga_main_y:
;		push di
;		;mov	cx, SCREEN_WIDTH
;		;mov dh, 0xA
;		mov	cx, SCALED_SCREEN_W
;		vga_main_x:
;			mov dx, 0xA
;			pixgroup:
;				push si
;				movsb
;				;jmp write_pix
;				pop si
;				dec dx
;				;cmp dl,0
;				jnz pixgroup
;;			inc si
;			dec cx
;			jnz vga_main_x
;		pop di
;		;mov ax, es:[di]
;		add di, 320
;		;mov [si], ax
;		dec bx
;		jnz	vga_main_y
;	jmp key_check
;	pop si
;	add si, 32
;	sub bx, 0xA
;	cmp bx, 0
;	jnz vga_y_block
;******************************************************************************
;
;	Reads char from buffer (function 0h,int16h)
; 	Char returned in al
; 	If char in al == 0x1b (ESC) then terminate program
;	Else, continue VGA *~pretty picture~* loop
;
;******************************************************************************
key_check:
	xor	ax,ax
	int	16h
	;;check if keypress is ESC
	;cmp	al, 1Bh
	cmp	al, 1
	jnz	baibai
	;jnz mbr_paint
;******************************************************************************
;
;	Terminates program (function 4Ch,int21h)
;
;******************************************************************************
;	mov	ax, 0x03		;reset VGA mode back to text-mode
;	int	10h
baibai:	
	mov	ax,4C00h		;terminate program
	int	21h


BUF:
	times 512-($-$$) db 0


SkullBitmap:
db 0x85,0x7e,0x7b,0x7b,0x79,0x76,0x73,0x71,0x6d,0x6a,0x69,0x66,0x64,0x63,0x61,0x5f,0x5d,0x5c,0x5b,0x5a,0x5a,0x59,0x57,0x56,0x55,0x55,0x54,0x54,0x55,0x55,0x54,0x55
db 0x57,0x5b,0x60,0x66,0x77,0x7f,0x75,0x71,0x6f,0x6e,0x6c,0x6b,0x6b,0x6c,0x6f,0x73,0x76,0x78,0x7a,0x7d,0x7f,0x82,0x85,0x86,0x89,0x8d,0x8f,0x92,0x94,0x97,0x98,0x9a
db 0x77,0x72,0x70,0x70,0x6d,0x6a,0x67,0x64,0x62,0x5f,0x5d,0x5b,0x59,0x57,0x56,0x54,0x52,0x51,0x50,0x4f,0x4e,0x4d,0x4c,0x4b,0x4b,0x4b,0x4b,0x4b,0x4c,0x4e,0x52,0x5d
db 0x5e,0x58,0x55,0x54,0x57,0x56,0x53,0x52,0x52,0x54,0x57,0x5b,0x5f,0x65,0x6a,0x6a,0x6a,0x6d,0x6f,0x71,0x75,0x7a,0x7c,0x7e,0x81,0x85,0x88,0x8a,0x8c,0x8e,0x8f,0x8f
db 0x6a,0x65,0x63,0x64,0x61,0x5e,0x5c,0x5a,0x57,0x54,0x53,0x52,0x50,0x4e,0x4c,0x4a,0x48,0x46,0x45,0x44,0x43,0x42,0x41,0x40,0x41,0x44,0x47,0x48,0x46,0x46,0x46,0x45
db 0x42,0x40,0x41,0x44,0x49,0x4e,0x4f,0x58,0x5b,0x56,0x58,0x58,0x58,0x59,0x5b,0x5c,0x5c,0x5d,0x5f,0x61,0x64,0x66,0x68,0x6b,0x6e,0x71,0x75,0x7b,0x7f,0x83,0x86,0x8c
db 0x5e,0x5b,0x59,0x5a,0x57,0x54,0x52,0x50,0x4d,0x4b,0x4a,0x4a,0x47,0x44,0x42,0x40,0x3d,0x3c,0x3a,0x3a,0x39,0x39,0x3a,0x3d,0x3f,0x3d,0x39,0x36,0x36,0x37,0x3c,0x40
db 0x4a,0x57,0x64,0x65,0x5d,0x4f,0x43,0x48,0x49,0x42,0x43,0x44,0x45,0x47,0x48,0x4a,0x4c,0x4e,0x50,0x53,0x56,0x58,0x5b,0x5d,0x60,0x64,0x67,0x6b,0x6e,0x71,0x75,0x7b
db 0x54,0x51,0x4f,0x50,0x4d,0x49,0x46,0x44,0x42,0x40,0x3f,0x3d,0x3a,0x38,0x36,0x35,0x33,0x32,0x32,0x32,0x36,0x37,0x36,0x32,0x2e,0x2e,0x34,0x40,0x4b,0x5c,0x6c,0x74
db 0x77,0x67,0x57,0x3c,0x33,0x36,0x3f,0x46,0x3a,0x39,0x3b,0x3c,0x3d,0x3f,0x41,0x40,0x42,0x44,0x46,0x49,0x4b,0x4e,0x4f,0x52,0x55,0x58,0x5b,0x5e,0x62,0x65,0x6a,0x6f
db 0x4a,0x47,0x46,0x48,0x43,0x40,0x3d,0x3b,0x39,0x37,0x36,0x34,0x31,0x2e,0x2d,0x2d,0x2b,0x2b,0x30,0x38,0x2f,0x29,0x27,0x27,0x37,0x62,0x7e,0x80,0x72,0x62,0x5a,0x50
db 0x38,0x2c,0x2b,0x2a,0x2a,0x39,0x37,0x36,0x2e,0x2d,0x2e,0x30,0x31,0x33,0x35,0x35,0x38,0x39,0x3d,0x44,0x42,0x43,0x47,0x49,0x4a,0x4e,0x52,0x54,0x57,0x5a,0x5f,0x65
db 0x41,0x3e,0x3d,0x3f,0x3a,0x37,0x35,0x33,0x30,0x2e,0x2e,0x2b,0x28,0x27,0x26,0x26,0x28,0x2f,0x34,0x2c,0x22,0x26,0x3c,0x5b,0x79,0x75,0x72,0x65,0x49,0x3a,0x35,0x34
db 0x2b,0x29,0x29,0x2d,0x37,0x4e,0x3c,0x31,0x25,0x25,0x26,0x27,0x29,0x2a,0x2c,0x2d,0x2f,0x31,0x36,0x4d,0x3e,0x39,0x3c,0x3e,0x41,0x45,0x48,0x4a,0x4c,0x4f,0x56,0x5a
db 0x37,0x34,0x34,0x36,0x31,0x2e,0x2c,0x29,0x27,0x27,0x27,0x26,0x23,0x22,0x21,0x29,0x2f,0x24,0x1f,0x2b,0x4c,0x6f,0x72,0x62,0x55,0x4b,0x40,0x33,0x29,0x27,0x27,0x27
db 0x27,0x27,0x29,0x2b,0x29,0x38,0x28,0x22,0x20,0x21,0x21,0x22,0x23,0x24,0x25,0x27,0x39,0x49,0x40,0x47,0x30,0x32,0x35,0x35,0x38,0x3c,0x3e,0x42,0x44,0x49,0x50,0x53
db 0x2f,0x2c,0x2d,0x2d,0x28,0x27,0x24,0x22,0x21,0x21,0x21,0x1f,0x1d,0x1d,0x2a,0x2c,0x1b,0x20,0x4b,0x6a,0x4e,0x31,0x22,0x22,0x20,0x19,0x16,0x14,0x15,0x15,0x15,0x17
db 0x18,0x19,0x18,0x17,0x19,0x26,0x19,0x1a,0x1c,0x1d,0x1e,0x1f,0x1f,0x1f,0x25,0x39,0x4a,0x32,0x25,0x26,0x28,0x2a,0x2e,0x2e,0x31,0x34,0x37,0x3a,0x3d,0x42,0x48,0x4d
db 0x27,0x25,0x26,0x26,0x22,0x20,0x1e,0x1d,0x1b,0x1b,0x1b,0x1a,0x18,0x2b,0x30,0x19,0x23,0x81,0x6e,0x2e,0x1d,0x16,0x13,0x14,0x13,0x12,0x11,0x12,0x12,0x12,0x12,0x14
db 0x13,0x12,0x13,0x13,0x13,0x20,0x16,0x15,0x15,0x17,0x1a,0x27,0x3b,0x40,0x43,0x40,0x21,0x1d,0x1e,0x1f,0x22,0x24,0x26,0x28,0x2a,0x2c,0x2f,0x33,0x36,0x3a,0x3f,0x45

