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-mode.inc"
12 .include "tgi-error.inc"
15 ; ------------------------------------------------------------------------
33 ; Used for passing parameters to the driver
40 ; ------------------------------------------------------------------------
44 ; Header. Includes jump table and constants.
46 ; First part of the header is a structure that has a magic and defines the
47 ; capabilities of the driver
49 .byte $74, $67, $69 ; "tgi"
50 .byte TGI_API_VERSION ; TGI API version number
51 .word 40 ; X resolution
52 .word 48 ; Y resolution
53 .byte 16 ; Number of drawing colors
54 .byte 1 ; Number of screens available
55 .byte 8 ; System font X size
56 .byte 8 ; System font Y size
57 .word $100 ; Aspect ratio
59 ; Next comes the jump table. With the exception of IRQ, all entries must be
60 ; valid and may point to an RTS for test versions (function not implemented).
81 .addr 0 ; IRQ entry is unused
83 ; ------------------------------------------------------------------------
87 ERROR: .res 1 ; Error code
88 MIX: .res 1 ; 4 lines of text
90 ; ------------------------------------------------------------------------
94 DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
95 .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
99 ; ------------------------------------------------------------------------
103 ; INIT: Changes an already installed device from text mode to graphics mode.
104 ; Note that INIT/DONE may be called multiple times while the driver
105 ; is loaded, while INSTALL is only called once, so any code that is needed
106 ; to initializes variables and so on must go here. Setting palette and
107 ; clearing the screen is not needed because this is called by the graphics
109 ; The graphics kernel will never call INIT when a graphics mode is already
110 ; active, so there is no need to protect against that.
111 ; Must set an error code: YES
113 ; Switch into graphics mode
114 bit $C082 ; Switch in ROM
117 bit $C080 ; Switch in LC bank 2 for R/O
119 ; Done, reset the error code
126 ; INSTALL routine. Is called after the driver is loaded into memory. May
127 ; initialize anything that has to be done just once. Is probably empty
129 ; Must set an error code: NO
133 ; UNINSTALL routine. Is called before the driver is removed from memory. May
134 ; clean up anything done by INSTALL but is probably empty most of the time.
135 ; Must set an error code: NO
139 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
140 ; The page number is already checked to be valid by the graphics kernel.
141 ; Must set an error code: NO (will only be called if page ok)
145 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
146 ; The page number is already checked to be valid by the graphics kernel.
147 ; Must set an error code: NO (will only be called if page ok)
151 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
152 ; direction is passend in X/Y, the text direction is passed in A.
153 ; Must set an error code: NO
157 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
158 ; current text style. The text to output is given as a zero terminated
159 ; string with address in ptr3.
160 ; Must set an error code: NO
164 ; DONE: Will be called to switch the graphics device back into text mode.
165 ; The graphics kernel will never call DONE when no graphics mode is active,
166 ; so there is no need to protect against that.
167 ; Must set an error code: NO
169 bit $C082 ; Switch in ROM
172 bit $C080 ; Switch in LC bank 2 for R/O
175 ; GETERROR: Return the error code in A and clear it.
182 ; CLEAR: Clears the screen.
183 ; Must set an error code: NO
185 bit $C082 ; Switch in ROM
186 lda COLOR ; Save current drawing color
189 ldy MAXY,x ; Max Y depends on 4 lines of text
192 sta COLOR ; Save current drawing color
193 bit $C080 ; Switch in LC bank 2 for R/O
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 ; Must set an error code: NO (will only be called if color ok)
200 bit $C082 ; Switch in ROM
202 bit $C080 ; Switch in LC bank 2 for R/O
205 ; CONTROL: Platform/driver specific entry point.
206 ; Must set an error code: YES
208 ; Check data msb and code to be 0
212 ; Check data lsb to be [0..1]
216 bit $C082 ; Switch in ROM
218 ; Switch 4 lines of text
220 .assert MIXCLR + 1 = MIXSET, error
221 lda MIXCLR,x ; No BIT absolute,X available
223 ; Save current switch setting
228 ; Clear 8 lines of graphics
229 lda COLOR ; Save current drawing color
231 lda #39 ; Rightmost column
235 ldy #$00 ; Leftmost column
237 jsr HLINE ; Preserves X
239 cpx #47+1 ; Last line
242 sta COLOR ; Save current drawing color
243 bcs :+ ; Branch always
245 ; Clear 4 lines of text
247 : bit $C080 ; Switch in LC bank 2 for R/O
249 ; Done, reset the error code
251 beq :+ ; Branch always
253 ; Done, set the error code
254 err: lda #TGI_ERR_INV_ARG
258 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
259 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
261 ; Must set an error code: YES
263 lda #TGI_ERR_INV_FUNC
267 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
268 ; set the palette should return the default palette here, so there's no
269 ; way for this function to fail.
270 ; Must set an error code: NO
274 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
275 ; drivers should return something reasonable here, even drivers that don't
276 ; support palettes, otherwise the caller has no way to determine the colors
277 ; of the (not changeable) palette.
278 ; Must set an error code: NO (all drivers must have a default palette)
284 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
285 ; color. The coordinates passed to this function are never outside the
286 ; visible screen area, so there is no need for clipping inside this function.
287 ; Must set an error code: NO
289 bit $C082 ; Switch in ROM
293 bit $C080 ; Switch in LC bank 2 for R/O
296 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
297 ; coordinates passed to this function are never outside the visible screen
298 ; area, so there is no need for clipping inside this function.
300 bit $C082 ; Switch in ROM
305 bit $C080 ; Switch in LC bank 2 for R/O
308 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
309 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
310 ; Contrary to most other functions, the graphics kernel will sort and clip
311 ; the coordinates before calling the driver, so on entry the following
312 ; conditions are valid:
315 ; (X1 >= 0) && (X1 < XRES)
316 ; (X2 >= 0) && (X2 < XRES)
317 ; (Y1 >= 0) && (Y1 < YRES)
318 ; (Y2 >= 0) && (Y2 < YRES)
319 ; Must set an error code: NO
321 bit $C082 ; Switch in ROM
328 jsr HLINE ; Preserves X
332 bit $C080 ; Switch in LC bank 2 for R/O
335 ; ------------------------------------------------------------------------
337 .include "../tgi/tgidrv_line.inc"