From: Oliver Schmidt
Date: Wed, 14 Oct 2015 22:15:38 +0000 (+0200)
Subject: Adjusted current working directory initialization on Apple and Atari.
X-Git-Tag: V2.16~212
X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=76a5a72403266b923b9bdc9ccd5f4de2a352459a;p=cc65
Adjusted current working directory initialization on Apple and Atari.
Moving __cwd from BSS into INITBSS does of course ;-) not only impact the CBM targets but all targets with disk I/O support.
Note: Code using `__cwd-1` may trigger an ld65 range error because __cwd may end up at the very begining of a segment. As far as I see this is an ld65 bug which I'm not try to fix - at least here.
---
diff --git a/cfg/apple2-overlay.cfg b/cfg/apple2-overlay.cfg
index d0b34692f..244e4582f 100644
--- a/cfg/apple2-overlay.cfg
+++ b/cfg/apple2-overlay.cfg
@@ -18,7 +18,7 @@ SYMBOLS {
__STACKSIZE__: type = weak, value = $0800; # 2k stack
__OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay
__LOADADDR__: type = weak, value = __STARTUP_RUN__;
- __LOADSIZE__: type = weak, value = __ZPSAVE_RUN__ - __STARTUP_RUN__ +
+ __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ +
__MOVE_LAST__ - __MOVE_START__;
}
MEMORY {
@@ -45,7 +45,7 @@ SEGMENTS {
CODE: load = RAM, type = ro;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
- ZPSAVE: load = RAM, type = bss, define = yes;
+ INITBSS: load = RAM, type = bss, define = yes;
BSS: load = RAM, type = bss, define = yes;
INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes;
LC: load = MOVE, run = LC, type = ro, optional = yes;
diff --git a/cfg/apple2-system.cfg b/cfg/apple2-system.cfg
index 33ab04f5e..f07208e45 100644
--- a/cfg/apple2-system.cfg
+++ b/cfg/apple2-system.cfg
@@ -5,7 +5,7 @@ SYMBOLS {
__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 = __ZPSAVE_RUN__ - __STARTUP_RUN__ +
+ __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ +
__MOVE_LAST__ - __MOVE_START__;
}
MEMORY {
@@ -21,7 +21,7 @@ SEGMENTS {
CODE: load = RAM, type = ro;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
- ZPSAVE: load = RAM, type = bss, define = yes;
+ INITBSS: load = RAM, type = bss, define = yes;
BSS: load = RAM, type = bss, define = yes;
INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes;
LC: load = MOVE, run = LC, type = ro, optional = yes;
diff --git a/cfg/apple2.cfg b/cfg/apple2.cfg
index 5673302d1..27eb706c4 100644
--- a/cfg/apple2.cfg
+++ b/cfg/apple2.cfg
@@ -10,7 +10,7 @@ SYMBOLS {
__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 = __ZPSAVE_RUN__ - __STARTUP_RUN__ +
+ __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ +
__MOVE_LAST__ - __MOVE_START__;
}
MEMORY {
@@ -28,7 +28,7 @@ SEGMENTS {
CODE: load = RAM, type = ro;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
- ZPSAVE: load = RAM, type = bss, define = yes;
+ INITBSS: load = RAM, type = bss, define = yes;
BSS: load = RAM, type = bss, define = yes;
INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes;
LC: load = MOVE, run = LC, type = ro, optional = yes;
diff --git a/cfg/apple2enh-overlay.cfg b/cfg/apple2enh-overlay.cfg
index d0b34692f..244e4582f 100644
--- a/cfg/apple2enh-overlay.cfg
+++ b/cfg/apple2enh-overlay.cfg
@@ -18,7 +18,7 @@ SYMBOLS {
__STACKSIZE__: type = weak, value = $0800; # 2k stack
__OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay
__LOADADDR__: type = weak, value = __STARTUP_RUN__;
- __LOADSIZE__: type = weak, value = __ZPSAVE_RUN__ - __STARTUP_RUN__ +
+ __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ +
__MOVE_LAST__ - __MOVE_START__;
}
MEMORY {
@@ -45,7 +45,7 @@ SEGMENTS {
CODE: load = RAM, type = ro;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
- ZPSAVE: load = RAM, type = bss, define = yes;
+ INITBSS: load = RAM, type = bss, define = yes;
BSS: load = RAM, type = bss, define = yes;
INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes;
LC: load = MOVE, run = LC, type = ro, optional = yes;
diff --git a/cfg/apple2enh-system.cfg b/cfg/apple2enh-system.cfg
index 33ab04f5e..f07208e45 100644
--- a/cfg/apple2enh-system.cfg
+++ b/cfg/apple2enh-system.cfg
@@ -5,7 +5,7 @@ SYMBOLS {
__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 = __ZPSAVE_RUN__ - __STARTUP_RUN__ +
+ __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ +
__MOVE_LAST__ - __MOVE_START__;
}
MEMORY {
@@ -21,7 +21,7 @@ SEGMENTS {
CODE: load = RAM, type = ro;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
- ZPSAVE: load = RAM, type = bss, define = yes;
+ INITBSS: load = RAM, type = bss, define = yes;
BSS: load = RAM, type = bss, define = yes;
INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes;
LC: load = MOVE, run = LC, type = ro, optional = yes;
diff --git a/cfg/apple2enh.cfg b/cfg/apple2enh.cfg
index 5673302d1..27eb706c4 100644
--- a/cfg/apple2enh.cfg
+++ b/cfg/apple2enh.cfg
@@ -10,7 +10,7 @@ SYMBOLS {
__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 = __ZPSAVE_RUN__ - __STARTUP_RUN__ +
+ __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ +
__MOVE_LAST__ - __MOVE_START__;
}
MEMORY {
@@ -28,7 +28,7 @@ SEGMENTS {
CODE: load = RAM, type = ro;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
- ZPSAVE: load = RAM, type = bss, define = yes;
+ INITBSS: load = RAM, type = bss, define = yes;
BSS: load = RAM, type = bss, define = yes;
INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes;
LC: load = MOVE, run = LC, type = ro, optional = yes;
diff --git a/cfg/atari-cart.cfg b/cfg/atari-cart.cfg
index db9486a9f..58457c606 100644
--- a/cfg/atari-cart.cfg
+++ b/cfg/atari-cart.cfg
@@ -22,6 +22,7 @@ SEGMENTS {
CODE: load = ROM, type = ro, define = yes;
RODATA: load = ROM, type = ro, optional = yes;
DATA: load = ROM, run = RAM, type = rw, define = yes, optional = yes;
+ INITBSS: load = RAM, type = bss, optional = yes;
BSS: load = RAM, type = bss, define = yes, optional = yes;
CARTHDR: load = CARTID, type = ro;
ZEROPAGE: load = ZP, type = zp, optional = yes;
diff --git a/cfg/atari-cassette.cfg b/cfg/atari-cassette.cfg
index 2116aecd0..80b5c695f 100644
--- a/cfg/atari-cassette.cfg
+++ b/cfg/atari-cassette.cfg
@@ -19,6 +19,7 @@ SEGMENTS {
CODE: load = RAM, type = ro, define = yes;
RODATA: load = RAM, type = ro, optional = yes;
DATA: load = RAM, type = rw, optional = yes;
+ INITBSS: load = RAM, type = bss, optional = yes;
BSS: load = RAM, type = bss, define = yes, optional = yes;
ZEROPAGE: load = ZP, type = zp, optional = yes;
EXTZP: load = ZP, type = zp, optional = yes;
diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg
index 1d339b208..b3abad988 100644
--- a/cfg/atari-overlay.cfg
+++ b/cfg/atari-overlay.cfg
@@ -49,6 +49,7 @@ SEGMENTS {
CODE: load = RAM, type = ro, define = yes;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
+ INITBSS: load = RAM, type = bss, optional = yes;
BSS: load = RAM, type = bss, define = yes;
ZEROPAGE: load = ZP, type = zp;
EXTZP: load = ZP, type = zp, optional = yes;
diff --git a/cfg/atari.cfg b/cfg/atari.cfg
index dce593f05..97b289d7e 100644
--- a/cfg/atari.cfg
+++ b/cfg/atari.cfg
@@ -37,6 +37,7 @@ SEGMENTS {
CODE: load = RAM, type = ro, define = yes;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
+ INITBSS: load = RAM, type = bss, optional = yes;
BSS: load = RAM, type = bss, define = yes;
ZEROPAGE: load = ZP, type = zp;
EXTZP: load = ZP, type = zp, optional = yes;
diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg
index 01fc76a26..f96096995 100644
--- a/cfg/atarixl-largehimem.cfg
+++ b/cfg/atarixl-largehimem.cfg
@@ -70,6 +70,7 @@ SEGMENTS {
CODE: load = RAM, type = ro, define = yes;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
+ INITBSS: load = RAM, type = bss, optional = yes;
BSS: load = RAM, type = bss, define = yes;
ZEROPAGE: load = ZP, type = zp;
EXTZP: load = ZP, type = zp, optional = yes;
diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg
index 68d0f524e..7356fc03e 100644
--- a/cfg/atarixl-overlay.cfg
+++ b/cfg/atarixl-overlay.cfg
@@ -82,6 +82,7 @@ SEGMENTS {
CODE: load = RAM, type = ro, define = yes;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
+ INITBSS: load = RAM, type = bss, optional = yes;
BSS: load = RAM, type = bss, define = yes;
ZEROPAGE: load = ZP, type = zp;
EXTZP: load = ZP, type = zp, optional = yes;
diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg
index aad3ce613..84992a205 100644
--- a/cfg/atarixl.cfg
+++ b/cfg/atarixl.cfg
@@ -68,6 +68,7 @@ SEGMENTS {
CODE: load = RAM, type = ro, define = yes;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
+ INITBSS: load = RAM, type = bss, optional = yes;
BSS: load = RAM, type = bss, define = yes;
ZEROPAGE: load = ZP, type = zp;
EXTZP: load = ZP, type = zp, optional = yes;
diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s
index 445039b1e..f061b212b 100644
--- a/libsrc/apple2/crt0.s
+++ b/libsrc/apple2/crt0.s
@@ -11,7 +11,7 @@
.import callmain
.import __LC_START__, __LC_LAST__ ; Linker generated
.import __INIT_RUN__, __INIT_SIZE__ ; Linker generated
- .import __ZPSAVE_RUN__ ; Linker generated
+ .import __INITBSS_RUN__ ; Linker generated
.include "zeropage.inc"
.include "apple2.inc"
@@ -29,14 +29,14 @@
bit $C081
; Set the source start address.
- lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
- ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
+ lda #<(__INITBSS_RUN__ + __INIT_SIZE__)
+ ldy #>(__INITBSS_RUN__ + __INIT_SIZE__)
sta $9B
sty $9C
; Set the source last address.
- lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
- ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
+ lda #<(__INITBSS_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
+ ldy #>(__INITBSS_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
sta $96
sty $97
@@ -51,14 +51,14 @@
jsr $D39A ; BLTU2
; Set the source start address.
- lda #<__ZPSAVE_RUN__
- ldy #>__ZPSAVE_RUN__
+ lda #<__INITBSS_RUN__
+ ldy #>__INITBSS_RUN__
sta $9B
sty $9C
; Set the source last address.
- lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
- ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
+ lda #<(__INITBSS_RUN__ + __INIT_SIZE__)
+ ldy #>(__INITBSS_RUN__ + __INIT_SIZE__)
sta $96
sty $97
@@ -201,7 +201,7 @@ q_param:.byte $04 ; param_count
; Final jump when we're done
done: jmp DOSWARM ; Potentially patched at runtime
- .segment "ZPSAVE"
+ .segment "INITBSS"
zpsave: .res zpspace
diff --git a/libsrc/apple2/initcwd.s b/libsrc/apple2/initcwd.s
index 044076e3f..7af29c75e 100644
--- a/libsrc/apple2/initcwd.s
+++ b/libsrc/apple2/initcwd.s
@@ -21,20 +21,21 @@ initcwd:
jsr callmli
; Check for null prefix
- lda __cwd
+ ldx __cwd
beq done
; Remove length byte and trailing slash
- sta tmp1
- ldx #$01
-: lda __cwd,x
- sta __cwd - 1,x
+ dex
+ stx tmp1
+ ldx #$00
+: lda __cwd + 1,x
+ sta __cwd,x
inx
cpx tmp1
bcc :-
; Add terminating zero
lda #$00
- sta __cwd - 1,x
+ sta __cwd,x
done: rts
diff --git a/libsrc/atari/initcwd.s b/libsrc/atari/initcwd.s
index 074b9476f..c292e72c3 100644
--- a/libsrc/atari/initcwd.s
+++ b/libsrc/atari/initcwd.s
@@ -21,13 +21,13 @@
sta ICBLH,x
jsr CIOV
bmi oserr
- ldx #0 ; ATEOL -> \0
-: lda __cwd,x
- inx
+ ldx #$FF ; ATEOL -> \0
+: inx
+ lda __cwd,x
cmp #ATEOL
bne :-
lda #0
- sta __cwd-1,x
+ sta __cwd,x
oserr: rts
.endproc