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