Quantcast
Channel: nesdev.org
Viewing all articles
Browse latest Browse all 746

scrolling problem

$
0
0
Can someone help me determine why the scroll position is affected sometime by this routine?

I know about the t register, but im not sure i managed to not affect it . Im almost sure the problem is because of that routine, try yourself, when you loose hearts, sometime the scroll position move, trying to fix that. If I dont use the routine, the scroll is okay.

Code:

INITIALISE_HEARTS_P1:LDA #$0A           ; Load immediate value 0A (10 in decimal)    STA heart_counter_P1 ; Store the value 0A into heart_counter_P1RTS; Return from subroutineLOOSE_ONE_HEART_P1:LDA heart_counter_P1    SEC                       ; Set the carry flag to prepare for subtraction    SBC #$01                  ; Subtract 1 from the value in the accumulator    STA heart_counter_P1      ; Store the decremented value back to heart_counter_P1JSR HEARTS_TILES_LOGIC_P1RTSRESET_HEART_TILES_P1:LDA PPU_VRAM_ADDR      ; Load current value of PPU_VRAM_ADDR    AND #%11000000         ; Clear the lower 6 bits, preserving upper XX    ORA #%00100000         ; Set the lower bits to 100000    STA PPU_VRAM_ADDR      ; Write back to PPU_VRAM_ADDR    LDA #$60    STA PPU_VRAM_ADDR  ; Write low byte to PPU address registerLDX #$00RESETTILES_HEARTS_P1:    LDA #$00                 ; Tile ID to write (change this to the desired tile ID)    STA PPU_VRAM_DATA           ; Write tile ID to PPU data register    INX                       ; Increment X to track tile writes    CPX #$0A      ; Compare x with total hearts (10)    BNE RESETTILES_HEARTS_P1  ; If X < heart_counter_P1, continue writing tilesRTSHEARTS_TILES_LOGIC_P1:JSR RESET_HEART_TILES_P1    LDA PPU_VRAM_ADDR      ; Load current value of PPU_VRAM_ADDR    AND #%11000000         ; Clear the lower 6 bits, preserving upper 2 bits (bits 6 and 7)    ORA #%00100000         ; Set bit 5 (the sixth bit), while keeping the upper 2 bits intact    STA PPU_VRAM_ADDR      ; Write the modified value back to PPU_VRAM_ADDR    LDA #$60       STA PPU_VRAM_ADDR        ; Write low byte to PPU address register    ; Check if heart_counter_P1 == 0    LDA heart_counter_P1      ; Load the current value of heart_counter_P1    BEQ HEART_COUNTER_ZERO_P1 ; If heart_counter_P1 is 0, branch to reset    ; Loop to write tiles based on heart_counter_P1    LDX #$00        ; Initialize X to 0 for tile write loopWRITETILES_HEARTS_P1:    LDA #$31                  ; Tile ID to write (change this to the desired tile ID)    STA PPU_VRAM_DATA           ; Write tile ID to PPU data register    INX                       ; Increment X to track tile writes    CPX heart_counter_P1      ; Compare X with heart_counter_P1 (number of hearts)    BNE WRITETILES_HEARTS_P1  ; If X < heart_counter_P1, continue writing tiles    RTS                       ; Return from subroutineHEART_COUNTER_ZERO_P1:    JSR INITIALISE_HEARTS_P1  ; Call to reset heart_counter_p2 to 10 if it reached 0JSR HEARTS_TILES_LOGIC_P1    RTS                       ; Return from subroutineHEARTS_CHECK:    ; Check if call_ennemy1hp == 1 OR hit_bullet == 1    LDA call_ennemy1hp  ; Load call_ennemy1hp into A    ORA hit_bullet      ; Perform logical OR with hit_bullet    BEQ NO_LOOSE_HEART  ; If both are 0, skip the heart losing routine    ; If either call_ennemy1hp == 1 or hit_bullet == 1, call LOOSE_ONE_HEART_P1    JSR LOOSE_ONE_HEART_P1    ; Set both flags to 0 (call_ennemy1hp = 0, hit_bullet = 0)    LDA #$00            ; Load 0 into A    STA call_ennemy1hp  ; Store 0 into call_ennemy1hp    STA hit_bullet      ; Store 0 into hit_bulletNO_LOOSE_HEART:    RTS
cart.nes

Statistics: Posted by v.depatie — Thu Jan 16, 2025 7:05 pm — Replies 5 — Views 163



Viewing all articles
Browse latest Browse all 746

Trending Articles