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