Skip to content

Commit

Permalink
Unify soft stack initialization. (#122)
Browse files Browse the repository at this point in the history
The intended value of the soft stack pointer is the byte *after* the top-most
(last) writable byte in the stack area. This matches the convention used by
targets "dodo" and "sim"; therefore, this commit fixes it for all other
targets.
  • Loading branch information
asiekierka authored Jun 19, 2023
1 parent deae7c3 commit 1e761df
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 10 deletions.
5 changes: 4 additions & 1 deletion mos-platform/atari8/init-stack.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

.global __do_init_stack

; Initialize soft stack pointer to MEMTOP
; Initialize soft stack pointer to MEMTOP+1
.section .init.100,"axR",@progbits
__do_init_stack:
clc
lda $2e5
adc #1
sta __rc0
lda $2e6
adc #0
sta __rc1
2 changes: 1 addition & 1 deletion mos-platform/c64/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ INPUT(unmap-basic.o)

/* With the BASIC ROM unmapped, set initial soft stack address to
* right before the I/O mapped $D000-DFFF area. (It grows down.) */
__stack = 0xCFFF;
__stack = 0xD000;

OUTPUT_FORMAT {
/* Tells the C64 LOAD command where to place the file's contents. */
Expand Down
2 changes: 1 addition & 1 deletion mos-platform/cx16/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MEMORY {
INCLUDE commodore.ld

/* Set initial soft stack address to end of BASIC area. (It grows down.) */
__stack = 0x9eff;
__stack = 0x9f00;

OUTPUT_FORMAT {
/* Tells the LOAD command where to place the file's contents. */
Expand Down
2 changes: 1 addition & 1 deletion mos-platform/mega65/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ INCLUDE commodore.ld
INPUT(unmap-basic.o)

/* Set initial soft stack address to end of BASIC area. (It grows down.) */
__stack = 0xcfff;
__stack = 0xd000;

OUTPUT_FORMAT {
/* Tells the LOAD command where to place the file's contents. */
Expand Down
2 changes: 1 addition & 1 deletion mos-platform/nes-mmc1/c-in-prg-ram-0.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ REGION_ALIAS("c_ram", prg_ram_0)
/* Ensure that PRG-RAM bank 0 is selected before C starts. */
INPUT(init-prg-ram-0.o)

__stack = 0x7fff;
__stack = 0x8000;
2 changes: 1 addition & 1 deletion mos-platform/nes/c-in-ram.ld
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Place C sections in NES RAM. */
REGION_ALIAS("c_ram", ram)
__stack = 0x07ff;
__stack = 0x0800;
2 changes: 1 addition & 1 deletion mos-platform/osi-c1p/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ SECTIONS { INCLUDE c.ld }

/* Set initial soft stack address to end of RAM area. (It grows down.) */
/* TODO make RAM size configurable */
__stack = 0x7FFF;
__stack = 0x8000;

OUTPUT_FORMAT { TRIM(ram) }
2 changes: 1 addition & 1 deletion mos-platform/pet/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MEMORY {
INCLUDE commodore.ld

/* Grow stack downwards from end of RAM */
__stack = (__ram_size * 1024) - 1;
__stack = (__ram_size * 1024);

OUTPUT_FORMAT {
/* Tells the PET LOAD command where to place the file's contents. */
Expand Down
3 changes: 1 addition & 2 deletions mos-platform/rpc8e/init-stack.S
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ __do_init_stack:
pla
sta $00,x
txa
; FIXME: Does the soft stack point to the final writable byte,
; or one byte after?
inc a
inc a
sta __rc0

Expand Down

0 comments on commit 1e761df

Please sign in to comment.