
FixedDMACRAM: macro src, dest, len
    dc.l  $94009300|(((\len)<<7)&$FF0000)|(((\len)>>1)&$FF)
    dc.l  $96009500|(((\src)<<7)&$FF0000)|(((\src)>>1)&$FF)
    dc.w  $9700|(((\src)>>17)&$FF)
    dc.l  $C0000080|((\dest)&$3FFF)<<16|(\dest)>>14
    endm

    
ReloadHBL:
	jmp   (a4)
ReloadHBL_End:
HBL1:
    
	move.w #$8114, VDPCONTROL
    move.l (a6)+, VDPCONTROL
	move.l (a6)+, VDPCONTROL
	move.w (a6)+, VDPCONTROL
	move.l (a6)+, VDPCONTROL
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	move.w #$8174, VDPCONTROL
    Lea HBL2, a4
	rte
HBL2:
    Lea HBL1, a4
    rte

ReloadVBL:
    setvsramaddr $0,  vdpcontrol
    move.w d7, vdpdata
    sub.w #-2, d7
	lea 7*2*4(a5), a5
	lea (a5), a6
    lea HBL1, a4
	bra.w RELOADHBL
	


	
PalPix:
	move.w #$9001, VDPCONTROL
    disableints
		move.l #reloadVBL, (RAM_VINTLOC+2)
        lea (ReloadHBL), a0
        lea (RAM_HInt), a1
        move.l #((reloadHBL_End-ReloadHBL)/2)-1,d0   
@CopyHINT:
        move.w (a0)+, (a1)+
        dbf d0, @CopyHINT 
	setcramaddr 0, vdpcontrol
    move.w #0, VDPDATA
	singledmavram Megascrolltiles, 32, 40*32*32, VDPCONTROL
	singledmavram PalPixMap, $C000, 64*32*2,vdpcontrol
	lea DMATABLE, a5
	lea HBL1, a4
	
	moveq #0, d7
    
	enableints
@Datloop
    
    WaitFrame
    Echo_z80request
    move.b ($A01200), d0
    move.b #0, ($A01200)
    echo_z80release
    tst.b d0
    bne.w @NextPart 
    
    jmp @Datloop
@nextpart
	rts
	
    jmp @Datloop
	rts
	
DMATable:
x = 0

	rept 1536
		rept 4
			Fixeddmacram MegaScroll+32*x+2, 2, 30
		endr
x = x+1
	endr
	
	even
	

Megascroll:
	incbin ./palpix/palpix.pal
	even
MegascrollTiles:
	incbin ./palpix/palpix.bin
	even
	

PalPixMap:
x = 0
	rept 32
	rept 40
		
		dc.w x+1
x = x+1
	endr
	rept 24
		dc.w 0
	endr
	endr
    
 
	