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 ; ------------------------------------------------------------------------
35 ; Variables mapped to the zero page segment variables. Some of these are
36 ; used for passing parameters to the driver.
48 ; Line routine stuff (must be on zpage)
52 ERR := regsave ; (2) LINE
53 NX := regsave+2 ; (2) LINE
55 ; ------------------------------------------------------------------------
59 ; Header. Includes jump table and constants.
61 ; First part of the header is a structure that has a magic and defines the
62 ; capabilities of the driver
64 .byte $74, $67, $69 ; "tgi"
65 .byte TGI_API_VERSION ; TGI API version number
66 .word 40 ; X resolution
67 .word 48 ; Y resolution
68 .byte 16 ; Number of drawing colors
69 .byte 1 ; Number of screens available
70 .byte 8 ; System font X size
71 .byte 8 ; System font Y size
72 .word $100 ; Aspect ratio
74 ; Next comes the jump table. With the exception of IRQ, all entries must be
75 ; valid and may point to an RTS for test versions (function not implemented).
96 .addr 0 ; IRQ entry is unused
98 ; ------------------------------------------------------------------------
102 ; Absolute variables used in the code
104 ERROR: .res 1 ; Error code
105 MIX: .res 1 ; 4 lines of text
116 ; ------------------------------------------------------------------------
120 ; Constants and tables
122 DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
123 .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
127 ; ------------------------------------------------------------------------
131 ; INIT: Changes an already installed device from text mode to graphics mode.
132 ; Note that INIT/DONE may be called multiple times while the driver
133 ; is loaded, while INSTALL is only called once, so any code that is needed
134 ; to initializes variables and so on must go here. Setting palette and
135 ; clearing the screen is not needed because this is called by the graphics
137 ; The graphics kernel will never call INIT when a graphics mode is already
138 ; active, so there is no need to protect against that.
139 ; Must set an error code: YES
141 ; Switch into graphics mode
142 bit $C082 ; Switch in ROM
145 bit $C080 ; Switch in LC bank 2 for R/O
147 ; Done, reset the error code
154 ; INSTALL routine. Is called after the driver is loaded into memory. May
155 ; initialize anything that has to be done just once. Is probably empty
157 ; Must set an error code: NO
161 ; UNINSTALL routine. Is called before the driver is removed from memory. May
162 ; clean up anything done by INSTALL but is probably empty most of the time.
163 ; Must set an error code: NO
167 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
168 ; The page number is already checked to be valid by the graphics kernel.
169 ; Must set an error code: NO (will only be called if page ok)
173 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
174 ; The page number is already checked to be valid by the graphics kernel.
175 ; Must set an error code: NO (will only be called if page ok)
179 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
180 ; direction is passend in X/Y, the text direction is passed in A.
181 ; Must set an error code: NO
185 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
186 ; current text style. The text to output is given as a zero terminated
187 ; string with address in ptr3.
188 ; Must set an error code: NO
192 ; DONE: Will be called to switch the graphics device back into text mode.
193 ; The graphics kernel will never call DONE when no graphics mode is active,
194 ; so there is no need to protect against that.
195 ; Must set an error code: NO
197 bit $C082 ; Switch in ROM
200 bit $C080 ; Switch in LC bank 2 for R/O
203 ; GETERROR: Return the error code in A and clear it.
210 ; CLEAR: Clears the screen.
211 ; Must set an error code: NO
213 bit $C082 ; Switch in ROM
214 lda COLOR ; Save current drawing color
217 ldy MAXY,x ; Max Y depends on 4 lines of text
220 sta COLOR ; Save current drawing color
221 bit $C080 ; Switch in LC bank 2 for R/O
224 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
225 ; to be in a valid range (0..maxcolor-1).
226 ; Must set an error code: NO (will only be called if color ok)
228 bit $C082 ; Switch in ROM
230 bit $C080 ; Switch in LC bank 2 for R/O
233 ; CONTROL: Platform/driver specific entry point.
234 ; Must set an error code: YES
236 ; Check data msb and code to be 0
240 ; Check data lsb to be [0..1]
244 bit $C082 ; Switch in ROM
246 ; Switch 4 lines of text
248 .assert MIXCLR + 1 = MIXSET, error
249 lda MIXCLR,x ; No BIT absolute,X available
251 ; Save current switch setting
256 ; Clear 8 lines of graphics
257 lda COLOR ; Save current drawing color
259 lda #39 ; Rightmost column
263 ldy #$00 ; Leftmost column
265 jsr HLINE ; Preserves X
267 cpx #47+1 ; Last line
270 sta COLOR ; Save current drawing color
271 bcs :+ ; Branch always
273 ; Clear 4 lines of text
275 : bit $C080 ; Switch in LC bank 2 for R/O
277 ; Done, reset the error code
279 beq :+ ; Branch always
281 ; Done, set the error code
282 err: lda #TGI_ERR_INV_ARG
286 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
287 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
289 ; Must set an error code: YES
291 lda #TGI_ERR_INV_FUNC
295 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
296 ; set the palette should return the default palette here, so there's no
297 ; way for this function to fail.
298 ; Must set an error code: NO
302 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
303 ; drivers should return something reasonable here, even drivers that don't
304 ; support palettes, otherwise the caller has no way to determine the colors
305 ; of the (not changeable) palette.
306 ; Must set an error code: NO (all drivers must have a default palette)
312 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
313 ; color. The coordinates passed to this function are never outside the
314 ; visible screen area, so there is no need for clipping inside this function.
315 ; Must set an error code: NO
317 bit $C082 ; Switch in ROM
321 bit $C080 ; Switch in LC bank 2 for R/O
324 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
325 ; coordinates passed to this function are never outside the visible screen
326 ; area, so there is no need for clipping inside this function.
328 bit $C082 ; Switch in ROM
333 bit $C080 ; Switch in LC bank 2 for R/O
336 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
337 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
338 ; Must set an error code: NO
442 ; for (count = nx; count > 0; --count) {
447 for: lda COUNT ; count > 0
498 ; if (abs (pb) < abs (ub)) {
516 ; else { x1 = x1 + ax
556 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
557 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
558 ; Contrary to most other functions, the graphics kernel will sort and clip
559 ; the coordinates before calling the driver, so on entry the following
560 ; conditions are valid:
563 ; (X1 >= 0) && (X1 < XRES)
564 ; (X2 >= 0) && (X2 < XRES)
565 ; (Y1 >= 0) && (Y1 < YRES)
566 ; (Y2 >= 0) && (Y2 < YRES)
567 ; Must set an error code: NO
569 bit $C082 ; Switch in ROM
580 bit $C080 ; Switch in LC bank 2 for R/O
583 ; Copies of some runtime routines
603 ; Compare A/Y to zp,X
604 sta TEMP ; TEMP/TEMP2 - arg2
612 tya ; X/A - arg1 (a = high)