]> git.sur5r.net Git - cc65/blob - libsrc/atmos/atmos-240-200-2.s
Parse #pragma align() (does nothing currently).
[cc65] / libsrc / atmos / atmos-240-200-2.s
1 ;
2 ; Graphics driver for the 240x200x2 mode on the Atmos
3 ;
4 ; Stefan Haubenthal <polluks@sdf.lonestar.org>
5 ;
6
7         .include        "zeropage.inc"
8
9         .include        "tgi-kernel.inc"
10         .include        "tgi-error.inc"
11         .include        "atmos.inc"
12
13         .macpack        generic
14
15 ; ------------------------------------------------------------------------
16 ; Header. Includes jump table and constants.
17
18 .segment        "JUMPTABLE"
19
20 ; First part of the header is a structure that has a magic and defines the
21 ; capabilities of the driver
22
23         .byte   $74, $67, $69           ; "tgi"
24         .byte   TGI_API_VERSION         ; TGI API version number
25         .word   240                     ; X resolution
26         .word   200                     ; Y resolution
27         .byte   2                       ; Number of drawing colors
28         .byte   1                       ; Number of screens available
29 xsize:  .byte   6                       ; System font X size
30         .byte   8                       ; System font Y size
31         .word   $011C                   ; Aspect ratio (based on 4/3 display)
32
33 ; Next comes the jump table. Currently all entries must be valid and may point
34 ; to an RTS for test versions (function not implemented).
35
36         .addr   INSTALL
37         .addr   UNINSTALL
38         .addr   INIT
39         .addr   DONE
40         .addr   GETERROR
41         .addr   CONTROL
42         .addr   CLEAR
43         .addr   SETVIEWPAGE
44         .addr   SETDRAWPAGE
45         .addr   SETCOLOR
46         .addr   SETPALETTE
47         .addr   GETPALETTE
48         .addr   GETDEFPALETTE
49         .addr   SETPIXEL
50         .addr   GETPIXEL
51         .addr   LINE
52         .addr   BAR
53         .addr   TEXTSTYLE
54         .addr   OUTTEXT
55         .addr   0                       ; IRQ entry is unused
56
57 ; ------------------------------------------------------------------------
58 ; Data.
59
60 ; Variables mapped to the zero page segment variables. Some of these are
61 ; used for passing parameters to the driver.
62
63 X1              = ptr1
64 Y1              = ptr2
65 X2              = ptr3
66 Y2              = ptr4
67 RADIUS          = tmp1
68
69 ; Absolute variables used in the code
70
71 .bss
72
73 ERROR:          .res    1       ; Error code
74 MODE:           .res    1       ; Graphics mode
75
76 ; Constants and tables
77 PARAM1          = $2E1
78 PARAM2          = $2E3
79 PARAM3          = $2E5
80 TEXT            = $EC21
81 HIRES           = $EC33
82 CURSET          = $F0C8
83 CURMOV          = $F0FD
84 DRAW            = $F110
85 CHAR            = $F12D
86 POINT           = $F1C8
87 PAPER           = $F204
88 INK             = $F210
89
90 .rodata
91
92 DEFPALETTE:     .byte   $00, $07
93
94 .code
95
96 ; ------------------------------------------------------------------------
97 ; INSTALL routine. Is called after the driver is loaded into memory. May
98 ; initialize anything that has to be done just once. Is probably empty
99 ; most of the time.
100 ;
101 ; Must set an error code: NO
102 ;
103
104 INSTALL:
105
106 ; ------------------------------------------------------------------------
107 ; UNINSTALL routine. Is called before the driver is removed from memory. May
108 ; clean up anything done by INSTALL but is probably empty most of the time.
109 ;
110 ; Must set an error code: NO
111 ;
112
113 UNINSTALL:
114         rts
115
116 ; ------------------------------------------------------------------------
117 ; INIT: Changes an already installed device from text mode to graphics
118 ; mode.
119 ; Note that INIT/DONE may be called multiple times while the driver
120 ; is loaded, while INSTALL is only called once, so any code that is needed
121 ; to initializes variables and so on must go here. Setting palette and
122 ; clearing the screen is not needed because this is called by the graphics
123 ; kernel later.
124 ; The graphics kernel will never call INIT when a graphics mode is already
125 ; active, so there is no need to protect against that.
126 ;
127 ; Must set an error code: YES
128 ;
129
130 INIT:
131
132 ; Switch into graphics mode
133
134         jsr     HIRES
135
136 ; Done, reset the error code
137
138         lda     #TGI_ERR_OK
139         sta     ERROR
140         rts
141
142 ; ------------------------------------------------------------------------
143 ; DONE: Will be called to switch the graphics device back into text mode.
144 ; The graphics kernel will never call DONE when no graphics mode is active,
145 ; so there is no need to protect against that.
146 ;
147 ; Must set an error code: NO
148 ;
149
150 DONE            = TEXT
151
152 ; ------------------------------------------------------------------------
153 ; GETERROR: Return the error code in A and clear it.
154
155 GETERROR:
156         ldx     #TGI_ERR_OK
157         lda     ERROR
158         stx     ERROR
159         rts
160
161 ; ------------------------------------------------------------------------
162 ; CONTROL: Platform/driver specific entry point.
163 ;
164 ; Must set an error code: YES
165 ;
166
167 CONTROL:
168         sta     $213
169         lda     #TGI_ERR_OK
170         sta     ERROR
171         rts
172
173 ; ------------------------------------------------------------------------
174 ; CLEAR: Clears the screen.
175 ;
176 ; Must set an error code: NO
177 ;
178
179 CLEAR           = HIRES
180
181 ; ------------------------------------------------------------------------
182 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
183 ; The page number is already checked to be valid by the graphics kernel.
184 ;
185 ; Must set an error code: NO (will only be called if page ok)
186 ;
187
188 SETVIEWPAGE:
189
190 ; ------------------------------------------------------------------------
191 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
192 ; The page number is already checked to be valid by the graphics kernel.
193 ;
194 ; Must set an error code: NO (will only be called if page ok)
195 ;
196
197 SETDRAWPAGE:
198         rts
199
200 ; ------------------------------------------------------------------------
201 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
202 ; to be in a valid range (0..maxcolor-1).
203 ;
204 ; Must set an error code: NO (will only be called if color ok)
205 ;
206
207 SETCOLOR:
208         sta     MODE
209         rts
210
211 ; ------------------------------------------------------------------------
212 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
213 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
214 ; are not supported
215 ;
216 ; Must set an error code: YES
217 ;
218
219 SETPALETTE:
220         ldy     #0
221         lda     (ptr1),y
222         sta     PARAM1
223         jsr     PAPER
224         ldy     #1
225         lda     (ptr1),y
226         sta     PARAM1
227         jsr     INK
228         lda     #TGI_ERR_OK
229         sta     ERROR
230         rts
231
232 ; ------------------------------------------------------------------------
233 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
234 ; set the palette should return the default palette here, so there's no
235 ; way for this function to fail.
236 ;
237 ; Must set an error code: NO
238 ;
239
240 GETPALETTE:
241
242 ; ------------------------------------------------------------------------
243 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
244 ; drivers should return something reasonable here, even drivers that don't
245 ; support palettes, otherwise the caller has no way to determine the colors
246 ; of the (not changeable) palette.
247 ;
248 ; Must set an error code: NO (all drivers must have a default palette)
249 ;
250
251 GETDEFPALETTE:
252         lda     #<DEFPALETTE
253         ldx     #>DEFPALETTE
254         rts
255
256 ; ------------------------------------------------------------------------
257 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
258 ; color. The coordinates passed to this function are never outside the
259 ; visible screen area, so there is no need for clipping inside this function.
260 ;
261 ; Must set an error code: NO
262 ;
263
264 SETPIXEL:
265         lda     MODE
266 mymode: sta     PARAM3
267         lda     X1
268         sta     PARAM1
269         lda     Y1
270         sta     PARAM2
271         lda     #0
272         sta     PARAM1+1
273         sta     PARAM2+1
274         jmp     CURSET
275
276 ; ------------------------------------------------------------------------
277 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
278 ; coordinates passed to this function are never outside the visible screen
279 ; area, so there is no need for clipping inside this function.
280
281 GETPIXEL:
282         lda     X1
283         sta     PARAM1
284         lda     Y1
285         sta     PARAM2
286         lda     #0
287         sta     PARAM1+1
288         sta     PARAM2+1
289         jsr     POINT
290         lda     PARAM1
291         and     #%00000001
292         ldx     #0
293         rts
294
295 ; ------------------------------------------------------------------------
296 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
297 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
298 ;
299 ; Must set an error code: NO
300 ;
301
302 LINE:
303         jsr     SETPIXEL
304         lda     X2
305         sub     X1
306         sta     PARAM1
307         lda     X2+1
308         sbc     X1+1
309         sta     PARAM1+1
310         lda     Y2
311         sub     Y1
312         sta     PARAM2
313         lda     Y2+1
314         sbc     Y1+1
315         sta     PARAM2+1
316         lda     MODE
317         sta     PARAM3
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     X1
371         sta     PARAM1
372         lda     Y1
373         sta     PARAM2
374         lda     #3
375         sta     PARAM3
376         jsr     CURSET
377
378         ldy     #0
379 @next:  lda     (ptr3),y
380         beq     @end
381         sta     PARAM1
382         lda     #0
383         sta     PARAM2
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         lda     #3
394         sta     PARAM3
395         jsr     CURMOV
396         pla
397         tay
398         iny
399         bne     @next
400 @end:   rts