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