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"?>
<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"/>
<layer id="1" name="Tile Layer 1" width="256" height="30">
<data encoding="csv">

View File

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

View File

@ -118,13 +118,13 @@ NO_MUSIC equ 1 ; turn music + tool loading
jsr BlitInit ; Initialize the memory
jsr GrafInit ; Initialize the graphics screen
ldx #6 ; Gameboy Advance size
ldx #0 ; Gameboy Advance size
jsr SetScreenMode
lda #0 ; Set the virtual Y-position
jsr SetBG0YPos
lda #15 ; Set the virtual X-position
lda #0 ; Set the virtual X-position
jsr SetBG0XPos
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
sta BankLoad ; Store "Bank Pointer"
ldx #0
jsr SetScreenMode
jsr MovePlayerToOrigin
jsr MovePlayerToOrigin ; Put the player at the beginning of the map
lda #$FFFF ; Force a redraw of all the tiles
jsr _UpdateBG0TileMap
; jsr DoTiles
; 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.
jsr _ApplyBG0XPosPre
lda #$FFFF ; Force a tile refresh
jsr _UpdateBG0TileMap
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
; 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
lda :Bottom
sec
sbc :Top
inc
sta :Height
sta :Height ; Maximum value of 25
lda :Right
sec
sbc :Left
inc
sta :Width
sta :Width ; Maximum value of 40
; Compute the offset into the tile array of the top-left corner
@ -298,7 +302,7 @@ _UpdateBG0TileMap
lda :BlkX
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
lda #0
sta :BlkX
@ -319,7 +323,7 @@ _UpdateBG0TileMap
lda :BlkY ; The y lookup has a double0length array, may not need the bounds check
inc
cmp #27
cmp #MAX_TILE_Y+1
bcc *+5
lda #0
sta :BlkY
@ -377,6 +381,22 @@ _UpdateBG0TileMap