Hi all,
so everything was working fine with my project until I decided to use some RAM for a collision map (basically an array to hold a 0 for empty space, 1 for occupied space).
After creating the collision map I lose my picture, however the debugger shows my nametable is all there and looks fine on the PPU.
First question is, is there a common denominator to help debug through when the screen is black but the nametable looks fine?
Second question is, does anything in the code stand out as obvious? By the way, prior to updating the nametable I wait for vblank, turn off rendering, write to the PPU, then try to update my collision map. I wait for vblank again, then turn rendering back on.
Full disclosure on this next bit, originally I added the collision update logic in my nametable loader code but this was also giving me a black screen, so to test I broke it out into its own subroutine but I'm getting the same result. And I know this loop will read an extra 64 bytes from the attribute table but I planned on making this work first (I can save the 64 bytes after this works). What is very weird is, if I remove the STA command under the solid_tile label then my picture comes back..
so everything was working fine with my project until I decided to use some RAM for a collision map (basically an array to hold a 0 for empty space, 1 for occupied space).
After creating the collision map I lose my picture, however the debugger shows my nametable is all there and looks fine on the PPU.
First question is, is there a common denominator to help debug through when the screen is black but the nametable looks fine?
Second question is, does anything in the code stand out as obvious? By the way, prior to updating the nametable I wait for vblank, turn off rendering, write to the PPU, then try to update my collision map. I wait for vblank again, then turn rendering back on.
Code:
nt_collision_ptr .rs 2 ; pointer to nametable collision map
Code:
Reset_nt_collision_ptr:
; set collision pointer to page 2 in RAM
LDA #$00 ; low byte
STA nt_collision_ptr
LDA #$01 ; high byte
STA nt_collision_ptr + 1
;done, $0100
RTS
; set collision pointer to page 2 in RAM
LDA #$00 ; low byte
STA nt_collision_ptr
LDA #$01 ; high byte
STA nt_collision_ptr + 1
;done, $0100
RTS
Full disclosure on this next bit, originally I added the collision update logic in my nametable loader code but this was also giving me a black screen, so to test I broke it out into its own subroutine but I'm getting the same result. And I know this loop will read an extra 64 bytes from the attribute table but I planned on making this work first (I can save the 64 bytes after this works). What is very weird is, if I remove the STA command under the solid_tile label then my picture comes back..
Code:
Update_collision_map:
JSR Reset_nt_collision_ptr
LDX #$00
LDY #$00
update_collision_loop:
LDA [nametable_ptr], y
CMP #TILE_CLEAR
BNE solid_tile
; empty space
LDA #$00
STA [nt_collision_ptr], y
JMP resume_collision_load
solid_tile:
LDA #$01
STA [nt_collision_ptr], y
resume_collision_load:
INY
CPY #$00 ; wrap around = 256 tiles
BNE update_collision_loop
; see if next set needs to be processed
INC nt_collision_ptr + 1
LDY #$00
INX
CPX #$04
BNE update_collision_loop
RTS
JSR Reset_nt_collision_ptr
LDX #$00
LDY #$00
update_collision_loop:
LDA [nametable_ptr], y
CMP #TILE_CLEAR
BNE solid_tile
; empty space
LDA #$00
STA [nt_collision_ptr], y
JMP resume_collision_load
solid_tile:
LDA #$01
STA [nt_collision_ptr], y
resume_collision_load:
INY
CPY #$00 ; wrap around = 256 tiles
BNE update_collision_loop
; see if next set needs to be processed
INC nt_collision_ptr + 1
LDY #$00
INX
CPX #$04
BNE update_collision_loop
RTS