]> git.sur5r.net Git - cc65/blob - libsrc/atari/system_check.s
untabify
[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 .ifdef __ATARIXL__
17
18         .export         syschk
19         .import         __SYSCHK_LOAD__
20         .import         __STARTADDRESS__       ; needed by xlmemchk.inc
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   end - 1
68
69 ; ------------------------------------------------------------------------
70 ; Actual code
71
72 .segment        "SYSCHK"
73
74 ; no XL machine
75 no_xl:  print_string "This program needs an XL machine."
76         jmp     fail
77
78 ; entry point
79 syschk:
80         lda     $fcd8           ; from ostype.s
81         cmp     #$a2
82         beq     no_xl
83
84 ; we have an XL machine, now check memory
85         lda     RAMSIZ
86         cmp     #$80
87         bcs     sys_ok
88
89 ; not enough memory
90         print_string "Not enough memory."
91 fail:   jsr     delay
92         jmp     (DOSVEC)
93
94
95 sys_ok:
96         .include "xlmemchk.inc"         ; calculate lowest address we will use when we move the screen buffer down
97
98         sec
99         lda     MEMLO
100         sbc     lowadr
101         lda     MEMLO+1
102         sbc     lowadr+1
103         bcc     memlo_ok
104
105 ; load address was too low
106         print_string2 lmemerr_txt, lmemerr_txt_len
107         jsr     delay           ; long text takes longer to read, give user additional time
108         jmp     fail
109
110 ; all is well(tm), launch the application
111 memlo_ok:
112 .ifdef DEBUG
113         print_string "Stage #1 OK"
114         jsr     delay
115 .endif
116         rts
117
118
119 lmemerr_txt:
120         .byte   "Not enough memory to move screen", ATEOL
121         .byte   "memory to low memory. Consider using", ATEOL
122         .byte   "a higher load address.", ATEOL
123 lmemerr_txt_len = * - lmemerr_txt
124
125
126 ; short delay
127 .proc   delay
128
129         lda     #10
130 l:      jsr     delay1
131         clc
132         sbc     #0
133         bne     l
134         rts
135
136 delay1: ldx     #0
137         ldy     #0
138 loop:   dey
139         bne     loop
140         dex
141         bne     loop
142         rts
143
144 .endproc
145
146 end:
147
148 ; ------------------------------------------------------------------------
149 ; Chunk "trailer" - sets INITAD
150
151 .segment        "SYSCHKTRL"
152
153         .word   INITAD
154         .word   INITAD+1
155         .word   syschk
156
157 .endif  ; .ifdef __ATARIXL__