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