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"
8 .include "tgi-kernel.inc"
9 .include "tgi-error.inc"
12 .include "jumptab.inc"
13 .include "geossym.inc"
14 .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.
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 xres: .word 320 ; X resolution
46 yres: .word 200 ; Y resolution
47 .byte 2 ; Number of drawing colors
48 pages: .byte 1 ; Number of screens available
49 .byte 8 ; System font X size
50 .byte 8 ; System font Y size
51 aspect: .word $00D4 ; Aspect ratio (based on 4/3 display)
52 .byte 0 ; TGI driver flags
54 ; Next comes the jump table. With the exception of IRQ, all entries must be
55 ; valid, and may point to an RTS for test versions (function not implemented).
76 .addr 0 ; IRQ entry is unused
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
93 SCRBASE: .res 1 ; High byte of screen base (64k VDC only)
95 ERROR: .res 1 ; Error code
96 PALETTE: .res 2 ; The current palette
98 BITMASK: .res 1 ; $00 = clear, $01 = set pixels
100 OLDCOLOR: .res 1 ; colors before entering gfx mode
107 ; Constants and tables
111 DEFPALETTE: .byte $00, $0f ; White on black
112 PALETTESIZE = * - DEFPALETTE
114 ; color translation table (indexed by VIC color)
115 COLTRANS: .byte $00, $0f, $08, $06, $0a, $04, $02, $0c
116 .byte $0d, $0b, $09, $01, $0e, $05, $03, $07
117 ; colors BROWN and GRAY3 are wrong
121 ; ------------------------------------------------------------------------
122 ; INSTALL routine. Is called after the driver is loaded into memory. May
123 ; initialize anything that has to be done just once. Is probably empty
126 ; Must set an error code: NO
130 lda version ; if GEOS 1.0...
134 lda c128Flag ; at least GEOS 2.0, but we're on C128?
136 lda graphMode ; GEOS 2.0, C128, but is 80 column screen enabled?
138 @L40: rts ; leave default values for 40 column screen
140 ; check for VDC version and update register $19 value
143 ; double the x resolution and halve the aspect ratio
151 ; update number of available screens
153 ldx #VDC_CSET ; determine size of RAM...
157 jsr VDCWriteReg ; turn on 64k
159 jsr settestadr1 ; save original value of test byte
163 lda #$55 ; write $55 here
165 jsr test64k ; read it here and there
166 lda #$aa ; write $aa here
168 jsr test64k ; read it here and there
172 jsr VDCWriteByte ; restore original value of test byte
174 lda ptr1 ; do bytes match?
183 jsr VDCWriteReg ; restore 16/64k flag
184 jmp @endok ; and leave default values for 16k
191 sta SCRBASE ; draw page 0 as default
201 jsr VDCWriteByte ; write $55
203 jsr VDCReadByte ; read here
206 jsr VDCReadByte ; and there
215 ldy #$02 ; test page 2 (here)
218 ldy #$42 ; or page 64+2 (there)
222 ; ------------------------------------------------------------------------
223 ; UNINSTALL routine. Is called before the driver is removed from memory. May
224 ; clean up anything done by INSTALL but is probably empty most of the time.
226 ; Must set an error code: NO
233 ; ------------------------------------------------------------------------
234 ; INIT: Changes an already installed device from text mode to graphics
236 ; Note that INIT/DONE may be called multiple times while the driver
237 ; is loaded, while INSTALL is only called once, so any code that is needed
238 ; to initializes variables and so on must go here. Setting palette and
239 ; clearing the screen is not needed because this is called by the graphics
241 ; The graphics kernel will never call INIT when a graphics mode is already
242 ; active, so there is no need to protect against that.
244 ; Must set an error code: YES
249 stx BITMASK ; solid black as pattern
252 lda #ST_WR_FORE ; write only on foreground
258 ; Remember current color value (40 columns)
263 ; Remember current color value (80 columns)
264 @L80: lda scr80colors
267 jsr SETVIEWPAGE ; switch into viewpage 0
269 ; Done, reset the error code
275 ; ------------------------------------------------------------------------
276 ; DONE: Will be called to switch the graphics device back into text mode.
277 ; The graphics kernel will never call DONE when no graphics mode is active,
278 ; so there is no need to protect against that.
280 ; Must set an error code: NO
285 jsr SETVIEWPAGE ; switch into viewpage 0
291 sta screencolors ; restore color for 40 columns
293 @L1: sta COLOR_MATRIX,x
294 sta COLOR_MATRIX+$0100,x
295 sta COLOR_MATRIX+$0200,x
296 sta COLOR_MATRIX+1000-256,x
301 @L80: lda OLDCOLOR ; restore color for 80 columns
305 ; ------------------------------------------------------------------------
306 ; GETERROR: Return the error code in A and clear it.
314 ; ------------------------------------------------------------------------
315 ; CONTROL: Platform/driver specific entry point.
317 ; Must set an error code: YES
321 lda #TGI_ERR_INV_FUNC
325 ; ------------------------------------------------------------------------
326 ; CLEAR: Clears the screen.
328 ; Must set an error code: NO
344 lda #>639 ; 80 columns
347 @L40: lda #>319 ; 40 columns
356 ; ------------------------------------------------------------------------
357 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
358 ; The page number is already checked to be valid by the graphics kernel.
360 ; Must set an error code: NO (will only be called if page ok)
374 ; ------------------------------------------------------------------------
375 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
376 ; The page number is already checked to be valid by the graphics kernel.
378 ; Must set an error code: NO (will only be called if page ok)
392 ; ------------------------------------------------------------------------
393 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
394 ; to be in a valid range (0..maxcolor-1).
396 ; Must set an error code: NO (will only be called if color ok)
404 jmp SetPattern ; need to have either 0 or 1
406 ; ------------------------------------------------------------------------
407 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
408 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
411 ; Must set an error code: YES
415 jsr GETERROR ; clear error (if any)
418 @L1: lda (ptr1),y ; Copy the palette
419 and #$0F ; Make a valid color
424 ; Put colors from palette into screen
429 lda PALETTE+1 ; foreground
434 ora PALETTE ; background
436 @L2: sta COLOR_MATRIX,x
437 sta COLOR_MATRIX+$0100,x
438 sta COLOR_MATRIX+$0200,x
439 sta COLOR_MATRIX+1000-256,x
444 @L80: ldy PALETTE+1 ; Foreground color
450 ldy PALETTE ; Background color
456 ; ------------------------------------------------------------------------
457 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
458 ; set the palette should return the default palette here, so there's no
459 ; way for this function to fail.
461 ; Must set an error code: NO
469 ; ------------------------------------------------------------------------
470 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
471 ; drivers should return something reasonable here, even drivers that don't
472 ; support palettes, otherwise the caller has no way to determine the colors
473 ; of the (not changeable) palette.
475 ; Must set an error code: NO (all drivers must have a default palette)
483 ; ------------------------------------------------------------------------
484 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
485 ; color. The coordinates passed to this function are never outside the
486 ; visible screen area, so there is no need for clipping inside this function.
488 ; Must set an error code: NO
499 lda BITMASK ; set or clear C flag
505 ; ------------------------------------------------------------------------
506 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
507 ; coordinates passed to this function are never outside the visible screen
508 ; area, so there is no need for clipping inside this function.
526 ; ------------------------------------------------------------------------
527 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
528 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
530 ; Must set an error code: NO
547 lda BITMASK ; set or clear C flag
553 ; ------------------------------------------------------------------------
554 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
555 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
556 ; Contrary to most other functions, the graphics kernel will sort and clip
557 ; the coordinates before calling the driver, so on entry the following
558 ; conditions are valid:
561 ; (X1 >= 0) && (X1 < XRES)
562 ; (X2 >= 0) && (X2 < XRES)
563 ; (Y1 >= 0) && (Y1 < YRES)
564 ; (Y2 >= 0) && (Y2 < YRES)
566 ; Must set an error code: NO
584 ; ------------------------------------------------------------------------
585 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
586 ; direction is passend in X/Y, the text direction is passed in A.
588 ; Must set an error code: NO
598 ; ------------------------------------------------------------------------
599 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
600 ; current text style. The text to output is given as a zero terminated
601 ; string with address in ptr3.
603 ; Must set an error code: NO
608 ; cmp #TGI_TEXT_HORIZONTAL ; this is equal 0
611 lda X1 ; horizontal text output
624 lda X1 ; vertical text output
660 @L0: bit VDC_ADDR_REG
669 @L0: bit VDC_ADDR_REG