Jump to content
IGNORED

With regard to the stack


Propane13

Recommended Posts

I've got a good inkling for how the stack works, but I wanted to confirm something.

When I do the following in code:

 

LDA #$FF

TXS

 

Is the stack now initialized to 0x01ff?

I just want to verify the result of the following code:

 

LDA #$FF

TXS

JSR Place

Place:

LDA #$FF

STA $FF

RTS

 

I want to make sure this wouldn't corrupt my return address, due to a stack-push from an RTS.

 

Conversely, I would assume that this code *would* break:

 

LDA #$FF

TXS

JSR Place

Place:

LDA #$FF

STA $01FF

RTS

 

Can someone confirm?

 

Below is some documentation from the 7800 dev guide I found for reference, but it isn't *too* concrete in its explanation of the stack.

 

There are two (2) 6116 2Kx8 RAM chips on the 7800 PC board.

Together they occupy addresses x '1800' to x'27FF'. They are

also partly accessible (shadowed) at addresses x '0040' - x

'00ff' and x '0140' - x '00FF' to extend zero page (quick access)

RAM and first page (stack) RAM. Refer to the memory map appendix

for further information.

 

 

Memory map:

_________________________________

0000 | |

| TIA Registers |

|_________________________________| 001F

0020 | |

| MARIA Registers |

|_________________________________| 003F

0040 | |

| RAM |

| (6116 Block Zero) |

|_________________________________| 00FF

0100 | |

| Shadow of Page 0 |

| (TIA and MARIA) |

|_________________________________| 013F

0140 | |

| RAM |

| (6116 Block One) |

|_________________________________| 01FF

 

Many thanks to anyone who can confirm this!

-John

 

P.S. Sorry for posting a lot here recently, but I'm working on a project, and am trying to dive back in.

Link to comment
Share on other sites

I've got a good inkling for how the stack works, but I wanted to confirm something.

When I do the following in code:

 

LDA #$FF

TXS

 

Is the stack now initialized to 0x01ff?

I just want to verify the result of the following code:

 

LDA #$FF

TXS

JSR Place

Place:

LDA #$FF

STA $FF

RTS

 

I want to make sure this wouldn't corrupt my return address, due to a stack-push from an RTS.

 

Conversely, I would assume that this code *would* break:

 

LDA #$FF

TXS

JSR Place

Place:

LDA #$FF

STA $01FF

RTS

 

Can someone confirm?

 

Your code will not work as you expect.

 

TXS transfers the contents of the X register to the SP register. If you want to set the stack to point at $01FF, then you must do this:

 

	 LDX #$FF
 TSX

 

If the SP is set to $01FF, then a JSR instruction will place the hi-byte of the return address at $01FF and the lo-byte at $01FE. The resulting SP value will be $FD. In the Atari 2600, memory pages 0 and 1 are shadowed, so a write to $00FF is the same as a write to $01FF. I am not sure if this is true on the 7800 in 7800 mod, but it must be true while the 7800 is in 2600 compatibility mode. If the 7800 memory map overlaps both page zero and page 1 like a 2600, then both of your test code examples will fail. Unless the hi-byte of the label Place: is $FF ;) In which case you will write $FF on top of the existing $FF.

 

The RTS instruction performs only 2 read operations. It does not write anything to memory. It adds 2 to the SP, and the PC is read from the stack. The values loaded into the PC are still in memory until you overwrite them.

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...
  • Recently Browsing   0 members

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