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__, __SYSCHK_END__
20 .import __STARTADDRESS__
22 ; the following imports are only needed for the 'atari' target version
23 .import __BSS_SIZE__, __BSS_RUN__
25 .import __RESERVED_MEMORY__
27 ; import our header and trailers
28 .forceimport __SYSCHKHDR__, __SYSCHKTRL__
30 .include "zeropage.inc"
33 .macro print_string text
36 start: .byte text, ATEOL
37 cont: ldx #0 ; channel 0
51 .macro print_string2 addr, len
67 ; ------------------------------------------------------------------------
72 rts ; for older DOSes which unconditionally run the first load chunk
76 ; check for SpartaDOS and its usage of RAM below ROM
77 ; return CF 0/1 for ok/bad
80 bne sdcrts0 ; not SpartaDOS, assume RAM is not used
82 ; check for BW-DOS, which always reports itself as SpartaDOS, but doesn't use memory under the ROM
83 lda DOS+3 ; 'B' in BW-DOS
86 lda DOS+4 ; 'W' in BW-DOS
88 beq sdcrts0 ; BW-DOS does not use RAM below ROM
90 sdnobw: lda DOS+1 ; SD version
91 cmp #$40 ; SD-X has $40 or higher
92 bcc sdcrts1 ; older versions (except maybe 1.x) always use the RAM under the ROM
93 ldy #31 ; offset for OSRMFLG
94 lda (DOSVEC),y ; get OSRMFLG
103 .byte "Memory under ROM is in use.", ATEOL
104 .byte "Cannot run this program.", ATEOL
105 ramrom_txt_len = * - ramrom_txt
108 .byte "Not enough memory to move screen", ATEOL
109 .byte "memory to low memory. Consider using", ATEOL
110 .byte "a higher load address.", ATEOL
111 lmemerrxl_txt_len = * - lmemerrxl_txt
114 no_xl: print_string "This program needs an XL machine."
118 ; ***** entry point (atarixl) *****
120 syschk: lda $fcd8 ; from ostype.s
124 ; we have an XL machine, now check memory
131 sys_ok: jsr sdcheck ; check for SpartaDOS-X, and if found, whether it uses the RAM under the ROM
134 print_string2 ramrom_txt, ramrom_txt_len
137 sd_ok: .include "xlmemchk.inc" ; calculate lowest address we will use when we move the screen buffer down
145 ; load address was too low
146 print_string2 lmemerrxl_txt, lmemerrxl_txt_len
147 jsr delay ; long text takes longer to read, give user additional time
150 .else ; above 'atarixl', below 'atari'
152 .define CIOV_org CIOV ; the print_string macros use CIOV_org, map this to CIOV
155 .byte "Program would load below MEMLO.", ATEOL
156 .byte "Consider using a higher load address.", ATEOL
157 lmemerr_txt_len = * - lmemerr_txt
160 ; ***** entry point (atari) *****
165 sbc #<__RESERVED_MEMORY__
168 sbc #>__RESERVED_MEMORY__
178 ;tmp contains address which must be above .bss's end
181 cmp #<(__BSS_RUN__ + __BSS_SIZE__)
183 sbc #>(__BSS_RUN__ + __BSS_SIZE__)
185 bcc mem_err ; program doesn't fit into memory
188 cmp #<__STARTADDRESS__
190 sbc #>__STARTADDRESS__
193 ; load address was too low
194 print_string2 lmemerr_txt, lmemerr_txt_len
195 jsr delay ; long text takes longer to read, give user additional time
200 ; all is well(tm), launch the application
203 print_string "Stage #1 OK"
209 mem_err:print_string "Not enough memory."
233 __SYSTEM_CHECK__=syschk
237 tmp: ; outside of the load chunk, some kind of poor man's .bss