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