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