working animation, but ugly

This commit is contained in:
tA 2020-05-24 17:54:13 +12:00
parent f3fd560eae
commit aa5b06312e
12 changed files with 547 additions and 225 deletions

Binary file not shown.

Binary file not shown.

View file

@ -2,23 +2,15 @@
; Actor Animation
;-----------------
SECTION "Actor Variables Struct", WRAM, ALIGN[8]
wWorldX: dw
wWorldY: dw
wActorState: db
wActorCounter: db
wActorData: dw
wActorTile: dw
SECTION "Actor", ROM0
Actor::
ActorROM::
.structs:
dw ActorIdle
.tiles:
ActorIdle::
db 60
db 15
dw .framePa
db 15
dw .frameRe

View file

@ -2,20 +2,33 @@
; Animation Subs
;----------------
SECTION "Animation Variables", HRAM
struct Actor
bytes 1, YPos
bytes 1, XPos
bytes 1, GFXCounter
bytes 1, GFXState
words 1, GFXData
bytes 1, TileData
end_struct
hCameraX: dw
hCameraY: dw
SECTION "Actor STructs", WRAM0
hWorkingX: dw
hWorkingY: dw
hWorkingScreenX: db
hWorkingScreenY: db
hWorkingState: db
hWorkingCounter: db
hWorkingData: dw
hWorkingTile: dw
hWorkingEnd:
dstruct Actor, Player
SECTION "Animation Variables", WRAM0
wCameraX: dw
wCameraY: dw
wWorkingX: dw
wWorkingY: dw
wWorkingScreenX: db
wWorkingScreenY: db
wWorkingState: db
wWorkingCounter: db
wWorkingData: dw
wWorkingTile: db
wWorkingEnd:
SECTION "Animations Subs", ROM0
@ -32,28 +45,119 @@ SECTION "Animations Subs", ROM0
; copied to shadowOAM (wShadowOAM)
RenderActor::
; load world X and Y to temp RAM
; @input: hl <- Player
; @input: de <- ShadowOAM place
ld a, [hli] ; a <- YPos
ld [wWorkingScreenY], a
ld a, [hli] ; a <- XPos
ld [wWorkingScreenX], a
push hl
ld a, [hli] ; a <- GFXCounter
ld [wWorkingCounter], a
ld a, [hli] ; a <- GFXState
ld [wWorkingState], a
ld a, [hli] ; a <- GFXData(Low)
ld [wWorkingData+1], a
ld a, [hli] ; a <- GFXData (High)
ld [wWorkingData], a
ld a, [hl] ; a <- TileData
ld [wWorkingTile], a
; fin loading data
ld a, [wWorkingData]
ld l, a
ld a, [wWorkingData+1]
ld h, a
; add actor struct offset saved in wWorkingState
ld a, [wWorkingState]
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 [hWorkingX], a
ld a, [hli]
ld [hWorkingX+1], a
ld a, [hli]
ld [hWorkingY], a
ld a, [hli]
ld [hWorkingY+1], a
; done loading X and Y
; figure out if within 256 of camera
; ---------
; first compare upper byte of XXYY
; if this is more than 1 away, break
ld a, [hCameraX]
ld b, a
ld a, [hWorkingX]
; b = camera byte
; a = actor byte
; work out if actor minus camera is <= 1
sub b
; ---------
ld a, [hl]
ld l, b
ld h, a
ld a, [hli] ; a <- state frame limit
ld b, a
ld a, [wWorkingCounter]
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
ld [wWorkingCounter], 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
inc hl
inc hl
jr .loopFrameFind
.foundFrame
ld a, [hli]
ld b, a
ld a, [hl]
ld h, a
ld l, b ; hl <- pointer to frame data
ld a, [hli]
ld b, a ; b <- sprite counter
.spriteLoop
; load Y position, then offset by -16
ld a, [hli]
ld c, a
ld a, [wWorkingScreenY]
add c
ld c, 16
add c
ld [de], a ; store YPos in shadowOAM
inc de
; load X position, then offset by -8
ld a, [hli]
ld c, a
ld a, [wWorkingScreenX]
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
ld a, [wWorkingTile]
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
.skipRendering
BUFFER EQU 160
TRUE EQU $42
FALSE EQU $69

View file

@ -57,3 +57,4 @@ hOAMDMA:
SECTION "Shadow OAM", WRAM0,ALIGN[8]
wShadowOAM::
ds 4*40
wShadowOAMEnd::

View file

@ -2,9 +2,7 @@
; Program Start
;----------------
BUFFER EQU 160
TRUE EQU $42
FALSE EQU $69
INCLUDE "src/actor.asm"
SECTION "Program Start", ROM0[$150]
Start:
@ -17,6 +15,7 @@ Start:
xor a
ldh [rLCDC], a
call Clear_Map
call Clear_OAM
call Load_Tiles
; call Load_Map
ld a, %11100100
@ -32,129 +31,26 @@ Start:
call CopyDMARoutine
ld a, 72
ld [rPlayerX], a
ld a, 88
ld [rPlayerY], a
;----
; Testing
;----
ld a, HIGH(ANS)
ld h, a
ld a, LOW(ANS)
ld l, a
; Case One: Camera@E100 vs Actor@E195 (Pass)
ld a, $E1
ld [N], a
ld a, $E1
ld [X], a
ld a, $00
ld [N+1], a
ld a, $95
ld [X+1], a
call CheckBoundry
; Case One: Camera@E095 vs Actor@E120 (Pass)
ld a, $E0
ld [N], a
ld a, $E1
ld [X], a
ld a, $95
ld [N+1], a
ld a, $20
ld [X+1], a
call CheckBoundry
; Case One: Camera@E100 vs Actor@E1FF (Fail)
ld a, $E1
ld [N], a
ld a, $E1
ld [X], a
ld a, $00
ld [N+1], a
ld a, $FF
ld [X+1], a
call CheckBoundry
; Case One: Camera@E1F0 vs Actor@E2DE (Fail)
ld a, $E1
ld [N], a
ld a, $E2
ld [X], a
ld a, $F0
ld [N+1], a
ld a, $DE
ld [X+1], a
call CheckBoundry
ld [Player_YPos], a
ld a, 80
ld [Player_XPos], a
xor a
ld [Player_GFXCounter], a
ld [Player_GFXState], a
ld [Player_TileData], a
ld a, HIGH(ActorROM)
ld [Player_GFXData], a
ld a, LOW(ActorROM)
ld [Player_GFXData + 1], a
game_loop:
call Wait_VBlank
call Read_Pad
call PC_Update
call Player_To_OAM
call Clear_OAM
ld de, wShadowOAM
ld hl, Player
call RenderActor
ld a, HIGH(wShadowOAM)
call hOAMDMA
jr game_loop
CheckBoundry::
;-----
; Check if word X is within BUFFER ahead of N
; BUFFER is always <= 255
; hl contains address to save result to
;-----
;= load high bytes
ld a, [N]
ld b, a
ld a, [X]
sub b
;= if carry is set, N is behind X, so skip
jr c, .skipRender
ld b, a
ld a, 2
cp b
;= if the difference is 2 or greater
;= we are not within BUFFER, so skip
jr c, .skipRender
jr z, .skipRender
dec a
cp b
;= if the high byte differ by 1, we
;= need to check over a a page
jr z, .swap
;= load the low bytes
ld a, [N+1]
ld b, a
ld a, [X+1]
sub b
ld b, a
ld a, BUFFER
cp b
;= if the difference is greater than
;= the buffer, skip
jr c, .skipRender
jr .render
.swap
;= load the low bytes in the opposite order
ld a, [X+1]
ld b, a
ld a, [N+1]
sub b
ld b, a
ld a, $FF - BUFFER
cp b
;= if they differ by the inverse of the buffer
;= they will not be within the gap between pages
jr nc, .skipRender
.render
;= success, do rendering stuff
; beep boop rendering stuff
ld a, TRUE
ld [hli], a
ret
.skipRender
;= failure, skip this one
; doing other stuff here
ld a, FALSE
ld [hli], a
ret

View file

@ -1,7 +1,9 @@
INCLUDE "inc/hardware.inc"
INCLUDE "inc/structs.asm"
INCLUDE "ass/parecivo.ass"
INCLUDE "ass/tiles.ass"
INCLUDE "ass/map.ass"
INCLUDE "src/animation.asm"
INCLUDE "src/entry.asm"
INCLUDE "src/header.asm"
INCLUDE "src/defines.asm"

View file

@ -134,16 +134,28 @@ PC_Update:
ret
Clear_Map:
xor a
ld hl, _SCRN0
ld bc, _SCRN0_END - _SCRN0
Clear_OAM:
ld hl, wShadowOAM
ld bc, wShadowOAMEnd - wShadowOAM
.loop:
xor a
ld [hli], a
dec bc
ld a, b
or c
jr z, .loop
jr nz, .loop
ret
Clear_Map:
ld hl, _SCRN0
ld bc, _SCRN0_END - _SCRN0
.loop:
xor a
ld [hli], a
dec bc
ld a, b
or c
jr nz, .loop
ret
Load_Tiles: