2 ; Graphics driver for the 40x48x16 mode on the Apple II
4 ; Stefan Haubenthal <polluks@sdf.lonestar.org>
5 ; Oliver Schmidt <ol.sc@web.de>
8 .include "zeropage.inc"
10 .include "tgi-kernel.inc"
11 .include "tgi-error.inc"
16 ; ------------------------------------------------------------------------
34 ; Used for passing parameters to the driver
41 ; ------------------------------------------------------------------------
44 module_header _a2e_lo_tgi
46 module_header _a2_lo_tgi
49 ; Header. Includes jump table and constants.
51 ; First part of the header is a structure that has a magic and defines the
52 ; capabilities of the driver
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 8 ; System font X size
62 .byte 8 ; System font Y size
63 .word $0198 ; Aspect ratio (based on 4/3 display)
64 .byte 0 ; TGI driver flags
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).
88 .addr 0 ; IRQ entry is unused
90 ; ------------------------------------------------------------------------
94 ERROR: .res 1 ; Error code
95 MIX: .res 1 ; 4 lines of text
97 ; ------------------------------------------------------------------------
101 DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
102 .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
104 TGI2COL: .byte $00, $0C, $03, $0F, $01, $09, $06, $02
105 .byte $04, $05, $07, $08, $0A, $0B, $0D, $0E
107 COL2TGI: .byte $00, $04, $07, $02, $08, $09, $06, $0A
108 .byte $0B, $05, $0C, $0D, $01, $0E, $0F, $03
112 ; ------------------------------------------------------------------------
116 ; INIT: Changes an already installed device from text mode to graphics mode.
117 ; Note that INIT/DONE may be called multiple times while the driver
118 ; is loaded, while INSTALL is only called once, so any code that is needed
119 ; to initializes variables and so on must go here. Setting palette and
120 ; clearing the screen is not needed because this is called by the graphics
122 ; The graphics kernel will never call INIT when a graphics mode is already
123 ; active, so there is no need to protect against that.
124 ; Must set an error code: YES
126 ; Switch into graphics mode
127 bit $C082 ; Switch in ROM
130 bit $C080 ; Switch in LC bank 2 for R/O
132 ; Done, reset the error code
139 ; INSTALL routine. Is called after the driver is loaded into memory. May
140 ; initialize anything that has to be done just once. Is probably empty
142 ; Must set an error code: NO
146 ; UNINSTALL routine. Is called before the driver is removed from memory. May
147 ; clean up anything done by INSTALL but is probably empty most of the time.
148 ; Must set an error code: NO
152 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
153 ; The page number is already checked to be valid by the graphics kernel.
154 ; Must set an error code: NO (will only be called if page ok)
158 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
159 ; The page number is already checked to be valid by the graphics kernel.
160 ; Must set an error code: NO (will only be called if page ok)
164 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
165 ; direction is passend in X/Y, the text direction is passed in A.
166 ; Must set an error code: NO
170 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
171 ; current text style. The text to output is given as a zero terminated
172 ; string with address in ptr3.
173 ; Must set an error code: NO
177 ; DONE: Will be called to switch the graphics device back into text mode.
178 ; The graphics kernel will never call DONE when no graphics mode is active,
179 ; so there is no need to protect against that.
180 ; Must set an error code: NO
182 bit $C082 ; Switch in ROM
185 bit $C080 ; Switch in LC bank 2 for R/O
188 ; GETERROR: Return the error code in A and clear it.
195 ; CLEAR: Clears the screen.
196 ; Must set an error code: NO
198 bit $C082 ; Switch in ROM
199 lda COLOR ; Save current drawing color
202 ldy MAXY,x ; Max Y depends on 4 lines of text
205 sta COLOR ; Restore current drawing color
206 bit $C080 ; Switch in LC bank 2 for R/O
209 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
210 ; to be in a valid range (0..maxcolor-1).
211 ; Must set an error code: NO (will only be called if color ok)
213 bit $C082 ; Switch in ROM
217 bit $C080 ; Switch in LC bank 2 for R/O
220 ; CONTROL: Platform/driver specific entry point.
221 ; Must set an error code: YES
223 ; Check data msb and code to be 0
227 ; Check data lsb to be [0..1]
231 bit $C082 ; Switch in ROM
233 ; Switch 4 lines of text
235 .assert MIXCLR + 1 = MIXSET, error
236 lda MIXCLR,x ; No BIT absolute,X available
238 ; Save current switch setting
243 ; Clear 8 lines of graphics
244 lda COLOR ; Save current drawing color
246 lda #39 ; Rightmost column
250 ldy #$00 ; Leftmost column
252 jsr HLINE ; Preserves X
254 cpx #47+1 ; Last line
257 sta COLOR ; Restore current drawing color
258 bcs :+ ; Branch always
260 ; Clear 4 lines of text
262 : bit $C080 ; Switch in LC bank 2 for R/O
264 ; Done, reset the error code
266 beq :+ ; Branch always
268 ; Done, set the error code
269 err: lda #TGI_ERR_INV_ARG
273 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
274 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
276 ; Must set an error code: YES
278 lda #TGI_ERR_INV_FUNC
282 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
283 ; set the palette should return the default palette here, so there's no
284 ; way for this function to fail.
285 ; Must set an error code: NO
289 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
290 ; drivers should return something reasonable here, even drivers that don't
291 ; support palettes, otherwise the caller has no way to determine the colors
292 ; of the (not changeable) palette.
293 ; Must set an error code: NO (all drivers must have a default palette)
299 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
300 ; color. The coordinates passed to this function are never outside the
301 ; visible screen area, so there is no need for clipping inside this function.
302 ; Must set an error code: NO
304 bit $C082 ; Switch in ROM
308 bit $C080 ; Switch in LC bank 2 for R/O
311 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
312 ; coordinates passed to this function are never outside the visible screen
313 ; area, so there is no need for clipping inside this function.
315 bit $C082 ; Switch in ROM
322 bit $C080 ; Switch in LC bank 2 for R/O
325 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
326 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
327 ; Contrary to most other functions, the graphics kernel will sort and clip
328 ; the coordinates before calling the driver, so on entry the following
329 ; conditions are valid:
332 ; (X1 >= 0) && (X1 < XRES)
333 ; (X2 >= 0) && (X2 < XRES)
334 ; (Y1 >= 0) && (Y1 < YRES)
335 ; (Y2 >= 0) && (Y2 < YRES)
336 ; Must set an error code: NO
338 bit $C082 ; Switch in ROM
345 jsr HLINE ; Preserves X
349 bit $C080 ; Switch in LC bank 2 for R/O
352 ; ------------------------------------------------------------------------
354 .include "../../tgi/tgidrv_line.inc"