]> git.sur5r.net Git - cc65/blob - libsrc/atari/system_check.s
Merge remote-tracking branch 'upstream/master'
[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
94 sys_ok:
95         .include "xlmemchk.inc"         ; calculate lowest address we will use when we move the screen buffer down
96
97         sec
98         lda     MEMLO
99         sbc     lowadr
100         lda     MEMLO+1
101         sbc     lowadr+1
102         bcc     memlo_ok
103
104 ; load address was too low
105         print_string2 lmemerr_txt, lmemerr_txt_len
106         jsr     delay           ; long text takes longer to read, give user additional time
107         jmp     fail
108
109 ; all is well(tm), launch the application
110 memlo_ok:
111 .ifdef DEBUG
112         print_string "Stage #1 OK"
113         jsr     delay
114 .endif
115         rts
116
117
118 lmemerr_txt:
119         .byte   "Not enough memory to move screen", ATEOL
120         .byte   "memory to low memory. Consider using", ATEOL
121         .byte   "a higher load address.", ATEOL
122 lmemerr_txt_len = * - lmemerr_txt
123
124
125 ; short delay
126 .proc   delay
127
128         lda     #10
129 l:      jsr     delay1
130         clc
131         sbc     #0
132         bne     l
133         rts
134
135 delay1: ldx     #0
136         ldy     #0
137 loop:   dey
138         bne     loop
139         dex
140         bne     loop
141         rts
142
143 .endproc
144
145 ; ------------------------------------------------------------------------
146 ; Chunk "trailer" - sets INITAD
147
148 trailer:
149         .word   INITAD
150         .word   INITAD+1
151         .word   __SYSCHK_LOAD__
152
153 .endif  ; .if .defined(__ATARIXL__)