Переглянути джерело

cleaned up animation code + fixed frame 0 bug

master
Thorn Avery 4 роки тому
джерело
коміт
88ad5534c3
2 змінених файлів з 59 додано та 71 видалено
  1. +55
    -68
      src/animation.asm
  2. +4
    -3
      src/entry.asm

+ 55
- 68
src/animation.asm Переглянути файл

@@ -7,8 +7,8 @@
bytes 1, XPos bytes 1, XPos
bytes 1, GFXCounter bytes 1, GFXCounter
bytes 1, GFXState bytes 1, GFXState
words 1, GFXData
bytes 1, TileData bytes 1, TileData
words 1, GFXData
end_struct end_struct


SECTION "Actor STructs", WRAM0 SECTION "Actor STructs", WRAM0
@@ -28,7 +28,6 @@ hWorkingState: db
hWorkingCounter: db hWorkingCounter: db
hWorkingData: dw hWorkingData: dw
hWorkingTile: db hWorkingTile: db
hWorkingEnd:


SECTION "Animations Subs", ROM0 SECTION "Animations Subs", ROM0


@@ -47,117 +46,105 @@ SECTION "Animations Subs", ROM0
RenderActor:: RenderActor::
; @input: hl <- Player ; @input: hl <- Player
; @input: de <- ShadowOAM place ; @input: de <- ShadowOAM place
ld a, [hli] ; a <- YPos
; clobbers af, bc, de, hl
ld a, [hli] ; a <- YPos
ldh [hWorkingScreenY], a ldh [hWorkingScreenY], a
ld a, [hli] ; a <- XPos
ld a, [hli] ; a <- XPos
ldh [hWorkingScreenX], a ldh [hWorkingScreenX], a
push hl
ld a, [hli] ; a <- GFXCounter
push hl ; save counter pointer on stack
ld a, [hli] ; a <- GFXCounter
ldh [hWorkingCounter], a ldh [hWorkingCounter], a
ld a, [hli] ; a <- GFXState
ld a, [hli] ; a <- GFXState
ldh [hWorkingState], a ldh [hWorkingState], a
ld a, [hli] ; a <- GFXData(Low)
ldh [hWorkingData+1], a
ld a, [hli] ; a <- GFXData (High)
ldh [hWorkingData], a
ld a, [hl] ; a <- TileData
ld a, [hli] ; a <- TileData
ldh [hWorkingTile], a ldh [hWorkingTile], a
; fin loading data
ld a, [hWorkingData]
ld a, [hli] ; a <- GFXData(Low)
ld h, [hl] ; a <- GFXData (High)
ld l, a ld l, a
ld a, [hWorkingData+1]
ld h, a
; add actor struct offset saved in wWorkingState
ld a, [hWorkingState]
rlca ; double state offset because of word length

ld a, [hWorkingState] ; add actor struct offset saved in wWorkingState
rlca ; double state offset because of word length
add a, l add a, l
ld l, a ld l, a
adc a, h adc a, h
sub l 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
ld h, a ; hl contains state struct pointer

ld a, [hli] ;
ld h, [hl] ; derefence [hl]
ld l, a ;

ld a, [hWorkingCounter] ld a, [hWorkingCounter]
inc a inc a
ld c, a
ld a, b
ld b, c
ld b, a
ld a, [hli] ; a <- state frame limit
cp b cp b
ld a, b ld a, b
jr nc, .continueAnimation jr nc, .continueAnimation
xor a xor a
.continueAnimation .continueAnimation
; TODO: make counter 0 indexed so doesnt skip first frame
ldh [hWorkingCounter], a ldh [hWorkingCounter], a
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
ld b, h ;
ld c, l ; save current hl
pop hl ; restore counter wram pointer
ld [hl], a ;
ld h, b ; restore hl
ld l, c ;
ld c, a ; save current frame in c
xor a ; set a = 0
.loopFrameFind ;
ld b, a ; b <- current total
ld a, [hli] ; a <- next frame tick limit
add b ; add to limit
cp c ; compare to limit
jr nc, .foundFrame ; if no carry, cum total > current frame
inc hl inc hl
inc hl inc hl
jr .loopFrameFind jr .loopFrameFind

.foundFrame .foundFrame
ld a, [hli] ld a, [hli]
ld b, a
ld a, [hl]
ld h, a
ld l, b ; hl <- pointer to frame data
ld h, [hl]
ld l, a ; hl <- pointer to frame data
ld a, [hli] ld a, [hli]
ld b, a ; b <- sprite counter
ld b, a ; b <- sprite counter

.spriteLoop .spriteLoop
; load Y position, then offset by -16
ld a, [hli]
ld a, [hli] ; load Y position, then offset by -16
ld c, a ld c, a
ld a, [hWorkingScreenY] ld a, [hWorkingScreenY]
add c add c
ld c, 16 ld c, 16
add c add c
ld [de], a ; store YPos in shadowOAM
ld [de], a ; store YPos in shadowOAM
inc de inc de
; load X position, then offset by -8
ld a, [hli]
ld a, [hli] ; load X position, then offset by -8
ld c, a ld c, a
ld a, [hWorkingScreenX] ld a, [hWorkingScreenX]
add c add c
ld c, 8 ld c, 8
add c add c
ld [de], a ; store YPos in shadowOAM
ld [de], a ; store XPos in shadowOAM
inc de inc de
; load tile offset, and add to base tile pointer
ld a, [hli]
ld a, [hli] ; load tile offset, and add to base tile pointer
ld c, a ld c, a
ld a, [hWorkingTile] ld a, [hWorkingTile]
add c add c
ld [de], a ld [de], a
inc de inc de
; load attributes and xor them
ld a, [hli]
ld a, [hli] ; load attributes and xor them
ld c, a ld c, a
ld a, 0 ; TO DO: set base attributes
ld a, 0 ; TO DO: set base attributes
xor c xor c
ld [de], a ld [de], a
inc de inc de
; end of single sprite
dec b
dec b ; end of single sprite
jr nz, .spriteLoop jr nz, .spriteLoop
ret ret

BUFFER EQU 160
TRUE EQU $42
FALSE EQU $69

+ 4
- 3
src/entry.asm Переглянути файл

@@ -33,14 +33,15 @@ Start:
ld [Player_YPos], a ld [Player_YPos], a
ld a, 80 ld a, 80
ld [Player_XPos], a ld [Player_XPos], a
xor a
ld a, $FF
ld [Player_GFXCounter], a ld [Player_GFXCounter], a
xor a
ld [Player_GFXState], a ld [Player_GFXState], a
ld [Player_TileData], a ld [Player_TileData], a
ld a, HIGH(ActorROM) ld a, HIGH(ActorROM)
ld [Player_GFXData], a
ld [Player_GFXData+1], a
ld a, LOW(ActorROM) ld a, LOW(ActorROM)
ld [Player_GFXData + 1], a
ld [Player_GFXData], a


ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON
ld [rLCDC], a ld [rLCDC], a


Завантаження…
Відмінити
Зберегти