dmgtris/src/field.asm

125 lines
2.0 KiB
NASM

IF !DEF(FIELD_ASM)
DEF FIELD_ASM EQU 1
INCLUDE "globals.asm"
SECTION "Field Variables", WRAM0
wField:: ds (10*24)
wShadowField:: ds (14*26)
SECTION "Field Functions", ROM0
FieldInit::
ld hl, wField
ld bc, 10*24
ld d, 1
call UnsafeMemSet
ld hl, wShadowField
ld bc, 14*26
ld d, $FF
call UnsafeMemSet
ret
FieldClear::
ld hl, wField
ld bc, 10*24
ld d, TILE_FIELD_EMPTY
call UnsafeMemSet
ret
ToShadowField::
ld hl, wField
ld de, wShadowField+2
ld c, 24
.outer
ld b, 10
.inner
ld a, [hl+]
ld [de], a
inc de
dec b
jr nz, .inner
inc de
inc de
inc de
inc de
dec c
jr nz, .outer
ret
FromShadowField::
ld hl, wField
ld de, wShadowField+2
ld c, 24
.outer
ld b, 10
.inner
ld a, [de]
ld [hl+], a
inc de
dec b
jr nz, .inner
inc de
inc de
inc de
inc de
dec c
jr nz, .outer
ret
; This routine will copy wField onto the screen.
BlitField::
; What to copy
ld de, wField + 40
; Where to put it
ld hl, FIELD_TOP_LEFT
; How much to increment hl after each row
ld bc, 32-10
; The first 14 rows can be blitted without checking for vram access.
REPT 14
REPT 10
ld a, [de]
ld [hl+], a
inc de
ENDR
add hl, bc
ENDR
: ldh a, [rLY]
cp a, 0
jr nz, :-
; The last 6 rows need some care.
REPT 6
; Wait until start of drawing, then insert 35 nops.
: ldh a, [rSTAT]
and a, 3
cp a, 3
jr nz, :-
REPT 35
nop
ENDR
; Blit a line.
REPT 10
ld a, [de]
ld [hl+], a
inc de
ENDR
; Increment HL so that the next line can be blitted.
add hl, bc
ENDR
; This has to finish just before the first LCDC interrupt of the frame or stuff will break in weird ways.
jp EventLoop
ENDC