2 ; Graphics driver for the 320x200x2 or 640x200x2 mode on GEOS 64/128
3 ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
6 .include "zeropage.inc"
8 .include "tgi-kernel.inc"
9 .include "tgi-mode.inc"
10 .include "tgi-error.inc"
12 .include "../inc/const.inc"
13 .include "../inc/jumptab.inc"
14 .include "../inc/geossym.inc"
15 .include "../inc/geossym2.inc"
19 ; ------------------------------------------------------------------------
22 VDC_ADDR_REG = $D600 ; VDC address
23 VDC_DATA_REG = $D601 ; VDC data
25 VDC_DSP_HI = 12 ; registers used
36 ; ------------------------------------------------------------------------
37 ; Header. Includes jump table and constants.
41 ; First part of the header is a structure that has a magic and defines the
42 ; capabilities of the driver
44 .byte $74, $67, $69 ; "tgi"
45 .byte TGI_API_VERSION ; TGI API version number
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 .res 4, $00 ; Reserved for future extensions
54 ; Next comes the jump table. Currently all entries must be valid and may point
55 ; 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.
97 XX = ptr3 ; (2) CIRCLE
98 YY = ptr4 ; (2) CIRCLE
99 MaxO = sreg ; (overwritten by TEMP3+TEMP4, but restored from OG/OU anyway)
100 XS = regsave ; (2) CIRCLE
101 YS = regsave+2 ; (2) CIRCLE
103 ; Absolute variables used in the code
107 SCRBASE: .res 1 ; High byte of screen base (64k VDC only)
109 ERROR: .res 1 ; Error code
110 PALETTE: .res 2 ; The current palette
112 BITMASK: .res 1 ; $00 = clear, $01 = set pixels
114 OLDCOLOR: .res 1 ; colors before entering gfx mode
116 ; Line routine stuff (combined with CIRCLE to save space)
127 ; Constants and tables
131 DEFPALETTE: .byte $00, $0f ; White on black
132 PALETTESIZE = * - DEFPALETTE
134 ; color translation table (indexed by VIC color)
135 COLTRANS: .byte $00, $0f, $08, $06, $0a, $04, $02, $0c
136 .byte $0d, $0b, $09, $01, $0e, $05, $03, $07
137 ; colors BROWN and GRAY3 are wrong
141 ; ------------------------------------------------------------------------
142 ; INSTALL routine. Is called after the driver is loaded into memory. May
143 ; initialize anything that has to be done just once. Is probably empty
146 ; Must set an error code: NO
150 lda version ; if GEOS 1.0...
154 lda c128Flag ; at least GEOS 2.0, but we're on C128?
156 lda graphMode ; GEOS 2.0, C128, but is 80 column screen enabled?
158 @L40: rts ; leave default values for 40 column screen
160 ; check for VDC version and update register $19 value
168 ; update number of available screens
170 ldx #VDC_CSET ; determine size of RAM...
174 jsr VDCWriteReg ; turn on 64k
176 jsr settestadr1 ; save original value of test byte
180 lda #$55 ; write $55 here
182 jsr test64k ; read it here and there
183 lda #$aa ; write $aa here
185 jsr test64k ; read it here and there
189 jsr VDCWriteByte ; restore original value of test byte
191 lda ptr1 ; do bytes match?
200 jsr VDCWriteReg ; restore 16/64k flag
201 jmp @endok ; and leave default values for 16k
208 sta SCRBASE ; draw page 0 as default
218 jsr VDCWriteByte ; write $55
220 jsr VDCReadByte ; read here
223 jsr VDCReadByte ; and there
232 ldy #$02 ; test page 2 (here)
235 ldy #$42 ; or page 64+2 (there)
239 ; ------------------------------------------------------------------------
240 ; UNINSTALL routine. Is called before the driver is removed from memory. May
241 ; clean up anything done by INSTALL but is probably empty most of the time.
243 ; Must set an error code: NO
250 ; ------------------------------------------------------------------------
251 ; INIT: Changes an already installed device from text mode to graphics
253 ; Note that INIT/DONE may be called multiple times while the driver
254 ; is loaded, while INSTALL is only called once, so any code that is needed
255 ; to initializes variables and so on must go here. Setting palette and
256 ; clearing the screen is not needed because this is called by the graphics
258 ; The graphics kernel will never call INIT when a graphics mode is already
259 ; active, so there is no need to protect against that.
261 ; Must set an error code: YES
266 stx BITMASK ; solid black as pattern
269 lda #ST_WR_FORE ; write only on foreground
275 ; Remember current color value (40 columns)
280 ; Remember current color value (80 columns)
281 @L80: lda scr80colors
284 jsr SETVIEWPAGE ; switch into viewpage 0
286 ; Done, reset the error code
292 ; ------------------------------------------------------------------------
293 ; DONE: Will be called to switch the graphics device back into text mode.
294 ; The graphics kernel will never call DONE when no graphics mode is active,
295 ; so there is no need to protect against that.
297 ; Must set an error code: NO
302 jsr SETVIEWPAGE ; switch into viewpage 0
308 sta screencolors ; restore color for 40 columns
310 @L1: sta COLOR_MATRIX,x
311 sta COLOR_MATRIX+$0100,x
312 sta COLOR_MATRIX+$0200,x
313 sta COLOR_MATRIX+1000-256,x
318 @L80: lda OLDCOLOR ; restore color for 80 columns
322 ; ------------------------------------------------------------------------
323 ; GETERROR: Return the error code in A and clear it.
331 ; ------------------------------------------------------------------------
332 ; CONTROL: Platform/driver specific entry point.
334 ; Must set an error code: YES
338 lda #TGI_ERR_INV_FUNC
342 ; ------------------------------------------------------------------------
343 ; CLEAR: Clears the screen.
345 ; Must set an error code: NO
361 lda #>639 ; 80 columns
364 @L40: lda #>319 ; 40 columns
373 ; ------------------------------------------------------------------------
374 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
375 ; The page number is already checked to be valid by the graphics kernel.
377 ; Must set an error code: NO (will only be called if page ok)
391 ; ------------------------------------------------------------------------
392 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
393 ; The page number is already checked to be valid by the graphics kernel.
395 ; Must set an error code: NO (will only be called if page ok)
409 ; ------------------------------------------------------------------------
410 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
411 ; to be in a valid range (0..maxcolor-1).
413 ; Must set an error code: NO (will only be called if color ok)
421 jmp SetPattern ; need to have either 0 or 1
423 ; ------------------------------------------------------------------------
424 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
425 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
428 ; Must set an error code: YES
432 jsr GETERROR ; clear error (if any)
435 @L1: lda (ptr1),y ; Copy the palette
436 and #$0F ; Make a valid color
441 ; Put colors from palette into screen
446 lda PALETTE+1 ; foreground
451 ora PALETTE ; background
453 @L2: sta COLOR_MATRIX,x
454 sta COLOR_MATRIX+$0100,x
455 sta COLOR_MATRIX+$0200,x
456 sta COLOR_MATRIX+1000-256,x
461 @L80: ldy PALETTE+1 ; Foreground color
467 ldy PALETTE ; Background color
473 ; ------------------------------------------------------------------------
474 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
475 ; set the palette should return the default palette here, so there's no
476 ; way for this function to fail.
478 ; Must set an error code: NO
486 ; ------------------------------------------------------------------------
487 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
488 ; drivers should return something reasonable here, even drivers that don't
489 ; support palettes, otherwise the caller has no way to determine the colors
490 ; of the (not changeable) palette.
492 ; Must set an error code: NO (all drivers must have a default palette)
500 ; ------------------------------------------------------------------------
501 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
502 ; color. The coordinates passed to this function are never outside the
503 ; visible screen area, so there is no need for clipping inside this function.
505 ; Must set an error code: NO
520 jsr icmp ; ( x < xres ) ...
529 jsr icmp ; ... && ( y < yres )
541 lda BITMASK ; set or clear C flag
547 ; ------------------------------------------------------------------------
548 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
549 ; coordinates passed to this function are never outside the visible screen
550 ; area, so there is no need for clipping inside this function.
568 ; ------------------------------------------------------------------------
569 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
570 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
572 ; Must set an error code: NO
589 lda BITMASK ; set or clear C flag
595 ; ------------------------------------------------------------------------
596 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
597 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
598 ; Contrary to most other functions, the graphics kernel will sort and clip
599 ; the coordinates before calling the driver, so on entry the following
600 ; conditions are valid:
603 ; (X1 >= 0) && (X1 < XRES)
604 ; (X2 >= 0) && (X2 < XRES)
605 ; (Y1 >= 0) && (Y1 < YRES)
606 ; (Y2 >= 0) && (Y2 < YRES)
608 ; Must set an error code: NO
626 ; ------------------------------------------------------------------------
627 ; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the
628 ; radius in tmp1 and the current drawing color.
630 ; Must set an error code: NO
636 jmp SETPIXELCLIP ; Plot as a point
654 stx YS+1 ; XS/YS to remember the center
663 @L12: ; plot points in 8 slices...
678 sta Y1+1 ; (stack)=ys+y, y1=(stack)
680 jsr SETPIXELCLIP ; plot(xs+x,ys+y)
688 sta Y1+1 ; y3 = y1 = ys-y
690 jsr SETPIXELCLIP ; plot(xs+x,ys-y)
702 jsr SETPIXELCLIP ; plot (xs-x,ys+y)
707 jsr SETPIXELCLIP ; plot (xs-x,ys-y)
723 sta Y1+1 ; (stack)=ys+x, y1=(stack)
725 jsr SETPIXELCLIP ; plot(xs+y,ys+x)
733 sta Y1+1 ; y3 = y1 = ys-x
735 jsr SETPIXELCLIP ; plot(xs+y,ys-x)
739 sta Y1 ; y1 = ys+x(stack)
747 jsr SETPIXELCLIP ; plot (xs-y,ys+x)
752 jsr SETPIXELCLIP ; plot (xs-y,ys-x)
802 @L0148: ; if (abs(ou)<abs(og))
833 ; ------------------------------------------------------------------------
834 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
835 ; direction is passend in X/Y, the text direction is passed in A.
837 ; Must set an error code: NO
847 ; ------------------------------------------------------------------------
848 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
849 ; current text style. The text to output is given as a zero terminated
850 ; string with address in ptr3.
852 ; Must set an error code: NO
857 ; cmp #TGI_TEXT_HORIZONTAL ; this is equal 0
860 lda X1 ; horizontal text output
873 lda X1 ; vertical text output
894 ; copies of some runtime routines
914 ; compare a/y to zp,x
915 sta TEMP ; TEMP/TEMP2 - arg2
923 tya ; x/a - arg1 (a=high)
954 @L0: bit VDC_ADDR_REG
963 @L0: bit VDC_ADDR_REG