2 ; Graphics driver for the 40x40x16 mode on the Apple II
4 ; Stefan Haubenthal <polluks@sdf.lonestar.org>
5 ; Based on Maciej Witkowiak's line and circle routine
8 .include "zeropage.inc"
10 .include "tgi-kernel.inc"
11 .include "tgi-mode.inc"
12 .include "tgi-error.inc"
17 ; ------------------------------------------------------------------------
28 ; ------------------------------------------------------------------------
29 ; Header. Includes jump table and constants.
33 ; First part of the header is a structure that has a magic and defines the
34 ; capabilities of the driver
36 .byte $74, $67, $69 ; "tgi"
37 .byte TGI_API_VERSION ; TGI API version number
38 xres: .word 40 ; X resolution
39 yres: .word 40 ; Y resolution
40 .byte 16 ; Number of drawing colors
41 .byte 1 ; Number of screens available
42 .byte 8 ; System font X size
43 .byte 8 ; System font Y size
44 .res 4, $00 ; Reserved for future extensions
46 ; Next comes the jump table. Currently all entries must be valid and may point
47 ; to an RTS for test versions (function not implemented).
70 ; ------------------------------------------------------------------------
73 ; Variables mapped to the zero page segment variables. Some of these are
74 ; used for passing parameters to the driver.
88 ; Line routine stuff (must be on zpage)
91 ERR = regsave ; (2) LINE
92 NX = regsave+2 ; (2) LINE
94 XX = ptr3 ; (2) CIRCLE
95 YY = ptr4 ; (2) CIRCLE
96 MaxO = sreg ; (overwritten by TEMP3+TEMP4, but restored from OG/OU anyway)
97 XS = regsave ; (2) CIRCLE
98 YS = regsave+2 ; (2) CIRCLE
100 ; Absolute variables used in the code
104 ERROR: .res 1 ; Error code
106 ; Line routine stuff (combined with CIRCLE to save space)
117 ; Constants and tables
121 DEFPALETTE: .byte $00, $0F, $01, $0E, $03, $04, $02, $0D
122 .byte $09, $08, $0B, $05, $0A, $0C, $06, $07
126 ; ------------------------------------------------------------------------
127 ; INSTALL routine. Is called after the driver is loaded into memory. May
128 ; initialize anything that has to be done just once. Is probably empty
131 ; Must set an error code: NO
137 ; ------------------------------------------------------------------------
138 ; UNINSTALL routine. Is called before the driver is removed from memory. May
139 ; clean up anything done by INSTALL but is probably empty most of the time.
141 ; Must set an error code: NO
148 ; ------------------------------------------------------------------------
149 ; INIT: Changes an already installed device from text mode to graphics
151 ; Note that INIT/DONE may be called multiple times while the driver
152 ; is loaded, while INSTALL is only called once, so any code that is needed
153 ; to initializes variables and so on must go here. Setting palette and
154 ; clearing the screen is not needed because this is called by the graphics
156 ; The graphics kernel will never call INIT when a graphics mode is already
157 ; active, so there is no need to protect against that.
159 ; Must set an error code: YES
164 ; Switch into graphics mode
168 ; Done, reset the error code
174 ; ------------------------------------------------------------------------
175 ; DONE: Will be called to switch the graphics device back into text mode.
176 ; The graphics kernel will never call DONE when no graphics mode is active,
177 ; so there is no need to protect against that.
179 ; Must set an error code: NO
184 ; ------------------------------------------------------------------------
185 ; GETERROR: Return the error code in A and clear it.
193 ; ------------------------------------------------------------------------
194 ; CONTROL: Platform/driver specific entry point.
196 ; Must set an error code: YES
200 lda #TGI_ERR_INV_FUNC
204 ; ------------------------------------------------------------------------
205 ; CLEAR: Clears the screen.
207 ; Must set an error code: NO
212 ; ------------------------------------------------------------------------
213 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
214 ; The page number is already checked to be valid by the graphics kernel.
216 ; Must set an error code: NO (will only be called if page ok)
221 ; ------------------------------------------------------------------------
222 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
223 ; The page number is already checked to be valid by the graphics kernel.
225 ; Must set an error code: NO (will only be called if page ok)
231 ; ------------------------------------------------------------------------
232 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
233 ; to be in a valid range (0..maxcolor-1).
235 ; Must set an error code: NO (will only be called if color ok)
240 ; ------------------------------------------------------------------------
241 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
242 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
245 ; Must set an error code: YES
249 lda #TGI_ERR_INV_FUNC
253 ; ------------------------------------------------------------------------
254 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
255 ; set the palette should return the default palette here, so there's no
256 ; way for this function to fail.
258 ; Must set an error code: NO
263 ; ------------------------------------------------------------------------
264 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
265 ; drivers should return something reasonable here, even drivers that don't
266 ; support palettes, otherwise the caller has no way to determine the colors
267 ; of the (not changeable) palette.
269 ; Must set an error code: NO (all drivers must have a default palette)
277 ; ------------------------------------------------------------------------
278 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
279 ; color. The coordinates passed to this function are never outside the
280 ; visible screen area, so there is no need for clipping inside this function.
282 ; Must set an error code: NO
297 jsr icmp ; ( x < xres ) ...
306 jsr icmp ; ... && ( y < yres )
315 ; ------------------------------------------------------------------------
316 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
317 ; coordinates passed to this function are never outside the visible screen
318 ; area, so there is no need for clipping inside this function.
328 ; ------------------------------------------------------------------------
329 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
330 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
332 ; Must set an error code: NO
420 ; for (count=nx;count>0;--count) {
425 @L0166: lda COUNT ; count>0
430 @L0167: jsr SETPIXELCLIP
466 ; if (abs(pb)<abs(ub)) {
482 ; } else { x1 = x1 + ay
519 ; ------------------------------------------------------------------------
520 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
521 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
522 ; Contrary to most other functions, the graphics kernel will sort and clip
523 ; the coordinates before calling the driver, so on entry the following
524 ; conditions are valid:
527 ; (X1 >= 0) && (X1 < XRES)
528 ; (X2 >= 0) && (X2 < XRES)
529 ; (Y1 >= 0) && (Y1 < YRES)
530 ; (Y2 >= 0) && (Y2 < YRES)
532 ; Must set an error code: NO
548 ; ------------------------------------------------------------------------
549 ; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the
550 ; radius in tmp1 and the current drawing color.
552 ; Must set an error code: NO
558 jmp SETPIXELCLIP ; Plot as a point
576 stx YS+1 ; XS/YS to remember the center
585 @L12: ; plot points in 8 slices...
598 sta Y1+1 ; (stack)=ys+y, y1=(stack)
600 jsr SETPIXELCLIP ; plot(xs+x,ys+y)
607 sta Y1+1 ; y3 = y1 = ys-y
609 jsr SETPIXELCLIP ; plot(xs+x,ys-y)
620 jsr SETPIXELCLIP ; plot (xs-x,ys+y)
625 jsr SETPIXELCLIP ; plot (xs-x,ys-y)
639 sta Y1+1 ; (stack)=ys+x, y1=(stack)
641 jsr SETPIXELCLIP ; plot(xs+y,ys+x)
648 sta Y1+1 ; y3 = y1 = ys-x
650 jsr SETPIXELCLIP ; plot(xs+y,ys-x)
654 sta Y1 ; y1 = ys+x(stack)
661 jsr SETPIXELCLIP ; plot (xs-y,ys+x)
666 jsr SETPIXELCLIP ; plot (xs-y,ys-x)
710 @L0148: ; if (abs(ou)<abs(og))
740 ; ------------------------------------------------------------------------
741 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
742 ; direction is passend in X/Y, the text direction is passed in A.
744 ; Must set an error code: NO
751 ; ------------------------------------------------------------------------
752 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
753 ; current text style. The text to output is given as a zero terminated
754 ; string with address in ptr3.
756 ; Must set an error code: NO
774 ; copies of some runtime routines
793 ; compare a/y to zp,x
794 sta TEMP ; TEMP/TEMP2 - arg2
802 tya ; x/a - arg1 (a=high)