;mode 0102 - 800x600     lfb=00000000    bpp=4   bpl=100
;mode 0103 - 800x600     lfb=01080000    bpp=8   bpl=800
;mode 0114 - 800x600     lfb=01080000    bpp=16  bpl=1600
;mode 0115 - 800x600     lfb=01080000    bpp=32  bpl=3200

format	mz
stack	sseg:tos
entry	cseg:start
heap	0

granularity equ word[buff+4]
videosegment equ word[buff+8]
bankswitch equ dword[buff+12]
bytesperline equ word[buff+16]
screencolumns equ word[buff+18]
screenrows equ word[buff+20]

segment cseg
start:	mov ax,dseg
	mov dx,es
	mov bx,ss
	mov ds,ax
	add bx,4096/16
	sub bx,dx
	mov ah,4ah
	int 21h

	call font16_initialise

	push ds
	pop es
	mov ax,4f01h
	mov cx,0103h
	mov di,buff
	int 10h
	cmp ax,4fh
	jnz .done

	mov ax,64
	sub dx,dx
	div granularity
	mov [pagesper64k],ax

	mov si,addresstable
	sub ax,ax
	sub dx,dx
	mov cx,screenrows
    .0: mov [si],ax
	mov [si+2],dx
	add si,4
	add ax,bytesperline
	jnc .1
	add dx,[pagesper64k]
    .1: dec cx
	jnz .0
	mov [currentbank],cx

	mov ax,4f02h
	mov bx,0103h
	int 10h

	sub al,al
	sub dx,dx
  .667: sub cx,cx
  .666: call setpixel8
	inc cx
	cmp cx,screencolumns
	jb .666
	inc dx
	inc al
	cmp dx,screenrows
	jb .667

.wait:	sub ax,ax
	int 16h
	mov ax,3
	int 10h
.done:	mov ah,4ch
	int 21h

setpixel8: ;AL=colour,CX=column,DX=row
	push cx dx di es ax
	mov di,dx
	shl di,2
	mov dx,word[addresstable+di+2]
	mov di,word[addresstable+di]
	add di,cx
	jnc .0
	add dx,[pagesper64k]
    .0: cmp dx,[currentbank]
	jz .1
	mov [currentbank],dx
	mov ax,4f05h
	sub bx,bx
	call bankswitch
    .1: pop ax
	mov es,videosegment
	mov [es:di],al
	pop es di dx cx
	ret





font16_initialise:
	push eax ebp bx es
	mov bh,3
	call .get
	mov [font8x8],eax
	mov bh,4
	call .get
	mov [font8x8+4],eax
	pop es bx ebp eax
	ret
.get:	mov ax,1130h
	int 10h
	;mov eax,es
	;movzx ebp,bp
	;shl eax,4
	;add eax,ebp
	mov ax,es
	shl eax,16
	mov ax,bp
	ret
font32_drawchar:























segment dseg
addresstable rd 1200
pagesper64k  rw 1
currentbank  rw 1
buff	     rb 256

font8x8  rd 2	;first dd is pointer to low 128 chars, next dd is high 128
font8x16 rd 2	;same

segment sseg
     rb 4096
tos:

;4bit
;0102 800x600
;0104 1024x768
;0106 1280x1024
;8bit
;0101 640x480
;0103 800x600
;0105 1024x768
;0107 1280x1024
;0145 1600x1200
;16bit
;0111 640x480
;0114 800x600
;0117 1024x768
;011A 1280x1024
;0146 1600x1200
;32bit
;0112 640x480
;0115 800x600
;0118 1024x768
;011B 1280x1024
;014A 1600x1200