]> git.sur5r.net Git - cc65/blobdiff - libsrc/geos/devel/geos-tgi.s
Removed tgi_load() and all corresponding infrastructure. The idea behind tgi_load...
[cc65] / libsrc / geos / devel / geos-tgi.s
index 02d459942626c1026d5363ed8c011d254737cf0d..d7484b47f7cf8528d5ef903cf3d31879b0b5ffbd 100644 (file)
@@ -1,16 +1,11 @@
 ;
-; Graphics driver for the 320x200x2 or 640x200x2 mode on GEOS 64/128
-; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
-; 28-31.12.2002
-;
-; - not tested OutText
-; - not tested on VDC
-; - erratic Circle when needs to clip
+; Graphics driver for the 320x200x2 and 640x200x2 modes on GEOS 64/128
+; 2010-08-17, Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
+; 2010-08-18, Greg King
 
        .include        "zeropage.inc"
 
        .include        "tgi-kernel.inc"
-        .include        "tgi-mode.inc"
         .include        "tgi-error.inc"
 
        .include        "../inc/const.inc"
@@ -23,8 +18,8 @@
 ; ------------------------------------------------------------------------
 ; Constants
 
-VDC_ADDR_REG     = $D600                 ; VDC address
-VDC_DATA_REG     = $D601                 ; VDC data
+VDC_ADDR_REG     := $D600                ; VDC address
+VDC_DATA_REG     := $D601                ; VDC data
 
 VDC_DSP_HI       = 12                    ; registers used
 VDC_DSP_LO       = 13
@@ -42,71 +37,53 @@ VDC_DATA      = 31
 
 .segment        "JUMPTABLE"
 
-; First part of the header is a structure that has a magic and defines the
-; capabilities of the driver
+; First part of the header is a structure that has a magic signature,
+; and defines the capabilities of the driver.
 
         .byte   $74, $67, $69           ; "tgi"
-        .byte   $00                     ; TGI version number
+        .byte   TGI_API_VERSION         ; TGI API version number
 xres:   .word   320                     ; X resolution
 yres:   .word   200                     ; Y resolution
         .byte   2                       ; Number of drawing colors
 pages: .byte   1                       ; Number of screens available
         .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
-; allow for emulation: In this case the vector will be zero. Emulation means
-; 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   BAR
-        .word   CIRCLE
-        .word   TEXTSTYLE
-        .word   OUTTEXT
+        .word   $100                    ; Aspect ratio: 1.0
+
+; Next comes the jump table. With the exception of IRQ, all entries must be
+; valid, and may point to an RTS for test versions (function not implemented).
+
+       .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   TEXTSTYLE
+       .addr   OUTTEXT
+       .addr   0                       ; IRQ entry is unused
 
 ; ------------------------------------------------------------------------
 ; Data.
 
-; Variables mapped to the zero page segment variables. Some of these are
+; 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
-
-ADDR           = tmp1
-TEMP           = tmp3
-TEMP2          = tmp4
-TEMP3          = sreg
-TEMP4          = sreg+1
-
-; Circle stuff
-XX             = ptr3          ; (2)   CIRCLE
-YY             = ptr4          ; (2)   CIRCLE
-MaxO           = sreg          ; (overwritten by TEMP3+TEMP4, but restored from OG/OU anyway)
-XS             = regsave       ; (2)   CIRCLE
-YS             = regsave+2     ; (2)   CIRCLE
 
 ; Absolute variables used in the code
 
@@ -121,12 +98,6 @@ BITMASK:        .res    1       ; $00 = clear, $01 = set pixels
 
 OLDCOLOR:      .res    1       ; colors before entering gfx mode
 
-; Line routine stuff (combined with CIRCLE to save space)
-
-OGora:          .res   2
-OUkos:          .res   2
-Y3:             .res   2
-
 ; Text output stuff
 TEXTMAGX:       .res    1
 TEXTMAGY:       .res    1
@@ -245,19 +216,19 @@ settestadr2:
        jmp     VDCSetSourceAddr
 
 ; ------------------------------------------------------------------------
-; 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
@@ -270,7 +241,6 @@ DEINSTALL:
 ;
 
 INIT:
-       ; ignore passed parameter
        ldx #$01
        stx BITMASK             ; solid black as pattern
        lda #1
@@ -303,7 +273,7 @@ INIT:
 ; 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:
@@ -354,7 +324,7 @@ CONTROL:
 ; Must set an error code: NO
 ;
 
-CLEAR:  
+CLEAR:
            lda curPattern
            pha
            lda #0
@@ -425,10 +395,9 @@ SETDRAWPAGE:
 SETCOLOR:
         tax
         beq     @L1
-        inx
-@L1:    stx     BITMASK
-       txa                     ; need to have either 0 or 1
-       jmp     SetPattern
+        lda    #1
+@L1:    sta     BITMASK
+       jmp     SetPattern      ; need to have either 0 or 1
 
 ; ------------------------------------------------------------------------
 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
@@ -439,6 +408,8 @@ SETCOLOR:
 ;
 
 SETPALETTE:
+       jsr     GETERROR        ; clear error (if any)
+
         ldy     #PALETTESIZE - 1
 @L1:    lda     (ptr1),y        ; Copy the palette
         and     #$0F            ; Make a valid color
@@ -479,10 +450,11 @@ SETPALETTE:
        jmp     VDCWriteReg
 
 ; ------------------------------------------------------------------------
-; 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:
@@ -491,10 +463,12 @@ 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:
@@ -510,31 +484,6 @@ GETDEFPALETTE:
 ; Must set an error code: NO
 ;
 
-SETPIXELCLIP:
-       lda     Y1+1
-       bmi     @finito         ; y<0
-       lda     X1+1
-       bmi     @finito         ; x<0
-       lda     xres
-       ldx     xres+1
-       sta     ADDR
-       stx     ADDR+1
-       ldx     #ADDR
-       lda     X1
-       ldy     X1+1
-       jsr     icmp            ; if (xres<x1)
-       bcs     @cont           ; !(xres<x1)
-@finito:rts
-@cont: lda     yres
-       ldx     yres+1
-       sta     ADDR
-       stx     ADDR+1
-       ldx     #ADDR
-       lda     Y1
-       ldy     Y1+1
-       jsr     icmp            ; if (yres<y1)
-       bcc     @finito
-
 SETPIXEL:
        lda     X1
        ldx     X1+1
@@ -570,36 +519,6 @@ GETPIXEL:
        ldx     #0
        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     X1
-       ldx     X1+1
-       ldy     Y1
-       sta     r3L
-       stx     r3H
-       sty     r11L
-       lda     X2
-       ldx     X2+1
-       sta     r4L
-       stx     r4H
-       lda     BITMASK
-       beq     @L1
-       lda     #%11111111              ; pattern
-@L1:   jmp     HorizontalLine
-
 ; ------------------------------------------------------------------------
 ; 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.
@@ -658,213 +577,6 @@ BAR:
        sty     r2H
        jmp     Rectangle
 
-; ------------------------------------------------------------------------
-; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the
-; radius in tmp1 and the current drawing color.
-;
-; Must set an error code: NO
-;
-
-CIRCLE: 
-       lda     RADIUS
-        bne     @L1
-        jmp     SETPIXELCLIP    ; Plot as a point
-
-@L1:   sta     XX
-       ; x = r;
-       lda     #0
-       sta     XX+1
-       sta     YY
-       sta     YY+1
-       sta     MaxO
-       sta     MaxO+1
-       ; y =0; mo=0;
-       lda     X1
-       ldx     X1+1
-       sta     XS
-       stx     XS+1
-       lda     Y1
-       ldx     Y1+1
-       sta     YS
-       stx     YS+1            ; XS/YS to remember the center
-
-       ; while (y<x) {
-@L013B:        ldx     #YY
-       lda     XX
-       ldy     XX+1
-       jsr     icmp
-       bcc     @L12
-       rts
-@L12:  ; plot points in 8 slices...
-       lda     XS
-       clc
-       adc     XX
-       sta     X1
-       lda     XS+1
-       adc     XX+1
-       sta     X1+1            ; x1 = xs+x
-       lda     YS
-       clc
-       adc     YY
-       sta     Y1
-       pha
-       lda     YS+1
-       adc     YY+1
-       sta     Y1+1            ; (stack)=ys+y, y1=(stack)
-       pha
-       jsr     SETPIXELCLIP    ; plot(xs+x,ys+y)
-       lda     YS
-       sec
-       sbc     YY
-       sta     Y1
-       sta     Y3
-       lda     YS+1
-       sbc     YY+1
-       sta     Y1+1            ; y3 = y1 = ys-y
-       sta     Y3+1
-       jsr     SETPIXELCLIP    ; plot(xs+x,ys-y)
-       pla
-       sta     Y1+1
-       pla
-       sta     Y1              ; y1 = ys+y
-       lda     XS
-       sec
-       sbc     XX
-       sta     X1
-       lda     XS+1
-       sbc     XX+1
-       sta     X1+1
-       jsr     SETPIXELCLIP    ; plot (xs-x,ys+y)
-       lda     Y3
-       sta     Y1
-       lda     Y3+1
-       sta     Y1+1
-       jsr     SETPIXELCLIP    ; plot (xs-x,ys-y)
-
-       lda     XS
-       clc
-       adc     YY
-       sta     X1
-       lda     XS+1
-       adc     YY+1
-       sta     X1+1            ; x1 = xs+y
-       lda     YS
-       clc
-       adc     XX
-       sta     Y1
-       pha
-       lda     YS+1
-       adc     XX+1
-       sta     Y1+1            ; (stack)=ys+x, y1=(stack)
-       pha
-       jsr     SETPIXELCLIP    ; plot(xs+y,ys+x)
-       lda     YS
-       sec
-       sbc     XX
-       sta     Y1
-       sta     Y3
-       lda     YS+1
-       sbc     XX+1
-       sta     Y1+1            ; y3 = y1 = ys-x
-       sta     Y3+1
-       jsr     SETPIXELCLIP    ; plot(xs+y,ys-x)
-       pla
-       sta     Y1+1
-       pla
-       sta     Y1              ; y1 = ys+x(stack)
-       lda     XS
-       sec
-       sbc     YY
-       sta     X1
-       lda     XS+1
-       sbc     YY+1
-       sta     X1+1
-       jsr     SETPIXELCLIP    ; plot (xs-y,ys+x)
-       lda     Y3
-       sta     Y1
-       lda     Y3+1
-       sta     Y1+1
-       jsr     SETPIXELCLIP    ; plot (xs-y,ys-x)
-
-       ; og = mo+y+y+1
-       lda     MaxO
-       ldx     MaxO+1
-       clc
-       adc     YY
-       tay
-       txa
-       adc     YY+1
-       tax
-       tya
-       clc
-       adc     YY
-       tay
-       txa
-       adc     YY+1
-       tax
-       tya
-       clc
-       adc     #1
-       bcc     @L0143
-       inx
-@L0143:        sta     OGora
-       stx     OGora+1
-       ; ou = og-x-x+1
-       sec
-       sbc     XX
-       tay
-       txa
-       sbc     XX+1
-       tax
-       tya
-       sec
-       sbc     XX
-       tay
-       txa
-       sbc     XX+1
-       tax
-       tya
-       clc
-       adc     #1
-       bcc     @L0146
-       inx
-@L0146:        sta     OUkos
-       stx     OUkos+1
-       ; ++y
-       inc     YY
-       bne     @L0148
-       inc     YY+1
-@L0148:        ; if (abs(ou)<abs(og))
-       lda     OUkos
-       ldy     OUkos+1
-       jsr     abs
-       sta     TEMP3
-       sty     TEMP4
-       lda     OGora
-       ldy     OGora+1
-       jsr     abs
-       ldx     #TEMP3
-       jsr     icmp
-       bpl     @L0149
-       ; { --x;
-       sec
-       lda     XX
-       sbc     #1
-       sta     XX
-       bcs     @L014E
-       dec     XX+1
-@L014E:        ; mo = ou; }
-       lda     OUkos
-       ldx     OUkos+1
-       jmp     @L014G
-       ; else { mo = og }
-@L0149:        lda     OGora
-       ldx     OGora+1
-@L014G:        sta     MaxO
-       stx     MaxO+1
-       ; }
-        jmp    @L013B
-
 ; ------------------------------------------------------------------------
 ; 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.
@@ -888,7 +600,11 @@ TEXTSTYLE:
 ;
 
 OUTTEXT:
-       lda     X1
+       lda     TEXTDIR
+;      cmp     #TGI_TEXT_HORIZONTAL    ; this is equal 0
+       bne     @vertical
+
+       lda     X1              ; horizontal text output
        ldx     X1+1
        ldy     Y1
        sta     r11L
@@ -900,50 +616,26 @@ OUTTEXT:
        stx     r0H
        jmp     PutString
 
-;-------------
-; copies of some runtime routines
-
-abs:
-       ; a/y := abs(a/y)
-       dey
-       iny
-       bpl     @L1
-       ; negay
+@vertical:
+       lda     X1              ; vertical text output
+       ldx     X1+1
+       ldy     Y1
+       sta     r11L
+       stx     r11H
+       sty     r1H
+       ldy     #0
+       lda     (ptr3),y
+       beq     @end
+       jsr     PutChar
+       inc     ptr3
+       bne     @L1
+       inc     ptr3+1
+@L1:   lda     Y1
        clc
-       eor     #$ff
-       adc     #1
-       pha
-       tya
-       eor     #$ff
-       adc     #0
-       tay
-       pla
-@L1:   rts
-
-icmp:
-       ; compare a/y to zp,x
-       sta     TEMP            ; TEMP/TEMP2 - arg2
-       sty     TEMP2
-       lda     $0,x
-       pha
-       lda     $1,x
-       tay
-       pla
-       tax
-       tya                     ; x/a - arg1 (a=high)
-
-       sec
-       sbc     TEMP2
-       bne     @L4
-       cpx     TEMP
-       beq     @L3
-       adc     #$ff
-       ora     #$01
-@L3:   rts
-@L4:   bvc     @L3
-       eor     #$ff
-       ora     #$01
-       rts
+       adc     #8
+       sta     Y1
+       bne     @vertical
+@end:  rts
 
 ;-------------
 ; VDC helpers