]> git.sur5r.net Git - cc65/commitdiff
More work on the graphics subsystem
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 7 Jul 2002 10:30:31 +0000 (10:30 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 7 Jul 2002 10:30:31 +0000 (10:30 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1334 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_done.s
libsrc/tgi/tgi_getcolorcount.s
libsrc/tgi/tgi_getdefpalette.s [new file with mode: 0644]
libsrc/tgi/tgi_geterror.s
libsrc/tgi/tgi_getmaxcolor.s
libsrc/tgi/tgi_getpagecount.s [new file with mode: 0644]
libsrc/tgi/tgi_getpalette.s [new file with mode: 0644]
libsrc/tgi/tgi_init.s
libsrc/tgi/tgi_setpalette.s [new file with mode: 0644]

index 530bacb77cdf6a48195a035d070cfa27ff1c5429..258c0c24c827b3f39a7827c74a1b4b1dcbdb4be0 100644 (file)
@@ -32,7 +32,7 @@
 ;*****************************************************************************/
 
 
-                                                            
+
 ; Error constants
 TGI_ERR_OK              = 0     ; No error
 TGI_ERR_NO_DRIVER       = 1     ; No driver available
@@ -40,6 +40,6 @@ 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
-
+TGI_ERR_INV_FUNC       = 6     ; Function not supported
 
 
index bed920317a8e121637740e056775c90a677faa33..da96603c2336fa80e8644df7603d46bc38ec0925 100644 (file)
@@ -50,18 +50,22 @@ TGI_HDR_INSTALL         = TGI_HDR_JUMPTAB+0     ; INSTALL routine
 TGI_HDR_DEINSTALL       = TGI_HDR_JUMPTAB+2     ; DEINSTALL routine
 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_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_GETERROR       = TGI_HDR_JUMPTAB+8     ; GETERROR routine
+TGI_HDR_CONTROL         = TGI_HDR_JUMPTAB+10    ; CONTROL routine
+TGI_HDR_CLEAR           = TGI_HDR_JUMPTAB+12    ; CLEAR routine
+TGI_HDR_SETVIEWPAGE     = TGI_HDR_JUMPTAB+14    ; SETVIEWPAGE routine
+TGI_HDR_SETDRAWPAGE     = TGI_HDR_JUMPTAB+16    ; SETDRAWPAGE routine
+TGI_HDR_SETCOLOR        = TGI_HDR_JUMPTAB+18    ; SETCOLOR routine
+TGI_HDR_SETPALETTE      = TGI_HDR_JUMPTAB+20    ; SETPALETTE routine
+TGI_HDR_GETPALETTE      = TGI_HDR_JUMPTAB+22    ; GETPALETTE routine
+TGI_HDR_GETDEFPALETTE   = TGI_HDR_JUMPTAB+24    ; GETDEFPALETTE routine
+TGI_HDR_SETPIXEL        = TGI_HDR_JUMPTAB+26    ; SETPIXEL routine
+TGI_HDR_GETPIXEL        = TGI_HDR_JUMPTAB+28    ; GETPIXEL routine
+TGI_HDR_LINE            = TGI_HDR_JUMPTAB+30    ; LINE routine
+TGI_HDR_BAR             = TGI_HDR_JUMPTAB+32    ; BAR routine
+TGI_HDR_CIRCLE          = TGI_HDR_JUMPTAB+34    ; CIRCLE routine
 
-TGI_HDR_JUMPCOUNT       = 14            ; Number of jump vectors
+TGI_HDR_JUMPCOUNT       = 18            ; Number of jump vectors
 
 ;------------------------------------------------------------------------------
 ; Variables
@@ -84,11 +88,15 @@ TGI_HDR_JUMPCOUNT       = 14            ; Number of jump vectors
         .global tgi_deinstall
         .global tgi_init
         .global tgi_done
+       .global tgi_geterror
         .global tgi_control
         .global tgi_clear
         .global tgi_setviewpage
         .global tgi_setdrawpage
         .global tgi_setcolor
+        .global tgi_setpalette
+        .global tgi_getpalette
+        .global tgi_getdefpalette
         .global tgi_setpixel
         .global tgi_getpixel
         .global tgi_line
@@ -100,7 +108,6 @@ TGI_HDR_JUMPCOUNT       = 14            ; Number of jump vectors
 ; ASM functions
 
         .global tgi_emu_bar
-        .global tgi_fetch_error
         .global tgi_getset
         .global tgi_inv_arg
         .global tgi_linepop
index f69d453f1bce88945934f1b80091d9b310c23c49..fe3fdb9a5a37237e29d2094404ddf24103b83d47 100644 (file)
 
 
 
-/*****************************************************************************/
-/*                                  Data                                    */
-/*****************************************************************************/
-
-
-
-struct palettetype {
-    unsigned char   r;          /* Red component */
-    unsigned char   g;          /* Green component */
-    unsigned char   b;          /* Blue component */
-};
-
-
-
 /*****************************************************************************/
 /*                                Functions                                 */
 /*****************************************************************************/
@@ -79,7 +65,7 @@ void __fastcall__ tgi_load_driver (const char* name);
  */
 
 void __fastcall__ tgi_unload (void);
-/* Unload the currently loaded driver. */
+/* Unload the currently loaded driver. Will call tgi_done if necessary. */
 
 void __fastcall__ tgi_init (unsigned char mode);
 /* Initialize the given graphics mode. */
@@ -93,49 +79,67 @@ unsigned char __fastcall__ tgi_geterror (void);
  */
 
 void __fastcall__ tgi_clear (void);
-/* Clear the screen */
+/* Clear the screen. */
+
+void __fastcall__ tgi_getpagecount (void);
+/* Returns the number of screen pages available. */
 
 void __fastcall__ tgi_setviewpage (unsigned char page);
-/* Set the visible page. */
+/* Set the visible page. Will set an error if the page is not available. */
 
 void __fastcall__ tgi_setdrawpage (unsigned char page);
-/* Set the drawable page */
+/* Set the drawable page. Will set an error if the page is not available. */
+
+unsigned char __fastcall__ tgi_getcolorcount (void);
+/* Get the number of available colors. */
 
 unsigned char __fastcall__ tgi_getmaxcolor (void);
 /* Return the maximum supported color number (the number of colors would
  * then be getmaxcolor()+1).
  */
 
-unsigned __fastcall__ tgi_getmaxx (void);
-/* Return the maximum x coordinate. The resolution in x direction is
- * getmaxx() + 1
+void __fastcall__ tgi_setcolor (unsigned char color);
+/* Set the current drawing color. */
+
+unsigned char __fastcall__ tgi_getcolor (void);
+/* Return the current drawing color. */
+
+void __fastcall__ tgi_setpalette (const unsigned char* palette);
+/* Set the palette (not available with all drivers/hardware). palette is
+ * a pointer to as many entries as there are colors.
  */
 
-unsigned __fastcall__ tgi_getmaxy (void);
-/* Return the maximum y coordinate. The resolution in y direction is
- * getmaxy() + 1
+const unsigned char* __fastcall__ tgi_getpalette (void);
+/* Return the current palette. Will return NULL for drivers that do not
+ * support palettes.
  */
 
-unsigned char __fastcall__ tgi_getcolorcount (void);
-/* Get the number of available colors */
+const unsigned char* __fastcall__ tgi_getdefpalette (void);
+/* Return the default palette. Will return NULL for drivers that do not
+ * support palettes.
+ */
 
 unsigned __fastcall__ tgi_getxres (void);
-/* Return the resolution in X direction */
+/* Return the resolution in X direction. */
 
-unsigned __fastcall__ tgi_getyres (void);
-/* Return the resolution in Y direction */
+unsigned __fastcall__ tgi_getmaxx (void);
+/* Return the maximum x coordinate. The resolution in x direction is
+ * getmaxx() + 1
+ */
 
-void __fastcall__ tgi_setcolor (unsigned char color);
-/* Set the current drawing color */
+unsigned __fastcall__ tgi_getyres (void);
+/* Return the resolution in Y direction. */
 
-unsigned char __fastcall__ tgi_getcolor (void);
-/* Return the current drawing color */
+unsigned __fastcall__ tgi_getmaxy (void);
+/* Return the maximum y coordinate. The resolution in y direction is
+ * getmaxy() + 1
+ */
 
 unsigned char __fastcall__ tgi_getpixel (int x, int y);
-/* Get the color value of a pixel */
+/* Get the color value of a pixel. */
 
 void __fastcall__ tgi_setpixel (int x, int y);
-/* Plot a point in the current drawing color */
+/* Plot a pixel in the current drawing color. */
 
 void __fastcall__ tgi_gotoxy (int x, int y);
 /* Set the graphics cursor to the given position. */
index 2c6ec151422b9f5fca6c597a6757839981d66537..25365a4d39312827407c6f95a620e5a1e41366b9 100644 (file)
@@ -50,6 +50,7 @@
 #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 */
+#define TGI_ERR_INV_FUNC       6       /* Function not supported */
 
 
 
index bf83d49aa5860772baa20c0b8bb63e1551ec3d2e..de9f6041a7c4bf3593124c17a885b913fcda5caa 100644 (file)
@@ -64,11 +64,15 @@ typedef struct {
     void*               deinstall;      /* DEINSTALL routine */
     void*               init;           /* INIT routine */
     void*               done;           /* DONE routine */
+    void*              geterror;       /* GETERROR routine */
     void*               control;        /* CONTROL routine */
     void*               clear;          /* CLEAR routine */
     void*               setviewpage;    /* SETVIEWPAGE routine */
     void*               setdrawpage;    /* SETDRAWPAGE routine */
     void*               setcolor;       /* SETCOLOR routine */
+    void*               setpalette;     /* SETPALETTE routine */
+    void*               getpalette;     /* GETPALETTE routine */
+    void*               getdefpalette;  /* GETDEFPALETTE routine */
     void*               setpixel;       /* SETPIXEL routine */
     void*               getpixel;       /* GETPIXEL routine */
     void*               line;           /* LINE routine */
index df324661e3a32dde17f0a517c1701315a0e6bf65..8639852990de3a7b817769b65ee98db744347810 100644 (file)
@@ -21,10 +21,13 @@ S_OBJS =            tgi-kernel.o            \
                 tgi_emu_bar.o           \
                 tgi_getcolor.o          \
                 tgi_getcolorcount.o     \
+                tgi_getdefpalette.o     \
                 tgi_geterror.o          \
                 tgi_getmaxcolor.o       \
                 tgi_getmaxx.o           \
                 tgi_getmaxy.o           \
+                tgi_getpagecount.o      \
+                tgi_getpalette.o        \
                 tgi_getpixel.o          \
                 tgi_getset.o            \
                 tgi_getxres.o           \
@@ -37,6 +40,7 @@ S_OBJS =              tgi-kernel.o            \
                        tgi_map_mode.o          \
                 tgi_setcolor.o          \
                 tgi_setdrawpage.o       \
+                tgi_setpalette.o        \
                 tgi_setpixel.o          \
                 tgi_setdrawpage.o       \
                 tgi_unload.o
index c2be3d473188271fdbc2ed7e59d5b41f37952743..80592faa54be7cdc3235a7f74035eb76a26d8d18 100644 (file)
 
 .bss
 
-_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_xres:      .res    2               ; X resolution of the current mode
-_tgi_yres:      .res    2               ; Y resolution of the current mode
-_tgi_colorcount:.res    1               ; Number of available colors
-_tgi_pagecount: .res    1               ; Number of available screen pages
+_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_xres:          .res    2           ; X resolution of the current mode
+_tgi_yres:          .res    2           ; Y resolution of the current mode
+_tgi_colorcount:    .res    1           ; Number of available colors
+_tgi_pagecount:     .res    1           ; Number of available screen pages
 
 
 .data
 
 ; Jump table for the driver functions.
 
-tgi_install:   jmp     $0000
-tgi_deinstall: jmp     $0000
-tgi_init:       jmp    $0000
-tgi_done:       jmp    $0000
-tgi_control:    jmp    $0000
-tgi_clear:      jmp     $0000
-tgi_setviewpage:jmp     $0000
-tgi_setdrawpage:jmp     $0000
-tgi_setcolor:   jmp     $0000
-tgi_setpixel:   jmp     $0000
-tgi_getpixel:   jmp     $0000
-tgi_line:       jmp     $0000
-tgi_bar:        jmp     $0000
-tgi_circle:     jmp     $0000
+tgi_install:               jmp     $0000
+tgi_deinstall:             jmp     $0000
+tgi_init:           jmp     $0000
+tgi_done:           jmp     $0000
+tgi_geterror:      jmp     $0000
+tgi_control:        jmp     $0000
+tgi_clear:          jmp     $0000
+tgi_setviewpage:    jmp     $0000
+tgi_setdrawpage:    jmp     $0000
+tgi_setcolor:       jmp     $0000
+tgi_setpalette:     jmp     $0000
+tgi_getpalette:     jmp     $0000
+tgi_getdefpalette:  jmp     $0000
+tgi_setpixel:       jmp     $0000
+tgi_getpixel:       jmp     $0000
+tgi_line:           jmp     $0000
+tgi_bar:            jmp     $0000
+tgi_circle:         jmp     $0000
 
 
 ;----------------------------------------------------------------------------
@@ -103,27 +107,13 @@ _tgi_setup:
         dex
         bpl     @L4
 
-        jsr     tgi_install             ; Call driver install routine
-
-;       jmp     tgi_fetch_error
-
-;----------------------------------------------------------------------------
-; Fetch the error code from the driver and place it into the global error
-; variable. The function will also return the error in A and the flags from
-; loading the error code are set.
-
-tgi_fetch_error:
-        jsr     tgi_set_ptr
-       ldy     #TGI_HDR_ERROR
-       lda     (ptr1),y
-       sta     _tgi_error
-       rts
+        jmp     tgi_install             ; Call driver install routine
 
 ;----------------------------------------------------------------------------
 ; Load the pointer to the tgi driver into ptr1.
 
 tgi_set_ptr:
-       lda     _tgi_drv
+               lda     _tgi_drv
        sta     ptr1
        lda     _tgi_drv+1
        sta     ptr1+1
index 463e93b799d0887ad8a9660b3dbae3ab40d07606..e3abf53fde2a9887f41a8d9fe719cd524af39b04 100644 (file)
@@ -5,6 +5,7 @@
 ; /* End graphics mode, switch back to text mode. Will NOT unload the driver! */
 
         .include        "tgi-kernel.inc"
+        .include        "tgi-error.inc"
 
         .export         _tgi_done
 
@@ -12,7 +13,9 @@ _tgi_done:
         lda     _tgi_mode               ; Is a graphics mode active?
         beq     @L1                     ; Jump if not
         jsr     tgi_done                ; Call the driver routine
-        jsr     tgi_fetch_error         ; Get the error code
+        jsr     tgi_geterror            ; Get the error code
+        sta     _tgi_error              ; Save it for reference
+        cmp     #TGI_ERR_OK
         bne     @L1                     ; Jump if we had an error
         sta     _tgi_mode               ; Reset the current mode (A = 0)
 @L1:    rts
index 8059e2d3bea318f4e8e20046294de647b5b5e468..0661a43f0288a3a5d0f61b53ed9e7ef646f72c1e 100644 (file)
@@ -9,7 +9,7 @@
 
 
 _tgi_getcolorcount:
-        lda     _tgi_colors
+        lda     _tgi_colorcount
         ldx     #0
         rts
 
diff --git a/libsrc/tgi/tgi_getdefpalette.s b/libsrc/tgi/tgi_getdefpalette.s
new file mode 100644 (file)
index 0000000..f1bf1c9
--- /dev/null
@@ -0,0 +1,15 @@
+;
+; Ullrich von Bassewitz, 23.06.2002
+;
+; const unsigned char* __fastcall__ tgi_getdefpalette (void);
+; /* Return the default palette. Will return NULL for drivers that do not
+;  * support palettes.
+;  */
+;
+
+        .include        "tgi-kernel.inc"
+        .export         _tgi_getdefpalette
+
+_tgi_getdefpalette      =       tgi_getdefpalette       ; Call the driver
+
+
index e291cf87999b511058abd8ffcc311dd2974e63d6..0aa12e17c187cc794687ee01a3d8c8481dd17ec9 100644 (file)
         .export         _tgi_geterror
 
 _tgi_geterror:
-        ldx     #0
-        lda     _tgi_error
-        stx     _tgi_error
-        rts
+        jsr     tgi_geterror            ; First call driver
+        ldx     #$00                    ; Clear high byte
+        ldy     _tgi_error              ; Test high level error code
+        beq     @L1                     ; Branch if no high level error code
+        tya                             ; Use high level code if we have one
+        stx     _tgi_error              ; Clear high level error code
+@L1:    rts
 
index dda4fb2439c4677a9d90e374ccfc6cc06a28ccef..67931192041de49d4ad19f72142ebb7c051cda5c 100644 (file)
@@ -4,14 +4,15 @@
 ; unsigned char __fastcall__ tgi_getmaxcolor (void);
 ; /* Return the maximum supported color number (the number of colors would
 ;  * then be getmaxcolor()+1).
-;  */
+;  */                          
+;
 
         .include        "tgi-kernel.inc"
         .export         _tgi_getmaxcolor
 
 
 _tgi_getmaxcolor:
-        ldx     _tgi_colors
+        ldx     _tgi_colorcount
         dex
         txa
         ldx     #0
diff --git a/libsrc/tgi/tgi_getpagecount.s b/libsrc/tgi/tgi_getpagecount.s
new file mode 100644 (file)
index 0000000..de59e9b
--- /dev/null
@@ -0,0 +1,16 @@
+;
+; Ullrich von Bassewitz, 23.06.2002
+;
+; void __fastcall__ tgi_getpagecount (void);
+; /* Returns the number of screen pages available. */
+;
+
+        .include        "tgi-kernel.inc"
+        .export         _tgi_getpagecount
+
+
+_tgi_getpagecount:
+        lda     _tgi_pagecount
+        ldx     #0
+        rts
+
diff --git a/libsrc/tgi/tgi_getpalette.s b/libsrc/tgi/tgi_getpalette.s
new file mode 100644 (file)
index 0000000..46eaa30
--- /dev/null
@@ -0,0 +1,17 @@
+;
+; Ullrich von Bassewitz, 23.06.2002
+;
+; const unsigned char* __fastcall__ tgi_getpalette (void);
+; /* Return the current palette. Will return NULL for drivers that do not
+;  * support palettes.
+;  */
+;
+
+        .include        "tgi-kernel.inc"
+        .export         _tgi_getpalette
+
+
+_tgi_getpalette         =       tgi_getpalette          ; Call the driver
+
+
+
index c0876f0c58cf1836e2a3b28515483bd65b8ee577..68254785b7e2ee46778175c269e75c1b998ad502 100644 (file)
@@ -8,6 +8,7 @@
         .include        "tgi-kernel.inc"
         .include        "tgi-error.inc"
 
+        .importzp       ptr1
         .import         _tgi_done
         .import         _tgi_setcolor
         .export         _tgi_init
@@ -18,14 +19,34 @@ _tgi_init:
         pla
         sta     _tgi_mode               ; Remember the mode
         jsr     tgi_init                ; Go into graphics mode
-        jsr     tgi_fetch_error         ; Get the error code
-        bne     @L1                     ; Jump on error
-        ldx     _tgi_colorcount
+        jsr     tgi_geterror            ; Get the error code
+        sta     _tgi_error              ; Save for later reference
+        cmp     #TGI_ERR_OK
+        bne     @L9                     ; Jump on error
+
+; Do driver initialization. First set the default palette.
+
+        jsr     tgi_getdefpalette       ; Get the default palette into A/X
+        sta     ptr1
+        stx     ptr1+1
+        ora     ptr1+1                  ; Do we have a default palette?
+        beq     @L1                     ; Jump if no
+        jsr     tgi_setpalette          ; Set the default palette
+
+; Set the drawing color to the maximum color
+
+@L1:    ldx     _tgi_colorcount
         dex
         txa
-        jmp     _tgi_setcolor           ; tgi_setcolor (tgi_getmaxcolor ());
+        jsr     _tgi_setcolor           ; tgi_setcolor (tgi_getmaxcolor ());
+
+; Clear the screen
+
+        jmp     tgi_clear
+
+; Error exit
 
-@L1:    lda     #$00
+@L9:    lda     #$00
         sta     _tgi_mode               ; Clear the mode if init was not successful
         rts
 
diff --git a/libsrc/tgi/tgi_setpalette.s b/libsrc/tgi/tgi_setpalette.s
new file mode 100644 (file)
index 0000000..baa572b
--- /dev/null
@@ -0,0 +1,21 @@
+;
+; Ullrich von Bassewitz, 23.06.2002
+;
+; void __fastcall__ tgi_setpalette (const unsigned char* palette);
+; /* Set the palette (not available with all drivers/hardware). palette is
+;  * a pointer to as many entries as there are colors.
+;  */
+;
+
+        .include        "tgi-kernel.inc"
+
+        .importzp       ptr1
+        .export         _tgi_setpalette
+
+
+_tgi_setpalette:
+        sta     ptr1
+        stx     ptr1+1
+        jmp     tgi_setpalette          ; Call the driver
+
+