I'm using this code in a hack I'm working on and I modified it a little. Everything seems to be working fine except getting a mushroom or any other powerup does not give me HP back. Here is what I have so far;
;------------------
;Numbered Health Bar
;------------------
!Freespace = $1FC000
!Health = $0DC4
!Dmg = $7F8611
!Mush = $02
Header
LoROM
org $01C510
db $00,00,00,00
org $01C515
db $00
org $01C51C
db $00
org $01C524
db $00,00,00,00
;--------
org $0491DB
JML Level
NOP
org $F2E0
JML Midwayheal
NOP #4
org $01C561
JML Mushroom
org $8F7E
JSL Tilemaps
org $F5F8
NOP #4
org $9E2C
JSL GameLoad
NOP #2
org $F5D5
JML Hit
org $F60A
JML SubDead
org $01C561;lol
org $01C604;my code. 1up=hp
JSL OneUpLives
org !Freespace
!CodeSize = Ending-Routine
db "STAR"
dw !CodeSize-$01
dw !CodeSize-$01^$FFFF
Routine:
;----------
;Level Load
;----------
Level:
LDA !Health
BNE NoRefill
LDA #$0A
STA !Health
NoRefill:
LDA #$02
STA $0DB1
JML $0491E0
;----------
;Mushroom Heal
;----------
Mushroom:
LDA !Health
CMP #$0A
BPL StoreItem
LDA !Health
CLC
ADC #!Mush
STA !Health
BRA CheckBig
StoreItem:
LDA $19
BEQ GetBig
LDA $0DC2
BNE NoItem
INC $0DC2
BRA NoItem
CheckBig:
LDA $19
BNE NoItem
GetBig:
LDX #$02
STX $71
NoItem:
JML $01C565
;----------
;Midway Heal
;----------
Midwayheal:
LDA !Health
CMP #$0A
BEQ .Skip
INC
STA !Health
LDA $19
BNE .Skip
INC
STA $19
.Skip
JML $00F2E8
;--------
;Game Load
;--------
GameLoad:
STA $0DBE
STZ $0DBF
LDA #$0A
STA !Health
RTL
;---------
;Tile Data
;---------
Tilemaps:
STX $0F18 ;coins tilemap 1st digit
STA $0F19 ;coins tilemap 2nd digit
; LDA !Health
; CMP #$01
; BNE End
; STZ $19 ;Hah, gotcha
; BRA Tiles ;Might as well nuke the check too
;End:
LDA #$01
STA $19
Tiles:
LDA #$11
LDX #$19
LDY #$26
STA $0F01 ;H
STX $0F02 ;P
STY $0F1B ;x
LDA !Health
JSL HexDec
STX $0F1C ;#
STA $0F1D ;#
Return:
RTL
;-------------
;Hex/Dec Conversion Loop
;-------------
HexDec:
LDX #$00
Loops:
CMP #$0A
BNE Return
SBC #$0A
INX
BRA Loops
;--------------
;Hit/Death Routine
;--------------
Hit:
PHB
PHK
PLB
LDA $7FAB10,x
AND #$08
BEQ NotCustom
LDA $7FAB9E,x
TAY
LDA CustSprList,y
BRA StoreSprDmg
NotCustom:
LDY $9E,x
LDA NormSprList,y
StoreSprDmg:
STA !Dmg
LDA !Dmg
BEQ NoSpr
LDA !Health
SEC
SBC !Dmg
BRA SprSet
NoSpr:
LDA !Health
DEC
SprSet:
STA !Health
PLB
LDA !Health
BEQ SubDeath
BMI SubDeath
JML $00F5F3
SubDeath:
STZ $19
STZ !Health
SubDead:
LDA #$09
STA $1DFB
JML $00F60F
SprReturn:
RTL
;My code
OneUpLives:
LDA #$0A
STA !Health
;JML $02ACE5;Uncomment to make it still give 1ups
RTL
There is a sprite list below all this code, but the problem must be in here somewhere.
Layout by LDA during C3.