2020-05-08 19:40:26 -04:00
|
|
|
;----------------
|
|
|
|
; Animation Subs
|
|
|
|
;----------------
|
|
|
|
|
2020-05-24 01:54:13 -04:00
|
|
|
struct Actor
|
|
|
|
bytes 1, YPos
|
|
|
|
bytes 1, XPos
|
|
|
|
bytes 1, GFXCounter
|
|
|
|
bytes 1, GFXState
|
|
|
|
words 1, GFXData
|
|
|
|
bytes 1, TileData
|
|
|
|
end_struct
|
2020-05-08 19:40:26 -04:00
|
|
|
|
2020-05-24 01:54:13 -04:00
|
|
|
SECTION "Actor STructs", WRAM0
|
2020-05-08 19:40:26 -04:00
|
|
|
|
2020-05-24 01:54:13 -04:00
|
|
|
dstruct Actor, Player
|
|
|
|
|
2020-05-24 23:49:17 -04:00
|
|
|
SECTION "Animation Variables", HRAM
|
2020-05-24 01:54:13 -04:00
|
|
|
|
2020-05-24 23:49:17 -04:00
|
|
|
hCameraX: dw
|
|
|
|
hCameraY: dw
|
2020-05-24 01:54:13 -04:00
|
|
|
|
2020-05-24 23:49:17 -04:00
|
|
|
hWorkingX: dw
|
|
|
|
hWorkingY: dw
|
|
|
|
hWorkingScreenX: db
|
|
|
|
hWorkingScreenY: db
|
|
|
|
hWorkingState: db
|
|
|
|
hWorkingCounter: db
|
|
|
|
hWorkingData: dw
|
|
|
|
hWorkingTile: db
|
|
|
|
hWorkingEnd:
|
2020-05-08 19:40:26 -04:00
|
|
|
|
|
|
|
SECTION "Animations Subs", ROM0
|
|
|
|
|
|
|
|
; RenderActor:
|
|
|
|
; takes a pointer to an actor struct
|
|
|
|
; and renders it to shadow OAM, advancinc
|
|
|
|
; the animation frame and constructing
|
|
|
|
; each frame as needed.
|
|
|
|
|
|
|
|
; initial input:
|
|
|
|
; [hl] <- start of Actor Struct in WRAM
|
|
|
|
; output:
|
|
|
|
; an oam object for each line in the frame data,
|
|
|
|
; copied to shadowOAM (wShadowOAM)
|
|
|
|
|
|
|
|
RenderActor::
|
2020-05-24 01:54:13 -04:00
|
|
|
; @input: hl <- Player
|
|
|
|
; @input: de <- ShadowOAM place
|
|
|
|
ld a, [hli] ; a <- YPos
|
2020-05-24 23:49:17 -04:00
|
|
|
ldh [hWorkingScreenY], a
|
2020-05-24 01:54:13 -04:00
|
|
|
ld a, [hli] ; a <- XPos
|
2020-05-24 23:49:17 -04:00
|
|
|
ldh [hWorkingScreenX], a
|
2020-05-24 01:54:13 -04:00
|
|
|
push hl
|
|
|
|
ld a, [hli] ; a <- GFXCounter
|
2020-05-24 23:49:17 -04:00
|
|
|
ldh [hWorkingCounter], a
|
2020-05-24 01:54:13 -04:00
|
|
|
ld a, [hli] ; a <- GFXState
|
2020-05-24 23:49:17 -04:00
|
|
|
ldh [hWorkingState], a
|
2020-05-24 01:54:13 -04:00
|
|
|
ld a, [hli] ; a <- GFXData(Low)
|
2020-05-24 23:49:17 -04:00
|
|
|
ldh [hWorkingData+1], a
|
2020-05-24 01:54:13 -04:00
|
|
|
ld a, [hli] ; a <- GFXData (High)
|
2020-05-24 23:49:17 -04:00
|
|
|
ldh [hWorkingData], a
|
2020-05-24 01:54:13 -04:00
|
|
|
ld a, [hl] ; a <- TileData
|
2020-05-24 23:49:17 -04:00
|
|
|
ldh [hWorkingTile], a
|
2020-05-24 01:54:13 -04:00
|
|
|
; fin loading data
|
2020-05-24 23:49:17 -04:00
|
|
|
ld a, [hWorkingData]
|
2020-05-24 01:54:13 -04:00
|
|
|
ld l, a
|
2020-05-24 23:49:17 -04:00
|
|
|
ld a, [hWorkingData+1]
|
2020-05-24 01:54:13 -04:00
|
|
|
ld h, a
|
|
|
|
; add actor struct offset saved in wWorkingState
|
2020-05-24 23:49:17 -04:00
|
|
|
ld a, [hWorkingState]
|
2020-05-24 01:54:13 -04:00
|
|
|
rlca ; double state offset because of word length
|
|
|
|
add a, l
|
|
|
|
ld l, a
|
|
|
|
adc a, h
|
|
|
|
sub l
|
|
|
|
ld h, a ; hl contains state struct pointer
|
|
|
|
ld a, [hli]
|
|
|
|
ld b, a
|
|
|
|
ld a, [hl]
|
|
|
|
ld l, b
|
|
|
|
ld h, a
|
|
|
|
ld a, [hli] ; a <- state frame limit
|
|
|
|
ld b, a
|
2020-05-24 23:49:17 -04:00
|
|
|
ld a, [hWorkingCounter]
|
2020-05-24 01:54:13 -04:00
|
|
|
inc a
|
|
|
|
ld c, a
|
|
|
|
ld a, b
|
|
|
|
ld b, c
|
|
|
|
cp b
|
|
|
|
ld a, b
|
|
|
|
jr nc, .continueAnimation
|
|
|
|
xor a
|
|
|
|
.continueAnimation
|
|
|
|
; TODO: make counter 0 indexed so doesnt skip first frame
|
2020-05-24 23:49:17 -04:00
|
|
|
ldh [hWorkingCounter], a
|
2020-05-24 01:54:13 -04:00
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
pop hl
|
|
|
|
ld [hl], a
|
|
|
|
ld h, b
|
|
|
|
ld l, c
|
|
|
|
.loopFrameFind
|
|
|
|
ld b, a ; b <- current frame count
|
|
|
|
ld a, [hli] ; a <- next frame block
|
|
|
|
ld c, a
|
|
|
|
ld a, b
|
|
|
|
ld b, c
|
|
|
|
sub b
|
|
|
|
jr z, .foundFrame
|
|
|
|
jr c, .foundFrame
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
jr .loopFrameFind
|
|
|
|
.foundFrame
|
2020-05-08 19:40:26 -04:00
|
|
|
ld a, [hli]
|
2020-05-24 01:54:13 -04:00
|
|
|
ld b, a
|
|
|
|
ld a, [hl]
|
|
|
|
ld h, a
|
|
|
|
ld l, b ; hl <- pointer to frame data
|
2020-05-08 19:40:26 -04:00
|
|
|
ld a, [hli]
|
2020-05-24 01:54:13 -04:00
|
|
|
ld b, a ; b <- sprite counter
|
|
|
|
.spriteLoop
|
|
|
|
; load Y position, then offset by -16
|
2020-05-08 19:40:26 -04:00
|
|
|
ld a, [hli]
|
2020-05-24 01:54:13 -04:00
|
|
|
ld c, a
|
2020-05-24 23:49:17 -04:00
|
|
|
ld a, [hWorkingScreenY]
|
2020-05-24 01:54:13 -04:00
|
|
|
add c
|
|
|
|
ld c, 16
|
|
|
|
add c
|
|
|
|
ld [de], a ; store YPos in shadowOAM
|
|
|
|
inc de
|
|
|
|
; load X position, then offset by -8
|
2020-05-08 19:40:26 -04:00
|
|
|
ld a, [hli]
|
2020-05-24 01:54:13 -04:00
|
|
|
ld c, a
|
2020-05-24 23:49:17 -04:00
|
|
|
ld a, [hWorkingScreenX]
|
2020-05-24 01:54:13 -04:00
|
|
|
add c
|
|
|
|
ld c, 8
|
|
|
|
add c
|
|
|
|
ld [de], a ; store YPos in shadowOAM
|
|
|
|
inc de
|
|
|
|
; load tile offset, and add to base tile pointer
|
|
|
|
ld a, [hli]
|
|
|
|
ld c, a
|
2020-05-24 23:49:17 -04:00
|
|
|
ld a, [hWorkingTile]
|
2020-05-24 01:54:13 -04:00
|
|
|
add c
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
; load attributes and xor them
|
|
|
|
ld a, [hli]
|
|
|
|
ld c, a
|
|
|
|
ld a, 0 ; TO DO: set base attributes
|
|
|
|
xor c
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
; end of single sprite
|
|
|
|
dec b
|
|
|
|
jr nz, .spriteLoop
|
|
|
|
ret
|
|
|
|
|
|
|
|
BUFFER EQU 160
|
|
|
|
TRUE EQU $42
|
|
|
|
FALSE EQU $69
|