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