From 34cf7657e8a9d07a8cc4692cabd47acb9aeda112 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 30 May 2013 02:26:15 +0200 Subject: [PATCH 01/90] 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 02/90] 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 03/90] "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 04/90] 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 05/90] 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 06/90] 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 07/90] 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 08/90] 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 09/90] 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 10/90] 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 11/90] 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 12/90] 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 13/90] 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 14/90] 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 15/90] 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 16/90] 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 17/90] 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 18/90] 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 19/90] 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 20/90] 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 21/90] 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 22/90] 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 23/90] 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 24/90] 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 25/90] 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 26/90] 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 27/90] 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 28/90] 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 29/90] 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 30/90] 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 31/90] 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 32/90] 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 33/90] 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 34/90] 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 35/90] 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 36/90] 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 37/90] 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 38/90] 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 39/90] 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 40/90] 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 41/90] 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 42/90] 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 43/90] 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 44/90] 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 45/90] 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 b1f69e0696d1cd7567cdcd02b716b70937a5bd37 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 22 Aug 2013 13:08:48 +0200 Subject: [PATCH 46/90] 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 47/90] 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 4062cb6b6ccd6e3a32ca6be4cc75579526fb8601 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Sun, 25 Aug 2013 11:20:27 +0200 Subject: [PATCH 48/90] 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 49/90] 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 50/90] 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 68fc4a1b1577f897d582dd605376fb6d4151101c Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 27 Aug 2013 10:21:42 +0200 Subject: [PATCH 51/90] 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 52/90] 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 53/90] 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 4a0bdf871baad88bec9b405221d08ebaaaaf87db Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 4 Sep 2013 22:10:36 +0200 Subject: [PATCH 54/90] 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 55/90] 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 c48fbd8a2b8b7646bfe43a633becf39ce8e9ba7f Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Sat, 7 Sep 2013 17:44:53 +0200 Subject: [PATCH 56/90] 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 ebfb4a0b528288e15ba4bedaead53d10cf75e8e5 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 11 Sep 2013 21:53:13 +0200 Subject: [PATCH 57/90] 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 58/90] 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 59/90] 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 60/90] 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 61/90] 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 62/90] 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 237bb9850c611f8f40b0fba26ccec62e7a02c857 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 13 Sep 2013 16:00:56 +0200 Subject: [PATCH 63/90] 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 64/90] 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 65/90] 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 66/90] 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 67/90] 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 68/90] 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 69/90] 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 70/90] 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 71/90] 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 72/90] 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 73/90] 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 74/90] 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 75/90] 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 76/90] 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 77/90] 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 c210dfcb9445f6c5706046d174867c52c1310c44 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 18 Sep 2013 16:36:03 +0200 Subject: [PATCH 78/90] 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 79/90] 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 80/90] 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 81/90] 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 82/90] 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 83/90] 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 84/90] 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 85/90] 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 86/90] 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 c88e0818b492017d01d1edb0c589e8a8613da58c Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 27 Sep 2013 21:49:45 +0200 Subject: [PATCH 87/90] 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 88/90] 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 89/90] 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 90/90] 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