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
|
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
|