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