Map objects get loaded as new map rows are drawn.
.de pat_tilemap, 10
.de pat_size, 0
+ ; map object types
+.se 0
+.de MOT_SET_PAT, 1
+.de MOT_DISABLE_SCROLL, 1
+.de MOT_ENABLE_SCROLL, 1
+.de MOT_RECT, 1
+.de MOT_ACTOR_SPAWNER, 1
+
; map object struct
.se 0
.de mo_type, 1
; $1: type
; $2: flags
; $3: row
- ; $4: dat1
- ; $5: dat2
+ ; $4: dat1/dat2 (word)
#macro modef
- .db $1, $2, $3, $4, $5
+ .db $1, $2, $3
+ dw $4
#endmacro
; adjusts an input position
ld a, SCRN0_END HI
ld [map_scrn_ptr+1], a
+ ; load mo ptr
+ ld hl, map_objs_ptr
+ add hl, de
+ ld a, [hl+]
+ ld [map_curr_obj], a
+ ld a, [hl+]
+ ld [map_curr_obj+1], a
+
call lcd_on
call vblank_wait
ld a, [map_curr_row]
inc a
ld [map_curr_row], a
- call map_check_obj
+
+ call mo_exec
ret
- ; checks the newly drawn row for objects
- ; that can execute code
-map_check_obj:
- ; TODO
- ret
; draws a full page of the currently selected map
; waits for blank between each row
ret
l1_map:
- mapdef 0, pat_empty, NULL, bank8000, bank8800, bank8C00, bank9000
+ mapdef 0, pat_empty, l1_objs, bank8000, bank8800, bank8C00, bank9000
+
+l1_objs:
+ modef MOT_SET_PAT, 0, 3, pat_center_grass
+ modef MOT_SET_PAT, 0, 5, pat_empty
; is checked
; if the row matches it is loaded into ram and executed
; when an object is off-screen it is unloded
+
+mo_routines:
+ dw mo_set_pat
+ dw mo_disable_scroll
+ dw mo_enable_scroll
+ dw mo_rect
+ dw mo_actor_spawner
+
+ ; executes all map objects in the map object list
+ ; until the mo's row != current row
+ ; advances mo ptr
+mo_exec:
+ ld a, [map_curr_obj]
+ ld e, a
+ ld a, [map_curr_obj+1]
+ ld d, a
+
+ ld a, [map_curr_row]
+ ld b, a ; b = current row
+@loop:
+ ; execute map object by type
+ ld hl, mo_row
+ add hl, de
+ ld a, [hl]
+ ; if rows do not match exit
+ cp a, b
+ jr nz, @done REL
+
+ ; otherwise call object routine
+ push_all
+ ld a, [de] ; type
+ add a, a ; * 2 for offset
+ ld hl, mo_routines
+ ld b, 0
+ ld c, a
+ add hl, bc
+
+ ; hl = rotuine ptr
+ ld a, [hl+]
+ ld b, a
+ ld a, [hl+]
+ ld h, a
+ ld l, b
+
+ ; call routine
+ call_hl
+
+
+ pop_all
+ ; go to next object
+ ld hl, mo_size
+ add hl, de
+ push hl
+ pop de ; de = next obj
+ jr @loop REL
+
+@done:
+
+ ; write back next ptr
+ ld a, e
+ ld [map_curr_obj], a
+ ld a, d
+ ld [map_curr_obj+1], a
+
+ ret
+
+ ; sets the next draw pattern
+ ; inputs:
+ ; de: map object ptr
+mo_set_pat:
+ ; new pattern is in dat1 and dat2
+ ld hl, mo_dat
+ add hl, de
+
+ ld a, [hl+]
+ ld [map_curr_pat], a
+ ld a, [hl]
+ ld [map_curr_pat+1], a
+ ret
+
+ ; disables map scrolling
+ ; inputs:
+ ; de: map object ptr
+mo_disable_scroll:
+ ret
+
+ ; enables map scrolling
+ ; inputs:
+ ; de: map object ptr
+mo_enable_scroll:
+ ret
+
+ ; spawns a collision rectangle
+ ; inputs:
+ ; de: map object ptr
+mo_rect:
+ ret
+
+ ; spawns an actor spawner
+ ; inputs:
+ ; de: map object ptr
+mo_actor_spawner:
+ ret
; tile space
.def int TS = 0x40
+.def int GS = 0x62
pat_empty:
.db TS, TS, TS, TS, TS, TS, TS, TS, TS, TS
+
+pat_center_grass:
+.db TS, TS, TS, GS, GS, GS, TS, TS, TS, TS
+
; enf of level row pattern
pat_eol:
map: .adv 2
; ptr to the next map object
; that may be loaded
-map_obj_ptr: .adv 2
+map_curr_obj: .adv 2
; current bg pointer to write to
map_scrn_ptr: .adv 2