]> git.sur5r.net Git - cc65/blob - libsrc/telestrat/tgi/telestrat-240-200-2.s
3ee918c4fd5e1aad3428abcacaf58503fd04b9b1
[cc65] / libsrc / telestrat / tgi / telestrat-240-200-2.s
1 ;
2 ; Graphics driver for the 240x200x2 monochrome mode on the Atmos
3 ;
4 ; Jede (jede@oric.org), 2017-10-15
5
6
7         .include        "zeropage.inc"
8
9         .include        "tgi-kernel.inc"
10         .include        "tgi-error.inc"
11         .include        "telestrat.inc"
12
13         .macpack        generic
14         .macpack        module
15
16 XSIZE   =       6                       ; System font width
17 YSIZE   =       8                       ; System font height
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table and constants.
21
22         module_header   _telestrat_240_200_2_tgi
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
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 ; Constant table
81
82 .rodata
83
84 DEFPALETTE:     .byte   0, 1
85
86 .code
87
88 ; ------------------------------------------------------------------------
89 ; INSTALL routine. Is called after the driver is loaded into memory. May
90 ; initialize anything that has to be done just once. Is probably empty
91 ; most of the time.
92 ;
93 ; Must set an error code: NO
94 ;
95
96 INSTALL:
97
98 ; ------------------------------------------------------------------------
99 ; UNINSTALL routine. Is called before the driver is removed from memory. May
100 ; clean up anything done by INSTALL but is probably empty most of the time.
101 ;
102 ; Must set an error code: NO
103 ;
104
105 UNINSTALL:
106         rts
107
108 ; ------------------------------------------------------------------------
109 ; INIT: Changes an already installed device from text mode to graphics
110 ; mode.
111 ; Note that INIT/DONE may be called multiple times while the driver
112 ; is loaded, while INSTALL is only called once, so any code that is needed
113 ; to initializes variables and so on must go here. Setting palette and
114 ; clearing the screen is not needed because this is called by the graphics
115 ; kernel later.
116 ; The graphics kernel will never call INIT when a graphics mode is already
117 ; active, so there is no need to protect against that.
118 ;
119 ; Must set an error code: YES
120 ;
121
122 INIT:
123
124 ; Switch into graphics mode
125
126         BRK_TELEMON(XHIRES)
127       
128 ; Done, reset the error code
129
130         lda     #TGI_ERR_OK
131         sta     ERROR
132         rts
133
134 ; ------------------------------------------------------------------------
135 ; DONE: Will be called to switch the graphics device back into text mode.
136 ; The graphics kernel will never call DONE when no graphics mode is active,
137 ; so there is no need to protect against that.
138 ;
139 ; Must set an error code: NO
140 ;
141
142 DONE:
143         BRK_TELEMON(XTEXT)
144         rts
145
146 ; ------------------------------------------------------------------------
147 ; GETERROR: Return the error code in A and clear it.
148
149 GETERROR:
150         ldx     #TGI_ERR_OK
151         lda     ERROR
152         stx     ERROR
153         rts
154
155 ; ------------------------------------------------------------------------
156 ; CONTROL: Platform/driver specific entry point.
157 ;
158 ; Must set an error code: YES
159 ;
160
161 CONTROL:
162         ; not done yet
163         rts
164
165 ; ------------------------------------------------------------------------
166 ; CLEAR: Clears the screen.
167 ;
168 ; Must set an error code: NO
169 ;
170
171 CLEAR:
172         ; not done yet
173         rts
174
175 ; ------------------------------------------------------------------------
176 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
177 ; The page number is already checked to be valid by the graphics kernel.
178 ;
179 ; Must set an error code: NO (will only be called if page ok)
180 ;
181
182 SETVIEWPAGE:
183
184 ; ------------------------------------------------------------------------
185 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
186 ; The page number is already checked to be valid by the graphics kernel.
187 ;
188 ; Must set an error code: NO (will only be called if page ok)
189 ;
190
191 SETDRAWPAGE:
192         rts
193
194 ; ------------------------------------------------------------------------
195 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
196 ; to be in a valid range (0..maxcolor-1).
197 ;
198 ; Must set an error code: NO (will only be called if color ok)
199 ;
200
201 SETCOLOR:
202         ;not done yet
203         rts
204
205 ; ------------------------------------------------------------------------
206 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
207 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
208 ; are not supported
209 ;
210 ; Must set an error code: YES
211 ;
212
213 SETPALETTE:
214         lda     #TGI_ERR_INV_FUNC       ; This resolution has no palette
215         sta     ERROR
216         rts
217
218 ; ------------------------------------------------------------------------
219 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
220 ; set the palette should return the default palette here, so there's no
221 ; way for this function to fail.
222 ;
223 ; Must set an error code: NO
224 ;
225
226 GETPALETTE:
227
228 ; ------------------------------------------------------------------------
229 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
230 ; drivers should return something reasonable here, even drivers that don't
231 ; support palettes, otherwise the caller has no way to determine the colors
232 ; of the (not changeable) palette.
233 ;
234 ; Must set an error code: NO (all drivers must have a default palette)
235 ;
236
237 GETDEFPALETTE:
238         ; not done yet
239         rts
240
241 ; ------------------------------------------------------------------------
242 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
243 ; color. The coordinates passed to this function are never outside the
244 ; visible screen area, so there is no need for clipping inside this function.
245 ;
246 ; Must set an error code: NO
247 ;
248
249 SETPIXEL:
250         lda #$80       ; curset on 
251 SETPIXELSETMODE:        
252         sta HRSFB
253         
254         lda X1
255         sta HRS1
256         lda Y1
257         sta HRS2
258         
259         
260         
261         BRK_TELEMON(XCURSE)
262
263         rts
264
265 ; ------------------------------------------------------------------------
266 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
267 ; coordinates passed to this function are never outside the visible screen
268 ; area, so there is no need for clipping inside this function.
269
270 GETPIXEL:
271         ; not done yet
272         rts
273
274 ; ------------------------------------------------------------------------
275 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
276 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
277 ;
278 ; Must set an error code: NO
279 ;
280
281 LINE:
282
283         lda   X1
284         sta   HRS1
285         lda   Y1
286         sta   HRS2
287
288         lda   X2
289         sta   HRS3
290         lda   Y2
291         sta   HRS4
292         
293         lda   #$ff
294         sta   HRSPAT
295
296         BRK_TELEMON(XDRAWA)
297
298         rts
299         
300 CIRCLE:    
301         ; not done yet
302         rts      
303       
304 ; ------------------------------------------------------------------------
305 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
306 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
307 ; Contrary to most other functions, the graphics kernel will sort and clip
308 ; the coordinates before calling the driver, so on entry the following
309 ; conditions are valid:
310 ;       X1 <= X2
311 ;       Y1 <= Y2
312 ;       (X1 >= 0) && (X1 < XRES)
313 ;       (X2 >= 0) && (X2 < XRES)
314 ;       (Y1 >= 0) && (Y1 < YRES)
315 ;       (Y2 >= 0) && (Y2 < YRES)
316 ;
317 ; Must set an error code: NO
318 ;
319
320 BAR:
321         ; not done yet
322         rts
323
324 ; ------------------------------------------------------------------------
325 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
326 ; direction is passend in X/Y, the text direction is passed in A.
327 ;
328 ; Must set an error code: NO
329 ;
330
331 TEXTSTYLE:
332         rts
333
334
335 ; ------------------------------------------------------------------------
336 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
337 ; current text style. The text to output is given as a zero terminated
338 ; string with address in ptr3.
339 ;
340 ; Must set an error code: NO
341 ;
342
343 OUTTEXT:
344         ; put hires cursor in X & Y
345         lda   #$00
346         jsr   SETPIXELSETMODE
347         
348         
349         ; count the length of the string
350         ldy   #$00
351 loop:        
352         lda   (ptr3),y
353         beq   out
354         iny
355         bne   loop
356 out:
357         ; XSCHAR routine from telemon needs to have the length of the string in X register
358         ; copy Y register to X register. It could be optimized in 65C02 with TYX
359         tya 
360         tax
361     
362         lda   ptr3     ; XSCHAR needs in A and Y the adress of the string        
363         ldy   ptr3+1    
364         BRK_TELEMON(XSCHAR)
365         rts