News:

11 March 2016 - Forum Rules

Main Menu

6502 and 65816 Differences

Started by SMB2J-2Q, August 16, 2022, 12:04:54 AM

Previous topic - Next topic

SMB2J-2Q

Since you guys helped me learn how to do a 6502 version of "DEC A" or "DEA" (DECrement Accumulator) which was an SEC+SBC (likewise, to do an "INC A" or "INA" (INCrement Accumulator) in 6502 code, you do that as CLC+ADC), I am wondering how the 6502 might be able to handle long-form returns from subroutines, or RTLs?

Since RTL ($6B) is only possible in 65816, what would I use instead for doing so in 6502?

For example, in Super Mario All-Stars, the coding that determines the maximum number of extra lives in Super Mario Bros. and Super Mario Bros.: The Lost Levels, contains an RTL termination instruction:
CODE_048596:
INC $075A           ;$04:8596 EE 5A 07
LDA $075A           ;$04:8599 AD 5A 07
CMP #$80            ;$04:859C C9 80
BCC CODE_0485A5     ;$04:859E 90 05
LDA #$7F            ;$04:85A0 A9 7F
STA $075A           ;$04:85A2 8D 5A 07

;Increase lives by 1 & make sure
;it doesn't get past 128.

CODE_0485A5:
RTL                 ;$04:85A5 6B

~Ben