dmgtris/src/field.asm

125 lines
2.0 KiB
NASM
Raw Normal View History

2023-10-13 09:20:28 +00:00
IF !DEF(FIELD_ASM)
DEF FIELD_ASM EQU 1
2023-10-16 05:47:11 +00:00
INCLUDE "globals.asm"
2023-10-13 09:20:28 +00:00
SECTION "Field Variables", WRAM0
2023-10-18 11:14:48 +00:00
wField:: ds (10*24)
wShadowField:: ds (14*26)
2023-10-13 09:20:28 +00:00
SECTION "Field Functions", ROM0
FieldInit::
2023-10-16 05:47:11 +00:00
ld hl, wField
2023-10-18 11:14:48 +00:00
ld bc, 10*24
2023-10-16 05:47:11 +00:00
ld d, 1
call UnsafeMemSet
2023-10-18 11:14:48 +00:00
ld hl, wShadowField
ld bc, 14*26
ld d, $FF
call UnsafeMemSet
2023-10-16 05:47:11 +00:00
ret
FieldClear::
2023-10-13 09:20:28 +00:00
ld hl, wField
2023-10-18 11:14:48 +00:00
ld bc, 10*24
2023-10-13 09:20:28 +00:00
ld d, TILE_FIELD_EMPTY
call UnsafeMemSet
ret
2023-10-18 11:14:48 +00:00
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
2023-10-18 01:32:25 +00:00
; This routine will copy wField onto the screen.
2023-10-13 09:20:28 +00:00
BlitField::
2023-10-18 01:32:25 +00:00
; What to copy
2023-10-18 11:14:48 +00:00
ld de, wField + 40
2023-10-18 01:32:25 +00:00
; Where to put it
ld hl, FIELD_TOP_LEFT
; How much to increment hl after each row
2023-10-18 03:26:06 +00:00
ld bc, 32-10
2023-10-18 01:32:25 +00:00
; The first 14 rows can be blitted without checking for vram access.
2023-10-13 09:20:28 +00:00
REPT 14
REPT 10
ld a, [de]
ld [hl+], a
inc de
ENDR
2023-10-18 01:32:25 +00:00
add hl, bc
2023-10-13 09:20:28 +00:00
ENDR
2023-10-18 03:26:06 +00:00
: ldh a, [rLY]
cp a, 0
jr nz, :-
2023-10-13 09:20:28 +00:00
; The last 6 rows need some care.
REPT 6
2023-10-18 03:26:06 +00:00
; 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
2023-10-13 09:20:28 +00:00
ENDR
2023-10-18 03:26:06 +00:00
; Increment HL so that the next line can be blitted.
2023-10-18 01:32:25 +00:00
add hl, bc
2023-10-13 09:20:28 +00:00
ENDR
2023-10-16 05:47:11 +00:00
; This has to finish just before the first LCDC interrupt of the frame or stuff will break in weird ways.
2023-10-18 01:32:25 +00:00
jp EventLoop
2023-10-13 09:20:28 +00:00
ENDC