1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-15 17:30:06 +00:00

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.
This commit is contained in:
Oliver Schmidt 2016-03-16 16:28:32 +01:00
parent 3d6cbec6a1
commit 1d1ba3ed3b
16 changed files with 49 additions and 55 deletions

View File

@ -8,10 +8,10 @@ SYMBOLS {
__RAMEND__: type = weak, value = $9800 + $1C00 * __GRAB__; __RAMEND__: type = weak, value = $9800 + $1C00 * __GRAB__;
} }
MEMORY { MEMORY {
ZP: file = "", define = yes, start = $00E2, size = $001A; ZP: file = "", define = yes, start = $00E2, size = $001A;
TAPEHDR: file = %O, type = ro, start = $0000, size = $001F; TAPEHDR: file = %O, type = ro, start = $0000, size = $001F;
BASHEAD: file = %O, define = yes, start = $0501, size = $000D; BASHEAD: file = %O, define = yes, start = $0501, size = $000D;
MAIN: file = %O, define = yes, start = __BASHEAD_LAST__, size = __RAMEND__ - __RAM_START__ - __STACKSIZE__; MAIN: file = %O, define = yes, start = __BASHEAD_LAST__, size = __RAMEND__ - __MAIN_START__ - __STACKSIZE__;
} }
SEGMENTS { SEGMENTS {
ZEROPAGE: load = ZP, type = zp; ZEROPAGE: load = ZP, type = zp;
@ -21,8 +21,9 @@ SEGMENTS {
LOWCODE: load = MAIN, type = ro, optional = yes; LOWCODE: load = MAIN, type = ro, optional = yes;
CODE: load = MAIN, type = ro; CODE: load = MAIN, type = ro;
RODATA: 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; DATA: load = MAIN, type = rw;
INIT: load = MAIN, type = rw, optional = yes;
ZPSAVE1: load = MAIN, type = rw, define = yes; # ZPSAVE1, ZPSAVE2 must be together ZPSAVE1: load = MAIN, type = rw, define = yes; # ZPSAVE1, ZPSAVE2 must be together
ZPSAVE2: load = MAIN, type = bss; # see "libsrc/atmos/crt0.s" ZPSAVE2: load = MAIN, type = bss; # see "libsrc/atmos/crt0.s"
BSS: load = MAIN, type = bss, define = yes; BSS: load = MAIN, type = bss, define = yes;

View File

@ -44,6 +44,7 @@ SEGMENTS {
CODE: type = ro, run = VLIR0, load = CVT; CODE: type = ro, run = VLIR0, load = CVT;
RODATA: type = ro, run = VLIR0, load = CVT; RODATA: type = ro, run = VLIR0, load = CVT;
DATA: type = rw, 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; BSS: type = bss, load = VLIR0, define = yes;
VLIRIDX1: type = ro, load = CVT, align = $200, optional = yes; VLIRIDX1: type = ro, load = CVT, align = $200, optional = yes;
OVERLAY1: type = ro, run = VLIR1, load = CVT, align_load = $200, optional = yes; OVERLAY1: type = ro, run = VLIR1, load = CVT, align_load = $200, optional = yes;

View File

@ -41,6 +41,7 @@ SEGMENTS {
CODE: type = ro, run = VLIR0, load = CVT; CODE: type = ro, run = VLIR0, load = CVT;
RODATA: type = ro, run = VLIR0, load = CVT; RODATA: type = ro, run = VLIR0, load = CVT;
DATA: type = rw, 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; BSS: type = bss, load = VLIR0, define = yes;
OVERLAY1: type = ro, run = VLIR1, load = CVT, align_load = $FE, optional = 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; OVERLAY2: type = ro, run = VLIR2, load = CVT, align_load = $FE, optional = yes;

View File

@ -43,6 +43,6 @@ initdostype:
: sta __dos_type : sta __dos_type
done: rts done: rts
.bss .data
__dos_type: .res 1 __dos_type: .byte $00

View File

@ -90,6 +90,6 @@ iobuf_free:
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
.bss .data
table: .res MAX_FDS table: .res MAX_FDS

View File

@ -65,6 +65,6 @@ _get_ostype:
ldx #$00 ldx #$00
rts rts
.bss .segment "INIT"
ostype: .res 1 ostype: .res 1

View File

@ -83,6 +83,7 @@ initmainargs:
; destroyed. ; destroyed.
ldy #$00 ldy #$00
sty buffer + BUF_LEN - 1
: lda BASIC_BUF,x : lda BASIC_BUF,x
sta buffer,y sta buffer,y
inx inx
@ -166,14 +167,13 @@ done: lda #<argv
stx __argv+1 stx __argv+1
rts rts
; This array is zeroed before initmainargs is called.
; char* argv[MAXARGS+1] = {FNAM};
.data .data
; char* argv[MAXARGS+1] = {FNAM};
argv: .addr FNAM argv: .addr FNAM
.res MAXARGS * 2 .res MAXARGS * 2
.bss .segment "INIT"
buffer: .res BUF_LEN buffer: .res BUF_LEN

View File

@ -48,6 +48,6 @@ done: rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Data ; Data
.bss .data
__dos_type: .res 1 ; default to ATARIDOS __dos_type: .byte 0 ; default to ATARIDOS

View File

@ -23,12 +23,6 @@ SPACE = 32 ; SPACE char.
.segment "ONCE" .segment "ONCE"
initmainargs: initmainargs:
lda #0
sta __argc
sta __argc+1
sta __argv
sta __argv+1
lda __dos_type ; which DOS? lda __dos_type ; which DOS?
cmp #ATARIDOS cmp #ATARIDOS
beq nargdos ; DOS does not support arguments beq nargdos ; DOS does not support arguments
@ -120,7 +114,7 @@ eopar:
finargs: finargs:
lda __argc lda __argc
asl asl
tax tax
lda #0 lda #0
sta argv,x sta argv,x
@ -134,7 +128,7 @@ finargs:
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
; Data ; Data
.bss .segment "INIT"
argv: .res (1 + MAXARGS) * 2 argv: .res (1 + MAXARGS) * 2

View File

@ -43,7 +43,7 @@ restore_caps:
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
.bss .segment "INIT"
capsave: capsave:
.res 1 .res 1

View File

@ -13,7 +13,7 @@
.macpack generic .macpack generic
MAXARGS = 10 ; Maximum number of arguments allowed MAXARGS = 10 ; Maximum number of arguments allowed
REM = $9d ; BASIC token-code REM = $9D ; BASIC token-code
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
@ -26,21 +26,21 @@ REM = $9d ; BASIC token-code
; Assume that the program was loaded, a moment ago, by the traditional LOAD ; Assume that the program was loaded, a moment ago, by the traditional LOAD
; statement. Save the "most-recent filename" as argument #0. ; statement. Save the "most-recent filename" as argument #0.
; Because the buffer, that we're copying into, was zeroed out,
; we don't need to add a NUL character. ldy #FNAME_LEN ; Limit the length
; lda #0 ; The terminating NUL character
ldy #FNAME_LEN - 1 ; limit the length beq L1 ; Branch always
L0: lda CFOUND_NAME,y L0: lda CFOUND_NAME,y
sta name,y L1: sta name,y
dey dey
bpl L0 bpl L0
inc __argc ; argc always is equal to, at least, 1 inc __argc ; argc always is equal to, at least, 1
; Find the "rem" token. ; Find the "rem" token.
;
ldx #0 ldx #0
L2: lda BASIC_BUF,x L2: lda BASIC_BUF,x
beq done ; no "rem", no args. beq done ; No "rem", no args.
inx inx
cmp #REM cmp #REM
bne L2 bne L2
@ -62,7 +62,7 @@ next: lda BASIC_BUF,x
beq done ; End of line reached beq done ; End of line reached
inx inx
cmp #' ' ; Skip leading spaces cmp #' ' ; Skip leading spaces
beq next ; beq next
; Found start of next argument. We've incremented the pointer in X already, so ; Found start of next argument. We've incremented the pointer in X already, so
; it points to the second character of the argument. This is useful since we ; it points to the second character of the argument. This is useful since we
@ -79,7 +79,7 @@ setterm:sta term ; Set end of argument marker
txa ; Get low byte txa ; Get low byte
add #<args add #<args
sta argv,y ; argv[y]= &arg sta argv,y ; argv[y]=&arg
lda #>$0000 lda #>$0000
adc #>args adc #>args
sta argv+1,y 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, ; A contains the terminating character. To make the argument a valid C string,
; replace the terminating character by a zero. ; replace the terminating character by a zero.
lda #$00 lda #0
sta args-1,x sta args-1,x
; Check if the maximum number of command line arguments is reached. If not, ; Check if the maximum number of command line arguments is reached. If not,
@ -120,14 +120,16 @@ done: lda #<argv
.endproc .endproc
; These arrays are zeroed before initmainargs is called. ; These arrays are zeroed before initmainargs is called.
; char name[16+1];
; char* argv[MAXARGS+1]={name}; .segment "INIT"
;
.bss
term: .res 1 term: .res 1
name: .res FNAME_LEN + 1 name: .res FNAME_LEN + 1
args: .res SCREEN_XSIZE * 2 - 1 args: .res SCREEN_XSIZE * 2 - 1
.data .data
; char* argv[MAXARGS+1]={name};
argv: .addr name argv: .addr name
.res MAXARGS * 2, $00 .res MAXARGS * 2

View File

@ -79,8 +79,7 @@ initstdin:
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
.bss .segment "INIT"
text_count: text_count:
.res 1 .res 1

View File

@ -39,7 +39,7 @@ L2: jsr KBDREAD ; Read char and return in A
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
; Module constructor/destructor ; Module constructor/destructor
.bss .segment "INIT"
keyvec: .res 2 keyvec: .res 2
.segment "ONCE" .segment "ONCE"
@ -48,9 +48,9 @@ initcgetc:
; Save the old vector ; Save the old vector
lda KeyStoreVec lda KeyStoreVec
ldx KeyStoreVec+1
sta keyvec sta keyvec
lda KeyStoreVec+1 stx keyvec+1
sta keyvec+1
; Set the new vector. I can only hope that this works for other C128 ; Set the new vector. I can only hope that this works for other C128
; versions... ; versions...
@ -68,5 +68,3 @@ SetVec: sei
stx KeyStoreVec+1 stx KeyStoreVec+1
cli cli
rts rts

View File

@ -15,10 +15,10 @@
.export __environ, __envcount, __envsize .export __environ, __envcount, __envsize
.import initenv .import initenv
.constructor env_init .constructor env_init
env_init := initenv env_init := initenv
.bss .data
__environ: __environ:
.addr 0 .addr 0
@ -26,5 +26,3 @@ __envcount:
.byte 0 .byte 0
__envsize: __envsize:
.byte 0 .byte 0

View File

@ -43,7 +43,7 @@ screensize:
ldy ysize ldy ysize
rts rts
.bss .segment "INIT"
xsize: xsize:
.res 1 .res 1

View File

@ -5,7 +5,7 @@
; Setup arguments for main ; Setup arguments for main
; ;
; There is always either 1 or 3 arguments: ; There is always either 1 or 3 arguments:
; <program name>,0 ; <program name>, 0
; or ; or
; <program name>, <data file name>, <data disk name>, 0 ; <program name>, <data file name>, <data disk name>, 0
; the 2nd case is when using DeskTop user drags an icon of a file and drops it ; 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 dataDiskName ; dataDiskName
.word $0000 ; last one must be NULL .word $0000 ; last one must be NULL
.bss .segment "INIT"
argv0: argv0:
.res 17 ; Program name .res 17 ; Program name