prepare_dma | ||||||
ld | C, | $80 | ||||
ld | B, | 10 | ||||
ld | HL, | DMAroutine | ||||
.loop | ld | A, | (HLI) | |||
ld | (C), | A | ||||
inc | C | |||||
dec | B | |||||
jr | NZ, | .loop | ||||
;use the following routine from a vblank interrupt | ||||||
dmadata_vblank_interrupt | ||||||
ld | A, | $0C | 3E | 0C | ||
ld | (dma), | A | E0 | 46 | C000-C09F > OAM | |
ld | A, | 40 | 3E | 28 | 160-cycle wait | |
.wait | dec | A | 3D | |||
jr | NZ, | .wait | 20 | FD | ||
ret | C9 | |||||
;use the following routine from anywhere else | ||||||
dmadata | ||||||
di | F3 | Interrupt disabled | ||||
ld | A, | $0C | 3E | 0C | ||
ld | (dma), | A | E0 | 46 | C000-C09F > OAM | |
ld | A, | 40 | 3E | 28 | 160-cycle wait | |
.wait | dec | A | 3D | |||
jr | NZ, | .wait | 20 | FD | ||
id | FB | Interrupt enabled | ||||
ret | C9 |
main | ||||
call | cont | ;Keypad input | ||
call | game | ;Game or other processing. | ||
.wait | halt | ;Halt the system clock. ;Return from HALT mode if an interrupt is generated. ;Wait for a vertical blanking interrupt. |
||
nop | ;Used to avoid bugs in the rare case ; that the instruction after the HALT instruction ; is not executed |
|||
ld | A, | (vblk_F) | ||
and | A | ;Generate a V-blank interrupt? | ||
jr | Z, | .wait | ;Jump if a non-V-blank interrupt | |
xor | A | |||
ld | (vblk_F), | A | ;Clear the V-Blank Flag | |
jr | main | |||
;vertical blanking routine | ||||
vblk | ||||
push | AF | |||
push | BC | |||
push | DE | |||
push | HL | |||
call | FF80 | |||
ld | A, | 1 | ||
ld | (vblk_F), | A | ||
pop | HL | |||
pop | DE | |||
pop | BC | pop | AF |
ld | A, | (addr_MBS) | ; get MSB of VRAM addr | |
and | $03 | ; VRAM is $9800 to $9BFF | ||
or | $98 | ; add on start of vram | ||
ld | (addr_MBS), | A | ; set MSB of VRAM addr |
ld | A, | (addr_LBS) | ; get LSB of VRAM addr | |
ld | B, | A | ; copy LSB of VRAM addr | |
and | $E0 | ; mask row start addr | ||
ld | C, | A | ; save result | |
ld | A, | B | ; get LSB of VRAM addr | |
and | $1F | ; calculate col offset | ||
or | C | ; add row start address | ||
ld | (addr_LBS), | A | ; set LSB of VRAM addr |
ld | A, | (row) | ; get row | |
swap | ; *16 | |||
rlc | ; *32 | |||
ld | C, | A | ; save result for later | |
and | $03 | ; calc MSB VRAM row start | ||
add | $98 | ; add start of VRAM | ||
ld | B, | A | ; set MSB of VRAL ptr | |
ld | A, | $E0 | ; LSB VRAM row start mask | |
and | C | ; calc LSB VRAM row start | ||
ld | C, | A | ; save LSB VRAM row start | |
ld | A, | (col) | ; get column | |
add | C, | ; add LSB VRAM row start | ||
ld | C, | A | ; BC contains VRAM addr |