From e3cbc7e8b8e1cbb294934cd3d80f9a9f01a2cf28 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Thu, 17 Mar 2016 21:07:19 +0100 Subject: [PATCH] Moved run location of ONCE segment. Make the same changes to the Apple II that were done with https://github.com/cc65/cc65/commit/0ee9b2e446198746c3a05b142ecd00784becf727 to the C64. Notes: - The startup code deliberately doesn't make use of symbols defined for the LC segment as that segment is optional. - The <...>-asm.cfg configs move the segment BSS to an own memory area BSS although this doesn't seem necessary. However the benefit is that the size of the memeory area MAIN is identical to the number of bytes loaded from disk into RAM. To keep this an invariant for all Apple II configs allows to simplify the EXEHDR to just refer to the symbols defined for MAIN. --- cfg/apple2-asm.cfg | 15 ++--- cfg/apple2-overlay.cfg | 55 ++++++++-------- cfg/apple2-system.cfg | 33 +++++----- cfg/apple2.cfg | 37 +++++------ cfg/apple2enh-asm.cfg | 21 +++--- cfg/apple2enh-overlay.cfg | 55 ++++++++-------- cfg/apple2enh-system.cfg | 33 +++++----- cfg/apple2enh.cfg | 37 +++++------ libsrc/apple2/crt0.s | 131 ++++++++++++++++++-------------------- libsrc/apple2/exehdr.s | 6 +- 10 files changed, 196 insertions(+), 227 deletions(-) diff --git a/cfg/apple2-asm.cfg b/cfg/apple2-asm.cfg index b9095cf0c..151ba84c4 100644 --- a/cfg/apple2-asm.cfg +++ b/cfg/apple2-asm.cfg @@ -3,20 +3,17 @@ FEATURES { STARTADDRESS: default = $0803; } -SYMBOLS { - __LOADADDR__: type = weak, value = __CODE_RUN__; - __LOADSIZE__: type = weak, value = __BSS_RUN__ - __CODE_RUN__; -} MEMORY { - ZP: start = $0080, size = $001A, define = yes; - HEADER: file = %O, start = $0000, size = $0004; - MAIN: file = %O, start = %S, size = $C000 - %S; + ZP: file = "", start = $0000, size = $00FF; + HEADER: file = %O, start = %S - 4, size = $0004; + MAIN: file = %O, define = yes, start = %S, size = $C000 - %S; + BSS: file = "", start = __MAIN_LAST__, size = $C000 - __MAIN_LAST__; } SEGMENTS { ZEROPAGE: load = ZP, type = zp, optional = yes; EXEHDR: load = HEADER, type = ro, optional = yes; - CODE: load = MAIN, type = rw, optional = yes, define = 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, define = yes; + BSS: load = BSS, type = bss, optional = yes, define = yes; } diff --git a/cfg/apple2-overlay.cfg b/cfg/apple2-overlay.cfg index 1e34b6250..e6a5ae25c 100644 --- a/cfg/apple2-overlay.cfg +++ b/cfg/apple2-overlay.cfg @@ -12,21 +12,18 @@ FEATURES { } SYMBOLS { __EXEHDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack __HIMEM__: type = weak, value = $9600; # Presumed RAM end __LCADDR__: type = weak, value = $D400; # Behind quit code __LCSIZE__: type = weak, value = $0C00; # Rest of bank two - __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay - __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __INIT_RUN__ - __STARTUP_RUN__ + - __MOVE_LAST__ - __MOVE_START__; } MEMORY { - ZP: define = yes, start = $0080, size = $001A; - HEADER: file = %O, start = $0000, size = $0004; - MAIN: file = %O, start = %S + __OVERLAYSIZE__, size = __HIMEM__ - __STACKSIZE__ - __OVERLAYSIZE__ - %S; - MOVE: file = %O, define = yes, start = $0000, size = $FFFF; - LC: define = yes, start = __LCADDR__, size = __LCSIZE__; + ZP: file = "", define = yes, start = $0080, size = $001A; + HEADER: file = %O, start = %S - 4, size = $0004; + MAIN: file = %O, define = yes, start = %S + __OVERLAYSIZE__, size = __HIMEM__ - __OVERLAYSIZE__ - %S; + BSS: file = "", start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__; + LC: file = "", define = yes, start = __LCADDR__, size = __LCSIZE__; OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; OVL2: file = "%O.2", start = %S, size = __OVERLAYSIZE__; OVL3: file = "%O.3", start = %S, size = __OVERLAYSIZE__; @@ -38,26 +35,26 @@ MEMORY { OVL9: file = "%O.9", start = %S, size = __OVERLAYSIZE__; } SEGMENTS { - ZEROPAGE: load = ZP, type = zp; - EXEHDR: load = HEADER, type = ro; - STARTUP: load = MAIN, type = ro, define = yes; - LOWCODE: load = MAIN, type = ro, optional = yes; - CODE: load = MAIN, type = ro; - RODATA: load = MAIN, type = ro; - DATA: load = MAIN, type = rw; - INIT: load = MAIN, type = bss, define = yes; - BSS: load = MAIN, type = bss, define = yes; - ONCE: load = MOVE, run = MAIN, type = ro, define = yes, optional = yes; - LC: load = MOVE, run = LC, type = ro, optional = yes; - OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; - OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; - OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; - OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; - OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; - OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; - OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; - OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; - OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; + ZEROPAGE: load = ZP, type = zp; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro, define = yes; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; + ONCE: load = MAIN, type = ro, define = yes; + LC: load = MAIN, run = LC, type = ro, optional = yes; + BSS: load = BSS, type = bss, define = yes; + OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; + OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; + OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; + OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; + OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; + OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; + OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; + OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; + OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/apple2-system.cfg b/cfg/apple2-system.cfg index 960be378c..f4684d9c2 100644 --- a/cfg/apple2-system.cfg +++ b/cfg/apple2-system.cfg @@ -1,30 +1,27 @@ # Configuration for ProDOS 8 system programs (without the header) SYMBOLS { + __STACKSIZE__: type = weak, value = $0800; # 2k stack __LCADDR__: type = weak, value = $D400; # Behind quit code __LCSIZE__: type = weak, value = $0C00; # Rest of bank two - __STACKSIZE__: type = weak, value = $0800; # 2k stack - __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __INIT_RUN__ - __STARTUP_RUN__ + - __MOVE_LAST__ - __MOVE_START__; } MEMORY { - ZP: define = yes, start = $0080, size = $001A; - MAIN: file = %O, start = $2000, size = $9F00 - __STACKSIZE__; - MOVE: file = %O, define = yes, start = $0000, size = $FFFF; - LC: define = yes, start = __LCADDR__, size = __LCSIZE__; + ZP: file = "", define = yes, start = $0080, size = $001A; + MAIN: file = %O, start = $2000, size = $BF00 - $2000; + BSS: file = "", start = __ONCE_RUN__, size = $BF00 - __STACKSIZE__ - __ONCE_RUN__; + LC: file = "", define = yes, start = __LCADDR__, size = __LCSIZE__; } SEGMENTS { - ZEROPAGE: load = ZP, type = zp; - STARTUP: load = MAIN, type = ro, define = yes; - LOWCODE: load = MAIN, type = ro, optional = yes; - CODE: load = MAIN, type = ro; - RODATA: load = MAIN, type = ro; - DATA: load = MAIN, type = rw; - INIT: load = MAIN, type = bss, define = yes; - BSS: load = MAIN, type = bss, define = yes; - ONCE: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; - LC: load = MOVE, run = LC, type = ro, optional = yes; + ZEROPAGE: load = ZP, type = zp; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; + ONCE: load = MAIN, type = ro, define = yes; + LC: load = MAIN, run = LC, type = ro, optional = yes; + BSS: load = BSS, type = bss, define = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/apple2.cfg b/cfg/apple2.cfg index 875103041..eba2a0e66 100644 --- a/cfg/apple2.cfg +++ b/cfg/apple2.cfg @@ -5,33 +5,30 @@ FEATURES { } SYMBOLS { __EXEHDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack __HIMEM__: type = weak, value = $9600; # Presumed RAM end __LCADDR__: type = weak, value = $D400; # Behind quit code __LCSIZE__: type = weak, value = $0C00; # Rest of bank two - __STACKSIZE__: type = weak, value = $0800; # 2k stack - __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __INIT_RUN__ - __STARTUP_RUN__ + - __MOVE_LAST__ - __MOVE_START__; } MEMORY { - ZP: define = yes, start = $0080, size = $001A; - HEADER: file = %O, start = $0000, size = $0004; - MAIN: file = %O, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; - MOVE: file = %O, define = yes, start = $0000, size = $FFFF; - LC: define = yes, start = __LCADDR__, size = __LCSIZE__; + ZP: file = "", define = yes, start = $0080, size = $001A; + HEADER: file = %O, start = %S - 4, size = $0004; + MAIN: file = %O, define = yes, start = %S, size = __HIMEM__ - %S; + BSS: file = "", start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__; + LC: file = "", define = yes, start = __LCADDR__, size = __LCSIZE__; } SEGMENTS { - ZEROPAGE: load = ZP, type = zp; - EXEHDR: load = HEADER, type = ro; - STARTUP: load = MAIN, type = ro, define = yes; - LOWCODE: load = MAIN, type = ro, optional = yes; - CODE: load = MAIN, type = ro; - RODATA: load = MAIN, type = ro; - DATA: load = MAIN, type = rw; - INIT: load = MAIN, type = bss, define = yes; - BSS: load = MAIN, type = bss, define = yes; - ONCE: load = MOVE, run = MAIN, type = ro, define = yes, optional = yes; - LC: load = MOVE, run = LC, type = ro, optional = yes; + ZEROPAGE: load = ZP, type = zp; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; + ONCE: load = MAIN, type = ro, define = yes; + LC: load = MAIN, run = LC, type = ro, optional = yes; + BSS: load = BSS, type = bss, define = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/apple2enh-asm.cfg b/cfg/apple2enh-asm.cfg index f7ede1bfe..151ba84c4 100644 --- a/cfg/apple2enh-asm.cfg +++ b/cfg/apple2enh-asm.cfg @@ -3,18 +3,17 @@ FEATURES { STARTADDRESS: default = $0803; } -SYMBOLS { - __LOADADDR__: type = weak, value = __CODE_RUN__; - __LOADSIZE__: type = weak, value = __BSS_RUN__ - __CODE_RUN__; -} MEMORY { - HEADER: file = %O, start = $0000, size = $0004; - MAIN: file = %O, start = %S, size = $C000 - %S; + ZP: file = "", start = $0000, size = $00FF; + HEADER: file = %O, start = %S - 4, size = $0004; + MAIN: file = %O, define = yes, start = %S, size = $C000 - %S; + BSS: file = "", start = __MAIN_LAST__, size = $C000 - __MAIN_LAST__; } SEGMENTS { - EXEHDR: load = HEADER, type = ro, optional = yes; - CODE: load = MAIN, type = rw, optional = yes, define = yes; - RODATA: load = MAIN, type = ro, optional = yes; - DATA: load = MAIN, type = rw, optional = yes; - BSS: load = MAIN, type = bss, optional = yes, define = yes; + ZEROPAGE: load = ZP, type = zp, optional = yes; + EXEHDR: load = HEADER, 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 = BSS, type = bss, optional = yes, define = yes; } diff --git a/cfg/apple2enh-overlay.cfg b/cfg/apple2enh-overlay.cfg index 1e34b6250..e6a5ae25c 100644 --- a/cfg/apple2enh-overlay.cfg +++ b/cfg/apple2enh-overlay.cfg @@ -12,21 +12,18 @@ FEATURES { } SYMBOLS { __EXEHDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack __HIMEM__: type = weak, value = $9600; # Presumed RAM end __LCADDR__: type = weak, value = $D400; # Behind quit code __LCSIZE__: type = weak, value = $0C00; # Rest of bank two - __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay - __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __INIT_RUN__ - __STARTUP_RUN__ + - __MOVE_LAST__ - __MOVE_START__; } MEMORY { - ZP: define = yes, start = $0080, size = $001A; - HEADER: file = %O, start = $0000, size = $0004; - MAIN: file = %O, start = %S + __OVERLAYSIZE__, size = __HIMEM__ - __STACKSIZE__ - __OVERLAYSIZE__ - %S; - MOVE: file = %O, define = yes, start = $0000, size = $FFFF; - LC: define = yes, start = __LCADDR__, size = __LCSIZE__; + ZP: file = "", define = yes, start = $0080, size = $001A; + HEADER: file = %O, start = %S - 4, size = $0004; + MAIN: file = %O, define = yes, start = %S + __OVERLAYSIZE__, size = __HIMEM__ - __OVERLAYSIZE__ - %S; + BSS: file = "", start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__; + LC: file = "", define = yes, start = __LCADDR__, size = __LCSIZE__; OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; OVL2: file = "%O.2", start = %S, size = __OVERLAYSIZE__; OVL3: file = "%O.3", start = %S, size = __OVERLAYSIZE__; @@ -38,26 +35,26 @@ MEMORY { OVL9: file = "%O.9", start = %S, size = __OVERLAYSIZE__; } SEGMENTS { - ZEROPAGE: load = ZP, type = zp; - EXEHDR: load = HEADER, type = ro; - STARTUP: load = MAIN, type = ro, define = yes; - LOWCODE: load = MAIN, type = ro, optional = yes; - CODE: load = MAIN, type = ro; - RODATA: load = MAIN, type = ro; - DATA: load = MAIN, type = rw; - INIT: load = MAIN, type = bss, define = yes; - BSS: load = MAIN, type = bss, define = yes; - ONCE: load = MOVE, run = MAIN, type = ro, define = yes, optional = yes; - LC: load = MOVE, run = LC, type = ro, optional = yes; - OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; - OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; - OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; - OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; - OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; - OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; - OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; - OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; - OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; + ZEROPAGE: load = ZP, type = zp; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro, define = yes; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; + ONCE: load = MAIN, type = ro, define = yes; + LC: load = MAIN, run = LC, type = ro, optional = yes; + BSS: load = BSS, type = bss, define = yes; + OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; + OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; + OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; + OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; + OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; + OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; + OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; + OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; + OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/apple2enh-system.cfg b/cfg/apple2enh-system.cfg index 6134851f0..f4684d9c2 100644 --- a/cfg/apple2enh-system.cfg +++ b/cfg/apple2enh-system.cfg @@ -1,30 +1,27 @@ # Configuration for ProDOS 8 system programs (without the header) SYMBOLS { + __STACKSIZE__: type = weak, value = $0800; # 2k stack __LCADDR__: type = weak, value = $D400; # Behind quit code __LCSIZE__: type = weak, value = $0C00; # Rest of bank two - __STACKSIZE__: type = weak, value = $0800; # 2k stack - __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __INIT_RUN__ - __STARTUP_RUN__ + - __MOVE_LAST__ - __MOVE_START__; } MEMORY { - ZP: define = yes, start = $0080, size = $001A; - MAIN: file = %O, start = $2000, size = $9F00 - __STACKSIZE__; - MOVE: file = %O, define = yes, start = $0000, size = $FFFF; - LC: define = yes, start = __LCADDR__, size = __LCSIZE__; + ZP: file = "", define = yes, start = $0080, size = $001A; + MAIN: file = %O, start = $2000, size = $BF00 - $2000; + BSS: file = "", start = __ONCE_RUN__, size = $BF00 - __STACKSIZE__ - __ONCE_RUN__; + LC: file = "", define = yes, start = __LCADDR__, size = __LCSIZE__; } SEGMENTS { - ZEROPAGE: load = ZP, type = zp; - STARTUP: load = MAIN, type = ro, define = yes; - LOWCODE: load = MAIN, type = ro, optional = yes; - CODE: load = MAIN, type = ro; - RODATA: load = MAIN, type = ro; - DATA: load = MAIN, type = rw; - INIT: load = MAIN, type = bss, define = yes; - BSS: load = MAIN, type = bss, define = yes; - ONCE: load = MOVE, run = MAIN, type = ro, define = yes, optional = yes; - LC: load = MOVE, run = LC, type = ro, optional = yes; + ZEROPAGE: load = ZP, type = zp; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; + ONCE: load = MAIN, type = ro, define = yes; + LC: load = MAIN, run = LC, type = ro, optional = yes; + BSS: load = BSS, type = bss, define = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/apple2enh.cfg b/cfg/apple2enh.cfg index 875103041..eba2a0e66 100644 --- a/cfg/apple2enh.cfg +++ b/cfg/apple2enh.cfg @@ -5,33 +5,30 @@ FEATURES { } SYMBOLS { __EXEHDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack __HIMEM__: type = weak, value = $9600; # Presumed RAM end __LCADDR__: type = weak, value = $D400; # Behind quit code __LCSIZE__: type = weak, value = $0C00; # Rest of bank two - __STACKSIZE__: type = weak, value = $0800; # 2k stack - __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __INIT_RUN__ - __STARTUP_RUN__ + - __MOVE_LAST__ - __MOVE_START__; } MEMORY { - ZP: define = yes, start = $0080, size = $001A; - HEADER: file = %O, start = $0000, size = $0004; - MAIN: file = %O, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; - MOVE: file = %O, define = yes, start = $0000, size = $FFFF; - LC: define = yes, start = __LCADDR__, size = __LCSIZE__; + ZP: file = "", define = yes, start = $0080, size = $001A; + HEADER: file = %O, start = %S - 4, size = $0004; + MAIN: file = %O, define = yes, start = %S, size = __HIMEM__ - %S; + BSS: file = "", start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__; + LC: file = "", define = yes, start = __LCADDR__, size = __LCSIZE__; } SEGMENTS { - ZEROPAGE: load = ZP, type = zp; - EXEHDR: load = HEADER, type = ro; - STARTUP: load = MAIN, type = ro, define = yes; - LOWCODE: load = MAIN, type = ro, optional = yes; - CODE: load = MAIN, type = ro; - RODATA: load = MAIN, type = ro; - DATA: load = MAIN, type = rw; - INIT: load = MAIN, type = bss, define = yes; - BSS: load = MAIN, type = bss, define = yes; - ONCE: load = MOVE, run = MAIN, type = ro, define = yes, optional = yes; - LC: load = MOVE, run = LC, type = ro, optional = yes; + ZEROPAGE: load = ZP, type = zp; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; + ONCE: load = MAIN, type = ro, define = yes; + LC: load = MAIN, run = LC, type = ro, optional = yes; + BSS: load = BSS, type = bss, define = yes; } FEATURES { CONDES: type = constructor, diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s index 7eee390fa..60a8516d1 100644 --- a/libsrc/apple2/crt0.s +++ b/libsrc/apple2/crt0.s @@ -6,16 +6,17 @@ .export _exit, done, return .export __STARTUP__ : absolute = 1 ; Mark as startup - .import zerobss + .import initlib, donelib - .import callmain + .import zerobss, callmain + .import __ONCE_LOAD__, __ONCE_SIZE__ ; Linker generated .import __LC_START__, __LC_LAST__ ; Linker generated - .import __ONCE_RUN__, __ONCE_SIZE__ ; Linker generated - .import __INIT_RUN__ ; Linker generated .include "zeropage.inc" .include "apple2.inc" +; ------------------------------------------------------------------------ + .segment "STARTUP" ; ProDOS TechRefMan, chapter 5.2.1: @@ -24,57 +25,16 @@ ldx #$FF txs ; Init stack pointer - ; Switch in LC bank 2 for W/O. - bit $C081 - bit $C081 - - ; Set the source start address. - lda #<(__INIT_RUN__ + __ONCE_SIZE__) - ldy #>(__INIT_RUN__ + __ONCE_SIZE__) - sta $9B - sty $9C - - ; Set the source last address. - lda #<(__INIT_RUN__ + __ONCE_SIZE__ + __LC_LAST__ - __LC_START__) - ldy #>(__INIT_RUN__ + __ONCE_SIZE__ + __LC_LAST__ - __LC_START__) - sta $96 - sty $97 - - ; Set the destination last address. - lda #<__LC_LAST__ - ldy #>__LC_LAST__ - sta $94 - sty $95 - - ; Call into Applesoft Block Transfer Up -- which handles zero- - ; sized blocks well -- to move the content of the LC memory area. - jsr $D39A ; BLTU2 - - ; Set the source start address. - lda #<__INIT_RUN__ - ldy #>__INIT_RUN__ - sta $9B - sty $9C - - ; Set the source last address. - lda #<(__INIT_RUN__ + __ONCE_SIZE__) - ldy #>(__INIT_RUN__ + __ONCE_SIZE__) - sta $96 - sty $97 - - ; Set the destination last address. - lda #<(__ONCE_RUN__ + __ONCE_SIZE__) - ldy #>(__ONCE_RUN__ + __ONCE_SIZE__) - sta $94 - sty $95 - - ; Call into Applesoft Block Transfer Up -- which handles moving - ; overlapping blocks upwards well -- to move the ONCE segment. - jsr $D39A ; BLTU2 - - ; Delegate all further processing, to keep the STARTUP segment small. + ; Save space by putting some of the start-up code in the ONCE segment, + ; which can be re-used by the BSS segment, the heap and the C stack. jsr init + ; Clear the BSS data. + jsr zerobss + + ; Push the command-line arguments; and, call main(). + jsr callmain + ; Avoid a re-entrance of donelib. This is also the exit() entry. _exit: ldx #exit @@ -109,6 +69,8 @@ exit: ldx #$02 ; We're done jmp done +; ------------------------------------------------------------------------ + .segment "ONCE" ; Save the zero-page locations that we need. @@ -118,9 +80,6 @@ init: ldx #zpspace-1 dex bpl :- - ; Clear the BSS data. - jsr zerobss - ; Save the original RESET vector. ldx #$02 : lda SOFTEV,x @@ -128,13 +87,6 @@ init: ldx #zpspace-1 dex bpl :- - ; ProDOS TechRefMan, chapter 5.3.5: - ; "Your system program should place in the RESET vector the - ; address of a routine that ... closes the files." - ldx #<_exit - lda #>_exit - jsr reset ; Setup RESET vector - ; Check for ProDOS. ldy $BF00 ; MLI call entry point cpy #$4C ; Is MLI present? (JMP opcode) @@ -164,14 +116,50 @@ basic: lda HIMEM : sta sp stx sp+1 + ; ProDOS TechRefMan, chapter 5.3.5: + ; "Your system program should place in the RESET vector the + ; address of a routine that ... closes the files." + ldx #<_exit + lda #>_exit + jsr reset ; Setup RESET vector + ; Call the module constructors. jsr initlib - ; Switch in LC bank 2 for R/O. - bit $C080 + ; Switch in LC bank 2 for W/O. + bit $C081 + bit $C081 - ; Push the command-line arguments; and, call main(). - jmp callmain + ; Set the source start address. + ; Aka __LC_LOAD__ iff segment LC exists. + lda #<(__ONCE_LOAD__ + __ONCE_SIZE__) + ldy #>(__ONCE_LOAD__ + __ONCE_SIZE__) + sta $9B + sty $9C + + ; Set the source last address. + ; Aka __LC_LOAD__ + __LC_SIZE__ iff segment LC exists. + lda #<((__ONCE_LOAD__ + __ONCE_SIZE__) + (__LC_LAST__ - __LC_START__)) + ldy #>((__ONCE_LOAD__ + __ONCE_SIZE__) + (__LC_LAST__ - __LC_START__)) + sta $96 + sty $97 + + ; Set the destination last address. + ; Aka __LC_RUN__ + __LC_SIZE__ iff segment LC exists. + lda #<__LC_LAST__ + ldy #>__LC_LAST__ + sta $94 + sty $95 + + ; Call into Applesoft Block Transfer Up -- which handles zero- + ; sized blocks well -- to move the content of the LC memory area. + jsr $D39A ; BLTU2 + + ; Switch in LC bank 2 for R/O and return. + bit $C080 + rts + +; ------------------------------------------------------------------------ .code @@ -187,6 +175,8 @@ quit: jsr $BF00 ; MLI call entry point .byte $65 ; Quit .word q_param +; ------------------------------------------------------------------------ + .rodata ; MLI parameter list for quit @@ -196,15 +186,16 @@ q_param:.byte $04 ; param_count .byte $00 ; reserved .word $0000 ; reserved +; ------------------------------------------------------------------------ + .data ; Final jump when we're done done: jmp DOSWARM ; Potentially patched at runtime +; ------------------------------------------------------------------------ + .segment "INIT" zpsave: .res zpspace - - .bss - rvsave: .res 3 diff --git a/libsrc/apple2/exehdr.s b/libsrc/apple2/exehdr.s index eb05e66be..778eee903 100644 --- a/libsrc/apple2/exehdr.s +++ b/libsrc/apple2/exehdr.s @@ -6,11 +6,11 @@ ; .export __EXEHDR__ : absolute = 1 ; Linker referenced - .import __LOADADDR__, __LOADSIZE__ ; Linker generated + .import __MAIN_START__, __MAIN_LAST__ ; Linker generated ; ------------------------------------------------------------------------ .segment "EXEHDR" - .addr __LOADADDR__ ; Load address - .word __LOADSIZE__ ; Load length + .addr __MAIN_START__ ; Load address + .word __MAIN_LAST__ - __MAIN_START__ ; Load length