2 ; Graphics driver for the 280x192x6 mode on the Apple II
4 ; Stefan Haubenthal <polluks@sdf.lonestar.org>
5 ; Based on Maciej Witkowiak's circle routine
8 .include "zeropage.inc"
10 .include "tgi-kernel.inc"
11 .include "tgi-mode.inc"
12 .include "tgi-error.inc"
17 ; ------------------------------------------------------------------------
20 TEXT := $F399 ; Return to text screen
21 HGR := $F3E2 ; Initialize and clear hi-res page 1.
22 HCLR := $F3F2 ; Clear the current hi-res screen to black.
23 HPOSN := $F411 ; Positions the hi-res cursor without
25 ; Enter with (A) = Y-coordinate, and
26 ; (Y,X) = X-coordinate.
27 HPLOT := $F457 ; Calls HPOSN and tries to plot a dot at
28 ; the cursor's position. If you are
29 ; trying to plot a non-white color at
30 ; a complementary color position, no
31 ; dot will be plotted.
32 HLIN := $F53A ; Draws a line from the last plotted
33 ; point or line destination to:
34 ; (X,A) = X-coordinate, and
36 DRAW := $F601 ; Draws a shape. Enter with (Y,X) = the
37 ; address of the shape table, and (A) =
38 ; the rotation factor. Uses the current
40 SETHCOL := $F6EC ; Set the hi-res color to (X), where (X)
41 ; must be between 0 and 7.
43 ; ------------------------------------------------------------------------
44 ; Header. Includes jump table and constants.
48 ; First part of the header is a structure that has a magic and defines the
49 ; capabilities of the driver
51 .byte $74, $67, $69 ; "tgi"
52 .byte TGI_API_VERSION ; TGI API version number
53 xres: .word 280 ; X resolution
54 yres: .word 192 ; Y resolution
55 .byte 8 ; Number of drawing colors
56 .byte 2 ; Number of screens available
57 .byte 8 ; System font X size
58 .byte 8 ; System font Y size
59 .res 4, $00 ; Reserved for future extensions
61 ; Next comes the jump table. Currently all entries must be valid and may point
62 ; to an RTS for test versions (function not implemented).
84 .addr 0 ; IRQ entry is unused
86 ; ------------------------------------------------------------------------
89 ; Variables mapped to the zero page segment variables. Some of these are
90 ; used for passing parameters to the driver.
105 XX = ptr3 ; (2) CIRCLE
106 YY = ptr4 ; (2) CIRCLE
107 MaxO = sreg ; (overwritten by TEMP3+TEMP4, but restored from OG/OU anyway)
108 XS = regsave ; (2) CIRCLE
109 YS = regsave+2 ; (2) CIRCLE
111 ; Absolute variables used in the code
115 ERROR: .res 1 ; Error code
117 ; Line routine stuff (combined with CIRCLE to save space)
128 ; Constants and tables
132 DEFPALETTE: .byte $00, $05, $04, $01, $00, $08, $06, $01; 6 unique colors
134 SHAPE: .byte $64,$01,$D0,$00,$D5,$00,$DA,$00,$E0,$00,$EF,$00,$FE,$00,$0C,$01
135 .byte $19,$01,$1D,$01,$25,$01,$2D,$01,$3D,$01,$46,$01,$4B,$01,$52,$01
136 .byte $56,$01,$60,$01,$70,$01,$77,$01,$83,$01,$8E,$01,$9A,$01,$A7,$01
137 .byte $B6,$01,$BF,$01,$CE,$01,$DD,$01,$E2,$01,$E7,$01,$F9,$01,$03,$02
138 .byte $15,$02,$1F,$02,$32,$02,$42,$02,$52,$02,$5E,$02,$6C,$02,$79,$02
139 .byte $85,$02,$91,$02,$A1,$02,$A9,$02,$B2,$02,$BF,$02,$C5,$02,$D5,$02
140 .byte $E5,$02,$F4,$02,$00,$03,$10,$03,$1F,$03,$2D,$03,$35,$03,$44,$03
141 .byte $53,$03,$63,$03,$71,$03,$7B,$03,$85,$03,$91,$03,$97,$03,$A3,$03
142 .byte $B6,$03,$BF,$03,$C3,$03,$CF,$03,$DC,$03,$E4,$03,$F3,$03,$00,$04
143 .byte $0A,$04,$19,$04,$25,$04,$2A,$04,$32,$04,$3C,$04,$43,$04,$50,$04
144 .byte $5A,$04,$66,$04,$72,$04,$7E,$04,$87,$04,$94,$04,$9C,$04,$A8,$04
145 .byte $B4,$04,$C1,$04,$CC,$04,$DB,$04,$E6,$04,$EE,$04,$F3,$04,$FB,$04
146 .byte $04,$05,$1A,$05,$1F,$05,$24,$05,$29,$05,$22,$01,$00,$00,$00,$00
147 .byte $09,$89,$92,$92,$00,$36,$36,$16,$0E,$00,$0D,$FE,$6E,$96,$52,$00
148 .byte $69,$FE,$17,$2D,$2D,$1E,$1F,$17,$2D,$2D,$1E,$1F,$6E,$4E,$00,$09
149 .byte $8D,$3F,$BF,$0D,$15,$3F,$0E,$0D,$1E,$3F,$77,$71,$09,$00,$6D,$11
150 .byte $DF,$77,$09,$1E,$17,$4D,$3A,$DF,$4E,$29,$0E,$00,$A9,$1F,$6E,$1E
151 .byte $17,$0D,$0D,$1E,$DF,$0E,$6D,$0E,$00,$36,$96,$52,$00,$09,$1E,$17
152 .byte $36,$15,$0E,$0E,$00,$15,$0E,$36,$1E,$17,$4E,$01,$00,$09,$8D,$1F
153 .byte $1F,$0E,$2D,$1E,$17,$2D,$15,$1F,$1F,$4E,$4E,$01,$00,$89,$6E,$3A
154 .byte $3F,$77,$31,$56,$09,$00,$92,$8A,$F6,$0D,$00,$52,$89,$3F,$B7,$52
155 .byte $49,$00,$92,$92,$0E,$00,$49,$11,$17,$1E,$17,$1E,$56,$49,$01,$00
156 .byte $29,$AD,$DF,$33,$4D,$35,$1F,$1F,$2E,$4D,$FE,$1B,$0E,$2D,$4E,$00
157 .byte $31,$77,$36,$BE,$2D,$0E,$00,$29,$AD,$DF,$73,$49,$1E,$BF,$1E,$2E
158 .byte $2D,$75,$00,$2D,$2D,$BE,$3E,$4E,$FE,$1B,$0E,$2D,$4E,$00,$49,$3E
159 .byte $17,$0D,$FE,$33,$2D,$2D,$1E,$76,$01,$00,$2D,$2D,$DE,$1B,$2E,$2D
160 .byte $15,$36,$DF,$73,$2D,$4E,$00,$09,$2D,$DE,$BB,$4D,$3A,$3F,$6E,$09
161 .byte $FE,$1B,$0E,$2D,$4E,$00,$2D,$2D,$BE,$1E,$17,$36,$4E,$09,$00,$29
162 .byte $AD,$DF,$33,$4D,$F1,$3F,$17,$4D,$31,$DF,$73,$2D,$4E,$00,$29,$AD
163 .byte $DF,$33,$4D,$31,$3F,$77,$09,$1E,$DF,$2A,$75,$09,$00,$12,$16,$96
164 .byte $01,$00,$52,$B2,$F6,$0D,$00,$49,$3E,$17,$2D,$2D,$35,$3F,$3F,$3F
165 .byte $0E,$2D,$2D,$F5,$1B,$77,$4E,$09,$00,$12,$2D,$2D,$DE,$9B,$2D,$2D
166 .byte $96,$01,$00,$49,$15,$FF,$13,$2D,$2D,$AD,$3F,$3F,$3F,$2E,$2D,$2D
167 .byte $1E,$37,$4E,$09,$00,$29,$AD,$DF,$73,$09,$1E,$B6,$4E,$01,$00,$09
168 .byte $2D,$3E,$37,$2D,$3E,$FF,$2A,$2D,$2D,$F5,$3F,$3F,$0E,$2D,$1E,$4D
169 .byte $01,$00,$09,$15,$1F,$17,$4D,$31,$DF,$33,$2D,$2D,$FE,$1B,$6E,$09
170 .byte $0E,$00,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$4D,$31,$DF,$33,$2D,$75
171 .byte $01,$00,$29,$AD,$DF,$33,$36,$4D,$11,$DF,$73,$2D,$4E,$00,$2D,$AD
172 .byte $DF,$6E,$31,$DF,$6E,$31,$DF,$17,$2D,$75,$01,$00,$2D,$2D,$DE,$1B
173 .byte $6E,$11,$3F,$37,$36,$2D,$2D,$0E,$00,$2D,$2D,$DE,$1B,$6E,$11,$3F
174 .byte $37,$36,$4E,$49,$00,$29,$AD,$DF,$33,$36,$4D,$35,$DF,$73,$2D,$75
175 .byte $00,$4D,$31,$DF,$33,$4D,$31,$3F,$3F,$6E,$09,$FE,$1B,$6E,$09,$0E
176 .byte $00,$2D,$1E,$36,$36,$17,$2D,$0E,$00,$49,$31,$36,$36,$DF,$73,$2D
177 .byte $4E,$00,$4D,$F1,$DF,$6E,$1E,$37,$0D,$15,$DF,$6E,$09,$0E,$00,$36
178 .byte $36,$36,$2D,$75,$00,$4D,$31,$FF,$37,$0D,$0D,$FE,$1F,$6E,$09,$FE
179 .byte $1B,$6E,$09,$0E,$00,$4D,$31,$DF,$33,$6D,$31,$1F,$1F,$6E,$29,$FE
180 .byte $1B,$6E,$09,$0E,$00,$29,$AD,$DF,$33,$4D,$31,$DF,$33,$4D,$31,$DF
181 .byte $73,$2D,$4E,$00,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$36,$4E,$49,$00
182 .byte $29,$AD,$DF,$33,$4D,$31,$DF,$33,$0D,$0D,$1E,$DF,$0E,$6D,$0E,$00
183 .byte $2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$0D,$15,$DF,$6E,$09,$0E,$00,$29
184 .byte $AD,$DF,$33,$4D,$3A,$77,$09,$FE,$1B,$0E,$2D,$4E,$00,$2D,$2D,$DE
185 .byte $36,$36,$76,$09,$00,$4D,$31,$DF,$33,$4D,$31,$DF,$33,$4D,$31,$DF
186 .byte $73,$2D,$4E,$00,$4D,$31,$DF,$33,$4D,$31,$DF,$33,$4D,$F1,$1F,$0E
187 .byte $4E,$01,$00,$4D,$31,$DF,$33,$4D,$31,$1F,$1F,$6E,$0D,$3E,$1F,$37
188 .byte $4D,$71,$00,$4D,$31,$DF,$73,$0D,$1E,$17,$0D,$15,$DF,$33,$4D,$71
189 .byte $00,$4D,$31,$DF,$73,$0D,$1E,$36,$76,$09,$00,$2D,$2D,$BE,$1E,$17
190 .byte $1E,$2E,$2D,$75,$00,$2D,$2D,$DE,$3B,$2E,$3E,$2E,$3E,$2E,$2D,$75
191 .byte $00,$72,$15,$0E,$15,$56,$00,$2D,$2D,$3E,$2E,$3E,$2E,$3E,$DF,$2A
192 .byte $2D,$75,$00,$49,$15,$3F,$17,$2D,$2D,$15,$3F,$3F,$3F,$4E,$2D,$3E
193 .byte $37,$2D,$3E,$6F,$49,$00,$92,$92,$49,$11,$3F,$3F,$4D,$09,$00,$76
194 .byte $96,$52,$00,$52,$2D,$35,$DF,$33,$4D,$31,$FF,$73,$6D,$0E,$00,$36
195 .byte $2D,$AD,$DF,$33,$4D,$31,$DF,$33,$2D,$75,$01,$00,$52,$2D,$DE,$33
196 .byte $76,$2D,$0E,$00,$49,$31,$DF,$2A,$2D,$FE,$1B,$6E,$09,$FE,$1B,$0E
197 .byte $2D,$75,$00,$52,$2D,$15,$DF,$33,$2D,$2D,$DE,$1B,$0E,$2D,$75,$00
198 .byte $09,$F5,$33,$8D,$3F,$77,$36,$4E,$01,$00,$52,$2D,$35,$DF,$33,$4D
199 .byte $31,$3F,$77,$09,$1E,$3F,$4D,$01,$00,$36,$2D,$AD,$DF,$33,$4D,$31
200 .byte $DF,$33,$4D,$71,$00,$16,$36,$36,$0E,$00,$09,$9E,$35,$36,$F6,$6F
201 .byte $01,$00,$36,$4D,$1E,$1F,$2E,$15,$1F,$6E,$71,$00,$35,$36,$36,$17
202 .byte $2D,$0E,$00,$12,$2D,$AD,$1F,$1F,$6E,$0D,$FE,$1F,$6E,$0D,$0E,$00
203 .byte $12,$2D,$15,$DF,$6E,$31,$DF,$6E,$71,$00,$52,$2D,$15,$DF,$33,$4D
204 .byte $31,$DF,$73,$2D,$4E,$00,$12,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$6E
205 .byte $49,$00,$52,$2D,$35,$DF,$33,$4D,$31,$3F,$77,$09,$2E,$00,$12,$0D
206 .byte $AD,$DF,$37,$36,$4E,$49,$00,$52,$2D,$F5,$DB,$0E,$2D,$15,$DF,$13
207 .byte $2D,$75,$01,$00,$31,$17,$2D,$F5,$33,$76,$75,$00,$12,$4D,$31,$DF
208 .byte $33,$4D,$31,$FF,$73,$6D,$0E,$00,$12,$4D,$31,$DF,$33,$4D,$F1,$1F
209 .byte $0E,$4E,$01,$00,$12,$4D,$31,$DF,$33,$0D,$0D,$FE,$1F,$0E,$0D,$4E
210 .byte $00,$12,$4D,$F1,$1F,$0E,$15,$1F,$17,$4D,$71,$00,$12,$4D,$31,$DF
211 .byte $33,$4D,$31,$3F,$77,$09,$1E,$3F,$4D,$01,$00,$12,$2D,$2D,$1E,$17
212 .byte $1E,$17,$2D,$2D,$0E,$00,$09,$F5,$33,$1E,$0E,$76,$75,$00,$36,$36
213 .byte $36,$2E,$00,$AD,$AE,$17,$FE,$2A,$4E,$01,$00,$69,$11,$1F,$1F,$4E
214 .byte $B1,$92,$09,$00,$2D,$2D,$35,$3F,$3F,$37,$2D,$2D,$35,$3F,$3F,$37
215 .byte $2D,$2D,$35,$3F,$3F,$37,$2D,$2D,$75,$00,$40,$C0,$40,$18,$00,$40
216 .byte $C0,$40,$43,$00,$40,$C0,$40,$08,$00,$19,$00,$00
220 ; ------------------------------------------------------------------------
221 ; INSTALL routine. Is called after the driver is loaded into memory. May
222 ; initialize anything that has to be done just once. Is probably empty
225 ; Must set an error code: NO
231 ; ------------------------------------------------------------------------
232 ; UNINSTALL routine. Is called before the driver is removed from memory. May
233 ; clean up anything done by INSTALL but is probably empty most of the time.
235 ; Must set an error code: NO
242 ; ------------------------------------------------------------------------
243 ; INIT: Changes an already installed device from text mode to graphics
245 ; Note that INIT/DONE may be called multiple times while the driver
246 ; is loaded, while INSTALL is only called once, so any code that is needed
247 ; to initializes variables and so on must go here. Setting palette and
248 ; clearing the screen is not needed because this is called by the graphics
250 ; The graphics kernel will never call INIT when a graphics mode is already
251 ; active, so there is no need to protect against that.
253 ; Must set an error code: YES
258 ; Switch into graphics mode
263 ; Done, reset the error code
269 ; ------------------------------------------------------------------------
270 ; DONE: Will be called to switch the graphics device back into text mode.
271 ; The graphics kernel will never call DONE when no graphics mode is active,
272 ; so there is no need to protect against that.
274 ; Must set an error code: NO
279 ; ------------------------------------------------------------------------
280 ; GETERROR: Return the error code in A and clear it.
288 ; ------------------------------------------------------------------------
289 ; CONTROL: Platform/driver specific entry point.
291 ; Must set an error code: YES
295 lda #TGI_ERR_INV_FUNC
299 ; ------------------------------------------------------------------------
300 ; CLEAR: Clears the screen.
302 ; Must set an error code: NO
307 ; ------------------------------------------------------------------------
308 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
309 ; The page number is already checked to be valid by the graphics kernel.
311 ; Must set an error code: NO (will only be called if page ok)
322 ; ------------------------------------------------------------------------
323 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
324 ; The page number is already checked to be valid by the graphics kernel.
326 ; Must set an error code: NO (will only be called if page ok)
334 @L1: lda #>$2000 ; Page 1
338 ; ------------------------------------------------------------------------
339 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
340 ; to be in a valid range (0..maxcolor-1).
342 ; Must set an error code: NO (will only be called if color ok)
349 ; ------------------------------------------------------------------------
350 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
351 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
354 ; Must set an error code: YES
358 lda #TGI_ERR_INV_FUNC
362 ; ------------------------------------------------------------------------
363 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
364 ; set the palette should return the default palette here, so there's no
365 ; way for this function to fail.
367 ; Must set an error code: NO
372 ; ------------------------------------------------------------------------
373 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
374 ; drivers should return something reasonable here, even drivers that don't
375 ; support palettes, otherwise the caller has no way to determine the colors
376 ; of the (not changeable) palette.
378 ; Must set an error code: NO (all drivers must have a default palette)
386 ; ------------------------------------------------------------------------
387 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
388 ; color. The coordinates passed to this function are never outside the
389 ; visible screen area, so there is no need for clipping inside this function.
391 ; Must set an error code: NO
406 jsr icmp ; ( x < xres ) ...
415 jsr icmp ; ... && ( y < yres )
425 ; ------------------------------------------------------------------------
426 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
427 ; coordinates passed to this function are never outside the visible screen
428 ; area, so there is no need for clipping inside this function.
435 jsr HPOSN ; 1st pixel
445 lda $E0 ; which neighbour
456 jsr HPOSN ; 2nd pixel
467 ; ------------------------------------------------------------------------
468 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
469 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
471 ; Must set an error code: NO
484 ; ------------------------------------------------------------------------
485 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
486 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
487 ; Contrary to most other functions, the graphics kernel will sort and clip
488 ; the coordinates before calling the driver, so on entry the following
489 ; conditions are valid:
492 ; (X1 >= 0) && (X1 < XRES)
493 ; (X2 >= 0) && (X2 < XRES)
494 ; (Y1 >= 0) && (Y1 < YRES)
495 ; (Y2 >= 0) && (Y2 < YRES)
497 ; Must set an error code: NO
514 ; ------------------------------------------------------------------------
515 ; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the
516 ; radius in tmp1 and the current drawing color.
518 ; Must set an error code: NO
524 jmp SETPIXELCLIP ; Plot as a point
542 stx YS+1 ; XS/YS to remember the center
551 @L12: ; plot points in 8 slices...
564 sta Y1+1 ; (stack)=ys+y, y1=(stack)
566 jsr SETPIXELCLIP ; plot(xs+x,ys+y)
573 sta Y1+1 ; y3 = y1 = ys-y
575 jsr SETPIXELCLIP ; plot(xs+x,ys-y)
586 jsr SETPIXELCLIP ; plot (xs-x,ys+y)
591 jsr SETPIXELCLIP ; plot (xs-x,ys-y)
605 sta Y1+1 ; (stack)=ys+x, y1=(stack)
607 jsr SETPIXELCLIP ; plot(xs+y,ys+x)
614 sta Y1+1 ; y3 = y1 = ys-x
616 jsr SETPIXELCLIP ; plot(xs+y,ys-x)
620 sta Y1 ; y1 = ys+x(stack)
627 jsr SETPIXELCLIP ; plot (xs-y,ys+x)
632 jsr SETPIXELCLIP ; plot (xs-y,ys-x)
676 @L0148: ; if (abs(ou)<abs(og))
706 ; ------------------------------------------------------------------------
707 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
708 ; direction is passend in X/Y, the text direction is passed in A.
710 ; Must set an error code: NO
724 ; ------------------------------------------------------------------------
725 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
726 ; current text style. The text to output is given as a zero terminated
727 ; string with address in ptr3.
729 ; Must set an error code: NO
747 sub #$1F ; no controls
773 ; copies of some runtime routines
792 ; compare a/y to zp,x
793 sta TEMP ; TEMP/TEMP2 - arg2
801 tya ; x/a - arg1 (a=high)