The BSS segment and the ONCE segment share the same start address. So they need to be placed in two different memory areas.
So far BSS was placed in the MAIN memory area and ONCE was placed in an additional memory area. Both memory areas were written to the output file. They just "happened" to be loadable and runnable at a stretch.
Now ONCE is placed in the MAIN memory area and BSS is placed in an additional memory area. Only MAIN is written to the output file. It becomes more obvious that BSS is "just" defined to share memory with ONCE.
MAIN: file = %O, start = %S, size = $D000 - %S;
}
SEGMENTS {
+ ZEROPAGE: load = ZP, type = zp, optional = yes;
LOADADDR: load = LOADADDR, type = ro;
EXEHDR: load = MAIN, type = ro, optional = yes;
CODE: load = MAIN, type = rw, optional = yes;
RODATA: load = MAIN, type = ro, optional = yes;
DATA: load = MAIN, type = rw, optional = yes;
BSS: load = MAIN, type = bss, optional = yes;
- ZEROPAGE: load = ZP, type = zp, optional = yes;
}
FEATURES {
- STARTADDRESS: default = $0801;
+ STARTADDRESS: default = $0801;
}
SYMBOLS {
__LOADADDR__: type = import;
ZP: file = "", define = yes, start = $0002, size = $001A;
LOADADDR: file = %O, start = %S - 2, size = $0002;
HEADER: file = %O, define = yes, start = %S, size = $000D;
- MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __OVERLAYSTART__ - __STACKSIZE__ - __HEADER_LAST__;
- INIT: file = %O, start = __BSS_RUN__, size = __HIMEM__ - __BSS_RUN__;
+ MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __HEADER_LAST__;
+ BSS: file = "", start = __ONCE_RUN__, size = __OVERLAYSTART__ - __STACKSIZE__ - __ONCE_RUN__;
OVL1ADDR: file = "%O.1", start = __OVERLAYSTART__ - 2, size = $0002;
OVL1: file = "%O.1", start = __OVERLAYSTART__, size = __OVERLAYSIZE__;
OVL2ADDR: file = "%O.2", start = __OVERLAYSTART__ - 2, size = $0002;
RODATA: load = MAIN, type = ro;
DATA: load = MAIN, type = rw;
INIT: load = MAIN, type = rw;
- BSS: load = MAIN, type = bss, define = yes;
- ONCE: load = INIT, type = ro;
+ ONCE: load = MAIN, type = ro, define = yes;
+ BSS: load = BSS, type = bss, define = yes;
OVL1ADDR: load = OVL1ADDR, type = ro;
OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes;
OVL2ADDR: load = OVL2ADDR, type = ro;
FEATURES {
- STARTADDRESS: default = $0801;
+ STARTADDRESS: default = $0801;
}
SYMBOLS {
__LOADADDR__: type = import;
__HIMEM__: type = weak, value = $D000;
}
MEMORY {
- ZP: file = "", define = yes, start = $0002, size = $001A;
- LOADADDR: file = %O, start = %S - 2, size = $0002;
- HEADER: file = %O, define = yes, start = %S, size = $000D;
- MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __STACKSIZE__ - __HEADER_LAST__;
- INIT: file = %O, start = __BSS_RUN__, size = __HIMEM__ - __BSS_RUN__;
+ ZP: file = "", define = yes, start = $0002, size = $001A;
+ LOADADDR: file = %O, start = %S - 2, size = $0002;
+ HEADER: file = %O, define = yes, start = %S, size = $000D;
+ MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __HEADER_LAST__;
+ BSS: file = "", start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp;
RODATA: load = MAIN, type = ro;
DATA: load = MAIN, type = rw;
INIT: load = MAIN, type = rw;
- BSS: load = MAIN, type = bss, define = yes;
- ONCE: load = INIT, type = ro, define = yes;
+ ONCE: load = MAIN, type = ro, define = yes;
+ BSS: load = BSS, type = bss, define = yes;
}
FEATURES {
CONDES: type = constructor,
; Set up the stack.
- lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
- ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
+ lda #<(__MAIN_START__ + __MAIN_SIZE__)
+ ldx #>(__MAIN_START__ + __MAIN_SIZE__)
sta sp
stx sp+1 ; Set argument stack ptr