Now using the sprite 0 trick to not scroll the status bar !
fixed a bug where spamming the sword attack and jumping would sometime freeze the sword sprite mid frame. spamming is now almost perfect !
Now since the background is always moving ( the green part to, and some of the orange part ), when I loose a heart, I modify the background data therefore frezzing and messing the memory.
Will work on that tonight !:
HEART_ROUTINES.s
INITIALISE_HEARTS_P1:
LDA #$0A ; Load immediate value 0A (10 in decimal)
STA heart_counter_P1 ; Store the value 0A into heart_counter_P1
RTS; Return from subroutine
LOOSE_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_P1
JSR HEARTS_TILES_LOGIC_P1
RTS
RESET_HEART_TILES_P1:
; Set PPU address to the correct position based on heart_counter_P1
LDA #$20 ; High byte of PPU address (e.g., $2000)
STA PPU_VRAM_ADDR2 ; Write high byte to PPU address register
LDA #$60
STA PPU_VRAM_ADDR2 ; Write low byte to PPU address register
LDX #$00
RESETTILES_HEARTS_P1:
LDA #$A7 ; Tile ID to write (change this to the desired tile ID)
STA PPU_VRAM_IO ; 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 tiles
RTS
HEARTS_TILES_LOGIC_P1:
JSR RESET_HEART_TILES_P1
; Set PPU address to the correct position based on heart_counter_P1
LDA #$20 ; High byte of PPU address (e.g., $2000)
STA PPU_VRAM_ADDR2 ; Write high byte to PPU address register
LDA #$60
STA PPU_VRAM_ADDR2 ; 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 loop
WRITETILES_HEARTS_P1:
LDA #$FF ; Tile ID to write (change this to the desired tile ID)
STA PPU_VRAM_IO ; 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
; Reset scroll and PPU control settings
LDA #$00
STA PPU_VRAM_ADDR2
STA PPU_VRAM_ADDR2
RTS ; Return from subroutine
HEART_COUNTER_ZERO_P1:
JSR INITIALISE_HEARTS_P1 ; Call to reset heart_counter_p2 to 10 if it reached 0
JSR HEARTS_TILES_LOGIC_P1
LDA #$00
STA PPU_VRAM_ADDR2
STA PPU_VRAM_ADDR2
RTS ; Return from subroutine
thats my current HEarts routines for player one. It messing with my scrolling code, any ideas ?
thats my scrolling code that I called every nmi, for now.:
OFFSET_BACKGROUND_VERTICAL2:
LDA #$00
STA $2003 ; Set sprite memory address to 0
LDA #$02
STA $4014 ; Sprite DMA from $0200
;; Clear PPU address registers
LDA #$00
STA $2006
STA $2006
;; Set initial scroll to 0 for the static status bar
LDA #$00
STA $2005 ; Horizontal scroll
STA $2005 ; Vertical scroll
;; Wait for Sprite 0 hit to clear (from the previous frame)
WaitNotSprite0:
LDA $2002 ; Read PPU status register
AND #%01000000 ; Check sprite 0 hit flag (bit 6)
BNE WaitNotSprite0 ; Wait until sprite 0 hit flag is cleared
;; Wait for Sprite 0 to be hit
WaitSprite0:
LDA $2002 ; Read PPU status register
AND #%01000000 ; Check sprite 0 hit flag (bit 6)
BEQ WaitSprite0 ; Wait until sprite 0 hit flag is set
;; Small delay to let the scanline finish drawing
LDX #$20 ; Adjust delay for timing
WaitScanline:
DEX
BNE WaitScanline
;; Increment and apply horizontal scroll for the background
INC offset_value ; Increment horizontal scroll variable
LDA offset_value
STA $2005 ; Write horizontal scroll register
LDA #$00 ; No vertical scrolling
STA $2005
;; Restore PPU settings for the next frame
LDA #%10010000 ; Enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
STA $2000
LDA #%00011110 ; Enable sprites, enable background, no clipping on left side
STA $2001
RTS
fixed a bug where spamming the sword attack and jumping would sometime freeze the sword sprite mid frame. spamming is now almost perfect !
Now since the background is always moving ( the green part to, and some of the orange part ), when I loose a heart, I modify the background data therefore frezzing and messing the memory.
Will work on that tonight !:
HEART_ROUTINES.s
INITIALISE_HEARTS_P1:
LDA #$0A ; Load immediate value 0A (10 in decimal)
STA heart_counter_P1 ; Store the value 0A into heart_counter_P1
RTS; Return from subroutine
LOOSE_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_P1
JSR HEARTS_TILES_LOGIC_P1
RTS
RESET_HEART_TILES_P1:
; Set PPU address to the correct position based on heart_counter_P1
LDA #$20 ; High byte of PPU address (e.g., $2000)
STA PPU_VRAM_ADDR2 ; Write high byte to PPU address register
LDA #$60
STA PPU_VRAM_ADDR2 ; Write low byte to PPU address register
LDX #$00
RESETTILES_HEARTS_P1:
LDA #$A7 ; Tile ID to write (change this to the desired tile ID)
STA PPU_VRAM_IO ; 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 tiles
RTS
HEARTS_TILES_LOGIC_P1:
JSR RESET_HEART_TILES_P1
; Set PPU address to the correct position based on heart_counter_P1
LDA #$20 ; High byte of PPU address (e.g., $2000)
STA PPU_VRAM_ADDR2 ; Write high byte to PPU address register
LDA #$60
STA PPU_VRAM_ADDR2 ; 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 loop
WRITETILES_HEARTS_P1:
LDA #$FF ; Tile ID to write (change this to the desired tile ID)
STA PPU_VRAM_IO ; 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
; Reset scroll and PPU control settings
LDA #$00
STA PPU_VRAM_ADDR2
STA PPU_VRAM_ADDR2
RTS ; Return from subroutine
HEART_COUNTER_ZERO_P1:
JSR INITIALISE_HEARTS_P1 ; Call to reset heart_counter_p2 to 10 if it reached 0
JSR HEARTS_TILES_LOGIC_P1
LDA #$00
STA PPU_VRAM_ADDR2
STA PPU_VRAM_ADDR2
RTS ; Return from subroutine
thats my current HEarts routines for player one. It messing with my scrolling code, any ideas ?
thats my scrolling code that I called every nmi, for now.:
OFFSET_BACKGROUND_VERTICAL2:
LDA #$00
STA $2003 ; Set sprite memory address to 0
LDA #$02
STA $4014 ; Sprite DMA from $0200
;; Clear PPU address registers
LDA #$00
STA $2006
STA $2006
;; Set initial scroll to 0 for the static status bar
LDA #$00
STA $2005 ; Horizontal scroll
STA $2005 ; Vertical scroll
;; Wait for Sprite 0 hit to clear (from the previous frame)
WaitNotSprite0:
LDA $2002 ; Read PPU status register
AND #%01000000 ; Check sprite 0 hit flag (bit 6)
BNE WaitNotSprite0 ; Wait until sprite 0 hit flag is cleared
;; Wait for Sprite 0 to be hit
WaitSprite0:
LDA $2002 ; Read PPU status register
AND #%01000000 ; Check sprite 0 hit flag (bit 6)
BEQ WaitSprite0 ; Wait until sprite 0 hit flag is set
;; Small delay to let the scanline finish drawing
LDX #$20 ; Adjust delay for timing
WaitScanline:
DEX
BNE WaitScanline
;; Increment and apply horizontal scroll for the background
INC offset_value ; Increment horizontal scroll variable
LDA offset_value
STA $2005 ; Write horizontal scroll register
LDA #$00 ; No vertical scrolling
STA $2005
;; Restore PPU settings for the next frame
LDA #%10010000 ; Enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
STA $2000
LDA #%00011110 ; Enable sprites, enable background, no clipping on left side
STA $2001
RTS
Statistics: Posted by v.depatie — Thu Dec 12, 2024 9:06 pm — Replies 0 — Views 53