2 ; Atari startup system check
4 ; This routine gets loaded prior to the main part of the executable
5 ; and checks if the system is compatible to run the program.
6 ; For the XL target it checks whether the system is an XL type one
7 ; and that enough memory is installed (which isn't the case for a 600XL).
8 ; For the non-XL target it checks whether there is enough memory
9 ; installed to run the program.
10 ; For both targets it checks that the program won't load below MEMLO.
11 ; If one of the checks fails, the loading of the main program
12 ; is aborted by jumping to DOSVEC.
14 ; Christian Groessler, chris@groessler.org, 2013
19 .export __SYSTEM_CHECK__: absolute = 1
20 .import __SYSCHK_LOAD__
21 .import __STARTADDRESS__
23 ; the following imports are only needed for the 'atari' target version
24 .import __BSS_SIZE__, __BSS_RUN__
26 .import __RESERVED_MEMORY__
28 .include "zeropage.inc"
32 .macro print_string text
35 start: .byte text, ATEOL
36 cont: ldx #0 ; channel 0
50 .macro print_string2 addr, len
66 ; ------------------------------------------------------------------------
71 rts ; for older DOSes which unconditionally run the first load chunk
75 ; check for SpartaDOS and its usage of RAM below ROM
76 ; return CF 0/1 for ok/bad
79 bne sdcrts0 ; not SpartaDOS, assume RAM is not used
81 ; check for BW-DOS, which always reports itself as SpartaDOS, but doesn't use memory under the ROM
82 lda DOS+3 ; 'B' in BW-DOS
85 lda DOS+4 ; 'W' in BW-DOS
87 beq sdcrts0 ; BW-DOS does not use RAM below ROM
89 sdnobw: lda DOS+1 ; SD version
90 cmp #$40 ; SD-X has $40 or higher
91 bcc sdcrts1 ; older versions (except maybe 1.x) always use the RAM under the ROM
92 ldy #31 ; offset for OSRMFLG
93 lda (DOSVEC),y ; get OSRMFLG
102 .byte "Memory under ROM is in use.", ATEOL
103 .byte "Cannot run this program.", ATEOL
104 ramrom_txt_len = * - ramrom_txt
107 .byte "Not enough memory to move screen", ATEOL
108 .byte "memory to low memory. Consider using", ATEOL
109 .byte "a higher load address.", ATEOL
110 lmemerrxl_txt_len = * - lmemerrxl_txt
113 no_xl: print_string "This program needs an XL machine."
117 ; ***** entry point (atarixl) *****
119 syschk: lda $fcd8 ; from ostype.s
123 ; we have an XL machine, now check memory
130 sys_ok: jsr sdcheck ; check for SpartaDOS-X, and if found, whether it uses the RAM under the ROM
133 print_string2 ramrom_txt, ramrom_txt_len
136 sd_ok: .include "xlmemchk.inc" ; calculate lowest address we will use when we move the screen buffer down
144 ; load address was too low
145 print_string2 lmemerrxl_txt, lmemerrxl_txt_len
146 jsr delay ; long text takes longer to read, give user additional time
149 .else ; above 'atarixl', below 'atari'
151 .define CIOV_org CIOV ; the print_string macros use CIOV_org, map this to CIOV
154 .byte "Program would load below MEMLO.", ATEOL
155 .byte "Consider using a higher load address.", ATEOL
156 lmemerr_txt_len = * - lmemerr_txt
159 ; ***** entry point (atari) *****
164 sbc #<__RESERVED_MEMORY__
167 sbc #>__RESERVED_MEMORY__
177 ;tmp contains address which must be above .bss's end
180 cmp #<(__BSS_RUN__ + __BSS_SIZE__)
182 sbc #>(__BSS_RUN__ + __BSS_SIZE__)
184 bcc mem_err ; program doesn't fit into memory
187 cmp #<__STARTADDRESS__
189 sbc #>__STARTADDRESS__
192 ; load address was too low
193 print_string2 lmemerr_txt, lmemerr_txt_len
194 jsr delay ; long text takes longer to read, give user additional time
199 ; all is well(tm), launch the application
202 print_string "Stage #1 OK"
208 mem_err:print_string "Not enough memory."
235 tmp: ; outside of the load chunk, some kind of poor man's .bss
238 ; ------------------------------------------------------------------------
243 .word __SYSCHK_LOAD__
246 ; ------------------------------------------------------------------------
247 ; Chunk "trailer" - sets INITAD