-; animation tables
-; each actor type has a table of all frames
-; of animation it may have
+
+
+ ; calls unit's draw function
+ ; inputs:
+ ; hl: actor ptr
+unit_update_draw:
+ push hl
+ ld de, act_draw
+ add hl, de
+ ; hl = draw ptr
+ ld a, [hl+]
+ ld e, a
+ ld a, [hl]
+ ld d, a
+ ; de = draw function
+ push de
+ pop hl ; hl = draw function
+ pop de ; de = actor
+ call_hl
+ ret
+
+ ; gets the left tile offset
+ ; for object 1
+ ; based on the y flip of oam
+ ; inputs:
+ ; a: oam flags
+ ; returns:
+ ; a: x-offset
+get_left_tile_offset1:
+ and a, OAM_FXFLIP
+ jr z, @not_set REL
+ ld a, 8
+ ret
+@not_set:
+ xor a, a
+ ret
+
+ ; gets the left tile offset
+ ; for object 2
+ ; based on the y flip of oam
+ ; inputs:
+ ; a: oam flags
+ ; returns:
+ ; a: x-offset
+get_left_tile_offset2:
+ and a, OAM_FXFLIP
+ jr z, @not_set REL
+ xor a, a
+ ret
+@not_set:
+ ld a, 8
+ ret
+
+ ; draws the unit's tile
+ ; based on the set oam tile
+ ; and the currently set offset
+ ; each actor has 2 tiles drawn here
+ ; tile 1 is the selected tile
+ ; tile 2 is the tile next (+1) to the selected tile
+ ; inputs
+ ; de: actor
+unit_draw:
+ push de
+ ld hl, act_oam_tile
+ add hl, de ; hl = tile
+ ld a, [hl+]
+
+ ld b, a ; base tile
+ ld a, [hl+]
+ ld c, a ; flags
+ ld a, [hl] ; a = tile offset
+ BREAK
+ add a, b ; base tile + offset
+ ld b, a ; b = real tile
+
+ ld a, c ; c = oam flags for offset call
+ call get_left_tile_offset1
+ push bc
+ call unit_generic_draw
+
+ ; draw same tile again
+ pop bc
+ pop de
+ push de
+ inc b
+ inc b ; b+=2
+ ld a, c ; a = flags
+ call get_left_tile_offset2
+ call unit_generic_draw
+ pop de
+
+ ldnull bc
+ ret
; tile table. This can be implemented as needed
.de act_oam_tile, 1
.de act_oam_flags, 1
+
+ ; offset from the currently selected tile
+ ; animations work by applying this offset
+ ; to the selected base tile
+ ; this allows runtime configuration
+ ; of the frames
+ ; e.g. the offset could be switched to 0/2 based
+ ; on the current frame count
+ ; to make an idel animation
+ ; note: the offset should always be an even number
+ ; due to the use of 8x16 objects
+.de act_rt_oam_tile_offset, 1
.de act_size, 0
dw $1
.db $2
.db $3
+ ; tile offset
+ .db 0
#endmacro
; define an actor without state
ret
- ; calls unit's draw function
- ; inputs:
- ; hl: actor ptr
-unit_update_draw:
- push hl
- ld de, act_draw
- add hl, de
- ; hl = draw ptr
- ld a, [hl+]
- ld e, a
- ld a, [hl]
- ld d, a
- ; de = draw function
- push de
- pop hl ; hl = draw function
- pop de ; de = actor
- call_hl
- ret
-
- ; gets the left tile offset
- ; for object 1
- ; based on the y flip of oam
- ; inputs:
- ; a: oam flags
- ; returns:
- ; a: x-offset
-get_left_tile_offset1:
- and a, OAM_FXFLIP
- jr z, @not_set REL
- ld a, 8
- ret
-@not_set:
- xor a, a
- ret
-
- ; gets the left tile offset
- ; for object 2
- ; based on the y flip of oam
- ; inputs:
- ; a: oam flags
- ; returns:
- ; a: x-offset
-get_left_tile_offset2:
- and a, OAM_FXFLIP
- jr z, @not_set REL
- xor a, a
- ret
-@not_set:
- ld a, 8
- ret
-
- ; inputs
- ; de: actor
-unit_draw:
- push de
- ld hl, act_oam_tile
- add hl, de ; hl = tile
- ld a, [hl+]
-
- ld b, a ; tile
- ld a, [hl]
- ld c, a ; flags
- call get_left_tile_offset1
- push bc
- call unit_generic_draw
-
- ; draw same tile again
- pop bc
- pop de
- push de
- inc b
- inc b ; b+=2
- ld a, c ; a = flags
- call get_left_tile_offset2
- call unit_generic_draw
- pop de
-
- ldnull bc
- ret
-
; adjust an object's position
; based on sub-tile state
; inputs: