Jump to content
IGNORED

How to Duplicate PHX, PHY on NES 6502?


Recommended Posts

Hi,

 

Inspired by the topic in the link above, what I wish to do is to try to duplicate this 65816-based code from Super Mario All-Stars, but to make it work for a classic 6502.

 

Here is the code in question:
 

KillPlayer:

stx Player_X_Speed

phx

lda #$01

sta PlayerSize

jsl GetPlayerColors (jsl is a special code used in 65816 to bring up subroutines from faraway program banks)

plx

inx

lda #DeathMusic

sta EventMusicQueue

lda #DeathMusic

sta EventMusicQueue

 

What I am dealing with here is a phx after stx and before lda, and a plx after sta and jsl.

 

For 6502, to duplicate phx I might:
 

pha

txa

pha

 

Whereas for plx:
 

pla

tax

pla

 

I read that to preserve the x register, I would also:

lda $0100,x

 

~Ben

 

Thank you,

 

 

 

Ben

 

Link to comment
Share on other sites

10 hours ago, splendidnut said:

For this particular case, you should be able to remove PHX and replace the PLX with LDX PLAYER_X_SPEED.  That should work as long as the GetPlayerColors subroutine doesn't change it.

 

 

UPDATE: I tried this modified code as Small Mario, and it works fine. I will update you later as to if it works right when I'm Fiery Mario and run out of time.

 

Here is the rest of the SMAS version's code:
 

sta $0e67 (what's this supposed to do in SMAS?)
sta ScrollLock ($0723)
lda #$fc
sta player_y_speed ($a0)
lda #$0b (a game engine subroutine bit)
bne SetKRout (sets player's state and other things)

 

And here's the original NES version's code, which did not explicitly take into account the player's size ($0754), colors (GetPlayerColors) and scroll lock ($0723). As the latter is halted when the player dies, I would make an LDA before it and set that as #$01.
 

KillPlayer:
stx Player_X_Speed (halts player's X movement by setting speed)
inx (this increments the last value loaded in X to get the DeathMusic)
stx EventMusicQueue
lda #$fc
sta Player_Y_Speed (#$fc sets the player's new Y speed)
lda #$0b (subroutine bit to call routine on next frame)
bne SetKRout (a branch to set player's state and other things)


And here's the code that comes right before it...
 

ForceInjury:
LDX PlayerStatus ($0756; in this case, the player becomes smaller)
BEQ KillPlayer
STA PlayerStatus
LDA #$08
STA InjuryTimer ($079e NES, $07ae SNES)
LDA #$04 (NES used the single-byte ASL to multiply the current A value to switch to the pipedown/player injured sound)
STA Square1SoundQueue
JSL GetPlayerColors (JSR for NES)
LDA #$0a (sets subroutine to run on next frame)
SetKRout:
LDY #$01 (sets player's new state)
SetPRout:
STA GameEngineSubroutine (#$0f; loads new subroutine to run on next frame)
STY PlayerState ($18 NES, $28 SMAS)
LDY #$ff
STY TimerControl ($0747)
INY
STY ScrollAmount ($0775)

ExInjColRoutines:
LDX ObjectOffset ($08 NES, $9e SMAS) (in KillPlayer routine; this X value is incremented using INX to get the DeathMusic jingle when stored into $FC, the EventMusicQueue)
RTS

 

~Ben

Edited by ColecoFan1981
Link to comment
Share on other sites

  • 2 months later...
On 11/28/2022 at 4:45 AM, splendidnut said:

For this particular case, you should be able to remove PHX and replace the PLX with LDX PLAYER_X_SPEED.  That should work as long as the GetPlayerColors subroutine doesn't change it.

 

 

Thank you; I finally found out how to do that:

KillPlayer:
stx Player_X_Speed
txa
pha
lda #$01
sta PlayerSize
pla
tax
inx
stx EventMusicQueue
stx ScrollLock
...

 

~Ben

Edited by ColecoFan1981
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...