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"
18 ; ------------------------------------------------------------------------
21 VDC_ADDR_REG := $D600 ; VDC address
22 VDC_DATA_REG := $D601 ; VDC data
24 VDC_DSP_HI = 12 ; registers used
35 ; ------------------------------------------------------------------------
36 ; Header. Includes jump table and constants.
38 module_header _geos_tgi_tgi
40 ; First part of the header is a structure that has a magic signature,
41 ; and defines the capabilities of the driver.
43 .byte $74, $67, $69 ; "tgi"
44 .byte TGI_API_VERSION ; TGI API version number
45 .addr $0000 ; Library reference
46 xres: .word 320 ; X resolution
47 yres: .word 200 ; Y resolution
48 .byte 2 ; Number of drawing colors
49 pages: .byte 1 ; Number of screens available
50 .byte 8 ; System font X size
51 .byte 8 ; System font Y size
52 aspect: .word $00D4 ; Aspect ratio (based on 4/3 display)
53 .byte 0 ; TGI driver flags
55 ; Next comes the jump table. With the exception of IRQ, all entries must be
56 ; valid, and may point to an RTS for test versions (function not implemented).
77 .addr 0 ; IRQ entry is unused
79 ; ------------------------------------------------------------------------
82 ; Variables mapped to the zero-page segment variables. Some of these are
83 ; used for passing parameters to the driver.
90 ; Absolute variables used in the code
95 .res 1 ; High byte of screen base (64k VDC only)
100 .res 2 ; The current palette
103 .res 1 ; $00 = clear, $01 = set pixels
106 .res 1 ; colors before entering gfx mode
116 ; Constants and tables
121 .byte $00, $0f ; White on black
122 PALETTESIZE = * - DEFPALETTE
124 ; color translation table (indexed by VIC color)
126 .byte $00, $0f, $08, $06, $0a, $04, $02, $0c
127 .byte $0d, $0b, $09, $01, $0e, $05, $03, $07
128 ; colors BROWN and GRAY3 are wrong
132 ; ------------------------------------------------------------------------
133 ; INSTALL routine. Is called after the driver is loaded into memory. May
134 ; initialize anything that has to be done just once. Is probably empty
137 ; Must set an error code: NO
141 lda version ; if GEOS 1.0...
145 lda c128Flag ; at least GEOS 2.0, but we're on C128?
147 lda graphMode ; GEOS 2.0, C128, but is 80 column screen enabled?
149 @L40: rts ; leave default values for 40 column screen
151 ; check for VDC version and update register $19 value
154 ; double the x resolution and halve the aspect ratio
162 ; update number of available screens
164 ldx #VDC_CSET ; determine size of RAM...
168 jsr VDCWriteReg ; turn on 64k
170 jsr settestadr1 ; save original value of test byte
174 lda #$55 ; write $55 here
176 jsr test64k ; read it here and there
177 lda #$aa ; write $aa here
179 jsr test64k ; read it here and there
183 jsr VDCWriteByte ; restore original value of test byte
185 lda ptr1 ; do bytes match?
194 jsr VDCWriteReg ; restore 16/64k flag
195 jmp @endok ; and leave default values for 16k
202 sta SCRBASE ; draw page 0 as default
212 jsr VDCWriteByte ; write $55
214 jsr VDCReadByte ; read here
217 jsr VDCReadByte ; and there
226 ldy #$02 ; test page 2 (here)
229 ldy #$42 ; or page 64+2 (there)
233 ; ------------------------------------------------------------------------
234 ; UNINSTALL routine. Is called before the driver is removed from memory. May
235 ; clean up anything done by INSTALL but is probably empty most of the time.
237 ; Must set an error code: NO
244 ; ------------------------------------------------------------------------
245 ; INIT: Changes an already installed device from text mode to graphics
247 ; Note that INIT/DONE may be called multiple times while the driver
248 ; is loaded, while INSTALL is only called once, so any code that is needed
249 ; to initializes variables and so on must go here. Setting palette and
250 ; clearing the screen is not needed because this is called by the graphics
252 ; The graphics kernel will never call INIT when a graphics mode is already
253 ; active, so there is no need to protect against that.
255 ; Must set an error code: YES
260 stx BITMASK ; solid black as pattern
263 lda #ST_WR_FORE ; write only on foreground
269 ; Remember current color value (40 columns)
274 ; Remember current color value (80 columns)
275 @L80: lda scr80colors
278 jsr SETVIEWPAGE ; switch into viewpage 0
280 ; Done, reset the error code
286 ; ------------------------------------------------------------------------
287 ; DONE: Will be called to switch the graphics device back into text mode.
288 ; The graphics kernel will never call DONE when no graphics mode is active,
289 ; so there is no need to protect against that.
291 ; Must set an error code: NO
296 jsr SETVIEWPAGE ; switch into viewpage 0
302 sta screencolors ; restore color for 40 columns
304 @L1: sta COLOR_MATRIX,x
305 sta COLOR_MATRIX+$0100,x
306 sta COLOR_MATRIX+$0200,x
307 sta COLOR_MATRIX+1000-256,x
312 @L80: lda OLDCOLOR ; restore color for 80 columns
316 ; ------------------------------------------------------------------------
317 ; GETERROR: Return the error code in A and clear it.
325 ; ------------------------------------------------------------------------
326 ; CONTROL: Platform/driver specific entry point.
328 ; Must set an error code: YES
332 lda #TGI_ERR_INV_FUNC
336 ; ------------------------------------------------------------------------
337 ; CLEAR: Clears the screen.
339 ; Must set an error code: NO
355 lda #>639 ; 80 columns
358 @L40: lda #>319 ; 40 columns
367 ; ------------------------------------------------------------------------
368 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
369 ; The page number is already checked to be valid by the graphics kernel.
371 ; Must set an error code: NO (will only be called if page ok)
385 ; ------------------------------------------------------------------------
386 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
387 ; The page number is already checked to be valid by the graphics kernel.
389 ; Must set an error code: NO (will only be called if page ok)
403 ; ------------------------------------------------------------------------
404 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
405 ; to be in a valid range (0..maxcolor-1).
407 ; Must set an error code: NO (will only be called if color ok)
415 jmp SetPattern ; need to have either 0 or 1
417 ; ------------------------------------------------------------------------
418 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
419 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
422 ; Must set an error code: YES
426 jsr GETERROR ; clear error (if any)
429 @L1: lda (ptr1),y ; Copy the palette
430 and #$0F ; Make a valid color
435 ; Put colors from palette into screen
440 lda PALETTE+1 ; foreground
445 ora PALETTE ; background
447 @L2: sta COLOR_MATRIX,x
448 sta COLOR_MATRIX+$0100,x
449 sta COLOR_MATRIX+$0200,x
450 sta COLOR_MATRIX+1000-256,x
455 @L80: ldy PALETTE+1 ; Foreground color
461 ldy PALETTE ; Background color
467 ; ------------------------------------------------------------------------
468 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
469 ; set the palette should return the default palette here, so there's no
470 ; way for this function to fail.
472 ; Must set an error code: NO
480 ; ------------------------------------------------------------------------
481 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
482 ; drivers should return something reasonable here, even drivers that don't
483 ; support palettes, otherwise the caller has no way to determine the colors
484 ; of the (not changeable) palette.
486 ; Must set an error code: NO (all drivers must have a default palette)
494 ; ------------------------------------------------------------------------
495 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
496 ; color. The coordinates passed to this function are never outside the
497 ; visible screen area, so there is no need for clipping inside this function.
499 ; Must set an error code: NO
510 lda BITMASK ; set or clear C flag
516 ; ------------------------------------------------------------------------
517 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
518 ; coordinates passed to this function are never outside the visible screen
519 ; area, so there is no need for clipping inside this function.
537 ; ------------------------------------------------------------------------
538 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
539 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
541 ; Must set an error code: NO
558 lda BITMASK ; set or clear C flag
564 ; ------------------------------------------------------------------------
565 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
566 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
567 ; Contrary to most other functions, the graphics kernel will sort and clip
568 ; the coordinates before calling the driver, so on entry the following
569 ; conditions are valid:
572 ; (X1 >= 0) && (X1 < XRES)
573 ; (X2 >= 0) && (X2 < XRES)
574 ; (Y1 >= 0) && (Y1 < YRES)
575 ; (Y2 >= 0) && (Y2 < YRES)
577 ; Must set an error code: NO
595 ; ------------------------------------------------------------------------
596 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
597 ; direction is passend in X/Y, the text direction is passed in A.
599 ; Must set an error code: NO
609 ; ------------------------------------------------------------------------
610 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
611 ; current text style. The text to output is given as a zero terminated
612 ; string with address in ptr3.
614 ; Must set an error code: NO
619 ; cmp #TGI_TEXT_HORIZONTAL ; this is equal 0
622 lda X1 ; horizontal text output
635 lda X1 ; vertical text output
671 @L0: bit VDC_ADDR_REG
680 @L0: bit VDC_ADDR_REG