Skip to content

Commit 1e761df

Browse files
authored
Unify soft stack initialization. (#122)
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.
1 parent deae7c3 commit 1e761df

File tree

9 files changed

+12
-10
lines changed

9 files changed

+12
-10
lines changed

mos-platform/atari8/init-stack.S

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
.global __do_init_stack
44

5-
; Initialize soft stack pointer to MEMTOP
5+
; Initialize soft stack pointer to MEMTOP+1
66
.section .init.100,"axR",@progbits
77
__do_init_stack:
8+
clc
89
lda $2e5
10+
adc #1
911
sta __rc0
1012
lda $2e6
13+
adc #0
1114
sta __rc1

mos-platform/c64/link.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ INPUT(unmap-basic.o)
1818

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

2323
OUTPUT_FORMAT {
2424
/* Tells the C64 LOAD command where to place the file's contents. */

mos-platform/cx16/link.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ MEMORY {
1515
INCLUDE commodore.ld
1616

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

2020
OUTPUT_FORMAT {
2121
/* Tells the LOAD command where to place the file's contents. */

mos-platform/mega65/link.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ INCLUDE commodore.ld
2828
INPUT(unmap-basic.o)
2929

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

3333
OUTPUT_FORMAT {
3434
/* Tells the LOAD command where to place the file's contents. */

mos-platform/nes-mmc1/c-in-prg-ram-0.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ REGION_ALIAS("c_ram", prg_ram_0)
44
/* Ensure that PRG-RAM bank 0 is selected before C starts. */
55
INPUT(init-prg-ram-0.o)
66

7-
__stack = 0x7fff;
7+
__stack = 0x8000;

mos-platform/nes/c-in-ram.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/* Place C sections in NES RAM. */
22
REGION_ALIAS("c_ram", ram)
3-
__stack = 0x07ff;
3+
__stack = 0x0800;

mos-platform/osi-c1p/link.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ SECTIONS { INCLUDE c.ld }
1717

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

2222
OUTPUT_FORMAT { TRIM(ram) }

mos-platform/pet/link.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ MEMORY {
1919
INCLUDE commodore.ld
2020

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

2424
OUTPUT_FORMAT {
2525
/* Tells the PET LOAD command where to place the file's contents. */

mos-platform/rpc8e/init-stack.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ __do_init_stack:
3838
pla
3939
sta $00,x
4040
txa
41-
; FIXME: Does the soft stack point to the final writable byte,
42-
; or one byte after?
41+
inc a
4342
inc a
4443
sta __rc0
4544

0 commit comments

Comments
 (0)