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