From b237bb9d9a83bb93fb86ebbb155e0611b425c03c Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Mon, 6 Jan 2014 20:24:29 +0100 Subject: [PATCH 01/10] Add support to create cartridges. --- cfg/atari-cart.cfg | 43 ++++++++++++++++++++++++++ libsrc/atari/carthdr.s | 20 ++++++++++++ libsrc/atari/cartinit.s | 13 ++++++++ libsrc/atari/cartstart.s | 67 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 cfg/atari-cart.cfg create mode 100644 libsrc/atari/carthdr.s create mode 100644 libsrc/atari/cartinit.s create mode 100644 libsrc/atari/cartstart.s diff --git a/cfg/atari-cart.cfg b/cfg/atari-cart.cfg new file mode 100644 index 000000000..cf6472656 --- /dev/null +++ b/cfg/atari-cart.cfg @@ -0,0 +1,43 @@ +FEATURES { + STARTADDRESS: default = $2000; +} +SYMBOLS { + __CART_HEADER__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __STARTADDRESS__: type = export, value = %S; + __RESERVED_MEMORY__: type = export, value = $0000; + __CARTFLAGS__: type = weak, value = $01; # see documentation for other possible values +} +MEMORY { + ZP: file = "", define = yes, start = $0082, size = $007E; + RAM: file = "", define = yes, start = %S, size = $2000; + ROM: file = %O, define = yes, start = $A000, size = $1FFA, fill = yes, fillval = $ff; + CARTID: file = %O, start = $BFFA, size = $0006; +} +SEGMENTS { + STARTUP: load = ROM, type = ro, define = yes; + LOWCODE: load = ROM, type = ro, define = yes, optional = yes; + INIT: load = ROM, type = ro, optional = yes; + CODE: load = ROM, type = ro, define = yes; + RODATA: load = ROM, type = ro; + DATA: load = ROM, run = RAM, type = rw, define = yes; + BSS: load = RAM, type = bss, define = yes; + CARTHDR: load = CARTID, type = ro; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; +} +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = INIT; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; +} diff --git a/libsrc/atari/carthdr.s b/libsrc/atari/carthdr.s new file mode 100644 index 000000000..7ec2fc9a6 --- /dev/null +++ b/libsrc/atari/carthdr.s @@ -0,0 +1,20 @@ +; Cartridge "header" +; (In fact, it's at the end of the cartridge, so more a "trailer".) +; +; Christian Groessler, 06-Jan-2014 + +.ifndef __ATARIXL__ + +.import __CARTFLAGS__, cartinit, cartstart +.export __CART_HEADER__: absolute = 1 + +.include "atari.inc" + + .segment "CARTHDR" + + .word cartstart ; start routine + .byte 0 ; must be zero + .byte <__CARTFLAGS__ + .word cartinit ; init routine + +.endif ; .ifndef __ATARIXL__ diff --git a/libsrc/atari/cartinit.s b/libsrc/atari/cartinit.s new file mode 100644 index 000000000..5930c62ec --- /dev/null +++ b/libsrc/atari/cartinit.s @@ -0,0 +1,13 @@ +; Cartridge init routine +; +; Christian Groessler, 06-Jan-2014 + +.ifndef __ATARIXL__ + +.export cartinit + +.segment "STARTUP" + +cartinit: rts + +.endif ; .ifndef __ATARIXL__ diff --git a/libsrc/atari/cartstart.s b/libsrc/atari/cartstart.s new file mode 100644 index 000000000..60771d54f --- /dev/null +++ b/libsrc/atari/cartstart.s @@ -0,0 +1,67 @@ +; Cartridge start routine +; +; Christian Groessler, 06-Jan-2014 + +.ifndef __ATARIXL__ + +.export cartstart + +.import start +.import __DATA_LOAD__, __DATA_SIZE__, __DATA_RUN__ +.importzp ptr1, ptr2, tmp1, tmp2 + +.include "atari.inc" + +.segment "STARTUP" + +; start routine of cartridge +; copy data segment to RAM and chain to entry point of crt0.s + +cartstart: lda #<__DATA_LOAD__ + sta ptr1 + lda #>__DATA_LOAD__ + sta ptr1+1 + lda #<__DATA_RUN__ + sta ptr2 + lda #>__DATA_RUN__ + sta ptr2+1 + lda #>__DATA_SIZE__ + sta tmp2 + lda #<__DATA_SIZE__ + sta tmp1 + jsr memcopy + jsr start ; run program + jmp (DOSVEC) ; return to DOS + + +; routine taken from http://www.obelisk.demon.co.uk/6502/algorithms.html +; +; copy memory +; ptr1 - source +; ptr2 - destination +; tmp2:tmp1 - len + +.proc memcopy + + ldy #0 + ldx tmp2 + beq last +pagecp: lda (ptr1),y + sta (ptr2),y + iny + bne pagecp + inc ptr1+1 + inc ptr2+1 + dex + bne pagecp +last: cpy tmp1 + beq done + lda (ptr1),y + sta (ptr2),y + iny + bne last +done: rts + +.endproc + +.endif ; .ifndef __ATARIXL__ From 692ec4a05bdaaa94154083ca47dd7fc317472c72 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 14 Jan 2014 23:12:35 +0100 Subject: [PATCH 02/10] remove TABs --- libsrc/atari/carthdr.s | 18 ++++----- libsrc/atari/cartinit.s | 8 ++-- libsrc/atari/cartstart.s | 86 ++++++++++++++++++++-------------------- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/libsrc/atari/carthdr.s b/libsrc/atari/carthdr.s index 7ec2fc9a6..52dc42053 100644 --- a/libsrc/atari/carthdr.s +++ b/libsrc/atari/carthdr.s @@ -5,16 +5,16 @@ .ifndef __ATARIXL__ -.import __CARTFLAGS__, cartinit, cartstart -.export __CART_HEADER__: absolute = 1 +.import __CARTFLAGS__, cartinit, cartstart +.export __CART_HEADER__: absolute = 1 -.include "atari.inc" +.include "atari.inc" - .segment "CARTHDR" + .segment "CARTHDR" - .word cartstart ; start routine - .byte 0 ; must be zero - .byte <__CARTFLAGS__ - .word cartinit ; init routine + .word cartstart ; start routine + .byte 0 ; must be zero + .byte <__CARTFLAGS__ + .word cartinit ; init routine -.endif ; .ifndef __ATARIXL__ +.endif ; .ifndef __ATARIXL__ diff --git a/libsrc/atari/cartinit.s b/libsrc/atari/cartinit.s index 5930c62ec..a0f235625 100644 --- a/libsrc/atari/cartinit.s +++ b/libsrc/atari/cartinit.s @@ -4,10 +4,10 @@ .ifndef __ATARIXL__ -.export cartinit +.export cartinit -.segment "STARTUP" +.segment "STARTUP" -cartinit: rts +cartinit: rts -.endif ; .ifndef __ATARIXL__ +.endif ; .ifndef __ATARIXL__ diff --git a/libsrc/atari/cartstart.s b/libsrc/atari/cartstart.s index 60771d54f..30723ef60 100644 --- a/libsrc/atari/cartstart.s +++ b/libsrc/atari/cartstart.s @@ -4,64 +4,64 @@ .ifndef __ATARIXL__ -.export cartstart +.export cartstart -.import start -.import __DATA_LOAD__, __DATA_SIZE__, __DATA_RUN__ -.importzp ptr1, ptr2, tmp1, tmp2 +.import start +.import __DATA_LOAD__, __DATA_SIZE__, __DATA_RUN__ +.importzp ptr1, ptr2, tmp1, tmp2 -.include "atari.inc" +.include "atari.inc" -.segment "STARTUP" +.segment "STARTUP" ; start routine of cartridge ; copy data segment to RAM and chain to entry point of crt0.s -cartstart: lda #<__DATA_LOAD__ - sta ptr1 - lda #>__DATA_LOAD__ - sta ptr1+1 - lda #<__DATA_RUN__ - sta ptr2 - lda #>__DATA_RUN__ - sta ptr2+1 - lda #>__DATA_SIZE__ - sta tmp2 - lda #<__DATA_SIZE__ - sta tmp1 - jsr memcopy - jsr start ; run program - jmp (DOSVEC) ; return to DOS +cartstart: lda #<__DATA_LOAD__ + sta ptr1 + lda #>__DATA_LOAD__ + sta ptr1+1 + lda #<__DATA_RUN__ + sta ptr2 + lda #>__DATA_RUN__ + sta ptr2+1 + lda #>__DATA_SIZE__ + sta tmp2 + lda #<__DATA_SIZE__ + sta tmp1 + jsr memcopy + jsr start ; run program + jmp (DOSVEC) ; return to DOS ; routine taken from http://www.obelisk.demon.co.uk/6502/algorithms.html ; ; copy memory -; ptr1 - source -; ptr2 - destination +; ptr1 - source +; ptr2 - destination ; tmp2:tmp1 - len -.proc memcopy +.proc memcopy - ldy #0 - ldx tmp2 - beq last -pagecp: lda (ptr1),y - sta (ptr2),y - iny - bne pagecp - inc ptr1+1 - inc ptr2+1 - dex - bne pagecp -last: cpy tmp1 - beq done - lda (ptr1),y - sta (ptr2),y - iny - bne last -done: rts + ldy #0 + ldx tmp2 + beq last +pagecp: lda (ptr1),y + sta (ptr2),y + iny + bne pagecp + inc ptr1+1 + inc ptr2+1 + dex + bne pagecp +last: cpy tmp1 + beq done + lda (ptr1),y + sta (ptr2),y + iny + bne last +done: rts .endproc -.endif ; .ifndef __ATARIXL__ +.endif ; .ifndef __ATARIXL__ From 94df0e8ef421aa20eb4ba19bd8f4ef0376a879e8 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 16 Jan 2014 23:45:21 +0100 Subject: [PATCH 03/10] made more segments optional so that the config file can be used for assembler programs, too --- cfg/atari-cart.cfg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cfg/atari-cart.cfg b/cfg/atari-cart.cfg index cf6472656..04934309b 100644 --- a/cfg/atari-cart.cfg +++ b/cfg/atari-cart.cfg @@ -11,17 +11,17 @@ SYMBOLS { MEMORY { ZP: file = "", define = yes, start = $0082, size = $007E; RAM: file = "", define = yes, start = %S, size = $2000; - ROM: file = %O, define = yes, start = $A000, size = $1FFA, fill = yes, fillval = $ff; + ROM: file = %O, define = yes, start = $A000, size = $1FFA, fill = yes, fillval = $FF; CARTID: file = %O, start = $BFFA, size = $0006; } SEGMENTS { - STARTUP: load = ROM, type = ro, define = yes; + STARTUP: load = ROM, type = ro, define = yes, optional = yes; LOWCODE: load = ROM, type = ro, define = yes, optional = yes; INIT: load = ROM, type = ro, optional = yes; CODE: load = ROM, type = ro, define = yes; - RODATA: load = ROM, type = ro; - DATA: load = ROM, run = RAM, type = rw, define = yes; - BSS: load = RAM, type = bss, define = yes; + RODATA: load = ROM, type = ro; optional = yes; + DATA: load = ROM, run = RAM, type = rw, define = yes; optional = yes; + BSS: load = RAM, type = bss, define = yes; optional = yes; CARTHDR: load = CARTID, type = ro; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; From dcbefb10186d2363e38dc02c5813c7be8bf6aa0c Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 16 Jan 2014 23:45:48 +0100 Subject: [PATCH 04/10] fix indentation --- libsrc/atari/carthdr.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/atari/carthdr.s b/libsrc/atari/carthdr.s index 52dc42053..3e4ea219c 100644 --- a/libsrc/atari/carthdr.s +++ b/libsrc/atari/carthdr.s @@ -10,7 +10,7 @@ .include "atari.inc" - .segment "CARTHDR" +.segment "CARTHDR" .word cartstart ; start routine .byte 0 ; must be zero From 5a404b678621e4e7c9869f0b7e5e97e7ea8e4efc Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 16 Jan 2014 23:49:04 +0100 Subject: [PATCH 05/10] fix last change --- cfg/atari-cart.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cfg/atari-cart.cfg b/cfg/atari-cart.cfg index 04934309b..ab84f98fc 100644 --- a/cfg/atari-cart.cfg +++ b/cfg/atari-cart.cfg @@ -19,9 +19,9 @@ SEGMENTS { LOWCODE: load = ROM, type = ro, define = yes, optional = yes; INIT: load = ROM, type = ro, optional = yes; 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; - BSS: load = RAM, type = bss, define = yes; optional = yes; + RODATA: load = ROM, type = ro, optional = yes; + DATA: load = ROM, run = RAM, type = rw, define = yes, optional = yes; + BSS: load = RAM, type = bss, define = yes, optional = yes; CARTHDR: load = CARTID, type = ro; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; From fd4d7d93ea28ddecee29f6b114a73383be200a55 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 16 Jan 2014 23:49:51 +0100 Subject: [PATCH 06/10] put this module's code into CODE segment --- libsrc/atari/cartstart.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/atari/cartstart.s b/libsrc/atari/cartstart.s index 30723ef60..47c1d89b7 100644 --- a/libsrc/atari/cartstart.s +++ b/libsrc/atari/cartstart.s @@ -12,7 +12,7 @@ .include "atari.inc" -.segment "STARTUP" +.segment "CODE" ; start routine of cartridge ; copy data segment to RAM and chain to entry point of crt0.s From b292597f1e80c677e473ec6ba9b71bcbeee2ae77 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 16 Jan 2014 23:53:53 +0100 Subject: [PATCH 07/10] use copydata instead of own routine --- libsrc/atari/cartstart.s | 48 ++-------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/libsrc/atari/cartstart.s b/libsrc/atari/cartstart.s index 47c1d89b7..ce403b5fb 100644 --- a/libsrc/atari/cartstart.s +++ b/libsrc/atari/cartstart.s @@ -6,8 +6,7 @@ .export cartstart -.import start -.import __DATA_LOAD__, __DATA_SIZE__, __DATA_RUN__ +.import start, copydata .importzp ptr1, ptr2, tmp1, tmp2 .include "atari.inc" @@ -17,51 +16,8 @@ ; start routine of cartridge ; copy data segment to RAM and chain to entry point of crt0.s -cartstart: lda #<__DATA_LOAD__ - sta ptr1 - lda #>__DATA_LOAD__ - sta ptr1+1 - lda #<__DATA_RUN__ - sta ptr2 - lda #>__DATA_RUN__ - sta ptr2+1 - lda #>__DATA_SIZE__ - sta tmp2 - lda #<__DATA_SIZE__ - sta tmp1 - jsr memcopy +cartstart: jsr copydata jsr start ; run program jmp (DOSVEC) ; return to DOS - -; routine taken from http://www.obelisk.demon.co.uk/6502/algorithms.html -; -; copy memory -; ptr1 - source -; ptr2 - destination -; tmp2:tmp1 - len - -.proc memcopy - - ldy #0 - ldx tmp2 - beq last -pagecp: lda (ptr1),y - sta (ptr2),y - iny - bne pagecp - inc ptr1+1 - inc ptr2+1 - dex - bne pagecp -last: cpy tmp1 - beq done - lda (ptr1),y - sta (ptr2),y - iny - bne last -done: rts - -.endproc - .endif ; .ifndef __ATARIXL__ From e6ed33505625db58fb4debe812d0ca490e66c0e2 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 17 Jan 2014 11:46:55 +0100 Subject: [PATCH 08/10] put code in CODE segment --- libsrc/atari/cartinit.s | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsrc/atari/cartinit.s b/libsrc/atari/cartinit.s index a0f235625..d3035d60c 100644 --- a/libsrc/atari/cartinit.s +++ b/libsrc/atari/cartinit.s @@ -6,8 +6,6 @@ .export cartinit -.segment "STARTUP" - cartinit: rts .endif ; .ifndef __ATARIXL__ From 2e44abf928e2fb7d6812f0330a39706f98c87f2d Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 17 Jan 2014 11:47:23 +0100 Subject: [PATCH 09/10] remove segment directive since CODE is the default segment --- libsrc/atari/cartstart.s | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsrc/atari/cartstart.s b/libsrc/atari/cartstart.s index ce403b5fb..eeac8933b 100644 --- a/libsrc/atari/cartstart.s +++ b/libsrc/atari/cartstart.s @@ -11,8 +11,6 @@ .include "atari.inc" -.segment "CODE" - ; start routine of cartridge ; copy data segment to RAM and chain to entry point of crt0.s From 40e49074a495aa77a7a6388361ead9b3ae6fc980 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 17 Jan 2014 20:08:41 +0100 Subject: [PATCH 10/10] add support for 16K cartridges --- cfg/atari-cart.cfg | 9 +++++---- libsrc/atari/carthdr.s | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cfg/atari-cart.cfg b/cfg/atari-cart.cfg index ab84f98fc..10674dc49 100644 --- a/cfg/atari-cart.cfg +++ b/cfg/atari-cart.cfg @@ -2,6 +2,7 @@ FEATURES { STARTADDRESS: default = $2000; } SYMBOLS { + __CARTSIZE__: type = weak, value = $2000; # possible values: $2000 and $4000 __CART_HEADER__: type = import; __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; @@ -9,10 +10,10 @@ SYMBOLS { __CARTFLAGS__: type = weak, value = $01; # see documentation for other possible values } MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; - RAM: file = "", define = yes, start = %S, size = $2000; - ROM: file = %O, define = yes, start = $A000, size = $1FFA, fill = yes, fillval = $FF; - CARTID: file = %O, start = $BFFA, size = $0006; + ZP: file = "", define = yes, start = $0082, size = $007E; + RAM: file = "", define = yes, start = %S, size = __CARTSIZE__; + ROM: file = %O, define = yes, start = $C000 - __CARTSIZE__, size = __CARTSIZE__ - 6, fill = yes, fillval = $FF; + CARTID: file = %O, start = $BFFA, size = $0006; } SEGMENTS { STARTUP: load = ROM, type = ro, define = yes, optional = yes; diff --git a/libsrc/atari/carthdr.s b/libsrc/atari/carthdr.s index 3e4ea219c..bda11c06b 100644 --- a/libsrc/atari/carthdr.s +++ b/libsrc/atari/carthdr.s @@ -5,7 +5,7 @@ .ifndef __ATARIXL__ -.import __CARTFLAGS__, cartinit, cartstart +.import __CARTSIZE__, __CARTFLAGS__, cartinit, cartstart .export __CART_HEADER__: absolute = 1 .include "atari.inc" @@ -17,4 +17,6 @@ .byte <__CARTFLAGS__ .word cartinit ; init routine +.assert (__CARTSIZE__ = $2000 || __CARTSIZE__ = $4000), error, "Cartridge size must either be $2000 or $4000" + .endif ; .ifndef __ATARIXL__