2 ; Graphics driver for the 280x192x8 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 ; ------------------------------------------------------------------------
25 ; Graphics entry points, by cbmnut (applenut??) cbmnut@hushmail.com
27 TEXT := $F399 ; Return to text screen
28 HGR2 := $F3D8 ; Initialize and clear hi-res page 2.
29 HGR := $F3E2 ; Initialize and clear hi-res page 1.
30 HCLR := $F3F2 ; Clear the current hi-res screen to black.
31 BKGND := $F3F6 ; Clear the current hi-res screen to the
32 ; last plotted color (from ($1C).
33 HPOSN := $F411 ; Positions the hi-res cursor without
35 ; Enter with (A) = Y-coordinate, and
36 ; (Y,X) = X-coordinate.
37 HPLOT := $F457 ; Calls HPOSN and tries to plot a dot at
38 ; the cursor's position. If you are
39 ; trying to plot a non-white color at
40 ; a complementary color position, no
41 ; dot will be plotted.
42 HLIN := $F53A ; Draws a line from the last plotted
43 ; point or line destination to:
44 ; (X,A) = X-coordinate, and
46 HFIND := $F5CB ; Converts the hi-res coursor's position
47 ; back to X- and Y-coordinates; stores
48 ; X-coordinate at $E0,E1 and Y-coordinate
50 DRAW := $F601 ; Draws a shape. Enter with (Y,X) = the
51 ; address of the shape table, and (A) =
52 ; the rotation factor. Uses the current
54 XDRAW := $F65D ; Draws a shape by inverting the existing
55 ; color of the dots the shape draws over.
56 ; Same entry parameters as DRAW.
57 SETHCOL := $F6EC ; Set the hi-res color to (X), where (X)
58 ; must be between 0 and 7.
60 ; ------------------------------------------------------------------------
62 ; Variables mapped to the zero page segment variables. Some of these are
63 ; used for passing parameters to the driver.
70 ; ------------------------------------------------------------------------
74 ; Header. Includes jump table and constants.
76 ; First part of the header is a structure that has a magic and defines the
77 ; capabilities of the driver
79 .byte $74, $67, $69 ; "tgi"
80 .byte TGI_API_VERSION ; TGI API version number
81 .word 280 ; X resolution
82 .word 192 ; Y resolution
83 .byte 8 ; Number of drawing colors
84 .byte 2 ; Number of screens available
85 .byte 7 ; System font X size
86 .byte 8 ; System font Y size
87 .word $100 ; Aspect ratio
89 ; Next comes the jump table. With the exception of IRQ, all entries must be
90 ; valid and may point to an RTS for test versions (function not implemented).
111 .addr 0 ; IRQ entry is unused
113 ; ------------------------------------------------------------------------
117 ; Absolute variables used in the code
119 ERROR: .res 1 ; Error code
122 Set80: .res 1 ; Set 80 column store
125 ; ------------------------------------------------------------------------
129 ; Constants and tables
131 DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
134 ; Beagle Bros Shape Mechanic font F.ASCII.SMALL
135 ; modified to exactly reproduce the text glyphs
136 .incbin "../apple2/apple2-280-192-8.fnt"
138 ; ------------------------------------------------------------------------
142 ; INIT: Changes an already installed device from text mode to graphics mode.
143 ; Note that INIT/DONE may be called multiple times while the driver
144 ; is loaded, while INSTALL is only called once, so any code that is needed
145 ; to initializes variables and so on must go here. Setting palette and
146 ; clearing the screen is not needed because this is called by the graphics
148 ; The graphics kernel will never call INIT when a graphics mode is already
149 ; active, so there is no need to protect against that.
150 ; Must set an error code: YES
153 ; Save and clear 80 column store
159 ; Switch into graphics mode
164 ; Beagle Bros Shape Mechanic fonts don't
165 ; scale well so use fixed scaling factor
169 ; Done, reset the error code
175 ; INSTALL routine. Is called after the driver is loaded into memory. May
176 ; initialize anything that has to be done just once. Is probably empty
178 ; Must set an error code: NO
182 ; UNINSTALL routine. Is called before the driver is removed from memory. May
183 ; clean up anything done by INSTALL but is probably empty most of the time.
184 ; Must set an error code: NO
188 ; DONE: Will be called to switch the graphics device back into text mode.
189 ; The graphics kernel will never call DONE when no graphics mode is active,
190 ; so there is no need to protect against that.
191 ; Must set an error code: NO
193 ; Switch into text mode
198 ; Restore 80 column store
202 : bit LORES ; Limit SET80COL-HISCR to text
206 ; GETERROR: Return the error code in A and clear it.
213 ; CLEAR: Clears the screen.
214 ; Must set an error code: NO
216 bit $C082 ; Switch in ROM
218 bit $C080 ; Switch in LC bank 2 for R/O
221 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
222 ; The page number is already checked to be valid by the graphics kernel.
223 ; Must set an error code: NO (will only be called if page ok)
226 .assert LOWSCR + 1 = HISCR, error
227 lda LOWSCR,x ; No BIT absolute,X available
230 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
231 ; The page number is already checked to be valid by the graphics kernel.
232 ; Must set an error code: NO (will only be called if page ok)
237 .byte $2C ; BIT absolute
238 : lda #>$2000 ; Page 1
242 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
243 ; to be in a valid range (0..maxcolor-1).
244 ; Must set an error code: NO (will only be called if color ok)
246 bit $C082 ; Switch in ROM
249 bit $C080 ; Switch in LC bank 2 for R/O
252 ; CONTROL: Platform/driver specific entry point.
253 ; Must set an error code: YES
257 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
258 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
260 ; Must set an error code: YES
262 lda #TGI_ERR_INV_FUNC
266 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
267 ; set the palette should return the default palette here, so there's no
268 ; way for this function to fail.
269 ; Must set an error code: NO
273 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
274 ; drivers should return something reasonable here, even drivers that don't
275 ; support palettes, otherwise the caller has no way to determine the colors
276 ; of the (not changeable) palette.
277 ; Must set an error code: NO (all drivers must have a default palette)
283 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
284 ; color. The coordinates passed to this function are never outside the
285 ; visible screen area, so there is no need for clipping inside this function.
286 ; Must set an error code: NO
288 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
311 adc #$03 ; += 4 (black -> black2, white -> white2)
313 bit $C080 ; Switch in LC bank 2 for R/O
316 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
317 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
318 ; Must set an error code: NO
320 bit $C082 ; Switch in ROM
329 bit $C080 ; Switch in LC bank 2 for R/O
332 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
333 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
334 ; Contrary to most other functions, the graphics kernel will sort and clip
335 ; the coordinates before calling the driver, so on entry the following
336 ; conditions are valid:
339 ; (X1 >= 0) && (X1 < XRES)
340 ; (X2 >= 0) && (X2 < XRES)
341 ; (Y1 >= 0) && (Y1 < YRES)
342 ; (Y2 >= 0) && (Y2 < YRES)
343 ; Must set an error code: NO
358 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
359 ; direction is passend in X/Y, the text direction is passed in A.
360 ; Must set an error code: NO
362 cmp #TGI_TEXT_VERTICAL
368 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
369 ; current text style. The text to output is given as a zero terminated
370 ; string with address in ptr3.
371 ; Must set an error code: NO
373 bit $C082 ; Switch in ROM
378 beq :+ ; Not horizontal
386 bne :+ ; Not vertical
391 lda FONT+2*99 ; "connection char"
394 lda FONT+2*99+1 ; "connection char"
400 sty tmp1 ; Save string index
402 sbc #$1F ; No control chars
413 jsr DRAW ; Draw char from string
417 jsr DRAW ; Draw "connection char"
418 ldy tmp1 ; Restore string index
420 bne :- ; Branch always
421 : bit $C080 ; Switch in LC bank 2 for R/O