diff --git a/crt0.o b/crt0.o index f6703be..e0a0fd9 100644 Binary files a/crt0.o and b/crt0.o differ diff --git a/crt0.s b/crt0.s index 492179c..4dc7225 100644 --- a/crt0.s +++ b/crt0.s @@ -1,38 +1,53 @@ -.export _init, _exit -.exportzp sp -.import _main +; --------------------------------------------------------------------------- +; crt0.s +; --------------------------------------------------------------------------- +; +; Startup code for cc65 (Single Board Computer version) -.export __STARTUP__: absolute = 1 -.import __RAM_START__, __RAM_SIZE__ +.export _init, _exit +.import _main -.import copydata, zerobss, initlib, donelib +.export __STARTUP__ : absolute = 1 ; Mark as startup +.import __RAM_START__, __RAM_SIZE__ ; Linker generated -; .include "zeropage.inc" +.import copydata, zerobss, initlib, donelib -; reserve byte or sp -.segment "ZEROPAGE" -sp: .res 1 +.include "zeropage.inc" +; --------------------------------------------------------------------------- +; Place the startup code in a special segment +.segment "STARTUP" -.segment "STARTUP" +; --------------------------------------------------------------------------- +; A little light 6502 housekeeping -_init: ldx #$ff - txs - cld +_init: LDX #$FF ; Initialize stack pointer to $01FF + TXS + CLD ; Clear decimal mode - lda #<(__RAM_START__ + __RAM_SIZE__) - STA sp - lda #>(__RAM_START__ + __RAM_SIZE__) - STA sp+1 +; --------------------------------------------------------------------------- +; Set cc65 argument stack pointer - jsr zerobss - jsr copydata - jsr initlib + LDA #<(__RAM_START__ + __RAM_SIZE__) + STA sp + LDA #>(__RAM_START__ + __RAM_SIZE__) + STA sp+1 - jsr _main +; --------------------------------------------------------------------------- +; Initialize memory storage -_exit: - jsr donelib - brk + JSR zerobss ; Clear BSS segment + JSR copydata ; Initialize DATA segment + JSR initlib ; Run constructors +; --------------------------------------------------------------------------- +; Call main() + + JSR _main + +; --------------------------------------------------------------------------- +; Back from main (this is also the _exit entry): force a software break + +_exit: JSR donelib ; Run destructors + BRK \ No newline at end of file diff --git a/macro.sh b/macro.sh index 1df0023..b8cc8eb 100755 --- a/macro.sh +++ b/macro.sh @@ -1,6 +1,6 @@ -cc65 test.c -o test.s +cc65 -t none test.c -o test.s ca65 test.s -o test.o # ca65 startup.s -o startup.o -ca65 zeropage.s -o zeropage.o -ca65 crt0.s -o crt0.o -ld65 crt0.o zeropage.o test.o -o test -C test.cfg \ No newline at end of file +# ca65 zeropage.s -o zeropage.o +# ca65 crt0.s -o crt0.o +ld65 zeropage.o test.o sbc.lib -o test -C test.cfg \ No newline at end of file diff --git a/ref.txt b/ref.txt index 156bc69..cd1b831 100644 --- a/ref.txt +++ b/ref.txt @@ -2,4 +2,6 @@ https://www.qmtpro.com/~nes/misc/nestest.txt https://www.pagetable.com/?p=410 https://pegvin.github.io/6502/index.html https://www.westerndesigncenter.com/wdc/documentation/w65c02s.pdf -vasm6502_std -Fbin -Felf -mid=PC386 test.asm -o out \ No newline at end of file +vasm6502_std -Fbin -Felf -mid=PC386 test.asm -o out +https://cc65.github.io/doc/customizing.html#s1 +/usr/share/cc65 \ No newline at end of file diff --git a/sbc.lib b/sbc.lib new file mode 100644 index 0000000..1284bfc Binary files /dev/null and b/sbc.lib differ diff --git a/test.cfg b/test.cfg index a358fec..9e88781 100644 --- a/test.cfg +++ b/test.cfg @@ -7,7 +7,7 @@ MEMORY { SEGMENTS { ZEROPAGE: load = ZP, type = zp; - DATA: load = RAM, type = rw; + DATA: load = RAM, type = rw, run = RAM; CODE: load = ROM, type = ro; HEAP: load = RAM, type = rw optional = yes; INIT: load = ROM, type = ro optional = yes; @@ -19,6 +19,17 @@ SEGMENTS { # ONCE: load = ROM, type = ro, optional = yes; } +FEATURES { + CONDES: segment = STARTUP, + type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__; + CONDES: segment = STARTUP, + type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__; +} + SYMBOLS { __STACKSIZE__: type = weak, value = $0200; # __RAM_START__: type = weak, value = $0200; diff --git a/test.o b/test.o index d66b34c..15bdbf1 100644 Binary files a/test.o and b/test.o differ diff --git a/zeropage.o b/zeropage.o index 838d475..b1f2501 100644 Binary files a/zeropage.o and b/zeropage.o differ