]> git.sur5r.net Git - cc65/blob - libsrc/atmos/atmos-240-200-2.s
Comment additions and changes.
[cc65] / libsrc / atmos / atmos-240-200-2.s
1 ;
2 ; Graphics driver for the 240x200x2 mode on the Atmos
3 ;
4 ; Stefan Haubenthal <polluks@sdf.lonestar.org>
5 ;
6
7         .include        "zeropage.inc"
8
9         .include        "tgi-kernel.inc"
10         .include        "tgi-mode.inc"
11         .include        "tgi-error.inc"
12         .include        "atmos.inc"
13
14         .macpack        generic
15
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table and constants.
18
19 .segment        "JUMPTABLE"
20
21 ; First part of the header is a structure that has a magic and defines the
22 ; capabilities of the driver
23
24         .byte   $74, $67, $69           ; "tgi"
25         .byte   TGI_API_VERSION         ; TGI API version number
26         .word   240                     ; X resolution
27         .word   200                     ; Y resolution
28         .byte   2                       ; Number of drawing colors
29         .byte   1                       ; Number of screens available
30 xsize:  .byte   6                       ; System font X size
31         .byte   8                       ; System font Y size
32         .res    4, $00                  ; Reserved for future extensions
33
34 ; Next comes the jump table. Currently all entries must be valid and may point
35 ; to an RTS for test versions (function not implemented).
36
37         .addr   INSTALL
38         .addr   UNINSTALL
39         .addr   INIT
40         .addr   DONE
41         .addr   GETERROR
42         .addr   CONTROL
43         .addr   CLEAR
44         .addr   SETVIEWPAGE
45         .addr   SETDRAWPAGE
46         .addr   SETCOLOR
47         .addr   SETPALETTE
48         .addr   GETPALETTE
49         .addr   GETDEFPALETTE
50         .addr   SETPIXEL
51         .addr   GETPIXEL
52         .addr   LINE
53         .addr   BAR
54         .addr   _CIRCLE
55         .addr   TEXTSTYLE
56         .addr   OUTTEXT
57         .addr   0                       ; IRQ entry is unused
58
59 ; ------------------------------------------------------------------------
60 ; Data.
61
62 ; Variables mapped to the zero page segment variables. Some of these are
63 ; used for passing parameters to the driver.
64
65 X1              = ptr1
66 Y1              = ptr2
67 X2              = ptr3
68 Y2              = ptr4
69 RADIUS          = tmp1
70
71 ; Absolute variables used in the code
72
73 .bss
74
75 ERROR:          .res    1       ; Error code
76 MODE:           .res    1       ; Graphics mode
77
78 ; Constants and tables
79 PARAM1          = $2E1
80 PARAM2          = $2E3
81 PARAM3          = $2E5
82 TEXT            = $EC21
83 HIRES           = $EC33
84 CURSET          = $F0C8
85 CURMOV          = $F0FD
86 DRAW            = $F110
87 CHAR            = $F12D
88 POINT           = $F1C8
89 PAPER           = $F204
90 INK             = $F210
91 CIRCLE          = $F37F
92
93 .rodata
94
95 DEFPALETTE:     .byte   $00, $07
96
97 .code
98
99 ; ------------------------------------------------------------------------
100 ; INSTALL routine. Is called after the driver is loaded into memory. May
101 ; initialize anything that has to be done just once. Is probably empty
102 ; most of the time.
103 ;
104 ; Must set an error code: NO
105 ;
106
107 INSTALL:
108
109 ; ------------------------------------------------------------------------
110 ; UNINSTALL routine. Is called before the driver is removed from memory. May
111 ; clean up anything done by INSTALL but is probably empty most of the time.
112 ;
113 ; Must set an error code: NO
114 ;
115
116 UNINSTALL:
117         rts
118
119 ; ------------------------------------------------------------------------
120 ; INIT: Changes an already installed device from text mode to graphics
121 ; mode.
122 ; Note that INIT/DONE may be called multiple times while the driver
123 ; is loaded, while INSTALL is only called once, so any code that is needed
124 ; to initializes variables and so on must go here. Setting palette and
125 ; clearing the screen is not needed because this is called by the graphics
126 ; kernel later.
127 ; The graphics kernel will never call INIT when a graphics mode is already
128 ; active, so there is no need to protect against that.
129 ;
130 ; Must set an error code: YES
131 ;
132
133 INIT:
134
135 ; Switch into graphics mode
136
137         jsr     HIRES
138
139 ; Done, reset the error code
140
141         lda     #TGI_ERR_OK
142         sta     ERROR
143         rts
144
145 ; ------------------------------------------------------------------------
146 ; DONE: Will be called to switch the graphics device back into text mode.
147 ; The graphics kernel will never call DONE when no graphics mode is active,
148 ; so there is no need to protect against that.
149 ;
150 ; Must set an error code: NO
151 ;
152
153 DONE            = TEXT
154
155 ; ------------------------------------------------------------------------
156 ; GETERROR: Return the error code in A and clear it.
157
158 GETERROR:
159         ldx     #TGI_ERR_OK
160         lda     ERROR
161         stx     ERROR
162         rts
163
164 ; ------------------------------------------------------------------------
165 ; CONTROL: Platform/driver specific entry point.
166 ;
167 ; Must set an error code: YES
168 ;
169
170 CONTROL:
171         sta     $213
172         lda     #TGI_ERR_OK
173         sta     ERROR
174         rts
175
176 ; ------------------------------------------------------------------------
177 ; CLEAR: Clears the screen.
178 ;
179 ; Must set an error code: NO
180 ;
181
182 CLEAR           = HIRES
183
184 ; ------------------------------------------------------------------------
185 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
186 ; The page number is already checked to be valid by the graphics kernel.
187 ;
188 ; Must set an error code: NO (will only be called if page ok)
189 ;
190
191 SETVIEWPAGE:
192
193 ; ------------------------------------------------------------------------
194 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
195 ; The page number is already checked to be valid by the graphics kernel.
196 ;
197 ; Must set an error code: NO (will only be called if page ok)
198 ;
199
200 SETDRAWPAGE:
201         rts
202
203 ; ------------------------------------------------------------------------
204 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
205 ; to be in a valid range (0..maxcolor-1).
206 ;
207 ; Must set an error code: NO (will only be called if color ok)
208 ;
209
210 SETCOLOR:
211         sta     MODE
212         rts
213
214 ; ------------------------------------------------------------------------
215 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
216 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
217 ; are not supported
218 ;
219 ; Must set an error code: YES
220 ;
221
222 SETPALETTE:
223         ldy     #0
224         lda     (ptr1),y
225         sta     PARAM1
226         jsr     PAPER
227         ldy     #1
228         lda     (ptr1),y
229         sta     PARAM1
230         jsr     INK
231         lda     #TGI_ERR_OK
232         sta     ERROR
233         rts
234
235 ; ------------------------------------------------------------------------
236 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
237 ; set the palette should return the default palette here, so there's no
238 ; way for this function to fail.
239 ;
240 ; Must set an error code: NO
241 ;
242
243 GETPALETTE:
244
245 ; ------------------------------------------------------------------------
246 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
247 ; drivers should return something reasonable here, even drivers that don't
248 ; support palettes, otherwise the caller has no way to determine the colors
249 ; of the (not changeable) palette.
250 ;
251 ; Must set an error code: NO (all drivers must have a default palette)
252 ;
253
254 GETDEFPALETTE:
255         lda     #<DEFPALETTE
256         ldx     #>DEFPALETTE
257         rts
258
259 ; ------------------------------------------------------------------------
260 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
261 ; color. The coordinates passed to this function are never outside the
262 ; visible screen area, so there is no need for clipping inside this function.
263 ;
264 ; Must set an error code: NO
265 ;
266
267 SETPIXEL:
268         lda     MODE
269 mymode: sta     PARAM3
270         lda     X1
271         sta     PARAM1
272         lda     Y1
273         sta     PARAM2
274         lda     #0
275         sta     PARAM1+1
276         sta     PARAM2+1
277         jmp     CURSET
278
279 ; ------------------------------------------------------------------------
280 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
281 ; coordinates passed to this function are never outside the visible screen
282 ; area, so there is no need for clipping inside this function.
283
284 GETPIXEL:
285         lda     X1
286         sta     PARAM1
287         lda     Y1
288         sta     PARAM2
289         lda     #0
290         sta     PARAM1+1
291         sta     PARAM2+1
292         jsr     POINT
293         lda     PARAM1
294         and     #%00000001
295         ldx     #0
296         rts
297
298 ; ------------------------------------------------------------------------
299 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
300 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
301 ;
302 ; Must set an error code: NO
303 ;
304
305 LINE:
306         jsr     SETPIXEL
307         lda     X2
308         sub     X1
309         sta     PARAM1
310         lda     X2+1
311         sbc     X1+1
312         sta     PARAM1+1
313         lda     Y2
314         sub     Y1
315         sta     PARAM2
316         lda     Y2+1
317         sbc     Y1+1
318         sta     PARAM2+1
319         lda     MODE
320         sta     PARAM3
321         jmp     DRAW
322
323 ; ------------------------------------------------------------------------
324 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
325 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
326 ; Contrary to most other functions, the graphics kernel will sort and clip
327 ; the coordinates before calling the driver, so on entry the following
328 ; conditions are valid:
329 ;       X1 <= X2
330 ;       Y1 <= Y2
331 ;       (X1 >= 0) && (X1 < XRES)
332 ;       (X2 >= 0) && (X2 < XRES)
333 ;       (Y1 >= 0) && (Y1 < YRES)
334 ;       (Y2 >= 0) && (Y2 < YRES)
335 ;
336 ; Must set an error code: NO
337 ;
338
339 BAR:
340         inc     Y2
341 @L1:    lda     Y2
342         pha
343         lda     Y1
344         sta     Y2
345         jsr     LINE
346         pla
347         sta     Y2
348         inc     Y1
349         cmp     Y1
350         bne     @L1
351         rts
352
353 ; ------------------------------------------------------------------------
354 ; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the
355 ; radius in tmp1 and the current drawing color.
356 ;
357 ; Must set an error code: NO
358 ;
359
360 _CIRCLE:
361         lda     #3
362         jsr     mymode
363         lda     RADIUS
364         sta     PARAM1
365         lda     MODE
366         sta     PARAM2
367         jmp     CIRCLE
368
369 ; ------------------------------------------------------------------------
370 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
371 ; direction is passend in X/Y, the text direction is passed in A.
372 ;
373 ; Must set an error code: NO
374 ;
375
376 TEXTSTYLE:
377         rts
378
379
380 ; ------------------------------------------------------------------------
381 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
382 ; current text style. The text to output is given as a zero terminated
383 ; string with address in ptr3.
384 ;
385 ; Must set an error code: NO
386 ;
387
388 OUTTEXT:
389         lda     X1
390         sta     PARAM1
391         lda     Y1
392         sta     PARAM2
393         lda     #3
394         sta     PARAM3
395         jsr     CURSET
396
397         ldy     #0
398 @next:  lda     (ptr3),y
399         beq     @end
400         sta     PARAM1
401         lda     #0
402         sta     PARAM2
403         lda     MODE
404         sta     PARAM3
405         tya
406         pha
407         jsr     CHAR
408         lda     xsize
409         sta     PARAM1
410         lda     #0
411         sta     PARAM2
412         lda     #3
413         sta     PARAM3
414         jsr     CURMOV
415         pla
416         tay
417         iny
418         bne     @next
419 @end:   rts