fixed scanline bug + removed old code

This commit is contained in:
Thorn Avery 2020-05-25 15:49:17 +12:00
parent 9f2ddc6621
commit c4ccba52d2
6 changed files with 47 additions and 142 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
build build
*.swp *.swp
*.swo

View File

@ -7,7 +7,6 @@ SECTION "Actor", ROM0
ActorROM:: ActorROM::
.structs: .structs:
dw ActorIdle dw ActorIdle
.tiles:
ActorIdle:: ActorIdle::
db 60 db 60
db 15 db 15

View File

@ -15,20 +15,20 @@ SECTION "Actor STructs", WRAM0
dstruct Actor, Player dstruct Actor, Player
SECTION "Animation Variables", WRAM0 SECTION "Animation Variables", HRAM
wCameraX: dw hCameraX: dw
wCameraY: dw hCameraY: dw
wWorkingX: dw hWorkingX: dw
wWorkingY: dw hWorkingY: dw
wWorkingScreenX: db hWorkingScreenX: db
wWorkingScreenY: db hWorkingScreenY: db
wWorkingState: db hWorkingState: db
wWorkingCounter: db hWorkingCounter: db
wWorkingData: dw hWorkingData: dw
wWorkingTile: db hWorkingTile: db
wWorkingEnd: hWorkingEnd:
SECTION "Animations Subs", ROM0 SECTION "Animations Subs", ROM0
@ -48,27 +48,27 @@ RenderActor::
; @input: hl <- Player ; @input: hl <- Player
; @input: de <- ShadowOAM place ; @input: de <- ShadowOAM place
ld a, [hli] ; a <- YPos ld a, [hli] ; a <- YPos
ld [wWorkingScreenY], a ldh [hWorkingScreenY], a
ld a, [hli] ; a <- XPos ld a, [hli] ; a <- XPos
ld [wWorkingScreenX], a ldh [hWorkingScreenX], a
push hl push hl
ld a, [hli] ; a <- GFXCounter ld a, [hli] ; a <- GFXCounter
ld [wWorkingCounter], a ldh [hWorkingCounter], a
ld a, [hli] ; a <- GFXState ld a, [hli] ; a <- GFXState
ld [wWorkingState], a ldh [hWorkingState], a
ld a, [hli] ; a <- GFXData(Low) ld a, [hli] ; a <- GFXData(Low)
ld [wWorkingData+1], a ldh [hWorkingData+1], a
ld a, [hli] ; a <- GFXData (High) ld a, [hli] ; a <- GFXData (High)
ld [wWorkingData], a ldh [hWorkingData], a
ld a, [hl] ; a <- TileData ld a, [hl] ; a <- TileData
ld [wWorkingTile], a ldh [hWorkingTile], a
; fin loading data ; fin loading data
ld a, [wWorkingData] ld a, [hWorkingData]
ld l, a ld l, a
ld a, [wWorkingData+1] ld a, [hWorkingData+1]
ld h, a ld h, a
; add actor struct offset saved in wWorkingState ; add actor struct offset saved in wWorkingState
ld a, [wWorkingState] ld a, [hWorkingState]
rlca ; double state offset because of word length rlca ; double state offset because of word length
add a, l add a, l
ld l, a ld l, a
@ -82,7 +82,7 @@ RenderActor::
ld h, a ld h, a
ld a, [hli] ; a <- state frame limit ld a, [hli] ; a <- state frame limit
ld b, a ld b, a
ld a, [wWorkingCounter] ld a, [hWorkingCounter]
inc a inc a
ld c, a ld c, a
ld a, b ld a, b
@ -93,7 +93,7 @@ RenderActor::
xor a xor a
.continueAnimation .continueAnimation
; TODO: make counter 0 indexed so doesnt skip first frame ; TODO: make counter 0 indexed so doesnt skip first frame
ld [wWorkingCounter], a ldh [hWorkingCounter], a
ld b, h ld b, h
ld c, l ld c, l
pop hl pop hl
@ -124,7 +124,7 @@ RenderActor::
; load Y position, then offset by -16 ; load Y position, then offset by -16
ld a, [hli] ld a, [hli]
ld c, a ld c, a
ld a, [wWorkingScreenY] ld a, [hWorkingScreenY]
add c add c
ld c, 16 ld c, 16
add c add c
@ -133,7 +133,7 @@ RenderActor::
; load X position, then offset by -8 ; load X position, then offset by -8
ld a, [hli] ld a, [hli]
ld c, a ld c, a
ld a, [wWorkingScreenX] ld a, [hWorkingScreenX]
add c add c
ld c, 8 ld c, 8
add c add c
@ -142,7 +142,7 @@ RenderActor::
; load tile offset, and add to base tile pointer ; load tile offset, and add to base tile pointer
ld a, [hli] ld a, [hli]
ld c, a ld c, a
ld a, [wWorkingTile] ld a, [hWorkingTile]
add c add c
ld [de], a ld [de], a
inc de inc de

View File

@ -12,19 +12,8 @@ P1F_DPAD EQU $20
SECTION "ROM Vars", ROM0 SECTION "ROM Vars", ROM0
dPlayerWidth: db 2
dPlayerHeight: db 2
dPlayerSpriteTiles: db $01, $02, $09, $0A
SECTION "WRAM Vars", WRAM0[$C000] SECTION "WRAM Vars", WRAM0[$C000]
X: dw
N: dw
ANS: db
rPlayerX: db
rPlayerY: db
SECTION "HRAM Vars", HRAM SECTION "HRAM Vars", HRAM
hVBlankFlag: db hVBlankFlag: db

View File

@ -25,8 +25,6 @@ Start:
ld [rSCY], a ld [rSCY], a
ld [rSCX], a ld [rSCX], a
ld [rNR52], a ld [rNR52], a
ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON
ld [rLCDC], a
call CopyDMARoutine call CopyDMARoutine
@ -43,11 +41,14 @@ Start:
ld a, LOW(ActorROM) ld a, LOW(ActorROM)
ld [Player_GFXData + 1], a ld [Player_GFXData + 1], a
ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON
ld [rLCDC], a
game_loop: game_loop:
call Wait_VBlank call Hide_OAM
call Read_Pad call Read_Pad
call PC_Update call PC_Update
call Clear_OAM call Wait_VBlank
ld de, wShadowOAM ld de, wShadowOAM
ld hl, Player ld hl, Player
call RenderActor call RenderActor

View File

@ -1,102 +1,3 @@
Player_To_OAM:
; -- first loop --
ld hl, wShadowOAM
ld a, [dPlayerHeight]
ld b, a
ld d, 16
ld a, [rPlayerY]
add d ; d has the base Y value (counting offsets)
ld d, a
.fouter
ld a, [dPlayerWidth]
ld c, a ; c is finner counter
.finner
ld a, d
ld [hl], a
ld a, 4
call .add4hl
; end of finner loop
dec c
jr nz, .finner
ld a, d
ld d, 8
add d
ld d, a
; end of fouter loop
dec b
jr nz, .fouter
; -- second loop --
ld hl, wShadowOAM+1
ld a, [dPlayerHeight]
ld b, a
.souter
ld d, 8
ld a, [rPlayerX]
add d
ld d, a
ld a, [dPlayerWidth]
ld c, a
.sinner
ld a, d
ld [hl], a
add 8
ld d, a
ld a, 4
call .add4hl
dec c
jr nz, .sinner
dec b
jr nz, .souter
; -- third loop --
ld hl, wShadowOAM+2
ld de, dPlayerSpriteTiles
ld a, [dPlayerHeight]
ld b, a
ld a, [dPlayerWidth]
ld c, a
xor a
.tloop1
add b
dec c
jr nz, .tloop1
ld c, a
.tloop2
ld a, [de]
ld [hl], a
ld a, 4
call .add4hl
inc de
dec c
jr nz, .tloop2
; -- fourth loop --
ld hl, wShadowOAM+3
ld a, [dPlayerHeight]
ld b, a
ld a, [dPlayerWidth]
ld c, a
xor a
.lloop1
add b
dec c
jr nz, .lloop1
ld c, a
.lloop2
xor a
ld [hl], a
ld a, 4
call .add4hl
dec c
jr nz, .lloop2
ret
.add4hl:
add a, l ; a = low + old_l
ld l, a ; a = low + old_l = new_l
adc a, h ; a = new_l + old_h + carry
sub l ; a = old_h + carry
ld h, a
ret
PC_Update: PC_Update:
ld b, 0 ld b, 0
ld c, 0 ld c, 0
@ -146,6 +47,20 @@ Clear_OAM:
jr nz, .loop jr nz, .loop
ret ret
Hide_OAM:
ld hl, wShadowOAM
ld c, wShadowOAMEnd - wShadowOAM
.loop:
xor a
ld [hl], a
ld a, l
or 3
inc a
ld l, a
dec c
jr nz, .loop
ret
Clear_Map: Clear_Map:
ld hl, _SCRN0 ld hl, _SCRN0
ld bc, _SCRN0_END - _SCRN0 ld bc, _SCRN0_END - _SCRN0