I send the buffer without using DMA, in the CPU loop in every frame.
The ROM running on the console works, also on emulators - so even without DMA, sending the buffer to VRAM outside the VBLANK is done without problems - the only question is whether you can do that, are there any restrictions? I tried to send using DMA, but I am doing something wrong and here I would like to advise you on how to do it correctly.
SATBuff Send Code to SAT VRAM Directly, No DMA: (simple_platformer_genesis_DIRECT_SAT.bin)
Code: Select all
0x00FF0000-00FF01FF - SATBuff
;------------------------------
Forever:
BSR WaitVSync ; synchronize speed
BSR UpdateSAT
; game mechanics
BRA Forever
;------------------------------
WaitVSync:
MOVE.L (VarVSync),D0 ; Read value from VarVSync into D0
WaitVSync_:
MOVE.L (VarVSync),D1 ; Read value from VarVSync into D1
CMP.L D0,D1 ; Compare D0 and D1
BEQ WaitVsync_ ; If result is 0 the value has not been changed
; so jump back to 1
RTS
;------------------------------
INT_VInterrupt: ; Vertical interrupt - run once per frame (50hz in PAL, 60hz in NTSC)
ADD.L #1,(VarVSync)
RTE
;------------------------------
UpdateSAT: ; ### Runs on real hardware too, sends SATBuff directly to SAT VRAM ###
SetVRAMWrite 0xF000 ; copy 128 long-words to SAT (512 bytes = 64 sprites)
LEA 0x00FF0000,A0
MOVE.W #128-1,D0
UpdateSAT_Loop:
MOVE.L (A0)+,$00C00000 ; vdp_data
DBF D0,UpdateSAT_Loop ; DBF/DBRA
RTS
Code: Select all
;------------------------------
UpdateSAT_: ; ### It works incorrectly, not on every emu and probably it will not work on hardware ###
; MOVE.W #$8174,($C00004) ; VDP Register #1, Enable DMA
MOVE.W #$0100,D0 ; Word's to Send
MOVE.L #$70000003,D2 ; VRAM destination address
LEA $00FF0000,A0 ; source address
JSR DoDMAtoVRAM
; MOVE.W #$8164,($C00004) ; VDP Register #1, Disable DMA
RTS
;------------------------------
DoDMAtoVRAM:
MOVE.L #$C00004,A1 ; D0 = WORD's to transfer
MOVE.L #$94009300,D1 ; D2 = VRAM address
OR.B D0,D1 ; A0 = Source address
LSR.W #8,D0
SWAP D0
CLR.W D0
OR.L D0,D1
MOVE.L D1,(A1)
MOVE.L A0,D0
LSR.L #1,D0
MOVE.L #$97009500,D1
OR.B D0,D1
LSR.W #8,D0
OR.W #$9600,D0
MOVE.W D0,(A1) ; MID
SWAP D0
SWAP D1
AND.B #$3F,D0
OR.B D0,D1
MOVE.L D1,(A1) ; LOW, HIGH
OR.B #$80,D2
MOVE.L D2,(A1)
RTS