	
	
DoLineTable:	
	mov.l LineTable,r6
	mov.l LineStartAddr,r8	;Addr in pairs of bytes (Actual addr /2)
	mov.l LineCount,r0 
	mov.l OneLineSizeA,r7	;Length of line in pairs of bytes
	
	
	
LineTableLoop:	
	mov.w r8,@r6	;Define line address
	add r7,r8		;Move down one line
	add	#2,r6		;Next Line table address
	
	add #-1,r0
	cmp/eq #0,r0
	bf LineTableLoop

	rts	
	nop
	

PageFlip:
	mov.l #UserRam,r14		;R14 points to our work ram
	;mov.l AdrUserRam,r14		;R14 points to our work ram
	
	mov.l @(UserRam_VdpStat,r14),r1		;Get framebuffer state (Delay slot)
	mov	r1,r0
	mov.l VdpState,r2	;2000410a VDP State
	xor	#1,r0				;Flip frame buffer
	mov.l r0,@(UserRam_VdpStat,r14)	;Save in ram
	mov.w r0,@r2			;Flip frame buffer
	
WaitForFlip:	
	mov.l VdpState,r3	;2000410a
	mov.w @r3,r0
	and	#1,r0				;Buffer State
	cmp/eq r1,r0			;Has buffer flipped?
	bt WaitForFlip			;NO! Then Wait!!!
	rts	
	nop
	
	
	align 4	

AdrUserRam: 	dc.l UserRam
AdrPalette:		dc.l Palette
AdrFont:		dc.l Font

UserRam_VdpStat equ 0	
UserRam_CursorX equ 4
UserRam_CursorY equ 8
	
UserRam:
	dc.l 0	;VDP Stat cache
	dc.l 0	;Xpos
	dc.l 0	;Ypos
	dc.l 0
	dc.l 0
	dc.l 0
	
Palette:
		 ;-BBBBBGGGGGRRRRR
	dc.w %0011110000000000
	dc.w %0000001111111111
	dc.w %0111111111100000
	dc.w %0000000000011111
	
	ltorg

	
	align 4
	
OneLineSizeA:	dc.l 160
OneLineSize:	dc.l 320
LineCount:		dc.l 224
LineStartAddr:	dc.l $100
VarBlock:

Regs32x:
        dc.l $20004000     ;  6  - Ofst:&60001A0	32x Registers (64 bytes) - Cache through Addr
VdpRegs:
        dc.l $20004100     ;  7  - Ofst:&60001A4	VDP Registers (16 bytes) - Cache through Addr
ColorRam:
        dc.l $20004200     ;  8  - Ofst:&60001A8	VDP CRAM (512 bytes)	 - Cache through Addr
VdpState:
        dc.l $2000410A     ; 10  - Ofst:&60001B0	SH2_RB_VDP_State
LineTable:
        dc.l $24000000     ; 11  - Ofst:&60001B4	Frame Buffer (128k bytes)- Cache through Addr (Line Table)
        dc.l $24000002     ; 12  - Ofst:&60001B8	Frame Buffer (128k bytes)- Cache through Addr
        dc.l $0000A100     ; 13  - Ofst:&60001BC
		
AdrScreenbuffer:  ;dc.l $24000200 ; equ ScreenBase		
ScreenBase:   dc.l $24000200     ; 14  - Ofst:&60001C0	Frame Buffer (128k bytes)- Cache through Addr (Data)
	
Font:							;1bpp font - 8x8 96 characters 
	binclude "\ResALL\Font96.FNT"
	