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>
6 ; Based on Maciej Witkowiak's line and circle routine
9 .include "zeropage.inc"
11 .include "tgi-kernel.inc"
12 .include "tgi-mode.inc"
13 .include "tgi-error.inc"
18 ; ------------------------------------------------------------------------
35 ; ------------------------------------------------------------------------
37 ; Variables mapped to the zero page segment variables. Some of these are
38 ; used for passing parameters to the driver.
52 ; Line routine stuff (must be on zpage)
56 ERR := regsave ; (2) LINE
57 NX := regsave+2 ; (2) LINE
59 ; Circle routine stuff (must be on zpage)
61 XX := ptr3 ; (2) CIRCLE
62 YY := ptr4 ; (2) CIRCLE
63 MaxO := sreg ; (overwritten by TEMP3+TEMP4, but restored from OG/OU anyway)
64 XS := regsave ; (2) CIRCLE
65 YS := regsave+2 ; (2) CIRCLE
67 ; ------------------------------------------------------------------------
71 ; Header. Includes jump table and constants.
73 ; First part of the header is a structure that has a magic and defines the
74 ; capabilities of the driver
76 .byte $74, $67, $69 ; "tgi"
77 .byte TGI_API_VERSION ; TGI API version number
78 xres: .word 40 ; X resolution
79 yres: .word 48 ; Y resolution
80 .byte 16 ; Number of drawing colors
81 .byte 1 ; Number of screens available
82 .byte 8 ; System font X size
83 .byte 8 ; System font Y size
84 .res 4, $00 ; Reserved for future extensions
86 ; Next comes the jump table. Currently all entries must be valid and may point
87 ; to an RTS for test versions (function not implemented).
109 .addr 0 ; IRQ entry is unused
111 ; ------------------------------------------------------------------------
115 ; Absolute variables used in the code
117 ERROR: .res 1 ; Error code
119 ; Line routine stuff (combined with circle routine stuff to save space)
131 ; ------------------------------------------------------------------------
135 ; Constants and tables
137 DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
138 .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
140 ; ------------------------------------------------------------------------
144 ; INIT: Changes an already installed device from text mode to graphics mode.
145 ; Note that INIT/DONE may be called multiple times while the driver
146 ; is loaded, while INSTALL is only called once, so any code that is needed
147 ; to initializes variables and so on must go here. Setting palette and
148 ; clearing the screen is not needed because this is called by the graphics
150 ; The graphics kernel will never call INIT when a graphics mode is already
151 ; active, so there is no need to protect against that.
152 ; Must set an error code: YES
154 ; Switch into graphics mode
155 bit $C082 ; Switch in ROM
158 bit $C080 ; Switch in LC bank 2 for R/O
160 ; Done, reset the error code
166 ; INSTALL routine. Is called after the driver is loaded into memory. May
167 ; initialize anything that has to be done just once. Is probably empty
169 ; Must set an error code: NO
173 ; UNINSTALL routine. Is called before the driver is removed from memory. May
174 ; clean up anything done by INSTALL but is probably empty most of the time.
175 ; Must set an error code: NO
179 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
180 ; The page number is already checked to be valid by the graphics kernel.
181 ; Must set an error code: NO (will only be called if page ok)
185 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
186 ; The page number is already checked to be valid by the graphics kernel.
187 ; Must set an error code: NO (will only be called if page ok)
191 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
192 ; direction is passend in X/Y, the text direction is passed in A.
193 ; Must set an error code: NO
197 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
198 ; current text style. The text to output is given as a zero terminated
199 ; string with address in ptr3.
200 ; Must set an error code: NO
204 ; DONE: Will be called to switch the graphics device back into text mode.
205 ; The graphics kernel will never call DONE when no graphics mode is active,
206 ; so there is no need to protect against that.
207 ; Must set an error code: NO
209 bit $C082 ; Switch in ROM
212 bit $C080 ; Switch in LC bank 2 for R/O
215 ; GETERROR: Return the error code in A and clear it.
222 ; CLEAR: Clears the screen.
223 ; Must set an error code: NO
225 bit $C082 ; Switch in ROM
227 bit $C080 ; Switch in LC bank 2 for R/O
230 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
231 ; to be in a valid range (0..maxcolor-1).
232 ; Must set an error code: NO (will only be called if color ok)
234 bit $C082 ; Switch in ROM
236 bit $C080 ; Switch in LC bank 2 for R/O
239 ; CONTROL: Platform/driver specific entry point.
240 ; Must set an error code: YES
244 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
245 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
247 ; Must set an error code: YES
249 lda #TGI_ERR_INV_FUNC
253 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
254 ; set the palette should return the default palette here, so there's no
255 ; way for this function to fail.
256 ; Must set an error code: NO
260 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
261 ; drivers should return something reasonable here, even drivers that don't
262 ; support palettes, otherwise the caller has no way to determine the colors
263 ; of the (not changeable) palette.
264 ; Must set an error code: NO (all drivers must have a default palette)
270 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
271 ; color. The coordinates passed to this function are never outside the
272 ; visible screen area, so there is no need for clipping inside this function.
273 ; Must set an error code: NO
275 bit $C082 ; Switch in ROM
279 bit $C080 ; Switch in LC bank 2 for R/O
294 jsr icmp ; ( x < xres ) ...
303 jsr icmp ; ... && ( y < yres )
307 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
308 ; coordinates passed to this function are never outside the visible screen
309 ; area, so there is no need for clipping inside this function.
311 bit $C082 ; Switch in ROM
316 bit $C080 ; Switch in LC bank 2 for R/O
319 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
320 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
321 ; Must set an error code: NO
423 ; for (count = nx; count > 0; --count) {
428 for: lda COUNT ; count > 0
475 ; if (abs (pb) < abs (ub)) {
493 ; else { x1 = x1 + ax
530 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
531 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
532 ; Contrary to most other functions, the graphics kernel will sort and clip
533 ; the coordinates before calling the driver, so on entry the following
534 ; conditions are valid:
537 ; (X1 >= 0) && (X1 < XRES)
538 ; (X2 >= 0) && (X2 < XRES)
539 ; (Y1 >= 0) && (Y1 < YRES)
540 ; (Y2 >= 0) && (Y2 < YRES)
541 ; Must set an error code: NO
543 bit $C082 ; Switch in ROM
554 bit $C080 ; Switch in LC bank 2 for R/O
557 ; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the
558 ; radius in tmp1 and the current drawing color.
559 ; Must set an error code: NO
563 jmp SETPIXELCLIP ; Plot as a point
582 stx YS+1 ; XS/YS to remember the center
592 ; Plot points in 8 slices...
598 sta X1+1 ; x1 = xs + x
605 sta Y1+1 ; (stack) = ys + y, y1 = (stack)
607 jsr SETPIXELCLIP ; plot (xs + x, ys + y)
614 sta Y1+1 ; y3 = y1 = ys - y
616 jsr SETPIXELCLIP ; plot (xs + x, ys - y)
627 jsr SETPIXELCLIP ; plot (xs - x, ys + y)
632 jsr SETPIXELCLIP ; plot (xs - x, ys - y)
639 sta X1+1 ; x1 = xs + y
646 sta Y1+1 ; (stack) = ys + x, y1 = (stack)
648 jsr SETPIXELCLIP ; plot (xs + y, ys + x)
655 sta Y1+1 ; y3 = y1 = ys - x
657 jsr SETPIXELCLIP ; plot (xs + y, ys - x)
661 sta Y1 ; y1 = ys + x(stack)
668 jsr SETPIXELCLIP ; plot (xs - y, ys + x)
673 jsr SETPIXELCLIP ; plot (xs - y, ys - x)
675 ; og = mo + y + y + 1
696 ; ou = og - x - x + 1
720 ; if (abs (ou) < abs (og)) {
754 ; Copies of some runtime routines
774 ; Compare A/Y to zp,X
775 sta TEMP ; TEMP/TEMP2 - arg2
783 tya ; X/A - arg1 (a = high)