SNES stack pushing to zero page? ...and other SNES related questions

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
User avatar
SusiKette
Posts: 110
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

SNES stack pushing to zero page? ...and other SNES related questions

Post by SusiKette » Thu Feb 20, 2020 11:50 am

While debugging code I noticed that the return address for a subroutine was pushed to $00:00FE - $00:00FF instead of $00:01FE - $00:01FF. As far as I have read, SNES should use page 1 for stack just like NES, but still it seems to go to zero page. Not sure if I need to post any code, but here is all code until the subroutine:

Code: Select all

WRAM_Clear_DMA_Table:
.byte %00001000					; DMAPx
.byte $80						; BBADx
.byte <WRAM_Clear_DMA_Table+7	; A1TxL
.byte >WRAM_Clear_DMA_Table+7	; A1TxH
.byte $00						; A1Bx
.byte $FF						; DASxL
.byte $FF						; DASxH
.byte $00						; Fill Byte

RESET:
		CLC
		XCE					; Disable Emulation Mode
		SEI
		CLD
		
		.a8
		.i8
		SEP #$30
		
		LDA #$80
		STA INIDISP
		STZ NMITIMEN
		STZ MDMAEN
		STZ HDMAEN
		LDA #$01
		STA MEMSEL
		LDX #$FF
		TXS
		
		LDX #$01

Memory_Clear_Loop:
		LDY #$00
		STZ WMADDL			; Set WRAM address for DMA
		STZ WMADDM
		STX WMADDH
		
		LDA WRAM_Clear_DMA_Table,Y		; Set DMA with fixed Source
		STA DMAP0
		INY
		LDA WRAM_Clear_DMA_Table,Y			; Set DMA destination to $2180
		STA BBAD0
		INY
		LDA WRAM_Clear_DMA_Table,Y
		STA A1T0L
		INY
		LDA WRAM_Clear_DMA_Table,Y
		STA A1T0H
		INY
		LDA WRAM_Clear_DMA_Table,Y
		STA A1B0
		INY
		LDA WRAM_Clear_DMA_Table,Y			; Set DMA transfer to $FFFF bytes
		STA DAS0L
		INY
		LDA WRAM_Clear_DMA_Table,Y
		STA DAS0H
		
		LDA #$01
		STA MDMAEN			; Start DMA transfer
		DEX					; Decrement X and loop to clear the second page
		BPL Memory_Clear_Loop
		
		JSR Reset_Register_Setup
I'll be posting other questions here as they come up so I don't have to keep making new threads for them.

lidnariq
Posts: 9403
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: SNES stack pushing to zero page? ...and other SNES related questions

Post by lidnariq » Thu Feb 20, 2020 11:53 am

SusiKette wrote:
Thu Feb 20, 2020 11:50 am
While debugging code I noticed that the return address for a subroutine was pushed to $00:00FE - $00:00FF instead of $00:01FE - $00:01FF. As far as I have read, SNES should use page 1 for stack just like NES, but still it seems to go to zero page.
If you're in Emulation (65C02) mode, that's correct. But since you're in native mode, the stack pointer is a full 16 bits.

edit: The 65816 datasheet additionally says:
In the Native mode (E=0), [...] If the Index Select Bit (X) equals one, both registers will be 8 bits wide, and the high byte is forced to zero.
and
All transfers from one register to another will result in a full 16-bit output from the source register.
so both together means that 8-bit X, set to $FF, and then TXS will result in the stack pointer holding $00FF.

creaothceann
Posts: 224
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: SNES stack pushing to zero page? ...and other SNES related questions

Post by creaothceann » Fri Feb 21, 2020 3:05 am

lidnariq wrote:
Thu Feb 20, 2020 11:53 am
SusiKette wrote:
Thu Feb 20, 2020 11:50 am
While debugging code I noticed that the return address for a subroutine was pushed to $00:00FE - $00:00FF instead of $00:01FE - $00:01FF. As far as I have read, SNES should use page 1 for stack just like NES, but still it seems to go to zero page.
If you're in Emulation (65C02) mode, that's correct. But since you're in native mode, the stack pointer is a full 16 bits.
In emulation mode the stack also doesn't wrap for "new" instructions.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10

Post Reply