]> git.sur5r.net Git - cc65/blob - libsrc/apple2/tgi/a2.lo.s
Indicate a dummy outtext
[cc65] / libsrc / apple2 / tgi / a2.lo.s
1 ;
2 ; Graphics driver for the 40x48x16 mode on the Apple II
3 ;
4 ; Stefan Haubenthal <polluks@sdf.lonestar.org>
5 ; Oliver Schmidt <ol.sc@web.de>
6 ;
7
8         .include        "zeropage.inc"
9
10         .include        "tgi-kernel.inc"
11         .include        "tgi-error.inc"
12         .include        "apple2.inc"
13
14         .macpack        module
15
16 ; ------------------------------------------------------------------------
17
18 ; Zero page stuff
19
20 H2      :=      $2C
21 COLOR   :=      $30
22
23 ; ROM entry points
24
25 TEXT    :=      $F399
26 PLOT    :=      $F800
27 HLINE   :=      $F819
28 CLRSC2  :=      $F838
29 SETCOL  :=      $F864
30 SCRN    :=      $F871
31 SETGR   :=      $FB40
32 HOME    :=      $FC58
33
34 ; Used for passing parameters to the driver
35
36 X1      :=      ptr1
37 Y1      :=      ptr2
38 X2      :=      ptr3
39 Y2      :=      ptr4
40
41 ; ------------------------------------------------------------------------
42
43         .ifdef  __APPLE2ENH__
44         module_header   _a2e_lo_tgi
45         .else
46         module_header   _a2_lo_tgi
47         .endif
48
49 ; Header. Includes jump table and constants.
50
51 ; First part of the header is a structure that has a magic and defines the
52 ; capabilities of the driver
53
54         .byte   $74, $67, $69   ; "tgi"
55         .byte   TGI_API_VERSION ; TGI API version number
56         .addr   $0000           ; Library reference
57         .word   40              ; X resolution
58         .word   48              ; Y resolution
59         .byte   16              ; Number of drawing colors
60         .byte   1               ; Number of screens available
61         .byte   0               ; System font X size
62         .byte   0               ; System font Y size
63         .word   $0198           ; Aspect ratio (based on 4/3 display)
64         .byte   0               ; TGI driver flags
65
66 ; Next comes the jump table. With the exception of IRQ, all entries must be
67 ; valid and may point to an RTS for test versions (function not implemented).
68
69         .addr   INSTALL
70         .addr   UNINSTALL
71         .addr   INIT
72         .addr   DONE
73         .addr   GETERROR
74         .addr   CONTROL
75         .addr   CLEAR
76         .addr   SETVIEWPAGE
77         .addr   SETDRAWPAGE
78         .addr   SETCOLOR
79         .addr   SETPALETTE
80         .addr   GETPALETTE
81         .addr   GETDEFPALETTE
82         .addr   SETPIXEL
83         .addr   GETPIXEL
84         .addr   LINE
85         .addr   BAR
86         .addr   TEXTSTYLE
87         .addr   OUTTEXT
88
89 ; ------------------------------------------------------------------------
90
91         .bss
92
93 ERROR:  .res    1               ; Error code
94 MIX:    .res    1               ; 4 lines of text
95
96 ; ------------------------------------------------------------------------
97
98         .rodata
99
100 DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
101             .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
102
103 TGI2COL:    .byte $00, $0C, $03, $0F, $01, $09, $06, $02
104             .byte $04, $05, $07, $08, $0A, $0B, $0D, $0E
105
106 COL2TGI:    .byte $00, $04, $07, $02, $08, $09, $06, $0A
107             .byte $0B, $05, $0C, $0D, $01, $0E, $0F, $03
108
109 MAXY:   .byte 47, 39
110
111 ; ------------------------------------------------------------------------
112
113         .code
114
115 ; INIT: Changes an already installed device from text mode to graphics mode.
116 ; Note that INIT/DONE may be called multiple times while the driver
117 ; is loaded, while INSTALL is only called once, so any code that is needed
118 ; to initializes variables and so on must go here. Setting palette and
119 ; clearing the screen is not needed because this is called by the graphics
120 ; kernel later.
121 ; The graphics kernel will never call INIT when a graphics mode is already
122 ; active, so there is no need to protect against that.
123 ; Must set an error code: YES
124 INIT:
125         ; Switch into graphics mode
126         bit     $C082           ; Switch in ROM
127         jsr     SETGR
128         bit     MIXCLR
129         bit     $C080           ; Switch in LC bank 2 for R/O
130
131         ; Done, reset the error code
132         lda     #TGI_ERR_OK
133         sta     ERROR
134         sta     MIX
135
136         ; Fall through
137
138 ; INSTALL routine. Is called after the driver is loaded into memory. May
139 ; initialize anything that has to be done just once. Is probably empty
140 ; most of the time.
141 ; Must set an error code: NO
142 INSTALL:
143         ; Fall through
144
145 ; UNINSTALL routine. Is called before the driver is removed from memory. May
146 ; clean up anything done by INSTALL but is probably empty most of the time.
147 ; Must set an error code: NO
148 UNINSTALL:
149         ; Fall through
150
151 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
152 ; The page number is already checked to be valid by the graphics kernel.
153 ; Must set an error code: NO (will only be called if page ok)
154 SETVIEWPAGE:
155         ; Fall through
156
157 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
158 ; The page number is already checked to be valid by the graphics kernel.
159 ; Must set an error code: NO (will only be called if page ok)
160 SETDRAWPAGE:
161         ; Fall through
162
163 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
164 ; direction is passend in X/Y, the text direction is passed in A.
165 ; Must set an error code: NO
166 TEXTSTYLE:
167         ; Fall through
168
169 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
170 ; current text style. The text to output is given as a zero terminated
171 ; string with address in ptr3.
172 ; Must set an error code: NO
173 OUTTEXT:
174         rts
175
176 ; DONE: Will be called to switch the graphics device back into text mode.
177 ; The graphics kernel will never call DONE when no graphics mode is active,
178 ; so there is no need to protect against that.
179 ; Must set an error code: NO
180 DONE:
181         bit     $C082           ; Switch in ROM
182         jsr     TEXT
183         jsr     HOME
184         bit     $C080           ; Switch in LC bank 2 for R/O
185         rts
186
187 ; GETERROR: Return the error code in A and clear it.
188 GETERROR:
189         lda     ERROR
190         ldx     #TGI_ERR_OK
191         stx     ERROR
192         rts
193
194 ; CLEAR: Clears the screen.
195 ; Must set an error code: NO
196 CLEAR:
197         bit     $C082           ; Switch in ROM
198         lda     COLOR           ; Save current drawing color
199         pha
200         ldx     MIX
201         ldy     MAXY,x          ; Max Y depends on 4 lines of text
202         jsr     CLRSC2
203         pla
204         sta     COLOR           ; Restore current drawing color
205         bit     $C080           ; Switch in LC bank 2 for R/O
206         rts
207
208 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
209 ; to be in a valid range (0..maxcolor-1).
210 ; Must set an error code: NO (will only be called if color ok)
211 SETCOLOR:
212         bit     $C082           ; Switch in ROM
213         tax
214         lda     TGI2COL,x
215         jsr     SETCOL
216         bit     $C080           ; Switch in LC bank 2 for R/O
217         rts
218
219 ; CONTROL: Platform/driver specific entry point.
220 ; Must set an error code: YES
221 CONTROL:
222         ; Check data msb and code to be 0
223         ora     ptr1+1
224         bne     err
225
226         ; Check data lsb to be [0..1]
227         lda     ptr1
228         cmp     #1+1
229         bcs     err
230         bit     $C082           ; Switch in ROM
231
232         ; Switch 4 lines of text
233         tax
234         .assert MIXCLR + 1 = MIXSET, error
235         lda     MIXCLR,x        ; No BIT absolute,X available
236
237         ; Save current switch setting
238         txa
239         sta     MIX
240         bne     text
241
242         ; Clear 8 lines of graphics
243         lda     COLOR           ; Save current drawing color
244         pha
245         lda     #39             ; Rightmost column
246         sta     H2
247         ldx     #40             ; First line
248 :       txa
249         ldy     #$00            ; Leftmost column
250         sty     COLOR           ; Black
251         jsr     HLINE           ; Preserves X
252         inx
253         cpx     #47+1           ; Last line
254         bcc     :-
255         pla
256         sta     COLOR           ; Restore current drawing color
257         bcs     :+              ; Branch always
258
259         ; Clear 4 lines of text
260 text:   jsr     HOME
261 :       bit     $C080           ; Switch in LC bank 2 for R/O
262
263         ; Done, reset the error code
264         lda     #TGI_ERR_OK
265         beq     :+              ; Branch always
266
267         ; Done, set the error code
268 err:    lda     #TGI_ERR_INV_ARG
269 :       sta     ERROR
270         rts
271
272 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
273 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
274 ; are not supported
275 ; Must set an error code: YES
276 SETPALETTE:
277         lda     #TGI_ERR_INV_FUNC
278         sta     ERROR
279         rts
280
281 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
282 ; set the palette should return the default palette here, so there's no
283 ; way for this function to fail.
284 ; Must set an error code: NO
285 GETPALETTE:
286         ; Fall through
287
288 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
289 ; drivers should return something reasonable here, even drivers that don't
290 ; support palettes, otherwise the caller has no way to determine the colors
291 ; of the (not changeable) palette.
292 ; Must set an error code: NO (all drivers must have a default palette)
293 GETDEFPALETTE:
294         lda     #<DEFPALETTE
295         ldx     #>DEFPALETTE
296         rts
297
298 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
299 ; color. The coordinates passed to this function are never outside the
300 ; visible screen area, so there is no need for clipping inside this function.
301 ; Must set an error code: NO
302 SETPIXEL:
303         bit     $C082           ; Switch in ROM
304         ldy     X1
305         lda     Y1
306         jsr     PLOT
307         bit     $C080           ; Switch in LC bank 2 for R/O
308         rts
309
310 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
311 ; coordinates passed to this function are never outside the visible screen
312 ; area, so there is no need for clipping inside this function.
313 GETPIXEL:
314         bit     $C082           ; Switch in ROM
315         ldy     X1
316         lda     Y1
317         jsr     SCRN
318         tax
319         lda     COL2TGI,x
320         ldx     #$00
321         bit     $C080           ; Switch in LC bank 2 for R/O
322         rts
323
324 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
325 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
326 ; Contrary to most other functions, the graphics kernel will sort and clip
327 ; the coordinates before calling the driver, so on entry the following
328 ; conditions are valid:
329 ;       X1 <= X2
330 ;       Y1 <= Y2
331 ;       (X1 >= 0) && (X1 < XRES)
332 ;       (X2 >= 0) && (X2 < XRES)
333 ;       (Y1 >= 0) && (Y1 < YRES)
334 ;       (Y2 >= 0) && (Y2 < YRES)
335 ; Must set an error code: NO
336 BAR:
337         bit     $C082           ; Switch in ROM
338         lda     X2
339         sta     H2
340         inc     Y2
341         ldx     Y1
342 :       txa
343         ldy     X1
344         jsr     HLINE           ; Preserves X
345         inx
346         cpx     Y2
347         bcc     :-
348         bit     $C080           ; Switch in LC bank 2 for R/O
349         rts
350
351 ; ------------------------------------------------------------------------
352
353 .include        "../../tgi/tgidrv_line.inc"