.DATA
VBEINFOBLOCK	STRUCT	
VBESIGNATURE	DB	'VESA' ; vbe signature
VBEVERSION	DW	0200H ; vbe version
OEMSTRINGPTR	DD	? ; pointer to oem string
CAPABILITIES	DB	4 DUP (?) ; capabilities of graphics controller
VIDEOMODEPTR	DD	? ; pointer to videomodelist
TOTALMEMORY	DW	? ; number of 64kb memory blocks
; added for vbe 2.0
OEMSOFTWAREREV	DW	? ; vbe implementation software revision
OEMVENDORNAMEPTR	DD	? ; pointer to vendor name string
OEMPRODUCTNAMEPTR	DD	? ; pointer to product name string
OEMPRODUCTREVPTR	DD	? ; pointer to product revision string
VBEINFORESERVED	DB	222 DUP (?); reserved for vbe implementation scratch
;   area
OEMDATA	DB	256 DUP (?); data area for oem strings
VBEINFOBLOCK	ENDS	
			
MODEINFOBLOCK	STRUCT	
; mandatory information for all vbe revisions modeattributes	dw	?	; mode attributes
WINAATTRIBUTES	DB	? ; window a attributes
WINBATTRIBUTES	DB	? ; window b attributes
WINGRANULARITY	DW	? ; window granularity
WINSIZE	DW	? ; window size
WINASEGMENT	DW	? ; window a start segment
WINBSEGMENT	DW	? ; window b start segment
WINFUNCPTR	DD	? ; pointer to window function
BYTESPERSCANLINE	DW	? ; bytes per scan line
; mandatory information for vbe 1.2 and above
XRESOLUTION	DW	? ; horizontal resolution in pixels or characters3
YRESOLUTION	DW	? ; vertical resolution in pixels or characters
XCHARSIZE	DB	? ; character cell width in pixels
YCHARSIZE	DB	? ; character cell height in pixels
NUMBEROFPLANES	DB	? ; number of memory planes
			
;3pixels in graphics modes, characters in text modes.
BITSPERPIXEL	DB	? ; bits per pixel
NUMBEROFBANKS	DB	? ; number of banks
MEMORYMODEL	DB	? ; memory model type
BANKSIZE	DB	? ; bank size in kb
NUMBEROFIMAGEPAGES	DB	? ; number of images
RESERVED	DB	1 ; reserved for page function
; direct color fields (required for direct/6 and yuv/7 memory models)
REDMASKSIZE	DB	? ; size of direct color red mask in bits
REDFIELDPOSITION	DB	? ; bit position of lsb of red mask
GREENMASKSIZE	DB	? ; size of direct color green mask in bits
GREENFIELDPOSITION	DB	? ; bit position of lsb of green mask
BLUEMASKSIZE	DB	? ; size of direct color blue mask in bits
BLUEFIELDPOSITION	DB	? ; bit position of lsb of blue mask
RSVDMASKSIZE	DB	? ; size of direct color reserved mask in bits
RSVDFIELDPOSITION	DB	? ; bit position of lsb of reserved mask
DIRECTCOLORMODEINFO	DB	? ; direct color mode attributes
; mandatory information for vbe 2.0 and above 
physbaseptr	dd	?	; physical address for flat memory frame buffer
OFFSCREENMEMOFFSET	DD	? ; pointer to start of off screen memory
OFFSCREENMEMSIZE	DW	? ; amount of off screen memory in 1k units
MODEINFORESERVED	DB	206 DUP (?)  ; remainder of modeinfoblock
MODEINFOBLOCK	ENDS	
			
SUPVBEINFOBLOCK	STRUCT	
SUPVBESIGNATURE	DB	'VBE/???' ; supplemental vbe signature
SUPVBEVERSION	DW	? ; supplemental vbe version
SUPVBESUBFUNC	DB	8 DUP (?) ; bitfield of supported subfunctions
OEMSOFTWAREREV	DW	? ; oem software revision
OEMVENDORNAMEPTR	DD	? ; pointer to vendor name string
OEMPRODUCTNAMEPTR	DD	? ; pointer to product name string
OEMPRODUCTREVPTR	DD	? ; pointer to product revision string
OEMSTRINGPTR	DD	? ; pointer to oem string
SUPVBEINFORESERVED	DB	221 DUP (?); reserved for description strings and future
; expansion
SUPVBEINFOBLOCK	ENDS	
			
;text
;108h	-	80	60
;109h	-	132	25
;10ah	-	132	43
;10bh	-	132	50
;10ch	-	132	60
;
;graphics
;100h	-	640x400 256
;101h	-	640x480 256
;102h	6ah	800x600	16
;103h	-	800x600 256
;104h	-	1024x768 16
;105h	-	1024x768 256
;106h	-	1280x1024 16
;107h	-	1280x1024 256
;10dh	-	320x200	32k (1:5:5:5:)
;10eh	-	320x200	64k (5:6:5)
;10fh	-	320x200	16.8m (8:8:8)
;110h	-	640x480	32k (1:5:5:5:)
;111h	-	640x480	64k (5:6:5)
;112h	-	640x480	16.8m (8:8:8)
;113h	-	800x600	32k (1:5:5:5:)
;114h	-	800x600	64k (5:6:5)
;115h	-	800x600	16.8m (8:8:8)
;116h	-	1024x768	32k (1:5:5:5:)
;117h	-	1024x768	64k (5:6:5)
;118h	-	1024x768	16.8m (8:8:8)
;119h	-	1280x1024	32k (1:5:5:5:)
;11ah	-	1280x1024	64k (5:6:5)
;11bh	-	1280x1024	16.8m (8:8:8)
			
			
SCREENBITSPERPIXEL	DW	0
BANKCOUNT	DW	48
BANKLINECOUNT	DD	16
LINESIZE	DD	4096
BMPW	DD	0
BMPW2	DD	0
BMPW3	DD	0
BMPH	DD	0
BMPSTARTPOS	DD	0
BMPSIZE	DD	0
BMPHEADERSIZE	DW	0
BMPBITSPERPIXEL	DW	0
MODEINFO	MODEINFOBLOCK	{}
STARTBANK	DD	0
			
.CODE
; bx = mode
GVESA	PROC	
	PUSH	EAX	
	PUSH	EBX	
	PUSH	ECX	
	PUSH	EDX	
	MOV	AX,0A000H	
	MOV	ES,AX	
	MOV	AX,4F02H	
;	mov 	bx, 118h		; 16m color 1024*768
	INT	10H	
	CMP	BX,112H	
	JE	SET640X480	
	CMP	BX,115H	
	JE	SET800X600	
	MOV	BANKCOUNT,48	
	MOV	BANKLINECOUNT,16	
	MOV	LINESIZE,4096	
	MOV	SCREENBITSPERPIXEL,4	
	JMP	SETVESAOK	
SET640X480:
	MOV	BANKCOUNT,48	
	MOV	BANKLINECOUNT,26	
	MOV	LINESIZE,2560	
	MOV	SCREENBITSPERPIXEL,4	
	JMP	SETVESAOK	
SET800X600:
	MOV	BANKCOUNT,48	
	MOV	BANKLINECOUNT,21	
	MOV	LINESIZE,3200	
	MOV	SCREENBITSPERPIXEL,4	
SETVESAOK:
	POP	EDX	
	POP	ECX	
	POP	EBX	
	POP	EAX	
	RET		
GVESA	ENDP	
; //////////////////////////////////////////////////////////////////////////////////////
; ///////////////////  load binary file //////////////////////////////////////
; ///////////////////////////////////////////////////////////////////////////////////////
; ds:esi = offset parent form
; ds:edi = offset memo
; ds:ebx = offset dirname of full path
; output dx= 0 if filesize larger than 64k
LOADBINARYFILE	PROC	
	PUSH	EAX	
	PUSH	EBX	
	PUSH	ECX	
	PUSH	ESI	
	PUSH	EDI	
	PUSH	EBP	
;	mov	ebx,offset	filename1	; esi
; //////////////////////////////////////////////////////////////////////////////////////////
; create a temporary segment
; //////////////////////////////////////////////////////////////////////////////////////////
	PUSH	EBX	
	MOV	EAX,8000H	
	MOV	EBX,2	
	MOV	ECX,1	
	CALL	GETMEM	
	MOV	MPLDATASEGMENT,EAX	
	MOV	FS,AX	
	POP	EBX	
	PUSH	EDI	
	PUSH	ESI	
	MOV	ESI,EBX	
	CALL	GETDIRPARAMS	
	POP	ESI	
	XOR	EBX,EBX	
	MOV	BX,FS	
	MOV	EAX,CURRENTDIRSECTOR	
	MOV	ECX,0	
	MOV	CX,SECTORPERCLUSTER	
	MOV	EDI,0	
	CALL	READSECTOR	
	POP	EDI	
	MOV	EBX,DIRINDEX	
	MOV	ECX,FS:[BX+28]	; filesize
	CMP	ECX,65535	
	JBE	BMPLOADSKIPBIGFILE	
	MOV	ESI,OFFSET BIGFILEMSG
	CALL	SHOWMESSAGE	
	MOV	ECX,MPLDATASEGMENT	
	CALL	FREEMEM	
	MOV	DX,0	
	JMP	EXITBMPLOADFROMFILE	
BMPLOADSKIPBIGFILE:
	MOV	EAX,ECX	
; //////////////////////////////////////////////////////////////////////////////////////////
	MOV	AX,FS:[BX+20]	; hicluster
	SHL	EAX,16	
	MOV	AX,FS:[BX+26]	; low cluster
; load file from disk into the buffer
	MOV	EBX,EAX	; start cluster
	XOR	EAX,EAX	
	MOV	EAX,FS	; segment to load file
	CALL	LOADFILE	
EXITBMPLOADFROMFILE:
	POP	EBP	
	POP	EDI	
	POP	ESI	
	POP	ECX	
	POP	EBX	
	POP	EAX	
	RET		
LOADBINARYFILE	ENDP	
			
; fs:[si] : start of bitmap file
GETBITMAPPARAMS	PROC	
; get bitmap parameters from header
	PUSHAD		
	MOV	AX,FS:[14]	
	MOV	BMPHEADERSIZE,AX	
	MOV	AX,FS:[28]	
	MOV	BMPBITSPERPIXEL,AX	
			
	MOV	EAX,FS:[18]	
	MOV	BMPW,EAX	
	XOR	ECX,ECX	
	XOR	EDX,EDX	
	MOV	CX,BMPBITSPERPIXEL	
	CMP	CX,8
	JAE	SET24OR8BITBMP
	CMP	CX,4
	JE	SET4BITBMP
	MOV	CX,8
	JMP	SET1BITBMP
; here deal with 4 or 1 bit bitmap
SET4BITBMP:
	MOV	CX,2
SET1BITBMP:
	XOR	EDX,EDX	
	DIV	ECX	
	MOV	EBX,EAX
	CMP	EDX,0
	JE	SKIPSET1BITBMP1
	INC	EAX
SKIPSET1BITBMP1:
	MOV	BMPW3,EAX
	MOV	ECX,4
	XOR	EDX,EDX	
	DIV	ECX	
	CMP	EDX,0
	JE	SKIPSET1BITBMP2
	INC	EAX
SKIPSET1BITBMP2:
	SHL	EAX,2
	MOV	BMPW2,EAX
	JMP	EXITGETBITMAPPARAMS	
; here deal with 24 or 8 bit bitmap
SET24OR8BITBMP:
	SHR	ECX,3	
	MUL	ECX	
	MOV	ECX,4	
	XOR	EDX,EDX	
	DIV	ECX	
	CMP	EDX,0
	JE	GETBITSKIPBMPW2
	INC	EAX
	SHL	EAX,2
GETBITSKIPBMPW2:
	MOV	BMPW2,EAX	

EXITGETBITMAPPARAMS:
	MOV	EAX,FS:[22]	
	MOV	BMPH,EAX	
	MOV	EAX,FS:[2]	
	MOV	BMPSIZE,EAX	
	POPAD		
	RET		

GETBITMAPPARAMS	ENDP	


; input
; eax = bmpx
; ebx = bmpy
; output
; edi = screen position

SETBITMAPPOS	PROC
	XCHG	EAX,EBX
	MOV	EAX,EAX	; bmpy
	PUSH	EBX
	PUSH	EAX	; save y pos
	XOR	EDX,EDX
	MOV	ECX,BANKLINECOUNT
	DIV	ECX
	MOV	EBX,EDX	; remaining lines
	MOV	STARTBANK,EAX
	MOV	EDX,EAX	; start bank
	CALL	SETBANK
	POP	EAX	; get y
	POP	EBX
; calculate offset in start bank using x,y
	PUSH	EDX	; save start bank
;	mov	eax,bmpy
	DEC	EAX
	XOR	EDX,EDX
	MOV	ECX,LINESIZE
	MUL	ECX
	ADD	EAX,EBX	; bmpx
	ADD	EAX,EBX	; bmpx
	ADD	EAX,EBX	; bmpx
	ADD	EAX,EBX	; bmpx
	XOR	EDX,EDX
	MOV	ECX,65536
	DIV	ECX
	MOV	EAX,EDX
	MOV	BMPSTARTPOS,EAX
	MOV	EDI,EAX	; bmp pos in the current bank
	POP	EDX
	RET
SETBITMAPPOS	ENDP


; fs:[si] = bitmap file 
; eax = x pos
; ebx = y pos
DRAWBITMAP		PROC
	PUSHAD
; get bitmap parameters from header	
	CALL	GETBITMAPPARAMS
	MOV	EAX,BMPX
	MOV	EBX,BMPY
	CALL	SETBITMAPPOS

	MOV	AX,BMPBITSPERPIXEL
	CMP	AX,24
	JE	DRAWBITMAP24
	CMP	AX,8
	JE	DRAWBITMAP8
	CMP	AX,4
	JE	DRAWBITMAP4
	CMP	AX,1
	JE	DRAWBITMAP1
	JMP	EXITDRAWBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  24 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
DRAWBITMAP24:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start to draw from bottom to up 
	SUB	EBX,BMPW2		; width+residue
DRAWBITMAP24LOOP4:
	MOV	ECX,BMPW		; width
DRAWBITMAP24LOOP3:
	XOR	EAX,EAX
	MOV	EAX,FS:[BX]
	MOV	ES:[DI],EAX
	ADD	EDI,4

	CMP	EDI,65536
	JB	DRAWBITMAP24NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP24NOINC:
	ADD	EBX,3
	DEC	ECX
	CMP	ECX,0
	JNE	DRAWBITMAP24LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	DRAWBITMAP24NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP24NOINC2:
;	br
	SUB	EBX,BMPW		; width
	SUB	EBX,BMPW		; width
	SUB	EBX,BMPW		; back to the start of current row
	SUB	EBX,BMPW2		; start of previous row 

	DEC	EBP
	CMP	EBP,0
	JNE	DRAWBITMAP24LOOP4
	JMP	EXITDRAWBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  8 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
DRAWBITMAP8:

	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
DRAWBITMAP8LOOP4:
	MOV	ECX,BMPW		; width
DRAWBITMAP8LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	EAX,2
	MOV	ESI,EAX
	MOV	EAX,FS:[54+ESI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	DRAWBITMAP8NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP8NOINC:
	INC	EBX
	DEC	ECX
	CMP	ECX,0
	JNE	DRAWBITMAP8LOOP3
;	br

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	DRAWBITMAP8NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP8NOINC2:
;	br
	SUB	EBX,BMPW		; back to the start of current row
	SUB	EBX,BMPW2		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	DRAWBITMAP8LOOP4
	JMP	EXITDRAWBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  4 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////

DRAWBITMAP4:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
DRAWBITMAP4LOOP4:
	MOV	ECX,BMPW		; width
DRAWBITMAP4LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	AL,4
	SHR	AL,4
	SHL	EAX,2
	MOV	ESI,EAX
	MOV	EAX,FS:[54+ESI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	DRAWBITMAP4NOINC1
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP4NOINC1:
	DEC	ECX
	INC	EBX
	CMP	ECX,0
	JE	DRAWBITMAP4NEXTROW	

	DEC	EBX
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHR	AL,4
	SHL	EAX,2
	MOV	ESI,EAX
	MOV	EAX,FS:[54+ESI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	DRAWBITMAP4NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP4NOINC2:
	INC	EBX
	DEC	ECX
	CMP	ECX,0
	JNE	DRAWBITMAP4LOOP3
DRAWBITMAP4NEXTROW:

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	DRAWBITMAP4NOINC3
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP4NOINC3:
;	br
	SUB	EBX,BMPW3		; back to the start of current row
	SUB	EBX,BMPW2		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	DRAWBITMAP4LOOP4

	JMP	EXITDRAWBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  1 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
DRAWBITMAP1:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
DRAWBITMAP1LOOP4:
	MOV	ECX,BMPW		; width
	MOV	SI,0
DRAWBITMAP1LOOP3:
DRAWBITMAP1CONTDRAW:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]

	PUSH	CX
	MOV	CX,SI
	SHL	AL,CL
	SHR	AL,7
	POP	CX

	SHL	EAX,2
	ADD	EAX,54

	PUSH	ESI
	MOV	ESI,EAX
	MOV	EAX,FS:[ESI]	
	POP	ESI

	MOV	ES:[DI],AL
	INC	EDI
	MOV	ES:[DI],AH
	INC	EDI
	SHR	EAX,16
	MOV	ES:[DI],AL
	INC	EDI
	INC	EDI
	CMP	EDI,65536
	JB	DRAWBITMAP1NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP1NOINC:
	DEC	ECX
	INC	EBX
	CMP	ECX,0
	JE	DRAWBITMAP1NEXTROW	
	DEC	EBX
	INC	SI
	CMP	SI,8
	JNE	DRAWBITMAP1CONTDRAW
	MOV	SI,0
	INC	EBX
	CMP	ECX,0
	JNE	DRAWBITMAP1LOOP3
DRAWBITMAP1NEXTROW:
	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	DRAWBITMAP1NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
DRAWBITMAP1NOINC2:
;	br
	SUB	EBX,BMPW3		; back to the start of current row
	SUB	EBX,BMPW2		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	DRAWBITMAP1LOOP4
; //////////////////////////////////////////////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
EXITDRAWBITMAP:
	POPAD
	RET
DRAWBITMAP	ENDP
	

; fs:[si] = bitmap file 
; eax = x pos
; ebx = y pos
INVERTCOLORS	PROC
	PUSHAD
; get bitmap parameters from header	
	CALL	GETBITMAPPARAMS
;	mov	eax,bmpx
;	mov	ebx,bmpy
	CALL	SETBITMAPPOS

	MOV	AX,BMPBITSPERPIXEL
	CMP	AX,24
	JE	INVERTBITMAP24
	CMP	AX,8
	JE	INVERTBITMAP8
	CMP	AX,4
	JE	INVERTBITMAP4
	CMP	AX,1
	JE	INVERTBITMAP1
	JMP	EXITINVERTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  24 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
INVERTBITMAP24:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
INVERTCOLORSLOOP4:
	MOV	ECX,BMPW		; width
INVERTCOLORSLOOP3:
	MOV	EAX,FS:[BX]
	SHL	EAX,8
	SHR	EAX,8

	PUSH	ECX
	MOV	ECX,0FFFFFFH
	SUB	ECX,EAX
	MOV	EAX,ECX
	POP	ECX
	MOV	ES:[DI],EAX

	ADD	EDI,4
	CMP	EDI,65536
	JB	INVERTCOLORSNOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERTCOLORSNOINC:
	ADD	EBX,3
	DEC	ECX
	CMP	ECX,0
	JNE	INVERTCOLORSLOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	INVERTCOLORSNOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERTCOLORSNOINC2:
;	br
	SUB	EBX,BMPW		; width
	SUB	EBX,BMPW		; width
	SUB	EBX,BMPW		; back to the start of current row
	SUB	EBX,BMPW2		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	INVERTCOLORSLOOP4
	JMP	EXITINVERTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  8 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////

INVERTBITMAP8:

	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
INVERT8LOOP4:
	MOV	ECX,BMPW		; width
INVERT8LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	EAX,2
	MOV	ESI,EAX
	MOV	EAX,FS:[54+ESI]	
	SHL	EAX,8
	SHR	EAX,8
	PUSH	ECX
	MOV	ECX,0FFFFFFH
	SUB	ECX,EAX
	MOV	EAX,ECX
	POP	ECX
	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	INVERT8NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERT8NOINC:
	INC	EBX
	DEC	ECX
	CMP	ECX,0
	JNE	INVERT8LOOP3
;	br

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	INVERT8NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERT8NOINC2:
;	br
	SUB	EBX,BMPW		; back to the start of current row
	SUB	EBX,BMPW2		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	INVERT8LOOP4

	JMP	EXITINVERTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  4 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////

INVERTBITMAP4:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; //////////////////////////////////////////////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
INVERT4LOOP4:
	MOV	ECX,BMPW		; width
INVERT4LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	AL,4
	SHR	AL,4
	SHL	EAX,2
	MOV	ESI,EAX
	MOV	EAX,FS:[54+ESI]	

	SHL	EAX,8
	SHR	EAX,8
	PUSH	ECX
	MOV	ECX,0FFFFFFH
	SUB	ECX,EAX
	MOV	EAX,ECX
	POP	ECX

	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	INVERT4NOINC1
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERT4NOINC1:
	DEC	ECX
	INC	EBX
	CMP	ECX,0
	JE	INVERT4NEXTROW	

	DEC	EBX
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHR	AL,4
	SHL	EAX,2
	MOV	ESI,EAX
	MOV	EAX,FS:[54+ESI]	

	SHL	EAX,8
	SHR	EAX,8
	PUSH	ECX
	MOV	ECX,0FFFFFFH
	SUB	ECX,EAX
	MOV	EAX,ECX
	POP	ECX

	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	INVERT4NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERT4NOINC2:
	INC	EBX
	DEC	ECX
	CMP	ECX,0
	JNE	INVERT4LOOP3
INVERT4NEXTROW:

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	INVERT4NOINC3
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERT4NOINC3:
;	br
	SUB	EBX,BMPW3		; back to the start of current row
	SUB	EBX,BMPW2		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	INVERT4LOOP4

	JMP	EXITINVERTBITMAP

; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  1 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////

INVERTBITMAP1:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
INVERT1LOOP4:
	MOV	ECX,BMPW		; width
	MOV	SI,0
INVERT1LOOP3:
INVERT1CONTDRAW:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]

	PUSH	CX
	MOV	CX,SI
	SHL	AL,CL
	SHR	AL,7
	POP	CX

	SHL	EAX,2
	ADD	EAX,54

	PUSH	ESI
	MOV	ESI,EAX
	MOV	EAX,FS:[ESI]	
	POP	ESI

	SHL	EAX,8
	SHR	EAX,8
	PUSH	ECX
	MOV	ECX,0FFFFFFH
	SUB	ECX,EAX
	MOV	EAX,ECX
	POP	ECX

	MOV	ES:[DI],EAX
	ADD	EDI,4

	CMP	EDI,65536
	JB	INVERT1NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERT1NOINC:
	DEC	ECX
	INC	EBX
	CMP	ECX,0
	JE	INVERT1NEXTROW	
	DEC	EBX
	INC	SI
	CMP	SI,8
	JNE	INVERT1CONTDRAW
	MOV	SI,0
	INC	EBX
	CMP	ECX,0
	JNE	INVERT1LOOP3
INVERT1NEXTROW:
	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	INVERT1NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
INVERT1NOINC2:
;	br
	SUB	EBX,BMPW3		; back to the start of current row
	SUB	EBX,BMPW2		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	INVERT1LOOP4

EXITINVERTBITMAP:
	POPAD
	RET
INVERTCOLORS	ENDP



; fs:[si] = bitmap file 
; eax = x pos
; ebx = y pos
MIRRORBITMAP	PROC
	PUSHAD
; get bitmap parameters from header	
	CALL	GETBITMAPPARAMS
;	mov	eax,bmpx
;	mov	ebx,bmpy
	CALL	SETBITMAPPOS

	MOV	AX,BMPBITSPERPIXEL
	CMP	AX,24
	JE	MIRRORBITMAP24
	CMP	AX,8
	JE	MIRRORBITMAP8
	CMP	AX,4
	JE	MIRRORBITMAP4
	CMP	AX,1
	JE	MIRRORBITMAP1
	JMP	EXITMIRRORBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  24 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////

MIRRORBITMAP24:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
	ADD	EBX,BMPW
	ADD	EBX,BMPW
	ADD	EBX,BMPW
	SUB	EBX,3
MIRROR24LOOP4:
	MOV	ECX,BMPW		; width
MIRROR24LOOP3:
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	ADD	EDI,2
	INC	EBX
	CMP	EDI,65536
	JB	MIRROR24NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR24NOINC:
	SUB	EBX,6
	DEC	ECX
	CMP	ECX,0
	JNE	MIRROR24LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	MIRROR24NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR24NOINC2:
	SUB	EBX,BMPW2		; start of previous row 
	ADD	EBX,BMPW
	ADD	EBX,BMPW
	ADD	EBX,BMPW

	DEC	EBP
	CMP	EBP,0
	JNE	MIRROR24LOOP4
	JMP	EXITMIRRORBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  8 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////

MIRRORBITMAP8:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
	ADD	EBX,BMPW
MIRROR8LOOP4:
	MOV	ECX,BMPW		; width
MIRROR8LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4

	CMP	EDI,65536
	JB	MIRROR8NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR8NOINC:
	DEC	EBX
	DEC	ECX
	CMP	ECX,0
	JNE	MIRROR8LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	MIRROR8NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR8NOINC2:
	SUB	EBX,BMPW2		; start of previous row 
	ADD	EBX,BMPW
	DEC	EBP
	CMP	EBP,0
	JNE	MIRROR8LOOP4

	JMP	EXITMIRRORBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  4 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////

MIRRORBITMAP4:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
	ADD	EBX,BMPW3
	DEC	EBX
MIRROR4LOOP4:
	MOV	ECX,BMPW
MIRROR4LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	AL,4
	SHR	AL,4
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	MIRROR4NOINC1
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR4NOINC1:
	DEC	ECX
	DEC	EBX
	CMP	ECX,0
	JE	MIRROR4NEXTROW	
	INC	EBX
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHR	AL,4
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	DEC	EBX
	CMP	EDI,65536
	JB	MIRROR4NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR4NOINC2:
	DEC	ECX
	CMP	ECX,0
	JNE	MIRROR4LOOP3
MIRROR4NEXTROW:
	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	MIRROR4NOINC3
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR4NOINC3:
;	br
	SUB	EBX,BMPW2		; back to the start of current row
	ADD	EBX,BMPW3		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	MIRROR4LOOP4

	JMP	EXITMIRRORBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  1 bit bitmaps ///////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
MIRRORBITMAP1:
	MOV	EBP,BMPH		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2		; width+residue
	ADD	EBX,BMPW3
	DEC	EBX
MIRROR1LOOP4:
	MOV	ECX,BMPW
	MOV	SI,8
MIRROR1LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]

	PUSH	CX
	MOV	CX,SI
	DEC	CX
	SHL	AL,CL
	SHR	AL,7
	POP	CX

	SHL	EAX,2
	ADD	EAX,54
	PUSH	ESI
	MOV	ESI,EAX
	MOV	EAX,FS:[ESI]	
	POP	ESI

	MOV	ES:[DI],AL
	INC	EDI
	MOV	ES:[DI],AH
	INC	EDI
	SHR	EAX,16
	MOV	ES:[DI],AL
	INC	EDI
	INC	EDI
	CMP	EDI,65536
	JB	MIRROR1NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR1NOINC:
	DEC	ECX
	DEC	EBX
	CMP	ECX,0
	JE	MIRROR1NEXTROW	
	INC	EBX
	DEC	SI
	CMP	SI,0
	JNE	MIRROR1LOOP3
	MOV	SI,8
	DEC	EBX
	CMP	ECX,0
	JNE	MIRROR1LOOP3
MIRROR1NEXTROW:
	BR
	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	MIRROR1NOINC3
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
MIRROR1NOINC3:
;	br
	SUB	EBX,BMPW2		; back to the start of current row
	ADD	EBX,BMPW3		; start of previous row 
	DEC	EBP
	CMP	EBP,0
	JNE	MIRROR1LOOP4

EXITMIRRORBITMAP:
	POPAD
	RET
MIRRORBITMAP	ENDP


; fs:[si] = bitmap file 
; eax = x pos
; ebx = y pos
ROTATEBITMAPLEFT	PROC
	PUSHAD
; get bitmap parameters from header	
	CALL	GETBITMAPPARAMS
;	mov	eax,bmpx
;	mov	ebx,bmpy
	CALL	SETBITMAPPOS

	MOV	AX,BMPBITSPERPIXEL
	CMP	AX,24
	JE	ROTATELEFTBITMAP24
	CMP	AX,8
	JE	ROTATELEFTBITMAP8
	CMP	AX,4
	JE	ROTATELEFTBITMAP4
	CMP	AX,1
	JE	ROTATELEFTBITMAP1
	JMP	EXITROTATELEFTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  24 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
ROTATELEFTBITMAP24:
	MOV	EBP,BMPW		; height
	MOV	EBX,BMPSIZE	
	SUB	EBX,BMPW2
	ADD	EBX,BMPW
	ADD	EBX,BMPW
	ADD	EBX,BMPW
ROTATE24LOOP4:
	PUSH	EBX
	MOV	ECX,BMPH		; width
ROTATE24LOOP3:
	PUSH	EBX
	SUB	EBX,3
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EDI
	INC	EBX
	POP	EBX
	SUB	EBX,BMPW2

	CMP	EDI,65536
	JB	ROTATE24NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
ROTATE24NOINC:
	DEC	ECX
	CMP	ECX,0
	JNE	ROTATE24LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	CMP	EDI,65536
	JB	ROTATE24NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
ROTATE24NOINC2:
	
	POP	EBX
	DEC	EBX
	DEC	EBX
	DEC	EBX
	DEC	EBP
	CMP	EBP,0
	JNE	ROTATE24LOOP4

	JMP	EXITROTATELEFTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  8 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
ROTATELEFTBITMAP8:
	MOV	EBP,BMPW		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2
	ADD	EBX,BMPW
	DEC	EBX
ROTATELEFT8LOOP4:
	PUSH	EBX
	MOV	ECX,BMPH		; width
ROTATELEFT8LOOP3:
	PUSH	EBX
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	POP	EBX
	SUB	EBX,BMPW2

	CMP	EDI,65536
	JB	ROTATELEFT8NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
ROTATELEFT8NOINC:
	DEC	ECX
	CMP	ECX,0
	JNE	ROTATELEFT8LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	CMP	EDI,65536
	JB	ROTATELEFT8NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
ROTATELEFT8NOINC2:
	POP	EBX
	DEC	EBX
	DEC	EBP
	CMP	EBP,0
	JNE	ROTATELEFT8LOOP4

	JMP	EXITROTATELEFTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  4 bit bitmaps //////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
ROTATELEFTBITMAP4:
	MOV	EBP,BMPW		; height
	MOV	EBX,BMPSIZE	
; start from bottom up 
	SUB	EBX,BMPW2
	ADD	EBX,BMPW3
	DEC	EBX
ROTATELEFT4LOOP4:
	PUSH	EBX
	MOV	ECX,BMPH		; width
ROTATELEFT4LOOP3:
	PUSH	EBX
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	AL,4
	SHR	AL,4
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	ROTATELEFT4NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
ROTATELEFT4NOINC:
	POP	EBX
	SUB	EBX,BMPW2
	DEC	ECX
	CMP	ECX,0
	JNE	ROTATELEFT4LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	CMP	EDI,65536
	JB	ROTATELEFT4NOINC3
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
ROTATELEFT4NOINC3:
	POP	EBX
	DEC	EBP
	CMP	EBP,0
	JE	EXITROTATELEFTBITMAP


;	br
	PUSH	EBX
	MOV	ECX,BMPH		; width
ROTATELEFT4LOOP2:
	PUSH	EBX
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHR	AL,4
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	ROTATELEFT4NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
ROTATELEFT4NOINC2:
	POP	EBX
	SUB	EBX,BMPW2
	DEC	ECX
	CMP	ECX,0
	JNE	ROTATELEFT4LOOP2

	ADD	EDI,LINESIZE
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	CMP	EDI,65536
	JB	ROTATELEFT4NOINC4
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
ROTATELEFT4NOINC4:
	POP	EBX

	DEC	EBX
	DEC	EBP
	CMP	EBP,0
	JNE	ROTATELEFT4LOOP4

	JMP	EXITROTATELEFTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  1 bit bitmaps ///////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
ROTATELEFTBITMAP1:
;	MOV	EBP,BMPW		; height
;	MOV	EBX,BMPSIZE	
;; start from bottom up 
;	SUB	EBX,BMPW2
;	ADD	EBX,BMPW3
;	DEC	EBX
;ROTATELEFT1LOOP4:
;	PUSH	EBX
;	MOV	ECX,BMPH		; width
;ROTATELEFT1LOOP3:
;	PUSH	EBX
;	XOR	EAX,EAX
;	MOV	AL,FS:[BX]
;	SHL	AL,7
;	SHR	AL,7
;	SHL	EAX,2
;	ADD	EAX,54
;	MOV	ESI,EAX
;	MOV	EAX,FS:[SI]	
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	CMP	EDI,65536
;	JB	ROTATELEFT1NOINC
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;ROTATELEFT1NOINC:
;	POP	EBX
;	SUB	EBX,BMPW2
;	DEC	ECX
;	CMP	ECX,0
;	JNE	ROTATELEFT1LOOP3
;
;	ADD	EDI,LINESIZE
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	CMP	EDI,65536
;	JB	ROTATELEFT1NOINC3
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;ROTATELEFT1NOINC3:
;	POP	EBX
;	DE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
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	CMP	EDI,65536
;	JB	ROTATELEFT1NOINC10
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;ROTATELEFT1NOINC10:
;	POP	EBX
;	SUB	EBX,BMPW2
;	DEC	ECX
;	CMP	ECX,0
;	JNE	ROTATELEFT1LOOP10
;
;	ADD	EDI,LINESIZE
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	CMP	EDI,65536
;	JB	ROTATELEFT1NOINC10A
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;ROTATELEFT1NOINC10A:
;	POP	EBX
;	DEC	EBP
;	CMP	EBP,0
;	JE	EXITROTATELEFTBITMAP
;
;
;	PUSH	EBX
;	MOV	ECX,BMPH		; width
;ROTATELEFT1LOOP11:
;	PUSH	EBX
;	XOR	EAX,EAX
;	MOV	AL,FS:[BX]
;	SHL	AL,0
;	SHR	AL,7
;	SHL	EAX,2
;	ADD	EAX,54
;	MOV	ESI,EAX
;	MOV	EAX,FS:[SI]	
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	CMP	EDI,65536
;	JB	ROTATELEFT1NOINC11
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;ROTATELEFT1NOINC11:
;	POP	EBX
;	SUB	EBX,BMPW2
;	DEC	ECX
;	CMP	ECX,0
;	JNE	ROTATELEFT1LOOP11
;
;	ADD	EDI,LINESIZE
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	CMP	EDI,65536
;	JB	ROTATELEFT1NOINC11A
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;ROTATELEFT1NOINC11A:
;	POP	EBX
;	DEC	EBP
;	CMP	EBP,0
;	JE	EXITROTATELEFTBITMAP
;
;
;
;	DEC	EBX
;	DEC	EBP
;	CMP	EBP,0
;	JNE	ROTATELEFT1LOOP4
;
EXITROTATELEFTBITMAP:
	POPAD
	RET
ROTATEBITMAPLEFT	ENDP



; fs:[si] = bitmap file
; eax = x pos
; ebx = y pos
ROTATEBITMAPRIGHT	PROC
	PUSHAD
; get bitmap parameters from header
	CALL	GETBITMAPPARAMS
;	mov	eax,bmpx
;	mov	ebx,bmpy
	CALL	SETBITMAPPOS

	MOV	AX,BMPBITSPERPIXEL
	CMP	AX,24
	JE	ROTATERIGHTBITMAP24
	CMP	AX,8
	JE	ROTATERIGHTBITMAP8
	CMP	AX,4
	JE	ROTATERIGHTBITMAP4
	CMP	AX,1
	JE	ROTATERIGHTBITMAP1
	JMP	EXITROTATERIGHTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  24 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
ROTATERIGHTBITMAP24:
	MOV	EBP,BMPW		; height
	XOR	EBX,EBX
	ADD	EBX,54
ROTATERIGHT24LOOP4:
	PUSH	EBX
	MOV	ECX,BMPH		; width
ROTATERIGHT24LOOP3:
	PUSH	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EDI
	INC	EBX
	POP	EBX
	ADD	EBX,BMPW2

	CMP	EDI,65536
	JB	ROTATERIGHT24NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK
ROTATERIGHT24NOINC:
	DEC	ECX
	CMP	ECX,0
	JNE	ROTATERIGHT24LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	CMP	EDI,65536
	JB	ROTATERIGHT24NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK
ROTATERIGHT24NOINC2:
	POP	EBX
	INC	EBX
	INC	EBX
	INC	EBX
	DEC	EBP
	CMP	EBP,0
	JNE	ROTATERIGHT24LOOP4

	JMP	EXITROTATERIGHTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  8 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
ROTATERIGHTBITMAP8:
	MOV	EBP,BMPW		; width
	XOR	EBX,EBX
	ADD	EBX,54
	ADD	EBX,1024
ROTATERIGHT8LOOP4:
	PUSH	EBX
	MOV	ECX,BMPH		; height
ROTATERIGHT8LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]
	MOV	ES:[DI],EAX
	ADD	EDI,4
	ADD	EBX,BMPW2

	CMP	EDI,65536
	JB	ROTATERIGHT8NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK
ROTATERIGHT8NOINC:
	DEC	ECX
	CMP	ECX,0
	JNE	ROTATERIGHT8LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	CMP	EDI,65536
	JB	ROTATERIGHT8NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK
ROTATERIGHT8NOINC2:
	POP	EBX
	INC	EBX
	DEC	EBP
	CMP	EBP,0
	JNE	ROTATERIGHT8LOOP4

	JMP	EXITROTATERIGHTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  4 bit bitmaps //////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
ROTATERIGHTBITMAP4:
	MOV	EBP,BMPW		; width
	XOR	EBX,EBX
	ADD	EBX,54
	ADD	EBX,64
ROTATERIGHT4LOOP4:
	PUSH	EBX
	MOV	ECX,BMPH		; height
ROTATERIGHT4LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	AL,4
	SHR	AL,4
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]
	MOV	ES:[DI],EAX
	ADD	EDI,4
	ADD	EBX,BMPW2

	CMP	EDI,65536
	JB	ROTATERIGHT4NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK
ROTATERIGHT4NOINC:
	DEC	ECX
	CMP	ECX,0
	JNE	ROTATERIGHT4LOOP3

	POP	EBX

	DEC	EBP
	CMP	EBP,0
	JE	EXITROTATERIGHTBITMAP

	ADD	EDI,LINESIZE
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	CMP	EDI,65536
	JB	ROTATERIGHT4NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK
ROTATERIGHT4NOINC2:
	PUSH	EBX

	MOV	ECX,BMPH		; height
ROTATERIGHT4LOOP3A:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHR	AL,4
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]
	MOV	ES:[DI],EAX
	ADD	EDI,4
	ADD	EBX,BMPW2

	CMP	EDI,65536
	JB	ROTATERIGHT4NOINCA
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK
ROTATERIGHT4NOINCA:
	DEC	ECX
	CMP	ECX,0
	JNE	ROTATERIGHT4LOOP3A


	ADD	EDI,LINESIZE
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	SUB	EDI,BMPH
	CMP	EDI,65536
	JB	ROTATERIGHT4NOINC2A
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK
ROTATERIGHT4NOINC2A:
	POP	EBX

	INC	EBX
	DEC	EBP
	CMP	EBP,0
	JNE	ROTATERIGHT4LOOP4

	JMP	EXITROTATERIGHTBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  1 bit bitmaps ///////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
ROTATERIGHTBITMAP1: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SI]
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	ADD	EBX,BMPW2
;
;	CMP	EDI,65536
;	JB	ROTATERIGHT1NOINC10
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK
;ROTATERIGHT1NOINC10:
;	DEC	ECX
;	CMP	ECX,0
;	JNE	ROTATERIGHT1LOOP10
;
;	POP	EBX
;
;	DEC	EBP
;	CMP	EBP,0
;	JE	EXITROTATERIGHTBITMAP
;
;	ADD	EDI,LINESIZE
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	SUB	EDI,BMPH
;	CMP	EDI,65536
;	JB	ROTATERIGHT1NOINC10A
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK
;ROTATERIGHT1NOINC10A:
;
;	INC	EBX
;	DEC	EBP
;	CMP	EBP,0
;	JNE	ROTATERIGHT1LOOP4
;
EXITROTATERIGHTBITMAP:
	POPAD
	RET
ROTATEBITMAPRIGHT	ENDP



; fs:[si] = bitmap file 
; eax = x pos
; ebx = y pos
UPDOWNBITMAP	PROC
	PUSHAD
; get bitmap parameters from header	
	CALL	GETBITMAPPARAMS
;	mov	eax,bmpx
;	mov	ebx,bmpy
	CALL	SETBITMAPPOS

	MOV	AX,BMPBITSPERPIXEL
	CMP	AX,24
	JE	UPDOWNBITMAP24
	CMP	AX,8
	JE	UPDOWNBITMAP8
	CMP	AX,4
	JE	UPDOWNBITMAP4
	CMP	AX,1
	JE	UPDOWNBITMAP1
	JMP	EXITUPDOWNBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  24 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
UPDOWNBITMAP24:
	MOV	EBP,BMPH		; height
	XOR	EBX,EBX
	ADD	EBX,54
UPDOWN24LOOP4:
	MOV	ECX,BMPW		; width
UPDOWN24LOOP3:
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EBX
	MOV	AL,FS:[BX]
	MOV	ES:[DI],AL
	INC	EDI
	INC	EDI
	INC	EBX

	CMP	EDI,65536
	JB	UPDOWN24NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
UPDOWN24NOINC:
	DEC	ECX
	CMP	ECX,0
	JNE	UPDOWN24LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	UPDOWN24NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
UPDOWN24NOINC2:
	br
	SUB	EBX,BMPW		; width
	SUB	EBX,BMPW		; width
	SUB	EBX,BMPW		; back to the start of current row
	ADD	EBX,BMPW2		; start of next row 
	DEC	EBP
	CMP	EBP,0
	JNE	UPDOWN24LOOP4

	JMP	EXITUPDOWNBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  8 bit bitmaps /////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
UPDOWNBITMAP8:
	MOV	EBP,BMPH		; height
	XOR	EBX,EBX
	ADD	EBX,54
UPDOWN8LOOP4:
	MOV	ECX,BMPW		; width
UPDOWN8LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4

	INC	EBX
	CMP	EDI,65536
	JB	UPDOWN8NOINC
	MOV	EDI,65536
	INC	EDX
	CALL	SETBANK	
UPDOWN8NOINC:
	DEC	ECX
	CMP	ECX,0
	JNE	UPDOWN8LOOP3

	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	UPDOWN8NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
UPDOWN8NOINC2:
;	br
	SUB	EBX,BMPW		; back to the start of current row
	ADD	EBX,BMPW2		; start of next row 
	DEC	EBP
	CMP	EBP,0
	JNE	UPDOWN8LOOP4
	JMP	EXITUPDOWNBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  4 bit bitmaps //////////////////////////////////////////////
; /////////////////////////////////////////////////////////////////////////////////////
UPDOWNBITMAP4:
	MOV	EBP,BMPH		; height
	XOR	EBX,EBX
	ADD	EBX,54
	ADD	EBX,64
UPDOWN4LOOP4:
	MOV	ECX,BMPW		; width
UPDOWN4LOOP3:
	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHL	AL,4
	SHR	AL,4
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	CMP	EDI,65536
	JB	UPDOWN4NOINC
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
UPDOWN4NOINC:
	INC	EBX
	DEC	ECX
	CMP	ECX,0
	JE	UPDOWN4NEXTROW
	DEC	EBX

	XOR	EAX,EAX
	MOV	AL,FS:[BX]
	SHR	AL,4
	SHL	EAX,2
	ADD	EAX,54
	MOV	ESI,EAX
	MOV	EAX,FS:[SI]	
	MOV	ES:[DI],EAX
	ADD	EDI,4
	INC	EBX
	CMP	EDI,65536
	JB	UPDOWN4NOINC2
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
UPDOWN4NOINC2:
	DEC	ECX
	CMP	ECX,0
	JNE	UPDOWN4LOOP3

UPDOWN4NEXTROW:
	ADD	EDI,LINESIZE
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	SUB	EDI,BMPW
	CMP	EDI,65536
	JB	UPDOWN4NOINC3A
	SUB	EDI,65536
	INC	EDX
	CALL	SETBANK	
UPDOWN4NOINC3A:
	SUB	EBX,BMPW3		; back to the start of current row
	ADD	EBX,BMPW2		; start of next row 
	DEC	EBP
	CMP	EBP,0
	JNE	UPDOWN4LOOP4
	JMP	EXITUPDOWNBITMAP
; //////////////////////////////////////////////////////////////////////////////////////
; ////////////////  1 bit bitmaps ///////////////////////////////////////////////
; //////////////////////////////////////////////////////////////////////////////////////
UPDOWNBITMAP1:
;	MOV	EBP,BMPH		; height
;	XOR	EBX,EBX
;	ADD	EBX,54
;	ADD	EBX,8
;UPDOWN1LOOP4:
;	MOV	ECX,BMPW		; width
;UPDOWN1LOOP3:
;	XOR	EAX,EAX
;	MOV	AL,FS:[BX]
;	SHL	AL,0
;	SHR	AL,7
;	SHL	EAX,2
;	ADD	EAX,54
;	MOV	ESI,EAX
;	MOV	EAX,FS:[SI]	
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	CMP	EDI,65536
;	JB	UPDOWN1NOINC
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;UPDOWN1NOINC:
;	INC	EBX
;	DEC	ECX
;	CMP	ECX,0
;	JE	UPDOWN1NEXTROW
;	DEC	EBX
;
;	XOR	EAX,EAX
;	MOV	AL,FS:[BX]
;	SHL	AL,1
;	SHR	AL,7
;	SHL	EAX,2
;	ADD	EAX,54
;	MOV	ESI,EAX
;	MOV	EAX,FS:[SI]	
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	CMP	EDI,65536
;	JB	UPDOWN1NOINC2
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;UPDOWN1NOINC2:
;	INC	EBX
;	DEC	ECX
;	CMP	ECX,0
;	JE	UPDOWN1NEXTROW
;	DEC	EBX
;
;	XOR	EAX,EAX
;	MOV	AL,FS:[BX]
;	SHL	AL,2
;	SHR	AL,7
;	SHL	EAX,2
;	ADD	EAX,54
;	MOV	ESI,EAX
;	MOV	EAX,FS:[SI]	
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	CMP	EDI,65536
;	JB	UPDOWN1NOINC3
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;UPDOWN1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
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	CMP	EDI,65536
;	JB	UPDOWN1NOINC7
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;UPDOWN1NOINC7:
;	INC	EBX
;	DEC	ECX
;	CMP	ECX,0
;	JE	UPDOWN1NEXTROW
;	DEC	EBX
;
;	XOR	EAX,EAX
;	MOV	AL,FS:[BX]
;	SHL	AL,7
;	SHR	AL,7
;	SHL	EAX,2
;	ADD	EAX,54
;	MOV	ESI,EAX
;	MOV	EAX,FS:[SI]	
;	MOV	ES:[DI],EAX
;	ADD	EDI,4
;	CMP	EDI,65536
;	JB	UPDOWN1NOINC8
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;UPDOWN1NOINC8:
;	INC	EBX
;	DEC	ECX
;	CMP	ECX,0
;	JNE	UPDOWN1LOOP3
;
;UPDOWN1NEXTROW:
;	ADD	EDI,LINESIZE
;	SUB	EDI,BMPW
;	SUB	EDI,BMPW
;	SUB	EDI,BMPW
;	SUB	EDI,BMPW
;	CMP	EDI,65536
;	JB	UPDOWN1NOINC3A
;	SUB	EDI,65536
;	INC	EDX
;	CALL	SETBANK	
;UPDOWN1NOINC3A:
;	BR
;	SUB	EBX,BMPW3		; back to the start of current row
;	ADD	EBX,BMPW2		; start of next row 
;	DEC	EBP
;	CMP	EBP,0
;	JNE	UPDOWN1LOOP4
;
EXITUPDOWNBITMAP:
	POPAD
	RET
UPDOWNBITMAP	ENDP

