; capabilities of the driver
.byte $74, $67, $69 ; "tgi"
- .byte $00 ; TGI version number
+ .byte TGI_API_VERSION ; TGI API version number
.word 320 ; X resolution
.word 200 ; Y resolution
.byte 2 ; Number of drawing colors
.byte 1 ; Number of screens available
- .res 6, $00 ; Reserved for future extensions
+ .byte 8 ; System font X size
+ .byte 8 ; System font Y size
+ .res 4, $00 ; Reserved for future extensions
; Next comes the jump table. Currently all entries must be valid and may point
; to an RTS for test versions (function not implemented). A future version may
; that the graphics kernel will emulate the function by using lower level
; primitives - for example ploting a line by using calls to SETPIXEL.
- .word INSTALL
- .word DEINSTALL
- .word INIT
- .word DONE
- .word GETERROR
- .word CONTROL
- .word CLEAR
- .word SETVIEWPAGE
- .word SETDRAWPAGE
- .word SETCOLOR
- .word SETPALETTE
- .word GETPALETTE
- .word GETDEFPALETTE
- .word SETPIXEL
- .word GETPIXEL
- .word HORLINE
- .word LINE
- .word 0 ; BAR
- .word CIRCLE
-
+ .addr INSTALL
+ .addr UNINSTALL
+ .addr INIT
+ .addr DONE
+ .addr GETERROR
+ .addr CONTROL
+ .addr CLEAR
+ .addr SETVIEWPAGE
+ .addr SETDRAWPAGE
+ .addr SETCOLOR
+ .addr SETPALETTE
+ .addr GETPALETTE
+ .addr GETDEFPALETTE
+ .addr SETPIXEL
+ .addr GETPIXEL
+ .addr LINE
+ .addr BAR
+ .addr CIRCLE
+ .addr TEXTSTYLE
+ .addr OUTTEXT
+ .addr 0 ; IRQ entry is unused
; ------------------------------------------------------------------------
; Data.
; Variables mapped to the zero page segment variables. Some of these are
; used for passing parameters to the driver.
-X1 = ptr1
-Y1 = ptr2
-X2 = ptr3
-Y2 = ptr4
-RADIUS = tmp1
+X1 := ptr1
+Y1 := ptr2
+X2 := ptr3
+Y2 := ptr4
+RADIUS := tmp1
-ROW = tmp2 ; Bitmap row...
-COL = tmp3 ; ...and column, both set by PLOT
-TEMP = tmp4
-TEMP2 = sreg
-POINT = regsave
+ROW := tmp2 ; Bitmap row...
+COL := tmp3 ; ...and column, both set by PLOT
+TEMP := tmp4
+TEMP2 := sreg
+POINT := regsave
+INRANGE := regsave+2 ; PLOT variable, $00 = coordinates in range
-CHUNK = X2 ; Used in the line routine
-OLDCHUNK = X2+1 ; Dito
+CHUNK := X2 ; Used in the line routine
+OLDCHUNK := X2+1 ; Dito
; Absolute variables used in the code
; INIT/DONE
OLDD018: .res 1 ; Old register value
-; PLOT variables
-INRANGE: .res 1 ; $00 = coordinates in range
-
; Line routine stuff
DX: .res 2
DY: .res 2
-; Circle routine stuff
+; Circle routine stuff, overlaid by BAR variables
+X1SAVE:
CURX: .res 1
CURY: .res 1
+Y1SAVE:
BROW: .res 1 ; Bottom row
TROW: .res 1 ; Top row
+X2SAVE:
LCOL: .res 1 ; Left column
RCOL: .res 1 ; Right column
+Y2SAVE:
CHUNK1: .res 1
OLDCH1: .res 1
CHUNK2: .res 1
OLDCH2: .res 1
+; Text output stuff
+TEXTMAGX: .res 1
+TEXTMAGY: .res 1
+TEXTDIR: .res 1
+
; Constants and tables
.rodata
; ------------------------------------------------------------------------
-; DEINSTALL routine. Is called before the driver is removed from memory. May
+; UNINSTALL routine. Is called before the driver is removed from memory. May
; clean up anything done by INSTALL but is probably empty most of the time.
;
; Must set an error code: NO
;
-DEINSTALL:
+UNINSTALL:
rts
; ------------------------------------------------------------------------
; INIT: Changes an already installed device from text mode to graphics
-; mode. The number of the graphics mode is passed to the function in A.
+; mode.
; Note that INIT/DONE may be called multiple times while the driver
; is loaded, while INSTALL is only called once, so any code that is needed
; to initializes variables and so on must go here. Setting palette and
; Must set an error code: YES
;
-INIT: cmp #TGI_MODE_320_200_2 ; Correct mode?
- beq @L1 ; Jump if yes
- lda #TGI_ERR_INV_MODE ; ## Error
- bne @L9
+INIT:
; Initialize variables
-@L1: ldx #$FF
+ ldx #$FF
stx BITMASK
; Switch into graphics mode
lda $D011 ; And turn on bitmap
ora #$20
- sta $D011
+DONE1: sta $D011
; Done, reset the error code
lda #TGI_ERR_OK
-@L9: sta ERROR
+ sta ERROR
rts
; ------------------------------------------------------------------------
; The graphics kernel will never call DONE when no graphics mode is active,
; so there is no need to protect against that.
;
-; Must set an error code: YES
+; Must set an error code: NO
;
DONE: lda $DD02 ; Set the data direction regs
sta $01
cli
-; Done
+; Done, reset the error code
+ lda #TGI_ERR_OK
+ sta ERROR
rts
; ------------------------------------------------------------------------
-; GETPALETTE: Return the current palette in A/X. Must return NULL and set an
-; error if palettes are not supported.
+; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
+; set the palette should return the default palette here, so there's no
+; way for this function to fail.
;
-; Must set an error code: YES
+; Must set an error code: NO
;
GETPALETTE:
rts
; ------------------------------------------------------------------------
-; GETDEFPALETTE: Return the default palette for the driver in A/X. Must
-; return NULL and set an error of palettes are not supported.
+; GETDEFPALETTE: Return the default palette for the driver in A/X. All
+; drivers should return something reasonable here, even drivers that don't
+; support palettes, otherwise the caller has no way to determine the colors
+; of the (not changeable) palette.
;
-; Must set an error code: YES
+; Must set an error code: NO (all drivers must have a default palette)
;
GETDEFPALETTE:
ldx #$00 ; Clear high byte
rts
-; ------------------------------------------------------------------------
-; HORLINE: Draw a horizontal line from X1/Y to X2/Y, where X1 = ptr1,
-; Y = ptr2 and X2 = ptr3, using the current drawing color.
-;
-; This is a special line drawing entry used when the line is know to be
-; horizontal, for example by the BAR emulation routine. If the driver does
-; not have special code for horizontal lines, it may just copy Y to Y2 and
-; proceed with the generic line drawing code.
-;
-; Note: Line coordinates will always be sorted (Y1 <= X2) and clipped.
-;
-; Must set an error code: NO
-;
-
-HORLINE:
- lda ptr2
- sta ptr4
- lda ptr2+1
- sta ptr4+1
-; jmp LINE
-
; ------------------------------------------------------------------------
; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
; X2/Y2 = ptr3/ptr4 using the current drawing color.
bmi @C1 ;Skip if column is negative
cmp #39 ;End if move past end of screen
bcs EXIT
-@C1: lda POINT
+@C1: lda POINT
adc #8
sta POINT
bcc @CONT
@CONT1: inc ROW
bne @DONE
lda COL
- bmi @DONE
- lda #00
- sta INRANGE
+ bpl @CLEAR
@DONE: rts
@DECPTR: ;Okay, subtract 320 then
bne @DONE
lda COL
bmi @DONE
- lda #00
+@CLEAR: lda #00
sta INRANGE
rts
+
@TOAST: pla ;Remove old return address
pla
jmp EXIT ;Restore interrupts, etc.
; Must set an error code: NO
;
-BAR: rts
+; Note: This function needs optimization. It's just a cheap translation of
+; the original C wrapper and could be written much smaller (besides that,
+; calling LINE is not a good idea either).
+
+BAR: lda Y2
+ sta Y2SAVE
+ lda Y2+1
+ sta Y2SAVE+1
+
+ lda X2
+ sta X2SAVE
+ lda X2+1
+ sta X2SAVE+1
+
+ lda Y1
+ sta Y1SAVE
+ lda Y1+1
+ sta Y1SAVE+1
+
+ lda X1
+ sta X1SAVE
+ lda X1+1
+ sta X1SAVE+1
+
+@L1: lda Y1
+ sta Y2
+ lda Y1+1
+ sta Y2+1
+ jsr LINE
+
+ lda Y1SAVE
+ cmp Y2SAVE
+ bne @L2
+ lda Y1SAVE
+ cmp Y2SAVE
+ beq @L4
+
+@L2: inc Y1SAVE
+ bne @L3
+ inc Y1SAVE+1
+
+@L3: lda Y1SAVE
+ sta Y1
+ lda Y1SAVE+1
+ sta Y1+1
+
+ lda X1SAVE
+ sta X1
+ lda X1SAVE+1
+ sta X1+1
+
+ lda X2SAVE
+ sta X2
+ lda X2SAVE+1
+ sta X2+1
+ jmp @L1
+
+@L4: rts
+
; ------------------------------------------------------------------------
; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the
sta (X2),y
EXIT3: rts
+; ------------------------------------------------------------------------
+; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
+; direction is passend in X/Y, the text direction is passed in A.
+;
+; Must set an error code: NO
+;
+
+TEXTSTYLE:
+ stx TEXTMAGX
+ sty TEXTMAGY
+ sta TEXTDIR
+ rts
+
+
+; ------------------------------------------------------------------------
+; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
+; current text style. The text to output is given as a zero terminated
+; string with address in ptr3.
+;
+; Must set an error code: NO
+;
+
+OUTTEXT:
+ rts
+
; ------------------------------------------------------------------------
; Calculate all variables to plot the pixel at X1/Y1. If the point is out
; of range, a carry is returned and INRANGE is set to a value !0 zero. If