]> git.sur5r.net Git - cc65/blob - libsrc/atari/system_check.s
d197dfdb62b43331af34642c832c9ec9d222002d
[cc65] / libsrc / atari / system_check.s
1 ;
2 ; Atari XL startup system check
3 ;
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 ; It checks whether the system is an XL type one and that enough
7 ; memory is installed (which isn't the case for a 600XL).
8 ; If the system doesn't qualify, the loading of the main program
9 ; is aborted by jumping to DOSVEC.
10 ;
11 ; Christian Groessler, chris@groessler.org, 2013
12 ;
13
14 DEBUG   =       1
15
16 .if .defined(__ATARIXL__)
17
18         .export         syschk
19         .import         __SYSCHK_LOAD__
20         .import         __SAVEAREA_LOAD__
21
22         .include        "zeropage.inc"
23         .include        "atari.inc"
24
25
26 .macro print_string text
27         .local  start, cont
28         jmp     cont
29 start:  .byte   text, ATEOL
30 cont:   ldx     #0              ; channel 0
31         lda     #<start
32         sta     ICBAL,x         ; address
33         lda     #>start
34         sta     ICBAH,x
35         lda     #<(cont - start)
36         sta     ICBLL,x         ; length
37         lda     #>(cont - start)
38         sta     ICBLH,x
39         lda     #PUTCHR
40         sta     ICCOM,x
41         jsr     CIOV_org
42 .endmacro
43 .macro print_string2 addr, len
44
45         ldx     #0              ; channel 0
46         lda     #<addr
47         sta     ICBAL,x         ; address
48         lda     #>addr
49         sta     ICBAH,x
50         lda     #<len
51         sta     ICBLL,x         ; length
52         lda     #>len
53         sta     ICBLH,x
54         lda     #PUTCHR
55         sta     ICCOM,x
56         jsr     CIOV_org
57
58 .endmacro
59
60
61 ; ------------------------------------------------------------------------
62 ; Chunk header
63
64 .segment        "SYSCHKHDR"
65
66         .word   __SYSCHK_LOAD__
67         .word   trailer - 1
68
69 ; ------------------------------------------------------------------------
70 ; Actual code
71
72 .segment        "SYSCHK"
73
74 syschk:
75         lda     $fcd8           ; from ostype.s
76         cmp     #$a2
77         bne     is_xl
78
79 ; no XL machine
80         print_string "This program needs an XL machine."
81         jmp     fail
82
83 ; we have an XL machine, now check memory
84 is_xl:  lda     RAMSIZ
85         cmp     #$80
86         bcs     sys_ok
87
88 ; not enough memory
89         print_string "Not enough memory."
90 fail:   jsr     delay
91         jmp     (DOSVEC)
92
93 lowadr: .res    2               ; lowest address we need in order to move screen memory down, depending on start address of program
94
95
96 ; system is basically supported, check if there is enough space btw. MEMLO and our start address
97 ; to move screen memory there
98
99 CMPVAL = 64+255+992             ; you may ask, why these values...   @@@ document
100
101 sys_ok: lda     #<__SAVEAREA_LOAD__
102         sec
103         sbc     #<CMPVAL
104         sta     lowadr
105         lda     #>__SAVEAREA_LOAD__
106         sbc     #>CMPVAL
107         sta     lowadr+1
108
109         sec
110         lda     MEMLO
111         sbc     lowadr
112         lda     MEMLO+1
113         sbc     lowadr+1
114         bcc     memlo_ok
115
116 ; load address was too low
117         print_string2 lmemerr_txt, lmemerr_txt_len
118         jsr     delay           ; long text takes longer to read, give user additional time
119         jmp     fail
120
121 ; all is well(tm), launch the application
122 memlo_ok:
123 .ifdef DEBUG
124         print_string "Stage #1 OK"
125         jsr     delay
126 .endif
127         rts
128
129
130 lmemerr_txt:
131         .byte   "Not enough memory to move screen", ATEOL
132         .byte   "memory to low memory. Consider using", ATEOL
133         .byte   "a higher load address.", ATEOL
134 lmemerr_txt_len = * - lmemerr_txt
135
136
137 ; short delay
138 .proc   delay
139
140         lda     #10
141 l:      jsr     delay1
142         clc
143         sbc     #0
144         bne     l
145         rts
146
147 delay1: ldx     #0
148         ldy     #0
149 loop:   dey
150         bne     loop
151         dex
152         bne     loop
153         rts
154
155 .endproc
156
157 ; ------------------------------------------------------------------------
158 ; Chunk "trailer" - sets INITAD
159
160 trailer:
161         .word   INITAD
162         .word   INITAD+1
163         .word   __SYSCHK_LOAD__
164
165 .endif  ; .if .defined(__ATARIXL__)