2 ; Graphics driver for the 320x200x2 and 640x200x2 modes on GEOS 64/128
3 ; 2010-08-17, Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
4 ; 2010-08-18, Greg King
6 .include "zeropage.inc"
7 .include "tgi-kernel.inc"
8 .include "tgi-error.inc"
10 .include "jumptab.inc"
11 .include "geossym.inc"
12 .include "geossym2.inc"
16 ; ------------------------------------------------------------------------
19 VDC_ADDR_REG := $D600 ; VDC address
20 VDC_DATA_REG := $D601 ; VDC data
22 VDC_DSP_HI = 12 ; registers used
33 ; ------------------------------------------------------------------------
34 ; Header. Includes jump table and constants.
38 ; First part of the header is a structure that has a magic signature,
39 ; and defines the capabilities of the driver.
41 .byte $74, $67, $69 ; "tgi"
42 .byte TGI_API_VERSION ; TGI API version number
43 xres: .word 320 ; X resolution
44 yres: .word 200 ; Y resolution
45 .byte 2 ; Number of drawing colors
46 pages: .byte 1 ; Number of screens available
47 .byte 8 ; System font X size
48 .byte 8 ; System font Y size
49 aspect: .word $00D4 ; Aspect ratio (based on 4/3 display)
50 .byte 0 ; TGI driver flags
52 ; Next comes the jump table. With the exception of IRQ, all entries must be
53 ; valid, and may point to an RTS for test versions (function not implemented).
74 .addr 0 ; IRQ entry is unused
76 ; ------------------------------------------------------------------------
79 ; Variables mapped to the zero-page segment variables. Some of these are
80 ; used for passing parameters to the driver.
87 ; Absolute variables used in the code
92 .res 1 ; High byte of screen base (64k VDC only)
97 .res 2 ; The current palette
100 .res 1 ; $00 = clear, $01 = set pixels
103 .res 1 ; colors before entering gfx mode
113 ; Constants and tables
118 .byte $00, $0f ; White on black
119 PALETTESIZE = * - DEFPALETTE
121 ; color translation table (indexed by VIC color)
123 .byte $00, $0f, $08, $06, $0a, $04, $02, $0c
124 .byte $0d, $0b, $09, $01, $0e, $05, $03, $07
125 ; colors BROWN and GRAY3 are wrong
129 ; ------------------------------------------------------------------------
130 ; INSTALL routine. Is called after the driver is loaded into memory. May
131 ; initialize anything that has to be done just once. Is probably empty
134 ; Must set an error code: NO
138 lda version ; if GEOS 1.0...
142 lda c128Flag ; at least GEOS 2.0, but we're on C128?
144 lda graphMode ; GEOS 2.0, C128, but is 80 column screen enabled?
146 @L40: rts ; leave default values for 40 column screen
148 ; check for VDC version and update register $19 value
151 ; double the x resolution and halve the aspect ratio
159 ; update number of available screens
161 ldx #VDC_CSET ; determine size of RAM...
165 jsr VDCWriteReg ; turn on 64k
167 jsr settestadr1 ; save original value of test byte
171 lda #$55 ; write $55 here
173 jsr test64k ; read it here and there
174 lda #$aa ; write $aa here
176 jsr test64k ; read it here and there
180 jsr VDCWriteByte ; restore original value of test byte
182 lda ptr1 ; do bytes match?
191 jsr VDCWriteReg ; restore 16/64k flag
192 jmp @endok ; and leave default values for 16k
199 sta SCRBASE ; draw page 0 as default
209 jsr VDCWriteByte ; write $55
211 jsr VDCReadByte ; read here
214 jsr VDCReadByte ; and there
223 ldy #$02 ; test page 2 (here)
226 ldy #$42 ; or page 64+2 (there)
230 ; ------------------------------------------------------------------------
231 ; UNINSTALL routine. Is called before the driver is removed from memory. May
232 ; clean up anything done by INSTALL but is probably empty most of the time.
234 ; Must set an error code: NO
241 ; ------------------------------------------------------------------------
242 ; INIT: Changes an already installed device from text mode to graphics
244 ; Note that INIT/DONE may be called multiple times while the driver
245 ; is loaded, while INSTALL is only called once, so any code that is needed
246 ; to initializes variables and so on must go here. Setting palette and
247 ; clearing the screen is not needed because this is called by the graphics
249 ; The graphics kernel will never call INIT when a graphics mode is already
250 ; active, so there is no need to protect against that.
252 ; Must set an error code: YES
257 stx BITMASK ; solid black as pattern
260 lda #ST_WR_FORE ; write only on foreground
266 ; Remember current color value (40 columns)
271 ; Remember current color value (80 columns)
272 @L80: lda scr80colors
275 jsr SETVIEWPAGE ; switch into viewpage 0
277 ; Done, reset the error code
283 ; ------------------------------------------------------------------------
284 ; DONE: Will be called to switch the graphics device back into text mode.
285 ; The graphics kernel will never call DONE when no graphics mode is active,
286 ; so there is no need to protect against that.
288 ; Must set an error code: NO
293 jsr SETVIEWPAGE ; switch into viewpage 0
299 sta screencolors ; restore color for 40 columns
301 @L1: sta COLOR_MATRIX,x
302 sta COLOR_MATRIX+$0100,x
303 sta COLOR_MATRIX+$0200,x
304 sta COLOR_MATRIX+1000-256,x
309 @L80: lda OLDCOLOR ; restore color for 80 columns
313 ; ------------------------------------------------------------------------
314 ; GETERROR: Return the error code in A and clear it.
322 ; ------------------------------------------------------------------------
323 ; CONTROL: Platform/driver specific entry point.
325 ; Must set an error code: YES
329 lda #TGI_ERR_INV_FUNC
333 ; ------------------------------------------------------------------------
334 ; CLEAR: Clears the screen.
336 ; Must set an error code: NO
352 lda #>639 ; 80 columns
355 @L40: lda #>319 ; 40 columns
364 ; ------------------------------------------------------------------------
365 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
366 ; The page number is already checked to be valid by the graphics kernel.
368 ; Must set an error code: NO (will only be called if page ok)
382 ; ------------------------------------------------------------------------
383 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
384 ; The page number is already checked to be valid by the graphics kernel.
386 ; Must set an error code: NO (will only be called if page ok)
400 ; ------------------------------------------------------------------------
401 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
402 ; to be in a valid range (0..maxcolor-1).
404 ; Must set an error code: NO (will only be called if color ok)
412 jmp SetPattern ; need to have either 0 or 1
414 ; ------------------------------------------------------------------------
415 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
416 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
419 ; Must set an error code: YES
423 jsr GETERROR ; clear error (if any)
426 @L1: lda (ptr1),y ; Copy the palette
427 and #$0F ; Make a valid color
432 ; Put colors from palette into screen
437 lda PALETTE+1 ; foreground
442 ora PALETTE ; background
444 @L2: sta COLOR_MATRIX,x
445 sta COLOR_MATRIX+$0100,x
446 sta COLOR_MATRIX+$0200,x
447 sta COLOR_MATRIX+1000-256,x
452 @L80: ldy PALETTE+1 ; Foreground color
458 ldy PALETTE ; Background color
464 ; ------------------------------------------------------------------------
465 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
466 ; set the palette should return the default palette here, so there's no
467 ; way for this function to fail.
469 ; Must set an error code: NO
477 ; ------------------------------------------------------------------------
478 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
479 ; drivers should return something reasonable here, even drivers that don't
480 ; support palettes, otherwise the caller has no way to determine the colors
481 ; of the (not changeable) palette.
483 ; Must set an error code: NO (all drivers must have a default palette)
491 ; ------------------------------------------------------------------------
492 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
493 ; color. The coordinates passed to this function are never outside the
494 ; visible screen area, so there is no need for clipping inside this function.
496 ; Must set an error code: NO
507 lda BITMASK ; set or clear C flag
513 ; ------------------------------------------------------------------------
514 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
515 ; coordinates passed to this function are never outside the visible screen
516 ; area, so there is no need for clipping inside this function.
534 ; ------------------------------------------------------------------------
535 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
536 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
538 ; Must set an error code: NO
555 lda BITMASK ; set or clear C flag
561 ; ------------------------------------------------------------------------
562 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
563 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
564 ; Contrary to most other functions, the graphics kernel will sort and clip
565 ; the coordinates before calling the driver, so on entry the following
566 ; conditions are valid:
569 ; (X1 >= 0) && (X1 < XRES)
570 ; (X2 >= 0) && (X2 < XRES)
571 ; (Y1 >= 0) && (Y1 < YRES)
572 ; (Y2 >= 0) && (Y2 < YRES)
574 ; Must set an error code: NO
592 ; ------------------------------------------------------------------------
593 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
594 ; direction is passend in X/Y, the text direction is passed in A.
596 ; Must set an error code: NO
606 ; ------------------------------------------------------------------------
607 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
608 ; current text style. The text to output is given as a zero terminated
609 ; string with address in ptr3.
611 ; Must set an error code: NO
616 ; cmp #TGI_TEXT_HORIZONTAL ; this is equal 0
619 lda X1 ; horizontal text output
632 lda X1 ; vertical text output
668 @L0: bit VDC_ADDR_REG
677 @L0: bit VDC_ADDR_REG