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).
78 ; ------------------------------------------------------------------------
81 ; Variables mapped to the zero-page segment variables. Some of these are
82 ; used for passing parameters to the driver.
89 ; Absolute variables used in the code
94 .res 1 ; High byte of screen base (64k VDC only)
99 .res 2 ; The current palette
102 .res 1 ; $00 = clear, $01 = set pixels
105 .res 1 ; colors before entering gfx mode
115 ; Constants and tables
120 .byte $00, $0f ; White on black
121 PALETTESIZE = * - DEFPALETTE
123 ; color translation table (indexed by VIC color)
125 .byte $00, $0f, $08, $06, $0a, $04, $02, $0c
126 .byte $0d, $0b, $09, $01, $0e, $05, $03, $07
127 ; colors BROWN and GRAY3 are wrong
131 ; ------------------------------------------------------------------------
132 ; INSTALL routine. Is called after the driver is loaded into memory. May
133 ; initialize anything that has to be done just once. Is probably empty
136 ; Must set an error code: NO
140 lda version ; if GEOS 1.0...
144 lda c128Flag ; at least GEOS 2.0, but we're on C128?
146 lda graphMode ; GEOS 2.0, C128, but is 80 column screen enabled?
148 @L40: rts ; leave default values for 40 column screen
150 ; check for VDC version and update register $19 value
153 ; double the x resolution and halve the aspect ratio
161 ; update number of available screens
163 ldx #VDC_CSET ; determine size of RAM...
167 jsr VDCWriteReg ; turn on 64k
169 jsr settestadr1 ; save original value of test byte
173 lda #$55 ; write $55 here
175 jsr test64k ; read it here and there
176 lda #$aa ; write $aa here
178 jsr test64k ; read it here and there
182 jsr VDCWriteByte ; restore original value of test byte
184 lda ptr1 ; do bytes match?
193 jsr VDCWriteReg ; restore 16/64k flag
194 jmp @endok ; and leave default values for 16k
201 sta SCRBASE ; draw page 0 as default
211 jsr VDCWriteByte ; write $55
213 jsr VDCReadByte ; read here
216 jsr VDCReadByte ; and there
225 ldy #$02 ; test page 2 (here)
228 ldy #$42 ; or page 64+2 (there)
232 ; ------------------------------------------------------------------------
233 ; UNINSTALL routine. Is called before the driver is removed from memory. May
234 ; clean up anything done by INSTALL but is probably empty most of the time.
236 ; Must set an error code: NO
243 ; ------------------------------------------------------------------------
244 ; INIT: Changes an already installed device from text mode to graphics
246 ; Note that INIT/DONE may be called multiple times while the driver
247 ; is loaded, while INSTALL is only called once, so any code that is needed
248 ; to initializes variables and so on must go here. Setting palette and
249 ; clearing the screen is not needed because this is called by the graphics
251 ; The graphics kernel will never call INIT when a graphics mode is already
252 ; active, so there is no need to protect against that.
254 ; Must set an error code: YES
259 stx BITMASK ; solid black as pattern
262 lda #ST_WR_FORE ; write only on foreground
268 ; Remember current color value (40 columns)
273 ; Remember current color value (80 columns)
274 @L80: lda scr80colors
277 jsr SETVIEWPAGE ; switch into viewpage 0
279 ; Done, reset the error code
285 ; ------------------------------------------------------------------------
286 ; DONE: Will be called to switch the graphics device back into text mode.
287 ; The graphics kernel will never call DONE when no graphics mode is active,
288 ; so there is no need to protect against that.
290 ; Must set an error code: NO
295 jsr SETVIEWPAGE ; switch into viewpage 0
301 sta screencolors ; restore color for 40 columns
303 @L1: sta COLOR_MATRIX,x
304 sta COLOR_MATRIX+$0100,x
305 sta COLOR_MATRIX+$0200,x
306 sta COLOR_MATRIX+1000-256,x
311 @L80: lda OLDCOLOR ; restore color for 80 columns
315 ; ------------------------------------------------------------------------
316 ; GETERROR: Return the error code in A and clear it.
324 ; ------------------------------------------------------------------------
325 ; CONTROL: Platform/driver specific entry point.
327 ; Must set an error code: YES
331 lda #TGI_ERR_INV_FUNC
335 ; ------------------------------------------------------------------------
336 ; CLEAR: Clears the screen.
338 ; Must set an error code: NO
354 lda #>639 ; 80 columns
357 @L40: lda #>319 ; 40 columns
366 ; ------------------------------------------------------------------------
367 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
368 ; The page number is already checked to be valid by the graphics kernel.
370 ; Must set an error code: NO (will only be called if page ok)
384 ; ------------------------------------------------------------------------
385 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
386 ; The page number is already checked to be valid by the graphics kernel.
388 ; Must set an error code: NO (will only be called if page ok)
402 ; ------------------------------------------------------------------------
403 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
404 ; to be in a valid range (0..maxcolor-1).
406 ; Must set an error code: NO (will only be called if color ok)
414 jmp SetPattern ; need to have either 0 or 1
416 ; ------------------------------------------------------------------------
417 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
418 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
421 ; Must set an error code: YES
425 jsr GETERROR ; clear error (if any)
428 @L1: lda (ptr1),y ; Copy the palette
429 and #$0F ; Make a valid color
434 ; Put colors from palette into screen
439 lda PALETTE+1 ; foreground
444 ora PALETTE ; background
446 @L2: sta COLOR_MATRIX,x
447 sta COLOR_MATRIX+$0100,x
448 sta COLOR_MATRIX+$0200,x
449 sta COLOR_MATRIX+1000-256,x
454 @L80: ldy PALETTE+1 ; Foreground color
460 ldy PALETTE ; Background color
466 ; ------------------------------------------------------------------------
467 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
468 ; set the palette should return the default palette here, so there's no
469 ; way for this function to fail.
471 ; Must set an error code: NO
479 ; ------------------------------------------------------------------------
480 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
481 ; drivers should return something reasonable here, even drivers that don't
482 ; support palettes, otherwise the caller has no way to determine the colors
483 ; of the (not changeable) palette.
485 ; Must set an error code: NO (all drivers must have a default palette)
493 ; ------------------------------------------------------------------------
494 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
495 ; color. The coordinates passed to this function are never outside the
496 ; visible screen area, so there is no need for clipping inside this function.
498 ; Must set an error code: NO
509 lda BITMASK ; set or clear C flag
515 ; ------------------------------------------------------------------------
516 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
517 ; coordinates passed to this function are never outside the visible screen
518 ; area, so there is no need for clipping inside this function.
536 ; ------------------------------------------------------------------------
537 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
538 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
540 ; Must set an error code: NO
557 lda BITMASK ; set or clear C flag
563 ; ------------------------------------------------------------------------
564 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
565 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
566 ; Contrary to most other functions, the graphics kernel will sort and clip
567 ; the coordinates before calling the driver, so on entry the following
568 ; conditions are valid:
571 ; (X1 >= 0) && (X1 < XRES)
572 ; (X2 >= 0) && (X2 < XRES)
573 ; (Y1 >= 0) && (Y1 < YRES)
574 ; (Y2 >= 0) && (Y2 < YRES)
576 ; Must set an error code: NO
594 ; ------------------------------------------------------------------------
595 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
596 ; direction is passend in X/Y, the text direction is passed in A.
598 ; Must set an error code: NO
608 ; ------------------------------------------------------------------------
609 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
610 ; current text style. The text to output is given as a zero terminated
611 ; string with address in ptr3.
613 ; Must set an error code: NO
618 ; cmp #TGI_TEXT_HORIZONTAL ; this is equal 0
621 lda X1 ; horizontal text output
634 lda X1 ; vertical text output
670 @L0: bit VDC_ADDR_REG
679 @L0: bit VDC_ADDR_REG