From 34cf7657e8a9d07a8cc4692cabd47acb9aeda112 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 30 May 2013 02:26:15 +0200 Subject: [PATCH 001/144] Add two load chunks: - First chunk checks system (if it's XL and memory is ok). - Second chunk contains the contents for the shadow memory beneath the ROM and copies the contents to their destination address. It also moves the screen memory to low memory in front of the program. --- cfg/atarixl.cfg | 70 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 975d16213..cbd31bfe6 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -1,29 +1,67 @@ FEATURES { STARTADDRESS: default = $2E00; } + SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __RESERVED_MEMORY__: type = weak, value = $0000; + syschk: type = import; # force inclusion of SYSCHK + sramprep: type = import; # force inclusion of SRPREP } + MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; - HEADER: file = %O, start = $0000, size = $0006; - RAM: file = %O, start = %S, size = $BC20 - __STACKSIZE__ - %S; - TRAILER: file = %O, start = $0000, size = $0006; + ZP: file = "", define = yes, start = $0082, size = $007E; + +# just $FFFF + HEADER: file = %O, start = $0000, size = $0002; + +# "system check" load chunk + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHK: file = %O, start = $2E00, size = $0E00; + +# "shadow RAM preparation" load chunk + SRPREPHDR: file = %O, start = $0000, size = $0004; + SRPREP: file = %O, start = %S, size = $7C20 - %S - $04FF; # $04FF: space for temp. chargen buffer, page aligned + SRPREPTRL: file = %O, start = $0000, size = $0006; + +# "main program" load chunk + MAINHDR: file = %O, start = $0000, size = $0004; + RAM: file = %O, start = %S + __SAVEAREA_SIZE__, size = $D000 - __STACKSIZE__ - %S - __SAVEAREA_SIZE__; + +# address of relocated character generator + CHARGEN: file = "", define = yes, start = $D800, size = $0400; + +# memory beneath the ROM + SHADOW_RAM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; + +# defines entry point into program + TRAILER: file = %O, start = $0000, size = $0006; } + SEGMENTS { - EXEHDR: load = HEADER, type = ro; - STARTUP: load = RAM, type = ro, define = yes; - LOWCODE: load = RAM, type = ro, define = yes, optional = yes; - INIT: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro, define = yes; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = zp, optional = yes; - AUTOSTRT: load = TRAILER, type = ro; + EXEHDR: load = HEADER, type = ro; + + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHK, type = rw, define = yes, optional = yes; + + SRPREPHDR: load = SRPREPHDR, type = ro; + SAVEAREA: load = SRPREP, type = bss, define = yes; # shared btw. SRPREP and RAM + SRPREP: load = SRPREP, type = rw, define = yes; + SHADOW_RAM: load = SRPREP, run = SHADOW_RAM, type = rw, define = yes, optional = yes; + SRPREPTRL: load = SRPREPTRL, type = ro; + + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + ZPSAVE: load = RAM, type = bss, define = yes; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; } FEATURES { CONDES: type = constructor, From 06f441e90ffb96afea13d4b92e2ff371c6e3ece8 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 30 May 2013 02:30:19 +0200 Subject: [PATCH 002/144] Some small first changes for the 'atarixl' target. --- libsrc/atari/crt0.s | 37 +++++++++++++++++++++++++++++++++++++ libsrc/atari/ostype.s | 4 ++++ 2 files changed, 41 insertions(+) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index f007e64ad..dfaa626fa 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -18,6 +18,7 @@ .include "zeropage.inc" .include "atari.inc" + .include "save_area.inc" ; ------------------------------------------------------------------------ ; EXE header @@ -25,6 +26,11 @@ .segment "EXEHDR" .word $FFFF + +.if .defined(__ATARIXL__) +.segment "MAINHDR" +.endif + .word __STARTUP_LOAD__ .word __ZPSAVE_LOAD__ - 1 @@ -57,6 +63,8 @@ L1: lda sp,x tsx stx spsave +.if .not .defined(__ATARIXL__) + ; Report memory usage lda APPMHI @@ -74,6 +82,16 @@ L1: lda sp,x sta APPMHI+1 sta sp+1 ; setup runtime stack part 2 +.else + + ; for now... needs to use value from linker script later + lda MEMTOP + sta sp + lda MEMTOP+1 + sta sp+1 + +.endif + ; Call module constructors jsr initlib @@ -119,6 +137,8 @@ _exit: jsr donelib ; Run module destructors lda old_shflok sta SHFLOK +.if .not .defined(__ATARIXL__) + ; Restore APPMHI lda appmsav @@ -126,6 +146,23 @@ _exit: jsr donelib ; Run module destructors lda appmsav+1 sta APPMHI+1 +.else + +; Atari XL target stuff... + + lda PORTB_save + sta PORTB + lda MEMTOP_save + sta MEMTOP + lda MEMTOP_save+1 + sta MEMTOP+1 + lda APPMHI_save + sta APPMHI + lda APPMHI_save+1 + sta APPMHI+1 +.endif + + ; Copy back the zero page stuff ldx #zpspace-1 diff --git a/libsrc/atari/ostype.s b/libsrc/atari/ostype.s index d93b3ab88..dc17018fa 100644 --- a/libsrc/atari/ostype.s +++ b/libsrc/atari/ostype.s @@ -40,6 +40,10 @@ .export _get_ostype +.if .defined(__ATARIXL__) +.warning "fix me!" +.endif + .proc _get_ostype lda $fcd8 From 2f6e7874c626d9c5ef8f55dd1352b1b5e9851c4a Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 30 May 2013 02:31:25 +0200 Subject: [PATCH 003/144] "save area" is used to save modified system variables and ports. It's shared between the second and main chunk. --- libsrc/atari/save_area.inc | 6 ++++++ libsrc/atari/save_area.s | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 libsrc/atari/save_area.inc create mode 100644 libsrc/atari/save_area.s diff --git a/libsrc/atari/save_area.inc b/libsrc/atari/save_area.inc new file mode 100644 index 000000000..10ee4af23 --- /dev/null +++ b/libsrc/atari/save_area.inc @@ -0,0 +1,6 @@ + +.import SAVMSC_save +.import MEMTOP_save +.import APPMHI_save +.import RAMTOP_save +.import PORTB_save \ No newline at end of file diff --git a/libsrc/atari/save_area.s b/libsrc/atari/save_area.s new file mode 100644 index 000000000..0467b67cb --- /dev/null +++ b/libsrc/atari/save_area.s @@ -0,0 +1,25 @@ +; +; Atari XL, shared data between 2nd load chunk and main chunk +; +; Contains old values of modified system variables and ports. +; +; Christian Groessler, chris@groessler.org, 2013 +; + +.if .defined(__ATARIXL__) + +.export SAVMSC_save +.export MEMTOP_save +.export APPMHI_save +.export RAMTOP_save +.export PORTB_save + +.segment "SAVEAREA" + +SAVMSC_save: .res 2 +MEMTOP_save: .res 2 +APPMHI_save: .res 2 +RAMTOP_save: .res 1 +PORTB_save: .res 1 + +.endif From 480d2a93056270e95b4802abc0c03520bdbb1f7f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 30 May 2013 02:33:09 +0200 Subject: [PATCH 004/144] Code & data for "system check" load chunk in the atarixl target. --- libsrc/atari/system_check.s | 159 ++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 libsrc/atari/system_check.s diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s new file mode 100644 index 000000000..e8d44b29c --- /dev/null +++ b/libsrc/atari/system_check.s @@ -0,0 +1,159 @@ +; +; Atari XL startup system check +; +; This routine gets loaded prior to the main part of the executable +; and checks if the system is compatible to run the program. +; It checks whether the system is an XL type one and that enough +; memory is installed (which isn't the case for a 600XL). +; If the system doesn't qualify, the loading of the main program +; is aborted by jumping to DOSVEC. +; +; Christian Groessler, chris@groessler.org, 2013 +; + +.if .defined(__ATARIXL__) + + .export syschk + .import __SYSCHK_LOAD__ + .import __SAVEAREA_LOAD__ + + .include "zeropage.inc" + .include "atari.inc" + + +.macro print_string text + .local start, cont + jmp cont +start: .byte text, ATEOL +cont: ldx #0 ; channel 0 + lda #start + sta ICBAH,x + lda #<(cont - start) + sta ICBLL,x ; length + lda #>(cont - start) + sta ICBLH,x + lda #PUTCHR + sta ICCOM,x + jsr CIOV +.endmacro +.macro print_string2 addr, len + + ldx #0 ; channel 0 + lda #addr + sta ICBAH,x + lda #len + sta ICBLH,x + lda #PUTCHR + sta ICCOM,x + jsr CIOV + +.endmacro + + +; ------------------------------------------------------------------------ +; Chunk header + +.segment "SYSCHKHDR" + + .word __SYSCHK_LOAD__ + .word trailer - 1 + +; ------------------------------------------------------------------------ +; Actual code + +.segment "SYSCHK" + +syschk: + lda $fcd8 ; from ostype.s + cmp #$a2 + bne is_xl + +; no XL machine + print_string "This program needs an XL machine." + jmp fail + +; we have an XL machine, now check memory +is_xl: lda RAMSIZ + cmp #$80 + bcs sys_ok + +; not enough memory + print_string "Not enough memory." +fail: jsr delay + jmp (DOSVEC) + +lowadr: .res 2 ; lowest address we need in order to move screen memory down, depending on start address of program + + +; system is basically supported, check if there is enough space btw. MEMLO and our start address +; to move screen memory there + +CMPVAL = 64+255+992 ; you may ask, why these values... @@@ document + +sys_ok: lda #<__SAVEAREA_LOAD__ + sec + sbc #__SAVEAREA_LOAD__ + sbc #>CMPVAL + sta lowadr+1 + + sec + lda MEMLO + sbc lowadr + lda MEMLO+1 + sbc lowadr+1 + bcc memlo_ok + +; load address was too low + print_string2 lmemerr_txt, lmemerr_txt_len + jsr delay ; long text takes longer to read, give user additional time + jmp fail + +; all is well(tm), launch the application +memlo_ok: + rts + + +lmemerr_txt: + .byte "Not enough memory to move screen", ATEOL + .byte "memory to low memory. Consider using", ATEOL + .byte "a higher load address.", ATEOL +lmemerr_txt_len = * - lmemerr_txt + + +; short delay +.proc delay + + lda #10 +l: jsr delay1 + clc + sbc #0 + bne l + rts + +delay1: ldx #0 + ldy #0 +loop: dey + bne loop + dex + bne loop + rts + +.endproc + +; ------------------------------------------------------------------------ +; Chunk "trailer" - sets INITAD + +trailer: + .word INITAD + .word INITAD+1 + .word __SYSCHK_LOAD__ + +.endif ; .if .defined(__ATARIXL__) From 79d150b62671ae7eaa2b94350f08179582cc836c Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 30 May 2013 02:34:06 +0200 Subject: [PATCH 005/144] Code & data for "shadow RAM preparation" load chunk in the atarixl target. Intermediate check-in, unfinished... --- libsrc/atari/shadow_ram_prepare.s | 185 ++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 libsrc/atari/shadow_ram_prepare.s diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s new file mode 100644 index 000000000..2fc8ffbc3 --- /dev/null +++ b/libsrc/atari/shadow_ram_prepare.s @@ -0,0 +1,185 @@ +; +; Atari XL shadow RAM preparation routines +; +; Tasks: +; - move screen memory below load address +; - copy shadow RAM contents to their destination +; +; Christian Groessler, chris@groessler.org, 2013 +; + +.if .defined(__ATARIXL__) + + .export sramprep + .import __SRPREP_LOAD__, __SRPREP_SIZE__ + .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__ + .import __CHARGEN_LOAD__, __CHARGEN_SIZE__ + .import __SAVEAREA_LOAD__ + + .include "zeropage.inc" + .include "atari.inc" + .include "save_area.inc" + +.macro print_string text + .local start, cont + jmp cont +start: .byte text, ATEOL +cont: ldx #0 ; channel 0 + lda #start + sta ICBAH,x + lda #<(cont - start) + sta ICBLL,x ; length + lda #>(cont - start) + sta ICBLH,x + lda #PUTCHR + sta ICCOM,x + jsr CIOV +.endmacro + +; ------------------------------------------------------------------------ +; Chunk header + +.segment "SRPREPHDR" + + .word __SRPREP_LOAD__ + .word __SRPREP_LOAD__ + __SRPREP_SIZE__ - 1 + +; ------------------------------------------------------------------------ +; Actual code + +.segment "SRPREP" + +sramprep: + print_string "in sramprep" + +; save values of modified system variables and ports + lda RAMTOP + sta RAMTOP_save + lda MEMTOP + sta MEMTOP_save + lda MEMTOP+1 + sta MEMTOP_save+1 + lda APPMHI + sta APPMHI_save + lda APPMHI+1 + sta APPMHI_save+1 + lda PORTB + sta PORTB_save + +; disable BASIC + + lda PORTB + ora #2 + sta PORTB + + +; ... change memory bla + +CMPVAL = 64+255+992 ; you may ask, why these values... @@@ document + +sys_ok: lda #<__SAVEAREA_LOAD__ + sec + sbc #__SAVEAREA_LOAD__ + sbc #>CMPVAL + sta MEMTOP+1 + sta APPMHI+1 + + lda #>__SAVEAREA_LOAD__ - 1 + sta RAMTOP + + + +; ... issue ar GRAPHICS 0 call (copied'n'pasted from TGI drivers) + + + ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) + + ; Reopen it in Graphics 0 + lda #OPEN + sta ICCOM,x + lda #OPNIN | OPNOT + sta ICAX1,x + lda #0 + sta ICAX2,x + lda #screen_device + sta ICBAH,x + lda #screen_device_length + sta ICBLH,x + jsr CIOV + bpl okoko + + print_string "GR 0 FAILED" + jsr delay + jsr delay + jsr delay + + jmp xxx + +okoko: + + + ; Now close it again; we don't need it anymore :) + lda #CLOSE + sta ICCOM,x + jsr CIOV + + print_string "GR 0 OKOKO" + jsr delay + + + + + + +xxx: + + + + + + rts + +; short delay +.proc delay + + lda #10 +l: jsr delay1 + clc + sbc #0 + bne l + rts + +delay1: ldx #0 + ldy #0 +loop: dey + bne loop + dex + bne loop + rts + +.endproc + +screen_device: .byte "S:",0 +screen_device_length = * - screen_device + + .byte " ** srprep ** end-->" + +; ------------------------------------------------------------------------ +; Chunk "trailer" - sets INITAD + +.segment "SRPREPTRL" + + .word INITAD + .word INITAD+1 + .word __SRPREP_LOAD__ + +.endif ; .if .defined(__ATARIXL__) From 164fb56580eb921c1eaf2dcbb021c1f596665a05 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 01:35:19 +0200 Subject: [PATCH 006/144] move ZPSAVE into area already saved by 2nd load chunk --- cfg/atarixl.cfg | 64 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index cbd31bfe6..ce7d98280 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -10,58 +10,58 @@ SYMBOLS { } MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; + ZP: file = "", define = yes, start = $0082, size = $007E; # just $FFFF - HEADER: file = %O, start = $0000, size = $0002; + HEADER: file = %O, start = $0000, size = $0002; # "system check" load chunk - SYSCHKHDR: file = %O, start = $0000, size = $0004; - SYSCHK: file = %O, start = $2E00, size = $0E00; + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHK: file = %O, start = $2E00, size = $0E00; # "shadow RAM preparation" load chunk - SRPREPHDR: file = %O, start = $0000, size = $0004; - SRPREP: file = %O, start = %S, size = $7C20 - %S - $04FF; # $04FF: space for temp. chargen buffer, page aligned - SRPREPTRL: file = %O, start = $0000, size = $0006; + SRPREPHDR: file = %O, start = $0000, size = $0004; + SRPREP: file = %O, start = %S, size = $7C20 - %S - $04FF; # $04FF: space for temp. chargen buffer, page aligned + SRPREPTRL: file = %O, start = $0000, size = $0006; # "main program" load chunk - MAINHDR: file = %O, start = $0000, size = $0004; - RAM: file = %O, start = %S + __SAVEAREA_SIZE__, size = $D000 - __STACKSIZE__ - %S - __SAVEAREA_SIZE__; + MAINHDR: file = %O, start = $0000, size = $0004; + RAM: file = %O, define = yes, start = %S + __SAVEAREA_SIZE__ + __ZPSAVE_SIZE__, size = $D000 - __STACKSIZE__ - %S - __SAVEAREA_SIZE__ - __ZPSAVE_SIZE__; # address of relocated character generator - CHARGEN: file = "", define = yes, start = $D800, size = $0400; + CHARGEN: file = "", define = yes, start = $D800, size = $0400; # memory beneath the ROM - SHADOW_RAM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; + RAM_BELOW_ROM: file = "", start = $DC00, size = $FFF0 - $DC00; # defines entry point into program - TRAILER: file = %O, start = $0000, size = $0006; + TRAILER: file = %O, start = $0000, size = $0006; } SEGMENTS { - EXEHDR: load = HEADER, type = ro; + EXEHDR: load = HEADER, type = ro; - SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; - SYSCHK: load = SYSCHK, type = rw, define = yes, optional = yes; + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHK, type = rw, define = yes, optional = yes; - SRPREPHDR: load = SRPREPHDR, type = ro; - SAVEAREA: load = SRPREP, type = bss, define = yes; # shared btw. SRPREP and RAM - SRPREP: load = SRPREP, type = rw, define = yes; - SHADOW_RAM: load = SRPREP, run = SHADOW_RAM, type = rw, define = yes, optional = yes; - SRPREPTRL: load = SRPREPTRL, type = ro; + SRPREPHDR: load = SRPREPHDR, type = ro; + SAVEAREA: load = SRPREP, type = bss, define = yes; # shared btw. SRPREP and RAM + ZPSAVE: load = SRPREP, type = bss, define = yes; + SRPREP: load = SRPREP, type = rw, define = yes; + SHADOW_RAM: load = SRPREP, run = RAM_BELOW_ROM, type = rw, define = yes, optional = yes; + SRPREPTRL: load = SRPREPTRL, type = ro; - MAINHDR: load = MAINHDR, type = ro; - STARTUP: load = RAM, type = ro, define = yes; - LOWCODE: load = RAM, type = ro, define = yes, optional = yes; - INIT: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro, define = yes; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = zp, optional = yes; - AUTOSTRT: load = TRAILER, type = ro; + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; } FEATURES { CONDES: type = constructor, From c1468f11b2105ede7f6943a7646060933b80b319 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 01:37:40 +0200 Subject: [PATCH 007/144] rename CIOV and SIOV to CIOV_org and SIOV_org for atarixl target --- asminc/atari.inc | 7 +++++++ libsrc/atari/system_check.s | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/asminc/atari.inc b/asminc/atari.inc index 29159a177..1f3641cf4 100644 --- a/asminc/atari.inc +++ b/asminc/atari.inc @@ -956,8 +956,15 @@ CASETV = $E440 ;cassette handler vector table DISKIV = $E450 ;vector to initialize DIO DSKINV = $E453 ;vector to DIO +.if .defined(__ATARIXL__) +CIOV = $C0 +SIOV = $C3 +CIOV_org = $E456 ;vector to CIO +SIOV_org = $E459 ;vector to SIO +.else CIOV = $E456 ;vector to CIO SIOV = $E459 ;vector to SIO +.endif SETVBV = $E45C ;vector to set VBLANK parameters SYSVBV = $E45F ;vector to process immediate VBLANK XITVBV = $E462 ;vector to process deferred VBLANK diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index e8d44b29c..19e574243 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -36,7 +36,7 @@ cont: ldx #0 ; channel 0 sta ICBLH,x lda #PUTCHR sta ICCOM,x - jsr CIOV + jsr CIOV_org .endmacro .macro print_string2 addr, len @@ -51,7 +51,7 @@ cont: ldx #0 ; channel 0 sta ICBLH,x lda #PUTCHR sta ICCOM,x - jsr CIOV + jsr CIOV_org .endmacro From 7aa22317027df79a5a492b2e676421e0df09ba16 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 01:38:16 +0200 Subject: [PATCH 008/144] adapt to atarixl target --- libsrc/atari/cgetc.s | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libsrc/atari/cgetc.s b/libsrc/atari/cgetc.s index f8948a5bc..43969c2aa 100644 --- a/libsrc/atari/cgetc.s +++ b/libsrc/atari/cgetc.s @@ -7,22 +7,28 @@ .include "atari.inc" .export _cgetc,setcursor + .import KEYBDV_wrapper .import cursor,mul40 _cgetc: jsr setcursor + lda #12 + sta ICAX1Z ; fix problems with direct call to KEYBDV +.if .not .defined(__ATARIXL__) jsr @1 +.else + jsr KEYBDV_wrapper +.endif ldx #0 rts -@1: lda KEYBDV+5 +.if .not .defined(__ATARIXL__) +@1: lda KEYBDV+5 pha lda KEYBDV+4 pha - lda #12 - sta ICAX1Z ; fix problems with direct call to KEYBDV - rts - + rts +.endif .proc setcursor From 00fca46d2a0a16d463886d0de4d30bf428a0aba1 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 01:40:45 +0200 Subject: [PATCH 009/144] move ZPSAVE content into its own file (used by 2nd load chunk and crt0.s in atarixl target) --- libsrc/atari/zpsave.s | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 libsrc/atari/zpsave.s diff --git a/libsrc/atari/zpsave.s b/libsrc/atari/zpsave.s new file mode 100644 index 000000000..81736c269 --- /dev/null +++ b/libsrc/atari/zpsave.s @@ -0,0 +1,9 @@ +.export zpsave +.include "zeropage.inc" + +.segment "ZPSAVE" + +zpsave: .res zpspace + +; ------------------------------------------------------------------------ + From 9908561e80aa956df365741b248f9fec0e1dc37f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 01:42:30 +0200 Subject: [PATCH 010/144] add more saved content --- libsrc/atari/save_area.inc | 15 ++++++++++----- libsrc/atari/save_area.s | 10 ++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libsrc/atari/save_area.inc b/libsrc/atari/save_area.inc index 10ee4af23..d3868723d 100644 --- a/libsrc/atari/save_area.inc +++ b/libsrc/atari/save_area.inc @@ -1,6 +1,11 @@ -.import SAVMSC_save -.import MEMTOP_save -.import APPMHI_save -.import RAMTOP_save -.import PORTB_save \ No newline at end of file +.import IRQ_save +.import NMI_save +.import RESET_save +.import SAVMSC_save +.import MEMTOP_save +.import APPMHI_save +.import RAMTOP_save +.import PORTB_save +.import ZP_CIOV_save +.import ZP_SIOV_save diff --git a/libsrc/atari/save_area.s b/libsrc/atari/save_area.s index 0467b67cb..e222b70bd 100644 --- a/libsrc/atari/save_area.s +++ b/libsrc/atari/save_area.s @@ -8,17 +8,27 @@ .if .defined(__ATARIXL__) +.export IRQ_save +.export NMI_save +.export RESET_save .export SAVMSC_save .export MEMTOP_save .export APPMHI_save .export RAMTOP_save .export PORTB_save +.export ZP_CIOV_save +.export ZP_SIOV_save .segment "SAVEAREA" +IRQ_save: .res 2 +NMI_save: .res 2 +RESET_save: .res 2 SAVMSC_save: .res 2 MEMTOP_save: .res 2 APPMHI_save: .res 2 +ZP_CIOV_save: .res 3 +ZP_SIOV_save: .res 3 RAMTOP_save: .res 1 PORTB_save: .res 1 From 9228b002b0887e4403b3bb22d15c763255c539b8 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 01:45:53 +0200 Subject: [PATCH 011/144] Handlers which manage the banking in and out of the ROM. --- libsrc/atari/shadow_ram_handlers.s | 175 +++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 libsrc/atari/shadow_ram_handlers.s diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s new file mode 100644 index 000000000..d3532b238 --- /dev/null +++ b/libsrc/atari/shadow_ram_handlers.s @@ -0,0 +1,175 @@ +; +; Atari XL shadow RAM handlers +; +; Christian Groessler, chris@groessler.org, 2013 +; + +.if .defined(__ATARIXL__) + + .include "atari.inc" + .include "save_area.inc" + .import __CHARGEN_START__ + + .export sram_init + .export KEYBDV_wrapper + +.macro disable_rom + lda PORTB + and #$fe + sta PORTB +.endmacro +.macro enable_rom + lda PORTB + ora #1 + sta PORTB +.endmacro + +.segment "INIT" + +; Turn off ROMs, install system and interrupt wrappers, set new chargen pointer + +sram_init: + +; disable all interrupts + sei + ldx #0 + stx NMIEN ; disable NMI + + disable_rom + +; setup interrupt vectors + lda #my_IRQ_han + sta $ffff + + lda #my_RESET_han + sta $fffd + + lda #my_NMI_han + sta $fffb + +; setup pointers to CIOV and SIOV wrappers + lda #$4C ; JMP opcode + sta CIOV + lda #my_CIOV + sta CIOV+2 + lda #$4C ; JMP opcode + sta SIOV + lda #my_SIOV + sta SIOV+2 + +; set new chargen + lda #>__CHARGEN_START__ + sta CHBAS + sta CHBASE + +; enable interrupts + lda #$40 + sta NMIEN + cli + + rts + + +.segment "LOWCODE" + +.macro int_wrap orgvec + .local ret + pha + enable_rom + lda #>ret + pha + lda #(kret-1) + pha + lda #<(kret-1) + pha + enable_rom + lda KEYBDV+5 + pha + lda KEYBDV+4 + pha + rts ; call keyboard handler +kret: pha + disable_rom + pla + rts + +.if 0 + .import KEYBDV_wrapper + .import cursor,mul40 + +_cgetc: + jsr setcursor +.if .not .defined(__ATARIXL__) + jsr @1 +.else + jsr KEYBDV_wrapper +.endif + ldx #0 + rts + +.if .not .defined(__ATARIXL__) +@1: lda KEYBDV+5 + pha + lda KEYBDV+4 + pha + lda #12 + sta ICAX1Z ; fix problems with direct call to KEYBDV + rts +.endif +.endif + +.endif ; .if .defined(__ATARIXL__) From 8e632b2847e6a6321023e41d67baf23e4faf8d9e Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 01:47:25 +0200 Subject: [PATCH 012/144] some more changes -- atarixl target basically works now --- libsrc/atari/crt0.s | 35 ++++-- libsrc/atari/shadow_ram_prepare.s | 180 ++++++++++++++++++++++++++++-- 2 files changed, 193 insertions(+), 22 deletions(-) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index dfaa626fa..d8578d4ac 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -13,8 +13,12 @@ .import initlib, donelib .import callmain, zerobss - .import __STARTUP_LOAD__, __ZPSAVE_LOAD__ + .import __STARTUP_LOAD__, __ZPSAVE_LOAD__, __BSS_LOAD__ .import __RESERVED_MEMORY__ + .import __RAM_START__, __RAM_SIZE__ + .import zpsave + .import sram_init + .include "zeropage.inc" .include "atari.inc" @@ -32,7 +36,11 @@ .endif .word __STARTUP_LOAD__ +.if .defined(__ATARIXL__) + .word __BSS_LOAD__ - 1 +.else .word __ZPSAVE_LOAD__ - 1 +.endif ; ------------------------------------------------------------------------ ; Actual code @@ -46,6 +54,8 @@ ; Real entry point: +.if .not .defined(__ATARIXL__) ; already done in previous load chunk + ; Save the zero page locations we need ldx #zpspace-1 @@ -54,6 +64,12 @@ L1: lda sp,x dex bpl L1 +.else + + jsr sram_init + +.endif + ; Clear the BSS data jsr zerobss @@ -84,16 +100,17 @@ L1: lda sp,x .else - ; for now... needs to use value from linker script later - lda MEMTOP - sta sp - lda MEMTOP+1 - sta sp+1 + lda #<(__RAM_START__ + __RAM_SIZE__ - 1) + sta sp + lda #>(__RAM_START__ + __RAM_SIZE__ - 1) + sta sp+1 .endif ; Call module constructors +; brk + jsr initlib ; Set left margin to 0 @@ -184,12 +201,6 @@ L2: lda zpsave,x ; ------------------------------------------------------------------------ -.segment "ZPSAVE" - -zpsave: .res zpspace - -; ------------------------------------------------------------------------ - .bss spsave: .res 1 diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 2fc8ffbc3..60de9dbf1 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -3,6 +3,7 @@ ; ; Tasks: ; - move screen memory below load address +; - copy ROM chargen to its new place ; - copy shadow RAM contents to their destination ; ; Christian Groessler, chris@groessler.org, 2013 @@ -13,8 +14,10 @@ .export sramprep .import __SRPREP_LOAD__, __SRPREP_SIZE__ .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__ - .import __CHARGEN_LOAD__, __CHARGEN_SIZE__ + .import __SHADOW_RAM_RUN__ + .import __CHARGEN_START__, __CHARGEN_SIZE__ .import __SAVEAREA_LOAD__ + .import zpsave .include "zeropage.inc" .include "atari.inc" @@ -35,7 +38,7 @@ cont: ldx #0 ; channel 0 sta ICBLH,x lda #PUTCHR sta ICCOM,x - jsr CIOV + jsr CIOV_org .endmacro ; ------------------------------------------------------------------------ @@ -55,6 +58,7 @@ sramprep: print_string "in sramprep" ; save values of modified system variables and ports + lda RAMTOP sta RAMTOP_save lda MEMTOP @@ -67,6 +71,31 @@ sramprep: sta APPMHI_save+1 lda PORTB sta PORTB_save + lda CIOV ; zero-page wrapper + sta ZP_CIOV_save + lda CIOV+1 + sta ZP_CIOV_save+1 + lda CIOV+2 + sta ZP_CIOV_save+2 + lda SIOV ; zero-page wrapper + sta ZP_SIOV_save + lda SIOV+1 + sta ZP_SIOV_save+1 + lda SIOV+2 + sta ZP_SIOV_save+2 + + lda $fffe + sta IRQ_save + lda $ffff + sta IRQ_save+1 + lda $fffc + sta RESET_save + lda $fffd + sta RESET_save+1 + lda $fffa + sta NMI_save + lda $fffb + sta NMI_save+1 ; disable BASIC @@ -75,7 +104,7 @@ sramprep: sta PORTB -; ... change memory bla +; ... change system memory variables bla CMPVAL = 64+255+992 ; you may ask, why these values... @@@ document @@ -91,10 +120,10 @@ sys_ok: lda #<__SAVEAREA_LOAD__ lda #>__SAVEAREA_LOAD__ - 1 sta RAMTOP - - -; ... issue ar GRAPHICS 0 call (copied'n'pasted from TGI drivers) + + +; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) @@ -114,7 +143,7 @@ sys_ok: lda #<__SAVEAREA_LOAD__ sta ICBLL,x lda #>screen_device_length sta ICBLH,x - jsr CIOV + jsr CIOV_org bpl okoko print_string "GR 0 FAILED" @@ -122,7 +151,8 @@ sys_ok: lda #<__SAVEAREA_LOAD__ jsr delay jsr delay - jmp xxx + jmp (DOSVEC) ; abort loading + okoko: @@ -130,24 +160,147 @@ okoko: ; Now close it again; we don't need it anymore :) lda #CLOSE sta ICCOM,x - jsr CIOV + jsr CIOV_org print_string "GR 0 OKOKO" jsr delay +; Save the zero page locations we need + ldx #zpspace-1 +L1: lda sp,x + sta zpsave,x + dex + bpl L1 +; copy chargen to low memory + lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__) + sta ptr3+1 + lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__) + sta ptr3 + beq cg_addr_ok -xxx: + ; page align the new chargen address + inc ptr3+1 + lda #0 + sta ptr3 +cg_addr_ok: + lda #DCSORG + sta ptr1+1 + lda ptr3 + sta ptr2 + lda ptr3+1 + sta ptr2+1 + lda #>__CHARGEN_SIZE__ + sta tmp2 + lda #<__CHARGEN_SIZE__ + sta tmp2+1 + jsr memcopy +; TODO: switch to this temp. chargen +; disable ROMs + sei + ldx #0 + stx NMIEN ; disable NMI + lda PORTB + and #$fe + sta PORTB ; now ROM is mapped out +; copy shadow RAM contents to their destination + + lda #<__SHADOW_RAM_SIZE__ + bne do_copy + lda #>__SHADOW_RAM_SIZE__ + beq no_copy ; we have no shadow RAM contents + + ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len +do_copy:lda #<__SHADOW_RAM_LOAD__ + sta ptr1 + lda #>__SHADOW_RAM_LOAD__ + sta ptr1+1 + lda #<__SHADOW_RAM_RUN__ + sta ptr2 + lda #>__SHADOW_RAM_RUN__ + sta ptr2+1 + lda #<__SHADOW_RAM_SIZE__ + sta tmp1 + lda #>__SHADOW_RAM_SIZE__ + sta tmp2 + + jsr memcopy + +no_copy: + +; copy chargen to its new location + + lda ptr3 + sta ptr1 + lda ptr3+1 + sta ptr1+1 + lda #<__CHARGEN_START__ + sta ptr2 + lda #>__CHARGEN_START__ + sta ptr2+1 + lda #>__CHARGEN_SIZE__ + sta tmp2 + lda #<__CHARGEN_SIZE__ + sta tmp2+1 + jsr memcopy + +; re-enable ROM + + lda PORTB + ora #1 + sta PORTB + lda #$40 + sta NMIEN ; enable VB again + cli ; and enable IRQs rts + +; my 6502 fu is rusty, so I took a routine from the internet (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 + + +.byte "HERE ****************** HERE ***************>>>>>>" + +sramsize: + .word __SHADOW_RAM_SIZE__ + ; short delay .proc delay @@ -173,6 +326,13 @@ screen_device_length = * - screen_device .byte " ** srprep ** end-->" +; ------------------------------------------------------------------------ +; Provide an empty SHADOW_RAM segment in order that the linker is happy +; if the user program doesn't have a SHADOW_RAM segment. + +.segment "SHADOW_RAM" + + ; ------------------------------------------------------------------------ ; Chunk "trailer" - sets INITAD From 451b34bc758426010adfdf56a75b89eb079ea5c8 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 01:50:07 +0200 Subject: [PATCH 013/144] When turning the ROM off and on, also change the chargen pointer. --- libsrc/atari/shadow_ram_handlers.s | 37 ++++++------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index d3532b238..e2de0c319 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -17,11 +17,17 @@ lda PORTB and #$fe sta PORTB + lda #>__CHARGEN_START__ + sta CHBAS + sta CHBASE .endmacro .macro enable_rom lda PORTB ora #1 sta PORTB + lda #$E0 + sta CHBAS + sta CHBASE .endmacro .segment "INIT" @@ -35,6 +41,7 @@ sram_init: ldx #0 stx NMIEN ; disable NMI +; disable ROMs disable_rom ; setup interrupt vectors @@ -67,11 +74,6 @@ sram_init: lda #>my_SIOV sta SIOV+2 -; set new chargen - lda #>__CHARGEN_START__ - sta CHBAS - sta CHBASE - ; enable interrupts lda #$40 sta NMIEN @@ -147,29 +149,4 @@ kret: pha pla rts -.if 0 - .import KEYBDV_wrapper - .import cursor,mul40 - -_cgetc: - jsr setcursor -.if .not .defined(__ATARIXL__) - jsr @1 -.else - jsr KEYBDV_wrapper -.endif - ldx #0 - rts - -.if .not .defined(__ATARIXL__) -@1: lda KEYBDV+5 - pha - lda KEYBDV+4 - pha - lda #12 - sta ICAX1Z ; fix problems with direct call to KEYBDV - rts -.endif -.endif - .endif ; .if .defined(__ATARIXL__) From 7f0dbde77ff0f0084b8919b5098dafd13da8f32f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 14:49:25 +0200 Subject: [PATCH 014/144] Take SHADOW_RAM size into account. --- libsrc/atari/shadow_ram_prepare.s | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 60de9dbf1..6bc3ab87e 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -47,7 +47,7 @@ cont: ldx #0 ; channel 0 .segment "SRPREPHDR" .word __SRPREP_LOAD__ - .word __SRPREP_LOAD__ + __SRPREP_SIZE__ - 1 + .word __SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__ - 1 ; ------------------------------------------------------------------------ ; Actual code @@ -176,9 +176,9 @@ L1: lda sp,x ; copy chargen to low memory - lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__) + lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) sta ptr3+1 - lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__) + lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) sta ptr3 beq cg_addr_ok @@ -250,7 +250,7 @@ no_copy: lda #>__CHARGEN_SIZE__ sta tmp2 lda #<__CHARGEN_SIZE__ - sta tmp2+1 + sta tmp1 jsr memcopy ; re-enable ROM From c1230b8af6c3ceda23a0735f06243cdbe862c999 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 31 May 2013 14:49:46 +0200 Subject: [PATCH 015/144] small cleanup --- libsrc/atari/crt0.s | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index d8578d4ac..73d216713 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -109,8 +109,6 @@ L1: lda sp,x ; Call module constructors -; brk - jsr initlib ; Set left margin to 0 From b03913370c8c047d2a706f6599a8dd68e935d6d8 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Sat, 8 Jun 2013 00:35:07 +0200 Subject: [PATCH 016/144] Use symbolic names for all CIO commands. --- asminc/atari.inc | 55 ++++++++++++++++++++++------------------- libsrc/atari/initcwd.s | 2 +- libsrc/atari/lseek.s | 10 ++++---- libsrc/atari/syschdir.s | 4 +-- libsrc/atari/sysmkdir.s | 2 +- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/asminc/atari.inc b/asminc/atari.inc index 1f3641cf4..f01131665 100644 --- a/asminc/atari.inc +++ b/asminc/atari.inc @@ -44,9 +44,34 @@ CLOSE = $0C ;close STATIS = $0D ;status SPECIL = $0E ;special -; Special Entry Command Equates +; DOS IOCB command codes -; Screen Commands +RENAME = $20 ;rename disk file +DELETE = $21 ;delete disk file +LOCKFL = $23 ;lock file (set to read-only) +UNLOCK = $24 ;unlock file +POINT = $25 ;point sector +NOTE = $26 ;note sector +GETFL = $27 ;get file length +CHDIR_MYDOS = $29 ;change directory (MyDOS) +MKDIR = $2A ;make directory (MyDOS/SpartaDOS) +CHDIR_SPDOS = $2C ;change directory (SpartaDOS) +FORMAT = $FE ;format + +GETCWD = $30 ;get current directory (MyDOS/SpartaDOS) + +; Special Entry Command Equates +; DOS Commands +; Command line table, Index values for (DOSVEC),Y -- COMTAB +; Compatible with OS/A+, DOS XL and SpartaDOS + +COMTAB = 0 ;DOS entry jump vector +ZCRNAME = 3 ;file name crunch routine jump vector +BUFOFF = 10 ;next parameter buffer offset +COMFNAM = 33 ;destination buffer for crunch routine +LBUF = 63 ;command line input buffer + +; Screen IOCB Commands DRAWLN = $11 ;draw line FILLIN = $12 ;draw line with right fill @@ -710,6 +735,9 @@ FPSCR1 = $05EC ;6-byte floating point temporary ;LBFEND = $05FF ;##old## END OF LBUFF + +DOS = $0700 + ;------------------------------------------------------------------------- ; Cartridge Address Equates ;------------------------------------------------------------------------- @@ -1029,29 +1057,6 @@ STOPLN = $BA ;2-byte stopped line number ERRSAVE = $C3 ;1-byte error code PTABW = $C9 ;1-byte tab width -;------------------------------------------------------------------------- -; DOS -;------------------------------------------------------------------------- - -DOS = $0700 - -RENAME = $20 ;RENAME DISK FILE -DELETE = $21 ;DELETE DISK FILE -LOCKFL = $23 ;LOCK FILE TO READ ONLY -UNLOCK = $24 ;UNLOCK LOCKED FILE -POINT = $25 ;POINT SECTOR -NOTE = $26 ;NOTE SECTOR -FORMAT = $FE ;FORMAT - -; Command line table, Index values for (DOSVEC),Y -- COMTAB -; Compatible with OS/A+, DOS XL and SpartaDOS - -COMTAB = 0 ;DOS entry jump vector -ZCRNAME = 3 ;file name crunch routine jump vector -BUFOFF = 10 ;next parameter buffer offset -COMFNAM = 33 ;destination buffer for crunch routine -LBUF = 63 ;command line input buffer - ;------------------------------------------------------------------------- ; ATASCII CHARACTER DEFS ;------------------------------------------------------------------------- diff --git a/libsrc/atari/initcwd.s b/libsrc/atari/initcwd.s index 19df6a5a4..d7b574314 100644 --- a/libsrc/atari/initcwd.s +++ b/libsrc/atari/initcwd.s @@ -11,7 +11,7 @@ jsr findfreeiocb bne oserr - lda #48 + lda #GETCWD sta ICCOM,x lda #<__cwd sta ICBLL,x diff --git a/libsrc/atari/lseek.s b/libsrc/atari/lseek.s index bf934294c..889976f5b 100644 --- a/libsrc/atari/lseek.s +++ b/libsrc/atari/lseek.s @@ -68,7 +68,7 @@ iocberr:jsr incsp6 ; SEEK_CUR cur: ldx tmp3 - lda #38 ; NOTE + lda #NOTE sta ICCOM,x jsr CIOV ; read it bmi xxerr @@ -84,7 +84,7 @@ l01: lda ICAX3,x ; low byte of position ; SEEK_END end: ldx tmp3 - lda #39 ; get file size + lda #GETFL sta ICCOM,x jsr CIOV bpl l01 @@ -126,7 +126,7 @@ ret: jsr incsp6 .if 0 ; return exactly the position DOS has ldx tmp3 - lda #38 ; NOTE + lda #NOTE sta ICCOM,x jsr CIOV ; read it bmi xxerr @@ -168,7 +168,7 @@ seek: jsr ldax0sp ; get lower word of new offset sta ICAX4,x lda ptr4 sta ICAX5,x - lda #37 ;POINT + lda #POINT sta ICCOM,x jsr CIOV bpl ret @@ -201,7 +201,7 @@ chk_supp: cmp #$40 bcs supp1 ; SD-X (ver 4.xx) supports seeking on all disks ldx tmp3 ; iocb to use - lda #39 ; get file size + lda #GETFL sta ICCOM,x jsr CIOV bmi notsupp ; error code ? should be 168 (invalid command) diff --git a/libsrc/atari/syschdir.s b/libsrc/atari/syschdir.s index 9fc45edbd..16cb3a1fe 100644 --- a/libsrc/atari/syschdir.s +++ b/libsrc/atari/syschdir.s @@ -58,9 +58,9 @@ ucok1: lda __dos_type cmp #SPARTADOS beq :+ - lda #41 + lda #CHDIR_MYDOS .byte $2C ; BIT -: lda #44 +: lda #CHDIR_SPDOS sta ICCOM,x lda #0 sta ICAX1,x diff --git a/libsrc/atari/sysmkdir.s b/libsrc/atari/sysmkdir.s index de3252ced..56a068757 100644 --- a/libsrc/atari/sysmkdir.s +++ b/libsrc/atari/sysmkdir.s @@ -61,7 +61,7 @@ ucok1: sta ICBAH,y tya tax - lda #42 + lda #MKDIR sta ICCOM,x lda #8 sta ICAX1,x From 8e8a37c47b99fde16d26534cba5bcabd2ef38f35 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Mon, 10 Jun 2013 14:22:30 +0200 Subject: [PATCH 017/144] intermediate check-in --- libsrc/atari/shadow_ram_handlers.s | 145 ++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 3 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index e2de0c319..564568130 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -4,6 +4,7 @@ ; Christian Groessler, chris@groessler.org, 2013 ; + .if .defined(__ATARIXL__) .include "atari.inc" @@ -13,15 +14,24 @@ .export sram_init .export KEYBDV_wrapper +BUFSZ = 128 +BUFSZ_CIO = BUFSZ +BUFSZ_SIO = BUFSZ + .macro disable_rom + .local cont + ;dec enable_count + ;bne cont lda PORTB and #$fe sta PORTB lda #>__CHARGEN_START__ sta CHBAS sta CHBASE +cont: .endmacro .macro enable_rom + ;inc enable_count lda PORTB ora #1 sta PORTB @@ -32,6 +42,8 @@ .segment "INIT" +enable_count: .res 1 + ; Turn off ROMs, install system and interrupt wrappers, set new chargen pointer sram_init: @@ -42,6 +54,8 @@ sram_init: stx NMIEN ; disable NMI ; disable ROMs + ;inx + stx enable_count disable_rom ; setup interrupt vectors @@ -82,8 +96,24 @@ sram_init: rts +.segment "LOWBUFS" + +; bounce buffers for CIO and SIO calls +CIOV_buffer: .res BUFSZ_CIO +SIOV_buffer: .res BUFSZ_SIO + + .segment "LOWCODE" +; Interrupt handlers +; ------------------ + +; The interrupt handlers don't look at the current state of PORTB and +; unconditionally disable the ROMs on exit. +; Please note that this works, since if the ROMs are enabled we anyway +; aren't being called here because the vectors are pointing to their +; original ROM locations. + .macro int_wrap orgvec .local ret pha @@ -109,35 +139,139 @@ my_RESET_han: int_wrap RESET_save +; System request handlers +; ----------------------- + +; CIO handler +; We have buffer pointer and length entries in the IOCB, but their +; usage depends on the function. +; Some functions don't care about both (pointer and length), and some +; only use the pointer (like e.g. OPEN), and some use both. +; So we need function specific handlers to correctly deal with +; buffers which are overlapping with the ROM area. +; All input and output registers need to be preserved (I'm not 100% +; sure about Y, but let's preserve it for now.) +; +; FIXME: Currently only the requests used by the runtime lib are handled. + my_CIOV: + +; @@@ TODO: check X for valid IOCB index ((X < $80) and ((X & $F) == 0)) + + sta CIO_a + sty CIO_y + stx CIO_x + + lda ICCOM,x ; get function + cmp #OPEN + beq CIO_filename ; filename as input parameter in buffer, length not used + cmp #PUTREC + bcc CIO_read ; input (GETREC or GETCHR) + cmp #CLOSE + bcc CIO_write ; output (PUTREC or PUTCHR) + beq CIO_pass ; pass through, buffer not used + cmp #RENAME ; 2 filenames as input parameters in buffer, length not used + beq CIO_filename2 + cmp GETCWD + bcc CIO_filename ; filename as parameter in buffer, length not used + beq CIO_read ; input + bcs CIO_pass ; other command: assume no buffers + + + +.if 0 ; all crap +; check if buffer is potentially used (buffer length != 0) + pha + lda ICBLL,x + ora ICBLH,x + bne could_be + pla + jmp CIOV_call + +; buffer might be used by the request + +could_be: + +; check if buffer is inside ROM area + + lda ICBAH,x + cmp #$C0 ; if buffer is above $C000, it's definitely inside ROM area + bcs need_work + + lda ICBAL,x ; low byte of buffer address + adc ICBLL,x ; low byte of buffer length + lda ICBAH,x ; high byte (address) + adc ICBLH,x ; high byte (length) + cmp #$C0 + bcc CIOV_call ; no need to use bounce buffers, just forward call to CIO + +need_work: + +; Check if length is bigger than the size of our bounce buffer. +; If yes, we need to split the call into multiple calls. +; @@@ FIXME: currently only supports bounce buffers < 256 bytes + + lda ICBLH,x ; high byte of length + bne hard_work + lda ICBLL,x ; low byte of length + cmp #(kret-1) pha lda #<(kret-1) pha + lda PORTB + sta cur_KEYBDV_PORTB enable_rom lda KEYBDV+5 pha @@ -145,8 +279,13 @@ KEYBDV_wrapper: pha rts ; call keyboard handler kret: pha - disable_rom + lda cur_KEYBDV_PORTB + sta PORTB pla rts +cur_CIOV_PORTB: .res 1 +cur_SIOV_PORTB: .res 1 +cur_KEYBDV_PORTB: .res 1 + .endif ; .if .defined(__ATARIXL__) From 85dc09fd9f115286875b622d59b62016eb814212 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 12 Jun 2013 13:26:26 +0200 Subject: [PATCH 018/144] add LOWBUFS segment --- cfg/atarixl.cfg | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index ce7d98280..34b6593a7 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -26,7 +26,15 @@ MEMORY { # "main program" load chunk MAINHDR: file = %O, start = $0000, size = $0004; - RAM: file = %O, define = yes, start = %S + __SAVEAREA_SIZE__ + __ZPSAVE_SIZE__, size = $D000 - __STACKSIZE__ - %S - __SAVEAREA_SIZE__ - __ZPSAVE_SIZE__; + RAM: file = %O, define = yes, start = %S + + __SAVEAREA_SIZE__ + + __LOWBUFS_SIZE__ + + __ZPSAVE_SIZE__, size = $D000 - + __STACKSIZE__ - + %S - + __SAVEAREA_SIZE__ - + __LOWBUFS_SIZE__ - + __ZPSAVE_SIZE__; # address of relocated character generator CHARGEN: file = "", define = yes, start = $D800, size = $0400; @@ -46,6 +54,7 @@ SEGMENTS { SRPREPHDR: load = SRPREPHDR, type = ro; SAVEAREA: load = SRPREP, type = bss, define = yes; # shared btw. SRPREP and RAM + LOWBUFS: load = SRPREP, type = bss, define = yes; ZPSAVE: load = SRPREP, type = bss, define = yes; SRPREP: load = SRPREP, type = rw, define = yes; SHADOW_RAM: load = SRPREP, run = RAM_BELOW_ROM, type = rw, define = yes, optional = yes; From e5f409e357a82a4ae69374b1fcd692ec5b3eb6a3 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 12 Jun 2013 13:27:28 +0200 Subject: [PATCH 019/144] intermediate check-in -- added handling of read requests --- libsrc/atari/shadow_ram_handlers.s | 445 +++++++++++++++++++++++------ 1 file changed, 358 insertions(+), 87 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 564568130..9bd9e11c3 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -9,6 +9,7 @@ .include "atari.inc" .include "save_area.inc" + .include "zeropage.inc" .import __CHARGEN_START__ .export sram_init @@ -19,19 +20,14 @@ BUFSZ_CIO = BUFSZ BUFSZ_SIO = BUFSZ .macro disable_rom - .local cont - ;dec enable_count - ;bne cont lda PORTB and #$fe sta PORTB lda #>__CHARGEN_START__ sta CHBAS sta CHBASE -cont: .endmacro .macro enable_rom - ;inc enable_count lda PORTB ora #1 sta PORTB @@ -42,7 +38,7 @@ cont: .segment "INIT" -enable_count: .res 1 +;enable_count: .res 1 ; Turn off ROMs, install system and interrupt wrappers, set new chargen pointer @@ -55,7 +51,7 @@ sram_init: ; disable ROMs ;inx - stx enable_count + ;stx enable_count disable_rom ; setup interrupt vectors @@ -95,16 +91,22 @@ sram_init: rts +.segment "EXTZP" : zeropage + +zpptr1: .res 2 +zpptr2: .res 2 + .segment "LOWBUFS" ; bounce buffers for CIO and SIO calls -CIOV_buffer: .res BUFSZ_CIO -SIOV_buffer: .res BUFSZ_SIO +CIO_buffer: .res BUFSZ_CIO +SIO_buffer: .res BUFSZ_SIO .segment "LOWCODE" + ; Interrupt handlers ; ------------------ @@ -142,95 +144,40 @@ my_RESET_han: ; System request handlers ; ----------------------- -; CIO handler -; We have buffer pointer and length entries in the IOCB, but their -; usage depends on the function. -; Some functions don't care about both (pointer and length), and some -; only use the pointer (like e.g. OPEN), and some use both. -; So we need function specific handlers to correctly deal with -; buffers which are overlapping with the ROM area. -; All input and output registers need to be preserved (I'm not 100% -; sure about Y, but let's preserve it for now.) -; -; FIXME: Currently only the requests used by the runtime lib are handled. -my_CIOV: +; for filenames we assume they will fit into our bounce buffer -; @@@ TODO: check X for valid IOCB index ((X < $80) and ((X & $F) == 0)) - - sta CIO_a - sty CIO_y - stx CIO_x - - lda ICCOM,x ; get function - cmp #OPEN - beq CIO_filename ; filename as input parameter in buffer, length not used - cmp #PUTREC - bcc CIO_read ; input (GETREC or GETCHR) - cmp #CLOSE - bcc CIO_write ; output (PUTREC or PUTCHR) - beq CIO_pass ; pass through, buffer not used - cmp #RENAME ; 2 filenames as input parameters in buffer, length not used - beq CIO_filename2 - cmp GETCWD - bcc CIO_filename ; filename as parameter in buffer, length not used - beq CIO_read ; input - bcs CIO_pass ; other command: assume no buffers - - - -.if 0 ; all crap -; check if buffer is potentially used (buffer length != 0) +; one filename, terminated by "invalid character", located at ICBAL/ICBAH +CIO_filename: + jsr setup_zpptr1_y0 + jsr copy_filename +CIO_fn_cont: + jsr ciobuf_to_iocb + ldy CIO_y + jsr CIO_call_a ; call CIO (maybe A isn't needed, then we could call CIO_call) + php pha - lda ICBLL,x - ora ICBLH,x - bne could_be +;@@@ check if X is preserved over CIO call + jsr restore_icba ; restore original ICBAL/ICBAH pla - jmp CIOV_call + plp + rts ; back to application -; buffer might be used by the request -could_be: +; two filenames, terminated and separated by "invalid character", located at ICBAL/ICBAH -; check if buffer is inside ROM area - - lda ICBAH,x - cmp #$C0 ; if buffer is above $C000, it's definitely inside ROM area - bcs need_work - - lda ICBAL,x ; low byte of buffer address - adc ICBLL,x ; low byte of buffer length - lda ICBAH,x ; high byte (address) - adc ICBLH,x ; high byte (length) - cmp #$C0 - bcc CIOV_call ; no need to use bounce buffers, just forward call to CIO - -need_work: - -; Check if length is bigger than the size of our bounce buffer. -; If yes, we need to split the call into multiple calls. -; @@@ FIXME: currently only supports bounce buffers < 256 bytes - - lda ICBLH,x ; high byte of length - bne hard_work - lda ICBLL,x ; low byte of length - cmp # data too large for our buffers + ; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES + lda # bounce buffer size? + bcs br_last ; no, last transfer, use remaining size + + lda #>BUFSZ_CIO + sta ICBLH,x ; set data length + lda #BUFSZ_CIO + sbc orig_len+1 + rts + + +; copy data from bounce buffer into user buffer +; input: X - IOCB index +; zpptr1 - pointer to user buffer +; output: A - destroyed +; Y - 0 +copy_to_user: + ldy ICBLL,x ; get # of bytes read (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES) + beq copy_done +copy: dey + lda CIO_buffer,y + sta (zpptr1),y + cpy #0 + bne copy +copy_done: + rts + + +; copy ICBLL/ICBLH to 'orig_len' +; input: X - IOCB index +; output: A - destroyed +iocblen_to_orig_len: + lda ICBLL,x + sta orig_len + lda ICBLH,x + sta orig_len+1 + rts + + +; copy ICBAL/ICBAH to 'orig_ptr' +; input: X - IOCB index +; output: A - destroyed +iocbptr_to_orig_ptr: + lda ICBAL,x + sta orig_ptr + lda ICBAH,x + sta orig_ptr+1 + rts + + +; copy 'orig_ptr' to ICBAL/ICBAH +; input: X - IOCB index +; output: A - destroyed +orig_ptr_to_iocbptr: + lda orig_ptr + sta ICBAL,x + lda orig_ptr+1 + sta ICBAH,x + rts + + +; restore original contents of ICBAL/ICBAH from 'zpptr1' +; input: X - IOCB index +; output: A - destroyed +restore_icba: + lda zpptr1 + sta ICBAL,x + lda zpptr1+1 + sta ICBAH,x + rts + + +; put bounce buffer address into ICBAL/ICBAH +; input: X - IOCB index +; output: A - destroyed +ciobuf_to_iocb: + lda #CIO_buffer + sta ICBAH,x + rts + + +; copy file name pointed to by 'zpptr1' to bounce buffer 'CIO_buffer' +; input: Y - index into file name buffer and CIO_buffer +; output: Y - points to first invalid byte after file name +; A - destroyed +copy_filename: + lda (zpptr1),y + sta CIO_buffer,y + beq copy_fn_done + iny + cmp #ATEOL + bne copy_filename + dey +copy_fn_done: + rts + + +; write IOCB buffer address into zpptr1 +; input: X - IOCB index +; output: Y - 0 (for setup_zpptr1_y0, else unchanged) +; A - destroyed +setup_zpptr1_y0: + ldy #0 +setup_zpptr1: + lda ICBAL,x ; put buffer address into zp pointer + sta zpptr1 + lda ICBAH,x + sta zpptr1+1 + rts + +;--------------------------------------------------------- + my_SIOV: pha lda PORTB @@ -263,6 +525,7 @@ my_SIOV: plp rts +;--------------------------------------------------------- KEYBDV_wrapper: @@ -284,8 +547,16 @@ kret: pha pla rts +CIO_a: .res 1 +CIO_x: .res 1 +CIO_y: .res 1 +CIO_p: .res 1 cur_CIOV_PORTB: .res 1 cur_SIOV_PORTB: .res 1 cur_KEYBDV_PORTB: .res 1 +orig_ptr: .res 2 +orig_len: .res 2 +req_len: .res 2 +retlen: .res 2 .endif ; .if .defined(__ATARIXL__) From 9f8b5668e14ca68c063dce6ce338df9bedcfab7b Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 13 Jun 2013 00:54:03 +0200 Subject: [PATCH 020/144] Add handling of write requests --- libsrc/atari/shadow_ram_handlers.s | 201 +++++++++++++++++++++++++---- 1 file changed, 178 insertions(+), 23 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 9bd9e11c3..8c4400cbc 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -94,7 +94,7 @@ sram_init: .segment "EXTZP" : zeropage zpptr1: .res 2 -zpptr2: .res 2 +;zpptr2: .res 2 .segment "LOWBUFS" @@ -195,17 +195,6 @@ CIOV_call: rts - - -CIO_write: - lda ICBLL,x - ora ICBLH,x - beq CIO_call_a ; special I/O through A register in case buffer length is 0 - - ;... - bne CIO_call_a - - ; CIO handler ; We have buffer pointer and length entries in the IOCB, but their ; usage depends on the function. @@ -220,9 +209,6 @@ CIO_write: my_CIOV: - ;jmp CIOV_call - ;brk - ; @@@ TODO: check X for valid IOCB index ((X < $80) and ((X & $F) == 0)) sta CIO_a @@ -235,7 +221,7 @@ my_CIOV: cmp #PUTREC bcc CIO_read ; input (GETREC or GETCHR) cmp #CLOSE - bcc CIO_write ; output (PUTREC or PUTCHR) + bcc CIO_write_jmp ; output (PUTREC or PUTCHR) beq CIO_call_a ; pass through, buffer not used cmp #RENAME ; 2 filenames as input parameters in buffer, length not used beq CIO_filename2 @@ -245,12 +231,20 @@ my_CIOV: bcs CIO_call_a ; other commands: assume no buffer ; not reached +CIO_write_jmp: + jmp CIO_write + + +; READ handler +; ------------ CIO_read: lda ICBLL,x ora ICBLH,x beq CIO_call_a ; special I/O through A register in case buffer length is 0 +; @@@ TODO: check if bounce buffer is really needed because buffer is in ROM area + ; If the data length is larger than our bounce buffer, we have to split the request into smaller ones. ; Otherwise we can get away with one call and a copy to the final destination afterwards. @@ -267,16 +261,16 @@ CIO_read: jsr ciobuf_to_iocb jsr CIO_call_a ; call CIO php - bpl no_err + bpl @no_err cpy #EOFERR - beq no_err + beq @no_err pha jsr restore_icba pla plp rts ; return with error -no_err: +@no_err: sta CIO_a sty CIO_y @@ -356,6 +350,7 @@ br_no_err: bne br_done ; update user buffer pointer (zpptr1) + clc lda zpptr1 adc ICBLL,x sta zpptr1 @@ -394,6 +389,149 @@ br_done: +CIO_call_a_jmp: + jmp CIO_call_a + + + +; WRITE handler +; ------------- + + +CIO_write: + lda ICBLL,x + ora ICBLH,x + beq CIO_call_a_jmp ; special I/O through A register in case buffer length is 0 + +; @@@ TODO: check if bounce buffer is really needed because buffer is in ROM area + +; If the data length is larger than our bounce buffer, we have to split the request into smaller ones. +; Otherwise we can get away with a copy to the bounce buffer and the call. + + lda ICBLH,x ; get high byte of length + bne big_write ; not zero -> data too large for our buffers + ; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES + lda # bounce buffer size? + bcs bw_last ; no, last transfer, use remaining size + + lda #>BUFSZ_CIO + sta ICBLH,x ; set data length + lda # 255 BYTES) - beq copy_done -copy: dey + beq @copy_done +@copy: dey lda CIO_buffer,y sta (zpptr1),y cpy #0 - bne copy -copy_done: + bne @copy +@copy_done: + rts + + +; copy data from user buffer into bounce buffer +; input: X - IOCB index +; zpptr1 - pointer to user buffer +; output: A - destroyed +; Y - 0 +copy_from_user: + ldy ICBLL,x ; get # of bytes to write (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES) + beq @copy_done +@copy: dey + lda (zpptr1),y + sta CIO_buffer,y + cpy #0 + bne @copy +@copy_done: rts From ce1313b36cbaf313d587eac6555078e1bea3aa68 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 13 Jun 2013 01:07:40 +0200 Subject: [PATCH 021/144] some debug messages ".ifdef DEBUG" --- libsrc/atari/shadow_ram_prepare.s | 6 +++++- libsrc/atari/system_check.s | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 6bc3ab87e..34c3f570f 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -9,6 +9,8 @@ ; Christian Groessler, chris@groessler.org, 2013 ; +DEBUG = 1 + .if .defined(__ATARIXL__) .export sramprep @@ -162,8 +164,10 @@ okoko: sta ICCOM,x jsr CIOV_org - print_string "GR 0 OKOKO" +.ifdef DEBUG + print_string "Stage #2 OK" jsr delay +.endif ; Save the zero page locations we need diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index 19e574243..d197dfdb6 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -11,6 +11,8 @@ ; Christian Groessler, chris@groessler.org, 2013 ; +DEBUG = 1 + .if .defined(__ATARIXL__) .export syschk @@ -118,6 +120,10 @@ sys_ok: lda #<__SAVEAREA_LOAD__ ; all is well(tm), launch the application memlo_ok: +.ifdef DEBUG + print_string "Stage #1 OK" + jsr delay +.endif rts From a6477c8caf184b45c3d61fd4e98edad308bcc341 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 13 Jun 2013 01:16:05 +0200 Subject: [PATCH 022/144] better error message --- libsrc/atari/shadow_ram_prepare.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 34c3f570f..fe367dbdc 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -148,7 +148,7 @@ sys_ok: lda #<__SAVEAREA_LOAD__ jsr CIOV_org bpl okoko - print_string "GR 0 FAILED" + print_string "Internal error, aborting..." jsr delay jsr delay jsr delay From 7eca62f8e4953ae69c9b2201c829287c355751dc Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 13 Jun 2013 01:16:35 +0200 Subject: [PATCH 023/144] Move scrdev into it's own file. On the atarixl target it will be referenced by crt0.s. --- libsrc/atari/graphics.s | 6 +----- libsrc/atari/scrdev.s | 7 +++++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 libsrc/atari/scrdev.s diff --git a/libsrc/atari/graphics.s b/libsrc/atari/graphics.s index 60f2ff789..cad5412bc 100644 --- a/libsrc/atari/graphics.s +++ b/libsrc/atari/graphics.s @@ -15,6 +15,7 @@ .import clriocb .import fdtoiocb .import newfd + .import scrdev .importzp tmp1,tmp2,tmp3 .include "atari.inc" @@ -100,8 +101,3 @@ cioerr: jsr fddecusage ; decrement usage counter of fd as open failed jmp __do_oserror .endproc ; __graphics - - - .rodata - -scrdev: .byte "S:", 0 diff --git a/libsrc/atari/scrdev.s b/libsrc/atari/scrdev.s new file mode 100644 index 000000000..c9d5b6919 --- /dev/null +++ b/libsrc/atari/scrdev.s @@ -0,0 +1,7 @@ +; Name of the "screen" device + + .export scrdev + + .rodata + +scrdev: .byte "S:", 0 From e621ca0ccebb48dfb389c42029d8ff8010f93c9a Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 13 Jun 2013 01:17:53 +0200 Subject: [PATCH 024/144] Better cleanup on program exit on atarixl target --- libsrc/atari/crt0.s | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 73d216713..844b70368 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -18,7 +18,9 @@ .import __RAM_START__, __RAM_SIZE__ .import zpsave .import sram_init - +.if .defined(__ATARIXL__) + .import scrdev +.endif .include "zeropage.inc" .include "atari.inc" @@ -167,6 +169,8 @@ _exit: jsr donelib ; Run module destructors lda PORTB_save sta PORTB + lda RAMTOP_save + sta RAMTOP lda MEMTOP_save sta MEMTOP lda MEMTOP_save+1 @@ -175,6 +179,33 @@ _exit: jsr donelib ; Run module destructors sta APPMHI lda APPMHI_save+1 sta APPMHI+1 + + + +; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) + + + ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) + + ; Reopen it in Graphics 0 + lda #OPEN + sta ICCOM,x + lda #OPNIN | OPNOT + sta ICAX1,x + lda #0 + sta ICAX2,x + lda #scrdev + sta ICBAH,x + lda #3 + sta ICBLL,x + lda #0 + sta ICBLH,x + jsr CIOV_org + + + .endif From b45c765969a3063c30ae6003f84b6b1d9340f69a Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Mon, 17 Jun 2013 18:56:28 +0200 Subject: [PATCH 025/144] make one more debug message ".ifdef DEBUG" --- libsrc/atari/shadow_ram_prepare.s | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index fe367dbdc..e3be4799d 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -57,7 +57,9 @@ cont: ldx #0 ; channel 0 .segment "SRPREP" sramprep: +.ifdef DEBUG print_string "in sramprep" +.endif ; save values of modified system variables and ports From 47d16e86a40ebc3ba74f1293419307ea490f03bb Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 18 Jun 2013 13:00:51 +0200 Subject: [PATCH 026/144] Add indication on the screen of occurring IRQs and NMIs (only for debug version). NMI handler: set I status bit to original value before interrupt before chaining to ROM NMI handler. --- libsrc/atari/shadow_ram_handlers.s | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 8c4400cbc..206dcfcaf 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -4,6 +4,7 @@ ; Christian Groessler, chris@groessler.org, 2013 ; +DEBUG = 1 .if .defined(__ATARIXL__) @@ -132,9 +133,50 @@ ret: disable_rom .endmacro my_IRQ_han: +.ifdef DEBUG + php + pha + tya + pha + ldy #0 + lda (SAVMSC),y + clc + adc #1 + sta (SAVMSC),y + pla + tay + pla + plp +.endif int_wrap IRQ_save my_NMI_han: +.ifdef DEBUG + php + pha + tya + pha + ldy #39 + lda (SAVMSC),y + clc + adc #1 + sta (SAVMSC),y + pla + tay + pla + plp +.endif +; set I bit to interrupted value + pha + txa + pha + tsx + lda $103,x + pha + plp + pla + tax + pla int_wrap NMI_save my_RESET_han: From 2a525f8a48fc1eb9a4dd911c660e087fe3d2e94b Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 19 Jun 2013 11:05:03 +0200 Subject: [PATCH 027/144] some cleanups --- libsrc/atari/shadow_ram_handlers.s | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 206dcfcaf..3c65c98ee 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -51,8 +51,6 @@ sram_init: stx NMIEN ; disable NMI ; disable ROMs - ;inx - ;stx enable_count disable_rom ; setup interrupt vectors @@ -95,7 +93,6 @@ sram_init: .segment "EXTZP" : zeropage zpptr1: .res 2 -;zpptr2: .res 2 .segment "LOWBUFS" @@ -180,7 +177,8 @@ my_NMI_han: int_wrap NMI_save my_RESET_han: - int_wrap RESET_save + enable_rom + jmp (RESET_save) ; System request handlers @@ -200,7 +198,6 @@ CIO_fn_cont: jsr CIO_call_a ; call CIO (maybe A isn't needed, then we could call CIO_call) php pha -;@@@ check if X is preserved over CIO call jsr restore_icba ; restore original ICBAL/ICBAH pla plp From 6ed1b07e594d400e6263708eee69f18e5ac17986 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 20 Jun 2013 23:31:41 +0200 Subject: [PATCH 028/144] Fix check whether there is enough memory btw. MEMLO and the program load address to move screen buffer there. --- libsrc/atari/shadow_ram_prepare.s | 20 ++----- libsrc/atari/system_check.s | 20 ++----- libsrc/atari/xlmemchk.inc | 91 +++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 30 deletions(-) create mode 100644 libsrc/atari/xlmemchk.inc diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index e3be4799d..81b05ece3 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -107,26 +107,18 @@ sramprep: ora #2 sta PORTB +.include "xlmemchk.inc" -; ... change system memory variables bla - -CMPVAL = 64+255+992 ; you may ask, why these values... @@@ document - -sys_ok: lda #<__SAVEAREA_LOAD__ - sec - sbc #__SAVEAREA_LOAD__ - sbc #>CMPVAL + ldx tstadr2 + stx MEMTOP + stx APPMHI + lda tstadr2+1 sta MEMTOP+1 sta APPMHI+1 - - lda #>__SAVEAREA_LOAD__ - 1 + lda lowadr+1 sta RAMTOP - ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index d197dfdb6..bb0fe483e 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -90,27 +90,15 @@ is_xl: lda RAMSIZ fail: jsr delay jmp (DOSVEC) -lowadr: .res 2 ; lowest address we need in order to move screen memory down, depending on start address of program - -; system is basically supported, check if there is enough space btw. MEMLO and our start address -; to move screen memory there - -CMPVAL = 64+255+992 ; you may ask, why these values... @@@ document - -sys_ok: lda #<__SAVEAREA_LOAD__ - sec - sbc #__SAVEAREA_LOAD__ - sbc #>CMPVAL - sta lowadr+1 +sys_ok: +.include "xlmemchk.inc" sec lda MEMLO - sbc lowadr + sbc tstadr2 lda MEMLO+1 - sbc lowadr+1 + sbc tstadr2+1 bcc memlo_ok ; load address was too low diff --git a/libsrc/atari/xlmemchk.inc b/libsrc/atari/xlmemchk.inc new file mode 100644 index 000000000..a4207aaec --- /dev/null +++ b/libsrc/atari/xlmemchk.inc @@ -0,0 +1,91 @@ +; ... change system memory variables bla + + + jmp cont + +lowadr: .word __SAVEAREA_LOAD__ & $FF00 ; our load address, rounded down to page boundary +tstadr: .res 2 +tstadr2:.res 2 +tmp: .res 1 + + +; When setting a display mode, the ROM takes the RAMTOP value +; and subtracts the size of the screen memory from it. This will +; become the new screen memory address. +; From this address it subtracts the size of the display list. +; This will become the new display list address. +; Screen memory cannot cross 4K boundaries and a display list +; cannot cross a 1K boundary. +; Work out a sane value for RAMTOP to prevent boundary crossing. +; RAMTOP is only one byte, it counts in memory pages. + +cont: + +_SCRBUFSZ = (40 * 24) ; size of mode 0 screen buffer +_DLSZ = 32 ; size of mode 0 display list + +; subtract screen memory size from our load address + + lda lowadr + sec + sbc #<_SCRBUFSZ + sta tstadr + lda lowadr+1 + sbc #>_SCRBUFSZ + sta tstadr+1 + +; check if a 4K boundary is crossed + + lda lowadr+1 + and #$f0 + sta tmp + lda tstadr+1 + and #$f0 + cmp tmp + beq scrmemok + +; 4K boundary will be crossed, take 4K boundary address as lowadr + +al4k: lda lowadr+1 + and #$f0 + tax + dex + stx lowadr+1 + bne cont + +; subtract display list size from calculated screen address + +scrmemok: + lda tstadr + sec + sbc #<_DLSZ + sta tstadr2 + lda tstadr+1 + sbc #>_DLSZ + sta tstadr2+1 + +; check if a 1K boundary is crossed + + lda tstadr+1 + and #$fc + sta tmp + lda tstadr2+1 + and #$fc + cmp tmp + bne al4k ; 1K boundary will be crossed, decrease lowadr + +; address of display list is ok + +dlok: + +; decrease tstadr2 by two + + lda tstadr2 + sec + sbc #2 + sta tstadr2 + bcs dec_cont + lda tstadr2+1 + sbc #0 + sta tstadr2+1 +dec_cont: From f16516047a551319c82debd339ded8bc2b587212 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 21 Jun 2013 00:01:07 +0200 Subject: [PATCH 029/144] cleanups and add more comments --- libsrc/atari/shadow_ram_prepare.s | 8 +-- libsrc/atari/system_check.s | 6 +- libsrc/atari/xlmemchk.inc | 92 +++++++++++++++++++------------ 3 files changed, 63 insertions(+), 43 deletions(-) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 81b05ece3..079443ae6 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -107,15 +107,15 @@ sramprep: ora #2 sta PORTB -.include "xlmemchk.inc" + .include "xlmemchk.inc" ; calculate lowest address used and new value for RAMTOP - ldx tstadr2 + ldx lowadr stx MEMTOP stx APPMHI - lda tstadr2+1 + lda lowadr+1 sta MEMTOP+1 sta APPMHI+1 - lda lowadr+1 + lda lodadr+1 sta RAMTOP diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index bb0fe483e..ee7480922 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -92,13 +92,13 @@ fail: jsr delay sys_ok: -.include "xlmemchk.inc" + .include "xlmemchk.inc" ; calculate lowest address we will use when we move the screen buffer down sec lda MEMLO - sbc tstadr2 + sbc lowadr lda MEMLO+1 - sbc tstadr2+1 + sbc lowadr+1 bcc memlo_ok ; load address was too low diff --git a/libsrc/atari/xlmemchk.inc b/libsrc/atari/xlmemchk.inc index a4207aaec..9cc6b612c 100644 --- a/libsrc/atari/xlmemchk.inc +++ b/libsrc/atari/xlmemchk.inc @@ -1,12 +1,21 @@ -; ... change system memory variables bla - - - jmp cont - -lowadr: .word __SAVEAREA_LOAD__ & $FF00 ; our load address, rounded down to page boundary -tstadr: .res 2 -tstadr2:.res 2 -tmp: .res 1 +; +; Christian Groessler, Jun-2013 +; +; This routine is used in preparation to move the screen memory +; in front of the program. +; +; It calculates the value to put into RAMTOP for a subsequent +; "GRAPHICS 0" call, and the lowest address which will be used +; by the screen memory afterwards. +; +; inputs: +; __SAVEAREA_LOAD__ - load address of the program +; outputs: +; lodadr - (high byte only) value to +; write into RAMTOP +; lowadr - lowest address occupied by +; screen data +; ; When setting a display mode, the ROM takes the RAMTOP value @@ -16,27 +25,35 @@ tmp: .res 1 ; This will become the new display list address. ; Screen memory cannot cross 4K boundaries and a display list ; cannot cross a 1K boundary. +; ; Work out a sane value for RAMTOP to prevent boundary crossing. ; RAMTOP is only one byte, it counts in memory pages. +; +; The ROM doesn't do this boundary checking, since it doesn't +; expect RAMTOP to have (rather) arbitrary values. For a +; "GRAPHICS 0" call and RAMTOP representing the possible physically +; available memory, boundary crossing cannot happen. -cont: -_SCRBUFSZ = (40 * 24) ; size of mode 0 screen buffer -_DLSZ = 32 ; size of mode 0 display list +SCRBUFSZ = (40 * 24) ; size of mode 0 screen buffer +DLSZ = 32 ; size of mode 0 display list + + +scrmemtst: ; subtract screen memory size from our load address - lda lowadr + lda lodadr sec - sbc #<_SCRBUFSZ + sbc #_SCRBUFSZ + lda lodadr+1 + sbc #>SCRBUFSZ sta tstadr+1 ; check if a 4K boundary is crossed - lda lowadr+1 + lda lodadr+1 and #$f0 sta tmp lda tstadr+1 @@ -44,48 +61,51 @@ _DLSZ = 32 ; size of mode 0 display list cmp tmp beq scrmemok -; 4K boundary will be crossed, take 4K boundary address as lowadr +; 4K boundary will be crossed, use this 4K boundary address as lodadr -al4k: lda lowadr+1 +al4k: lda lodadr+1 and #$f0 tax dex - stx lowadr+1 - bne cont + stx lodadr+1 + bne scrmemtst +; not reached + + +lodadr: .word __SAVEAREA_LOAD__ & $FF00 ; our program's load address, rounded down to page boundary +tstadr: .res 2 +lowadr: .res 2 +tmp: .res 1 + ; subtract display list size from calculated screen address scrmemok: lda tstadr sec - sbc #<_DLSZ - sta tstadr2 + sbc #_DLSZ - sta tstadr2+1 + sbc #>DLSZ + sta lowadr+1 ; check if a 1K boundary is crossed lda tstadr+1 and #$fc sta tmp - lda tstadr2+1 + lda lowadr+1 and #$fc cmp tmp - bne al4k ; 1K boundary will be crossed, decrease lowadr + bne al4k ; 1K boundary will be crossed, decrease lodadr ; address of display list is ok +; decrease lowadr by two -dlok: - -; decrease tstadr2 by two - - lda tstadr2 + lda lowadr sec sbc #2 - sta tstadr2 + sta lowadr bcs dec_cont - lda tstadr2+1 - sbc #0 - sta tstadr2+1 + dec lowadr+1 dec_cont: From 73c4566ca7ef4f5d441c234a543e1ec99e3a136b Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 21 Jun 2013 01:53:13 +0200 Subject: [PATCH 030/144] Fix writing one byte beyond screen buffer. --- libsrc/atari/clrscr.s | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libsrc/atari/clrscr.s b/libsrc/atari/clrscr.s index 58fb63137..483cd047e 100644 --- a/libsrc/atari/clrscr.s +++ b/libsrc/atari/clrscr.s @@ -9,26 +9,26 @@ .importzp ptr1 .import setcursor +SCRSIZE = 960 ; 40x24: size of default atari screen + _clrscr:lda SAVMSC ; screen memory sta ptr1 lda SAVMSC+1 clc - adc #>(40*24) + adc #>(SCRSIZE-1) sta ptr1+1 lda #0 ; screen code of space char sta OLDCHR - ldy #<(40*24) ; 40x24: size of default atari screen - ldx #>(40*24) + ldy #<(SCRSIZE-1) + ldx #>(SCRSIZE-1) _clr1: sta (ptr1),y dey bne _clr1 sta (ptr1),y dex bmi done - ldy ptr1+1 + dec ptr1+1 dey - sty ptr1+1 - ldy #255 jmp _clr1 done: sta COLCRS From 1347947f0d76040b92e694c5b290c78fd22da885 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 25 Jun 2013 00:48:26 +0200 Subject: [PATCH 031/144] some nicer debug messages --- libsrc/atari/shadow_ram_prepare.s | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 079443ae6..123872196 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -58,7 +58,7 @@ cont: ldx #0 ; channel 0 sramprep: .ifdef DEBUG - print_string "in sramprep" + print_string "entering stage #2" .endif ; save values of modified system variables and ports @@ -158,11 +158,6 @@ okoko: sta ICCOM,x jsr CIOV_org -.ifdef DEBUG - print_string "Stage #2 OK" - jsr delay -.endif - ; Save the zero page locations we need @@ -174,6 +169,11 @@ L1: lda sp,x ; copy chargen to low memory +.ifdef DEBUG + print_string "copy chargen to low memory" + print_string "set up high memory" +.endif + lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) sta ptr3+1 lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) @@ -235,7 +235,7 @@ do_copy:lda #<__SHADOW_RAM_LOAD__ no_copy: -; copy chargen to its new location +; copy chargen to its new (final) location lda ptr3 sta ptr1 @@ -260,6 +260,10 @@ no_copy: sta NMIEN ; enable VB again cli ; and enable IRQs +.ifdef DEBUG + print_string "Stage #2 OK" + jsr delay +.endif rts From be880bd15799df2b0ce8eceea44a81f9d02a0262 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 25 Jun 2013 00:48:43 +0200 Subject: [PATCH 032/144] remove TABs --- libsrc/atari/shadow_ram_prepare.s | 370 +++++++++++++++--------------- 1 file changed, 185 insertions(+), 185 deletions(-) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 123872196..5f1e90437 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -9,38 +9,38 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -DEBUG = 1 +DEBUG = 1 .if .defined(__ATARIXL__) - .export sramprep + .export sramprep .import __SRPREP_LOAD__, __SRPREP_SIZE__ - .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__ - .import __SHADOW_RAM_RUN__ - .import __CHARGEN_START__, __CHARGEN_SIZE__ - .import __SAVEAREA_LOAD__ - .import zpsave + .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__ + .import __SHADOW_RAM_RUN__ + .import __CHARGEN_START__, __CHARGEN_SIZE__ + .import __SAVEAREA_LOAD__ + .import zpsave .include "zeropage.inc" .include "atari.inc" - .include "save_area.inc" + .include "save_area.inc" .macro print_string text - .local start, cont - jmp cont -start: .byte text, ATEOL -cont: ldx #0 ; channel 0 - lda #start - sta ICBAH,x - lda #<(cont - start) - sta ICBLL,x ; length - lda #>(cont - start) - sta ICBLH,x - lda #PUTCHR - sta ICCOM,x - jsr CIOV_org + .local start, cont + jmp cont +start: .byte text, ATEOL +cont: ldx #0 ; channel 0 + lda #start + sta ICBAH,x + lda #<(cont - start) + sta ICBLL,x ; length + lda #>(cont - start) + sta ICBLH,x + lda #PUTCHR + sta ICCOM,x + jsr CIOV_org .endmacro ; ------------------------------------------------------------------------ @@ -58,71 +58,71 @@ cont: ldx #0 ; channel 0 sramprep: .ifdef DEBUG - print_string "entering stage #2" + print_string "entering stage #2" .endif ; save values of modified system variables and ports - lda RAMTOP - sta RAMTOP_save - lda MEMTOP - sta MEMTOP_save - lda MEMTOP+1 - sta MEMTOP_save+1 - lda APPMHI - sta APPMHI_save - lda APPMHI+1 - sta APPMHI_save+1 - lda PORTB - sta PORTB_save - lda CIOV ; zero-page wrapper - sta ZP_CIOV_save - lda CIOV+1 - sta ZP_CIOV_save+1 - lda CIOV+2 - sta ZP_CIOV_save+2 - lda SIOV ; zero-page wrapper - sta ZP_SIOV_save - lda SIOV+1 - sta ZP_SIOV_save+1 - lda SIOV+2 - sta ZP_SIOV_save+2 + lda RAMTOP + sta RAMTOP_save + lda MEMTOP + sta MEMTOP_save + lda MEMTOP+1 + sta MEMTOP_save+1 + lda APPMHI + sta APPMHI_save + lda APPMHI+1 + sta APPMHI_save+1 + lda PORTB + sta PORTB_save + lda CIOV ; zero-page wrapper + sta ZP_CIOV_save + lda CIOV+1 + sta ZP_CIOV_save+1 + lda CIOV+2 + sta ZP_CIOV_save+2 + lda SIOV ; zero-page wrapper + sta ZP_SIOV_save + lda SIOV+1 + sta ZP_SIOV_save+1 + lda SIOV+2 + sta ZP_SIOV_save+2 - lda $fffe - sta IRQ_save - lda $ffff - sta IRQ_save+1 - lda $fffc - sta RESET_save - lda $fffd - sta RESET_save+1 - lda $fffa - sta NMI_save - lda $fffb - sta NMI_save+1 + lda $fffe + sta IRQ_save + lda $ffff + sta IRQ_save+1 + lda $fffc + sta RESET_save + lda $fffd + sta RESET_save+1 + lda $fffa + sta NMI_save + lda $fffb + sta NMI_save+1 ; disable BASIC - lda PORTB - ora #2 - sta PORTB + lda PORTB + ora #2 + sta PORTB - .include "xlmemchk.inc" ; calculate lowest address used and new value for RAMTOP + .include "xlmemchk.inc" ; calculate lowest address used and new value for RAMTOP - ldx lowadr - stx MEMTOP - stx APPMHI - lda lowadr+1 - sta MEMTOP+1 - sta APPMHI+1 - lda lodadr+1 - sta RAMTOP + ldx lowadr + stx MEMTOP + stx APPMHI + lda lowadr+1 + sta MEMTOP+1 + sta APPMHI+1 + lda lodadr+1 + sta RAMTOP ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) - ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) + ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) ; Reopen it in Graphics 0 lda #OPEN @@ -140,14 +140,14 @@ sramprep: lda #>screen_device_length sta ICBLH,x jsr CIOV_org - bpl okoko + bpl okoko - print_string "Internal error, aborting..." - jsr delay - jsr delay - jsr delay + print_string "Internal error, aborting..." + jsr delay + jsr delay + jsr delay - jmp (DOSVEC) ; abort loading + jmp (DOSVEC) ; abort loading okoko: @@ -170,99 +170,99 @@ L1: lda sp,x ; copy chargen to low memory .ifdef DEBUG - print_string "copy chargen to low memory" - print_string "set up high memory" + print_string "copy chargen to low memory" + print_string "set up high memory" .endif - lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) - sta ptr3+1 - lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) - sta ptr3 - beq cg_addr_ok + lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) + sta ptr3+1 + lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) + sta ptr3 + beq cg_addr_ok - ; page align the new chargen address - inc ptr3+1 - lda #0 - sta ptr3 + ; page align the new chargen address + inc ptr3+1 + lda #0 + sta ptr3 cg_addr_ok: - lda #DCSORG - sta ptr1+1 - lda ptr3 - sta ptr2 - lda ptr3+1 - sta ptr2+1 - lda #>__CHARGEN_SIZE__ - sta tmp2 - lda #<__CHARGEN_SIZE__ - sta tmp2+1 - jsr memcopy + lda #DCSORG + sta ptr1+1 + lda ptr3 + sta ptr2 + lda ptr3+1 + sta ptr2+1 + lda #>__CHARGEN_SIZE__ + sta tmp2 + lda #<__CHARGEN_SIZE__ + sta tmp2+1 + jsr memcopy ; TODO: switch to this temp. chargen ; disable ROMs - sei - ldx #0 - stx NMIEN ; disable NMI - lda PORTB - and #$fe - sta PORTB ; now ROM is mapped out + sei + ldx #0 + stx NMIEN ; disable NMI + lda PORTB + and #$fe + sta PORTB ; now ROM is mapped out ; copy shadow RAM contents to their destination - lda #<__SHADOW_RAM_SIZE__ - bne do_copy - lda #>__SHADOW_RAM_SIZE__ - beq no_copy ; we have no shadow RAM contents + lda #<__SHADOW_RAM_SIZE__ + bne do_copy + lda #>__SHADOW_RAM_SIZE__ + beq no_copy ; we have no shadow RAM contents - ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len -do_copy:lda #<__SHADOW_RAM_LOAD__ - sta ptr1 - lda #>__SHADOW_RAM_LOAD__ - sta ptr1+1 - lda #<__SHADOW_RAM_RUN__ - sta ptr2 - lda #>__SHADOW_RAM_RUN__ - sta ptr2+1 - lda #<__SHADOW_RAM_SIZE__ - sta tmp1 - lda #>__SHADOW_RAM_SIZE__ - sta tmp2 + ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len +do_copy:lda #<__SHADOW_RAM_LOAD__ + sta ptr1 + lda #>__SHADOW_RAM_LOAD__ + sta ptr1+1 + lda #<__SHADOW_RAM_RUN__ + sta ptr2 + lda #>__SHADOW_RAM_RUN__ + sta ptr2+1 + lda #<__SHADOW_RAM_SIZE__ + sta tmp1 + lda #>__SHADOW_RAM_SIZE__ + sta tmp2 - jsr memcopy + jsr memcopy no_copy: ; copy chargen to its new (final) location - lda ptr3 - sta ptr1 - lda ptr3+1 - sta ptr1+1 - lda #<__CHARGEN_START__ - sta ptr2 - lda #>__CHARGEN_START__ - sta ptr2+1 - lda #>__CHARGEN_SIZE__ - sta tmp2 - lda #<__CHARGEN_SIZE__ - sta tmp1 - jsr memcopy + lda ptr3 + sta ptr1 + lda ptr3+1 + sta ptr1+1 + lda #<__CHARGEN_START__ + sta ptr2 + lda #>__CHARGEN_START__ + sta ptr2+1 + lda #>__CHARGEN_SIZE__ + sta tmp2 + lda #<__CHARGEN_SIZE__ + sta tmp1 + jsr memcopy ; re-enable ROM - lda PORTB - ora #1 - sta PORTB - lda #$40 - sta NMIEN ; enable VB again - cli ; and enable IRQs + lda PORTB + ora #1 + sta PORTB + lda #$40 + sta NMIEN ; enable VB again + cli ; and enable IRQs .ifdef DEBUG - print_string "Stage #2 OK" - jsr delay + print_string "Stage #2 OK" + jsr delay .endif rts @@ -274,26 +274,26 @@ no_copy: ; 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 @@ -301,32 +301,32 @@ done: rts .byte "HERE ****************** HERE ***************>>>>>>" sramsize: - .word __SHADOW_RAM_SIZE__ + .word __SHADOW_RAM_SIZE__ ; short delay -.proc delay +.proc delay - lda #10 -l: jsr delay1 - clc - sbc #0 - bne l - rts + lda #10 +l: jsr delay1 + clc + sbc #0 + bne l + rts -delay1: ldx #0 - ldy #0 -loop: dey - bne loop - dex - bne loop - rts +delay1: ldx #0 + ldy #0 +loop: dey + bne loop + dex + bne loop + rts .endproc -screen_device: .byte "S:",0 +screen_device: .byte "S:",0 screen_device_length = * - screen_device - .byte " ** srprep ** end-->" + .byte " ** srprep ** end-->" ; ------------------------------------------------------------------------ ; Provide an empty SHADOW_RAM segment in order that the linker is happy @@ -344,4 +344,4 @@ screen_device_length = * - screen_device .word INITAD+1 .word __SRPREP_LOAD__ -.endif ; .if .defined(__ATARIXL__) +.endif ; .if .defined(__ATARIXL__) From b31e0d32496a33e92818f44950dc7c84c376f87a Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 25 Jun 2013 00:53:21 +0200 Subject: [PATCH 033/144] small memory optimization: appmsav not needed in the xl target --- libsrc/atari/crt0.s | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 844b70368..9e3026625 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -233,9 +233,11 @@ L2: lda zpsave,x .bss spsave: .res 1 -appmsav: .res 1 old_shflok: .res 1 old_lmargin: .res 1 +.if .not .defined(__ATARIXL__) +appmsav: .res 1 +.endif .segment "AUTOSTRT" .word RUNAD ; defined in atari.h From df1165e0e0eb5f395cf043b0aedaef0d7201f102 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 25 Jun 2013 01:12:11 +0200 Subject: [PATCH 034/144] move findfreeiocb function into its own object file --- libsrc/atari/fdtable.s | 26 -------------------------- libsrc/atari/findfreeiocb.inc | 23 +++++++++++++++++++++++ libsrc/atari/findfreeiocb.s | 7 +++++++ 3 files changed, 30 insertions(+), 26 deletions(-) create mode 100644 libsrc/atari/findfreeiocb.inc create mode 100644 libsrc/atari/findfreeiocb.s diff --git a/libsrc/atari/fdtable.s b/libsrc/atari/fdtable.s index 7e3325055..fd9f5021b 100644 --- a/libsrc/atari/fdtable.s +++ b/libsrc/atari/fdtable.s @@ -11,7 +11,6 @@ .import fdt_to_fdi .export clriocb .export fdtoiocb_down - .export findfreeiocb .export fddecusage .export newfd @@ -87,31 +86,6 @@ loop: sta ICHID,x .endproc -; find a free iocb -; no entry parameters -; return ZF = 0/1 for not found/found -; index in X if found -; all registers destroyed - -.proc findfreeiocb - - ldx #0 - ldy #$FF -loop: tya - cmp ICHID,x - beq found - txa - clc - adc #$10 - tax - cmp #$80 - bcc loop - inx ; return ZF cleared -found: rts - -.endproc ; findfreeiocb - - ; decrements usage counter for fd ; if 0 reached, it's marked as unused ; get fd index in tmp2 diff --git a/libsrc/atari/findfreeiocb.inc b/libsrc/atari/findfreeiocb.inc new file mode 100644 index 000000000..92140efd4 --- /dev/null +++ b/libsrc/atari/findfreeiocb.inc @@ -0,0 +1,23 @@ +; find a free iocb +; no entry parameters +; return ZF = 0/1 for not found/found +; index in X if found +; all registers destroyed + +.proc findfreeiocb + + ldx #0 + ldy #$FF +loop: tya + cmp ICHID,x + beq found + txa + clc + adc #$10 + tax + cmp #$80 + bcc loop + inx ; return ZF cleared +found: rts + +.endproc ; findfreeiocb diff --git a/libsrc/atari/findfreeiocb.s b/libsrc/atari/findfreeiocb.s new file mode 100644 index 000000000..a500b1f77 --- /dev/null +++ b/libsrc/atari/findfreeiocb.s @@ -0,0 +1,7 @@ +; +; Christian Groessler, June-2013 +; + + .include "atari.inc" + .export findfreeiocb + .include "findfreeiocb.inc" From a03b3574b65a6167ac1207e66b83888eb0ca8465 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 25 Jun 2013 01:27:47 +0200 Subject: [PATCH 035/144] use first free IOCB for "GRAPHICS 0" call instead of using a hard-coded one --- libsrc/atari/crt0.s | 11 +++++---- libsrc/atari/shadow_ram_prepare.s | 38 +++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 9e3026625..b9c20cc72 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -20,6 +20,7 @@ .import sram_init .if .defined(__ATARIXL__) .import scrdev + .import findfreeiocb .endif .include "zeropage.inc" @@ -181,11 +182,9 @@ _exit: jsr donelib ; Run module destructors sta APPMHI+1 - ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) - - ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) + jsr findfreeiocb ; Reopen it in Graphics 0 lda #OPEN @@ -203,8 +202,10 @@ _exit: jsr donelib ; Run module destructors lda #0 sta ICBLH,x jsr CIOV_org - - +; add error checking here... + lda #CLOSE + sta ICCOM,x + jsr CIOV_org .endif diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 5f1e90437..f8a7dbbf6 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -122,7 +122,17 @@ sramprep: ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) - ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) + jsr findfreeiocb +.ifdef DEBUG ; only check in debug version, this shouldn't happen normally(tm) + beq iocbok + print_string "Internal error, no free IOCB!" + jsr delay + jsr delay + jsr delay + jsr restore ; restore stuff we've changed + jmp (DOSVEC) ; abort loading +iocbok: +.endif ; Reopen it in Graphics 0 lda #OPEN @@ -140,20 +150,18 @@ sramprep: lda #>screen_device_length sta ICBLH,x jsr CIOV_org - bpl okoko + bpl scrok +; shouldn't happen(tm) print_string "Internal error, aborting..." jsr delay jsr delay jsr delay - + jsr restore ; restore stuff we've changed jmp (DOSVEC) ; abort loading -okoko: - - - ; Now close it again; we don't need it anymore :) +scrok: ; now close it again -- we don't need it anymore lda #CLOSE sta ICCOM,x jsr CIOV_org @@ -266,6 +274,7 @@ no_copy: .endif rts +.include "findfreeiocb.inc" ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html) @@ -298,6 +307,21 @@ done: rts .endproc +; clean up after a fatal error + +restore:lda RAMTOP_save + sta RAMTOP + lda MEMTOP_save + sta MEMTOP + lda MEMTOP_save+1 + sta MEMTOP+1 + lda APPMHI_save + sta APPMHI + lda APPMHI_save+1 + sta APPMHI+1 + rts + + .byte "HERE ****************** HERE ***************>>>>>>" sramsize: From 250e26c56e071b59b0613ed07f4387650c834923 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 28 Jun 2013 01:08:07 +0200 Subject: [PATCH 036/144] Don't save original IRQ, NMI, and RESET vectors -- it's not needed. --- libsrc/atari/save_area.inc | 10 +++++++--- libsrc/atari/save_area.s | 8 +------- libsrc/atari/shadow_ram_handlers.s | 6 +++--- libsrc/atari/shadow_ram_prepare.s | 13 ------------- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/libsrc/atari/save_area.inc b/libsrc/atari/save_area.inc index d3868723d..f14152ae0 100644 --- a/libsrc/atari/save_area.inc +++ b/libsrc/atari/save_area.inc @@ -1,7 +1,11 @@ +; +; Atari XL, shared data between 2nd load chunk and main chunk, header file +; +; Contains old values of modified system variables and ports. +; +; Christian Groessler, chris@groessler.org, 2013 +; -.import IRQ_save -.import NMI_save -.import RESET_save .import SAVMSC_save .import MEMTOP_save .import APPMHI_save diff --git a/libsrc/atari/save_area.s b/libsrc/atari/save_area.s index e222b70bd..752e81487 100644 --- a/libsrc/atari/save_area.s +++ b/libsrc/atari/save_area.s @@ -1,5 +1,5 @@ ; -; Atari XL, shared data between 2nd load chunk and main chunk +; Atari XL, shared data between 2nd load chunk and main chunk, definition file ; ; Contains old values of modified system variables and ports. ; @@ -8,9 +8,6 @@ .if .defined(__ATARIXL__) -.export IRQ_save -.export NMI_save -.export RESET_save .export SAVMSC_save .export MEMTOP_save .export APPMHI_save @@ -21,9 +18,6 @@ .segment "SAVEAREA" -IRQ_save: .res 2 -NMI_save: .res 2 -RESET_save: .res 2 SAVMSC_save: .res 2 MEMTOP_save: .res 2 APPMHI_save: .res 2 diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 3c65c98ee..80dc5c2d1 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -145,7 +145,7 @@ my_IRQ_han: pla plp .endif - int_wrap IRQ_save + int_wrap $FFFE my_NMI_han: .ifdef DEBUG @@ -174,11 +174,11 @@ my_NMI_han: pla tax pla - int_wrap NMI_save + int_wrap $FFFA my_RESET_han: enable_rom - jmp (RESET_save) + jmp ($FFFC) ; System request handlers diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index f8a7dbbf6..6458ffdb1 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -88,19 +88,6 @@ sramprep: lda SIOV+2 sta ZP_SIOV_save+2 - lda $fffe - sta IRQ_save - lda $ffff - sta IRQ_save+1 - lda $fffc - sta RESET_save - lda $fffd - sta RESET_save+1 - lda $fffa - sta NMI_save - lda $fffb - sta NMI_save+1 - ; disable BASIC lda PORTB From f04dc3570c942d373f6781d90e505d157422a4c5 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 9 Jul 2013 23:39:42 +0200 Subject: [PATCH 037/144] close IOCB if open failed -- otherwise is is still marked as "in use" --- libsrc/atari/graphics.s | 13 +++++++++---- libsrc/atari/open.s | 8 ++++++-- libsrc/atari/posixdirent.s | 3 +++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/libsrc/atari/graphics.s b/libsrc/atari/graphics.s index cad5412bc..ab26ed0da 100644 --- a/libsrc/atari/graphics.s +++ b/libsrc/atari/graphics.s @@ -10,12 +10,12 @@ .export __graphics .import findfreeiocb - .import __do_oserror,__oserror + .import __oserror .import fddecusage .import clriocb .import fdtoiocb .import newfd - .import scrdev + .import scrdev .importzp tmp1,tmp2,tmp3 .include "atari.inc" @@ -97,7 +97,12 @@ doopen: txa stx __oserror rts -cioerr: jsr fddecusage ; decrement usage counter of fd as open failed - jmp __do_oserror +cioerr: sty tmp3 ; remember error code + lda #CLOSE + sta ICCOM,x + jsr CIOV ; close IOCB again since open failed + jsr fddecusage ; and decrement usage counter of fd + lda tmp3 ; put error code into A + jmp __mappederrno .endproc ; __graphics diff --git a/libsrc/atari/open.s b/libsrc/atari/open.s index 8aeff9ed4..306cf52c2 100644 --- a/libsrc/atari/open.s +++ b/libsrc/atari/open.s @@ -140,8 +140,12 @@ finish: php plp bpl ok - jsr fddecusage ; decrement usage counter of fd as open failed - tya ; put error code into A + sty tmp3 ; remember error code + lda #CLOSE + sta ICCOM,x + jsr CIOV ; close IOCB again since open failed + jsr fddecusage ; and decrement usage counter of fd + lda tmp3 ; put error code into A jmp __mappederrno ok: lda tmp2 ; get fd diff --git a/libsrc/atari/posixdirent.s b/libsrc/atari/posixdirent.s index 3417e4bfc..a722b3b06 100644 --- a/libsrc/atari/posixdirent.s +++ b/libsrc/atari/posixdirent.s @@ -63,6 +63,9 @@ .endproc cioerr: sty __oserror + lda #CLOSE + sta ICCOM,x + jsr CIOV ; close IOCB again since open failed jmp return0 .proc _readdir From a3ad7d07a195e3a539c5f6df8ff4f9a52fae7a00 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 16 Jul 2013 01:29:49 +0200 Subject: [PATCH 038/144] fix '_sysrmdir' for SpartaDOS --- asminc/atari.inc | 1 + libsrc/atari/sysrmdir.s | 89 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/asminc/atari.inc b/asminc/atari.inc index 6aeb48383..615765132 100644 --- a/asminc/atari.inc +++ b/asminc/atari.inc @@ -55,6 +55,7 @@ NOTE = $26 ;note sector GETFL = $27 ;get file length CHDIR_MYDOS = $29 ;change directory (MyDOS) MKDIR = $2A ;make directory (MyDOS/SpartaDOS) +RMDIR = $2B ;remove directory (SpartaDOS) CHDIR_SPDOS = $2C ;change directory (SpartaDOS) FORMAT = $FE ;format diff --git a/libsrc/atari/sysrmdir.s b/libsrc/atari/sysrmdir.s index 9c057ba44..2a2b160c1 100644 --- a/libsrc/atari/sysrmdir.s +++ b/libsrc/atari/sysrmdir.s @@ -1,10 +1,97 @@ ; ; Stefan Haubenthal, 2005-12-24 +; Christian Groessler, 2013-07-16 ; ; unsigned char __fastcall__ _sysrmdir (const char* name); +; +; for SpartaDOS and MyDOS ; + .include "atari.inc" + .include "errno.inc" .export __sysrmdir .import __sysremove + .import __dos_type + .import ucase_fn + .import findfreeiocb + .import addysp + .importzp sreg + .importzp tmp3 + .importzp tmp4 -__sysrmdir := __sysremove +.proc __sysrmdir + + pha + lda __dos_type + beq not_impl ; AtariDOS + cmp #OSADOS+1 + bcc do_sparta ; OS/A and SpartaDOS + pla + jmp __sysremove ; MyDOS and others (TODO: check XDOS) + +not_impl: + pla + lda #NVALID + rts + +iocberr: + pla ; cleanup stack + pla + lda #TMOF + rts + +do_sparta: + txa + pha + jsr findfreeiocb + bne iocberr ; no IOCB available + + stx tmp4 ; remember IOCB + pla + tax + pla + +.ifdef UCASE_FILENAME + + jsr ucase_fn + bcc ucok1 + + lda #183 ; see oserror.s + rts +ucok1: + +.endif ; defined UCASE_FILENAME + + ldy tmp4 ; IOCB index + sta ICBAL,y ; store pointer to filename + txa + sta ICBAH,y + tya + tax + lda #RMDIR + sta ICCOM,x + lda #0 + sta ICAX1,x + lda #0 + sta ICAX2,x + sta ICBLL,x + sta ICBLH,x + jsr CIOV + +.ifdef UCASE_FILENAME + tya + pha + ldy tmp3 ; get size + jsr addysp ; free used space on the stack + pla + tay +.endif ; defined UCASE_FILENAME + + bmi cioerr + lda #0 + rts + +cioerr: tya + rts + +.endproc ; __sysrmdir From 0bd97f5445a36d3e4e7b6685097bb10c63a0c338 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 17 Jul 2013 23:33:12 +0200 Subject: [PATCH 039/144] remove unused import sreg --- libsrc/atari/sysrmdir.s | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/atari/sysrmdir.s b/libsrc/atari/sysrmdir.s index 2a2b160c1..44930a072 100644 --- a/libsrc/atari/sysrmdir.s +++ b/libsrc/atari/sysrmdir.s @@ -15,7 +15,6 @@ .import ucase_fn .import findfreeiocb .import addysp - .importzp sreg .importzp tmp3 .importzp tmp4 From 8f23c1bac7a457636385a56ebca326947839b6e9 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 17 Jul 2013 23:37:03 +0200 Subject: [PATCH 040/144] don't include errno.inc -- not necessary --- libsrc/atari/sysrmdir.s | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/atari/sysrmdir.s b/libsrc/atari/sysrmdir.s index 44930a072..851d9ffa3 100644 --- a/libsrc/atari/sysrmdir.s +++ b/libsrc/atari/sysrmdir.s @@ -8,7 +8,6 @@ ; .include "atari.inc" - .include "errno.inc" .export __sysrmdir .import __sysremove .import __dos_type From 993555da949779c531ea74cbacd0931452869130 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 24 Jul 2013 00:40:09 +0200 Subject: [PATCH 041/144] implement _sysrename for Atari --- libsrc/atari/open.s | 5 +- libsrc/atari/syschdir.s | 7 ++ libsrc/atari/sysmkdir.s | 7 ++ libsrc/atari/sysremove.s | 7 ++ libsrc/atari/sysrename.s | 184 +++++++++++++++++++++++++++++++++++++++ libsrc/atari/sysrmdir.s | 13 ++- libsrc/atari/ucase_fn.s | 18 ++-- 7 files changed, 231 insertions(+), 10 deletions(-) create mode 100644 libsrc/atari/sysrename.s diff --git a/libsrc/atari/open.s b/libsrc/atari/open.s index 306cf52c2..2188257cb 100644 --- a/libsrc/atari/open.s +++ b/libsrc/atari/open.s @@ -91,7 +91,10 @@ cont: ldy #3 jsr ldaxysp .ifdef UCASE_FILENAME - +.ifdef DEFAULT_DEVICE + ldy #$80 + sty tmp2 ; set flag for ucase_fn +.endif jsr ucase_fn bcc ucok1 invret: lda # Date: Wed, 24 Jul 2013 00:44:44 +0200 Subject: [PATCH 042/144] Don't import tmp1, slipped in by mistake in last commit --- libsrc/atari/ucase_fn.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/atari/ucase_fn.s b/libsrc/atari/ucase_fn.s index eb3ebfb37..e53750e29 100644 --- a/libsrc/atari/ucase_fn.s +++ b/libsrc/atari/ucase_fn.s @@ -21,7 +21,7 @@ .include "atari.inc" .ifdef DEFAULT_DEVICE - .importzp tmp2, tmp1 + .importzp tmp2 .import __defdev .endif .importzp tmp3,ptr4,sp From d68307ee5279909dea6a6b4fce25aaca7ef39d58 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 24 Jul 2013 10:24:47 +0200 Subject: [PATCH 043/144] fix cleanup of stack --- libsrc/atari/sysrename.s | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libsrc/atari/sysrename.s b/libsrc/atari/sysrename.s index d3e430ada..fef18bded 100644 --- a/libsrc/atari/sysrename.s +++ b/libsrc/atari/sysrename.s @@ -164,13 +164,14 @@ copend2:ldx tmp4 clc adc sspc sta sp - bcc L2 - inc sp+1 -L2: pla - tay + lda sp+1 + adc sspc+1 + sta sp+1 ; handle status + pla + tay bmi cioerr lda #0 rts From 7ee873cc87915fbd07693b76f08bc7fdf06a3f6d Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 24 Jul 2013 15:04:56 +0200 Subject: [PATCH 044/144] add "tinyshell" test program for file operations --- testcode/lib/tinyshell.c | 385 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 385 insertions(+) create mode 100644 testcode/lib/tinyshell.c diff --git a/testcode/lib/tinyshell.c b/testcode/lib/tinyshell.c new file mode 100644 index 000000000..f4a18126b --- /dev/null +++ b/testcode/lib/tinyshell.c @@ -0,0 +1,385 @@ +/* + * Simple ("tiny") shell to test filename and directory functions. + * Copyright (c) 2013, Christian Groessler, chris@groessler.org + */ + +#define VERSION_ASC "0.90" + +#define KEYB_BUFSZ 80 +#define PROMPT ">>> " +#ifdef __ATARI__ +#define UPPERCASE /* define (e.g. for Atari) to convert filenames etc. to upper case */ +#endif + +#include +#include +#include +#include +#include +#ifndef __CC65__ +#include +#include +#else +#define MAXPATHLEN 64 +#endif +#include +#include +#include + +#define CMD_NOTHING 0 +#define CMD_INVALID 1 +#define CMD_HELP 2 +#define CMD_QUIT 3 +#define CMD_LS 4 +#define CMD_MKDIR 5 +#define CMD_RMDIR 6 +#define CMD_CHDIR 7 +#define CMD_RM 8 +#define CMD_RENAME 9 +#define CMD_COPY 10 +#define CMD_PWD 11 + +static unsigned char terminate; +static unsigned char cmd; +static unsigned char *cmd_asc, *arg1, *arg2, *arg3; +static unsigned char keyb_buf[KEYB_BUFSZ]; +static size_t cpbuf_sz = 4096; + +struct cmd_table { + unsigned char *name; + unsigned char code; +} cmd_table[] = { + { "help", CMD_HELP }, + { "quit", CMD_QUIT }, + { "q", CMD_QUIT }, + { "exit", CMD_QUIT }, + { "ls", CMD_LS }, + { "dir", CMD_LS }, + { "md", CMD_MKDIR }, + { "mkdir", CMD_MKDIR }, + { "rd", CMD_RMDIR }, + { "rmdir", CMD_RMDIR }, + { "cd", CMD_CHDIR }, + { "chdir", CMD_CHDIR }, + { "rm", CMD_RM }, + { "del", CMD_RM }, + { "cp", CMD_COPY }, + { "copy", CMD_COPY }, + { "mv", CMD_RENAME }, + { "ren", CMD_RENAME }, + { "pwd", CMD_PWD }, + { NULL, 0 } +}; + +static void banner(void) +{ + puts("\"tiny\" command line shell, v" VERSION_ASC); + puts("written by chris@groessler.org"); + puts("type 'help' for help\n"); +} + +static void get_command(void) +{ + unsigned char i = 0; + + arg1 = arg2 = arg3 = NULL; + + /* issue prompt */ + printf(PROMPT); + + /* get input from the user */ + if (! fgets(keyb_buf, KEYB_BUFSZ, stdin)) { + puts(""); + cmd = CMD_QUIT; + return; + } + + /* split input into cmd, arg1, arg2, arg3 */ + + /* get and parse command */ + cmd_asc = strtok(keyb_buf, " \t\n"); + if (! cmd_asc) { + cmd = CMD_NOTHING; + return; + } + cmd = CMD_INVALID; + while (cmd_table[i].name) { + if (! strcmp(cmd_table[i].name, cmd_asc)) { + cmd = cmd_table[i].code; + break; + } + i++; + } + + /* get arguments */ + arg1 = strtok(NULL, " \t\n"); + if (! arg1) + return; + arg2 = strtok(NULL, " \t\n"); + if (! arg2) + return; + arg3 = strtok(NULL, " \t\n"); +} + +static void cmd_help(void) +{ + puts("quit, exit - exit shell"); + puts("ls, dir - display current directory"); + puts(" and drive contents"); + puts("rm, del - delete file"); + puts("cp, copy - copy file"); + puts("mv, ren - rename file"); + puts("cd, chdir - change directory or drive"); + puts("md, mkdir - make directory or drive"); + puts("rd, rmdir - remove directory or drive"); + puts("sorry, you cannot start programs here"); +} + +static void cmd_ls(void) +{ + DIR *dir; + unsigned char *arg; + struct dirent *dirent; +#ifdef __ATARI__ + char need_free = 0; +#endif + + if (arg2) { + puts("usage: ls [dir]"); + return; + } + + /* print directory listing */ + if (arg1) { +#ifdef UPPERCASE + strupr(arg1); +#endif +#ifdef __ATARI__ + /* not sure if this shouldn't be done by the runtime lib */ + if (*(arg1 + strlen(arg1) - 1) == ':' || *(arg1 + strlen(arg1) - 1) == '>') { + arg = malloc(strlen(arg1) + 4); + if (! arg) { + printf("malloc failed: %s", strerror(errno)); + return; + } + need_free = 1; + memcpy(arg, arg1, strlen(arg1) + 1); + strcat(arg, "*.*"); + } + else +#endif + arg = arg1; + } + else + arg = "."; + + dir = opendir(arg); +#ifdef __ATARI__ + if (need_free) free(arg); +#endif + if (! dir) { + puts("opendir failed"); + return; + } + + while (dirent = readdir(dir)) + puts(dirent->d_name); + + closedir(dir); +} + +static void cmd_rm(void) +{ + if (!arg1 || arg2) { + puts("usage: rm "); + return; + } + +#ifdef UPPERCASE + strupr(arg1); +#endif + + if (unlink(arg1)) + printf("remove failed: %s\n", strerror(errno)); +} + +static void cmd_mkdir(void) +{ + if (!arg1 || arg2) { + puts("usage: mkdir "); + return; + } + +#ifdef UPPERCASE + strupr(arg1); +#endif + + if (mkdir(arg1, 0777)) + printf("mkdir failed: %s\n", strerror(errno)); +} + +static void cmd_rmdir(void) +{ + if (!arg1 || arg2) { + puts("usage: rmdir "); + return; + } + +#ifdef UPPERCASE + strupr(arg1); +#endif + + if (rmdir(arg1)) + printf("rmdir failed: %s\n", strerror(errno)); +} + +static void cmd_chdir(void) +{ + if (!arg1 || arg2) { + puts("usage: cddir "); + return; + } + +#ifdef UPPERCASE + strupr(arg1); +#endif + + if (chdir(arg1)) + printf("chdir failed: %s\n", strerror(errno)); +} + +static void cmd_pwd(void) +{ + char *buf; + + if (arg1) { + puts("usage: pwd"); + return; + } + + buf = malloc(MAXPATHLEN); + if (! buf) { + printf("malloc %u bytes failed: %s\n", MAXPATHLEN, strerror(errno)); + return; + } + if (!getcwd(buf, MAXPATHLEN)) { + printf("getcwd failed: %s\n", strerror(errno)); + free(buf); + return; + } + + puts(buf); + free(buf); +} + +static void cmd_rename(void) +{ + if (!arg2 || arg3) { + puts("usage: mv "); + return; + } + +#ifdef UPPERCASE + strupr(arg1); + strupr(arg2); +#endif + + if (rename(arg1, arg2)) + printf("rename failed: %s\n", strerror(errno)); +} + +static void cmd_copy(void) +{ + int srcfd = -1, dstfd = -1; + unsigned char *buf; + int readsz, writesz; + + if (!arg2 || arg3) { + puts("usage: cp "); + return; + } + +#ifdef UPPERCASE + strupr(arg1); + strupr(arg2); +#endif + + buf = malloc(cpbuf_sz); + if (! buf) { + printf("malloc %u bytes failed: %s\n", cpbuf_sz, strerror(errno)); + return; + } + + while (1) { + if (srcfd == -1) { + srcfd = open(arg1, O_RDONLY); + if (srcfd < 0) { + printf("open(%s) failed: %s\n", arg1, strerror(errno)); + break; + } + } + + readsz = read(srcfd, buf, cpbuf_sz); + if (readsz < 0) { + printf("read error: %s\n", strerror(errno)); + break; + } + if (! readsz) + break; + + if (dstfd == -1) { + dstfd = open(arg2, O_WRONLY | O_CREAT | O_TRUNC, 0777); + if (dstfd < 0) { + printf("open(%s) failed: %s\n", arg2, strerror(errno)); + break; + } + } + + writesz = write(dstfd, buf, readsz); + if (writesz < 0 || writesz != readsz) { + printf("write error: %s\n", strerror(errno)); + break; + } + if (readsz != cpbuf_sz) + break; + } + + free(buf); + if (srcfd >= 0) close(srcfd); + if (dstfd >= 0) close(dstfd); +} + +static void run_command(void) +{ + switch (cmd) { + default: puts("internal error"); return; + case CMD_NOTHING: return; + case CMD_INVALID: puts("invalid command"); return; + case CMD_HELP: cmd_help(); return; + case CMD_QUIT: terminate = 1; return; + case CMD_LS: cmd_ls(); return; + case CMD_RM: cmd_rm(); return; + case CMD_CHDIR: cmd_chdir(); return; + case CMD_MKDIR: cmd_mkdir(); return; + case CMD_RMDIR: cmd_rmdir(); return; + case CMD_PWD: cmd_pwd(); return; + case CMD_RENAME: cmd_rename(); return; + case CMD_COPY: cmd_copy(); return; + } +} + +int main(void) +{ + banner(); + + while (! terminate) { + get_command(); + run_command(); + } + return 0; +} + +/* Local Variables: */ +/* c-file-style: "cpg" */ +/* c-basic-offset: 4 */ +/* End: */ From bb9f1d031ae97f9546a02af32ea7bdb562911d3f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 30 Jul 2013 00:52:58 +0200 Subject: [PATCH 045/144] disable GETCWD command until I have a proper way to test it --- libsrc/atari/shadow_ram_handlers.s | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 80dc5c2d1..1edc82d51 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -241,8 +241,6 @@ CIOV_call: ; and some only use the pointer (like e.g. OPEN), and some use both. ; So we need function specific handlers to correctly deal with ; buffers which are overlapping with the ROM area. -; All input and output registers need to be preserved (I'm not 100% -; sure about Y as input, but let's preserve it for now.) ; ; FIXME: Currently only the requests used by the runtime lib are handled. @@ -266,13 +264,17 @@ my_CIOV: beq CIO_filename2 cmp #GETCWD bcc CIO_filename ; filename as input parameter in buffer, length not used - beq CIO_read ; input + beq CIO_invalid ; GETCWD not supported yet bcs CIO_call_a ; other commands: assume no buffer ; not reached CIO_write_jmp: jmp CIO_write +CIO_invalid: + lda CIO_a + ldy #DINVCM + rts ; READ handler ; ------------ From be7c24177c7eb0b3b86bc76b6f603368f6981ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Pati=C3=B1o?= Date: Sat, 3 Aug 2013 15:42:16 +0200 Subject: [PATCH 046/144] Promoted _auxtype to a struct to gain access to additional fields While creating files there was no possibility to explicitly set the time or date. This is necessary for example while copying files since the original time and date should be kept. --- include/apple2.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/apple2.h b/include/apple2.h index 190248b0d..396ddfde5 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -139,7 +139,12 @@ extern unsigned char _dos_type; * following variables to determine the file type and the aux type to use. */ extern unsigned char _filetype; /* Default 6 */ -extern unsigned int _auxtype; /* Default 0 */ +extern struct { + unsigned int aux; + unsigned char storage; + unsigned int date; + unsigned int time; +} _auxtype; /* Default 0 */ /* The addresses of the static drivers */ #if !defined(__APPLE2ENH__) From 9b157a5b1e7c2be37a6bb2a030290d89a556d7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Pati=C3=B1o?= Date: Sat, 3 Aug 2013 19:08:36 +0200 Subject: [PATCH 047/144] Defined a struct to contain the date and time data To keep backward compatibility auxtype and the date/time are kept separated. A struct similar to the one used in dirent.h is used to access the create_date and create_time fields. --- include/apple2.h | 16 +++++++++++----- libsrc/apple2/open.s | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/apple2.h b/include/apple2.h index 396ddfde5..89a01d857 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -139,12 +139,18 @@ extern unsigned char _dos_type; * following variables to determine the file type and the aux type to use. */ extern unsigned char _filetype; /* Default 6 */ +extern unsigned int _auxtype; /* Default 0 */ extern struct { - unsigned int aux; - unsigned char storage; - unsigned int date; - unsigned int time; -} _auxtype; /* Default 0 */ + struct { + unsigned day :5; + unsigned mon :4; + unsigned year :7; + } createdate; + struct { + unsigned char min; + unsigned char hour; + } createtime; +} _datetime; /* The addresses of the static drivers */ #if !defined(__APPLE2ENH__) diff --git a/libsrc/apple2/open.s b/libsrc/apple2/open.s index db40c3c74..b1686df70 100644 --- a/libsrc/apple2/open.s +++ b/libsrc/apple2/open.s @@ -5,7 +5,7 @@ ; .export _open, closedirect, freebuffer - .export __filetype, __auxtype + .export __filetype, __auxtype, __datetime .constructor raisefilelevel .destructor closeallfiles, 5 @@ -246,5 +246,6 @@ __filetype: __auxtype: .word $0000 ; AUX_TYPE: Load address N/A .byte $01 ; STORAGE_TYPE: Standard seedling file +__datetime: .word $0000 ; CREATE_DATE: Current date .word $0000 ; CREATE_TIME: Current time From bf160cae6964624260f99e4b4ded4d88d07179cc Mon Sep 17 00:00:00 2001 From: Greg King Date: Tue, 6 Aug 2013 10:09:46 -0400 Subject: [PATCH 048/144] Added symbol names for useful Atmos addresses. --- asminc/atmos.inc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/asminc/atmos.inc b/asminc/atmos.inc index 20bb806f1..6534a2ef0 100644 --- a/asminc/atmos.inc +++ b/asminc/atmos.inc @@ -18,21 +18,26 @@ FNAME_LEN = 16 ; maximum length of file-name ; --------------------------------------------------------------------------- ; Zero page +SCRPTR := $12 BASIC_BUF := $35 +CHARGOT := $E8 +TXTPTR := $E9 ; --------------------------------------------------------------------------- ; Low memory MODEKEY := $0209 -CAPSLOCK := $020C +CAPSLOCK := $020C ; $7F = not locked, $FF = locked PATTERN := $0213 -IRQVec := $0245 +IRQVec := $0245 ; "fast" interrupt vector JOINFLAG := $025A ; 0 = don't joiu, $4A = join BASIC programs VERIFYFLAG := $025B ; 0 = load, 1 = verify CURS_Y := $0268 CURS_X := $0269 STATUS := $026A +BACKGRND := $026B +FOREGRND := $026C TIMER3 := $0276 CFILE_NAME := $027F CFOUND_NAME := $0293 @@ -40,10 +45,13 @@ FILESTART := $02A9 FILEEND := $02AB AUTORUN := $02AD ; $00 = only load, $C7 = autorun LANGFLAG := $02AE ; $00 = BASIC, $80 = machine code +LOADERR := $02B1 KEYBUF := $02DF +PARMERR := $02E0 PARAM1 := $02E1 ; & $02E2 PARAM2 := $02E3 ; & $02E4 PARAM3 := $02E5 ; & $02E6 +BANGVEC := $02F5 ; --------------------------------------------------------------------------- @@ -92,3 +100,11 @@ POINT := $F1C8 PAPER := $F204 INK := $F210 PRINT := $F77C + +; Sound Effects +PING := $FA9F +SHOOT := $FAB5 +EXPLODE := $FACB +ZAP := $FAE1 +TICK := $FB14 +TOCK := $FB2A From 6589288a04b3cb675d60e88528de8b45cfe687d7 Mon Sep 17 00:00:00 2001 From: Greg King Date: Tue, 6 Aug 2013 11:12:30 -0400 Subject: [PATCH 049/144] Exposed, to C code, the names of the Atmos ROM's sound effect functions. --- include/atmos.h | 24 ++++++++++++++++++++++++ libsrc/atmos/atmos.s | 15 +++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 libsrc/atmos/atmos.s diff --git a/include/atmos.h b/include/atmos.h index eed6d7564..72388c974 100644 --- a/include/atmos.h +++ b/include/atmos.h @@ -126,12 +126,36 @@ extern void atmos_240_200_2_tgi[]; /* Referred to by tgi_static_stddrv[] */ +/*****************************************************************************/ +/* Functions */ +/*****************************************************************************/ + + + void __fastcall__ atmos_load(const char* name); /* Load Atmos tape. */ void __fastcall__ atmos_save(const char* name, const void* start, const void* end); /* Save Atmos tape. */ +void atmos_explode (void); +/* Bomb sound effect */ + +void atmos_ping (void); +/* Bell or ricochet sound effect */ + +void atmos_shoot (void); +/* Pistol sound effect */ + +void atmos_tick (void); +/* High-pitch click */ + +void atmos_tock (void); +/* Low-pitch click */ + +void atmos_zap (void); +/* Raygun sound effect */ + /* End of atmos.h */ diff --git a/libsrc/atmos/atmos.s b/libsrc/atmos/atmos.s new file mode 100644 index 000000000..6b5a4a49c --- /dev/null +++ b/libsrc/atmos/atmos.s @@ -0,0 +1,15 @@ +; +; Expose include-file symbol names to C code. +; + + .export _atmos_ping, _atmos_shoot, _atmos_explode + .export _atmos_zap, _atmos_tick, _atmos_tock + + .include "atmos.inc" + +_atmos_ping := PING +_atmos_shoot := SHOOT +_atmos_explode := EXPLODE +_atmos_zap := ZAP +_atmos_tick := TICK +_atmos_tock := TOCK From 7d9bba213bf7f4dca221899c59571baa36293d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Pati=C3=B1o?= Date: Thu, 8 Aug 2013 18:23:48 +0200 Subject: [PATCH 050/144] Comments added --- include/apple2.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/apple2.h b/include/apple2.h index 89a01d857..51475e234 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -138,18 +138,18 @@ extern unsigned char _dos_type; /* The file stream implementation and the POSIX I/O functions will use the * following variables to determine the file type and the aux type to use. */ -extern unsigned char _filetype; /* Default 6 */ -extern unsigned int _auxtype; /* Default 0 */ +extern unsigned char _filetype; /* Default: 6 */ +extern unsigned int _auxtype; /* Default: 0 */ extern struct { struct { unsigned day :5; unsigned mon :4; unsigned year :7; - } createdate; + } createdate; /* Current date: 0 */ struct { unsigned char min; unsigned char hour; - } createtime; + } createtime; /* Current time: 0 */ } _datetime; /* The addresses of the static drivers */ From 5602cf742f9e9832ca139c5c1ab9a5fb2ae80a92 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Thu, 8 Aug 2013 18:46:21 +0200 Subject: [PATCH 051/144] Adjusted comment. --- include/apple2.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/apple2.h b/include/apple2.h index 51475e234..310e697b1 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -136,7 +136,8 @@ extern unsigned char _dos_type; /* The file stream implementation and the POSIX I/O functions will use the - * following variables to determine the file type and the aux type to use. + * following variables to determine the file type, aux type and creation time + * stamp to use. */ extern unsigned char _filetype; /* Default: 6 */ extern unsigned int _auxtype; /* Default: 0 */ From 1dab0103f1ba9261b3e1dbf6eb5e294b65794df9 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 20 Aug 2013 07:43:47 +0200 Subject: [PATCH 052/144] Made EXTZP segment optional on GEOS as it is used only by CONIO. --- cfg/geos-apple.cfg | 2 +- cfg/geos-cbm.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cfg/geos-apple.cfg b/cfg/geos-apple.cfg index 1900c4866..746e1f2bf 100644 --- a/cfg/geos-apple.cfg +++ b/cfg/geos-apple.cfg @@ -32,7 +32,7 @@ MEMORY { } SEGMENTS { ZEROPAGE: type = zp, load = ZP; - EXTZP: type = zp, load = ZP; + EXTZP: type = zp, load = ZP, optional = yes; EXTBSS: type = bss, load = EXT, define = yes, optional = yes; FILEINFO: type = ro, load = CVT, offset = $002; RECORDS: type = ro, load = CVT, offset = $100, optional = yes; diff --git a/cfg/geos-cbm.cfg b/cfg/geos-cbm.cfg index f2aea55a2..ddef00a99 100644 --- a/cfg/geos-cbm.cfg +++ b/cfg/geos-cbm.cfg @@ -31,7 +31,7 @@ MEMORY { } SEGMENTS { ZEROPAGE: type = zp, load = ZP; - EXTZP: type = zp, load = ZP; + EXTZP: type = zp, load = ZP, optional = yes; DIRENTRY: type = ro, load = CVT, align = $FE; FILEINFO: type = ro, load = CVT, align = $FE; RECORDS: type = ro, load = CVT, align = $FE, optional = yes; From b1f69e0696d1cd7567cdcd02b716b70937a5bd37 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 22 Aug 2013 13:08:48 +0200 Subject: [PATCH 053/144] add some more SIO information --- asminc/atari.inc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/asminc/atari.inc b/asminc/atari.inc index 615765132..da524baad 100644 --- a/asminc/atari.inc +++ b/asminc/atari.inc @@ -101,11 +101,28 @@ SIO_FORMAT = $21 ;format disk (default density) SIO_FORMATS = $22 ;1050: format medium density SIO_CONFIG = $44 ;configure drive SIO_CONFIGSF = $4B ;slow/fast configure drive?? +SIO_RDPERCOM = $4E ;read PERCOM block (XF551) +SIO_WRPERCOM = $4F ;write PERCOM block (XF551) SIO_WRITE = $50 ;write sector SIO_READ = $52 ;read sector SIO_STAT = $53 ;get status information SIO_VERIFY = $56 ;verify sector SIO_WRITEV = $57 ;write sector with verify +SIO_WRITETRK = $60 ;write track (Speedy) +SIO_READTRK = $62 ;read track (Speedy) + +; SIO Status Code (DSTATS) +; Input: data direction +; Bit #7 - W (write operation) +; #6 - R (read operation) +; Output: status code +; $01 (001) -- OPERATION COMPLETE (NO ERRORS) +; $8A (138) -- DEVICE TIMEOUT (DOESN'T RESPOND) +; $8B (139) -- DEVICE NAK +; $8C (140) -- SERIAL BUS INPUT FRAMING ERROR +; $8E (142) -- SERIAL BUS DATA FRAME OVERRUN ERROR +; $8F (143) -- SERIAL BUS DATA FRAME CHECKSUM ERROR +; $90 (144) -- DEVICE DONE ERROR ; Character and Key Code Equates From 5d7b5900f9aa23aa5a52d2c46515164ee6c34152 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 22 Aug 2013 14:47:50 +0200 Subject: [PATCH 054/144] implement SIO handler --- libsrc/atari/shadow_ram_handlers.s | 211 ++++++++++++++++++++++++----- 1 file changed, 178 insertions(+), 33 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 1edc82d51..048a5a5c0 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -16,9 +16,7 @@ DEBUG = 1 .export sram_init .export KEYBDV_wrapper -BUFSZ = 128 -BUFSZ_CIO = BUFSZ -BUFSZ_SIO = BUFSZ +BUFSZ = 256 ; bounce buffer size .macro disable_rom lda PORTB @@ -39,8 +37,6 @@ BUFSZ_SIO = BUFSZ .segment "INIT" -;enable_count: .res 1 - ; Turn off ROMs, install system and interrupt wrappers, set new chargen pointer sram_init: @@ -98,8 +94,7 @@ zpptr1: .res 2 .segment "LOWBUFS" ; bounce buffers for CIO and SIO calls -CIO_buffer: .res BUFSZ_CIO -SIO_buffer: .res BUFSZ_SIO +bounce_buffer: .res BUFSZ .segment "LOWCODE" @@ -193,7 +188,7 @@ CIO_filename: jsr setup_zpptr1_y0 jsr copy_filename CIO_fn_cont: - jsr ciobuf_to_iocb + jsr bncbuf_to_iocb ldy CIO_y jsr CIO_call_a ; call CIO (maybe A isn't needed, then we could call CIO_call) php @@ -214,6 +209,7 @@ CIO_filename2: jmp CIO_fn_cont +; enable ROM, call CIO, disable ROM CIO_call_a: lda CIO_a @@ -292,14 +288,14 @@ CIO_read: lda ICBLH,x ; get high byte of length bne big_read ; not zero -> data too large for our buffers ; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES - lda # bounce buffer size? + jsr cmp_orig_len_bnc_bufsz ; is transfer length > bounce buffer size? bcs br_last ; no, last transfer, use remaining size - lda #>BUFSZ_CIO + lda #>BUFSZ sta ICBLH,x ; set data length - lda # data too large for our buffers ; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES - lda # bounce buffer size? + jsr cmp_orig_len_bnc_bufsz ; is transfer length > bounce buffer size? bcs bw_last ; no, last transfer, use remaining size - lda #>BUFSZ_CIO + lda #>BUFSZ sta ICBLH,x ; set data length - lda #BUFSZ_CIO + lda #>BUFSZ sbc orig_len+1 rts @@ -595,7 +591,7 @@ copy_to_user: ldy ICBLL,x ; get # of bytes read (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES) beq @copy_done @copy: dey - lda CIO_buffer,y + lda bounce_buffer,y sta (zpptr1),y cpy #0 bne @copy @@ -613,7 +609,7 @@ copy_from_user: beq @copy_done @copy: dey lda (zpptr1),y - sta CIO_buffer,y + sta bounce_buffer,y cpy #0 bne @copy @copy_done: @@ -667,21 +663,21 @@ restore_icba: ; put bounce buffer address into ICBAL/ICBAH ; input: X - IOCB index ; output: A - destroyed -ciobuf_to_iocb: - lda #CIO_buffer + lda #>bounce_buffer sta ICBAH,x rts -; copy file name pointed to by 'zpptr1' to bounce buffer 'CIO_buffer' -; input: Y - index into file name buffer and CIO_buffer +; copy file name pointed to by 'zpptr1' to 'bounce_buffer' +; input: Y - index into file name buffer and bounce_buffer ; output: Y - points to first invalid byte after file name ; A - destroyed copy_filename: lda (zpptr1),y - sta CIO_buffer,y + sta bounce_buffer,y beq copy_fn_done iny cmp #ATEOL @@ -706,12 +702,35 @@ setup_zpptr1: ;--------------------------------------------------------- +; SIO handler +; We only handle SIO_STAT, SIO_READ, SIO_WRITE, and SIO_WRITEV. +; These are the only functions used by the runtime library currently. +; For other function we return NVALID status code. + my_SIOV: - pha + lda DCOMND ; get command + cmp #SIO_STAT + beq SIO_stat + cmp #SIO_READ + beq SIO_read + cmp #SIO_WRITE + beq SIO_write + cmp #SIO_WRITEV + beq SIO_write + + ; unhandled command + lda #NVALID +SIO_err:sta DSTATS + rts + +; SIO_STAT is always called with a low buffer (by the runtime) +SIO_stat: + ; fall thru + +SIO_call: lda PORTB sta cur_SIOV_PORTB enable_rom - pla jsr SIOV_org php pha @@ -721,6 +740,132 @@ my_SIOV: plp rts + +; SIO read handler +; ---------------- + +SIO_read: + +; @@@ TODO: check if bounce buffer is really needed because buffer is in ROM area + +; we only support transfers <= bounce buffer size + jsr cmp_sio_len_bnc_bufsz + bcs sio_read_len_ok + + lda #DERROR ; don't know a better status code for this + bne SIO_err + +sio_read_len_ok: + lda DBUFLO + sta zpptr1 ; remember destination buffer address + lda DBUFHI + sta zpptr1+1 + + jsr bncbuf_to_dbuf ; put bounce buffer address to DBUFLO/DBUFHI + + jsr SIO_call ; do the operation + pha + lda DSTATS ; get status + bmi sio_read_ret ; error + + ; copy data to user buffer +sio_read_ok: + lda DBYTHI ; could be 1 for 256 bytes + beq srok1 + ldy #0 + beq srok2 +srok1: ldy DBYTLO +srok2: dey +sio_read_copy: + lda bounce_buffer,y + sta (zpptr1),y + dey + cpy #$ff + bne sio_read_copy + +sio_read_ret: + jsr orgbuf_to_dbuf + + pla + rts ; success return + + +; SIO write handler +; ----------------- + +SIO_write: + +; @@@ TODO: check if bounce buffer is really needed because buffer is in ROM area + +; we only support transfers <= bounce buffer size + jsr cmp_sio_len_bnc_bufsz + bcs sio_write_len_ok + + lda #DERROR ; don't know a better status code for this + bne SIO_err + +sio_write_len_ok: + lda DBUFLO + sta zpptr1 ; get source buffer address + lda DBUFHI + sta zpptr1+1 + + ; copy data from user buffer to bounce buffer + lda DBYTHI ; could be 1 for 256 bytes + beq swok1 + ldy #0 + beq swok2 +swok1: ldy DBYTLO +swok2: dey +sio_write_copy: + lda (zpptr1),y + sta bounce_buffer,y + dey + cpy #$ff + bne sio_write_copy + + jsr bncbuf_to_dbuf ; put bounce buffer address to DBUFLO/DBUFHI + + jsr SIO_call ; do the operation + pha + jsr orgbuf_to_dbuf + pla + rts + + +; check if SIO length is larger than bounce buffer size +; input: orig_len - length +; output: A - destroyed +; CF - 0/1 for larger/not larger +cmp_sio_len_bnc_bufsz: + sec + lda #BUFSZ + sbc DBYTHI + rts + +; put bounce buffer address into DBUFLO/DBUFHI +; input: (--) +; output: A - destroyed +bncbuf_to_dbuf: + lda #bounce_buffer + sta DBUFHI + rts + +; put original buffer address into DBUFLO/DBUFHI +; input: zpptr1 - original pointer +; output: A - destroyed +orgbuf_to_dbuf: + lda zpptr1 + sta DBUFLO + lda zpptr1+1 + sta DBUFHI + rts + + ;--------------------------------------------------------- KEYBDV_wrapper: From 177e967629967dcf5bb65d7bdd8517f06926c190 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Thu, 22 Aug 2013 16:33:30 +0200 Subject: [PATCH 055/144] Added TGI color defines. --- include/atari.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/atari.h b/include/atari.h index e47d1ccea..61de88beb 100644 --- a/include/atari.h +++ b/include/atari.h @@ -131,6 +131,24 @@ #define COLOR_LIGHTBLUE _gtia_mkcolor(HUE_BLUE,6) #define COLOR_GRAY3 _gtia_mkcolor(HUE_GREY,5) +/* TGI color defines */ +#define TGI_COLOR_BLACK COLOR_BLACK +#define TGI_COLOR_WHITE COLOR_WHITE +#define TGI_COLOR_RED COLOR_RED +#define TGI_COLOR_CYAN COLOR_CYAN +#define TGI_COLOR_VIOLET COLOR_VIOLET +#define TGI_COLOR_GREEN COLOR_GREEN +#define TGI_COLOR_BLUE COLOR_BLUE +#define TGI_COLOR_YELLOW COLOR_YELLOW +#define TGI_COLOR_ORANGE COLOR_ORANGE +#define TGI_COLOR_BROWN COLOR_BROWN +#define TGI_COLOR_LIGHTRED COLOR_LIGHTRED +#define TGI_COLOR_GRAY1 COLOR_GRAY1 +#define TGI_COLOR_GRAY2 COLOR_GRAY2 +#define TGI_COLOR_LIGHTGREEN COLOR_LIGHTGREEN +#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE +#define TGI_COLOR_GRAY3 COLOR_GRAY3 + /* color register functions */ extern void __fastcall__ _setcolor (unsigned char color_reg, unsigned char hue, unsigned char luminace); extern void __fastcall__ _setcolor_low (unsigned char color_reg, unsigned char color_value); From 1c83d8232b7999caea5ed04dd5133d69aa81d638 Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 23 Aug 2013 03:06:00 -0400 Subject: [PATCH 056/144] Added a driver to the CBM510 library that lets a joystick pretend to be a mouse. --- include/cbm510.h | 7 +- libsrc/cbm510/mcbdefault.s | 131 +++++++++ libsrc/cbm510/mou/cbm510-joy.s | 445 ++++++++++++++++++++++++++++++ libsrc/cbm510/mouse_stat_stddrv.s | 13 + libsrc/cbm510/mouse_stddrv.s | 16 ++ libsrc/cbm510/mouseref.s | 23 ++ 6 files changed, 632 insertions(+), 3 deletions(-) create mode 100644 libsrc/cbm510/mcbdefault.s create mode 100644 libsrc/cbm510/mou/cbm510-joy.s create mode 100644 libsrc/cbm510/mouse_stat_stddrv.s create mode 100644 libsrc/cbm510/mouse_stddrv.s create mode 100644 libsrc/cbm510/mouseref.s diff --git a/include/cbm510.h b/include/cbm510.h index 350527c89..797b2c4fa 100644 --- a/include/cbm510.h +++ b/include/cbm510.h @@ -2,11 +2,11 @@ /* */ /* cbm510.h */ /* */ -/* System specific definitions for the CBM5x0 / P500 */ +/* System-specific definitions for the CBM5x0 / P500 */ /* */ /* */ /* */ -/* (C) 2001-2009, Ullrich von Bassewitz */ +/* (C) 2001-2013, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -100,7 +100,7 @@ #define SID (*(struct __sid*)0xDA00) #include <_6526.h> -#define CIA (*(struct __6526*)0xDC00) +#define CIA2 (*(struct __6526*)0xDC00) #include <_6551.h> #define ACIA (*(struct __6551*)0xDD00) @@ -118,6 +118,7 @@ /* The addresses of the static drivers */ +extern void cbm510_joy_mou[]; /* Referred to by mouse_static_stddrv[] */ extern void cbm510_ram_emd[]; extern void cbm510_std_joy[]; /* Referred to by joy_static_stddrv[] */ extern void cbm510_std_ser[]; diff --git a/libsrc/cbm510/mcbdefault.s b/libsrc/cbm510/mcbdefault.s new file mode 100644 index 000000000..a6504ae30 --- /dev/null +++ b/libsrc/cbm510/mcbdefault.s @@ -0,0 +1,131 @@ +; +; Default mouse callbacks for the CBM510 (P128) +; +; 2004-03-20, Ullrich von Bassewitz2 +; 2013-06-25, Greg King +; +; All functions in this module should be interrupt-safe because they might +; be called from an interrupt handler. +; + + .export _mouse_def_callbacks + .import vic:zp + + .include "mouse-kernel.inc" + .include "cbm510.inc" + + .macpack generic + +; Sprite definitions. The first value can be changed to adjust the number +; of the sprite used for the mouse. All others depend on that value. +MOUSE_SPR = 0 ; Sprite used for the mouse +MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask +MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask +VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register +VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register + +; -------------------------------------------------------------------------- +; Hide the mouse pointer. Always called with interrupts disabled. + +.proc hide + + ldy #15 + sty IndReg + + ldy #VIC_SPR_ENA + lda (vic),y + and #MOUSE_SPR_NMASK + sta (vic),y + + ldy ExecReg + sty IndReg + rts + +.endproc + +; -------------------------------------------------------------------------- +; Show the mouse pointer. Always called with interrupts disabled. + +.proc show + + ldy #15 + sty IndReg + + ldy #VIC_SPR_ENA + lda (vic),y + ora #MOUSE_SPR_MASK + sta (vic),y + + ldy ExecReg + sty IndReg + rts + +.endproc + +; -------------------------------------------------------------------------- +; Move the mouse pointer x position to the value in .XA. Always called with +; interrupts disabled. + +.proc movex + + ldy #15 + sty IndReg + +; Add the x correction; and, set the low byte. That frees .A. + + add #<24 ; x correction + ldy #VIC_SPR_X + sta (vic),y + +; Set the high byte + + ldy #VIC_SPR_HI_X + txa + adc #>24 + bnz @L1 ; Branch if high byte not zero + lda (vic),y ; Get high x bits of all sprites + and #MOUSE_SPR_NMASK ; Clear high bit for sprite + sta (vic),y + +@L0: ldy ExecReg + sty IndReg + rts + +@L1: lda (vic),y ; Get high x bits of all sprites + ora #MOUSE_SPR_MASK ; Set high bit for sprite + sta (vic),y + bnz @L0 ; branch always + +.endproc + +; -------------------------------------------------------------------------- +; Move the mouse pointer y position to the value in .XA. Always called with +; interrupts disabled. + +.proc movey + + ldy #15 + sty IndReg + + add #50 ; y correction (first visible line) + ldy #VIC_SPR_Y + sta (vic),y ; Set y position + + ldy ExecReg + sty IndReg + rts + +.endproc + +; -------------------------------------------------------------------------- +; Callback structure + +.rodata + +_mouse_def_callbacks: + .addr hide + .addr show + .addr movex + .addr movey + + diff --git a/libsrc/cbm510/mou/cbm510-joy.s b/libsrc/cbm510/mou/cbm510-joy.s new file mode 100644 index 000000000..7a98f8d39 --- /dev/null +++ b/libsrc/cbm510/mou/cbm510-joy.s @@ -0,0 +1,445 @@ +; +; Driver for a "joystick mouse". +; +; 2009-09-26, Ullrich von Bassewitz +; 2013-08-22, Greg King +; + + .include "zeropage.inc" + .include "../extzp.inc" + + .include "mouse-kernel.inc" + .include "cbm510.inc" + + .macpack generic + +; ------------------------------------------------------------------------ +; Header. Includes jump table + +.segment "JUMPTABLE" + +HEADER: + +; Driver signature + + .byte $6d, $6f, $75 ; ASCII "mou" + .byte MOUSE_API_VERSION ; Mouse driver API version number + +; Library reference + + .addr $0000 + +; Jump table + + .addr INSTALL + .addr UNINSTALL + .addr HIDE + .addr SHOW + .addr SETBOX + .addr GETBOX + .addr MOVE + .addr BUTTONS + .addr POS + .addr INFO + .addr IOCTL + .addr IRQ + +; Mouse driver flags + + .byte MOUSE_FLAG_LATE_IRQ + +; Callback table, set by the kernel before INSTALL is called. + +CHIDE: jmp $0000 ; Hide the cursor +CSHOW: jmp $0000 ; Show the cursor +CMOVEX: jmp $0000 ; Move the cursor to x co-ord. +CMOVEY: jmp $0000 ; Move the cursor to y co-ord. + + +;---------------------------------------------------------------------------- +; Constants + +SCREEN_HEIGHT = YSIZE * 8 +SCREEN_WIDTH = XSIZE * 8 + +.scope JOY + UP = %00000001 + DOWN = %00000010 + LEFT = %00000100 + RIGHT = %00001000 + FIRE = %00010000 +.endscope + +;---------------------------------------------------------------------------- +; Global variables. The bounding box values are sorted so that they can be +; written with the least effort in the SETBOX and GETBOX routines; so, don't +; re-order them. + +.bss + +Vars: +YPos: .res 2 ; Current mouse position, y +XPos: .res 2 ; Current mouse position, x +XMin: .res 2 ; X1 value of bounding box +YMin: .res 2 ; Y1 value of bounding box +XMax: .res 2 ; X2 value of bounding box +YMax: .res 2 ; Y2 value of bounding box + +; Temporary value used in the interrupt handler + +Temp: .res 1 + +; Default values for above variables + +.rodata + +.proc DefVars + .word SCREEN_HEIGHT / 2 ; YPos + .word SCREEN_WIDTH / 2 ; XPos + .word 0 ; XMin + .word 0 ; YMin + .word SCREEN_WIDTH - 1 ; XMax + .word SCREEN_HEIGHT - 1 ; YMax +.endproc + +.code + +;---------------------------------------------------------------------------- +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present. +; Must return a MOUSE_ERR_xx code in .XA. + +INSTALL: + +; Initiate variables; just copy the default stuff over. + + ldx #.sizeof(DefVars) - 1 +@L1: lda DefVars,x + sta Vars,x + dex + bpl @L1 + +; Be sure the mouse cursor is invisible and at the default location. We +; need to do that here because our mouse interrupt handler doesn't set the +; mouse position if it hasn't changed. + + sei + jsr CHIDE + lda XPos + ldx XPos+1 + jsr CMOVEX + lda YPos + ldx YPos+1 + jsr CMOVEY + cli + +; Done, return zero. + + ldx #>MOUSE_ERR_OK + txa + rts + +;---------------------------------------------------------------------------- +; UNINSTALL routine. Is called before the driver is removed from memory. +; No return code required (the driver is removed from memory, on return). + +UNINSTALL := HIDE ; Hide cursor, on exit + +;---------------------------------------------------------------------------- +; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages +; a counter for calls to show/hide; and, the driver entry point is called only +; if the mouse currently is visible and should get hidden. For most drivers, +; no special action is required besides hiding the mouse cursor. +; No return code required. + +HIDE: sei + jsr CHIDE + cli + rts + +;---------------------------------------------------------------------------- +; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages +; a counter for calls to show/hide; and, the driver entry point is called only +; if the mouse currently is hidden and should become visible. For most drivers, +; no special action is required besides enabling the mouse cursor. +; No return code required. + +SHOW: sei + jsr CSHOW + cli + rts + +;---------------------------------------------------------------------------- +; SETBOX: Set the mouse bounding box. The parameters are passed as they come +; from the C program, that is, a pointer to a mouse_box struct in .XA. +; No checks are done if the mouse currently is inside the box; that is the job +; of the caller. It is not necessary to validate the parameters; trust the +; caller, and save some code here. No return code required. + +SETBOX: sta ptr1 + stx ptr1+1 ; Save data pointer + + ldy #.sizeof (MOUSE_BOX) - 1 + sei + +@L1: lda (ptr1),y + sta XMin,y + dey + bpl @L1 + + cli + rts + +;---------------------------------------------------------------------------- +; GETBOX: Return the mouse bounding box. The parameters are passed as they +; come from the C program, that is, a pointer to a mouse_box struct in .XA. + +GETBOX: sta ptr1 + stx ptr1+1 ; Save data pointer + + ldy #.sizeof (MOUSE_BOX) - 1 + +@L1: lda XMin,y + sta (ptr1),y + dey + bpl @L1 + + rts + +;---------------------------------------------------------------------------- +; MOVE: Move the mouse to a new position. The position is passed as it comes +; from the C program, that is: x on the stack and y in .XA. The C wrapper will +; remove the parameter from the stack, on return. +; No checks are done if the new position is valid (within the bounding box or +; the screen). No return code required. +; + +MOVE: sei ; No interrupts + + jsr MoveY ; Set new y position + + ldy #1 + lda (sp),y + sta XPos+1 + tax + dey + lda (sp),y + jsr MoveX ; Move the pointer + + cli ; Allow interrupts + rts + +;---------------------------------------------------------------------------- +; BUTTONS: Return the button mask in .XA. +; Joystick 2's fire button is the left mouse button. +; Joystick 1's fire button is the right mouse button. + +BUTTONS: + ldx #15 ; Switch to the system bank + stx IndReg + +; Get the fire-button bits + + ldy #CIA::PRA + lda (cia2),y + +; Switch back to the execution bank. + + ldy ExecReg + sty IndReg + +; Joystick 2, fire button is in bit 7. +; Joystick 1, fire button is in bit 6. + + and #%11000000 + rol a ; Move bits 7,6 to bits 1,0 + rol a + rol a + adc #%00001110 ; Move bit 1 to bit 4 + and #MOUSE_BTN_LEFT | MOUSE_BTN_RIGHT + +; Bits go up when buttons go down. + + eor #MOUSE_BTN_LEFT | MOUSE_BTN_RIGHT + ldx #>0 + rts + +;---------------------------------------------------------------------------- +; INFO: Returns mouse position and current button mask in the MOUSE_INFO +; struct pointed to by ptr1. No return code required. +; +; We're cheating here to keep the code smaller: The first fields of the +; mouse_info struct are identical to the mouse_pos struct; so, we just will +; use _mouse_pos to fill the position fields. + +INFO: jsr BUTTONS + +; Fill in the button state. + + ldy #MOUSE_INFO::BUTTONS + sta (ptr1),y + +; jmp POS ; Fall through + +;---------------------------------------------------------------------------- +; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1. +; No return code required. + +POS: ldy #MOUSE_POS::XCOORD ; Structure offset + + sei ; Disable interrupts + lda XPos ; Transfer the position + sta (ptr1),y + lda XPos+1 + iny + sta (ptr1),y + lda YPos + iny + sta (ptr1),y + lda YPos+1 + cli ; Enable interrupts + + iny + sta (ptr1),y ; Store last byte + + rts ; Done + +;---------------------------------------------------------------------------- +; IOCTL: Driver-defined entry point. The wrapper will pass a pointer to ioctl- +; specific data in ptr1, and the ioctl code in .A. +; Must return an error code in .XA. +; + +IOCTL: lda #MOUSE_ERR_INV_IOCTL + rts + +;---------------------------------------------------------------------------- +; IRQ: Irq.-handler entry point. Called as a subroutine, but in the IRQ context +; (so, be careful). The routine MUST return carry set if the interrupt has been +; 'handled' -- which means that the interrupt source is gone. Otherwise, it +; MUST return carry clear. +; Reads joystick 2. +; + +IRQ: ldy #15 ; Switch to the system bank + sty IndReg + +; Get the direction bits. + + ldy #CIA::PRB + lda (cia2),y ; Read joystick inputs + +; Switch back to the execution bank. + + ldy ExecReg + sty IndReg + +; Joystick 2, directions in bits 7-4. +; Mask the relevant bits. + + and #$F0 + eor #$F0 ; All bits are inverted + sta Temp + +; Check left/right. + + and #(JOY::LEFT | JOY::RIGHT) << 4 + bze @SkipX + +; We will cheat here, and rely on the fact that either the left OR the right +; bit can be active. + + and #JOY::RIGHT << 4 ; Check RIGHT bit + bnz @Right + lda #<-1 + tax + bnz @AddX ; Branch always +@Right: lda #<1 + ldx #>1 + +; Calculate the new x co-ordinate (--> .YA). + +@AddX: add XPos + tay ; Remember low byte + txa + adc XPos+1 + tax + +; Limit the x co-ordinate to the bounding box. + + cpy XMin + sbc XMin+1 + bpl @L1 + ldy XMin + ldx XMin+1 + jmp @L2 + +@L1: txa + cpy XMax + sbc XMax+1 + bmi @L2 + ldy XMax + ldx XMax+1 +@L2: tya + jsr MoveX + +; Calculate the y movement vector. + +@SkipX: lda Temp ; Get joystick again + and #(JOY::UP | JOY::DOWN) << 4 ; Check up/down + bze @SkipY + +; We will cheat here, and rely on the fact that either the up OR the down +; bit can be active. + + and #JOY::UP << 4 ; Check UP bit + bze @Down + lda #<-1 + tax + bnz @AddY +@Down: lda #<1 + ldx #>1 + +; Calculate the new y co-ordinate (--> .YA). + +@AddY: add YPos + tay ; Remember low byte + txa + adc YPos+1 + tax + +; Limit the y co-ordinate to the bounding box. + + cpy YMin + sbc YMin+1 + bpl @L3 + ldy YMin + ldx YMin+1 + jmp @L4 + +@L3: txa + cpy YMax + sbc YMax+1 + bmi @L4 + ldy YMax + ldx YMax+1 +@L4: tya + jsr MoveY + +; Done + +@SkipY: clc ; Interrupt not handled + rts + +; Move the mouse pointer to the new x pos. + +MoveX: sta XPos + stx XPos+1 + jmp CMOVEX + +; Move the mouse pointer to the new y pos. + +MoveY: sta YPos + stx YPos+1 + jmp CMOVEY diff --git a/libsrc/cbm510/mouse_stat_stddrv.s b/libsrc/cbm510/mouse_stat_stddrv.s new file mode 100644 index 000000000..71eec00ee --- /dev/null +++ b/libsrc/cbm510/mouse_stat_stddrv.s @@ -0,0 +1,13 @@ +; +; Address of the static standard mouse driver +; +; 2012-11-01, Oliver Schmidt +; 2013-08-06, Greg King +; +; const void mouse_static_stddrv[]; +; + + .export _mouse_static_stddrv + .import _cbm510_joy_mou + +_mouse_static_stddrv := _cbm510_joy_mou diff --git a/libsrc/cbm510/mouse_stddrv.s b/libsrc/cbm510/mouse_stddrv.s new file mode 100644 index 000000000..7f6ec42a2 --- /dev/null +++ b/libsrc/cbm510/mouse_stddrv.s @@ -0,0 +1,16 @@ +; +; Name of the standard mouse driver +; +; 2009-09-11, Ullrich von Bassewitz +; 2013-06-25, Greg King +; +; const char mouse_stddrv[]; +; + + .export _mouse_stddrv + +.rodata + +_mouse_stddrv: .asciiz "cbm510-joy.mou" + + diff --git a/libsrc/cbm510/mouseref.s b/libsrc/cbm510/mouseref.s new file mode 100644 index 000000000..90aeedf3a --- /dev/null +++ b/libsrc/cbm510/mouseref.s @@ -0,0 +1,23 @@ +; +; Pointer for library references by device drivers. +; +; 2013-07-25, Greg King +; + + .export mouse_libref, _pen_adjuster + + .data + +mouse_libref: ; generic label for mouse-kernel + +; A program optionally can set this pointer to a function that gives +; a calibration value to a driver. If this pointer isn't NULL, +; then a driver that wants a value can call that function. +; +; The function might read a value from a file; or, it might ask the user +; to help calibrate the driver. +; +; void __fastcall__ (*pen_adjuster)(unsigned char *) = NULL; +; +_pen_adjuster: + .addr $0000 From 004db51960a8b0cd4189c290794d046dd0981634 Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 23 Aug 2013 03:12:16 -0400 Subject: [PATCH 057/144] Made mousetest work better with CBM510s. --- samples/mousetest.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/samples/mousetest.c b/samples/mousetest.c index dd90e0990..e5ee4ca49 100644 --- a/samples/mousetest.c +++ b/samples/mousetest.c @@ -3,7 +3,7 @@ ** Will work for the C64/C128/CBM510/Atari/Apple2. ** ** 2001-09-13, Ullrich von Bassewitz -** 2013-07-25, Greg King +** 2013-08-23, Greg King ** */ @@ -85,7 +85,12 @@ static const unsigned char MouseSprite[64] = { static void __fastcall__ CheckError (const char* S, unsigned char Error) { if (Error != MOUSE_ERR_OK) { - cprintf ("%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error); + cprintf ("\n%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error); + + /* Wait for a key-press, so that some platforms can show the error + ** message before they remove the current screen. + */ + cgetc(); exit (EXIT_FAILURE); } } @@ -154,7 +159,7 @@ int main (void) cursor (0); clrscr (); - /* The pointer is created before the driver is installed, + /* The pointer should be created before the driver is installed, ** in case a lightpen driver needs it during calibration. */ @@ -178,7 +183,7 @@ int main (void) ** the value will be put into this file, for the next time. ** (Other drivers will ignore this.) */ -#ifdef __CBM__ +#if defined(__C64__) || defined(__C128__) pen_adjust ("pen.dat"); #endif @@ -222,8 +227,13 @@ top: /* Put a cross at the center of the screen. */ gotoxy (width / 2 - 3, height / 2 - 1); +#if defined(__CBM__) cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4, width / 2, ""); +#else + cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4, + width / 2, ""); +#endif /* Test loop */ ShowState (Jailed, Invisible); From 0159358934487c8bb1fdf84e6f71d9ba270e684c Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 23 Aug 2013 07:36:11 -0400 Subject: [PATCH 058/144] Cleaned 2 source files by removing commented-out lines that are active in other files. --- libsrc/c128/libref.s | 2 -- libsrc/c64/libref.s | 2 -- 2 files changed, 4 deletions(-) diff --git a/libsrc/c128/libref.s b/libsrc/c128/libref.s index 4f65e3959..7a59236c5 100644 --- a/libsrc/c128/libref.s +++ b/libsrc/c128/libref.s @@ -5,7 +5,6 @@ .export em_libref .export joy_libref -; .export mouse_libref .export ser_libref .export tgi_libref @@ -13,6 +12,5 @@ em_libref := _exit joy_libref := _exit -;mouse_libref := _exit ser_libref := _exit tgi_libref := _exit diff --git a/libsrc/c64/libref.s b/libsrc/c64/libref.s index 4f65e3959..7a59236c5 100644 --- a/libsrc/c64/libref.s +++ b/libsrc/c64/libref.s @@ -5,7 +5,6 @@ .export em_libref .export joy_libref -; .export mouse_libref .export ser_libref .export tgi_libref @@ -13,6 +12,5 @@ em_libref := _exit joy_libref := _exit -;mouse_libref := _exit ser_libref := _exit tgi_libref := _exit From 1a4d804a5f471ce27dc1cd08e1fc9be762938f9f Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 23 Aug 2013 18:19:49 -0400 Subject: [PATCH 059/144] Added cursor-flags initiation. The CBM510 runs programs in a non-system memory bank. It has its own zero page. Some things are copied from the system zero page; but, the cursor flags weren't copied. So, the cursor always blinked. That bug sometimes left cursor ghosts (reversed spaces) at the end of lines. --- libsrc/cbm510/crt0.s | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libsrc/cbm510/crt0.s b/libsrc/cbm510/crt0.s index 871fbb850..836038a06 100644 --- a/libsrc/cbm510/crt0.s +++ b/libsrc/cbm510/crt0.s @@ -56,9 +56,9 @@ ;------------------------------------------------------------------------------ ; A table that contains values that must be transfered from the system zero -; page into out zero page. Contains pairs of bytes, first one is the address +; page into our zero page. Contains pairs of bytes; first one is the address ; in the system ZP, second one is our ZP address. The table goes into page 2, -; but is declared here, because it is needed earlier. +; but is declared here because it is needed earlier. .SEGMENT "PAGE2" @@ -67,6 +67,8 @@ .byte $9F, DEVNUM .byte $CA, CURS_Y .byte $CB, CURS_X + .byte $E6, CURS_FLAG + .byte $E7, CURS_BLINK .byte $EC, CHARCOLOR .endproc From 172ce143498cd810816e12d19f835ecf2d309ec5 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 25 Aug 2013 00:31:36 -0400 Subject: [PATCH 060/144] Made an exec() program-chaining function for the Commodore libraries. --- libsrc/cbm/exec.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 libsrc/cbm/exec.c diff --git a/libsrc/cbm/exec.c b/libsrc/cbm/exec.c new file mode 100644 index 000000000..302115c17 --- /dev/null +++ b/libsrc/cbm/exec.c @@ -0,0 +1,99 @@ +/* +** Program-chaining function for Commodore platforms. +** +** 2013-08-24, Greg King +** +** This function exploits the program-chaining feature in CBM BASIC's ROM. +** It puts the desired program's name and unit number into a LOAD statement. +** Then, it points BASIC to that statement, so that the ROM will run that +** statement after this program quits. The ROM will load the next program, +** and execute it. +*/ + +#include +#include +#include +#include +#include +#include +#if defined(__CBM610__) +# include +#elif defined(__CBM510__) +# include +#endif + + +#pragma data-name(push, "LOWCODE") +static struct line { + const char end_of_line; + const struct line *const next; + const unsigned line_num; + const char load_token, quotes[2], add_token, quote; + char name[21]; + const char comma; + char unit[3]; +} basic = { + '\0', &basic + 1, /* high byte must be non-zero */ + 0, 0x93, + + /* This string operation copies the name to high BASIC RAM. + ** So, it won't be overwritten when the next program is loaded. + */ + "\"\"", 0xaa, '\"', + "\" ", /* format: "123:1234567890123456\"" */ + ',', "01" +}; +#pragma data-name(pop) + +/* These values are platform-specific. */ +extern const struct line *txtptr; +#pragma zpsym("txtptr") +extern char basbuf[]; /* BASIC's input buffer */ +extern void basbuf_len[]; +#pragma zpsym("basbuf_len") + + +int __fastcall__ exec (const char* progname, const char* cmdline) +{ + static int fd; + static unsigned char dv, n = 0; + + /* Exclude devices that can't load files. */ + dv = getcurrentdevice (); + if (dv < 8 && dv != 1 || dv > 30) { + return _mappederrno (9); /* illegal device number */ + } + utoa (dv, basic.unit, 10); + + /* Don't try to run a program that can't be found. */ + fd = open (progname, O_RDONLY); + if (fd < 0) { + return fd; + } + close (fd); + + do { + if ((basic.name[n] = progname[n]) == '\0') { + break; + } + } while (++n < 20); /* truncate long names */ + basic.name[n] = '\"'; + + /* Build the next program's argument list. */ + basbuf[0] = 0x8f; /* REM token */ + basbuf[1] = '\0'; + if (cmdline != NULL) { + strncat (basbuf, cmdline, (size_t)basbuf_len - 2); + } + +#if defined(__CBM510__) || defined(__CBM610__) + pokewsys ((unsigned)&txtptr, (unsigned)&basic); +#else + txtptr = &basic; +#endif + + /* (The return code, in ST, will be destroyed by LOAD. + ** So, don't bother to set it here.) + */ + exit (__AX__); +} From d0fb1fe0ae489c23ff753011575331be05fb25a3 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 25 Aug 2013 00:43:23 -0400 Subject: [PATCH 061/144] Added the model-specific addresses that the CBM exec() needs. --- asminc/c128.inc | 1 + asminc/c64.inc | 1 + asminc/cbm510.inc | 20 ++++++++++++++------ asminc/cbm610.inc | 14 ++++++++++---- asminc/pet.inc | 4 ++++ asminc/plus4.inc | 1 + asminc/vic20.inc | 1 + libsrc/cbm/execvars.s | 28 ++++++++++++++++++++++++++++ libsrc/pet/mainargs.s | 1 - 9 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 libsrc/cbm/execvars.s diff --git a/asminc/c128.inc b/asminc/c128.inc index 1fb8b397c..aac8678bf 100644 --- a/asminc/c128.inc +++ b/asminc/c128.inc @@ -6,6 +6,7 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +TXTPTR := $3D ; Pointer into BASIC source code TIME := $A0 ; 60HZ clock FNAM_LEN := $B7 ; Length of filename SECADR := $B9 ; Secondary address diff --git a/asminc/c64.inc b/asminc/c64.inc index f5dbcf549..f450fcc0b 100644 --- a/asminc/c64.inc +++ b/asminc/c64.inc @@ -6,6 +6,7 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +TXTPTR := $7A ; Pointer into BASIC source code TIME := $A0 ; 60 HZ clock FNAM_LEN := $B7 ; Length of filename SECADR := $B9 ; Secondary address diff --git a/asminc/cbm510.inc b/asminc/cbm510.inc index 827c507fc..f031a1e35 100644 --- a/asminc/cbm510.inc +++ b/asminc/cbm510.inc @@ -3,7 +3,8 @@ ; ; Taken from a kernal disassembly done by myself in 2000/2001. ; -; Ullrich von Bassewitz, 13.09.2001 +; 2001-09-13, Ullrich von Bassewitz +; 2013-08-23, Greg King ;----------------------------------------------------------------------------- @@ -12,6 +13,8 @@ ExecReg = $00 IndReg = $01 +TXTPTR := $85 ; Far pointer into BASIC source code + ; --------------------------------------------------------------------------- ; Screen size @@ -21,7 +24,7 @@ YSIZE = 25 ;----------------------------------------------------------------------------- ; I/O Definitions -; I/O $d800: VIC +; I/O $d800: VIC-II VIC_SPR0_X = $00 VIC_SPR0_Y = $01 @@ -75,7 +78,6 @@ VIC_BG_COLOR2 = $23 VIC_BG_COLOR3 = $24 - ; I/O $da00: SID 6581 SID_S1Lo = $00 @@ -112,7 +114,7 @@ SID_Noise = $1B SID_Read3 = $1C -; I/O $db00: CIA 6526 Inter Process Communication +; I/O $db00: CIA 6526, Inter Process Communication ; I/O $dc00: CIA 6526 .struct CIA @@ -176,7 +178,13 @@ SID_Read3 = $1C .endstruct -; Out video memory address +;----------------------------------------------------------------------------- +; Our video memory address -COLOR_RAM = $D400 ; System bank +COLOR_RAM := $D400 ; System bank + +;----------------------------------------------------------------------------- + +BASIC_BUF := $FB5E ; Bank 0 location of command-line +BASIC_BUF_LEN = 162 ; Maximum length of command-line diff --git a/asminc/cbm610.inc b/asminc/cbm610.inc index 94256eeb1..10d194ea7 100644 --- a/asminc/cbm610.inc +++ b/asminc/cbm610.inc @@ -9,8 +9,10 @@ ; --------------------------------------------------------------------------- ; Zeropage stuff -ExecReg = $00 -IndReg = $01 +ExecReg := $00 +IndReg := $01 + +TXTPTR := $85 ; Far pointer into BASIC source code ; --------------------------------------------------------------------------- ; Screen size @@ -29,7 +31,8 @@ YSIZE = 25 DATA .byte .endstruct -; I/O $db00: CIA 6526 Inter Process Communication + +; I/O $db00: CIA 6526, Inter Process Communication ; ; IPCcia = $db00 @@ -68,7 +71,6 @@ YSIZE = 25 ; cia = $dc00 - ; I/O $dd00: ACIA 6551 ; ; acia = $dd00 @@ -108,3 +110,7 @@ YSIZE = 25 ; tpi2 = $df00 +;----------------------------------------------------------------------------- + +BASIC_BUF := $FA5E ; Bank 1 location of command-line +BASIC_BUF_LEN = 162 ; Maximum length of command-line diff --git a/asminc/pet.inc b/asminc/pet.inc index a3dadf48d..1ebf391f9 100644 --- a/asminc/pet.inc +++ b/asminc/pet.inc @@ -7,6 +7,7 @@ ; Zero page, Commodore stuff MEMSIZE := $34 ; Size of memory installed +TXTPTR := $77 ; Pointer into BASIC source code TIME := $8D ; 60HZ clock KEY_COUNT := $9E ; Number of keys in input buffer RVS := $9F ; Reverse flag @@ -24,6 +25,9 @@ SCR_LINELEN := $D5 ; Screen line length CURS_Y := $D8 ; Cursor row FNADR := $DA ; Pointer to file name +BASIC_BUF := $200 ; Location of command-line +BASIC_BUF_LEN = 81 ; Maximum length of command-line + KEY_BUF := $26F ; Keyboard buffer ;---------------------------------------------------------------------------- diff --git a/asminc/plus4.inc b/asminc/plus4.inc index 014c18e60..17e250508 100644 --- a/asminc/plus4.inc +++ b/asminc/plus4.inc @@ -7,6 +7,7 @@ ; Zero page, Commodore stuff TMPPTR := $22 ; Temporary ptr used by BASIC +TXTPTR := $3B ; Pointer into BASIC source code TIME := $A3 ; 60HZ clock FNAM_LEN := $AB ; Length of filename LFN := $AC ; Logical file number diff --git a/asminc/vic20.inc b/asminc/vic20.inc index 6780d067d..c42db4258 100644 --- a/asminc/vic20.inc +++ b/asminc/vic20.inc @@ -6,6 +6,7 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +TXTPTR := $7A ; Pointer into BASIC source code TIME := $A0 ; 60HZ clock FNAM_LEN := $B7 ; Length of filename SECADR := $B9 ; Secondary address diff --git a/libsrc/cbm/execvars.s b/libsrc/cbm/execvars.s new file mode 100644 index 000000000..02eabc12e --- /dev/null +++ b/libsrc/cbm/execvars.s @@ -0,0 +1,28 @@ +; +; Platform-specific variables for the exec program-chaining function +; + +.if .defined (__C128__) + .include "c128.inc" +.elseif .defined (__C16__) + .include "c16.inc" +.elseif .defined (__C64__) + .include "c64.inc" +.elseif .defined (__CBM510__) + .include "cbm510.inc" +.elseif .defined (__CBM610__) + .include "cbm610.inc" +.elseif .defined (__PET__) + .include "pet.inc" +.elseif .defined (__PLUS4__) + .include "plus4.inc" +.else + .include "vic20.inc" +.endif + + .export _txtptr:zp, _basbuf, _basbuf_len:zp + +_txtptr := TXTPTR + +_basbuf := BASIC_BUF +_basbuf_len = BASIC_BUF_LEN diff --git a/libsrc/pet/mainargs.s b/libsrc/pet/mainargs.s index 9a63f50c2..0d5b18987 100644 --- a/libsrc/pet/mainargs.s +++ b/libsrc/pet/mainargs.s @@ -13,7 +13,6 @@ MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code NAME_LEN = 16 ; maximum length of command-name -BASIC_BUF= $200 ;--------------------------------------------------------------------------- From 2d66c27462c45845e710cd2f21eff643fe7617bb Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 25 Aug 2013 00:49:03 -0400 Subject: [PATCH 062/144] Added test programs for the exec() function. --- testcode/lib/arg-test.c | 3 +++ testcode/lib/exec-test1.c | 24 ++++++++++++++++++++++++ testcode/lib/exec-test2.c | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 testcode/lib/exec-test1.c create mode 100644 testcode/lib/exec-test2.c diff --git a/testcode/lib/arg-test.c b/testcode/lib/arg-test.c index c752acaeb..5c28faec0 100644 --- a/testcode/lib/arg-test.c +++ b/testcode/lib/arg-test.c @@ -9,6 +9,9 @@ int main (int argc, char* argv[]) for (I = 0; I < argc; ++I) { printf ("argv[%2d]: \"%s\"\n", I, argv[I]); } + + printf ("\n"); + getchar (); return EXIT_SUCCESS; } diff --git a/testcode/lib/exec-test1.c b/testcode/lib/exec-test1.c new file mode 100644 index 000000000..e2548fb0a --- /dev/null +++ b/testcode/lib/exec-test1.c @@ -0,0 +1,24 @@ +/* +** These programs test CC65's exec() program-chaining function. +** exec-test1 runs exec-test2 -- that tests the loading and starting of another +** program. Then, exec-test2 runs arg-test -- that tests command-line argument +** passing. +** +** 2013-08-24, Greg King +*/ + +#include +#include +#include +#include + +int main (void) { + clrscr (); + cprintf ("\nExec-test #1 -- launching #2...\r\n"); + + exec ("exec-test2", ""); + + cprintf ("\nFailed to find #2:\r\n %s.\r\n", _stroserror (_oserror)); + cgetc (); + return _oserror; +} diff --git a/testcode/lib/exec-test2.c b/testcode/lib/exec-test2.c new file mode 100644 index 000000000..e6c844a8e --- /dev/null +++ b/testcode/lib/exec-test2.c @@ -0,0 +1,23 @@ +/* +** These programs test CC65's exec() program-chaining function. +** exec-test1 runs exec-test2 -- that tests the loading and starting of another +** program. Then, exec-test2 runs arg-test -- that tests command-line argument +** passing. +** +** 2013-08-24, Greg King +*/ + +#include +#include +#include +#include + +int main (void) { + cprintf ("\nExec-test #2 -- launching arg-test...\r\n\n"); + + exec ("arg-test", "arg1 arg2 \"\" arg4"); + + cprintf ("\nFailed to find arg-test:\r\n %s.\r\n", _stroserror (_oserror)); + cgetc (); + return _oserror; +} From 6a9ab1a69a5906aef8448d4b0424485bf947bfba Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 25 Aug 2013 00:58:27 -0400 Subject: [PATCH 063/144] Added a little more info about how CBM program-chaining works. --- libsrc/cbm/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/cbm/exec.c b/libsrc/cbm/exec.c index 302115c17..dec2e0080 100644 --- a/libsrc/cbm/exec.c +++ b/libsrc/cbm/exec.c @@ -7,7 +7,7 @@ ** It puts the desired program's name and unit number into a LOAD statement. ** Then, it points BASIC to that statement, so that the ROM will run that ** statement after this program quits. The ROM will load the next program, -** and execute it. +** and will execute it (because the LOAD will be seen in a running program). */ #include From 4062cb6b6ccd6e3a32ca6be4cc75579526fb8601 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Sun, 25 Aug 2013 11:20:27 +0200 Subject: [PATCH 064/144] atarixl target: add support for interruptors, adapt TGI drivers --- asminc/atari.inc | 11 ++++-- libsrc/atari/irq.s | 12 +++++++ libsrc/atari/libref.s | 5 +++ libsrc/atari/shadow_ram_handlers.s | 50 ++++++++++++++++----------- libsrc/atari/shadow_ram_prepare.s | 11 ++++-- libsrc/atari/tgi/atari_tgi_common.inc | 37 +++++++++++++++----- 6 files changed, 93 insertions(+), 33 deletions(-) diff --git a/asminc/atari.inc b/asminc/atari.inc index da524baad..864b59808 100644 --- a/asminc/atari.inc +++ b/asminc/atari.inc @@ -1003,15 +1003,20 @@ CASETV = $E440 ;cassette handler vector table DISKIV = $E450 ;vector to initialize DIO DSKINV = $E453 ;vector to DIO .if .defined(__ATARIXL__) -CIOV = $C0 -SIOV = $C3 +.ifndef SHRAM_HANDLERS +.import CIO_handler, SIO_handler, SETVBV_handler +.endif +.define CIOV CIO_handler +.define SIOV SIO_handler +.define SETVBV SETVBV_handler CIOV_org = $E456 ;vector to CIO SIOV_org = $E459 ;vector to SIO +SETVBV_org = $E45C ;vector to set VBLANK parameters .else CIOV = $E456 ;vector to CIO SIOV = $E459 ;vector to SIO -.endif SETVBV = $E45C ;vector to set VBLANK parameters +.endif SYSVBV = $E45F ;vector to process immediate VBLANK XITVBV = $E462 ;vector to process deferred VBLANK SIOINV = $E465 ;vector to initialize SIO diff --git a/libsrc/atari/irq.s b/libsrc/atari/irq.s index 9a433ca00..597ad9d60 100644 --- a/libsrc/atari/irq.s +++ b/libsrc/atari/irq.s @@ -39,7 +39,19 @@ doneirq: IRQStub: cld ; Just to be sure +.if .defined(__ATARIXL__) + pha + lda PORTB + pha + and #$fe + sta PORTB ; disable ROM @@@ TODO: update CHARGEN +.endif jsr callirq ; Call the functions +.if .defined(__ATARIXL__) + pla + sta PORTB + pla +.endif jmp IRQInd ; Jump to the saved IRQ vector ; ------------------------------------------------------------------------ diff --git a/libsrc/atari/libref.s b/libsrc/atari/libref.s index 8d9ff3e08..6d93a0b8e 100644 --- a/libsrc/atari/libref.s +++ b/libsrc/atari/libref.s @@ -7,4 +7,9 @@ em_libref := _exit joy_libref := _exit +.if .defined(__ATARIXL__) + .import CIO_handler +tgi_libref := CIO_handler +.else tgi_libref := _exit +.endif diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 048a5a5c0..32b493ac0 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -8,6 +8,7 @@ DEBUG = 1 .if .defined(__ATARIXL__) + SHRAM_HANDLERS = 1 .include "atari.inc" .include "save_area.inc" .include "zeropage.inc" @@ -15,8 +16,12 @@ DEBUG = 1 .export sram_init .export KEYBDV_wrapper + .export CIO_handler + .export SIO_handler + .export SETVBV_handler -BUFSZ = 256 ; bounce buffer size +BUFSZ = 128 ; bounce buffer size +BUFSZ_SIO = 256 .macro disable_rom lda PORTB @@ -65,20 +70,6 @@ sram_init: lda #>my_NMI_han sta $fffb -; setup pointers to CIOV and SIOV wrappers - lda #$4C ; JMP opcode - sta CIOV - lda #my_CIOV - sta CIOV+2 - lda #$4C ; JMP opcode - sta SIOV - lda #my_SIOV - sta SIOV+2 - ; enable interrupts lda #$40 sta NMIEN @@ -94,7 +85,7 @@ zpptr1: .res 2 .segment "LOWBUFS" ; bounce buffers for CIO and SIO calls -bounce_buffer: .res BUFSZ +bounce_buffer: .res BUFSZ_SIO .segment "LOWCODE" @@ -240,7 +231,7 @@ CIOV_call: ; ; FIXME: Currently only the requests used by the runtime lib are handled. -my_CIOV: +CIO_handler: ; @@@ TODO: check X for valid IOCB index ((X < $80) and ((X & $F) == 0)) @@ -707,7 +698,7 @@ setup_zpptr1: ; These are the only functions used by the runtime library currently. ; For other function we return NVALID status code. -my_SIOV: +SIO_handler: lda DCOMND ; get command cmp #SIO_STAT beq SIO_stat @@ -839,9 +830,9 @@ sio_write_copy: ; CF - 0/1 for larger/not larger cmp_sio_len_bnc_bufsz: sec - lda #BUFSZ + lda #>BUFSZ_SIO sbc DBYTHI rts @@ -888,6 +879,24 @@ kret: pha pla rts +;--------------------------------------------------------- + +SETVBV_handler: + + pha + lda PORTB + sta cur_SETVBV_PORTB + enable_rom + pla + jsr SETVBV_org + php + pha + lda cur_SETVBV_PORTB + sta PORTB + pla + plp + rts + CIO_a: .res 1 CIO_x: .res 1 CIO_y: .res 1 @@ -895,6 +904,7 @@ CIO_p: .res 1 cur_CIOV_PORTB: .res 1 cur_SIOV_PORTB: .res 1 cur_KEYBDV_PORTB: .res 1 +cur_SETVBV_PORTB: .res 1 orig_ptr: .res 2 orig_len: .res 2 req_len: .res 2 diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index da83a1df9..ed30d4b2b 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -97,13 +97,20 @@ sramprep: ldx lowadr stx MEMTOP - stx APPMHI lda lowadr+1 sta MEMTOP+1 - sta APPMHI+1 lda lodadr+1 sta RAMTOP + ; set APPMHI to MEMLO (+ 1 for sanity) + lda MEMLO + clc + adc #1 + sta APPMHI + lda MEMLO+1 + adc #0 + sta APPMHI+1 + ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) diff --git a/libsrc/atari/tgi/atari_tgi_common.inc b/libsrc/atari/tgi/atari_tgi_common.inc index 7dba884fa..7151d2d1e 100644 --- a/libsrc/atari/tgi/atari_tgi_common.inc +++ b/libsrc/atari/tgi/atari_tgi_common.inc @@ -4,6 +4,12 @@ .macpack longbranch +.if .defined(__ATARIXL__) + CIO_vec := my_CIOV +.else + CIO_vec := CIOV +.endif + ; ****************************************************************************** ; ---------------------------------------------------------------------- @@ -18,7 +24,7 @@ .byte $74, $67, $69 ; "tgi" .byte TGI_API_VERSION ; TGI API version number - .addr $0000 ; Library reference +libref: .addr $0000 ; Library reference .word x_res ; X resolution .word y_res ; Y resolution .byte colors ; Number of drawing colors @@ -111,6 +117,10 @@ text_dir: .byte 0 ; Text direction, +.if .defined(__ATARIXL__) + my_CIOV: + .byte $4C, 0, 0 +.endif .code ; ****************************************************************************** @@ -161,6 +171,17 @@ screen_device_length := * - screen_device stx mask +.if .defined(__ATARIXL__) + + ; setup pointer to CIO + + lda libref + sta my_CIOV+1 + lda libref+1 + sta my_CIOV+2 +.endif + + ; Find a free IOCB lda #$70 search: tax @@ -202,7 +223,7 @@ switch: lda #OPEN sta ICBLL,x lda #>screen_device_length sta ICBLH,x - jsr CIOV + jsr CIO_vec .if ::pages = 2 ; Reserve 8K of high memory @@ -212,7 +233,7 @@ switch: lda #OPEN ; Close and reopen graphics lda #CLOSE sta ICCOM,x - jsr CIOV + jsr CIO_vec ; Reopen graphics lda #OPEN sta ICCOM,x @@ -228,7 +249,7 @@ switch: lda #OPEN sta ICBLL,x lda #>screen_device_length sta ICBLH,x - jsr CIOV + jsr CIO_vec ; Save screen pointers lda SAVMSC + 1 sta p0scr @@ -271,7 +292,7 @@ exit: sta error ; Close the S: device lda #CLOSE sta ICCOM,x - jsr CIOV + jsr CIO_vec ; Reopen it in Graphics 0 lda #OPEN @@ -288,12 +309,12 @@ exit: sta error sta ICBLL,x lda #>screen_device_length sta ICBLH,x - jsr CIOV + jsr CIO_vec ; Now close it again; we don't need it anymore :) lda #CLOSE sta ICCOM,x - jmp CIOV + jmp CIO_vec .endproc ; ****************************************************************************** @@ -640,7 +661,7 @@ done10: .endif sta ATACHR - jmp CIOV + jmp CIO_vec .else ; USE_CIO_LINE From a3511ea93dff055022d88ec3c4d6eb17ead2cb6e Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Mon, 26 Aug 2013 10:36:40 +0200 Subject: [PATCH 065/144] changes for atarixl target --- libsrc/atari/ostype.s | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/libsrc/atari/ostype.s b/libsrc/atari/ostype.s index dc17018fa..7a3342d2a 100644 --- a/libsrc/atari/ostype.s +++ b/libsrc/atari/ostype.s @@ -41,11 +41,41 @@ .export _get_ostype .if .defined(__ATARIXL__) -.warning "fix me!" + + .include "atari.inc" + .import __CHARGEN_START__ + .segment "LOWCODE" +.macro disable_rom + pha + lda PORTB + and #$fe + sta PORTB + lda #>__CHARGEN_START__ + sta CHBAS + sta CHBASE + pla +.endmacro +.macro enable_rom + lda PORTB + ora #1 + sta PORTB + lda #$E0 + sta CHBAS + sta CHBASE +.endmacro + +.else ; above atarixl, below atari + +.macro disable_rom +.endmacro +.macro enable_rom +.endmacro + .endif .proc _get_ostype + enable_rom lda $fcd8 cmp #$a2 beq _400800 @@ -67,6 +97,7 @@ and #%00111000 ora #%11 _fin: ldx #0 + disable_rom rts ; unknown ROM @@ -74,6 +105,7 @@ _fin: ldx #0 _unknown: lda #0 tax + disable_rom rts ; 1200XL ROM From 881ac93b6c556267e5d0510d7898d3bfbc5260b9 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Mon, 26 Aug 2013 12:16:26 +0200 Subject: [PATCH 066/144] remove warning about missing return value; fix typo --- testcode/lib/atari/ostype.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testcode/lib/atari/ostype.c b/testcode/lib/atari/ostype.c index e97bd00e6..f5e9296ca 100644 --- a/testcode/lib/atari/ostype.c +++ b/testcode/lib/atari/ostype.c @@ -40,6 +40,7 @@ int main(void) printf("is'a a XL/XE, %s, Rev. %d\n",palntsc ? "PAL" : "NTSC",minor); break; } - printf("hit to continure...\n"); + printf("hit to continue...\n"); c = getchar(); + return 0; } From 13a7812cf57a55e0086962dd4598b0747d9eec5a Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 22 Aug 2013 13:08:48 +0200 Subject: [PATCH 067/144] add some more SIO information --- asminc/atari.inc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/asminc/atari.inc b/asminc/atari.inc index 1fff3ebae..d976d6475 100644 --- a/asminc/atari.inc +++ b/asminc/atari.inc @@ -101,11 +101,28 @@ SIO_FORMAT = $21 ;format disk (default density) SIO_FORMATS = $22 ;1050: format medium density SIO_CONFIG = $44 ;configure drive SIO_CONFIGSF = $4B ;slow/fast configure drive?? +SIO_RDPERCOM = $4E ;read PERCOM block (XF551) +SIO_WRPERCOM = $4F ;write PERCOM block (XF551) SIO_WRITE = $50 ;write sector SIO_READ = $52 ;read sector SIO_STAT = $53 ;get status information SIO_VERIFY = $56 ;verify sector SIO_WRITEV = $57 ;write sector with verify +SIO_WRITETRK = $60 ;write track (Speedy) +SIO_READTRK = $62 ;read track (Speedy) + +; SIO Status Code (DSTATS) +; Input: data direction +; Bit #7 - W (write operation) +; #6 - R (read operation) +; Output: status code +; $01 (001) -- OPERATION COMPLETE (NO ERRORS) +; $8A (138) -- DEVICE TIMEOUT (DOESN'T RESPOND) +; $8B (139) -- DEVICE NAK +; $8C (140) -- SERIAL BUS INPUT FRAMING ERROR +; $8E (142) -- SERIAL BUS DATA FRAME OVERRUN ERROR +; $8F (143) -- SERIAL BUS DATA FRAME CHECKSUM ERROR +; $90 (144) -- DEVICE DONE ERROR ; Character and Key Code Equates From 887ba4d501d3bf99c0ec983637bb3e3227a2a987 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Mon, 26 Aug 2013 12:16:26 +0200 Subject: [PATCH 068/144] remove warning about missing return value; fix typo --- testcode/lib/atari/ostype.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testcode/lib/atari/ostype.c b/testcode/lib/atari/ostype.c index e97bd00e6..f5e9296ca 100644 --- a/testcode/lib/atari/ostype.c +++ b/testcode/lib/atari/ostype.c @@ -40,6 +40,7 @@ int main(void) printf("is'a a XL/XE, %s, Rev. %d\n",palntsc ? "PAL" : "NTSC",minor); break; } - printf("hit to continure...\n"); + printf("hit to continue...\n"); c = getchar(); + return 0; } From 67571d4f5f79369409c472904c066d3d41389040 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 26 Aug 2013 22:02:00 -0400 Subject: [PATCH 069/144] Changed some CPU memory-mapped register definitions from expression mode into label mode. --- asminc/cbm510.inc | 6 +++--- asminc/cbm610.inc | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/asminc/cbm510.inc b/asminc/cbm510.inc index f031a1e35..dfeee1d4e 100644 --- a/asminc/cbm510.inc +++ b/asminc/cbm510.inc @@ -4,14 +4,14 @@ ; Taken from a kernal disassembly done by myself in 2000/2001. ; ; 2001-09-13, Ullrich von Bassewitz -; 2013-08-23, Greg King +; 2013-08-26, Greg King ;----------------------------------------------------------------------------- ; Zeropage stuff -ExecReg = $00 -IndReg = $01 +ExecReg := $00 ; Controls execution memory bank +IndReg := $01 ; Controls indirect indexed load-store bank TXTPTR := $85 ; Far pointer into BASIC source code diff --git a/asminc/cbm610.inc b/asminc/cbm610.inc index 10d194ea7..f442f5da8 100644 --- a/asminc/cbm610.inc +++ b/asminc/cbm610.inc @@ -1,16 +1,17 @@ ; -; Zeropage and I/O definitions for the CBM 610 +; Zero page variables and I/O definitions for the CBM 610 ; ; Taken from a kernal disassembly done by myself in 1987. ; -; Ullrich von Bassewitz, 28.09.1998 +; 1998-09-28, Ullrich von Bassewitz +; 2013-08-26, Greg King ; --------------------------------------------------------------------------- ; Zeropage stuff -ExecReg := $00 -IndReg := $01 +ExecReg := $00 ; Controls execution memory bank +IndReg := $01 ; Controls indirect indexed load-store bank TXTPTR := $85 ; Far pointer into BASIC source code From 68fc4a1b1577f897d582dd605376fb6d4151101c Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 27 Aug 2013 10:21:42 +0200 Subject: [PATCH 070/144] rename KEYBDV_wrapper to KEYBDV_handler --- libsrc/atari/cgetc.s | 8 ++++---- libsrc/atari/shadow_ram_handlers.s | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libsrc/atari/cgetc.s b/libsrc/atari/cgetc.s index 43969c2aa..cf853f5ce 100644 --- a/libsrc/atari/cgetc.s +++ b/libsrc/atari/cgetc.s @@ -7,7 +7,7 @@ .include "atari.inc" .export _cgetc,setcursor - .import KEYBDV_wrapper + .import KEYBDV_handler .import cursor,mul40 _cgetc: @@ -17,17 +17,17 @@ _cgetc: .if .not .defined(__ATARIXL__) jsr @1 .else - jsr KEYBDV_wrapper + jsr KEYBDV_handler .endif ldx #0 rts .if .not .defined(__ATARIXL__) -@1: lda KEYBDV+5 +@1: lda KEYBDV+5 pha lda KEYBDV+4 pha - rts + rts .endif .proc setcursor diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 32b493ac0..56ddc76c3 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -15,7 +15,7 @@ DEBUG = 1 .import __CHARGEN_START__ .export sram_init - .export KEYBDV_wrapper + .export KEYBDV_handler .export CIO_handler .export SIO_handler .export SETVBV_handler @@ -859,7 +859,7 @@ orgbuf_to_dbuf: ;--------------------------------------------------------- -KEYBDV_wrapper: +KEYBDV_handler: lda #>(kret-1) pha From e12fbe35a80a883652a58b7f7d16be787588e536 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 27 Aug 2013 22:01:19 +0200 Subject: [PATCH 071/144] em-test.c: add support for Atari --- testcode/lib/em-test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testcode/lib/em-test.c b/testcode/lib/em-test.c index c7fee6a59..41a7eb2c8 100644 --- a/testcode/lib/em-test.c +++ b/testcode/lib/em-test.c @@ -20,6 +20,10 @@ #define DRIVERNAME "a2e.auxmem.emd" #elif defined(__APPLE2__) #define DRIVERNAME "a2.auxmem.emd" +#elif defined(__ATARIXL__) +#define DRIVERNAME "atrx130.emd" +#elif defined(__ATARI__) +#define DRIVERNAME "atr130.emd" #else #define DRIVERNAME "unknown" #error "Unknown target system" @@ -63,6 +67,9 @@ static void cmp (unsigned page, register const unsigned* buf, cprintf ("\r\nData mismatch in page $%04X at $%04X\r\n" "Data is $%04X (should be $%04X)\r\n", page, buf, *buf, num); +#ifdef __ATARI__ + cgetc (); +#endif exit (EXIT_FAILURE); } } @@ -84,6 +91,9 @@ int main (void) if (Res != EM_ERR_OK) { cprintf ("Error in em_load_driver: %u\r\n", Res); cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror)); +#ifdef __ATARI__ + cgetc (); +#endif exit (EXIT_FAILURE); } atexit (cleanup); @@ -195,6 +205,10 @@ int main (void) /* Success */ cprintf ("\r\nPassed!\r\n"); +#ifdef __ATARI__ + cgetc (); +#endif + return 0; } From 06162498a60fd4013265ce1a38dbebb0c041b0ae Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 27 Aug 2013 22:01:19 +0200 Subject: [PATCH 072/144] em-test.c: add support for Atari --- testcode/lib/em-test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testcode/lib/em-test.c b/testcode/lib/em-test.c index c7fee6a59..41a7eb2c8 100644 --- a/testcode/lib/em-test.c +++ b/testcode/lib/em-test.c @@ -20,6 +20,10 @@ #define DRIVERNAME "a2e.auxmem.emd" #elif defined(__APPLE2__) #define DRIVERNAME "a2.auxmem.emd" +#elif defined(__ATARIXL__) +#define DRIVERNAME "atrx130.emd" +#elif defined(__ATARI__) +#define DRIVERNAME "atr130.emd" #else #define DRIVERNAME "unknown" #error "Unknown target system" @@ -63,6 +67,9 @@ static void cmp (unsigned page, register const unsigned* buf, cprintf ("\r\nData mismatch in page $%04X at $%04X\r\n" "Data is $%04X (should be $%04X)\r\n", page, buf, *buf, num); +#ifdef __ATARI__ + cgetc (); +#endif exit (EXIT_FAILURE); } } @@ -84,6 +91,9 @@ int main (void) if (Res != EM_ERR_OK) { cprintf ("Error in em_load_driver: %u\r\n", Res); cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror)); +#ifdef __ATARI__ + cgetc (); +#endif exit (EXIT_FAILURE); } atexit (cleanup); @@ -195,6 +205,10 @@ int main (void) /* Success */ cprintf ("\r\nPassed!\r\n"); +#ifdef __ATARI__ + cgetc (); +#endif + return 0; } From ae9ab595490510674c63dee6b2b486192e237e42 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 27 Aug 2013 22:45:23 +0200 Subject: [PATCH 073/144] xlmemchk.inc: Fix wrong calculation if load address is at an exact 4K border. --- libsrc/atari/xlmemchk.inc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libsrc/atari/xlmemchk.inc b/libsrc/atari/xlmemchk.inc index 9cc6b612c..81e09ba90 100644 --- a/libsrc/atari/xlmemchk.inc +++ b/libsrc/atari/xlmemchk.inc @@ -61,13 +61,17 @@ scrmemtst: cmp tmp beq scrmemok +; if lodadr is at an exact 4K boundary, it's still ok + + lda lodadr+1 + and #$0f + beq scrmemok + ; 4K boundary will be crossed, use this 4K boundary address as lodadr al4k: lda lodadr+1 and #$f0 - tax - dex - stx lodadr+1 + sta lodadr+1 bne scrmemtst ; not reached @@ -89,6 +93,7 @@ scrmemok: sbc #>DLSZ sta lowadr+1 +.if 0 ; this cannot happen ; check if a 1K boundary is crossed lda tstadr+1 @@ -98,6 +103,7 @@ scrmemok: and #$fc cmp tmp bne al4k ; 1K boundary will be crossed, decrease lodadr +.endif ; address of display list is ok ; decrease lowadr by two From 0684ab7ab9b00ee800cf05c10a355f780664c5c3 Mon Sep 17 00:00:00 2001 From: Greg King Date: Wed, 28 Aug 2013 02:58:41 -0400 Subject: [PATCH 074/144] Fixed some return pointers. $1234 pointers were returned as $3434. --- libsrc/common/strlower.s | 9 +++++---- libsrc/common/strupper.s | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libsrc/common/strlower.s b/libsrc/common/strlower.s index 9df79b732..848a4faff 100644 --- a/libsrc/common/strlower.s +++ b/libsrc/common/strlower.s @@ -1,8 +1,9 @@ ; -; Ullrich von Bassewitz, 02.06.1998 +; 1998-06-02, Ullrich von Bassewitz +; 2013-08-28, Greg King ; -; char* strlower (char* s); -; char* strlwr (char* s); +; char* __fastcall__ strlower (char* s); +; char* __fastcall__ strlwr (char* s); ; ; Non-ANSI ; @@ -19,7 +20,7 @@ _strlwr: sta ptr1 ; Save s (working copy) stx ptr1+1 sta ptr2 - sta ptr2+1 ; save function result + stx ptr2+1 ; save function result ldy #0 loop: lda (ptr1),y ; get character diff --git a/libsrc/common/strupper.s b/libsrc/common/strupper.s index d7aa2f914..bf0d3b622 100644 --- a/libsrc/common/strupper.s +++ b/libsrc/common/strupper.s @@ -1,8 +1,9 @@ ; -; Ullrich von Bassewitz, 02.06.1998 +; 1998-06-02, Ullrich von Bassewitz +; 2013-08-28, Greg King ; -; char* strupper (char* s); -; char* strupr (char* s); +; char* __fastcall__ strupper (char* s); +; char* __fastcall__ strupr (char* s); ; ; Non-ANSI ; @@ -19,7 +20,7 @@ _strupr: sta ptr1 ; Save s (working copy) stx ptr1+1 sta ptr2 - sta ptr2+1 ; save function result + stx ptr2+1 ; save function result ldy #0 loop: lda (ptr1),y ; get character From 3969d920fafa024c573f994dd54da990331f5f5f Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sun, 1 Sep 2013 09:45:11 +0200 Subject: [PATCH 075/144] Bumped driver api versions due to recent intoduction of library references. --- asminc/em-kernel.inc | 2 +- asminc/joy-kernel.inc | 2 +- asminc/mouse-kernel.inc | 2 +- asminc/ser-kernel.inc | 2 +- asminc/tgi-kernel.inc | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/asminc/em-kernel.inc b/asminc/em-kernel.inc index 313bfc0bf..e7cdf9a70 100644 --- a/asminc/em-kernel.inc +++ b/asminc/em-kernel.inc @@ -55,7 +55,7 @@ ;------------------------------------------------------------------------------ ; The EMD API version, stored in EMD_HDR::VERSION -EMD_API_VERSION = $01 +EMD_API_VERSION = $02 ;------------------------------------------------------------------------------ ; The asm equivalent to the C em_copy structure diff --git a/asminc/joy-kernel.inc b/asminc/joy-kernel.inc index da22662b5..4fe5572cf 100644 --- a/asminc/joy-kernel.inc +++ b/asminc/joy-kernel.inc @@ -56,7 +56,7 @@ ;------------------------------------------------------------------------------ ; The JOY API version, stored in JOY_HDR::VERSION -JOY_API_VERSION = $02 +JOY_API_VERSION = $03 ;------------------------------------------------------------------------------ ; Variables diff --git a/asminc/mouse-kernel.inc b/asminc/mouse-kernel.inc index 9db47fcb8..d3ec9b30f 100644 --- a/asminc/mouse-kernel.inc +++ b/asminc/mouse-kernel.inc @@ -97,7 +97,7 @@ ;------------------------------------------------------------------------------ ; The mouse API version, stored in MOUSE_HDR::VERSION -MOUSE_API_VERSION = $03 +MOUSE_API_VERSION = $04 ;------------------------------------------------------------------------------ ; Bitmapped mouse driver flags, stored in MOUSE_HDR::FLAGS. diff --git a/asminc/ser-kernel.inc b/asminc/ser-kernel.inc index fff9b1440..e59501da6 100644 --- a/asminc/ser-kernel.inc +++ b/asminc/ser-kernel.inc @@ -57,7 +57,7 @@ ;------------------------------------------------------------------------------ ; The SER API version, stored SER_HDR::VERSION -SER_API_VERSION = $01 +SER_API_VERSION = $02 ;------------------------------------------------------------------------------ ; ser_params diff --git a/asminc/tgi-kernel.inc b/asminc/tgi-kernel.inc index 6e687315d..e9f2f6aa9 100644 --- a/asminc/tgi-kernel.inc +++ b/asminc/tgi-kernel.inc @@ -77,7 +77,7 @@ ;------------------------------------------------------------------------------ ; The TGI API version, stored at TGI_HDR_VERSION -TGI_API_VERSION = $04 +TGI_API_VERSION = $05 ;------------------------------------------------------------------------------ ; Bitmapped tgi driver flags, stored in TGI_HDR::VARS::FLAGS. From 875212a8503c4c3e8c1c6961eb22fd97c80b11e0 Mon Sep 17 00:00:00 2001 From: Greg King Date: Wed, 4 Sep 2013 09:16:00 -0400 Subject: [PATCH 076/144] Added more details about how the CBM exec() works. --- libsrc/cbm/exec.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/libsrc/cbm/exec.c b/libsrc/cbm/exec.c index dec2e0080..36c3afe00 100644 --- a/libsrc/cbm/exec.c +++ b/libsrc/cbm/exec.c @@ -1,12 +1,18 @@ /* ** Program-chaining function for Commodore platforms. ** -** 2013-08-24, Greg King +** 2013-09-04, Greg King ** ** This function exploits the program-chaining feature in CBM BASIC's ROM. -** It puts the desired program's name and unit number into a LOAD statement. -** Then, it points BASIC to that statement, so that the ROM will run that -** statement after this program quits. The ROM will load the next program, +** +** CC65's CBM programs have a BASIC program stub. We start those programs by +** RUNning that stub; it SYSes to the Machine Language code. Normally, after +** the ML code exits, the BASIC ROM continues running the stub. But, it has +** no more statements; so, the program stops. +** +** This function puts the desired program's name and device number into a LOAD +** statement. Then, it points BASIC to that statement, so that the ROM will run +** that statement after this program quits. The ROM will load the next program, ** and will execute it (because the LOAD will be seen in a running program). */ @@ -23,6 +29,24 @@ #endif +/* The struct below is a line of BASIC code. It sits in the LOWCODE segment +** to make sure that it won't be hidden by a ROM when BASIC is re-enabled. +** The line is: +** 0 LOAD""+"" ,01 +** After this function has written into the line, it might look like this: +** 0 LOAD""+"program name" ,08 +** +** When BASIC's LOAD command asks the Kernal to load a file, it gives the +** Kernal a pointer to a file-name string. CC65's CBM programs use that +** pointer to give a copy of the program's name to main()'s argv[0] parameter. +** But, when BASIC uses a string literal that's in a program, it points +** directly to that literal -- in the models that don't use banked RAM +** (Pet/CBM, VIC-20, and 64). The literal is overwritten by the next program +** that's loaded. So, argv[0] would point to machine code. String operations +** create a new result string -- even when that operation changes nothing. The +** result is put in the string space at the top of BASIC's memory. So, the ""+ +** in this BASIC line guarantees that argv[0] will get a name from a safe place. +*/ #pragma data-name(push, "LOWCODE") static struct line { const char end_of_line; @@ -33,13 +57,8 @@ static struct line { const char comma; char unit[3]; } basic = { - '\0', &basic + 1, /* high byte must be non-zero */ - 0, 0x93, - - /* This string operation copies the name to high BASIC RAM. - ** So, it won't be overwritten when the next program is loaded. - */ - "\"\"", 0xaa, '\"', + '\0', &basic + 1, /* high byte of link must be non-zero */ + 0, 0x93, "\"\"", 0xaa, '\"', "\" ", /* format: "123:1234567890123456\"" */ ',', "01" }; From 4a0bdf871baad88bec9b405221d08ebaaaaf87db Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 4 Sep 2013 22:10:36 +0200 Subject: [PATCH 077/144] Remove screen flicker while mapping ROM out and in. Some cleanups. --- libsrc/atari/shadow_ram_prepare.s | 65 ++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index ed30d4b2b..673d33490 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -43,7 +43,7 @@ cont: ldx #0 ; channel 0 .endmacro ; ------------------------------------------------------------------------ -; Chunk header +; EXE load chunk header .segment "SRPREPHDR" @@ -74,13 +74,13 @@ sramprep: sta APPMHI_save+1 lda PORTB sta PORTB_save - lda CIOV ; zero-page wrapper + lda CIOV ; zero-page wrapper sta ZP_CIOV_save lda CIOV+1 sta ZP_CIOV_save+1 lda CIOV+2 sta ZP_CIOV_save+2 - lda SIOV ; zero-page wrapper + lda SIOV ; zero-page wrapper sta ZP_SIOV_save lda SIOV+1 sta ZP_SIOV_save+1 @@ -112,11 +112,11 @@ sramprep: sta APPMHI+1 -; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) +; issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) to move screen memory down jsr findfreeiocb -.ifdef DEBUG ; only check in debug version, this shouldn't happen normally(tm) +.ifdef DEBUG ; only check in debug version, this shouldn't really happen(tm) beq iocbok print_string "Internal error, no free IOCB!" jsr delay @@ -164,7 +164,6 @@ scrok: ; now close it again -- we don't need it anymore .ifdef DEBUG print_string "copy chargen to low memory" - print_string "set up high memory" .endif lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) @@ -179,6 +178,20 @@ scrok: ; now close it again -- we don't need it anymore sta ptr3 cg_addr_ok: + + lda ptr3+1 + and #3 + beq cg_addr_ok2 + + ; align to next 1K boundary + lda ptr3+1 + and #$fc + clc + adc #4 + sta ptr3+1 + +cg_addr_ok2: + lda #DCSORG @@ -186,29 +199,40 @@ cg_addr_ok: lda ptr3 sta ptr2 lda ptr3+1 + pha ; needed later to set CHBAS/CHBASE sta ptr2+1 lda #>__CHARGEN_SIZE__ sta tmp2 lda #<__CHARGEN_SIZE__ - sta tmp2+1 + sta tmp1 jsr memcopy -; TODO: switch to this temp. chargen +.ifdef DEBUG + print_string "now setting up high memory" +.endif -; disable ROMs +; disable ROM sei ldx #0 - stx NMIEN ; disable NMI + stx NMIEN ; disable NMI lda PORTB and #$fe - sta PORTB ; now ROM is mapped out + tax + pla ; get temp. chargen address + sta WSYNC ; wait for horiz. retrace + stx PORTB ; now ROM is mapped out + +; switch to temporary chargen + + sta CHBASE + sta CHBAS ; copy shadow RAM contents to their destination lda #<__SHADOW_RAM_SIZE__ bne do_copy lda #>__SHADOW_RAM_SIZE__ - beq no_copy ; we have no shadow RAM contents + beq no_copy ; we have no shadow RAM contents ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len do_copy:lda #<__SHADOW_RAM_LOAD__ @@ -248,21 +272,26 @@ no_copy: lda PORTB ora #1 + ldx #>DCSORG + sta WSYNC ; wait for horiz. retrace sta PORTB + stx CHBASE + stx CHBAS lda #$40 sta NMIEN ; enable VB again cli ; and enable IRQs .ifdef DEBUG print_string "Stage #2 OK" + print_string "loading main chunk" jsr delay .endif rts .include "findfreeiocb.inc" -; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html) - +; routine taken from http://www.obelisk.demon.co.uk/6502/algorithms.html +; ; copy memory ; ptr1 - source ; ptr2 - destination @@ -307,6 +336,8 @@ restore:lda RAMTOP_save rts +.ifdef DEBUG + .byte "HERE ****************** HERE ***************>>>>>>" sramsize: @@ -332,10 +363,14 @@ loop: dey .endproc +.endif ; .ifdef DEBUG + screen_device: .byte "S:",0 screen_device_length = * - screen_device +.ifdef DEBUG .byte " ** srprep ** end-->" +.endif ; ------------------------------------------------------------------------ ; Provide an empty SHADOW_RAM segment in order that the linker is happy @@ -345,7 +380,7 @@ screen_device_length = * - screen_device ; ------------------------------------------------------------------------ -; Chunk "trailer" - sets INITAD +; EXE load chunk "trailer" - sets INITAD .segment "SRPREPTRL" From 21e6654524b10668c665f257728df1593badde98 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 4 Sep 2013 22:25:29 +0200 Subject: [PATCH 078/144] adjust size of SRPREP to account for 1K aligned character generator (not page aligned as I thought before) --- cfg/atarixl.cfg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index c95227ec9..1968ecd8e 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -21,7 +21,7 @@ MEMORY { # "shadow RAM preparation" load chunk SRPREPHDR: file = %O, start = $0000, size = $0004; - SRPREP: file = %O, start = %S, size = $7C20 - %S - $04FF; # $04FF: space for temp. chargen buffer, page aligned + SRPREP: file = %O, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned SRPREPTRL: file = %O, start = $0000, size = $0006; # "main program" load chunk @@ -34,14 +34,14 @@ MEMORY { __SAVEAREA_SIZE__ - __LOWBUFS_SIZE__; +# defines entry point into program + TRAILER: file = %O, start = $0000, size = $0006; + # address of relocated character generator CHARGEN: file = "", define = yes, start = $D800, size = $0400; # memory beneath the ROM RAM_BELOW_ROM: file = "", start = $DC00, size = $FFF0 - $DC00; - -# defines entry point into program - TRAILER: file = %O, start = $0000, size = $0006; } SEGMENTS { From eb741e1396a0417c8bacd1af8a81826d03f71a6f Mon Sep 17 00:00:00 2001 From: Greg King Date: Thu, 5 Sep 2013 11:32:50 -0400 Subject: [PATCH 079/144] Don't shift in an unknown carry bit. If that bit happenned to be set, then it would defeat the fancy ADC shifter. --- libsrc/cbm510/mou/cbm510-joy.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/cbm510/mou/cbm510-joy.s b/libsrc/cbm510/mou/cbm510-joy.s index 7a98f8d39..9381cf761 100644 --- a/libsrc/cbm510/mou/cbm510-joy.s +++ b/libsrc/cbm510/mou/cbm510-joy.s @@ -2,7 +2,7 @@ ; Driver for a "joystick mouse". ; ; 2009-09-26, Ullrich von Bassewitz -; 2013-08-22, Greg King +; 2013-09-05, Greg King ; .include "zeropage.inc" @@ -252,7 +252,7 @@ BUTTONS: ; Joystick 1, fire button is in bit 6. and #%11000000 - rol a ; Move bits 7,6 to bits 1,0 + asl a ; Move bits 7,6 to bits 1,0 rol a rol a adc #%00001110 ; Move bit 1 to bit 4 From c48fbd8a2b8b7646bfe43a633becf39ce8e9ba7f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Sat, 7 Sep 2013 17:44:53 +0200 Subject: [PATCH 080/144] remove ZP_CIOV_save and ZP_SIOV_save --- libsrc/atari/save_area.inc | 2 -- libsrc/atari/save_area.s | 4 ---- libsrc/atari/shadow_ram_prepare.s | 12 ------------ 3 files changed, 18 deletions(-) diff --git a/libsrc/atari/save_area.inc b/libsrc/atari/save_area.inc index f14152ae0..3ec660203 100644 --- a/libsrc/atari/save_area.inc +++ b/libsrc/atari/save_area.inc @@ -11,5 +11,3 @@ .import APPMHI_save .import RAMTOP_save .import PORTB_save -.import ZP_CIOV_save -.import ZP_SIOV_save diff --git a/libsrc/atari/save_area.s b/libsrc/atari/save_area.s index 752e81487..45cd42400 100644 --- a/libsrc/atari/save_area.s +++ b/libsrc/atari/save_area.s @@ -13,16 +13,12 @@ .export APPMHI_save .export RAMTOP_save .export PORTB_save -.export ZP_CIOV_save -.export ZP_SIOV_save .segment "SAVEAREA" SAVMSC_save: .res 2 MEMTOP_save: .res 2 APPMHI_save: .res 2 -ZP_CIOV_save: .res 3 -ZP_SIOV_save: .res 3 RAMTOP_save: .res 1 PORTB_save: .res 1 diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 673d33490..dd8b2c0da 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -74,18 +74,6 @@ sramprep: sta APPMHI_save+1 lda PORTB sta PORTB_save - lda CIOV ; zero-page wrapper - sta ZP_CIOV_save - lda CIOV+1 - sta ZP_CIOV_save+1 - lda CIOV+2 - sta ZP_CIOV_save+2 - lda SIOV ; zero-page wrapper - sta ZP_SIOV_save - lda SIOV+1 - sta ZP_SIOV_save+1 - lda SIOV+2 - sta ZP_SIOV_save+2 ; disable BASIC From e0c8c7dcb15551df2fd0d17ff2d4097e6b2dbc68 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 9 Sep 2013 17:03:40 -0400 Subject: [PATCH 081/144] Added a cbm510 lightpen driver. It's similar to the current c64 and c128 lightpen drivers. --- asminc/cbm510.inc | 6 + include/cbm510.h | 3 +- libsrc/cbm510/mou/cbm510-170c.s | 442 ++++++++++++++++++++++++++++++++ libsrc/cbm510/pencalib.c | 94 +++++++ 4 files changed, 544 insertions(+), 1 deletion(-) create mode 100644 libsrc/cbm510/mou/cbm510-170c.s create mode 100755 libsrc/cbm510/pencalib.c diff --git a/asminc/cbm510.inc b/asminc/cbm510.inc index dfeee1d4e..abc363728 100644 --- a/asminc/cbm510.inc +++ b/asminc/cbm510.inc @@ -23,6 +23,9 @@ YSIZE = 25 ;----------------------------------------------------------------------------- ; I/O Definitions +; Note: These numbers aren't addresses. They are offsets from the start of +; each chip's register set. They are used in the indirect indexed addressing +; mode. ; I/O $d800: VIC-II @@ -66,6 +69,9 @@ VIC_CTRL2 = $16 VIC_HLINE = $12 +VIC_LPEN_X = $13 +VIC_LPEN_Y = $14 + VIC_VIDEO_ADR = $18 VIC_IRR = $19 ; Interrupt request register diff --git a/include/cbm510.h b/include/cbm510.h index 797b2c4fa..b6c8892b1 100644 --- a/include/cbm510.h +++ b/include/cbm510.h @@ -118,7 +118,8 @@ /* The addresses of the static drivers */ -extern void cbm510_joy_mou[]; /* Referred to by mouse_static_stddrv[] */ +extern void cbm510_170c_mou[]; +extern void cbm510_joy_mou[]; /* Referred to by mouse_static_stddrv[] */ extern void cbm510_ram_emd[]; extern void cbm510_std_joy[]; /* Referred to by joy_static_stddrv[] */ extern void cbm510_std_ser[]; diff --git a/libsrc/cbm510/mou/cbm510-170c.s b/libsrc/cbm510/mou/cbm510-170c.s new file mode 100644 index 000000000..bf10cd24b --- /dev/null +++ b/libsrc/cbm510/mou/cbm510-170c.s @@ -0,0 +1,442 @@ +; +; Driver for the Inkwell Systems 170-C lightpen. +; +; 2013-09-05, Greg King +; + + .include "zeropage.inc" + .include "../extzp.inc" + + .include "mouse-kernel.inc" + .include "cbm510.inc" + + .macpack generic + +; ------------------------------------------------------------------------ +; Header. Includes jump table. + +.segment "JUMPTABLE" + +HEADER: + +; Driver signature + + .byte $6d, $6f, $75 ; ASCII "mou" + .byte MOUSE_API_VERSION ; Mouse driver API version number + +; Library reference + +LIBREF: .addr $0000 + +; Jump table + + .addr INSTALL + .addr UNINSTALL + .addr HIDE + .addr SHOW + .addr SETBOX + .addr GETBOX + .addr MOVE + .addr BUTTONS + .addr POS + .addr INFO + .addr IOCTL + .addr IRQ + +; Mouse driver flags + + .byte MOUSE_FLAG_EARLY_IRQ + +; Callback table, set by the kernel before INSTALL is called. + +CHIDE: jmp $0000 ; Hide the cursor +CSHOW: jmp $0000 ; Show the cursor +CMOVEX: jmp $0000 ; Move the cursor to X co-ord. +CMOVEY: jmp $0000 ; Move the cursor to Y co-ord. + + +;---------------------------------------------------------------------------- +; Constants + +SCREEN_WIDTH = XSIZE * 8 +SCREEN_HEIGHT = YSIZE * 8 + +;---------------------------------------------------------------------------- +; Global variables. The bounding box values are sorted so that they can be +; written with the least effort in the SETBOX and GETBOX routines; so, don't +; re-order them. + +.rodata + +; Default values for below variables +; (We use ".proc" because we want to define both a label and a scope.) + +.proc DefVars + .word 0 ; XMin + .word 0 ; YMin + .word SCREEN_WIDTH - 1 ; XMax + .word SCREEN_HEIGHT - 1 ; YMax +.endproc + +.bss + +Vars: +XMin: .res 2 ; X1 value of bounding box +YMin: .res 2 ; Y1 value of bounding box +XMax: .res 2 ; X2 value of bounding box +YMax: .res 2 ; Y2 value of bounding box + +XPos: .res 2 ; Current lightpen position, X +YPos: .res 2 ; Current lightpen position, Y + +OldPenX: .res 1 ; Previous HW-counter values +OldPenY: .res 1 + +.data + +; Default Inkwell calibration. +; The first number is the width of the left border; +; the second number is the actual calibration value. + +XOffset: .byte (24 + 24) / 2 ; x-offset + +; Jump to a function that puts a new calibration value into XOffset. +Calibrate: jmp $0000 + + +.code + +;---------------------------------------------------------------------------- +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present. +; Must return a MOUSE_ERR_xx code in .XA. + +INSTALL: + +; Initiate variables. Just copy the default stuff over. + + ldx #.sizeof (DefVars) - 1 +@L0: lda DefVars,x + sta Vars,x + dex + bpl @L0 + + ldx #15 ; Change to system bank + stx IndReg + ldy #VIC_LPEN_X + lda (vic),y + sta OldPenX + ldy #VIC_LPEN_Y + lda (vic),y + sta OldPenY + ldx ExecReg ; Change back to execution bank + stx IndReg + +; Call a calibration function through the library-reference. + + lda LIBREF + ldx LIBREF+1 + sta ptr1 ; Point to mouse_adjuster + stx ptr1+1 + ldy #1 + lda (ptr1),y + bze @L1 ; Don't call pointer if it's NULL + sta Calibrate+2 ; Point to function + dey + lda (ptr1),y + sta Calibrate+1 + lda #XOffset + jsr Calibrate + +; Be sure that the lightpen cursor is invisible and at the default location. +; It needs to be done here because the lightpen interrupt handler doesn't +; set the lightpen position if it hasn't changed. + +@L1: sei + jsr CHIDE + + lda #<(SCREEN_HEIGHT / 2) + ldx #>(SCREEN_HEIGHT / 2) + jsr MoveY + lda #<(SCREEN_WIDTH / 2) + ldx #>(SCREEN_WIDTH / 2) + jsr MoveX + cli + +; Done, return zero. + + lda #MOUSE_ERR_OK + tax + rts + +;---------------------------------------------------------------------------- +; UNINSTALL routine. Is called before the driver is removed from memory. +; No return code required (the driver is removed from memory on return). + +UNINSTALL := HIDE ; Hide cursor on exit + +;---------------------------------------------------------------------------- +; HIDE routine. Is called to hide the lightpen pointer. The mouse kernel manages +; a counter for calls to show/hide, and the driver entry point is called only +; if the mouse is currently visible, and should get hidden. For most drivers, +; no special action is required besides hiding the lightpen cursor. +; No return code required. + +HIDE: sei + jsr CHIDE + cli + rts + +;---------------------------------------------------------------------------- +; SHOW routine. Is called to show the lightpen pointer. The mouse kernel manages +; a counter for calls to show/hide, and the driver entry point is called only +; if the mouse is currently hidden, and should become visible. For most drivers, +; no special action is required besides enabling the lightpen cursor. +; No return code required. + +SHOW: sei + jsr CSHOW + cli + rts + +;---------------------------------------------------------------------------- +; SETBOX: Set the lightpen bounding box. The parameters are passed as they come +; from the C program, that is, a pointer to a mouse_box struct in .XA. +; No checks are done if the lightpen is currently inside the box, that is the job +; of the caller. It is not necessary to validate the parameters; trust the +; caller; and, save some code here. No return code required. + +SETBOX: sta ptr1 + stx ptr1+1 ; Save data pointer + + ldy #.sizeof (MOUSE_BOX) - 1 + sei + +@L1: lda (ptr1),y + sta XMin,y + dey + bpl @L1 + + cli + rts + +;---------------------------------------------------------------------------- +; GETBOX: Return the lightpen bounding box. The parameters are passed as they +; come from the C program, that is, a pointer to a mouse_box struct in .XA. + +GETBOX: sta ptr1 + stx ptr1+1 ; Save data pointer + + ldy #.sizeof (MOUSE_BOX) - 1 +@L1: lda XMin,y + sta (ptr1),y + dey + bpl @L1 + rts + +;---------------------------------------------------------------------------- +; MOVE: Move the mouse to a new position. The position is passed as it comes +; from the C program, that is: X on the stack and Y in .XA. The C wrapper will +; remove the parameter from the stack on return. +; No checks are done if the new position is valid (within the bounding box or +; the screen). No return code required. +; + +MOVE: sei ; No interrupts + jsr MoveY + + ldy #$01 + lda (sp),y + tax + dey + lda (sp),y + jsr MoveX ; Move the cursor + + cli ; Allow interrupts + rts + +;---------------------------------------------------------------------------- +; BUTTONS: Return the button mask in .XA. + +BUTTONS: + ldx #15 ; To system bank + stx IndReg + ldy #CIA::PRB + lda (cia2),y ; Read joystick inputs + ldx ExecReg ; Back to execution bank + stx IndReg + +; Joystick 1, directions in bits 3-0. +; Make the lightpen button look like a 1351 mouse. + + asl a ; Move joystick-left bit ... + asl a ; ... to fire-button bit + eor #MOUSE_BTN_LEFT + and #MOUSE_BTN_LEFT + ldx #>0 + rts + +;---------------------------------------------------------------------------- +; POS: Return the lightpen position in the MOUSE_POS struct pointed to by ptr1. +; No return code required. + +POS: ldy #MOUSE_POS::XCOORD ; Structure offset + + sei ; Disable interrupts + lda XPos ; Transfer the position + sta (ptr1),y + lda XPos+1 + iny + sta (ptr1),y + lda YPos + iny + sta (ptr1),y + lda YPos+1 + cli ; Enable interrupts + + iny + sta (ptr1),y ; Store last byte + rts + +;---------------------------------------------------------------------------- +; INFO: Returns lightpen position and current button mask in the MOUSE_INFO +; struct pointed to by ptr1. No return code required. +; +; We're cheating here, to keep the code smaller: The first fields of the +; mouse_info struct are identical to the mouse_pos struct; so, we'll just +; call _mouse_pos to initiate the struct pointer, and fill the position +; fields. + +INFO: jsr POS + +; Fill in the button state + + jsr BUTTONS ; Will not touch ptr1 + ldy #MOUSE_INFO::BUTTONS + sta (ptr1),y + rts + +;---------------------------------------------------------------------------- +; IOCTL: Driver-defined entry point. The wrapper will pass a pointer to ioctl- +; specific data in ptr1, and the ioctl code in .A. +; Must return an error code in .XA. +; + +IOCTL: lda #MOUSE_ERR_INV_IOCTL + rts + +;---------------------------------------------------------------------------- +; IRQ: Irq.-handler entry point. Called as a subroutine, but in the IRQ context +; (so, be careful). The routine MUST return carry set if the interrupt has been +; 'handled' -- which means that the interrupt source is gone. Otherwise, it +; MUST return carry clear. +; + +IRQ: ldx #15 ; To system bank + stx IndReg + +; Read the VIC-II lightpen registers. + + ldy #VIC_LPEN_Y + lda (vic),y + cmp OldPenY + +; Skip processing if nothing has changed. + + beq @SkipY + sta OldPenY + ldx ExecReg ; Back to execution bank + stx IndReg + +; Subtract the height of the top border, so that the lightpen co-ordinate +; will match the TGI co-ordinate. + + sub #50 + tay ; Remember low byte + ldx #>0 + +; Limit the Y co-ordinate to the bounding box. + + txa + cpy YMin + sbc YMin+1 + bpl @L3 + ldy YMin + ldx YMin+1 + jmp @L4 + +@L3: txa + cpy YMax + sbc YMax+1 + bmi @L4 + ldy YMax + ldx YMax+1 + +@L4: tya + jsr MoveY + + ldx #15 ; To system bank + stx IndReg +@SkipY: ldy #VIC_LPEN_X + lda (vic),y + ldx ExecReg ; Back to execution bank + stx IndReg + cmp OldPenX + +; Skip processing if nothing has changed. + + beq @SkipX + sta OldPenX + +; Adjust the value by the calibration offset. + + sub XOffset + +; Calculate the new X co-ordinate. +; The VIC-II register is eight bits; but, the screen co-ordinate is nine bits. +; Therefore, the VIC-II number is doubled. Then, it points to every other pixel; +; but, it can reach across the screen. + + asl a + tay ; Remember low byte + lda #>0 + rol a + tax ; Remember high byte + +; Limit the X co-ordinate to the bounding box. + + cpy XMin + sbc XMin+1 + bpl @L1 + ldy XMin + ldx XMin+1 + jmp @L2 + +@L1: txa + cpy XMax + sbc XMax+1 + bmi @L2 + ldy XMax + ldx XMax+1 + +@L2: tya + jsr MoveX + +; Done + +@SkipX: clc ; Interrupt not "handled" + rts + +; Move the lightpen pointer to the new Y pos. + +MoveY: sta YPos + stx YPos+1 + jmp CMOVEY + +; Move the lightpen pointer to the new X pos. + +MoveX: sta XPos + stx XPos+1 + jmp CMOVEX diff --git a/libsrc/cbm510/pencalib.c b/libsrc/cbm510/pencalib.c new file mode 100755 index 000000000..3ff3faf4c --- /dev/null +++ b/libsrc/cbm510/pencalib.c @@ -0,0 +1,94 @@ +/* +** Calibrate lightpen drivers to the current video hardware. +** +** 2013-09-05, Greg King +** +*/ + + +#include +#include +#include + + +#define COMMAND1 "Adjust by clicking on line." +#define COMMAND2 "Finish by clicking off bar." + + +/* +** There is a delay between when the VIC sends its signal, and when the display +** shows that signal. There is another delay between the display and when +** the lightpen says that it saw that signal. Each display and pen is different. +** Therefore, the driver must be calibrated to them. A white bar is painted on +** the screen; and, a line is drawn down the middle of it. When the user clicks +** on that line, the difference between its position and where the VIC thinks +** that the pen is pointing becomes an offset that is subtracted from what the +** VIC sees. +*/ +void __fastcall__ pen_calibrate (unsigned char *XOffset) +{ + unsigned char oldBg = bgcolor (COLOR_BLUE); + unsigned char oldText = textcolor (COLOR_GRAY3); + unsigned char oldRev = revers (1); + unsigned char sprite0Color = peekbsys ((unsigned)&VIC.spr_color[0]); + unsigned char width, width2, height, height4, height8; + struct mouse_info info; + + screensize (&width, &height); + width2 = width / 2; + height4 = height / 4; + height8 = height4 * 8; + + /* Draw a bar and line. */ + + clrscr (); + cclearxy (0, height4, height4 * width); + cvlinexy (width2, height4 + 1, height4 - 2); + revers (0); + + /* Print instructions. */ + + cputsxy (width2 - (sizeof COMMAND1) / 2, height / 2 + 1, COMMAND1); + cputsxy (width2 - (sizeof COMMAND2) / 2, height / 2 + 3, COMMAND2); + + pokebsys ((unsigned)&VIC.spr_color[0], COLOR_GRAY2); + mouse_show (); + mouse_move (width2 * 8, height8 / 2); + + for (;;) { + /* Wait for the main button to be released. */ + + do ; while ((mouse_buttons () & MOUSE_BTN_LEFT)); + + /* Wait for the main button to be pressed. */ + + do { + mouse_info (&info); + } while (!(info.buttons & MOUSE_BTN_LEFT)); + + /* Find out if the pen is on or off the bar. */ + + if (info.pos.y < height8 || info.pos.y >= height8 * 2) { + break; + } + + /* On the bar; adjust the offset. */ + /* Characters are eight pixels wide. + ** The VIC-II sees every other pixel; + ** so, we use half of the difference. + */ + + *XOffset += (info.pos.x - (width2 * 8 + 8/2)) / 2; + } + + /* Off the bar; wait for the main button to be released. */ + + do ; while ((mouse_buttons () & MOUSE_BTN_LEFT)); + + mouse_hide (); + pokebsys ((unsigned)&VIC.spr_color[0], sprite0Color); + revers (oldRev); + textcolor (oldText); + bgcolor (oldBg); + clrscr (); +} From 34c23c4c7d96814176e562622cad6bcdcaefac02 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 9 Sep 2013 17:09:33 -0400 Subject: [PATCH 082/144] Made mousetest.c know that the CBM510 has a lightpen driver. --- samples/mousetest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/mousetest.c b/samples/mousetest.c index e5ee4ca49..7d9409659 100644 --- a/samples/mousetest.c +++ b/samples/mousetest.c @@ -3,7 +3,7 @@ ** Will work for the C64/C128/CBM510/Atari/Apple2. ** ** 2001-09-13, Ullrich von Bassewitz -** 2013-08-23, Greg King +** 2013-09-05, Greg King ** */ @@ -183,7 +183,7 @@ int main (void) ** the value will be put into this file, for the next time. ** (Other drivers will ignore this.) */ -#if defined(__C64__) || defined(__C128__) +#if defined(__C64__) || defined(__C128__) || defined(__CBM510__) pen_adjust ("pen.dat"); #endif From 2b02a03e6c61dbf99b5bd196d68a422db55ae0c7 Mon Sep 17 00:00:00 2001 From: Greg King Date: Tue, 10 Sep 2013 06:47:17 -0400 Subject: [PATCH 083/144] Renamed the CBM510 lightpen driver to include the 184-C pen. --- include/cbm510.h | 2 +- libsrc/cbm510/mou/{cbm510-170c.s => cbm510-inkwl.s} | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) rename libsrc/cbm510/mou/{cbm510-170c.s => cbm510-inkwl.s} (99%) diff --git a/include/cbm510.h b/include/cbm510.h index b6c8892b1..25ea07540 100644 --- a/include/cbm510.h +++ b/include/cbm510.h @@ -118,7 +118,7 @@ /* The addresses of the static drivers */ -extern void cbm510_170c_mou[]; +extern void cbm510_inkwl_mou[]; extern void cbm510_joy_mou[]; /* Referred to by mouse_static_stddrv[] */ extern void cbm510_ram_emd[]; extern void cbm510_std_joy[]; /* Referred to by joy_static_stddrv[] */ diff --git a/libsrc/cbm510/mou/cbm510-170c.s b/libsrc/cbm510/mou/cbm510-inkwl.s similarity index 99% rename from libsrc/cbm510/mou/cbm510-170c.s rename to libsrc/cbm510/mou/cbm510-inkwl.s index bf10cd24b..8502a7034 100644 --- a/libsrc/cbm510/mou/cbm510-170c.s +++ b/libsrc/cbm510/mou/cbm510-inkwl.s @@ -1,5 +1,7 @@ ; -; Driver for the Inkwell Systems 170-C lightpen. +; Driver for the Inkwell Systems 170-C and 184-C lightpens. +; +; This driver reads only the main button on the 184-C. ; ; 2013-09-05, Greg King ; From ebfb4a0b528288e15ba4bedaead53d10cf75e8e5 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 11 Sep 2013 21:53:13 +0200 Subject: [PATCH 084/144] Fix strtoul 'endptr' return value: It should point to the first invalid character, not to the last valid character. --- libsrc/common/strtoul.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/common/strtoul.c b/libsrc/common/strtoul.c index fa0d64f42..54466db36 100644 --- a/libsrc/common/strtoul.c +++ b/libsrc/common/strtoul.c @@ -97,7 +97,7 @@ unsigned long __fastcall__ strtoul (const char* nptr, char** endptr, int base) */ if (endptr) { if (CvtCount > 0) { - *endptr = (char*) S - 1; + *endptr = (char*) S; } else { *endptr = (char*) nptr; } From 5a84da0d4e1f0ca6dabf3f943d6a705912f8914b Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 11 Sep 2013 21:53:13 +0200 Subject: [PATCH 085/144] Fix strtoul 'endptr' return value: It should point to the first invalid character, not to the last valid character. --- libsrc/common/strtoul.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/common/strtoul.c b/libsrc/common/strtoul.c index fa0d64f42..54466db36 100644 --- a/libsrc/common/strtoul.c +++ b/libsrc/common/strtoul.c @@ -97,7 +97,7 @@ unsigned long __fastcall__ strtoul (const char* nptr, char** endptr, int base) */ if (endptr) { if (CvtCount > 0) { - *endptr = (char*) S - 1; + *endptr = (char*) S; } else { *endptr = (char*) nptr; } From 8bc4b4c636c878f02d71a2875840cc340e87a285 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 11 Sep 2013 22:43:35 +0200 Subject: [PATCH 086/144] add code to add free shadow memory to heap (currently disabled) --- cfg/atarixl.cfg | 2 +- libsrc/atari/crt0.s | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 1968ecd8e..493381779 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -41,7 +41,7 @@ MEMORY { CHARGEN: file = "", define = yes, start = $D800, size = $0400; # memory beneath the ROM - RAM_BELOW_ROM: file = "", start = $DC00, size = $FFF0 - $DC00; + RAM_BELOW_ROM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; } SEGMENTS { diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index db8a595e3..eb5de1f40 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -97,6 +97,23 @@ jsr initlib +.if 0 +.if .defined(__ATARIXL__) + .import __heapadd + .import pushax + .import __RAM_BELOW_ROM_START__ + .import __RAM_BELOW_ROM_SIZE__ + .import __RAM_BELOW_ROM_LAST__ + + lda #<__RAM_BELOW_ROM_LAST__ + ldx #>__RAM_BELOW_ROM_LAST__ + jsr pushax + lda #<(__RAM_BELOW_ROM_SIZE__ - (__RAM_BELOW_ROM_LAST__ - __RAM_BELOW_ROM_START__)) + ldx #>(__RAM_BELOW_ROM_SIZE__ - (__RAM_BELOW_ROM_LAST__ - __RAM_BELOW_ROM_START__)) + jsr __heapadd +.endif +.endif + ; Set left margin to 0 lda LMARGN From 387f6e9b2194e080596337a69cc7d49cea170e97 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 11 Sep 2013 22:45:41 +0200 Subject: [PATCH 087/144] Check whether double buffering ('bounce buffering') is needed and only do it if needed. --- libsrc/atari/shadow_ram_handlers.s | 214 ++++++++++++++++++++++++++++- 1 file changed, 210 insertions(+), 4 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 56ddc76c3..adf9085b1 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -5,6 +5,7 @@ ; DEBUG = 1 +CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) .if .defined(__ATARIXL__) @@ -176,6 +177,10 @@ my_RESET_han: ; one filename, terminated by "invalid character", located at ICBAL/ICBAH CIO_filename: +.if CHKBUF + jsr chk_CIO_buf_fn + bcc CIO_call_a +.endif jsr setup_zpptr1_y0 jsr copy_filename CIO_fn_cont: @@ -193,6 +198,10 @@ CIO_fn_cont: ; two filenames, terminated and separated by "invalid character", located at ICBAL/ICBAH CIO_filename2: +.if CHKBUF + jsr chk_CIO_buf_fn2 + bcc CIO_call_a +.endif jsr setup_zpptr1_y0 jsr copy_filename iny @@ -271,7 +280,10 @@ CIO_read: ora ICBLH,x beq CIO_call_a ; special I/O through A register in case buffer length is 0 -; @@@ TODO: check if bounce buffer is really needed because buffer is in ROM area +.if CHKBUF + jsr chk_CIO_buf + bcc CIO_call_a +.endif ; If the data length is larger than our bounce buffer, we have to split the request into smaller ones. ; Otherwise we can get away with one call and a copy to the final destination afterwards. @@ -431,7 +443,10 @@ CIO_write: ora ICBLH,x beq CIO_call_a_jmp ; special I/O through A register in case buffer length is 0 -; @@@ TODO: check if bounce buffer is really needed because buffer is in ROM area +.if CHKBUF + jsr chk_CIO_buf + bcc CIO_call_a_jmp +.endif ; If the data length is larger than our bounce buffer, we have to split the request into smaller ones. ; Otherwise we can get away with a copy to the bounce buffer and the call. @@ -691,6 +706,125 @@ setup_zpptr1: sta zpptr1+1 rts + +.if CHKBUF + +; get length of file name pointed to by 'zpptr1' +; input: Y - index into file name +; output: Y - length +; A - destroyed +get_fn_len: + lda (zpptr1),y + beq @done + iny + cmp #ATEOL + bne get_fn_len + dey +@done: + rts + + +chk_CIO_buf_fn2: + tya + pha + lda ICBLL,x + pha + lda ICBLH,x + pha + jsr setup_zpptr1_y0 + jsr get_fn_len + iny ; include terminating zero + bne fn_cont + +chk_CIO_buf_fn: + tya + pha + lda ICBLL,x + pha + lda ICBLH,x + pha + jsr setup_zpptr1_y0 +fn_cont:jsr get_fn_len + iny ; include terminating zero + tya + sta ICBLL,x + lda #0 + sta ICBLH,x + jsr chk_CIO_buf + pla + sta ICBLH,x + pla + sta ICBLL,x + pla + tay + rts + + +; check if a CIO input/output buffer overlaps with ROM area (>= $C000) +; input: X - IOCB index +; ICBAL/ICBAH/ICBLL/ICBLH - buffer address and length +; output: CF - 1/0 for overlap/no overlap +; A - destroyed + +chk_CIO_buf: + lda ICBAH,x + cmp #$c0 + bcc @cont +@ret: +.ifdef DEBUG + jsr CIO_buf_noti +.endif + rts + +@cont: lda ICBAL,x + clc + adc ICBLL,x + lda ICBAH,x + adc ICBLH,x + bcs @ret ; ??? wraparound + cmp #$c0 +.ifdef DEBUG + jsr CIO_buf_noti +.endif + rts + +.ifdef DEBUG +; write to screen memory on 2nd line: +; pos 0: # of accesses without buffering +; pos 1: # of accesses with buffering +CIO_buf_noti: + php + pha + tya + pha + bcc @nobuf + + inc CIObnval_dobuf + jmp @cont + +@nobuf: inc CIObnval_nobuf + +@cont: ldy #40 + lda CIObnval_nobuf + sta (SAVMSC),y + ldy #41 + lda CIObnval_dobuf + sta (SAVMSC),y + + pla + tay + pla + plp + rts + +CIObnval_dobuf: + .byte 0 +CIObnval_nobuf: + .byte 0 +.endif + +.endif ; .if CHKBUF + ;--------------------------------------------------------- ; SIO handler @@ -737,7 +871,10 @@ SIO_call: SIO_read: -; @@@ TODO: check if bounce buffer is really needed because buffer is in ROM area +.if CHKBUF + jsr chk_SIO_buf + bcc SIO_call +.endif ; we only support transfers <= bounce buffer size jsr cmp_sio_len_bnc_bufsz @@ -786,7 +923,10 @@ sio_read_ret: SIO_write: -; @@@ TODO: check if bounce buffer is really needed because buffer is in ROM area +.if CHKBUF + jsr chk_SIO_buf + bcc SIO_call +.endif ; we only support transfers <= bounce buffer size jsr cmp_sio_len_bnc_bufsz @@ -857,6 +997,72 @@ orgbuf_to_dbuf: rts +.if CHKBUF + +; check if a SIO input/output buffer overlaps with ROM area (>= $C000) +; input: DBUFLO/DBUFHI/DBYTLO/DBYTHI - buffer address and length +; output: CF - 1/0 for overlap/no overlap +; A - destroyed + +chk_SIO_buf: + lda DBUFHI + cmp #$c0 + bcc @cont +@ret: +.ifdef DEBUG + jsr SIO_buf_noti +.endif + rts + +@cont: lda DBUFLO + clc + adc DBYTLO + lda DBUFHI + adc DBYTHI + bcs @ret ; ??? wraparound + cmp #$c0 +.ifdef DEBUG + jsr SIO_buf_noti +.endif + rts + +.ifdef DEBUG +; write to screen memory on 2nd line: +; pos 38: # of accesses without buffering +; pos 39: # of accesses with buffering +SIO_buf_noti: + php + pha + tya + pha + bcc @nobuf + + inc SIObnval_dobuf + jmp @cont + +@nobuf: inc SIObnval_nobuf + +@cont: ldy #78 + lda SIObnval_nobuf + sta (SAVMSC),y + ldy #79 + lda SIObnval_dobuf + sta (SAVMSC),y + + pla + tay + pla + plp + rts + +SIObnval_dobuf: + .byte 0 +SIObnval_nobuf: + .byte 0 +.endif + +.endif ; .if CHKBUF + ;--------------------------------------------------------- KEYBDV_handler: From 5a1dcbbe4c1b32eb42db7c622747954582a4ee0c Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 11 Sep 2013 23:59:24 +0200 Subject: [PATCH 088/144] Reduce flicker by waiting for horizontal retrace before switching ROM and CHARGEN. Can be disabled by setting USEWSYNC to 0. --- libsrc/atari/shadow_ram_handlers.s | 101 ++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 31 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index adf9085b1..e9b682cf1 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -5,6 +5,7 @@ ; DEBUG = 1 +USEWSYNC= 1 CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) .if .defined(__ATARIXL__) @@ -24,7 +25,22 @@ CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always don BUFSZ = 128 ; bounce buffer size BUFSZ_SIO = 256 +.macro wsync +.if USEWSYNC + sta WSYNC +.endif +.endmacro + .macro disable_rom + lda PORTB + and #$fe + wsync + sta PORTB + lda #>__CHARGEN_START__ + sta CHBAS + sta CHBASE +.endmacro +.macro disable_rom_quick lda PORTB and #$fe sta PORTB @@ -32,7 +48,25 @@ BUFSZ_SIO = 256 sta CHBAS sta CHBASE .endmacro +.macro disable_rom_val val + lda val + wsync + sta PORTB + lda #>__CHARGEN_START__ + sta CHBAS + sta CHBASE +.endmacro + .macro enable_rom + lda PORTB + ora #1 + wsync + sta PORTB + lda #$E0 + sta CHBAS + sta CHBASE +.endmacro +.macro enable_rom_quick lda PORTB ora #1 sta PORTB @@ -48,9 +82,9 @@ BUFSZ_SIO = 256 sram_init: ; disable all interrupts - sei ldx #0 stx NMIEN ; disable NMI + sei ; disable ROMs disable_rom @@ -72,9 +106,9 @@ sram_init: sta $fffb ; enable interrupts + cli lda #$40 sta NMIEN - cli rts @@ -104,14 +138,14 @@ bounce_buffer: .res BUFSZ_SIO .macro int_wrap orgvec .local ret pha - enable_rom + enable_rom_quick lda #>ret pha lda # Date: Thu, 12 Sep 2013 00:04:51 +0200 Subject: [PATCH 089/144] testcode/lib/tinyshell.c: add 'verbose' and 'cls' commands; add SP check --- testcode/lib/tinyshell.c | 75 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/testcode/lib/tinyshell.c b/testcode/lib/tinyshell.c index f4a18126b..c325f3947 100644 --- a/testcode/lib/tinyshell.c +++ b/testcode/lib/tinyshell.c @@ -5,12 +5,15 @@ #define VERSION_ASC "0.90" -#define KEYB_BUFSZ 80 -#define PROMPT ">>> " #ifdef __ATARI__ #define UPPERCASE /* define (e.g. for Atari) to convert filenames etc. to upper case */ #endif +#define CHECK_SP + +#define KEYB_BUFSZ 80 +#define PROMPT ">>> " + #include #include #include @@ -26,6 +29,10 @@ #include #include +#ifdef CHECK_SP +extern unsigned int getsp(void); /* comes from getsp.s */ +#endif + #define CMD_NOTHING 0 #define CMD_INVALID 1 #define CMD_HELP 2 @@ -38,7 +45,10 @@ #define CMD_RENAME 9 #define CMD_COPY 10 #define CMD_PWD 11 +#define CMD_CLS 12 +#define CMD_VERBOSE 13 +static unsigned char verbose; static unsigned char terminate; static unsigned char cmd; static unsigned char *cmd_asc, *arg1, *arg2, *arg3; @@ -68,6 +78,10 @@ struct cmd_table { { "mv", CMD_RENAME }, { "ren", CMD_RENAME }, { "pwd", CMD_PWD }, +#ifdef __CC65__ + { "cls", CMD_CLS }, +#endif + { "verbose", CMD_VERBOSE }, { NULL, 0 } }; @@ -82,6 +96,22 @@ static void get_command(void) { unsigned char i = 0; +#ifdef CHECK_SP + static char firstcall = 1; + static unsigned int good_sp; + unsigned int sp; + if (firstcall) + sp = good_sp = getsp(); + else + sp = getsp(); + + if (sp != good_sp) { + printf("SP: 0x%04X ***MISMATCH*** 0x%04X\n", sp, good_sp); + } + else if (verbose) + printf("SP: 0x%04X\n", sp); +#endif + arg1 = arg2 = arg3 = NULL; /* issue prompt */ @@ -132,6 +162,10 @@ static void cmd_help(void) puts("cd, chdir - change directory or drive"); puts("md, mkdir - make directory or drive"); puts("rd, rmdir - remove directory or drive"); +#ifdef __CC65__ + puts("cls - clear screen"); +#endif + puts("verbose - set verbosity level"); puts("sorry, you cannot start programs here"); } @@ -173,6 +207,8 @@ static void cmd_ls(void) else arg = "."; + if (verbose) + printf("Buffer addr: %p\n", arg); dir = opendir(arg); #ifdef __ATARI__ if (need_free) free(arg); @@ -262,6 +298,8 @@ static void cmd_pwd(void) printf("malloc %u bytes failed: %s\n", MAXPATHLEN, strerror(errno)); return; } + if (verbose) + printf("Buffer addr: %p\n", buf); if (!getcwd(buf, MAXPATHLEN)) { printf("getcwd failed: %s\n", strerror(errno)); free(buf); @@ -309,6 +347,8 @@ static void cmd_copy(void) printf("malloc %u bytes failed: %s\n", cpbuf_sz, strerror(errno)); return; } + if (verbose) + printf("Buffer addr: %p\n", buf); while (1) { if (srcfd == -1) { @@ -349,6 +389,33 @@ static void cmd_copy(void) if (dstfd >= 0) close(dstfd); } +#ifdef __CC65__ +static void cmd_cls(void) +{ + printf("\f"); +} +#endif + +static void cmd_verbose(void) +{ + unsigned long verb; + char *endptr; + + if (!arg1 || arg2) { + puts("usage: verbose "); + return; + } + + verb = strtoul(arg1, &endptr, 10); + if (verb > 255 || *endptr) { + printf("invalid verbosity level 0x%x\n", *endptr); + return; + } + + verbose = verb; + printf("verbosity level set to %d\n", verbose); +} + static void run_command(void) { switch (cmd) { @@ -365,6 +432,10 @@ static void run_command(void) case CMD_PWD: cmd_pwd(); return; case CMD_RENAME: cmd_rename(); return; case CMD_COPY: cmd_copy(); return; +#ifdef __CC65__ + case CMD_CLS: cmd_cls(); return; +#endif + case CMD_VERBOSE: cmd_verbose(); return; } } From 39e5bd0c18a347a5974d7800b640b61325ac294d Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 12 Sep 2013 00:04:51 +0200 Subject: [PATCH 090/144] testcode/lib/tinyshell.c: add 'verbose' and 'cls' commands; add SP check --- testcode/lib/tinyshell.c | 75 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/testcode/lib/tinyshell.c b/testcode/lib/tinyshell.c index f4a18126b..c325f3947 100644 --- a/testcode/lib/tinyshell.c +++ b/testcode/lib/tinyshell.c @@ -5,12 +5,15 @@ #define VERSION_ASC "0.90" -#define KEYB_BUFSZ 80 -#define PROMPT ">>> " #ifdef __ATARI__ #define UPPERCASE /* define (e.g. for Atari) to convert filenames etc. to upper case */ #endif +#define CHECK_SP + +#define KEYB_BUFSZ 80 +#define PROMPT ">>> " + #include #include #include @@ -26,6 +29,10 @@ #include #include +#ifdef CHECK_SP +extern unsigned int getsp(void); /* comes from getsp.s */ +#endif + #define CMD_NOTHING 0 #define CMD_INVALID 1 #define CMD_HELP 2 @@ -38,7 +45,10 @@ #define CMD_RENAME 9 #define CMD_COPY 10 #define CMD_PWD 11 +#define CMD_CLS 12 +#define CMD_VERBOSE 13 +static unsigned char verbose; static unsigned char terminate; static unsigned char cmd; static unsigned char *cmd_asc, *arg1, *arg2, *arg3; @@ -68,6 +78,10 @@ struct cmd_table { { "mv", CMD_RENAME }, { "ren", CMD_RENAME }, { "pwd", CMD_PWD }, +#ifdef __CC65__ + { "cls", CMD_CLS }, +#endif + { "verbose", CMD_VERBOSE }, { NULL, 0 } }; @@ -82,6 +96,22 @@ static void get_command(void) { unsigned char i = 0; +#ifdef CHECK_SP + static char firstcall = 1; + static unsigned int good_sp; + unsigned int sp; + if (firstcall) + sp = good_sp = getsp(); + else + sp = getsp(); + + if (sp != good_sp) { + printf("SP: 0x%04X ***MISMATCH*** 0x%04X\n", sp, good_sp); + } + else if (verbose) + printf("SP: 0x%04X\n", sp); +#endif + arg1 = arg2 = arg3 = NULL; /* issue prompt */ @@ -132,6 +162,10 @@ static void cmd_help(void) puts("cd, chdir - change directory or drive"); puts("md, mkdir - make directory or drive"); puts("rd, rmdir - remove directory or drive"); +#ifdef __CC65__ + puts("cls - clear screen"); +#endif + puts("verbose - set verbosity level"); puts("sorry, you cannot start programs here"); } @@ -173,6 +207,8 @@ static void cmd_ls(void) else arg = "."; + if (verbose) + printf("Buffer addr: %p\n", arg); dir = opendir(arg); #ifdef __ATARI__ if (need_free) free(arg); @@ -262,6 +298,8 @@ static void cmd_pwd(void) printf("malloc %u bytes failed: %s\n", MAXPATHLEN, strerror(errno)); return; } + if (verbose) + printf("Buffer addr: %p\n", buf); if (!getcwd(buf, MAXPATHLEN)) { printf("getcwd failed: %s\n", strerror(errno)); free(buf); @@ -309,6 +347,8 @@ static void cmd_copy(void) printf("malloc %u bytes failed: %s\n", cpbuf_sz, strerror(errno)); return; } + if (verbose) + printf("Buffer addr: %p\n", buf); while (1) { if (srcfd == -1) { @@ -349,6 +389,33 @@ static void cmd_copy(void) if (dstfd >= 0) close(dstfd); } +#ifdef __CC65__ +static void cmd_cls(void) +{ + printf("\f"); +} +#endif + +static void cmd_verbose(void) +{ + unsigned long verb; + char *endptr; + + if (!arg1 || arg2) { + puts("usage: verbose "); + return; + } + + verb = strtoul(arg1, &endptr, 10); + if (verb > 255 || *endptr) { + printf("invalid verbosity level 0x%x\n", *endptr); + return; + } + + verbose = verb; + printf("verbosity level set to %d\n", verbose); +} + static void run_command(void) { switch (cmd) { @@ -365,6 +432,10 @@ static void run_command(void) case CMD_PWD: cmd_pwd(); return; case CMD_RENAME: cmd_rename(); return; case CMD_COPY: cmd_copy(); return; +#ifdef __CC65__ + case CMD_CLS: cmd_cls(); return; +#endif + case CMD_VERBOSE: cmd_verbose(); return; } } From f39cb2fb73a94c4177e5467600360476dc01062f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 12 Sep 2013 00:16:09 +0200 Subject: [PATCH 091/144] testcode/lib/tinyshell.c: fix error message --- testcode/lib/tinyshell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcode/lib/tinyshell.c b/testcode/lib/tinyshell.c index c325f3947..90fda52fd 100644 --- a/testcode/lib/tinyshell.c +++ b/testcode/lib/tinyshell.c @@ -408,7 +408,7 @@ static void cmd_verbose(void) verb = strtoul(arg1, &endptr, 10); if (verb > 255 || *endptr) { - printf("invalid verbosity level 0x%x\n", *endptr); + puts("invalid verbosity level"); return; } From 619de8b31470f8b54844d00df86a39a9ef25046e Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 12 Sep 2013 00:16:09 +0200 Subject: [PATCH 092/144] testcode/lib/tinyshell.c: fix error message --- testcode/lib/tinyshell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcode/lib/tinyshell.c b/testcode/lib/tinyshell.c index c325f3947..90fda52fd 100644 --- a/testcode/lib/tinyshell.c +++ b/testcode/lib/tinyshell.c @@ -408,7 +408,7 @@ static void cmd_verbose(void) verb = strtoul(arg1, &endptr, 10); if (verb > 255 || *endptr) { - printf("invalid verbosity level 0x%x\n", *endptr); + puts("invalid verbosity level"); return; } From d488272357198c02c3d63bcc7c6a3105f40b9fdd Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 12 Sep 2013 12:32:59 +0200 Subject: [PATCH 093/144] testcode/lib/tinyshell.c: Enable SP check only for CC65 targets. Enable 'cls' command only for Atari. Enable subdirectory commands only for Atari and non-CC65 targets. --- testcode/lib/tinyshell.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/testcode/lib/tinyshell.c b/testcode/lib/tinyshell.c index 90fda52fd..f3b6aa769 100644 --- a/testcode/lib/tinyshell.c +++ b/testcode/lib/tinyshell.c @@ -7,9 +7,9 @@ #ifdef __ATARI__ #define UPPERCASE /* define (e.g. for Atari) to convert filenames etc. to upper case */ -#endif - #define CHECK_SP +#define HAVE_SUBDIRS +#endif #define KEYB_BUFSZ 80 #define PROMPT ">>> " @@ -22,6 +22,7 @@ #ifndef __CC65__ #include #include +#define HAVE_SUBDIRS #else #define MAXPATHLEN 64 #endif @@ -66,11 +67,13 @@ struct cmd_table { { "ls", CMD_LS }, { "dir", CMD_LS }, { "md", CMD_MKDIR }, +#ifdef HAVE_SUBDIRS { "mkdir", CMD_MKDIR }, { "rd", CMD_RMDIR }, { "rmdir", CMD_RMDIR }, { "cd", CMD_CHDIR }, { "chdir", CMD_CHDIR }, +#endif { "rm", CMD_RM }, { "del", CMD_RM }, { "cp", CMD_COPY }, @@ -78,7 +81,7 @@ struct cmd_table { { "mv", CMD_RENAME }, { "ren", CMD_RENAME }, { "pwd", CMD_PWD }, -#ifdef __CC65__ +#ifdef __ATARI__ { "cls", CMD_CLS }, #endif { "verbose", CMD_VERBOSE }, @@ -162,7 +165,7 @@ static void cmd_help(void) puts("cd, chdir - change directory or drive"); puts("md, mkdir - make directory or drive"); puts("rd, rmdir - remove directory or drive"); -#ifdef __CC65__ +#ifdef __ATARI__ puts("cls - clear screen"); #endif puts("verbose - set verbosity level"); @@ -239,6 +242,8 @@ static void cmd_rm(void) printf("remove failed: %s\n", strerror(errno)); } +#ifdef HAVE_SUBDIRS + static void cmd_mkdir(void) { if (!arg1 || arg2) { @@ -310,6 +315,8 @@ static void cmd_pwd(void) free(buf); } +#endif /* #ifdef HAVE_SUBDIRS */ + static void cmd_rename(void) { if (!arg2 || arg3) { @@ -389,7 +396,7 @@ static void cmd_copy(void) if (dstfd >= 0) close(dstfd); } -#ifdef __CC65__ +#ifdef __ATARI__ static void cmd_cls(void) { printf("\f"); @@ -426,13 +433,15 @@ static void run_command(void) case CMD_QUIT: terminate = 1; return; case CMD_LS: cmd_ls(); return; case CMD_RM: cmd_rm(); return; +#ifdef HAVE_SUBDIRS case CMD_CHDIR: cmd_chdir(); return; case CMD_MKDIR: cmd_mkdir(); return; case CMD_RMDIR: cmd_rmdir(); return; case CMD_PWD: cmd_pwd(); return; +#endif case CMD_RENAME: cmd_rename(); return; case CMD_COPY: cmd_copy(); return; -#ifdef __CC65__ +#ifdef __ATARI__ case CMD_CLS: cmd_cls(); return; #endif case CMD_VERBOSE: cmd_verbose(); return; From 2051adeb4de999a7fdceb9c59fe043da68737092 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 12 Sep 2013 12:38:20 +0200 Subject: [PATCH 094/144] Fix strtol 'endptr' return value. --- libsrc/common/strtol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/common/strtol.c b/libsrc/common/strtol.c index b7ccdf24c..f3ce08a35 100644 --- a/libsrc/common/strtol.c +++ b/libsrc/common/strtol.c @@ -102,7 +102,7 @@ long __fastcall__ strtol (const char* nptr, char** endptr, int base) */ if (endptr) { if (CvtCount > 0) { - *endptr = (char*) S - 1; + *endptr = (char*) S; } else { *endptr = (char*) nptr; } From bd2b2e0f7d2782fdd1a71a426f890ef95596ec13 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 12 Sep 2013 13:04:55 +0200 Subject: [PATCH 095/144] Fix last change: Stack check for all CC65 targets. Enable subdirectories on Apple 2. --- testcode/lib/tinyshell.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/testcode/lib/tinyshell.c b/testcode/lib/tinyshell.c index f3b6aa769..141065257 100644 --- a/testcode/lib/tinyshell.c +++ b/testcode/lib/tinyshell.c @@ -7,10 +7,17 @@ #ifdef __ATARI__ #define UPPERCASE /* define (e.g. for Atari) to convert filenames etc. to upper case */ -#define CHECK_SP #define HAVE_SUBDIRS #endif +#ifdef __APPLE2__ +#define HAVE_SUBDIRS +#endif + +#ifdef __CC65__ +#define CHECK_SP +#endif + #define KEYB_BUFSZ 80 #define PROMPT ">>> " From 237bb9850c611f8f40b0fba26ccec62e7a02c857 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 13 Sep 2013 16:00:56 +0200 Subject: [PATCH 096/144] Remove obsolete ZPSAVE segment. --- cfg/atari-overlay.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg index 02becd29b..6ccb5f602 100644 --- a/cfg/atari-overlay.cfg +++ b/cfg/atari-overlay.cfg @@ -29,7 +29,6 @@ SEGMENTS { CODE: load = RAM, type = ro, define = yes; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; From fbabf960caa4fc96a0b77ba75a1a7e683340a301 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 13 Sep 2013 16:00:56 +0200 Subject: [PATCH 097/144] Remove obsolete ZPSAVE segment. --- cfg/atari-overlay.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg index 02becd29b..6ccb5f602 100644 --- a/cfg/atari-overlay.cfg +++ b/cfg/atari-overlay.cfg @@ -29,7 +29,6 @@ SEGMENTS { CODE: load = RAM, type = ro, define = yes; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; From aac88eac53e3a0dc178a7711741e12f021850de1 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 13 Sep 2013 18:28:17 +0200 Subject: [PATCH 098/144] Use labels instead of segment load addresses to specify entry points in the EXE file. --- libsrc/atari/crt0.s | 4 +++- libsrc/atari/shadow_ram_prepare.s | 2 +- libsrc/atari/system_check.s | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index eb5de1f40..e30d7c07f 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -52,6 +52,8 @@ ; Real entry point: +start: + .if .defined(__ATARIXL__) jsr sram_init .endif @@ -229,4 +231,4 @@ APPMHI_save: .res 2 .segment "AUTOSTRT" .word RUNAD ; defined in atari.inc .word RUNAD+1 - .word __STARTUP_LOAD__ + 1 + .word start diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index dd8b2c0da..78e7ba4f0 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -374,6 +374,6 @@ screen_device_length = * - screen_device .word INITAD .word INITAD+1 - .word __SRPREP_LOAD__ + .word sramprep .endif ; .if .defined(__ATARIXL__) diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index ee7480922..2baa5d19c 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -71,17 +71,17 @@ cont: ldx #0 ; channel 0 .segment "SYSCHK" +; no XL machine +no_xl: print_string "This program needs an XL machine." + jmp fail + syschk: lda $fcd8 ; from ostype.s cmp #$a2 - bne is_xl - -; no XL machine - print_string "This program needs an XL machine." - jmp fail + beq no_xl ; we have an XL machine, now check memory -is_xl: lda RAMSIZ + lda RAMSIZ cmp #$80 bcs sys_ok @@ -148,6 +148,6 @@ loop: dey trailer: .word INITAD .word INITAD+1 - .word __SYSCHK_LOAD__ + .word syschk .endif ; .if .defined(__ATARIXL__) From 5caf6c8854ec2ee27899300a58e092fdf397bfce Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 13 Sep 2013 20:29:24 +0200 Subject: [PATCH 099/144] atarixl linker cfg file cleanups; set default load address to 400 for atarixl --- cfg/atarixl.cfg | 12 +++++++----- libsrc/atari/shadow_ram_handlers.s | 2 +- libsrc/atari/system_check.s | 9 ++++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 493381779..551aa4433 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -1,5 +1,5 @@ FEATURES { - STARTADDRESS: default = $2E00; + STARTADDRESS: default = $2400; } SYMBOLS { @@ -17,7 +17,8 @@ MEMORY { # "system check" load chunk SYSCHKHDR: file = %O, start = $0000, size = $0004; - SYSCHK: file = %O, start = $2E00, size = $0E00; + SYSCHK: file = %O, start = $2E00, size = $0300; + SYSCHKTRL: file = %O, start = $0000, size = $0006; # "shadow RAM preparation" load chunk SRPREPHDR: file = %O, start = $0000, size = $0004; @@ -28,11 +29,11 @@ MEMORY { MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + __SAVEAREA_SIZE__ + - __LOWBUFS_SIZE__, size = $D000 - + __LOWDATA_SIZE__, size = $D000 - __STACKSIZE__ - %S - __SAVEAREA_SIZE__ - - __LOWBUFS_SIZE__; + __LOWDATA_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; @@ -49,10 +50,11 @@ SEGMENTS { SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; SYSCHK: load = SYSCHK, type = rw, define = yes, optional = yes; + SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; SRPREPHDR: load = SRPREPHDR, type = ro; SAVEAREA: load = SRPREP, type = bss, define = yes; # shared btw. SRPREP and RAM - LOWBUFS: load = SRPREP, type = bss, define = yes; + LOWDATA: load = SRPREP, type = bss, define = yes; # " " " " " " " " SRPREP: load = SRPREP, type = rw, define = yes; SHADOW_RAM: load = SRPREP, run = RAM_BELOW_ROM, type = rw, define = yes, optional = yes; SRPREPTRL: load = SRPREPTRL, type = ro; diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index e9b682cf1..0a7e3ef00 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -117,7 +117,7 @@ sram_init: zpptr1: .res 2 -.segment "LOWBUFS" +.segment "LOWDATA" ; bounce buffers for CIO and SIO calls bounce_buffer: .res BUFSZ_SIO diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index 2baa5d19c..b0abc0dc8 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -17,7 +17,7 @@ DEBUG = 1 .export syschk .import __SYSCHK_LOAD__ - .import __SAVEAREA_LOAD__ + .import __SAVEAREA_LOAD__ ; needed by xlmemchk.inc .include "zeropage.inc" .include "atari.inc" @@ -64,7 +64,7 @@ cont: ldx #0 ; channel 0 .segment "SYSCHKHDR" .word __SYSCHK_LOAD__ - .word trailer - 1 + .word end - 1 ; ------------------------------------------------------------------------ ; Actual code @@ -142,10 +142,13 @@ loop: dey .endproc +end: + ; ------------------------------------------------------------------------ ; Chunk "trailer" - sets INITAD -trailer: +.segment "SYSCHKTRL" + .word INITAD .word INITAD+1 .word syschk From 85170998ad45cadb2064fa68349bb3a8975efd89 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 13 Sep 2013 21:47:39 +0200 Subject: [PATCH 100/144] more atarixl linker cfg file cleanups; adapt atarixl-overlay.cfg --- cfg/atarixl-overlay.cfg | 122 +++++++++++++++++++++--------- cfg/atarixl.cfg | 17 +++-- libsrc/atari/shadow_ram_prepare.s | 2 +- libsrc/atari/system_check.s | 3 +- libsrc/atari/xlmemchk.inc | 8 +- 5 files changed, 104 insertions(+), 48 deletions(-) diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 02becd29b..8b408c3a4 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -1,48 +1,100 @@ FEATURES { - STARTADDRESS: default = $2E00; + STARTADDRESS: default = $2400; } + SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __RESERVED_MEMORY__: type = weak, value = $0000; + __STARTADDRESS__: type = export, value = %S; + syschk: type = import; # force inclusion of SYSCHK + sramprep: type = import; # force inclusion of SRPREP } + MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; - HEADER: file = %O, start = $0000, size = $0006; - RAM: file = %O, start = %S + __OVERLAYSIZE__, size = $BC20 - __STACKSIZE__ - __OVERLAYSIZE__ - %S; - TRAILER: file = %O, start = $0000, size = $0006; - OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; - OVL2: file = "%O.2", start = %S, size = __OVERLAYSIZE__; - OVL3: file = "%O.3", start = %S, size = __OVERLAYSIZE__; - OVL4: file = "%O.4", start = %S, size = __OVERLAYSIZE__; - OVL5: file = "%O.5", start = %S, size = __OVERLAYSIZE__; - OVL6: file = "%O.6", start = %S, size = __OVERLAYSIZE__; - OVL7: file = "%O.7", start = %S, size = __OVERLAYSIZE__; - OVL8: file = "%O.8", start = %S, size = __OVERLAYSIZE__; - OVL9: file = "%O.9", start = %S, size = __OVERLAYSIZE__; + ZP: file = "", define = yes, start = $0082, size = $007E; + +# just $FFFF + HEADER: file = %O, start = $0000, size = $0002; + +# "system check" load chunk + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; + SYSCHKTRL: file = %O, start = $0000, size = $0006; + +# "shadow RAM preparation" load chunk + SRPREPHDR: file = %O, start = $0000, size = $0004; + SRPREPCHNK: file = %O, start = %S + __OVERLAYSIZE__, size = $7C20 - %S - __OVERLAYSIZE__ - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned + SRPREPTRL: file = %O, start = $0000, size = $0006; + +# "main program" load chunk + MAINHDR: file = %O, start = $0000, size = $0004; + RAM: file = %O, define = yes, start = %S + + __OVERLAYSIZE__ + + __SAVEAREA_SIZE__ + + __LOWDATA_SIZE__, size = $D000 - + __STACKSIZE__ - + %S - + __OVERLAYSIZE__ - + __SAVEAREA_SIZE__ - + __LOWDATA_SIZE__; + +# defines entry point into program + TRAILER: file = %O, start = $0000, size = $0006; + +# address of relocated character generator + CHARGEN: file = "", define = yes, start = $D800, size = $0400; + +# memory beneath the ROM + HIDDEN_RAM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; + +# overlays + OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; + OVL2: file = "%O.2", start = %S, size = __OVERLAYSIZE__; + OVL3: file = "%O.3", start = %S, size = __OVERLAYSIZE__; + OVL4: file = "%O.4", start = %S, size = __OVERLAYSIZE__; + OVL5: file = "%O.5", start = %S, size = __OVERLAYSIZE__; + OVL6: file = "%O.6", start = %S, size = __OVERLAYSIZE__; + OVL7: file = "%O.7", start = %S, size = __OVERLAYSIZE__; + OVL8: file = "%O.8", start = %S, size = __OVERLAYSIZE__; + OVL9: file = "%O.9", start = %S, size = __OVERLAYSIZE__; } + SEGMENTS { - EXEHDR: load = HEADER, type = ro; - STARTUP: load = RAM, type = ro, define = yes; - LOWCODE: load = RAM, type = ro, define = yes, optional = yes; - INIT: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro, define = yes; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = zp, optional = yes; - AUTOSTRT: load = TRAILER, type = ro; - OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; - OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; - OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; - OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; - OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; - OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; - OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; - OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; - OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; + EXEHDR: load = HEADER, type = ro; + + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; + SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; + + SRPREPHDR: load = SRPREPHDR, type = ro; + SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " + SRPREP: load = SRPREPCHNK, type = rw, define = yes; + SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SRPREPTRL: load = SRPREPTRL, type = ro; + + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; + + OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; + OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; + OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; + OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; + OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; + OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; + OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; + OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; + OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 551aa4433..dd49d421d 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -5,6 +5,7 @@ FEATURES { SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __RESERVED_MEMORY__: type = weak, value = $0000; + __STARTADDRESS__: type = export, value = %S; syschk: type = import; # force inclusion of SYSCHK sramprep: type = import; # force inclusion of SRPREP } @@ -17,12 +18,12 @@ MEMORY { # "system check" load chunk SYSCHKHDR: file = %O, start = $0000, size = $0004; - SYSCHK: file = %O, start = $2E00, size = $0300; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; SYSCHKTRL: file = %O, start = $0000, size = $0006; # "shadow RAM preparation" load chunk SRPREPHDR: file = %O, start = $0000, size = $0004; - SRPREP: file = %O, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned + SRPREPCHNK: file = %O, define = yes, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned SRPREPTRL: file = %O, start = $0000, size = $0006; # "main program" load chunk @@ -42,21 +43,21 @@ MEMORY { CHARGEN: file = "", define = yes, start = $D800, size = $0400; # memory beneath the ROM - RAM_BELOW_ROM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; + HIDDEN_RAM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; } SEGMENTS { EXEHDR: load = HEADER, type = ro; SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; - SYSCHK: load = SYSCHK, type = rw, define = yes, optional = yes; + SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; SRPREPHDR: load = SRPREPHDR, type = ro; - SAVEAREA: load = SRPREP, type = bss, define = yes; # shared btw. SRPREP and RAM - LOWDATA: load = SRPREP, type = bss, define = yes; # " " " " " " " " - SRPREP: load = SRPREP, type = rw, define = yes; - SHADOW_RAM: load = SRPREP, run = RAM_BELOW_ROM, type = rw, define = yes, optional = yes; + SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " + SRPREP: load = SRPREPCHNK, type = rw, define = yes; + SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SRPREPTRL: load = SRPREPTRL, type = ro; MAINHDR: load = MAINHDR, type = ro; diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 78e7ba4f0..e0dc23f77 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -18,7 +18,7 @@ DEBUG = 1 .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__ .import __SHADOW_RAM_RUN__ .import __CHARGEN_START__, __CHARGEN_SIZE__ - .import __SAVEAREA_LOAD__ + .import __STARTADDRESS__ ; needed by xlmemchk.inc .include "zeropage.inc" .include "atari.inc" diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index b0abc0dc8..b1d80b0c2 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -17,7 +17,7 @@ DEBUG = 1 .export syschk .import __SYSCHK_LOAD__ - .import __SAVEAREA_LOAD__ ; needed by xlmemchk.inc + .import __STARTADDRESS__ ; needed by xlmemchk.inc .include "zeropage.inc" .include "atari.inc" @@ -75,6 +75,7 @@ cont: ldx #0 ; channel 0 no_xl: print_string "This program needs an XL machine." jmp fail +; entry point syschk: lda $fcd8 ; from ostype.s cmp #$a2 diff --git a/libsrc/atari/xlmemchk.inc b/libsrc/atari/xlmemchk.inc index 81e09ba90..d2a079557 100644 --- a/libsrc/atari/xlmemchk.inc +++ b/libsrc/atari/xlmemchk.inc @@ -9,7 +9,7 @@ ; by the screen memory afterwards. ; ; inputs: -; __SAVEAREA_LOAD__ - load address of the program +; __STARTADDRESS__ - load address of the program ; outputs: ; lodadr - (high byte only) value to ; write into RAMTOP @@ -75,8 +75,10 @@ al4k: lda lodadr+1 bne scrmemtst ; not reached - -lodadr: .word __SAVEAREA_LOAD__ & $FF00 ; our program's load address, rounded down to page boundary +.ifdef DEBUG +.byte "XLMEMCHK:>" +.endif +lodadr: .word __STARTADDRESS__ & $FF00 ; our program's load address, rounded down to page boundary tstadr: .res 2 lowadr: .res 2 tmp: .res 1 From 5d36270f786a97ca82482693a174dfe098dbb2b6 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 17 Sep 2013 22:32:43 +0200 Subject: [PATCH 101/144] add IOCB command codes to atari.h --- include/atari.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/atari.h b/include/atari.h index 61de88beb..ff23526ee 100644 --- a/include/atari.h +++ b/include/atari.h @@ -286,5 +286,30 @@ struct __iocb { #define ZIOCB (*(struct __iocb *)0x20) /* zero page IOCB */ #define IOCB (*(struct __iocb *)0x340) /* system IOCB buffers */ +/* IOCB Command Codes */ +#define IOCB_OPEN 0x03 /* open */ +#define IOCB_GETREC 0x05 /* get record */ +#define IOCB_GETCHR 0x07 /* get character(s) */ +#define IOCB_PUTREC 0x09 /* put record */ +#define IOCB_PUTCHR 0x0B /* put character(s) */ +#define IOCB_CLOSE 0x0C /* close */ +#define IOCB_STATIS 0x0D /* status */ +#define IOCB_SPECIL 0x0E /* special */ +#define IOCB_DRAWLN 0x11 /* draw line */ +#define IOCB_FILLIN 0x12 /* draw line with right fill */ +#define IOCB_RENAME 0x20 /* rename disk file */ +#define IOCB_DELETE 0x21 /* delete disk file */ +#define IOCB_LOCKFL 0x23 /* lock file (set to read-only) */ +#define IOCB_UNLOCK 0x24 /* unlock file */ +#define IOCB_POINT 0x25 /* point sector */ +#define IOCB_NOTE 0x26 /* note sector */ +#define IOCB_GETFL 0x27 /* get file length */ +#define IOCB_CHDIR_MYDOS 0x29 /* change directory (MyDOS) */ +#define IOCB_MKDIR 0x2A /* make directory (MyDOS/SpartaDOS) */ +#define IOCB_RMDIR 0x2B /* remove directory (SpartaDOS) */ +#define IOCB_CHDIR_SPDOS 0x2C /* change directory (SpartaDOS) */ +#define IOCB_GETCWD 0x30 /* get current directory (MyDOS/SpartaDOS) */ +#define IOCB_FORMAT 0xFE /* format */ + /* End of atari.h */ #endif /* #ifndef _ATARI_H */ From b20294594cb84b6d13a7598709c252a837adcd79 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 17 Sep 2013 22:33:48 +0200 Subject: [PATCH 102/144] add testprogram for _sys() function on Atari --- testcode/lib/atari/sys.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 testcode/lib/atari/sys.c diff --git a/testcode/lib/atari/sys.c b/testcode/lib/atari/sys.c new file mode 100644 index 000000000..a35be9dac --- /dev/null +++ b/testcode/lib/atari/sys.c @@ -0,0 +1,37 @@ +/* + * testprogram for _sys() function on Atari + * + * 17-Sep-2013, chris@groessler.org + * + * uses PUTCHR IOCB function to display a string + */ + +#include +#include <6502.h> +#include + +static struct regs regs; +static struct __iocb *iocb = &IOCB; /* use IOCB #0 */ + +static char message[] = "I'm the sys test text\n"; + +int main(void) +{ + /* setup IOCB for CIO call */ + iocb->buffer = message; + iocb->buflen = sizeof(message) - 1; + iocb->command = IOCB_PUTCHR; + + /* setup input registers */ + regs.x = 0; /* IOCB #0 */ + regs.pc = 0xe456; /* CIOV */ + + /* call CIO */ + _sys(®s); + + if (regs.y != 1) + cprintf("CIO error 0x%02\r\n", regs.y); + + cgetc(); + return 0; +} From 1135bc2acd6e396cba1d2cb995bd9b327ef3fe7e Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 17 Sep 2013 22:32:43 +0200 Subject: [PATCH 103/144] add IOCB command codes to atari.h --- include/atari.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/atari.h b/include/atari.h index 61de88beb..ff23526ee 100644 --- a/include/atari.h +++ b/include/atari.h @@ -286,5 +286,30 @@ struct __iocb { #define ZIOCB (*(struct __iocb *)0x20) /* zero page IOCB */ #define IOCB (*(struct __iocb *)0x340) /* system IOCB buffers */ +/* IOCB Command Codes */ +#define IOCB_OPEN 0x03 /* open */ +#define IOCB_GETREC 0x05 /* get record */ +#define IOCB_GETCHR 0x07 /* get character(s) */ +#define IOCB_PUTREC 0x09 /* put record */ +#define IOCB_PUTCHR 0x0B /* put character(s) */ +#define IOCB_CLOSE 0x0C /* close */ +#define IOCB_STATIS 0x0D /* status */ +#define IOCB_SPECIL 0x0E /* special */ +#define IOCB_DRAWLN 0x11 /* draw line */ +#define IOCB_FILLIN 0x12 /* draw line with right fill */ +#define IOCB_RENAME 0x20 /* rename disk file */ +#define IOCB_DELETE 0x21 /* delete disk file */ +#define IOCB_LOCKFL 0x23 /* lock file (set to read-only) */ +#define IOCB_UNLOCK 0x24 /* unlock file */ +#define IOCB_POINT 0x25 /* point sector */ +#define IOCB_NOTE 0x26 /* note sector */ +#define IOCB_GETFL 0x27 /* get file length */ +#define IOCB_CHDIR_MYDOS 0x29 /* change directory (MyDOS) */ +#define IOCB_MKDIR 0x2A /* make directory (MyDOS/SpartaDOS) */ +#define IOCB_RMDIR 0x2B /* remove directory (SpartaDOS) */ +#define IOCB_CHDIR_SPDOS 0x2C /* change directory (SpartaDOS) */ +#define IOCB_GETCWD 0x30 /* get current directory (MyDOS/SpartaDOS) */ +#define IOCB_FORMAT 0xFE /* format */ + /* End of atari.h */ #endif /* #ifndef _ATARI_H */ From c6e6baab7da4cccac9e32217956ed7ee8fc9e82d Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 17 Sep 2013 22:33:48 +0200 Subject: [PATCH 104/144] add testprogram for _sys() function on Atari --- testcode/lib/atari/sys.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 testcode/lib/atari/sys.c diff --git a/testcode/lib/atari/sys.c b/testcode/lib/atari/sys.c new file mode 100644 index 000000000..a35be9dac --- /dev/null +++ b/testcode/lib/atari/sys.c @@ -0,0 +1,37 @@ +/* + * testprogram for _sys() function on Atari + * + * 17-Sep-2013, chris@groessler.org + * + * uses PUTCHR IOCB function to display a string + */ + +#include +#include <6502.h> +#include + +static struct regs regs; +static struct __iocb *iocb = &IOCB; /* use IOCB #0 */ + +static char message[] = "I'm the sys test text\n"; + +int main(void) +{ + /* setup IOCB for CIO call */ + iocb->buffer = message; + iocb->buflen = sizeof(message) - 1; + iocb->command = IOCB_PUTCHR; + + /* setup input registers */ + regs.x = 0; /* IOCB #0 */ + regs.pc = 0xe456; /* CIOV */ + + /* call CIO */ + _sys(®s); + + if (regs.y != 1) + cprintf("CIO error 0x%02\r\n", regs.y); + + cgetc(); + return 0; +} From 367bd368c0739f629ee00c383b08cab6090e4b1d Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 17 Sep 2013 22:52:18 +0200 Subject: [PATCH 105/144] override _sys() function for Atari targets --- libsrc/atari/_sys.s | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 libsrc/atari/_sys.s diff --git a/libsrc/atari/_sys.s b/libsrc/atari/_sys.s new file mode 100644 index 000000000..e5bf07f30 --- /dev/null +++ b/libsrc/atari/_sys.s @@ -0,0 +1,13 @@ +; +; Christian Groessler, 17-Sep-2013 +; +; Override _sys() function for Atari targets: +; 'atari' gets the regular function +; 'atarixl' doesn't support the _sys() function +; + +.if .not .defined(__ATARIXL__) + +.include "../common/_sys.s" + +.endif From f679c9703c29933ec3efe3b5b67f0711b915325f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 17 Sep 2013 23:03:33 +0200 Subject: [PATCH 106/144] consider __STACKSIZE__ when initializing sp for atarixl --- libsrc/atari/crt0.s | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index e30d7c07f..9bf5771d4 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -17,6 +17,7 @@ .import __RESERVED_MEMORY__ .import __RAM_START__, __RAM_SIZE__ .if .defined(__ATARIXL__) + .import __STACKSIZE__ .import sram_init .import scrdev .import findfreeiocb @@ -88,9 +89,9 @@ start: .else - lda #<(__RAM_START__ + __RAM_SIZE__ - 1) + lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) sta sp - lda #>(__RAM_START__ + __RAM_SIZE__ - 1) + lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) sta sp+1 .endif From 3df94fba92d230e1768780e7390c50be5ffda6d3 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 00:17:45 +0200 Subject: [PATCH 107/144] introduce SHADOW_RAM2 --- cfg/atarixl.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index dd49d421d..d5bee6575 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -57,7 +57,8 @@ SEGMENTS { SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " SRPREP: load = SRPREPCHNK, type = rw, define = yes; - SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SRPREPTRL: load = SRPREPTRL, type = ro; MAINHDR: load = MAINHDR, type = ro; From 678ffbdd4d707e32911c12d307a9cde69792c3a0 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 00:25:18 +0200 Subject: [PATCH 108/144] add support for SHADOW_RAM2 segment --- libsrc/atari/shadow_ram_prepare.s | 47 ++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index e0dc23f77..4dd0338b9 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -14,9 +14,9 @@ DEBUG = 1 .if .defined(__ATARIXL__) .export sramprep - .import __SRPREP_LOAD__, __SRPREP_SIZE__ - .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__ - .import __SHADOW_RAM_RUN__ + .import __SRPREP_LOAD__, __SRPREPCHNK_LAST__ + .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__, __SHADOW_RAM_RUN__ + .import __SHADOW_RAM2_LOAD__, __SHADOW_RAM2_SIZE__, __SHADOW_RAM2_RUN__ .import __CHARGEN_START__, __CHARGEN_SIZE__ .import __STARTADDRESS__ ; needed by xlmemchk.inc @@ -48,7 +48,7 @@ cont: ldx #0 ; channel 0 .segment "SRPREPHDR" .word __SRPREP_LOAD__ - .word __SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__ - 1 + .word __SRPREPCHNK_LAST__ - 1 ; ------------------------------------------------------------------------ ; Actual code @@ -148,15 +148,15 @@ scrok: ; now close it again -- we don't need it anymore jsr CIOV_org -; copy chargen to low memory +; copy chargen to low memory, just after the next possible address beyond our loaded chunk data .ifdef DEBUG print_string "copy chargen to low memory" .endif - lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) + lda #>__SRPREPCHNK_LAST__ sta ptr3+1 - lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__) + lda #<__SRPREPCHNK_LAST__ sta ptr3 beq cg_addr_ok @@ -215,7 +215,7 @@ cg_addr_ok2: sta CHBASE sta CHBAS -; copy shadow RAM contents to their destination +; copy shadow RAM contents to their destination (segment SHADOW_RAM) lda #<__SHADOW_RAM_SIZE__ bne do_copy @@ -240,6 +240,32 @@ do_copy:lda #<__SHADOW_RAM_LOAD__ no_copy: +; copy shadow RAM #2 contents to their destination (segment SHADOW_RAM2) + + lda #<__SHADOW_RAM2_SIZE__ + bne do_copy2 + lda #>__SHADOW_RAM2_SIZE__ + beq no_copy2 ; we have no shadow RAM contents + + ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len +do_copy2: + lda #<__SHADOW_RAM2_LOAD__ + sta ptr1 + lda #>__SHADOW_RAM2_LOAD__ + sta ptr1+1 + lda #<__SHADOW_RAM2_RUN__ + sta ptr2 + lda #>__SHADOW_RAM2_RUN__ + sta ptr2+1 + lda #<__SHADOW_RAM2_SIZE__ + sta tmp1 + lda #>__SHADOW_RAM2_SIZE__ + sta tmp2 + + jsr memcopy + +no_copy2: + ; copy chargen to its new (final) location lda ptr3 @@ -361,10 +387,11 @@ screen_device_length = * - screen_device .endif ; ------------------------------------------------------------------------ -; Provide an empty SHADOW_RAM segment in order that the linker is happy -; if the user program doesn't have a SHADOW_RAM segment. +; Provide empty SHADOW_RAM and SHADOW_RAM2 segments in order that the +; linker is happy if the user program doesn't have these segments. .segment "SHADOW_RAM" +.segment "SHADOW_RAM2" ; ------------------------------------------------------------------------ From de639fdf6a19759fb5ae1a4f0fe30cb42a829d20 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 00:27:45 +0200 Subject: [PATCH 109/144] introduce SHADOW_RAM2 --- cfg/atarixl-overlay.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 8b408c3a4..cfa786bf1 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -71,7 +71,8 @@ SEGMENTS { SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " SRPREP: load = SRPREPCHNK, type = rw, define = yes; - SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SRPREPTRL: load = SRPREPTRL, type = ro; MAINHDR: load = MAINHDR, type = ro; From 42835d91b889c3f98d2c49cfaf8ce5b9b42381a5 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 00:28:48 +0200 Subject: [PATCH 110/144] remove __RESERVED_MEMORY__: not supported on atarixl --- cfg/atarixl-overlay.cfg | 1 - cfg/atarixl.cfg | 1 - 2 files changed, 2 deletions(-) diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index cfa786bf1..74a4a8c2f 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -5,7 +5,6 @@ FEATURES { SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay - __RESERVED_MEMORY__: type = weak, value = $0000; __STARTADDRESS__: type = export, value = %S; syschk: type = import; # force inclusion of SYSCHK sramprep: type = import; # force inclusion of SRPREP diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index d5bee6575..94aff46a5 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -4,7 +4,6 @@ FEATURES { SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack - __RESERVED_MEMORY__: type = weak, value = $0000; __STARTADDRESS__: type = export, value = %S; syschk: type = import; # force inclusion of SYSCHK sramprep: type = import; # force inclusion of SRPREP From d0c41ecee9263b29113cde0bbbf46a1f08f710d9 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 00:38:29 +0200 Subject: [PATCH 111/144] Default atatixl.cfg file now leaves the character generator at $E000. This reduces the potential to flicker, but creates two separate memory areas in the high memory. For applications which require a large continuous memory space in high memory, atarixl-largehimem.cfg is provided. With high IRQ activity or DL interrupt there might be flicker. --- cfg/atarixl-largehimem.cfg | 89 ++++++++++++++++++++++++++++++++++++++ cfg/atarixl.cfg | 13 +++--- 2 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 cfg/atarixl-largehimem.cfg diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg new file mode 100644 index 000000000..94aff46a5 --- /dev/null +++ b/cfg/atarixl-largehimem.cfg @@ -0,0 +1,89 @@ +FEATURES { + STARTADDRESS: default = $2400; +} + +SYMBOLS { + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __STARTADDRESS__: type = export, value = %S; + syschk: type = import; # force inclusion of SYSCHK + sramprep: type = import; # force inclusion of SRPREP +} + +MEMORY { + ZP: file = "", define = yes, start = $0082, size = $007E; + +# just $FFFF + HEADER: file = %O, start = $0000, size = $0002; + +# "system check" load chunk + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; + SYSCHKTRL: file = %O, start = $0000, size = $0006; + +# "shadow RAM preparation" load chunk + SRPREPHDR: file = %O, start = $0000, size = $0004; + SRPREPCHNK: file = %O, define = yes, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned + SRPREPTRL: file = %O, start = $0000, size = $0006; + +# "main program" load chunk + MAINHDR: file = %O, start = $0000, size = $0004; + RAM: file = %O, define = yes, start = %S + + __SAVEAREA_SIZE__ + + __LOWDATA_SIZE__, size = $D000 - + __STACKSIZE__ - + %S - + __SAVEAREA_SIZE__ - + __LOWDATA_SIZE__; + +# defines entry point into program + TRAILER: file = %O, start = $0000, size = $0006; + +# address of relocated character generator + CHARGEN: file = "", define = yes, start = $D800, size = $0400; + +# memory beneath the ROM + HIDDEN_RAM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; +} + +SEGMENTS { + EXEHDR: load = HEADER, type = ro; + + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; + SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; + + SRPREPHDR: load = SRPREPHDR, type = ro; + SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " + SRPREP: load = SRPREPCHNK, type = rw, define = yes; + SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SRPREPTRL: load = SRPREPTRL, type = ro; + + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; +} +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/cfg/atarixl.cfg b/cfg/atarixl.cfg index 94aff46a5..e400c6bea 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -38,11 +38,14 @@ MEMORY { # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; -# address of relocated character generator - CHARGEN: file = "", define = yes, start = $D800, size = $0400; +# memory beneath the ROM preceeding the character generator + HIDDEN_RAM2: file = "", define = yes, start = $D800, size = $0800; + +# address of relocated character generator (same addess as ROM version) + CHARGEN: file = "", define = yes, start = $E000, size = $0400; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; + HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFF0 - $E400; } SEGMENTS { @@ -56,8 +59,8 @@ SEGMENTS { SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " SRPREP: load = SRPREPCHNK, type = rw, define = yes; - SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; - SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM2, type = rw, define = yes, optional = yes; SRPREPTRL: load = SRPREPTRL, type = ro; MAINHDR: load = MAINHDR, type = ro; From b71370630411c2b1102aa2e59c5b3e3b3d89b866 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 00:48:01 +0200 Subject: [PATCH 112/144] Get rid of SAVEAREA segment: fold it into LOWDATA. --- cfg/atarixl-largehimem.cfg | 13 +++++-------- cfg/atarixl-overlay.cfg | 15 ++++++--------- cfg/atarixl.cfg | 13 +++++-------- libsrc/atari/save_area.s | 2 +- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 94aff46a5..f01294d61 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -28,12 +28,10 @@ MEMORY { # "main program" load chunk MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + - __SAVEAREA_SIZE__ + - __LOWDATA_SIZE__, size = $D000 - - __STACKSIZE__ - - %S - - __SAVEAREA_SIZE__ - - __LOWDATA_SIZE__; + __LOWDATA_SIZE__, size = $D000 - + __STACKSIZE__ - + %S - + __LOWDATA_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; @@ -53,8 +51,7 @@ SEGMENTS { SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; SRPREPHDR: load = SRPREPHDR, type = ro; - SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 74a4a8c2f..5f19c6354 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -30,13 +30,11 @@ MEMORY { MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + __OVERLAYSIZE__ + - __SAVEAREA_SIZE__ + - __LOWDATA_SIZE__, size = $D000 - - __STACKSIZE__ - - %S - - __OVERLAYSIZE__ - - __SAVEAREA_SIZE__ - - __LOWDATA_SIZE__; + __LOWDATA_SIZE__, size = $D000 - + __STACKSIZE__ - + %S - + __OVERLAYSIZE__ - + __LOWDATA_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; @@ -67,8 +65,7 @@ SEGMENTS { SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; SRPREPHDR: load = SRPREPHDR, type = ro; - SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index e400c6bea..ceb4141af 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -28,12 +28,10 @@ MEMORY { # "main program" load chunk MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + - __SAVEAREA_SIZE__ + - __LOWDATA_SIZE__, size = $D000 - - __STACKSIZE__ - - %S - - __SAVEAREA_SIZE__ - - __LOWDATA_SIZE__; + __LOWDATA_SIZE__, size = $D000 - + __STACKSIZE__ - + %S - + __LOWDATA_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; @@ -56,8 +54,7 @@ SEGMENTS { SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; SRPREPHDR: load = SRPREPHDR, type = ro; - SAVEAREA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # " " " " " " " " + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM2, type = rw, define = yes, optional = yes; diff --git a/libsrc/atari/save_area.s b/libsrc/atari/save_area.s index 45cd42400..2fddce017 100644 --- a/libsrc/atari/save_area.s +++ b/libsrc/atari/save_area.s @@ -14,7 +14,7 @@ .export RAMTOP_save .export PORTB_save -.segment "SAVEAREA" +.segment "LOWDATA" SAVMSC_save: .res 2 MEMTOP_save: .res 2 From 7c0b049ef71dbe7eb362d6082ac5e1756dbaa661 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 01:27:44 +0200 Subject: [PATCH 113/144] some cosmetic cleanups --- libsrc/atari/shadow_ram_handlers.s | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 0a7e3ef00..c01f56ddb 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -293,8 +293,6 @@ CIOV_call: php pha disable_rom_val cur_CIOV_PORTB -; lda cur_CIOV_PORTB -; sta PORTB pla plp rts @@ -896,8 +894,6 @@ SIO_call: php pha disable_rom_val cur_SIOV_PORTB -; lda cur_SIOV_PORTB -; sta PORTB pla plp rts @@ -1118,8 +1114,6 @@ KEYBDV_handler: rts ; call keyboard handler kret: pha disable_rom_val cur_KEYBDV_PORTB -; lda cur_KEYBDV_PORTB -; sta PORTB pla rts @@ -1136,8 +1130,6 @@ SETVBV_handler: php pha disable_rom_val cur_SETVBV_PORTB -; lda cur_SETVBV_PORTB -; sta PORTB pla plp rts From ff18dcaa16462b9e21995bedd5a08653ab472fa0 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 17 Sep 2013 22:52:18 +0200 Subject: [PATCH 114/144] override _sys() function for Atari targets --- libsrc/atari/_sys.s | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 libsrc/atari/_sys.s diff --git a/libsrc/atari/_sys.s b/libsrc/atari/_sys.s new file mode 100644 index 000000000..e5bf07f30 --- /dev/null +++ b/libsrc/atari/_sys.s @@ -0,0 +1,13 @@ +; +; Christian Groessler, 17-Sep-2013 +; +; Override _sys() function for Atari targets: +; 'atari' gets the regular function +; 'atarixl' doesn't support the _sys() function +; + +.if .not .defined(__ATARIXL__) + +.include "../common/_sys.s" + +.endif From c210dfcb9445f6c5706046d174867c52c1310c44 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 16:36:03 +0200 Subject: [PATCH 115/144] use '.ifndef' instead of '.if .not .defined' --- libsrc/atari/_sys.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/atari/_sys.s b/libsrc/atari/_sys.s index e5bf07f30..66e4905ec 100644 --- a/libsrc/atari/_sys.s +++ b/libsrc/atari/_sys.s @@ -6,7 +6,7 @@ ; 'atarixl' doesn't support the _sys() function ; -.if .not .defined(__ATARIXL__) +.ifndef __ATARIXL__ .include "../common/_sys.s" From 2e10a55b5116a9dec0128ac4e0173a59e90cd871 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 16:36:03 +0200 Subject: [PATCH 116/144] use '.ifndef' instead of '.if .not .defined' --- libsrc/atari/_sys.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/atari/_sys.s b/libsrc/atari/_sys.s index e5bf07f30..66e4905ec 100644 --- a/libsrc/atari/_sys.s +++ b/libsrc/atari/_sys.s @@ -6,7 +6,7 @@ ; 'atarixl' doesn't support the _sys() function ; -.if .not .defined(__ATARIXL__) +.ifndef __ATARIXL__ .include "../common/_sys.s" From 0a7cb64d2ec44c6bbbe4ed2dab7f742c794295d9 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 19 Sep 2013 22:36:22 +0200 Subject: [PATCH 117/144] Use '.ifdef' and '.ifndef' instead of '.if .defined' and '.if .not .defined'. --- libsrc/atari/cgetc.s | 4 ++-- libsrc/atari/crt0.s | 14 +++++++------- libsrc/atari/irq.s | 4 ++-- libsrc/atari/libref.s | 2 +- libsrc/atari/ostype.s | 2 +- libsrc/atari/save_area.s | 2 +- libsrc/atari/shadow_ram_handlers.s | 4 ++-- libsrc/atari/shadow_ram_prepare.s | 4 ++-- libsrc/atari/system_check.s | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libsrc/atari/cgetc.s b/libsrc/atari/cgetc.s index cf853f5ce..54fe85bb4 100644 --- a/libsrc/atari/cgetc.s +++ b/libsrc/atari/cgetc.s @@ -14,7 +14,7 @@ _cgetc: jsr setcursor lda #12 sta ICAX1Z ; fix problems with direct call to KEYBDV -.if .not .defined(__ATARIXL__) +.ifndef __ATARIXL__ jsr @1 .else jsr KEYBDV_handler @@ -22,7 +22,7 @@ _cgetc: ldx #0 rts -.if .not .defined(__ATARIXL__) +.ifndef __ATARIXL__ @1: lda KEYBDV+5 pha lda KEYBDV+4 diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 9bf5771d4..07f2e3be7 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -16,7 +16,7 @@ .import __STARTUP_LOAD__, __BSS_LOAD__ .import __RESERVED_MEMORY__ .import __RAM_START__, __RAM_SIZE__ -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .import __STACKSIZE__ .import sram_init .import scrdev @@ -34,7 +34,7 @@ .word $FFFF -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .segment "MAINHDR" .endif @@ -55,7 +55,7 @@ start: -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ jsr sram_init .endif @@ -68,7 +68,7 @@ start: tsx stx spsave -.if .not .defined(__ATARIXL__) +.ifndef __ATARIXL__ ; Report memory usage @@ -101,7 +101,7 @@ start: jsr initlib .if 0 -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .import __heapadd .import pushax .import __RAM_BELOW_ROM_START__ @@ -165,7 +165,7 @@ _exit: jsr donelib ; Run module destructors lda APPMHI_save+1 sta APPMHI+1 -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ ; Atari XL target stuff... @@ -224,7 +224,7 @@ _exit: jsr donelib ; Run module destructors spsave: .res 1 old_shflok: .res 1 old_lmargin: .res 1 -.if .not .defined(__ATARIXL__) +.ifndef __ATARIXL__ APPMHI_save: .res 2 .endif diff --git a/libsrc/atari/irq.s b/libsrc/atari/irq.s index 597ad9d60..3fbdc971b 100644 --- a/libsrc/atari/irq.s +++ b/libsrc/atari/irq.s @@ -39,7 +39,7 @@ doneirq: IRQStub: cld ; Just to be sure -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ pha lda PORTB pha @@ -47,7 +47,7 @@ IRQStub: sta PORTB ; disable ROM @@@ TODO: update CHARGEN .endif jsr callirq ; Call the functions -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ pla sta PORTB pla diff --git a/libsrc/atari/libref.s b/libsrc/atari/libref.s index 6d93a0b8e..171bd6de6 100644 --- a/libsrc/atari/libref.s +++ b/libsrc/atari/libref.s @@ -7,7 +7,7 @@ em_libref := _exit joy_libref := _exit -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .import CIO_handler tgi_libref := CIO_handler .else diff --git a/libsrc/atari/ostype.s b/libsrc/atari/ostype.s index 7a3342d2a..4fbeaaf70 100644 --- a/libsrc/atari/ostype.s +++ b/libsrc/atari/ostype.s @@ -40,7 +40,7 @@ .export _get_ostype -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .include "atari.inc" .import __CHARGEN_START__ diff --git a/libsrc/atari/save_area.s b/libsrc/atari/save_area.s index 2fddce017..5495be8ca 100644 --- a/libsrc/atari/save_area.s +++ b/libsrc/atari/save_area.s @@ -6,7 +6,7 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .export SAVMSC_save .export MEMTOP_save diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index c01f56ddb..9714644ad 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -8,7 +8,7 @@ DEBUG = 1 USEWSYNC= 1 CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ SHRAM_HANDLERS = 1 .include "atari.inc" @@ -1147,4 +1147,4 @@ orig_len: .res 2 req_len: .res 2 retlen: .res 2 -.endif ; .if .defined(__ATARIXL__) +.endif ; .ifdef __ATARIXL__ diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 4dd0338b9..be40baed3 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -11,7 +11,7 @@ DEBUG = 1 -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .export sramprep .import __SRPREP_LOAD__, __SRPREPCHNK_LAST__ @@ -403,4 +403,4 @@ screen_device_length = * - screen_device .word INITAD+1 .word sramprep -.endif ; .if .defined(__ATARIXL__) +.endif ; .ifdef __ATARIXL__ diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index b1d80b0c2..b01311a4b 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -13,7 +13,7 @@ DEBUG = 1 -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .export syschk .import __SYSCHK_LOAD__ @@ -154,4 +154,4 @@ end: .word INITAD+1 .word syschk -.endif ; .if .defined(__ATARIXL__) +.endif ; .ifdef __ATARIXL__ From 47a6390753a33cf8d0b6a5747316e24d0b07fcda Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 19 Sep 2013 22:40:20 +0200 Subject: [PATCH 118/144] adjust some variable names --- libsrc/atari/crt0.s | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 07f2e3be7..f28439802 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -66,7 +66,7 @@ start: ; Setup the stack tsx - stx spsave + stx SP_save .ifndef __ATARIXL__ @@ -120,14 +120,14 @@ start: ; Set left margin to 0 lda LMARGN - sta old_lmargin + sta LMARGN_save ldy #0 sty LMARGN ; Set keyb to upper/lowercase mode ldx SHFLOK - stx old_shflok + stx SHFLOK_save sty SHFLOK ; Initialize conio stuff @@ -145,17 +145,17 @@ _exit: jsr donelib ; Run module destructors ; Restore system stuff - ldx spsave + ldx SP_save txs ; Restore stack pointer ; Restore left margin - lda old_lmargin + lda LMARGN_save sta LMARGN ; Restore kb mode - lda old_shflok + lda SHFLOK_save sta SHFLOK ; Restore APPMHI @@ -221,9 +221,9 @@ _exit: jsr donelib ; Run module destructors .bss -spsave: .res 1 -old_shflok: .res 1 -old_lmargin: .res 1 +SP_save: .res 1 +SHFLOK_save .res 1 +LMARGN_save: .res 1 .ifndef __ATARIXL__ APPMHI_save: .res 2 .endif From 60e97f4d96a61f8ea9ccfe772aa4d4fc588483f5 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 19 Sep 2013 23:21:09 +0200 Subject: [PATCH 119/144] move macros to enable and disable the ROM into a separate include file --- libsrc/atari/crt0.s | 2 +- libsrc/atari/ostype.s | 54 +++++++++------------- libsrc/atari/romswitch.inc | 73 ++++++++++++++++++++++++++++++ libsrc/atari/shadow_ram_handlers.s | 53 +--------------------- 4 files changed, 97 insertions(+), 85 deletions(-) create mode 100644 libsrc/atari/romswitch.inc diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index f28439802..f1cadd992 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -222,7 +222,7 @@ _exit: jsr donelib ; Run module destructors .bss SP_save: .res 1 -SHFLOK_save .res 1 +SHFLOK_save: .res 1 LMARGN_save: .res 1 .ifndef __ATARIXL__ APPMHI_save: .res 2 diff --git a/libsrc/atari/ostype.s b/libsrc/atari/ostype.s index 4fbeaaf70..d2bf8888e 100644 --- a/libsrc/atari/ostype.s +++ b/libsrc/atari/ostype.s @@ -40,40 +40,38 @@ .export _get_ostype + .include "atari.inc" + .include "romswitch.inc" + .ifdef __ATARIXL__ - .include "atari.inc" .import __CHARGEN_START__ .segment "LOWCODE" -.macro disable_rom + +.macro disable_rom_save_a pha - lda PORTB - and #$fe - sta PORTB - lda #>__CHARGEN_START__ - sta CHBAS - sta CHBASE - pla -.endmacro -.macro enable_rom - lda PORTB - ora #1 - sta PORTB - lda #$E0 - sta CHBAS - sta CHBASE + disable_rom + pla .endmacro .else ; above atarixl, below atari -.macro disable_rom -.endmacro -.macro enable_rom +.macro disable_rom_save_a .endmacro -.endif +.endif ; .ifdef __ATARIXL__ -.proc _get_ostype + +; unknown ROM + +_unknown: + lda #0 + tax + disable_rom_save_a + rts + + +_get_ostype: enable_rom lda $fcd8 @@ -97,15 +95,7 @@ and #%00111000 ora #%11 _fin: ldx #0 - disable_rom - rts - -; unknown ROM - -_unknown: - lda #0 - tax - disable_rom + disable_rom_save_a rts ; 1200XL ROM @@ -184,5 +174,3 @@ _400800_3: lda #%00010001 bne _fin - -.endproc diff --git a/libsrc/atari/romswitch.inc b/libsrc/atari/romswitch.inc new file mode 100644 index 000000000..58e09042a --- /dev/null +++ b/libsrc/atari/romswitch.inc @@ -0,0 +1,73 @@ +; +; Macros to disable and enable the ROM on Atari XL systems. +; +; Christian Groessler, chris@groessler.org, 19-Sep-2013 +; + + +.ifdef __ATARIXL__ + +USEWSYNC= 1 + +.if USEWSYNC +.macro wsync + sta WSYNC +.endmacro +.else +.macro wsync +.endmacro +.endif + + +.macro disable_rom + lda PORTB + and #$fe + wsync + sta PORTB + lda #>__CHARGEN_START__ + sta CHBAS + sta CHBASE +.endmacro +.macro disable_rom_quick + lda PORTB + and #$fe + sta PORTB + lda #>__CHARGEN_START__ + sta CHBAS + sta CHBASE +.endmacro +.macro disable_rom_val val + lda val + wsync + sta PORTB + lda #>__CHARGEN_START__ + sta CHBAS + sta CHBASE +.endmacro + +.macro enable_rom + lda PORTB + ora #1 + wsync + sta PORTB + lda #$E0 + sta CHBAS + sta CHBASE +.endmacro +.macro enable_rom_quick + lda PORTB + ora #1 + sta PORTB + lda #$E0 + sta CHBAS + sta CHBASE +.endmacro + +.else ; above __ATARIXL__, below not + +.macro disable_rom +.endmacro +.macro enable_rom +.endmacro + +.endif diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 9714644ad..ddc7b0842 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -5,7 +5,6 @@ ; DEBUG = 1 -USEWSYNC= 1 CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) .ifdef __ATARIXL__ @@ -14,6 +13,8 @@ CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always don .include "atari.inc" .include "save_area.inc" .include "zeropage.inc" + .include "romswitch.inc" + .import __CHARGEN_START__ .export sram_init @@ -25,56 +26,6 @@ CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always don BUFSZ = 128 ; bounce buffer size BUFSZ_SIO = 256 -.macro wsync -.if USEWSYNC - sta WSYNC -.endif -.endmacro - -.macro disable_rom - lda PORTB - and #$fe - wsync - sta PORTB - lda #>__CHARGEN_START__ - sta CHBAS - sta CHBASE -.endmacro -.macro disable_rom_quick - lda PORTB - and #$fe - sta PORTB - lda #>__CHARGEN_START__ - sta CHBAS - sta CHBASE -.endmacro -.macro disable_rom_val val - lda val - wsync - sta PORTB - lda #>__CHARGEN_START__ - sta CHBAS - sta CHBASE -.endmacro - -.macro enable_rom - lda PORTB - ora #1 - wsync - sta PORTB - lda #$E0 - sta CHBAS - sta CHBASE -.endmacro -.macro enable_rom_quick - lda PORTB - ora #1 - sta PORTB - lda #$E0 - sta CHBAS - sta CHBASE -.endmacro - .segment "INIT" ; Turn off ROMs, install system and interrupt wrappers, set new chargen pointer From fe7578801576cf8ebec0eb8dab2246fc5c466b67 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 19 Sep 2013 23:34:45 +0200 Subject: [PATCH 120/144] add CHARGEN_RELOC knob to conditionally include the code to change CHBASE --- libsrc/atari/romswitch.inc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libsrc/atari/romswitch.inc b/libsrc/atari/romswitch.inc index 58e09042a..9e229ea63 100644 --- a/libsrc/atari/romswitch.inc +++ b/libsrc/atari/romswitch.inc @@ -7,9 +7,10 @@ .ifdef __ATARIXL__ -USEWSYNC= 1 +USEWSYNC = 1 +CHARGEN_RELOC = 1 -.if USEWSYNC +.if .defined(USEWSYNC) .and .defined(CHARGEN_RELOC) .macro wsync sta WSYNC .endmacro @@ -24,25 +25,31 @@ USEWSYNC= 1 and #$fe wsync sta PORTB +.ifdef CHARGEN_RELOC lda #>__CHARGEN_START__ sta CHBAS sta CHBASE +.endif .endmacro .macro disable_rom_quick lda PORTB and #$fe sta PORTB +.ifdef CHARGEN_RELOC lda #>__CHARGEN_START__ sta CHBAS sta CHBASE +.endif .endmacro .macro disable_rom_val val lda val wsync sta PORTB +.ifdef CHARGEN_RELOC lda #>__CHARGEN_START__ sta CHBAS sta CHBASE +.endif .endmacro .macro enable_rom @@ -50,17 +57,21 @@ USEWSYNC= 1 ora #1 wsync sta PORTB +.ifdef CHARGEN_RELOC lda #$E0 sta CHBAS sta CHBASE +.endif .endmacro .macro enable_rom_quick lda PORTB ora #1 sta PORTB +.ifdef CHARGEN_RELOC lda #$E0 sta CHBAS sta CHBASE +.endif .endmacro .else ; above __ATARIXL__, below not From 37ed72bc891ae1885ce1c3343179b2fbbf122414 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 20 Sep 2013 00:10:34 +0200 Subject: [PATCH 121/144] cleanup and document CHARGEN_RELOC change --- libsrc/atari/romswitch.inc | 73 ++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/libsrc/atari/romswitch.inc b/libsrc/atari/romswitch.inc index 9e229ea63..e1f3433b6 100644 --- a/libsrc/atari/romswitch.inc +++ b/libsrc/atari/romswitch.inc @@ -3,6 +3,19 @@ ; ; Christian Groessler, chris@groessler.org, 19-Sep-2013 ; +; +; Defines which modify the operation of the macros: +; +; CHARGEN_RELOC: If defined, CHBAS and CHBASE are updated when +; enabling or disabling the ROM. +; If the ROM is enabled, $E0 is written to CHBAS +; and CHBASE. +; If the ROM is disabled, the upper byte of +; __CHARGEN_START__ is written to CHBAS and CHBASE. +; USEWSYNC: If defined, the code waits for horizontal retrace +; before switching the ROM and updating CHBAS and +; CHBASE. This define only has effect if CHAGEN_RELOC +; is also defined. .ifdef __ATARIXL__ @@ -10,68 +23,76 @@ USEWSYNC = 1 CHARGEN_RELOC = 1 + +.ifdef CHARGEN_RELOC + +.macro set_chbase val + lda #val + sta CHBAS + sta CHBASE +.endmacro + +.else + +.macro set_chbase val +.endmacro + +.endif ; .ifdef CHARGEN_RELOC + + .if .defined(USEWSYNC) .and .defined(CHARGEN_RELOC) + .macro wsync sta WSYNC .endmacro -.else + +.else ; above + .macro wsync .endmacro + .endif +; "disable ROM" macros + .macro disable_rom lda PORTB and #$fe wsync sta PORTB -.ifdef CHARGEN_RELOC - lda #>__CHARGEN_START__ - sta CHBAS - sta CHBASE -.endif + set_chbase >__CHARGEN_START__ .endmacro + .macro disable_rom_quick lda PORTB and #$fe sta PORTB -.ifdef CHARGEN_RELOC - lda #>__CHARGEN_START__ - sta CHBAS - sta CHBASE -.endif + set_chbase >__CHARGEN_START__ .endmacro + .macro disable_rom_val val lda val wsync sta PORTB -.ifdef CHARGEN_RELOC - lda #>__CHARGEN_START__ - sta CHBAS - sta CHBASE -.endif + set_chbase >__CHARGEN_START__ .endmacro +; "enable ROM" macros + .macro enable_rom lda PORTB ora #1 wsync sta PORTB -.ifdef CHARGEN_RELOC - lda #$E0 - sta CHBAS - sta CHBASE -.endif + set_chbase $E0 .endmacro + .macro enable_rom_quick lda PORTB ora #1 sta PORTB -.ifdef CHARGEN_RELOC - lda #$E0 - sta CHBAS - sta CHBASE -.endif + set_chbase $E0 .endmacro .else ; above __ATARIXL__, below not From aa2167926a49ed73a84ae5fc4eb7f8eb0d35cbe6 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 20 Sep 2013 00:26:49 +0200 Subject: [PATCH 122/144] move CHARGEN_RELOC enabling to Makefile.inc --- libsrc/atari/Makefile.inc | 17 +++++++++++++++++ libsrc/atari/romswitch.inc | 6 +----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/libsrc/atari/Makefile.inc b/libsrc/atari/Makefile.inc index d12b54058..af5a17e59 100644 --- a/libsrc/atari/Makefile.inc +++ b/libsrc/atari/Makefile.inc @@ -14,3 +14,20 @@ # needs DEFAULT_DEVICE to be defined, otherwise no effect CA65FLAGS += -D NUMDRVS=4 -D LINEBUF=80 -D UCASE_FILENAME=1 -D DEFAULT_DEVICE=1 -D DYNAMIC_DD=1 + +# The following defines are only used by the 'atarixl' target: +# +# CHARGEN_RELOC - If defined, CHBAS and CHBASE are updated when +# enabling or disabling the ROM. +# If the ROM is enabled, $E0 is written to CHBAS +# and CHBASE. +# If the ROM is disabled, the upper byte of +# __CHARGEN_START__ is written to CHBAS and CHBASE. +# USEWSYNC - If defined, the code waits for horizontal retrace +# before switching the ROM and updating CHBAS and +# CHBASE. This define only has effect if CHARGEN_RELOC +# is also defined. + +# Disabled by default, you should enable it if the linker script relocates the +# character generator (like atarixl-largehimem.cfg). +#CA65FLAGS += -D CHARGEN_RELOC -D USEWSYNC diff --git a/libsrc/atari/romswitch.inc b/libsrc/atari/romswitch.inc index e1f3433b6..7169f2b39 100644 --- a/libsrc/atari/romswitch.inc +++ b/libsrc/atari/romswitch.inc @@ -14,16 +14,12 @@ ; __CHARGEN_START__ is written to CHBAS and CHBASE. ; USEWSYNC: If defined, the code waits for horizontal retrace ; before switching the ROM and updating CHBAS and -; CHBASE. This define only has effect if CHAGEN_RELOC +; CHBASE. This define only has effect if CHARGEN_RELOC ; is also defined. .ifdef __ATARIXL__ -USEWSYNC = 1 -CHARGEN_RELOC = 1 - - .ifdef CHARGEN_RELOC .macro set_chbase val From 722dbaa1aa14872b7620ed9cdee907a58fae6b39 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 20 Sep 2013 18:09:16 +0200 Subject: [PATCH 123/144] Add comment describing the need to have the runtime library compiled with CHARGEN_RELOC enabled. --- cfg/atarixl-largehimem.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index f01294d61..895cfe430 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -1,3 +1,8 @@ +# This config file provides a single big upper memory block (HIDDEN_RAM). +# To achieve this, it relocates the character generator from $E000 to CHARGEN. +# The runtime library must be compiled with CHARGEN_RELOC for this config +# file to work. See libsrc/atari/Makefile.inc. + FEATURES { STARTADDRESS: default = $2400; } From 34e75afec3091c211e132d7b49d92d4cdcc84d06 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 20 Sep 2013 18:09:53 +0200 Subject: [PATCH 124/144] adapt to CHARGEN_RELOC --- libsrc/atari/irq.s | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/libsrc/atari/irq.s b/libsrc/atari/irq.s index 3fbdc971b..4a266630c 100644 --- a/libsrc/atari/irq.s +++ b/libsrc/atari/irq.s @@ -6,6 +6,10 @@ .import callirq .include "atari.inc" +.ifdef __ATARIXL__ + .import __CHARGEN_START__ + .include "romswitch.inc" +.endif ; ------------------------------------------------------------------------ @@ -40,17 +44,27 @@ doneirq: IRQStub: cld ; Just to be sure .ifdef __ATARIXL__ - pha - lda PORTB - pha - and #$fe - sta PORTB ; disable ROM @@@ TODO: update CHARGEN + pha +.ifdef CHARGEN_RELOC + lda CHBAS + pha +.endif + lda PORTB + pha + and #$fe + sta PORTB ; disable ROM + set_chbase >__CHARGEN_START__ .endif jsr callirq ; Call the functions .ifdef __ATARIXL__ - pla - sta PORTB - pla + pla + sta PORTB ; restore old ROM setting +.ifdef CHARGEN_RELOC + pla + sta CHBAS + sta CHBASE +.endif + pla .endif jmp IRQInd ; Jump to the saved IRQ vector From 82299f3caa4561d3b1f3ca95ea2c366e921d73a7 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 23 Sep 2013 16:10:12 -0400 Subject: [PATCH 125/144] Made the archiver announce a library's creation only if it is being verbose. --- src/ar65/library.c | 15 +++++++++------ src/ar65/main.c | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ar65/library.c b/src/ar65/library.c index 9fdbf9e91..9046e315f 100644 --- a/src/ar65/library.c +++ b/src/ar65/library.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2012, Ullrich von Bassewitz */ +/* (C) 1998-2013, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -38,6 +38,7 @@ #include /* common */ +#include "cmdline.h" #include "exprdefs.h" #include "libdefs.h" #include "print.h" @@ -60,7 +61,7 @@ /*****************************************************************************/ - + /* Name of the library file */ const char* LibName = 0; @@ -101,7 +102,7 @@ static void ReadHeader (void) } Header.Flags = Read16 (Lib); Header.IndexOffs = Read32 (Lib); -} +} @@ -229,7 +230,9 @@ void LibOpen (const char* Name, int MustExist, int NeedTemp) if (MustExist) { Error ("Library `%s' does not exist", Name); } else { - Warning ("Library `%s' not found - will be created", Name); + /* Announce the library's creation if ar65 is verbose. */ + Print (stdout, 1, + "%s: Library `%s' will be created.\n", ProgName, Name); } } else { @@ -307,7 +310,7 @@ static void LibCheckExports (ObjData* O) unsigned I; /* Let the user know what we do */ - Print (stdout, 1, "Module `%s' (%u exports):\n", O->Name, CollCount (&O->Exports)); + Print (stdout, 2, "Module `%s' (%u exports):\n", O->Name, CollCount (&O->Exports)); /* Insert the exports into the global table */ for (I = 0; I < CollCount (&O->Exports); ++I) { @@ -316,7 +319,7 @@ static void LibCheckExports (ObjData* O) const char* Name = CollConstAt (&O->Exports, I); /* Insert the name into the hash table */ - Print (stdout, 1, " %s\n", Name); + Print (stdout, 2, " %s\n", Name); ExpInsert (Name, O); } } diff --git a/src/ar65/main.c b/src/ar65/main.c index cf3c428f5..9af480632 100644 --- a/src/ar65/main.c +++ b/src/ar65/main.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2012, Ullrich von Bassewitz */ +/* (C) 1998-2013, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -60,11 +60,12 @@ static void Usage (void) /* Print usage information and exit */ { - printf ("Usage: %s lib file|module ...\n" - "Operation is one of:\n" + fprintf (stderr, "Usage: %s lib file|module ...\n" + "Operations are some of:\n" "\ta\tAdd modules\n" "\td\tDelete modules\n" "\tl\tList library contents\n" + "\tv\tIncrease verbosity (put before other operation)\n" "\tx\tExtract modules\n" "\tV\tPrint the archiver version\n", ProgName); From c88e0818b492017d01d1edb0c589e8a8613da58c Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 27 Sep 2013 21:49:45 +0200 Subject: [PATCH 126/144] Leave the character generator at $E000 like atarixl.cfg does. --- cfg/atarixl-overlay.cfg | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 5f19c6354..446b334c3 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -23,7 +23,7 @@ MEMORY { # "shadow RAM preparation" load chunk SRPREPHDR: file = %O, start = $0000, size = $0004; - SRPREPCHNK: file = %O, start = %S + __OVERLAYSIZE__, size = $7C20 - %S - __OVERLAYSIZE__ - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned + SRPREPCHNK: file = %O, define = yes, start = %S + __OVERLAYSIZE__, size = $7C20 - %S - __OVERLAYSIZE__ - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned SRPREPTRL: file = %O, start = $0000, size = $0006; # "main program" load chunk @@ -39,11 +39,14 @@ MEMORY { # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; -# address of relocated character generator - CHARGEN: file = "", define = yes, start = $D800, size = $0400; +# memory beneath the ROM preceeding the character generator + HIDDEN_RAM2: file = "", define = yes, start = $D800, size = $0800; + +# address of relocated character generator (same addess as ROM version) + CHARGEN: file = "", define = yes, start = $E000, size = $0400; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; + HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFF0 - $E400; # overlays OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; @@ -67,8 +70,8 @@ SEGMENTS { SRPREPHDR: load = SRPREPHDR, type = ro; LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM SRPREP: load = SRPREPCHNK, type = rw, define = yes; - SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; - SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; + SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM2, type = rw, define = yes, optional = yes; SRPREPTRL: load = SRPREPTRL, type = ro; MAINHDR: load = MAINHDR, type = ro; From 39a98f250b6cf587f1be952cfc0b7297ed82f33b Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 27 Sep 2013 22:01:54 +0200 Subject: [PATCH 127/144] untabify --- cfg/atarixl-largehimem.cfg | 8 +- cfg/atarixl.cfg | 8 +- libsrc/atari/ostype.s | 6 +- libsrc/atari/save_area.inc | 10 +- libsrc/atari/save_area.s | 20 +- libsrc/atari/scrdev.s | 2 +- libsrc/atari/shadow_ram_handlers.s | 1314 ++++++++++++++-------------- libsrc/atari/shadow_ram_prepare.s | 4 +- libsrc/atari/system_check.s | 140 +-- libsrc/atari/xlmemchk.inc | 106 +-- 10 files changed, 809 insertions(+), 809 deletions(-) diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 895cfe430..511ec4645 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -33,10 +33,10 @@ MEMORY { # "main program" load chunk MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + - __LOWDATA_SIZE__, size = $D000 - - __STACKSIZE__ - - %S - - __LOWDATA_SIZE__; + __LOWDATA_SIZE__, size = $D000 - + __STACKSIZE__ - + %S - + __LOWDATA_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index ceb4141af..6a7cd2873 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -28,10 +28,10 @@ MEMORY { # "main program" load chunk MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + - __LOWDATA_SIZE__, size = $D000 - - __STACKSIZE__ - - %S - - __LOWDATA_SIZE__; + __LOWDATA_SIZE__, size = $D000 - + __STACKSIZE__ - + %S - + __LOWDATA_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; diff --git a/libsrc/atari/ostype.s b/libsrc/atari/ostype.s index d2bf8888e..7248582a6 100644 --- a/libsrc/atari/ostype.s +++ b/libsrc/atari/ostype.s @@ -41,7 +41,7 @@ .export _get_ostype .include "atari.inc" - .include "romswitch.inc" + .include "romswitch.inc" .ifdef __ATARIXL__ @@ -50,8 +50,8 @@ .macro disable_rom_save_a pha - disable_rom - pla + disable_rom + pla .endmacro .else ; above atarixl, below atari diff --git a/libsrc/atari/save_area.inc b/libsrc/atari/save_area.inc index 3ec660203..ac433fded 100644 --- a/libsrc/atari/save_area.inc +++ b/libsrc/atari/save_area.inc @@ -6,8 +6,8 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -.import SAVMSC_save -.import MEMTOP_save -.import APPMHI_save -.import RAMTOP_save -.import PORTB_save +.import SAVMSC_save +.import MEMTOP_save +.import APPMHI_save +.import RAMTOP_save +.import PORTB_save diff --git a/libsrc/atari/save_area.s b/libsrc/atari/save_area.s index 5495be8ca..e46f3631e 100644 --- a/libsrc/atari/save_area.s +++ b/libsrc/atari/save_area.s @@ -8,18 +8,18 @@ .ifdef __ATARIXL__ -.export SAVMSC_save -.export MEMTOP_save -.export APPMHI_save -.export RAMTOP_save -.export PORTB_save +.export SAVMSC_save +.export MEMTOP_save +.export APPMHI_save +.export RAMTOP_save +.export PORTB_save .segment "LOWDATA" -SAVMSC_save: .res 2 -MEMTOP_save: .res 2 -APPMHI_save: .res 2 -RAMTOP_save: .res 1 -PORTB_save: .res 1 +SAVMSC_save: .res 2 +MEMTOP_save: .res 2 +APPMHI_save: .res 2 +RAMTOP_save: .res 1 +PORTB_save: .res 1 .endif diff --git a/libsrc/atari/scrdev.s b/libsrc/atari/scrdev.s index c9d5b6919..2d6ff3e07 100644 --- a/libsrc/atari/scrdev.s +++ b/libsrc/atari/scrdev.s @@ -1,6 +1,6 @@ ; Name of the "screen" device - .export scrdev + .export scrdev .rodata diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index ddc7b0842..09a59ea76 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -4,27 +4,27 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -DEBUG = 1 -CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) +DEBUG = 1 +CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) .ifdef __ATARIXL__ - SHRAM_HANDLERS = 1 + SHRAM_HANDLERS = 1 .include "atari.inc" - .include "save_area.inc" + .include "save_area.inc" .include "zeropage.inc" .include "romswitch.inc" - .import __CHARGEN_START__ + .import __CHARGEN_START__ - .export sram_init - .export KEYBDV_handler - .export CIO_handler - .export SIO_handler - .export SETVBV_handler + .export sram_init + .export KEYBDV_handler + .export CIO_handler + .export SIO_handler + .export SETVBV_handler -BUFSZ = 128 ; bounce buffer size -BUFSZ_SIO = 256 +BUFSZ = 128 ; bounce buffer size +BUFSZ_SIO = 256 .segment "INIT" @@ -33,45 +33,45 @@ BUFSZ_SIO = 256 sram_init: ; disable all interrupts - ldx #0 - stx NMIEN ; disable NMI - sei + ldx #0 + stx NMIEN ; disable NMI + sei ; disable ROMs - disable_rom + disable_rom ; setup interrupt vectors - lda #my_IRQ_han - sta $ffff + lda #my_IRQ_han + sta $ffff - lda #my_RESET_han - sta $fffd + lda #my_RESET_han + sta $fffd - lda #my_NMI_han - sta $fffb + lda #my_NMI_han + sta $fffb ; enable interrupts - cli - lda #$40 - sta NMIEN + cli + lda #$40 + sta NMIEN - rts + rts .segment "EXTZP" : zeropage -zpptr1: .res 2 +zpptr1: .res 2 .segment "LOWDATA" ; bounce buffers for CIO and SIO calls -bounce_buffer: .res BUFSZ_SIO +bounce_buffer: .res BUFSZ_SIO .segment "LOWCODE" @@ -86,71 +86,71 @@ bounce_buffer: .res BUFSZ_SIO ; aren't being called here because the vectors are pointing to their ; original ROM locations. -.macro int_wrap orgvec - .local ret - pha - enable_rom_quick - lda #>ret - pha - lda #ret + pha + lda # data too large for our buffers - ; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES - lda # data too large for our buffers + ; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES + lda # bounce buffer size? - bcs br_last ; no, last transfer, use remaining size + jsr cmp_orig_len_bnc_bufsz ; is transfer length > bounce buffer size? + bcs br_last ; no, last transfer, use remaining size - lda #>BUFSZ - sta ICBLH,x ; set data length - lda #BUFSZ + sta ICBLH,x ; set data length + lda # data too large for our buffers - ; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES - lda # data too large for our buffers + ; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES + lda # bounce buffer size? - bcs bw_last ; no, last transfer, use remaining size + jsr cmp_orig_len_bnc_bufsz ; is transfer length > bounce buffer size? + bcs bw_last ; no, last transfer, use remaining size - lda #>BUFSZ - sta ICBLH,x ; set data length - lda #BUFSZ + sta ICBLH,x ; set data length + lda #BUFSZ - sbc orig_len+1 - rts + sec + lda #BUFSZ + sbc orig_len+1 + rts ; copy data from bounce buffer into user buffer ; input: X - IOCB index ; zpptr1 - pointer to user buffer ; output: A - destroyed -; Y - 0 +; Y - 0 copy_to_user: - ldy ICBLL,x ; get # of bytes read (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES) - beq @copy_done -@copy: dey - lda bounce_buffer,y - sta (zpptr1),y - cpy #0 - bne @copy + ldy ICBLL,x ; get # of bytes read (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES) + beq @copy_done +@copy: dey + lda bounce_buffer,y + sta (zpptr1),y + cpy #0 + bne @copy @copy_done: - rts + rts ; copy data from user buffer into bounce buffer ; input: X - IOCB index ; zpptr1 - pointer to user buffer ; output: A - destroyed -; Y - 0 +; Y - 0 copy_from_user: - ldy ICBLL,x ; get # of bytes to write (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES) - beq @copy_done -@copy: dey - lda (zpptr1),y - sta bounce_buffer,y - cpy #0 - bne @copy + ldy ICBLL,x ; get # of bytes to write (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES) + beq @copy_done +@copy: dey + lda (zpptr1),y + sta bounce_buffer,y + cpy #0 + bne @copy @copy_done: - rts + rts ; copy ICBLL/ICBLH to 'orig_len' ; input: X - IOCB index ; output: A - destroyed iocblen_to_orig_len: - lda ICBLL,x - sta orig_len - lda ICBLH,x - sta orig_len+1 - rts + lda ICBLL,x + sta orig_len + lda ICBLH,x + sta orig_len+1 + rts ; copy ICBAL/ICBAH to 'orig_ptr' ; input: X - IOCB index ; output: A - destroyed iocbptr_to_orig_ptr: - lda ICBAL,x - sta orig_ptr - lda ICBAH,x - sta orig_ptr+1 - rts + lda ICBAL,x + sta orig_ptr + lda ICBAH,x + sta orig_ptr+1 + rts ; copy 'orig_ptr' to ICBAL/ICBAH ; input: X - IOCB index ; output: A - destroyed orig_ptr_to_iocbptr: - lda orig_ptr - sta ICBAL,x - lda orig_ptr+1 - sta ICBAH,x - rts + lda orig_ptr + sta ICBAL,x + lda orig_ptr+1 + sta ICBAH,x + rts ; restore original contents of ICBAL/ICBAH from 'zpptr1' ; input: X - IOCB index ; output: A - destroyed restore_icba: - lda zpptr1 - sta ICBAL,x - lda zpptr1+1 - sta ICBAH,x - rts + lda zpptr1 + sta ICBAL,x + lda zpptr1+1 + sta ICBAH,x + rts ; put bounce buffer address into ICBAL/ICBAH ; input: X - IOCB index ; output: A - destroyed bncbuf_to_iocb: - lda #bounce_buffer - sta ICBAH,x - rts + lda #bounce_buffer + sta ICBAH,x + rts ; copy file name pointed to by 'zpptr1' to 'bounce_buffer' @@ -667,15 +667,15 @@ bncbuf_to_iocb: ; output: Y - points to first invalid byte after file name ; A - destroyed copy_filename: - lda (zpptr1),y - sta bounce_buffer,y - beq copy_fn_done - iny - cmp #ATEOL - bne copy_filename - dey + lda (zpptr1),y + sta bounce_buffer,y + beq copy_fn_done + iny + cmp #ATEOL + bne copy_filename + dey copy_fn_done: - rts + rts ; write IOCB buffer address into zpptr1 @@ -683,13 +683,13 @@ copy_fn_done: ; output: Y - 0 (for setup_zpptr1_y0, else unchanged) ; A - destroyed setup_zpptr1_y0: - ldy #0 + ldy #0 setup_zpptr1: - lda ICBAL,x ; put buffer address into zp pointer - sta zpptr1 - lda ICBAH,x - sta zpptr1+1 - rts + lda ICBAL,x ; put buffer address into zp pointer + sta zpptr1 + lda ICBAH,x + sta zpptr1+1 + rts .if CHKBUF @@ -699,116 +699,116 @@ setup_zpptr1: ; output: Y - length ; A - destroyed get_fn_len: - lda (zpptr1),y - beq @done - iny - cmp #ATEOL - bne get_fn_len - dey + lda (zpptr1),y + beq @done + iny + cmp #ATEOL + bne get_fn_len + dey @done: - rts + rts chk_CIO_buf_fn2: - tya - pha - lda ICBLL,x - pha - lda ICBLH,x - pha - jsr setup_zpptr1_y0 - jsr get_fn_len - iny ; include terminating zero - bne fn_cont + tya + pha + lda ICBLL,x + pha + lda ICBLH,x + pha + jsr setup_zpptr1_y0 + jsr get_fn_len + iny ; include terminating zero + bne fn_cont chk_CIO_buf_fn: - tya - pha - lda ICBLL,x - pha - lda ICBLH,x - pha - jsr setup_zpptr1_y0 -fn_cont:jsr get_fn_len - iny ; include terminating zero - tya - sta ICBLL,x - lda #0 - sta ICBLH,x - jsr chk_CIO_buf - pla - sta ICBLH,x - pla - sta ICBLL,x - pla - tay - rts + tya + pha + lda ICBLL,x + pha + lda ICBLH,x + pha + jsr setup_zpptr1_y0 +fn_cont:jsr get_fn_len + iny ; include terminating zero + tya + sta ICBLL,x + lda #0 + sta ICBLH,x + jsr chk_CIO_buf + pla + sta ICBLH,x + pla + sta ICBLL,x + pla + tay + rts ; check if a CIO input/output buffer overlaps with ROM area (>= $C000) ; input: X - IOCB index -; ICBAL/ICBAH/ICBLL/ICBLH - buffer address and length +; ICBAL/ICBAH/ICBLL/ICBLH - buffer address and length ; output: CF - 1/0 for overlap/no overlap ; A - destroyed chk_CIO_buf: - lda ICBAH,x - cmp #$c0 - bcc @cont -@ret: + lda ICBAH,x + cmp #$c0 + bcc @cont +@ret: .ifdef DEBUG - jsr CIO_buf_noti + jsr CIO_buf_noti .endif - rts + rts -@cont: lda ICBAL,x - clc - adc ICBLL,x - lda ICBAH,x - adc ICBLH,x - bcs @ret ; ??? wraparound - cmp #$c0 +@cont: lda ICBAL,x + clc + adc ICBLL,x + lda ICBAH,x + adc ICBLH,x + bcs @ret ; ??? wraparound + cmp #$c0 .ifdef DEBUG - jsr CIO_buf_noti + jsr CIO_buf_noti .endif - rts + rts .ifdef DEBUG ; write to screen memory on 2nd line: ; pos 0: # of accesses without buffering ; pos 1: # of accesses with buffering CIO_buf_noti: - php - pha - tya - pha - bcc @nobuf + php + pha + tya + pha + bcc @nobuf - inc CIObnval_dobuf - jmp @cont + inc CIObnval_dobuf + jmp @cont -@nobuf: inc CIObnval_nobuf +@nobuf: inc CIObnval_nobuf -@cont: ldy #40 - lda CIObnval_nobuf - sta (SAVMSC),y - ldy #41 - lda CIObnval_dobuf - sta (SAVMSC),y +@cont: ldy #40 + lda CIObnval_nobuf + sta (SAVMSC),y + ldy #41 + lda CIObnval_dobuf + sta (SAVMSC),y - pla - tay - pla - plp - rts + pla + tay + pla + plp + rts CIObnval_dobuf: - .byte 0 + .byte 0 CIObnval_nobuf: - .byte 0 + .byte 0 .endif -.endif ; .if CHKBUF +.endif ; .if CHKBUF ;--------------------------------------------------------- @@ -818,36 +818,36 @@ CIObnval_nobuf: ; For other function we return NVALID status code. SIO_handler: - lda DCOMND ; get command - cmp #SIO_STAT - beq SIO_stat - cmp #SIO_READ - beq SIO_read - cmp #SIO_WRITE - beq SIO_write - cmp #SIO_WRITEV - beq SIO_write + lda DCOMND ; get command + cmp #SIO_STAT + beq SIO_stat + cmp #SIO_READ + beq SIO_read + cmp #SIO_WRITE + beq SIO_write + cmp #SIO_WRITEV + beq SIO_write - ; unhandled command - lda #NVALID -SIO_err:sta DSTATS - rts + ; unhandled command + lda #NVALID +SIO_err:sta DSTATS + rts ; SIO_STAT is always called with a low buffer (by the runtime) SIO_stat: - ; fall thru + ; fall thru SIO_call: - lda PORTB - sta cur_SIOV_PORTB - enable_rom - jsr SIOV_org - php - pha - disable_rom_val cur_SIOV_PORTB - pla - plp - rts + lda PORTB + sta cur_SIOV_PORTB + enable_rom + jsr SIOV_org + php + pha + disable_rom_val cur_SIOV_PORTB + pla + plp + rts ; SIO read handler @@ -856,50 +856,50 @@ SIO_call: SIO_read: .if CHKBUF - jsr chk_SIO_buf - bcc SIO_call + jsr chk_SIO_buf + bcc SIO_call .endif ; we only support transfers <= bounce buffer size - jsr cmp_sio_len_bnc_bufsz - bcs sio_read_len_ok + jsr cmp_sio_len_bnc_bufsz + bcs sio_read_len_ok - lda #DERROR ; don't know a better status code for this - bne SIO_err + lda #DERROR ; don't know a better status code for this + bne SIO_err sio_read_len_ok: - lda DBUFLO - sta zpptr1 ; remember destination buffer address - lda DBUFHI - sta zpptr1+1 + lda DBUFLO + sta zpptr1 ; remember destination buffer address + lda DBUFHI + sta zpptr1+1 - jsr bncbuf_to_dbuf ; put bounce buffer address to DBUFLO/DBUFHI + jsr bncbuf_to_dbuf ; put bounce buffer address to DBUFLO/DBUFHI - jsr SIO_call ; do the operation - pha - lda DSTATS ; get status - bmi sio_read_ret ; error + jsr SIO_call ; do the operation + pha + lda DSTATS ; get status + bmi sio_read_ret ; error - ; copy data to user buffer + ; copy data to user buffer sio_read_ok: - lda DBYTHI ; could be 1 for 256 bytes - beq srok1 - ldy #0 - beq srok2 -srok1: ldy DBYTLO -srok2: dey + lda DBYTHI ; could be 1 for 256 bytes + beq srok1 + ldy #0 + beq srok2 +srok1: ldy DBYTLO +srok2: dey sio_read_copy: - lda bounce_buffer,y - sta (zpptr1),y - dey - cpy #$ff - bne sio_read_copy + lda bounce_buffer,y + sta (zpptr1),y + dey + cpy #$ff + bne sio_read_copy sio_read_ret: - jsr orgbuf_to_dbuf + jsr orgbuf_to_dbuf - pla - rts ; success return + pla + rts ; success return ; SIO write handler @@ -908,44 +908,44 @@ sio_read_ret: SIO_write: .if CHKBUF - jsr chk_SIO_buf - bcc SIO_call + jsr chk_SIO_buf + bcc SIO_call .endif ; we only support transfers <= bounce buffer size - jsr cmp_sio_len_bnc_bufsz - bcs sio_write_len_ok + jsr cmp_sio_len_bnc_bufsz + bcs sio_write_len_ok - lda #DERROR ; don't know a better status code for this - jmp SIO_err + lda #DERROR ; don't know a better status code for this + jmp SIO_err sio_write_len_ok: - lda DBUFLO - sta zpptr1 ; get source buffer address - lda DBUFHI - sta zpptr1+1 + lda DBUFLO + sta zpptr1 ; get source buffer address + lda DBUFHI + sta zpptr1+1 - ; copy data from user buffer to bounce buffer - lda DBYTHI ; could be 1 for 256 bytes - beq swok1 - ldy #0 - beq swok2 -swok1: ldy DBYTLO -swok2: dey + ; copy data from user buffer to bounce buffer + lda DBYTHI ; could be 1 for 256 bytes + beq swok1 + ldy #0 + beq swok2 +swok1: ldy DBYTLO +swok2: dey sio_write_copy: - lda (zpptr1),y - sta bounce_buffer,y - dey - cpy #$ff - bne sio_write_copy + lda (zpptr1),y + sta bounce_buffer,y + dey + cpy #$ff + bne sio_write_copy - jsr bncbuf_to_dbuf ; put bounce buffer address to DBUFLO/DBUFHI + jsr bncbuf_to_dbuf ; put bounce buffer address to DBUFLO/DBUFHI - jsr SIO_call ; do the operation - pha - jsr orgbuf_to_dbuf - pla - rts + jsr SIO_call ; do the operation + pha + jsr orgbuf_to_dbuf + pla + rts ; check if SIO length is larger than bounce buffer size @@ -953,32 +953,32 @@ sio_write_copy: ; output: A - destroyed ; CF - 0/1 for larger/not larger cmp_sio_len_bnc_bufsz: - sec - lda #BUFSZ_SIO - sbc DBYTHI - rts + sec + lda #BUFSZ_SIO + sbc DBYTHI + rts ; put bounce buffer address into DBUFLO/DBUFHI ; input: (--) ; output: A - destroyed bncbuf_to_dbuf: - lda #bounce_buffer - sta DBUFHI - rts + lda #bounce_buffer + sta DBUFHI + rts ; put original buffer address into DBUFLO/DBUFHI ; input: zpptr1 - original pointer ; output: A - destroyed orgbuf_to_dbuf: - lda zpptr1 - sta DBUFLO - lda zpptr1+1 - sta DBUFHI - rts + lda zpptr1 + sta DBUFLO + lda zpptr1+1 + sta DBUFHI + rts .if CHKBUF @@ -989,113 +989,113 @@ orgbuf_to_dbuf: ; A - destroyed chk_SIO_buf: - lda DBUFHI - cmp #$c0 - bcc @cont + lda DBUFHI + cmp #$c0 + bcc @cont @ret: .ifdef DEBUG - jsr SIO_buf_noti + jsr SIO_buf_noti .endif - rts + rts -@cont: lda DBUFLO - clc - adc DBYTLO - lda DBUFHI - adc DBYTHI - bcs @ret ; ??? wraparound - cmp #$c0 +@cont: lda DBUFLO + clc + adc DBYTLO + lda DBUFHI + adc DBYTHI + bcs @ret ; ??? wraparound + cmp #$c0 .ifdef DEBUG - jsr SIO_buf_noti + jsr SIO_buf_noti .endif - rts + rts .ifdef DEBUG ; write to screen memory on 2nd line: ; pos 38: # of accesses without buffering ; pos 39: # of accesses with buffering SIO_buf_noti: - php - pha - tya - pha - bcc @nobuf + php + pha + tya + pha + bcc @nobuf - inc SIObnval_dobuf - jmp @cont + inc SIObnval_dobuf + jmp @cont -@nobuf: inc SIObnval_nobuf +@nobuf: inc SIObnval_nobuf -@cont: ldy #78 - lda SIObnval_nobuf - sta (SAVMSC),y - ldy #79 - lda SIObnval_dobuf - sta (SAVMSC),y +@cont: ldy #78 + lda SIObnval_nobuf + sta (SAVMSC),y + ldy #79 + lda SIObnval_dobuf + sta (SAVMSC),y - pla - tay - pla - plp - rts + pla + tay + pla + plp + rts SIObnval_dobuf: - .byte 0 + .byte 0 SIObnval_nobuf: - .byte 0 + .byte 0 .endif -.endif ; .if CHKBUF +.endif ; .if CHKBUF ;--------------------------------------------------------- KEYBDV_handler: - lda #>(kret-1) - pha - lda #<(kret-1) - pha - lda PORTB - sta cur_KEYBDV_PORTB - enable_rom - lda KEYBDV+5 + lda #>(kret-1) + pha + lda #<(kret-1) + pha + lda PORTB + sta cur_KEYBDV_PORTB + enable_rom + lda KEYBDV+5 pha lda KEYBDV+4 pha - rts ; call keyboard handler -kret: pha - disable_rom_val cur_KEYBDV_PORTB - pla - rts + rts ; call keyboard handler +kret: pha + disable_rom_val cur_KEYBDV_PORTB + pla + rts ;--------------------------------------------------------- SETVBV_handler: - pha - lda PORTB - sta cur_SETVBV_PORTB - enable_rom - pla - jsr SETVBV_org - php - pha - disable_rom_val cur_SETVBV_PORTB - pla - plp - rts + pha + lda PORTB + sta cur_SETVBV_PORTB + enable_rom + pla + jsr SETVBV_org + php + pha + disable_rom_val cur_SETVBV_PORTB + pla + plp + rts -CIO_a: .res 1 -CIO_x: .res 1 -CIO_y: .res 1 -CIO_p: .res 1 -cur_CIOV_PORTB: .res 1 -cur_SIOV_PORTB: .res 1 -cur_KEYBDV_PORTB: .res 1 -cur_SETVBV_PORTB: .res 1 -orig_ptr: .res 2 -orig_len: .res 2 -req_len: .res 2 -retlen: .res 2 +CIO_a: .res 1 +CIO_x: .res 1 +CIO_y: .res 1 +CIO_p: .res 1 +cur_CIOV_PORTB: .res 1 +cur_SIOV_PORTB: .res 1 +cur_KEYBDV_PORTB: .res 1 +cur_SETVBV_PORTB: .res 1 +orig_ptr: .res 2 +orig_len: .res 2 +req_len: .res 2 +retlen: .res 2 -.endif ; .ifdef __ATARIXL__ +.endif ; .ifdef __ATARIXL__ diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index be40baed3..bffabc059 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -90,7 +90,7 @@ sramprep: lda lodadr+1 sta RAMTOP - ; set APPMHI to MEMLO (+ 1 for sanity) + ; set APPMHI to MEMLO (+ 1 for sanity) lda MEMLO clc adc #1 @@ -104,7 +104,7 @@ sramprep: jsr findfreeiocb -.ifdef DEBUG ; only check in debug version, this shouldn't really happen(tm) +.ifdef DEBUG ; only check in debug version, this shouldn't really happen(tm) beq iocbok print_string "Internal error, no free IOCB!" jsr delay diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index b01311a4b..b1f823aad 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -11,11 +11,11 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -DEBUG = 1 +DEBUG = 1 .ifdef __ATARIXL__ - .export syschk + .export syschk .import __SYSCHK_LOAD__ .import __STARTADDRESS__ ; needed by xlmemchk.inc @@ -24,36 +24,36 @@ DEBUG = 1 .macro print_string text - .local start, cont - jmp cont -start: .byte text, ATEOL -cont: ldx #0 ; channel 0 - lda #start - sta ICBAH,x - lda #<(cont - start) - sta ICBLL,x ; length - lda #>(cont - start) - sta ICBLH,x - lda #PUTCHR - sta ICCOM,x - jsr CIOV_org + .local start, cont + jmp cont +start: .byte text, ATEOL +cont: ldx #0 ; channel 0 + lda #start + sta ICBAH,x + lda #<(cont - start) + sta ICBLL,x ; length + lda #>(cont - start) + sta ICBLH,x + lda #PUTCHR + sta ICCOM,x + jsr CIOV_org .endmacro .macro print_string2 addr, len - ldx #0 ; channel 0 - lda #addr - sta ICBAH,x - lda #len - sta ICBLH,x - lda #PUTCHR - sta ICCOM,x - jsr CIOV_org + ldx #0 ; channel 0 + lda #addr + sta ICBAH,x + lda #len + sta ICBLH,x + lda #PUTCHR + sta ICCOM,x + jsr CIOV_org .endmacro @@ -72,74 +72,74 @@ cont: ldx #0 ; channel 0 .segment "SYSCHK" ; no XL machine -no_xl: print_string "This program needs an XL machine." - jmp fail +no_xl: print_string "This program needs an XL machine." + jmp fail ; entry point syschk: - lda $fcd8 ; from ostype.s + lda $fcd8 ; from ostype.s cmp #$a2 beq no_xl ; we have an XL machine, now check memory - lda RAMSIZ - cmp #$80 - bcs sys_ok + lda RAMSIZ + cmp #$80 + bcs sys_ok ; not enough memory - print_string "Not enough memory." -fail: jsr delay - jmp (DOSVEC) + print_string "Not enough memory." +fail: jsr delay + jmp (DOSVEC) sys_ok: - .include "xlmemchk.inc" ; calculate lowest address we will use when we move the screen buffer down + .include "xlmemchk.inc" ; calculate lowest address we will use when we move the screen buffer down - sec - lda MEMLO - sbc lowadr - lda MEMLO+1 - sbc lowadr+1 - bcc memlo_ok + sec + lda MEMLO + sbc lowadr + lda MEMLO+1 + sbc lowadr+1 + bcc memlo_ok ; load address was too low - print_string2 lmemerr_txt, lmemerr_txt_len - jsr delay ; long text takes longer to read, give user additional time - jmp fail + print_string2 lmemerr_txt, lmemerr_txt_len + jsr delay ; long text takes longer to read, give user additional time + jmp fail ; all is well(tm), launch the application memlo_ok: .ifdef DEBUG - print_string "Stage #1 OK" - jsr delay + print_string "Stage #1 OK" + jsr delay .endif - rts + rts lmemerr_txt: - .byte "Not enough memory to move screen", ATEOL - .byte "memory to low memory. Consider using", ATEOL - .byte "a higher load address.", ATEOL -lmemerr_txt_len = * - lmemerr_txt + .byte "Not enough memory to move screen", ATEOL + .byte "memory to low memory. Consider using", ATEOL + .byte "a higher load address.", ATEOL +lmemerr_txt_len = * - lmemerr_txt ; short delay -.proc delay +.proc delay - lda #10 -l: jsr delay1 - clc - sbc #0 - bne l - rts + lda #10 +l: jsr delay1 + clc + sbc #0 + bne l + rts -delay1: ldx #0 - ldy #0 -loop: dey - bne loop - dex - bne loop - rts +delay1: ldx #0 + ldy #0 +loop: dey + bne loop + dex + bne loop + rts .endproc @@ -154,4 +154,4 @@ end: .word INITAD+1 .word syschk -.endif ; .ifdef __ATARIXL__ +.endif ; .ifdef __ATARIXL__ diff --git a/libsrc/atari/xlmemchk.inc b/libsrc/atari/xlmemchk.inc index d2a079557..f8be1c137 100644 --- a/libsrc/atari/xlmemchk.inc +++ b/libsrc/atari/xlmemchk.inc @@ -9,12 +9,12 @@ ; by the screen memory afterwards. ; ; inputs: -; __STARTADDRESS__ - load address of the program +; __STARTADDRESS__ - load address of the program ; outputs: -; lodadr - (high byte only) value to -; write into RAMTOP -; lowadr - lowest address occupied by -; screen data +; lodadr - (high byte only) value to +; write into RAMTOP +; lowadr - lowest address occupied by +; screen data ; @@ -35,85 +35,85 @@ ; available memory, boundary crossing cannot happen. -SCRBUFSZ = (40 * 24) ; size of mode 0 screen buffer -DLSZ = 32 ; size of mode 0 display list +SCRBUFSZ = (40 * 24) ; size of mode 0 screen buffer +DLSZ = 32 ; size of mode 0 display list scrmemtst: ; subtract screen memory size from our load address - lda lodadr - sec - sbc #SCRBUFSZ - sta tstadr+1 + lda lodadr + sec + sbc #SCRBUFSZ + sta tstadr+1 ; check if a 4K boundary is crossed - lda lodadr+1 - and #$f0 - sta tmp - lda tstadr+1 - and #$f0 - cmp tmp - beq scrmemok + lda lodadr+1 + and #$f0 + sta tmp + lda tstadr+1 + and #$f0 + cmp tmp + beq scrmemok ; if lodadr is at an exact 4K boundary, it's still ok - lda lodadr+1 - and #$0f - beq scrmemok + lda lodadr+1 + and #$0f + beq scrmemok ; 4K boundary will be crossed, use this 4K boundary address as lodadr -al4k: lda lodadr+1 - and #$f0 - sta lodadr+1 - bne scrmemtst +al4k: lda lodadr+1 + and #$f0 + sta lodadr+1 + bne scrmemtst ; not reached .ifdef DEBUG .byte "XLMEMCHK:>" .endif -lodadr: .word __STARTADDRESS__ & $FF00 ; our program's load address, rounded down to page boundary -tstadr: .res 2 -lowadr: .res 2 -tmp: .res 1 +lodadr: .word __STARTADDRESS__ & $FF00 ; our program's load address, rounded down to page boundary +tstadr: .res 2 +lowadr: .res 2 +tmp: .res 1 ; subtract display list size from calculated screen address scrmemok: - lda tstadr - sec - sbc #DLSZ - sta lowadr+1 + lda tstadr + sec + sbc #DLSZ + sta lowadr+1 -.if 0 ; this cannot happen +.if 0 ; this cannot happen ; check if a 1K boundary is crossed - lda tstadr+1 - and #$fc - sta tmp - lda lowadr+1 - and #$fc - cmp tmp - bne al4k ; 1K boundary will be crossed, decrease lodadr + lda tstadr+1 + and #$fc + sta tmp + lda lowadr+1 + and #$fc + cmp tmp + bne al4k ; 1K boundary will be crossed, decrease lodadr .endif ; address of display list is ok ; decrease lowadr by two - lda lowadr - sec - sbc #2 - sta lowadr - bcs dec_cont - dec lowadr+1 + lda lowadr + sec + sbc #2 + sta lowadr + bcs dec_cont + dec lowadr+1 dec_cont: From 213f93cce43218c35bda92b2ae1c2120d627ce25 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 27 Sep 2013 22:14:26 +0200 Subject: [PATCH 128/144] disable DEBUG --- libsrc/atari/shadow_ram_handlers.s | 2 +- libsrc/atari/shadow_ram_prepare.s | 41 +++++++++++++++--------------- libsrc/atari/system_check.s | 2 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 09a59ea76..78709c38c 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -4,7 +4,7 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -DEBUG = 1 +;DEBUG = 1 CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) .ifdef __ATARIXL__ diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index bffabc059..a08aa8cfe 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -9,7 +9,7 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -DEBUG = 1 +;DEBUG = 1 .ifdef __ATARIXL__ @@ -349,6 +349,25 @@ restore:lda RAMTOP_save sta APPMHI+1 rts +; short delay +.proc delay + + lda #10 +@loop: jsr delay1 + clc + sbc #0 + bne @loop + rts + +delay1: ldx #0 + ldy #0 +@loop: dey + bne @loop + dex + bne @loop + rts + +.endproc .ifdef DEBUG @@ -357,26 +376,6 @@ restore:lda RAMTOP_save sramsize: .word __SHADOW_RAM_SIZE__ -; short delay -.proc delay - - lda #10 -l: jsr delay1 - clc - sbc #0 - bne l - rts - -delay1: ldx #0 - ldy #0 -loop: dey - bne loop - dex - bne loop - rts - -.endproc - .endif ; .ifdef DEBUG screen_device: .byte "S:",0 diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index b1f823aad..5a23546f0 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -11,7 +11,7 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -DEBUG = 1 +;DEBUG = 1 .ifdef __ATARIXL__ From 7fb0cf4bb23fdf0c31fb8b5e112eb0e021c41c76 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 1 Oct 2013 11:32:08 +0200 Subject: [PATCH 129/144] Some formatting and style fixes. --- asminc/atari.inc | 8 ++-- cfg/atarixl-largehimem.cfg | 38 +++++++++--------- cfg/atarixl-overlay.cfg | 56 +++++++++++++-------------- cfg/atarixl.cfg | 38 +++++++++--------- libsrc/atari/crt0.s | 25 +++--------- libsrc/atari/irq.s | 2 +- libsrc/atari/shadow_ram_handlers.s | 8 ++-- libsrc/atari/tgi/atari_tgi_common.inc | 6 +-- 8 files changed, 84 insertions(+), 97 deletions(-) diff --git a/asminc/atari.inc b/asminc/atari.inc index 864b59808..c60f6642d 100644 --- a/asminc/atari.inc +++ b/asminc/atari.inc @@ -1002,16 +1002,16 @@ CASETV = $E440 ;cassette handler vector table DISKIV = $E450 ;vector to initialize DIO DSKINV = $E453 ;vector to DIO -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ .ifndef SHRAM_HANDLERS .import CIO_handler, SIO_handler, SETVBV_handler .endif .define CIOV CIO_handler .define SIOV SIO_handler .define SETVBV SETVBV_handler -CIOV_org = $E456 ;vector to CIO -SIOV_org = $E459 ;vector to SIO -SETVBV_org = $E45C ;vector to set VBLANK parameters +CIOV_org = $E456 ;vector to CIO +SIOV_org = $E459 ;vector to SIO +SETVBV_org = $E45C ;vector to set VBLANK parameters .else CIOV = $E456 ;vector to CIO SIOV = $E459 ;vector to SIO diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 511ec4645..d34494772 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -49,30 +49,30 @@ MEMORY { } SEGMENTS { - EXEHDR: load = HEADER, type = ro; + EXEHDR: load = HEADER, type = ro; - SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; - SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; - SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; + SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; - SRPREPHDR: load = SRPREPHDR, type = ro; - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM - SRPREP: load = SRPREPCHNK, type = rw, define = yes; + SRPREPHDR: load = SRPREPHDR, type = ro; + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; - SRPREPTRL: load = SRPREPTRL, type = ro; + SRPREPTRL: load = SRPREPTRL, type = ro; - MAINHDR: load = MAINHDR, type = ro; - STARTUP: load = RAM, type = ro, define = yes; - LOWCODE: load = RAM, type = ro, define = yes, optional = yes; - INIT: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro, define = yes; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = zp, optional = yes; - AUTOSTRT: load = TRAILER, type = ro; + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; } FEATURES { CONDES: type = constructor, diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 446b334c3..a07d8b27a 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -61,40 +61,40 @@ MEMORY { } SEGMENTS { - EXEHDR: load = HEADER, type = ro; + EXEHDR: load = HEADER, type = ro; - SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; - SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; - SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; + SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; - SRPREPHDR: load = SRPREPHDR, type = ro; - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM - SRPREP: load = SRPREPCHNK, type = rw, define = yes; + SRPREPHDR: load = SRPREPHDR, type = ro; + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM2, type = rw, define = yes, optional = yes; - SRPREPTRL: load = SRPREPTRL, type = ro; + SRPREPTRL: load = SRPREPTRL, type = ro; - MAINHDR: load = MAINHDR, type = ro; - STARTUP: load = RAM, type = ro, define = yes; - LOWCODE: load = RAM, type = ro, define = yes, optional = yes; - INIT: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro, define = yes; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = zp, optional = yes; - AUTOSTRT: load = TRAILER, type = ro; + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; - OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; - OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; - OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; - OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; - OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; - OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; - OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; - OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; - OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; + OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; + OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; + OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; + OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; + OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; + OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; + OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; + OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; + OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 6a7cd2873..55a14a5e0 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -47,30 +47,30 @@ MEMORY { } SEGMENTS { - EXEHDR: load = HEADER, type = ro; + EXEHDR: load = HEADER, type = ro; - SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; - SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; - SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; + SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; - SRPREPHDR: load = SRPREPHDR, type = ro; - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM - SRPREP: load = SRPREPCHNK, type = rw, define = yes; + SRPREPHDR: load = SRPREPHDR, type = ro; + LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM2, type = rw, define = yes, optional = yes; - SRPREPTRL: load = SRPREPTRL, type = ro; + SRPREPTRL: load = SRPREPTRL, type = ro; - MAINHDR: load = MAINHDR, type = ro; - STARTUP: load = RAM, type = ro, define = yes; - LOWCODE: load = RAM, type = ro, define = yes, optional = yes; - INIT: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro, define = yes; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = zp, optional = yes; - AUTOSTRT: load = TRAILER, type = ro; + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; } FEATURES { CONDES: type = constructor, diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index f1cadd992..72a0c3198 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -100,23 +100,6 @@ start: jsr initlib -.if 0 -.ifdef __ATARIXL__ - .import __heapadd - .import pushax - .import __RAM_BELOW_ROM_START__ - .import __RAM_BELOW_ROM_SIZE__ - .import __RAM_BELOW_ROM_LAST__ - - lda #<__RAM_BELOW_ROM_LAST__ - ldx #>__RAM_BELOW_ROM_LAST__ - jsr pushax - lda #<(__RAM_BELOW_ROM_SIZE__ - (__RAM_BELOW_ROM_LAST__ - __RAM_BELOW_ROM_START__)) - ldx #>(__RAM_BELOW_ROM_SIZE__ - (__RAM_BELOW_ROM_LAST__ - __RAM_BELOW_ROM_START__)) - jsr __heapadd -.endif -.endif - ; Set left margin to 0 lda LMARGN @@ -179,7 +162,9 @@ _exit: jsr donelib ; Run module destructors sta MEMTOP+1 -; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) +; Issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) in +; order to restore screen memory to its defailt location just +; before the ROM. jsr findfreeiocb @@ -199,7 +184,9 @@ _exit: jsr donelib ; Run module destructors lda #0 sta ICBLH,x jsr CIOV_org -; add error checking here... +; No error checking here, shouldn't happen(tm), and no way to +; recover anyway. + lda #CLOSE sta ICCOM,x jsr CIOV_org diff --git a/libsrc/atari/irq.s b/libsrc/atari/irq.s index 4a266630c..8ec1b12df 100644 --- a/libsrc/atari/irq.s +++ b/libsrc/atari/irq.s @@ -51,7 +51,7 @@ IRQStub: .endif lda PORTB pha - and #$fe + and #$FE sta PORTB ; disable ROM set_chbase >__CHARGEN_START__ .endif diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index 78709c38c..a01363318 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -4,12 +4,12 @@ ; Christian Groessler, chris@groessler.org, 2013 ; -;DEBUG = 1 -CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) +;DEBUG = 1 +CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0) .ifdef __ATARIXL__ - SHRAM_HANDLERS = 1 +SHRAM_HANDLERS = 1 .include "atari.inc" .include "save_area.inc" .include "zeropage.inc" @@ -23,7 +23,7 @@ CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering .export SIO_handler .export SETVBV_handler -BUFSZ = 128 ; bounce buffer size +BUFSZ = 128 ; bounce buffer size BUFSZ_SIO = 256 .segment "INIT" diff --git a/libsrc/atari/tgi/atari_tgi_common.inc b/libsrc/atari/tgi/atari_tgi_common.inc index 7151d2d1e..0d7972d34 100644 --- a/libsrc/atari/tgi/atari_tgi_common.inc +++ b/libsrc/atari/tgi/atari_tgi_common.inc @@ -4,7 +4,7 @@ .macpack longbranch -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ CIO_vec := my_CIOV .else CIO_vec := CIOV @@ -117,7 +117,7 @@ libref: .addr $0000 ; Library reference text_dir: .byte 0 ; Text direction, -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ my_CIOV: .byte $4C, 0, 0 .endif @@ -171,7 +171,7 @@ screen_device_length := * - screen_device stx mask -.if .defined(__ATARIXL__) +.ifdef __ATARIXL__ ; setup pointer to CIO From 35388418fda7fada093cc0f3bf0583b078ad56af Mon Sep 17 00:00:00 2001 From: Emanuele Fornara Date: Wed, 2 Oct 2013 20:55:01 +0100 Subject: [PATCH 130/144] fixed timep handling in time() --- libsrc/common/time.s | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libsrc/common/time.s b/libsrc/common/time.s index 2157eb49f..140d47e2c 100644 --- a/libsrc/common/time.s +++ b/libsrc/common/time.s @@ -27,10 +27,10 @@ ; Restore timep and check if it is NULL pla - sta ptr1 + sta ptr1+1 pla - sta ptr1+1 ; Restore timep - ora ptr1 ; timep == 0? + sta ptr1 ; Restore timep + ora ptr1+1 ; timep == 0? beq @L1 ; timep is not NULL, store the result there From 417110d3416218d014644ac583223d99f46e70dd Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 3 Oct 2013 14:11:35 +0200 Subject: [PATCH 131/144] Use all available memory below the ROM. --- cfg/atarixl-largehimem.cfg | 2 +- cfg/atarixl-overlay.cfg | 3 ++- cfg/atarixl.cfg | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index d34494772..7af90e214 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -45,7 +45,7 @@ MEMORY { CHARGEN: file = "", define = yes, start = $D800, size = $0400; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $DC00, size = $FFF0 - $DC00; + HIDDEN_RAM: file = "", define = yes, start = $DC00, size = $FFFA - $DC00; } SEGMENTS { diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index a07d8b27a..42cc5fac9 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -1,3 +1,4 @@ +B FEATURES { STARTADDRESS: default = $2400; } @@ -46,7 +47,7 @@ MEMORY { CHARGEN: file = "", define = yes, start = $E000, size = $0400; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFF0 - $E400; + HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFFA - $E400; # overlays OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 55a14a5e0..04a260059 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -43,7 +43,7 @@ MEMORY { CHARGEN: file = "", define = yes, start = $E000, size = $0400; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFF0 - $E400; + HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFFA - $E400; } SEGMENTS { From 73d38b0ff23c065ee9430bfa27b60400b7290bc4 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 3 Oct 2013 14:15:39 +0200 Subject: [PATCH 132/144] Fix typo in last change. --- cfg/atarixl-overlay.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 42cc5fac9..3437238b6 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -1,4 +1,3 @@ -B FEATURES { STARTADDRESS: default = $2400; } From 700fd4f18788827c16f8ff73014da158c9d42c6b Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 4 Oct 2013 00:53:34 +0200 Subject: [PATCH 133/144] Enable "system check" load chunk for non-XL Atari target. --- cfg/atari-overlay.cfg | 84 +++++++++++++--------- cfg/atari.cfg | 46 ++++++++---- libsrc/atari/crt0.s | 2 - libsrc/atari/system_check.s | 138 ++++++++++++++++++++++++++---------- 4 files changed, 182 insertions(+), 88 deletions(-) diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg index 6ccb5f602..dae56fce9 100644 --- a/cfg/atari-overlay.cfg +++ b/cfg/atari-overlay.cfg @@ -4,44 +4,62 @@ FEATURES { SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay + __STARTADDRESS__: type = export, value = %S; __RESERVED_MEMORY__: type = weak, value = $0000; + syschk: type = import; # force inclusion of SYSCHK } MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; - HEADER: file = %O, start = $0000, size = $0006; - RAM: file = %O, start = %S + __OVERLAYSIZE__, size = $BC20 - __STACKSIZE__ - __OVERLAYSIZE__ - %S; - TRAILER: file = %O, start = $0000, size = $0006; - OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; - OVL2: file = "%O.2", start = %S, size = __OVERLAYSIZE__; - OVL3: file = "%O.3", start = %S, size = __OVERLAYSIZE__; - OVL4: file = "%O.4", start = %S, size = __OVERLAYSIZE__; - OVL5: file = "%O.5", start = %S, size = __OVERLAYSIZE__; - OVL6: file = "%O.6", start = %S, size = __OVERLAYSIZE__; - OVL7: file = "%O.7", start = %S, size = __OVERLAYSIZE__; - OVL8: file = "%O.8", start = %S, size = __OVERLAYSIZE__; - OVL9: file = "%O.9", start = %S, size = __OVERLAYSIZE__; + ZP: file = "", define = yes, start = $0082, size = $007E; + +# file header, just $FFFF + HEADER: file = %O, start = $0000, size = $0002; + +# "system check" load chunk + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; + SYSCHKTRL: file = %O, start = $0000, size = $0006; + +# "main program" load chunk + MAINHDR: file = %O, start = $0000, size = $0004; + RAM: file = %O, define = yes, start = %S + __OVERLAYSIZE__, + size = $BC20 - __OVERLAYSIZE__ - __STACKSIZE__ - __RESERVED_MEMORY__ - %S; + TRAILER: file = %O, start = $0000, size = $0006; + + OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; + OVL2: file = "%O.2", start = %S, size = __OVERLAYSIZE__; + OVL3: file = "%O.3", start = %S, size = __OVERLAYSIZE__; + OVL4: file = "%O.4", start = %S, size = __OVERLAYSIZE__; + OVL5: file = "%O.5", start = %S, size = __OVERLAYSIZE__; + OVL6: file = "%O.6", start = %S, size = __OVERLAYSIZE__; + OVL7: file = "%O.7", start = %S, size = __OVERLAYSIZE__; + OVL8: file = "%O.8", start = %S, size = __OVERLAYSIZE__; + OVL9: file = "%O.9", start = %S, size = __OVERLAYSIZE__; } SEGMENTS { - EXEHDR: load = HEADER, type = ro; - STARTUP: load = RAM, type = ro, define = yes; - LOWCODE: load = RAM, type = ro, define = yes, optional = yes; - INIT: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro, define = yes; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = zp, optional = yes; - AUTOSTRT: load = TRAILER, type = ro; - OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; - OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; - OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; - OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; - OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; - OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; - OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; - OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; - OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; + EXEHDR: load = HEADER, type = ro; + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; + SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; + OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; + OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; + OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; + OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; + OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; + OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; + OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; + OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; + OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/atari.cfg b/cfg/atari.cfg index a82f64f74..df74b9aa9 100644 --- a/cfg/atari.cfg +++ b/cfg/atari.cfg @@ -3,26 +3,42 @@ FEATURES { } SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack + __STARTADDRESS__: type = export, value = %S; __RESERVED_MEMORY__: type = weak, value = $0000; + syschk: type = import; # force inclusion of SYSCHK } MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; - HEADER: file = %O, start = $0000, size = $0006; - RAM: file = %O, start = %S, size = $BC20 - __STACKSIZE__ - %S; - TRAILER: file = %O, start = $0000, size = $0006; + ZP: file = "", define = yes, start = $0082, size = $007E; + +# file header, just $FFFF + HEADER: file = %O, start = $0000, size = $0002; + +# "system check" load chunk + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; + SYSCHKTRL: file = %O, start = $0000, size = $0006; + +# "main program" load chunk + MAINHDR: file = %O, start = $0000, size = $0004; + RAM: file = %O, define = yes, start = %S, size = $BC20 - __STACKSIZE__ - __RESERVED_MEMORY__ - %S; + TRAILER: file = %O, start = $0000, size = $0006; } SEGMENTS { - EXEHDR: load = HEADER, type = ro; - STARTUP: load = RAM, type = ro, define = yes; - LOWCODE: load = RAM, type = ro, define = yes, optional = yes; - INIT: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro, define = yes; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = zp, optional = yes; - AUTOSTRT: load = TRAILER, type = ro; + EXEHDR: load = HEADER, type = ro; + SYSCHKHDR: load = SYSCHKHDR, type = ro, optional = yes; + SYSCHK: load = SYSCHKCHNK, type = rw, define = yes, optional = yes; + SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; + MAINHDR: load = MAINHDR, type = ro; + STARTUP: load = RAM, type = ro, define = yes; + LOWCODE: load = RAM, type = ro, define = yes, optional = yes; + INIT: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, optional = yes; + AUTOSTRT: load = TRAILER, type = ro; } FEATURES { CONDES: type = constructor, diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 72a0c3198..de72c1eb8 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -34,9 +34,7 @@ .word $FFFF -.ifdef __ATARIXL__ .segment "MAINHDR" -.endif .word __STARTUP_LOAD__ .word __BSS_LOAD__ - 1 diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index 5a23546f0..9dd42f154 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -1,11 +1,14 @@ ; -; Atari XL startup system check +; Atari startup system check ; ; This routine gets loaded prior to the main part of the executable ; and checks if the system is compatible to run the program. -; It checks whether the system is an XL type one and that enough -; memory is installed (which isn't the case for a 600XL). -; If the system doesn't qualify, the loading of the main program +; For the XL target it checks whether the system is an XL type one +; and that enough memory is installed (which isn't the case for a 600XL). +; For the non-XL target it checks whether there is enough memory +; installed to run the program. +; For both target it checks that the program won't load below MEMLO. +; If one of the checks fails the loading of the main program ; is aborted by jumping to DOSVEC. ; ; Christian Groessler, chris@groessler.org, 2013 @@ -13,11 +16,14 @@ ;DEBUG = 1 -.ifdef __ATARIXL__ - .export syschk .import __SYSCHK_LOAD__ - .import __STARTADDRESS__ ; needed by xlmemchk.inc + .import __STARTADDRESS__ + + ; the following imports are only needed for the 'atari' target version + .import __BSS_SIZE__, __BSS_RUN__ + .import __STACKSIZE__ + .import __RESERVED_MEMORY__ .include "zeropage.inc" .include "atari.inc" @@ -59,25 +65,26 @@ cont: ldx #0 ; channel 0 ; ------------------------------------------------------------------------ -; Chunk header - -.segment "SYSCHKHDR" - - .word __SYSCHK_LOAD__ - .word end - 1 - -; ------------------------------------------------------------------------ -; Actual code +; code .segment "SYSCHK" +.ifdef __ATARIXL__ + +lmemerrxl_txt: + .byte "Not enough memory to move screen", ATEOL + .byte "memory to low memory. Consider using", ATEOL + .byte "a higher load address.", ATEOL +lmemerrxl_txt_len = * - lmemerrxl_txt + ; no XL machine no_xl: print_string "This program needs an XL machine." jmp fail -; entry point -syschk: - lda $fcd8 ; from ostype.s + +; ***** entry point (atarixl) ***** + +syschk: lda $fcd8 ; from ostype.s cmp #$a2 beq no_xl @@ -86,11 +93,7 @@ syschk: cmp #$80 bcs sys_ok -; not enough memory - print_string "Not enough memory." -fail: jsr delay - jmp (DOSVEC) - + jmp mem_err sys_ok: .include "xlmemchk.inc" ; calculate lowest address we will use when we move the screen buffer down @@ -102,11 +105,63 @@ sys_ok: sbc lowadr+1 bcc memlo_ok +; load address was too low + print_string2 lmemerrxl_txt, lmemerrxl_txt_len + jsr delay ; long text takes longer to read, give user additional time + jmp fail + +.else ; above 'atarixl', below 'atari' + +.define CIOV_org CIOV ; the print_string macros use CIOV_org, map this to CIOV + +lmemerr_txt: + .byte "Program would load below MEMLO.", ATEOL + .byte "Consider using a higher load address.", ATEOL +lmemerr_txt_len = * - lmemerr_txt + + +; ***** entry point (atari) ***** + +syschk: + sec + lda MEMTOP + sbc #<__RESERVED_MEMORY__ + sta tmp + lda MEMTOP+1 + sbc #>__RESERVED_MEMORY__ + sta tmp+1 + lda tmp + sec + sbc #<__STACKSIZE__ + sta tmp + lda tmp+1 + sbc #>__STACKSIZE__ + sta tmp+1 + +;tmp contains address which must be above .bss's end + + sec + lda tmp + sbc #<(__BSS_RUN__ + __BSS_SIZE__) + lda tmp+1 + sbc #>(__BSS_RUN__ + __BSS_SIZE__) + + bcc mem_err ; program doesn't fit into memory + + sec + lda MEMLO + sbc #<__STARTADDRESS__ + lda MEMLO+1 + sbc #>__STARTADDRESS__ + bcc memlo_ok + ; load address was too low print_string2 lmemerr_txt, lmemerr_txt_len jsr delay ; long text takes longer to read, give user additional time jmp fail +.endif + ; all is well(tm), launch the application memlo_ok: .ifdef DEBUG @@ -115,36 +170,45 @@ memlo_ok: .endif rts - -lmemerr_txt: - .byte "Not enough memory to move screen", ATEOL - .byte "memory to low memory. Consider using", ATEOL - .byte "a higher load address.", ATEOL -lmemerr_txt_len = * - lmemerr_txt - +; not enough memory +mem_err:print_string "Not enough memory." +fail: jsr delay + jmp (DOSVEC) ; short delay .proc delay lda #10 -l: jsr delay1 +@loop: jsr delay1 clc sbc #0 - bne l + bne @loop rts delay1: ldx #0 ldy #0 -loop: dey - bne loop +@loop: dey + bne @loop dex - bne loop + bne @loop rts .endproc end: +.ifndef __ATARIXL__ +tmp: ; outside of the load chunk, some kind of poor man's .bss +.endif + +; ------------------------------------------------------------------------ +; Chunk header + +.segment "SYSCHKHDR" + + .word __SYSCHK_LOAD__ + .word end - 1 + ; ------------------------------------------------------------------------ ; Chunk "trailer" - sets INITAD @@ -153,5 +217,3 @@ end: .word INITAD .word INITAD+1 .word syschk - -.endif ; .ifdef __ATARIXL__ From 1077a2876ed46a72f3d5ce4c3f2f119817bc5c9f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 4 Oct 2013 01:02:35 +0200 Subject: [PATCH 134/144] Lower the default Atari start adress from $2E00 to $2000. With the startup memory check of the "system check" load chunk this should be fine --- cfg/atari-overlay.cfg | 2 +- cfg/atari.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg index dae56fce9..c58cf830a 100644 --- a/cfg/atari-overlay.cfg +++ b/cfg/atari-overlay.cfg @@ -1,5 +1,5 @@ FEATURES { - STARTADDRESS: default = $2E00; + STARTADDRESS: default = $2000; } SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack diff --git a/cfg/atari.cfg b/cfg/atari.cfg index df74b9aa9..69132cde3 100644 --- a/cfg/atari.cfg +++ b/cfg/atari.cfg @@ -1,5 +1,5 @@ FEATURES { - STARTADDRESS: default = $2E00; + STARTADDRESS: default = $2000; } SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack From e3b9e9a76ec4b836e46e567a98b0c3956d9ff713 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 4 Oct 2013 12:40:35 +0200 Subject: [PATCH 135/144] small optimization --- libsrc/atari/system_check.s | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index 9dd42f154..84573c84a 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -98,9 +98,8 @@ syschk: lda $fcd8 ; from ostype.s sys_ok: .include "xlmemchk.inc" ; calculate lowest address we will use when we move the screen buffer down - sec lda MEMLO - sbc lowadr + cmp lowadr lda MEMLO+1 sbc lowadr+1 bcc memlo_ok @@ -140,17 +139,15 @@ syschk: ;tmp contains address which must be above .bss's end - sec lda tmp - sbc #<(__BSS_RUN__ + __BSS_SIZE__) + cmp #<(__BSS_RUN__ + __BSS_SIZE__) lda tmp+1 sbc #>(__BSS_RUN__ + __BSS_SIZE__) bcc mem_err ; program doesn't fit into memory - sec lda MEMLO - sbc #<__STARTADDRESS__ + cmp #<__STARTADDRESS__ lda MEMLO+1 sbc #>__STARTADDRESS__ bcc memlo_ok From f488f7576c407e181de50be8df70f4f0ff7e3ab7 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 8 Oct 2013 23:03:53 +0200 Subject: [PATCH 136/144] Applied fix contributed by Greg King. The code void foo(void) { int i; long l = 1L * i; } triggered an Internal compiler error: Code generation messed up: StackPtr is -4, should be -2 Greg King: "We are lucky that the bug is simple -- a missing "else". The result is that the compiler thinks that it does the opposite of what it actually does: It thinks that it pushes the non-constant expression onto the stack. It doesn't; so, cc65's stack pointer is wrong." --- src/cc65/expr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 558967aa2..2125eb430 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1952,6 +1952,7 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */ type = CF_CONST; if ((Gen->Flags & GEN_NOPUSH) == 0) { g_push (ltype, 0); + } else { ltype |= CF_REG; /* Value is in register */ } From c22c6f28ff0509ee3e9e8b475e609c75a5140bb9 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 9 Oct 2013 11:33:53 +0200 Subject: [PATCH 137/144] Removed option from usage. The option in question was removed with https://github.com/oliverschmidt/cc65/commit/37c492b544dec2460fc2c16a3d66275cc0d4edc0 --- src/ld65/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ld65/main.c b/src/ld65/main.c index 25a6c76f8..84af34d54 100644 --- a/src/ld65/main.c +++ b/src/ld65/main.c @@ -114,7 +114,6 @@ static void Usage (void) " --config name\t\tUse linker config file\n" " --dbgfile name\tGenerate debug information\n" " --define sym=val\tDefine a symbol\n" - " --dump-config name\tDump a builtin configuration\n" " --end-group\t\tEnd a library group\n" " --force-import sym\tForce an import of symbol `sym'\n" " --help\t\tHelp (this text)\n" From f3d74cd166e3d5102480c84165365719fe6b842e Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 9 Oct 2013 21:55:44 +0200 Subject: [PATCH 138/144] Added optimizer fix originating from Ullrich von Bassewitz prepared by Greg King. --- src/cc65/coptstop.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/cc65/coptstop.c b/src/cc65/coptstop.c index 4d3fe76e6..dfa14d3f8 100644 --- a/src/cc65/coptstop.c +++ b/src/cc65/coptstop.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2001-2009 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2001-2013, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -58,7 +58,8 @@ typedef enum { LI_DIRECT = 0x01, /* Direct op may be used */ LI_RELOAD_Y = 0x02, /* Reload index register Y */ LI_REMOVE = 0x04, /* Load may be removed */ - LI_DUP_LOAD = 0x08, /* Duplicate load */ + LI_DONT_REMOVE = 0x08, /* Load may not be removed */ + LI_DUP_LOAD = 0x10, /* Duplicate load */ } LI_FLAGS; /* Structure that tells us how to load the lhs values */ @@ -245,6 +246,18 @@ static void AdjustLoadInfo (LoadInfo* LI, int Index, int Change) +static void HonourUseAndChg (LoadRegInfo* RI, unsigned Reg, const CodeEntry* E) +/* Honour use and change flags for an instruction */ +{ + if (E->Chg & Reg) { + ClearLoadRegInfo (RI); + } else if ((E->Use & Reg) && RI->LoadIndex >= 0) { + RI->Flags |= LI_DONT_REMOVE; + } +} + + + static void TrackLoads (LoadInfo* LI, CodeEntry* E, int I) /* Track loads for a code entry */ { @@ -349,15 +362,9 @@ static void TrackLoads (LoadInfo* LI, CodeEntry* E, int I) ClearLoadRegInfo (&LI->Y); } else { - if (E->Chg & REG_A) { - ClearLoadRegInfo (&LI->A); - } - if (E->Chg & REG_X) { - ClearLoadRegInfo (&LI->X); - } - if (E->Chg & REG_Y) { - ClearLoadRegInfo (&LI->Y); - } + HonourUseAndChg (&LI->A, REG_A, E); + HonourUseAndChg (&LI->X, REG_X, E); + HonourUseAndChg (&LI->Y, REG_Y, E); } } @@ -646,7 +653,7 @@ static void RemoveRegLoads (StackOpData* D, LoadInfo* LI) /* Both registers may be loaded with one insn, but DelEntry will in this * case clear the other one. */ - if (LI->A.Flags & LI_REMOVE) { + if ((LI->A.Flags & (LI_REMOVE | LI_DONT_REMOVE)) == LI_REMOVE) { if (LI->A.LoadIndex >= 0) { DelEntry (D, LI->A.LoadIndex); } @@ -654,7 +661,7 @@ static void RemoveRegLoads (StackOpData* D, LoadInfo* LI) DelEntry (D, LI->A.XferIndex); } } - if (LI->X.Flags & LI_REMOVE) { + if ((LI->X.Flags & (LI_REMOVE | LI_DONT_REMOVE)) == LI_REMOVE) { if (LI->X.LoadIndex >= 0) { DelEntry (D, LI->X.LoadIndex); } @@ -875,7 +882,7 @@ static unsigned Opt_tosshift (StackOpData* D, const char* Name) AddStoreA (D); /* Be sure to setup IP after adding the stores, otherwise it will get - * messed up. + * messed up. */ D->IP = D->OpIndex+1; From 3ef1ef33577b2616564ad52d41e0bb23ea869612 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 16 Oct 2013 17:55:45 +0200 Subject: [PATCH 139/144] comment and formatting fixes --- libsrc/atari/romswitch.inc | 4 ++-- libsrc/atari/shadow_ram_prepare.s | 10 ++++++---- libsrc/atari/system_check.s | 7 +++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libsrc/atari/romswitch.inc b/libsrc/atari/romswitch.inc index 7169f2b39..ed4cd96d8 100644 --- a/libsrc/atari/romswitch.inc +++ b/libsrc/atari/romswitch.inc @@ -28,7 +28,7 @@ sta CHBASE .endmacro -.else +.else ; above CHARGEN_RELOC, below not .macro set_chbase val .endmacro @@ -42,7 +42,7 @@ sta WSYNC .endmacro -.else ; above +.else ; above USEWSYNC, below not .macro wsync .endmacro diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index a08aa8cfe..76fae2f45 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -55,6 +55,8 @@ cont: ldx #0 ; channel 0 .segment "SRPREP" +; ***** entry point ***** + sramprep: .ifdef DEBUG print_string "entering stage #2" @@ -115,7 +117,7 @@ sramprep: iocbok: .endif - ; Reopen it in Graphics 0 + ; reopen it in Graphics 0 lda #OPEN sta ICCOM,x lda #OPNIN | OPNOT @@ -212,8 +214,8 @@ cg_addr_ok2: ; switch to temporary chargen - sta CHBASE - sta CHBAS + sta CHBASE + sta CHBAS ; copy shadow RAM contents to their destination (segment SHADOW_RAM) @@ -245,7 +247,7 @@ no_copy: lda #<__SHADOW_RAM2_SIZE__ bne do_copy2 lda #>__SHADOW_RAM2_SIZE__ - beq no_copy2 ; we have no shadow RAM contents + beq no_copy2 ; we have no shadow RAM #2 contents ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len do_copy2: diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index 84573c84a..ef544ef6f 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -7,8 +7,8 @@ ; and that enough memory is installed (which isn't the case for a 600XL). ; For the non-XL target it checks whether there is enough memory ; installed to run the program. -; For both target it checks that the program won't load below MEMLO. -; If one of the checks fails the loading of the main program +; For both targets it checks that the program won't load below MEMLO. +; If one of the checks fails, the loading of the main program ; is aborted by jumping to DOSVEC. ; ; Christian Groessler, chris@groessler.org, 2013 @@ -46,8 +46,8 @@ cont: ldx #0 ; channel 0 sta ICCOM,x jsr CIOV_org .endmacro -.macro print_string2 addr, len +.macro print_string2 addr, len ldx #0 ; channel 0 lda # Date: Wed, 16 Oct 2013 18:15:17 +0200 Subject: [PATCH 140/144] rename LOWDATA segment to LOWBSS --- cfg/atarixl-largehimem.cfg | 6 +++--- cfg/atarixl-overlay.cfg | 6 +++--- cfg/atarixl.cfg | 6 +++--- libsrc/atari/save_area.s | 2 +- libsrc/atari/shadow_ram_handlers.s | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 7af90e214..a4923d025 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -33,10 +33,10 @@ MEMORY { # "main program" load chunk MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + - __LOWDATA_SIZE__, size = $D000 - + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - - __LOWDATA_SIZE__; + __LOWBSS_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; @@ -56,7 +56,7 @@ SEGMENTS { SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; SRPREPHDR: load = SRPREPHDR, type = ro; - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + LOWBSS: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREPCHNK and RAM, not zero initialized SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 3437238b6..b38dff731 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -30,11 +30,11 @@ MEMORY { MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + __OVERLAYSIZE__ + - __LOWDATA_SIZE__, size = $D000 - + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __OVERLAYSIZE__ - - __LOWDATA_SIZE__; + __LOWBSS_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; @@ -68,7 +68,7 @@ SEGMENTS { SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; SRPREPHDR: load = SRPREPHDR, type = ro; - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + LOWBSS: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREPCHNK and RAM, not zero initialized SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM2, type = rw, define = yes, optional = yes; diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 04a260059..c57bef7b7 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -28,10 +28,10 @@ MEMORY { # "main program" load chunk MAINHDR: file = %O, start = $0000, size = $0004; RAM: file = %O, define = yes, start = %S + - __LOWDATA_SIZE__, size = $D000 - + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - - __LOWDATA_SIZE__; + __LOWBSS_SIZE__; # defines entry point into program TRAILER: file = %O, start = $0000, size = $0006; @@ -54,7 +54,7 @@ SEGMENTS { SYSCHKTRL: load = SYSCHKTRL, type = ro, optional = yes; SRPREPHDR: load = SRPREPHDR, type = ro; - LOWDATA: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREP and RAM + LOWBSS: load = SRPREPCHNK, type = bss, define = yes; # shared btw. SRPREPCHNK and RAM, not zero initialized SRPREP: load = SRPREPCHNK, type = rw, define = yes; SHADOW_RAM: load = SRPREPCHNK, run = HIDDEN_RAM, type = rw, define = yes, optional = yes; SHADOW_RAM2: load = SRPREPCHNK, run = HIDDEN_RAM2, type = rw, define = yes, optional = yes; diff --git a/libsrc/atari/save_area.s b/libsrc/atari/save_area.s index e46f3631e..8e6b13369 100644 --- a/libsrc/atari/save_area.s +++ b/libsrc/atari/save_area.s @@ -14,7 +14,7 @@ .export RAMTOP_save .export PORTB_save -.segment "LOWDATA" +.segment "LOWBSS" SAVMSC_save: .res 2 MEMTOP_save: .res 2 diff --git a/libsrc/atari/shadow_ram_handlers.s b/libsrc/atari/shadow_ram_handlers.s index a01363318..53a71ab71 100644 --- a/libsrc/atari/shadow_ram_handlers.s +++ b/libsrc/atari/shadow_ram_handlers.s @@ -68,7 +68,7 @@ sram_init: zpptr1: .res 2 -.segment "LOWDATA" +.segment "LOWBSS" ; bounce buffers for CIO and SIO calls bounce_buffer: .res BUFSZ_SIO From bf3a23c34c813e5a9f0fac69620ef1565cf4e023 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 18 Oct 2013 01:36:44 +0200 Subject: [PATCH 141/144] Rename 'syschk' symbol in the linker config file, which forces inclusion of the 'system check' load chunki, to '__SYSTEM_CHECK__'. --- cfg/atari-overlay.cfg | 2 +- cfg/atari.cfg | 2 +- cfg/atarixl-largehimem.cfg | 2 +- cfg/atarixl-overlay.cfg | 2 +- cfg/atarixl.cfg | 2 +- libsrc/atari/system_check.s | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg index c58cf830a..1cc0eb725 100644 --- a/cfg/atari-overlay.cfg +++ b/cfg/atari-overlay.cfg @@ -6,7 +6,7 @@ SYMBOLS { __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __STARTADDRESS__: type = export, value = %S; __RESERVED_MEMORY__: type = weak, value = $0000; - syschk: type = import; # force inclusion of SYSCHK + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk } MEMORY { ZP: file = "", define = yes, start = $0082, size = $007E; diff --git a/cfg/atari.cfg b/cfg/atari.cfg index 69132cde3..7555bb4a1 100644 --- a/cfg/atari.cfg +++ b/cfg/atari.cfg @@ -5,7 +5,7 @@ SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; __RESERVED_MEMORY__: type = weak, value = $0000; - syschk: type = import; # force inclusion of SYSCHK + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk } MEMORY { ZP: file = "", define = yes, start = $0082, size = $007E; diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index a4923d025..5217597ac 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -10,7 +10,7 @@ FEATURES { SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; - syschk: type = import; # force inclusion of SYSCHK + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk sramprep: type = import; # force inclusion of SRPREP } diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index b38dff731..6f5ccbd2c 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -6,7 +6,7 @@ SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __STARTADDRESS__: type = export, value = %S; - syschk: type = import; # force inclusion of SYSCHK + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk sramprep: type = import; # force inclusion of SRPREP } diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index c57bef7b7..430c7fb5f 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -5,7 +5,7 @@ FEATURES { SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; - syschk: type = import; # force inclusion of SYSCHK + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk sramprep: type = import; # force inclusion of SRPREP } diff --git a/libsrc/atari/system_check.s b/libsrc/atari/system_check.s index ef544ef6f..dbc0b5dfb 100644 --- a/libsrc/atari/system_check.s +++ b/libsrc/atari/system_check.s @@ -16,7 +16,7 @@ ;DEBUG = 1 - .export syschk + .export __SYSTEM_CHECK__: absolute = 1 .import __SYSCHK_LOAD__ .import __STARTADDRESS__ From b153ec88965943a0124b3a658cacc2291faceda5 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 18 Oct 2013 03:07:01 +0200 Subject: [PATCH 142/144] atari-asm.cfg linker config file --- cfg/atari-asm.cfg | 30 ++++++++++++++++++++++++++++++ cfg/atari-overlay.cfg | 5 ++++- cfg/atari.cfg | 5 ++++- cfg/atarixl-largehimem.cfg | 5 ++++- cfg/atarixl-overlay.cfg | 5 ++++- cfg/atarixl.cfg | 5 ++++- libsrc/atari/crt0.s | 22 +--------------------- libsrc/atari/exehdr.s | 8 ++++++++ libsrc/atari/exetrailer.s | 12 ++++++++++++ libsrc/atari/mainhdr.s | 9 +++++++++ 10 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 cfg/atari-asm.cfg create mode 100644 libsrc/atari/exehdr.s create mode 100644 libsrc/atari/exetrailer.s create mode 100644 libsrc/atari/mainhdr.s diff --git a/cfg/atari-asm.cfg b/cfg/atari-asm.cfg new file mode 100644 index 000000000..203521352 --- /dev/null +++ b/cfg/atari-asm.cfg @@ -0,0 +1,30 @@ +FEATURES { + STARTADDRESS: default = $2E00; +} +SYMBOLS { + __EXEHDR__: type = import; + __MAINCHNKHDR__: type = import; + __AUTOSTART__: type = import; # force inclusion of autostart "trailer" + __STARTADDRESS__: type = export, value = %S; +} +MEMORY { + ZP: file = "", define = yes, start = $0082, size = $007E; + +# file header, just $FFFF + HEADER: file = %O, start = $0000, size = $0002; + +# "main program" load chunk + MAINHDR: file = %O, start = $0000, size = $0004; + RAM: file = %O, define = yes, start = %S, size = $BC20 - %S; + TRAILER: file = %O, start = $0000, size = $0006; +} +SEGMENTS { + EXEHDR: load = HEADER, type = ro, optional = yes; + MAINHDR: load = MAINHDR, type = ro, optional = yes; + CODE: load = RAM, type = ro, define = yes, optional = yes; + RODATA: load = RAM, type = ro optional = yes; + DATA: load = RAM, type = rw optional = yes; + BSS: load = RAM, type = bss, define = yes, optional = yes; + ZEROPAGE: load = ZP, type = zp; + AUTOSTRT: load = TRAILER, type = ro, optional = yes; +} diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg index 1cc0eb725..d5a73531b 100644 --- a/cfg/atari-overlay.cfg +++ b/cfg/atari-overlay.cfg @@ -2,11 +2,14 @@ FEATURES { STARTADDRESS: default = $2000; } SYMBOLS { + __EXEHDR__: type = import; + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk + __MAINCHNKHDR__: type = import; + __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __STARTADDRESS__: type = export, value = %S; __RESERVED_MEMORY__: type = weak, value = $0000; - __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk } MEMORY { ZP: file = "", define = yes, start = $0082, size = $007E; diff --git a/cfg/atari.cfg b/cfg/atari.cfg index 7555bb4a1..ef57c3e52 100644 --- a/cfg/atari.cfg +++ b/cfg/atari.cfg @@ -2,10 +2,13 @@ FEATURES { STARTADDRESS: default = $2000; } SYMBOLS { + __EXEHDR__: type = import; + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk + __MAINCHNKHDR__: type = import; + __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; __RESERVED_MEMORY__: type = weak, value = $0000; - __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk } MEMORY { ZP: file = "", define = yes, start = $0082, size = $007E; diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 5217597ac..17874b600 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -8,9 +8,12 @@ FEATURES { } SYMBOLS { + __EXEHDR__: type = import; + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk + __MAINCHNKHDR__: type = import; + __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; - __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk sramprep: type = import; # force inclusion of SRPREP } diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 6f5ccbd2c..2f5595c0b 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -3,10 +3,13 @@ FEATURES { } SYMBOLS { + __EXEHDR__: type = import; + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk + __MAINCHNKHDR__: type = import; + __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __STARTADDRESS__: type = export, value = %S; - __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk sramprep: type = import; # force inclusion of SRPREP } diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 430c7fb5f..f217c308f 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -3,9 +3,12 @@ FEATURES { } SYMBOLS { + __EXEHDR__: type = import; + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk + __MAINCHNKHDR__: type = import; + __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; - __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk sramprep: type = import; # force inclusion of SRPREP } diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index de72c1eb8..464557fa7 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -8,12 +8,11 @@ ; Stefan Haubenthal ; - .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup + .export _exit, start .import initlib, donelib .import callmain, zerobss - .import __STARTUP_LOAD__, __BSS_LOAD__ .import __RESERVED_MEMORY__ .import __RAM_START__, __RAM_SIZE__ .ifdef __ATARIXL__ @@ -28,19 +27,6 @@ .include "atari.inc" ; ------------------------------------------------------------------------ -; EXE header - -.segment "EXEHDR" - - .word $FFFF - -.segment "MAINHDR" - - .word __STARTUP_LOAD__ - .word __BSS_LOAD__ - 1 - -; ------------------------------------------------------------------------ -; Actual code .segment "STARTUP" @@ -212,9 +198,3 @@ LMARGN_save: .res 1 .ifndef __ATARIXL__ APPMHI_save: .res 2 .endif - - -.segment "AUTOSTRT" - .word RUNAD ; defined in atari.inc - .word RUNAD+1 - .word start diff --git a/libsrc/atari/exehdr.s b/libsrc/atari/exehdr.s new file mode 100644 index 000000000..f2f77501d --- /dev/null +++ b/libsrc/atari/exehdr.s @@ -0,0 +1,8 @@ +; This file defines the EXE header for Atari executables + + .export __EXEHDR__: absolute = 1 + +.segment "EXEHDR" + + .word $FFFF + diff --git a/libsrc/atari/exetrailer.s b/libsrc/atari/exetrailer.s new file mode 100644 index 000000000..8cae0bdf0 --- /dev/null +++ b/libsrc/atari/exetrailer.s @@ -0,0 +1,12 @@ +; This file defines the EXE file "trailer" which sets the entry point + + .export __AUTOSTART__: absolute = 1 + .import start + + .include "atari.inc" + +.segment "AUTOSTRT" + .word RUNAD ; defined in atari.inc + .word RUNAD+1 + .word start + diff --git a/libsrc/atari/mainhdr.s b/libsrc/atari/mainhdr.s new file mode 100644 index 000000000..31b339b45 --- /dev/null +++ b/libsrc/atari/mainhdr.s @@ -0,0 +1,9 @@ +; This file defines the chunk header for the main program load chunk + + .export __MAINCHNKHDR__: absolute = 1 + .import __RAM_START__, __BSS_LOAD__ + +.segment "MAINHDR" + + .word __RAM_START__ + .word __BSS_LOAD__ - 1 From 9f44d00d179b1a91e787d335ad1bfc649401831a Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 18 Oct 2013 14:53:06 +0200 Subject: [PATCH 143/144] Put EXE header and main chunk load header into a single file -- it makes no sense to be able to include/exclude them separately. --- cfg/atari-asm.cfg | 1 - cfg/atari-overlay.cfg | 1 - cfg/atari.cfg | 1 - cfg/atarixl-largehimem.cfg | 1 - cfg/atarixl-overlay.cfg | 1 - cfg/atarixl.cfg | 1 - libsrc/atari/exehdr.s | 7 +++++-- libsrc/atari/mainhdr.s | 9 --------- 8 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 libsrc/atari/mainhdr.s diff --git a/cfg/atari-asm.cfg b/cfg/atari-asm.cfg index 203521352..4e87a8884 100644 --- a/cfg/atari-asm.cfg +++ b/cfg/atari-asm.cfg @@ -3,7 +3,6 @@ FEATURES { } SYMBOLS { __EXEHDR__: type = import; - __MAINCHNKHDR__: type = import; __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STARTADDRESS__: type = export, value = %S; } diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg index d5a73531b..1d339b208 100644 --- a/cfg/atari-overlay.cfg +++ b/cfg/atari-overlay.cfg @@ -4,7 +4,6 @@ FEATURES { SYMBOLS { __EXEHDR__: type = import; __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk - __MAINCHNKHDR__: type = import; __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay diff --git a/cfg/atari.cfg b/cfg/atari.cfg index ef57c3e52..dce593f05 100644 --- a/cfg/atari.cfg +++ b/cfg/atari.cfg @@ -4,7 +4,6 @@ FEATURES { SYMBOLS { __EXEHDR__: type = import; __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk - __MAINCHNKHDR__: type = import; __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 17874b600..533987258 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -10,7 +10,6 @@ FEATURES { SYMBOLS { __EXEHDR__: type = import; __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk - __MAINCHNKHDR__: type = import; __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 2f5595c0b..0c903ef45 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -5,7 +5,6 @@ FEATURES { SYMBOLS { __EXEHDR__: type = import; __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk - __MAINCHNKHDR__: type = import; __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index f217c308f..f2cf20bc6 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -5,7 +5,6 @@ FEATURES { SYMBOLS { __EXEHDR__: type = import; __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk - __MAINCHNKHDR__: type = import; __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; diff --git a/libsrc/atari/exehdr.s b/libsrc/atari/exehdr.s index f2f77501d..ea9fa95d7 100644 --- a/libsrc/atari/exehdr.s +++ b/libsrc/atari/exehdr.s @@ -1,8 +1,11 @@ -; This file defines the EXE header for Atari executables +; This file defines the EXE header and main chunk load header for Atari executables .export __EXEHDR__: absolute = 1 + .import __RAM_START__, __BSS_LOAD__ .segment "EXEHDR" - .word $FFFF +.segment "MAINHDR" + .word __RAM_START__ + .word __BSS_LOAD__ - 1 diff --git a/libsrc/atari/mainhdr.s b/libsrc/atari/mainhdr.s deleted file mode 100644 index 31b339b45..000000000 --- a/libsrc/atari/mainhdr.s +++ /dev/null @@ -1,9 +0,0 @@ -; This file defines the chunk header for the main program load chunk - - .export __MAINCHNKHDR__: absolute = 1 - .import __RAM_START__, __BSS_LOAD__ - -.segment "MAINHDR" - - .word __RAM_START__ - .word __BSS_LOAD__ - 1 From 478a7679a26efbbbb65666f992971b65e2f43a91 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 18 Oct 2013 22:07:05 +0200 Subject: [PATCH 144/144] Force inclusion of 'shadow RAM preparation' load chunk in crt0.s and not in the linker config file. --- cfg/atarixl-largehimem.cfg | 1 - cfg/atarixl-overlay.cfg | 1 - cfg/atarixl.cfg | 1 - libsrc/atari/crt0.s | 1 + libsrc/atari/shadow_ram_prepare.s | 1 + 5 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 533987258..01fc76a26 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -13,7 +13,6 @@ SYMBOLS { __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; - sramprep: type = import; # force inclusion of SRPREP } MEMORY { diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 0c903ef45..68d0f524e 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -9,7 +9,6 @@ SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __STARTADDRESS__: type = export, value = %S; - sramprep: type = import; # force inclusion of SRPREP } MEMORY { diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index f2cf20bc6..aad3ce613 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -8,7 +8,6 @@ SYMBOLS { __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; - sramprep: type = import; # force inclusion of SRPREP } MEMORY { diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 464557fa7..fb434b5de 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -20,6 +20,7 @@ .import sram_init .import scrdev .import findfreeiocb + .forceimport sramprep ; force inclusion of the "shadow RAM preparation" load chunk .include "save_area.inc" .endif diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 76fae2f45..a1760bd72 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -14,6 +14,7 @@ .ifdef __ATARIXL__ .export sramprep + .import __SRPREP_LOAD__, __SRPREPCHNK_LAST__ .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__, __SHADOW_RAM_RUN__ .import __SHADOW_RAM2_LOAD__, __SHADOW_RAM2_SIZE__, __SHADOW_RAM2_RUN__