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
|
|
|
|
wField:: ds (10*21)
|
|
|
|
|
|
|
|
|
|
|
|
SECTION "Field Functions", ROM0
|
|
|
|
FieldInit::
|
2023-10-16 05:47:11 +00:00
|
|
|
ld hl, wField
|
|
|
|
ld bc, 10*21
|
|
|
|
ld d, 1
|
|
|
|
call UnsafeMemSet
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
FieldClear::
|
2023-10-13 09:20:28 +00:00
|
|
|
ld hl, wField
|
|
|
|
ld bc, 10*21
|
|
|
|
ld d, TILE_FIELD_EMPTY
|
|
|
|
call UnsafeMemSet
|
|
|
|
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-16 05:47:11 +00:00
|
|
|
ld de, wField + 10
|
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
|
|
|
|
ld bc, 32
|
|
|
|
|
|
|
|
; 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
|
|
|
|
|
|
|
|
; The last 6 rows need some care.
|
|
|
|
REPT 6
|
|
|
|
REPT 2
|
|
|
|
: ldh a, [rSTAT]
|
|
|
|
and STATF_LCD
|
|
|
|
cp STATF_HBL
|
|
|
|
jr z, :-
|
|
|
|
: ldh a, [rSTAT]
|
|
|
|
and STATF_LCD
|
|
|
|
cp STATF_HBL
|
|
|
|
jr nz, :-
|
|
|
|
REPT 5
|
|
|
|
ld a, [de]
|
|
|
|
ld [hl+], a
|
|
|
|
inc de
|
|
|
|
ENDR
|
|
|
|
ENDR
|
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
|