]> git.sur5r.net Git - cc65/commitdiff
Working on the TGI library
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 22 Jun 2002 21:40:24 +0000 (21:40 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 22 Jun 2002 21:40:24 +0000 (21:40 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1323 b7a2c559-68d2-44c3-8de9-860c34a00d81

16 files changed:
asminc/tgi-error.inc
asminc/tgi-kernel.inc
include/tgi.h
include/tgi/tgi-error.h
include/tgi/tgi-kernel.h
libsrc/tgi/Makefile
libsrc/tgi/tgi-kernel.s
libsrc/tgi/tgi_getcolor.s [new file with mode: 0644]
libsrc/tgi/tgi_getpixel.s
libsrc/tgi/tgi_getset.s [new file with mode: 0644]
libsrc/tgi/tgi_init.s
libsrc/tgi/tgi_line.s
libsrc/tgi/tgi_linepop.s [new file with mode: 0644]
libsrc/tgi/tgi_lineto.s [new file with mode: 0644]
libsrc/tgi/tgi_setcolor.s
libsrc/tgi/tgi_setpixel.s

index e5d461985d1dfc9c7c0fcf987e0f39711172fa8a..530bacb77cdf6a48195a035d070cfa27ff1c5429 100644 (file)
 ;*****************************************************************************/
 
 
-
+                                                            
 ; Error constants
 TGI_ERR_OK              = 0     ; No error
 TGI_ERR_NO_DRIVER       = 1     ; No driver available
 TGI_ERR_LOAD_ERROR      = 2     ; Error loading driver
 TGI_ERR_INV_DRIVER      = 3     ; Invalid driver
 TGI_ERR_INV_MODE        = 4     ; Mode not supported by driver
+TGI_ERR_INV_ARG         = 5     ; Invalid function argument
 
 
 
index 96183bf69f99279f83ba9b50af0af96ea603120f..bd81082e210a0fcd1c86e0c6a47e83540d4bb2d5 100644 (file)
@@ -40,9 +40,10 @@ TGI_HDR_ID              = 0             ; Contains 0x74, 0x67, 0x69 ("tgi")
 TGI_HDR_VERSION         = 3             ; Interface version
 TGI_HDR_XRES            = 4             ; X resolution
 TGI_HDR_YRES            = 6             ; Y resolution
-TGI_HDR_COLORS          = 8             ; Number of available colors
-TGI_HDR_ERROR          = 9             ; Error code
-TGI_HDR_RES             = 10            ; Reserved for extensions
+TGI_HDR_COLORCOUNT      = 8             ; Number of available colors
+TGI_HDR_PAGECOUNT       = 9             ; Number of screens available
+TGI_HDR_ERROR          = 10            ; Error code
+TGI_HDR_RES             = 11            ; Reserved for extensions
 
 TGI_HDR_JUMPTAB         = 16
 TGI_HDR_INSTALL         = TGI_HDR_JUMPTAB+0     ; INSTALL routine
@@ -51,14 +52,16 @@ TGI_HDR_INIT            = TGI_HDR_JUMPTAB+4     ; INIT routine
 TGI_HDR_DONE            = TGI_HDR_JUMPTAB+6     ; DONE routine
 TGI_HDR_CONTROL         = TGI_HDR_JUMPTAB+8     ; CONTROL routine
 TGI_HDR_CLEAR           = TGI_HDR_JUMPTAB+10    ; CLEAR routine
-TGI_HDR_SETCOLOR        = TGI_HDR_JUMPTAB+12    ; SETCOLOR routine
-TGI_HDR_SETPIXEL        = TGI_HDR_JUMPTAB+14    ; SETPIXEL routine
-TGI_HDR_GETPIXEL        = TGI_HDR_JUMPTAB+16    ; GETPIXEL routine
-TGI_HDR_LINE            = TGI_HDR_JUMPTAB+18    ; LINE routine
-TGI_HDR_BAR             = TGI_HDR_JUMPTAB+20    ; BAR routine
-TGI_HDR_CIRCLE          = TGI_HDR_JUMPTAB+22    ; CIRCLE routine
+TGI_HDR_SETVIEWPAGE     = TGI_HDR_JUMPTAB+12    ; SETVIEWPAGE routine
+TGI_HDR_SETDRAWPAGE     = TGI_HDR_JUMPTAB+14    ; SETDRAWPAGE routine
+TGI_HDR_SETCOLOR        = TGI_HDR_JUMPTAB+16    ; SETCOLOR routine
+TGI_HDR_SETPIXEL        = TGI_HDR_JUMPTAB+18    ; SETPIXEL routine
+TGI_HDR_GETPIXEL        = TGI_HDR_JUMPTAB+20    ; GETPIXEL routine
+TGI_HDR_LINE            = TGI_HDR_JUMPTAB+22    ; LINE routine
+TGI_HDR_BAR             = TGI_HDR_JUMPTAB+24    ; BAR routine
+TGI_HDR_CIRCLE          = TGI_HDR_JUMPTAB+26    ; CIRCLE routine
 
-TGI_HDR_JUMPCOUNT       = 12            ; Number of jump vectors
+TGI_HDR_JUMPCOUNT       = 14            ; Number of jump vectors
 
 ;------------------------------------------------------------------------------
 ; Variables
@@ -66,8 +69,14 @@ TGI_HDR_JUMPCOUNT       = 12            ; Number of jump vectors
        .global _tgi_drv                ; Pointer to driver
        .global _tgi_error              ; Last error code
         .global _tgi_mode               ; Graphics mode or zero
+        .global _tgi_curx               ; Current drawing cursor X
+        .global _tgi_cury               ; Current drawing cursor Y
+        .global _tgi_color              ; Current drawing color
+        .global _tgi_bgcolor            ; Current background color
         .global _tgi_xres               ; X resolution of the current mode
-        .global _tgi_yres               ; Y resolution of the current mode 
+        .global _tgi_yres               ; Y resolution of the current mode
+        .global _tgi_colorcount         ; Number of available colors
+        .global _tgi_pagecount          ; Number of available screen pages
 
 ;------------------------------------------------------------------------------
 ; Driver entry points
@@ -78,6 +87,8 @@ TGI_HDR_JUMPCOUNT       = 12            ; Number of jump vectors
         .global tgi_done
         .global tgi_control
         .global tgi_clear
+        .global tgi_setviewpage
+        .global tgi_setdrawpage
         .global tgi_setcolor
         .global tgi_setpixel
         .global tgi_getpixel
@@ -89,6 +100,10 @@ TGI_HDR_JUMPCOUNT       = 12            ; Number of jump vectors
 ;------------------------------------------------------------------------------
 ; ASM functions
 
+        .global tgi_emu_bar
         .global tgi_fetch_error
+        .global tgi_getset
+        .global tgi_inv_arg
+        .global tgi_linepop
         .global tgi_set_ptr
 
index 64db5fcbd4c307277d6e9a69f5516ac27af0139f..da1a87187271dfd62dc80e69d9814df61e143818 100644 (file)
@@ -95,6 +95,12 @@ unsigned char __fastcall__ tgi_geterror (void);
 void __fastcall__ tgi_clear (void);
 /* Clear the screen */
 
+void __fastcall__ tgi_setviewpage (unsigned char page);
+/* Set the visible page. */
+
+void __fastcall__ tgi_setdrawpage (unsigned char page);
+/* Set the drawable page */
+
 unsigned char __fastcall__ tgi_getmaxcolor (void);
 /* Return the maximum supported color number (the number of colors would
  * then be getmaxcolor()+1).
@@ -110,6 +116,9 @@ unsigned __fastcall__ tgi_getmaxy (void);
  * getmaxy() + 1
  */
 
+unsigned char __fastcall__ tgi_getcolorcount (void);
+/* Get the number of available colors */
+
 unsigned __fastcall__ tgi_getxres (void);
 /* Return the resolution in X direction */
 
index 83c92bb51e05393e73447be1e6291739ac0f6e2b..2c6ec151422b9f5fca6c597a6757839981d66537 100644 (file)
@@ -49,6 +49,7 @@
 #define TGI_ERR_CANNOT_LOAD     2       /* Error loading driver */
 #define TGI_ERR_INV_DRIVER      3       /* Invalid driver */
 #define TGI_ERR_INV_MODE        4       /* Mode not supported by driver */
+#define TGI_ERR_INV_ARG         5       /* Invalid function argument */
 
 
 
index 3e11ba94fbf82b692c6410c22d83a84181fcc6c3..ff534737ac1cea9eb42ba80ac7a5f6898242e627 100644 (file)
@@ -54,9 +54,10 @@ typedef struct {
     unsigned char       version;        /* Interface version */
     unsigned            xres;           /* X resolution */
     unsigned            yres;           /* Y resolution */
-    unsigned char       colors;         /* Number of available colors */
-    unsigned char      error;          /* Error code */
-    unsigned char       res[6];         /* Reserved for extensions */
+    unsigned char       colorcount;     /* Number of available colors */
+    unsigned char       pagecount;      /* Number of screens available */
+    unsigned char      error;          /* Error code */
+    unsigned char       res[5];         /* Reserved for extensions */
 
     /* Jump vectors. Note that these are not C callable */
     void*               install;        /* INSTALL routine */
@@ -65,6 +66,8 @@ typedef struct {
     void*               done;           /* DONE routine */
     void*               control;        /* CONTROL routine */
     void*               clear;          /* CLEAR routine */
+    void*               setviewpage;    /* SETVIEWPAGE routine */
+    void*               setdrawpage;    /* SETDRAWPAGE routine */
     void*               setcolor;       /* SETCOLOR routine */
     void*               setpixel;       /* SETPIXEL routine */
     void*               getpixel;       /* GETPIXEL routine */
@@ -77,11 +80,17 @@ typedef struct {
 
 
 /* TGI kernel variables */
-extern tgi_drv_header* tgi_drv;        /* Pointer to driver */
-extern unsigned char   tgi_error;      /* Last error code */
+extern tgi_drv_header* tgi_drv;        /* Pointer to driver */
+extern unsigned char   tgi_error;      /* Last error code */
 extern unsigned char    tgi_mode;       /* Graphics mode or zero */
+extern int              tgi_curx;       /* Current drawing cursor X */
+extern int              tgi_cury;       /* Current drawing cursor Y */
+extern unsigned char    tgi_color;      /* Current drawing color */
+extern unsigned char    tgi_bgcolor;    /* Current background color */
 extern unsigned         tgi_xres;       /* X resolution of the current mode */
 extern unsigned         tgi_yres;       /* Y resolution of the current mode */
+extern unsigned char    tgi_colorcount; /* Number of available colors */
+extern unsigned char    tgi_pagecount;  /* Number of available screens */
 
 
 
index 85fdfa031cf53fb7c647cd306209035c72c2ab4b..6f436fc8793fc13e9805213fbaca3e44144244a9 100644 (file)
@@ -19,16 +19,20 @@ S_OBJS =            tgi-kernel.o            \
                 tgi_clear.o             \
                 tgi_done.o              \
                 tgi_emu_bar.o           \
+                tgi_getcolor.o          \
                 tgi_getcolorcount.o     \
                 tgi_geterror.o          \
                 tgi_getmaxcolor.o       \
                 tgi_getmaxx.o           \
                 tgi_getmaxy.o           \
                 tgi_getpixel.o          \
+                tgi_getset.o            \
                 tgi_getxres.o           \
                 tgi_getyres.o           \
                 tgi_init.o              \
                 tgi_line.o              \
+                tgi_linepop.o           \
+                tgi_lineto.o            \
                        tgi_map_mode.o          \
                 tgi_setcolor.o          \
                 tgi_setdrawpage.o       \
index af448398fe90ddd77c254861407f78551f8f6d6e..2981089328359b2d3bb23ef1af57507ef9a6865c 100644 (file)
 _tgi_drv:      .res    2               ; Pointer to driver
 _tgi_error:    .res    1               ; Last error code
 _tgi_mode:      .res    1               ; Graphics mode or zero
+_tgi_curx:      .res    2               ; Current drawing cursor X
+_tgi_cury:      .res    2               ; Current drawing cursor Y
+_tgi_color:     .res    1               ; Current drawing color
+_tgi_bgcolor:   .res    1               ; Current background color
 _tgi_xres:      .res    2               ; X resolution of the current mode
 _tgi_yres:      .res    2               ; Y resolution of the current mode
-_tgi_colors:    .res    1               ; Number of available colors
+_tgi_colorcount:.res    1               ; Number of available colors
 _tgi_pagecount: .res    1               ; Number of available screen pages
 
 
@@ -95,8 +99,10 @@ _tgi_setup:
 ; Initialize variables
 
         lda     #$00
-        sta     _tgi_error
-        sta     _tgi_mode
+        ldx     #6-1
+@L4:    sta     _tgi_error,x            ; Clear error/mode/curx/cury
+        dex
+        bpl     @L4
 
         jsr     tgi_install             ; Call driver install routine
 
diff --git a/libsrc/tgi/tgi_getcolor.s b/libsrc/tgi/tgi_getcolor.s
new file mode 100644 (file)
index 0000000..32efd55
--- /dev/null
@@ -0,0 +1,15 @@
+;
+; Ullrich von Bassewitz, 22.06.2002
+;
+; unsigned char __fastcall__ tgi_getcolor (void);
+; /* Return the current drawing color */
+
+
+        .include        "tgi-kernel.inc"
+        .export         _tgi_getcolor
+
+_tgi_getcolor:
+        lda     _tgi_color      ; Get the current drawing color
+        ldx     #0              ; Clear high byte
+        rts
+
index 6af67a816c50dd05d39515a0eb2e39f0f0fbd428..b70516732e78405130f99ecfd85ab89c8b05c107 100644 (file)
@@ -7,18 +7,12 @@
 
         .include        "tgi-kernel.inc"
 
-        .import         popax
-        .importzp       ptr1, ptr2
         .export         _tgi_getpixel
 
 _tgi_getpixel:
-        sta     ptr2            ; Get the coordinates
-        stx     ptr2+1
-        jsr     popax
-        sta     ptr1
-        stx     ptr1+1
-
+        jsr     tgi_getset      ; Pop args, check range
+        bcs     @L9
         jmp     tgi_getpixel    ; Call the driver
-
+@L9:    rts
 
 
diff --git a/libsrc/tgi/tgi_getset.s b/libsrc/tgi/tgi_getset.s
new file mode 100644 (file)
index 0000000..1d6353b
--- /dev/null
@@ -0,0 +1,44 @@
+;
+; Ullrich von Bassewitz, 22.06.2002
+;
+; Helper function for getpixel/setpixel. Load X/Y from stack and check if
+; the coordinates are valid. Return carry clear if so.
+;
+
+        .include        "tgi-kernel.inc"
+
+        .import         popax
+        .importzp       ptr1, ptr2
+
+
+tgi_getset:
+        sta     ptr2            ; Y
+        stx     ptr2+1
+        jsr     popax
+        sta     ptr1            ; X
+        stx     ptr1+1
+
+; Are the coordinates are out of range? First check if any ccord is negative.
+
+        txa
+        ora     ptr2+1
+        asl     a
+        bcs     @L9             ; Bail out if negative
+
+; Check if X is larger than the maximum x coord. If so, bail out
+
+        lda     ptr1
+        cmp     _tgi_xres
+        txa
+        sbc     _tgi_xres+1
+        bcs     @L9
+
+; Check if Y is larger than the maximum y coord.
+
+        lda     ptr2
+        cmp     _tgi_yres
+        lda     ptr2+1
+        sbc     _tgi_yres+1
+@L9:    rts
+
+
index e6716b99b6a945dda215edc3be13446f21fd43d1..c0876f0c58cf1836e2a3b28515483bd65b8ee577 100644 (file)
@@ -9,6 +9,7 @@
         .include        "tgi-error.inc"
 
         .import         _tgi_done
+        .import         _tgi_setcolor
         .export         _tgi_init
 
 _tgi_init:
@@ -18,8 +19,13 @@ _tgi_init:
         sta     _tgi_mode               ; Remember the mode
         jsr     tgi_init                ; Go into graphics mode
         jsr     tgi_fetch_error         ; Get the error code
-        beq     @L1                     ; Jump if no error
-        lda     #$00
+        bne     @L1                     ; Jump on error
+        ldx     _tgi_colorcount
+        dex
+        txa
+        jmp     _tgi_setcolor           ; tgi_setcolor (tgi_getmaxcolor ());
+
+@L1:    lda     #$00
         sta     _tgi_mode               ; Clear the mode if init was not successful
-@L1:    rts
+        rts
 
index 3f90ef5a29c9dee0ccdc41d426e122766b3737ad..8a96025468ae7de3d0d75b118515309e11a358d7 100644 (file)
@@ -8,15 +8,12 @@
         .include        "tgi-kernel.inc"
 
         .import         popax
-        .importzp       ptr1, ptr2, ptr3, ptr4
+        .importzp       ptr1, ptr2
         .export         _tgi_line
 
 _tgi_line:
-        sta     ptr4            ; Get the coordinates
-        stx     ptr4+1
-        jsr     popax
-        sta     ptr3
-        stx     ptr3+1
+        jsr     tgi_linepop     ; Pop/store Y2/X2
+
         jsr     popax
         sta     ptr2
         stx     ptr2+1
diff --git a/libsrc/tgi/tgi_linepop.s b/libsrc/tgi/tgi_linepop.s
new file mode 100644 (file)
index 0000000..f0779c5
--- /dev/null
@@ -0,0 +1,24 @@
+;
+; Ullrich von Bassewitz, 22.06.2002
+;
+; Helper function for tgi_line and tgi_lineto. Pops/stores X2/Y2.
+;
+
+        .include        "tgi-kernel.inc"
+
+        .import         popax
+        .importzp       ptr3, ptr4
+
+tgi_linepop:
+        sta     ptr4            ; Y2
+        stx     ptr4+1
+        sta     _tgi_cury
+        stx     _tgi_cury+1
+        jsr     popax
+        sta     ptr3            ; X2
+        stx     ptr3+1
+        sta     _tgi_curx
+        sta     _tgi_curx+1
+        rts
+
+
diff --git a/libsrc/tgi/tgi_lineto.s b/libsrc/tgi/tgi_lineto.s
new file mode 100644 (file)
index 0000000..1add867
--- /dev/null
@@ -0,0 +1,30 @@
+;
+; Ullrich von Bassewitz, 22.06.2002
+;
+; void __fastcall__ tgi_lineto (int x2, int y2);
+; /* Draw a line in the current drawing color from the graphics cursor to the
+;  * new end point.
+;  */
+
+        .include        "tgi-kernel.inc"
+
+        .import         popax
+        .importzp       ptr1, ptr2, ptr3, ptr4
+        .export         _tgi_lineto
+
+_tgi_lineto:
+        ldy     _tgi_curx       ; X1
+        sty     ptr1
+        ldy     _tgi_curx+1
+        sty     ptr1+1
+
+        ldy     _tgi_cury       ; Y1
+        sty     ptr2
+        ldy     _tgi_cury+1
+        sty     ptr2+1
+
+        jsr     tgi_linepop
+
+        jmp     tgi_line        ; Call the driver
+
+
index 0d430f76a0fc255ce1678332c927f43fcbcb8d84..242f07826c8cb2b2d88454b59bb57b5e2c7c25a3 100644 (file)
@@ -6,13 +6,13 @@
 
 
         .include        "tgi-kernel.inc"
-        .include        "tgi-error.inc"
         .export         _tgi_setcolor
 
 _tgi_setcolor:
-        cmp     _tgi_colors     ; Compare to available colors
+        cmp     _tgi_colorcount ; Compare to available colors
         bcs     @L1
+        sta     _tgi_color      ; Remember the drawing color
         jmp     tgi_setcolor    ; Call the driver
 @L1:    jmp     tgi_inv_arg     ; Invalid argument
-    
+
 
index cab5618cd141940bc9c42ca88ab6dad658ac89e4..d72c05dfc23d4d29cfe7d1f2164ad52a248f8f44 100644 (file)
@@ -7,16 +7,13 @@
 
         .include        "tgi-kernel.inc"
 
-        .import         popax
-        .importzp       ptr1, ptr2
         .export         _tgi_setpixel
 
 _tgi_setpixel:
-        sta     ptr2            ; Get the coordinates
-        stx     ptr2+1
-        jsr     popax
-        sta     ptr1
-        stx     ptr1+1
-
+        jsr     tgi_getset      ; Pop args, check range
+        bcs     @L9
         jmp     tgi_setpixel    ; Call the driver
+@L9:    rts
+
+