Fix full-screen tile refreshes; incremental tile drawing crashes

This commit is contained in:
Lucas Scharenbroich 2021-08-09 06:08:09 -05:00
parent 8d34da6c26
commit d3b21a91b9
5 changed files with 62 additions and 16 deletions

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="256" height="30" tilewidth="8" tileheight="8" infinite="0" nextlayerid="3" nextobjectid="2"> <map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="256" height="30" tilewidth="8" tileheight="8" infinite="0" nextlayerid="3" nextobjectid="2">
<editorsettings>
<export target="world_1-1.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="Overworld.tsx"/> <tileset firstgid="1" source="Overworld.tsx"/>
<layer id="1" name="Tile Layer 1" width="256" height="30"> <layer id="1" name="Tile Layer 1" width="256" height="30">
<data encoding="csv"> <data encoding="csv">

View File

@ -30,11 +30,21 @@ MoveRight
MoveUp MoveUp
clc clc
adc StartY ; Increment the virtual Y-position adc StartY ; Increment the virtual Y-position
jsr SetBG0YPos pha
lda StartY lda #240 ; virtual play field height
lsr sec
jsr SetBG1YPos sbc ScreenHeight
tax
cmp 1,s
bcc *+4
lda 1,s
jsr SetBG0YPos
pla
; lda StartY
; lsr
; jsr SetBG1YPos
jsr DoFrame jsr DoFrame
rts rts
@ -276,3 +286,6 @@ _DoTimers
pla pla
rts rts

View File

@ -118,13 +118,13 @@ NO_MUSIC equ 1 ; turn music + tool loading
jsr BlitInit ; Initialize the memory jsr BlitInit ; Initialize the memory
jsr GrafInit ; Initialize the graphics screen jsr GrafInit ; Initialize the graphics screen
ldx #6 ; Gameboy Advance size ldx #0 ; Gameboy Advance size
jsr SetScreenMode jsr SetScreenMode
lda #0 ; Set the virtual Y-position lda #0 ; Set the virtual Y-position
jsr SetBG0YPos jsr SetBG0YPos
lda #15 ; Set the virtual X-position lda #0 ; Set the virtual X-position
jsr SetBG0XPos jsr SetBG0XPos
jsr _InitBG1 ; Initialize the second background jsr _InitBG1 ; Initialize the second background
@ -140,9 +140,10 @@ NO_MUSIC equ 1 ; turn music + tool loading
jsr AllocOneBank2 ; Alloc 64KB for Load/Unpack jsr AllocOneBank2 ; Alloc 64KB for Load/Unpack
sta BankLoad ; Store "Bank Pointer" sta BankLoad ; Store "Bank Pointer"
ldx #0 jsr MovePlayerToOrigin ; Put the player at the beginning of the map
jsr SetScreenMode lda #$FFFF ; Force a redraw of all the tiles
jsr MovePlayerToOrigin jsr _UpdateBG0TileMap
; jsr DoTiles ; jsr DoTiles
; jsr DoLoadBG1 ; jsr DoLoadBG1
@ -1292,6 +1293,15 @@ qtRec adrl $0000

View File

@ -70,7 +70,6 @@ Render
; finally patch out the code field. Right now, the BRA operand is getting overwritten by tile data. ; finally patch out the code field. Right now, the BRA operand is getting overwritten by tile data.
jsr _ApplyBG0XPosPre jsr _ApplyBG0XPosPre
lda #$FFFF ; Force a tile refresh
jsr _UpdateBG0TileMap jsr _UpdateBG0TileMap
jsr _ApplyBG0XPos ; Patch the PEA instructions with exit BRA opcode jsr _ApplyBG0XPos ; Patch the PEA instructions with exit BRA opcode
@ -112,3 +111,4 @@ Render

View File

@ -215,19 +215,23 @@ _UpdateBG0TileMap
; This is a private subroutine that draws in tiles into the code fields using the ; This is a private subroutine that draws in tiles into the code fields using the
; data from the tilemap and the local :Top, :Left, :Bottom and :Right parameters. ; data from the tilemap and the local :Top, :Left, :Bottom and :Right parameters.
;
; The ranges are [:Left, :Right) and [:Top, :Bottom), so :Right can be, at most, 41
; if we are drawing all 41 tiles (Index 0 through 40). The :Bottom value can be
; at most 26.
MAX_TILE_X equ 40
MAX_TILE_Y equ 25
:DrawRectBG0 :DrawRectBG0
lda :Bottom lda :Bottom
sec sec
sbc :Top sbc :Top
inc sta :Height ; Maximum value of 25
sta :Height
lda :Right lda :Right
sec sec
sbc :Left sbc :Left
inc sta :Width ; Maximum value of 40
sta :Width
; Compute the offset into the tile array of the top-left corner ; Compute the offset into the tile array of the top-left corner
@ -298,7 +302,7 @@ _UpdateBG0TileMap
lda :BlkX lda :BlkX
inc inc
cmp #42 ; If we go past the physical block index, wrap around cmp #MAX_TILE_X+1 ; If we go past the physical block index, wrap around
bcc *+5 bcc *+5
lda #0 lda #0
sta :BlkX sta :BlkX
@ -319,7 +323,7 @@ _UpdateBG0TileMap
lda :BlkY ; The y lookup has a double0length array, may not need the bounds check lda :BlkY ; The y lookup has a double0length array, may not need the bounds check
inc inc
cmp #27 cmp #MAX_TILE_Y+1
bcc *+5 bcc *+5
lda #0 lda #0
sta :BlkY sta :BlkY
@ -377,6 +381,22 @@ _UpdateBG0TileMap