diff --git a/assets/tiled/world_1-1.tmx b/assets/tiled/world_1-1.tmx index ec03eae..9b57fec 100644 --- a/assets/tiled/world_1-1.tmx +++ b/assets/tiled/world_1-1.tmx @@ -1,5 +1,8 @@ + + + diff --git a/src/Actions.s b/src/Actions.s index ec1f4e7..0927da3 100644 --- a/src/Actions.s +++ b/src/Actions.s @@ -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 + + + diff --git a/src/App.Main.s b/src/App.Main.s index 2a78e5b..bb3f24e 100644 --- a/src/App.Main.s +++ b/src/App.Main.s @@ -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 + + + + + + + + + diff --git a/src/Render.s b/src/Render.s index d22b92b..4cec3a3 100644 --- a/src/Render.s +++ b/src/Render.s @@ -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 + diff --git a/src/TileMap.s b/src/TileMap.s index b3744d9..b7a0d7c 100644 --- a/src/TileMap.s +++ b/src/TileMap.s @@ -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 + + + + + + + + + + + + + + + +