From: Oliver Schmidt 
Date: Wed, 16 Mar 2016 15:28:32 +0000 (+0100)
Subject: Adjusted constructors.
X-Git-Tag: V2.16~160
X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1d1ba3ed3bf0b0b31e34601b7f40201589887537;p=cc65
Adjusted constructors.
The constructors are _NOT_ allowed anymore to access the BSS. Rather they must use the DATA segment or the INIT segment. The latter isn't cleared at any point so the constructors may use it to expose values to the main program. However they must make sure to always write the values as they are not pre-initialized.
---
diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg
index e5a574f0a..bb79a1e8a 100644
--- a/cfg/atmos.cfg
+++ b/cfg/atmos.cfg
@@ -8,10 +8,10 @@ SYMBOLS {
     __RAMEND__:    type = weak, value = $9800 + $1C00 * __GRAB__;
 }
 MEMORY {
-    ZP:      file = "", define = yes, start = $00E2, size = $001A;
-    TAPEHDR: file = %O, type   = ro,  start = $0000, size = $001F;
-    BASHEAD: file = %O, define = yes, start = $0501, size = $000D;
-    MAIN:    file = %O, define = yes, start = __BASHEAD_LAST__, size = __RAMEND__ - __RAM_START__ - __STACKSIZE__;
+    ZP:      file = "", define = yes, start = $00E2,            size = $001A;
+    TAPEHDR: file = %O, type   = ro,  start = $0000,            size = $001F;
+    BASHEAD: file = %O, define = yes, start = $0501,            size = $000D;
+    MAIN:    file = %O, define = yes, start = __BASHEAD_LAST__, size = __RAMEND__ - __MAIN_START__ - __STACKSIZE__;
 }
 SEGMENTS {
     ZEROPAGE: load = ZP,      type = zp;
@@ -21,8 +21,9 @@ SEGMENTS {
     LOWCODE:  load = MAIN,    type = ro,                optional = yes;
     CODE:     load = MAIN,    type = ro;
     RODATA:   load = MAIN,    type = ro;
-    ONCE:     load = MAIN,    type = ro,  define = yes, optional = yes;
+    ONCE:     load = MAIN,    type = ro,                optional = yes;
     DATA:     load = MAIN,    type = rw;
+    INIT:     load = MAIN,    type = rw,                optional = yes;
     ZPSAVE1:  load = MAIN,    type = rw,  define = yes; # ZPSAVE1, ZPSAVE2 must be together
     ZPSAVE2:  load = MAIN,    type = bss;               # see "libsrc/atmos/crt0.s"
     BSS:      load = MAIN,    type = bss, define = yes;
diff --git a/cfg/geos-apple.cfg b/cfg/geos-apple.cfg
index 9fc7024e1..b39cf1ebe 100644
--- a/cfg/geos-apple.cfg
+++ b/cfg/geos-apple.cfg
@@ -44,6 +44,7 @@ SEGMENTS {
     CODE:      type = ro,  run  = VLIR0,  load = CVT;
     RODATA:    type = ro,  run  = VLIR0,  load = CVT;
     DATA:      type = rw,  run  = VLIR0,  load = CVT;
+    INIT:      type = bss, load = VLIR0,                                 optional = yes;
     BSS:       type = bss, load = VLIR0,              define     = yes;
     VLIRIDX1:  type = ro,                 load = CVT, align      = $200, optional = yes;
     OVERLAY1:  type = ro,  run  = VLIR1,  load = CVT, align_load = $200, optional = yes;
diff --git a/cfg/geos-cbm.cfg b/cfg/geos-cbm.cfg
index f9bea76a0..0269dbacb 100644
--- a/cfg/geos-cbm.cfg
+++ b/cfg/geos-cbm.cfg
@@ -41,6 +41,7 @@ SEGMENTS {
     CODE:      type = ro,  run  = VLIR0,  load = CVT;
     RODATA:    type = ro,  run  = VLIR0,  load = CVT;
     DATA:      type = rw,  run  = VLIR0,  load = CVT;
+    INIT:      type = bss, load = VLIR0,                                optional = yes;
     BSS:       type = bss, load = VLIR0,              define     = yes;
     OVERLAY1:  type = ro,  run  = VLIR1,  load = CVT, align_load = $FE, optional = yes;
     OVERLAY2:  type = ro,  run  = VLIR2,  load = CVT, align_load = $FE, optional = yes;
diff --git a/libsrc/apple2/dosdetect.s b/libsrc/apple2/dosdetect.s
index cedb1f3e3..46fbb5484 100644
--- a/libsrc/apple2/dosdetect.s
+++ b/libsrc/apple2/dosdetect.s
@@ -43,6 +43,6 @@ initdostype:
 :       sta     __dos_type
 done:   rts
 
-        .bss
+        .data
 
-__dos_type:     .res    1
+__dos_type:     .byte   $00
diff --git a/libsrc/apple2/extra/iobuf-0800.s b/libsrc/apple2/extra/iobuf-0800.s
index 2e5d1927e..0ad7a751f 100644
--- a/libsrc/apple2/extra/iobuf-0800.s
+++ b/libsrc/apple2/extra/iobuf-0800.s
@@ -90,6 +90,6 @@ iobuf_free:
 
 ; ------------------------------------------------------------------------
 
-        .bss
+        .data
 
 table:  .res    MAX_FDS
diff --git a/libsrc/apple2/get_ostype.s b/libsrc/apple2/get_ostype.s
index cff6af9a3..b54e38d63 100644
--- a/libsrc/apple2/get_ostype.s
+++ b/libsrc/apple2/get_ostype.s
@@ -65,6 +65,6 @@ _get_ostype:
         ldx     #$00
         rts
 
-        .bss
+        .segment        "INIT"
 
 ostype: .res    1
diff --git a/libsrc/apple2/mainargs.s b/libsrc/apple2/mainargs.s
index e3db8bb10..de2f385f1 100644
--- a/libsrc/apple2/mainargs.s
+++ b/libsrc/apple2/mainargs.s
@@ -83,6 +83,7 @@ initmainargs:
 ; destroyed.
 
         ldy     #$00
+        sty     buffer + BUF_LEN - 1
 :       lda     BASIC_BUF,x
         sta     buffer,y
         inx
@@ -166,14 +167,13 @@ done:   lda     #$0000
         adc     #>args
         sta     argv+1,y
@@ -99,7 +99,7 @@ argloop:lda     BASIC_BUF,x
 ; A contains the terminating character. To make the argument a valid C string,
 ; replace the terminating character by a zero.
 
-        lda     #$00
+        lda     #0
         sta     args-1,x
 
 ; Check if the maximum number of command line arguments is reached. If not,
@@ -120,14 +120,16 @@ done:   lda     #,0
+; , 0
 ; or
 ; , , , 0
 ; the 2nd case is when using DeskTop user drags an icon of a file and drops it
@@ -71,7 +71,7 @@ argv:
         .word dataDiskName      ; dataDiskName
         .word $0000             ; last one must be NULL
 
-.bss
+.segment        "INIT"
 
 argv0:
         .res 17                 ; Program name