]> git.sur5r.net Git - cc65/commitdiff
Implementing TGI
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 21 Jun 2002 12:46:52 +0000 (12:46 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 21 Jun 2002 12:46:52 +0000 (12:46 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1311 b7a2c559-68d2-44c3-8de9-860c34a00d81

asminc/tgi-kernel.inc
include/tgi.h
include/tgi/tgi-kernel.h
libsrc/tgi/Makefile [new file with mode: 0644]
libsrc/tgi/tgi-kernel.s [new file with mode: 0644]
libsrc/tgi/tgi_geterror.s [new file with mode: 0644]
libsrc/tgi/tgi_getmaxx.s [new file with mode: 0644]
libsrc/tgi/tgi_getmaxy.s [new file with mode: 0644]
libsrc/tgi/tgi_getxres.s [new file with mode: 0644]
libsrc/tgi/tgi_getyres.s [new file with mode: 0644]
libsrc/tgi/tgi_map_mode.s [new file with mode: 0644]

index a6ecc7867eb5b0017bb43ad7b1677e2e0eaeb8be..c8a7667e8d58b74f12deff8d22e16cbd8b15d055 100644 (file)
 
 
 
+;------------------------------------------------------------------------------
 ; Offsets into the driver header
+
 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_RES             = 9             ; Reserved for extensions
-
-TGI_HDR_INSTALL         = 16            ; INSTALL routine
-TGI_HDR_DEINSTALL       = 18            ; DEINSTALL routine
-TGI_HDR_INIT            = 20            ; INIT routine
-TGI_HDR_POST            = 22            ; POST routine
-TGI_HDR_CONTROL         = 24            ; CONTROL routine
-TGI_HDR_CLEAR           = 26            ; CLEAR routine
-TGI_HDR_SETCOLOR        = 28            ; SETCOLOR routine
-TGI_HDR_SETPIXEL        = 30            ; SETPIXEL routine
-TGI_HDR_GETPIXEL        = 32            ; GETPIXEL routine
-TGI_HDR_LINE            = 34            ; LINE routine
-TGI_HDR_BAR             = 36            ; BAR routine
-TGI_HDR_CIRCLE          = 38            ; CIRCLE routine
+TGI_HDR_ERROR          = 9             ; Error code
+TGI_HDR_RES             = 10            ; Reserved for extensions
+
+TGI_HDR_JUMPTAB         = 16
+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_POST            = TGI_HDR_JUMPTAB+6     ; POST 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_JUMPCOUNT       = 12            ; Number of jump vectors
+
+;------------------------------------------------------------------------------
+; Variables
+
+       .global _tgi_drv                ; Pointer to driver
+       .global _tgi_error              ; Last error code
+
+;------------------------------------------------------------------------------
+; Driver entry points
+
+        .global tgi_install
+        .global tgi_deinstall
+        .global tgi_init
+        .global tgi_post
+        .global tgi_control
+        .global tgi_clear
+        .global tgi_setcolor
+        .global tgi_setpixel
+        .global tgi_getpixel
+        .global tgi_line
+        .global tgi_bar
+        .global tgi_circle
+
+
+;------------------------------------------------------------------------------
+; ASM functions
 
+        .global tgi_fetch_error
+        .global tgi_set_ptr
+        .global tgi_setup
 
index 1e1da43a6a4ba3299bb27b2fb55c1a376d44cf08..cd03890472eda80b24a69f035b75133a6dcbc2f3 100644 (file)
@@ -87,7 +87,7 @@ void __fastcall__ tgi_init (unsigned char mode);
 void __fastcall__ tgi_done (void);
 /* End graphics mode, switch back to text mode. Will NOT unload the driver! */
 
-unsigned char __fastcall__ tgi_error (void);
+unsigned char __fastcall__ tgi_geterror (void);
 /* Return the error code for the last operation. */
 
 void __fastcall__ tgi_clear (void);
index 3e6ae76be128a4adda5f743388b576242c6b2bfe..384537d54a3ed98c52e94b46af2edfa6a50a8154 100644 (file)
@@ -55,7 +55,8 @@ typedef struct {
     unsigned            xres;           /* X resolution */
     unsigned            yres;           /* Y resolution */
     unsigned char       colors;         /* Number of available colors */
-    unsigned char       res[7];         /* Reserved for extensions */
+    unsigned char      error;          /* Error code */
+    unsigned char       res[6];         /* Reserved for extensions */
 
     /* Jump vectors. Note that these are not C callable */
     void*               install;        /* INSTALL routine */
@@ -75,6 +76,23 @@ typedef struct {
 
 
 
+/* TGI kernel variables */
+extern tgi_drv_header  tgi_drv;        /* Pointer to driver */
+extern unsigned char   tgi_error;      /* Last error code */
+
+
+
+/*****************************************************************************/
+/*                                     Code                                  */
+/*****************************************************************************/
+
+
+
+const char* __fastcall__ tgi_map_mode (unsigned char mode);
+/* Map a tgi mode to a driver name. Returns NULL if no driver available. */
+
+
+
 /* End of tgi-kernel.h */
 #endif
 
diff --git a/libsrc/tgi/Makefile b/libsrc/tgi/Makefile
new file mode 100644 (file)
index 0000000..4e2168c
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# makefile for the TGI graphics kernel
+#
+
+.SUFFIXES: .o .s .c
+
+%.o:           %.c
+       @$(CC) $(CFLAGS) $<
+       @$(AS) -g -o $@ $(AFLAGS) $(*).s
+
+%.o:   %.s
+       @$(AS) -g -o $@ $(AFLAGS) $<
+
+C_OBJS =
+
+S_OBJS =       tgi-kernel.o    \
+                tgi_geterror.o  \
+                tgi_getmaxx.o   \
+                tgi_getmaxy.o   \
+                tgi_getxres.o   \
+                tgi_getyres.o   \
+               tgi_map_mode.o
+
+
+all:   $(C_OBJS) $(S_OBJS)
+
+clean:
+       @rm -f *~
+       @rm -f $(C_OBJS:.o=.s)
+       @rm -f $(C_OBJS)
+       @rm -f $(S_OBJS)
+
diff --git a/libsrc/tgi/tgi-kernel.s b/libsrc/tgi/tgi-kernel.s
new file mode 100644 (file)
index 0000000..c15737e
--- /dev/null
@@ -0,0 +1,85 @@
+;
+; Ullrich von Bassewitz, 21.06.2002
+;
+; Common functions of the tgi graphics kernel.
+;
+
+        .include        "tgi-kernel.inc"
+
+;----------------------------------------------------------------------------
+; Variables
+
+.bss
+
+_tgi_drv:      .res    2               ; Pointer to driver
+_tgi_error:    .res    1               ; Last error code
+
+
+.data
+
+; Jump table for the driver functions.
+
+tgi_install:   jmp     $0000
+tgi_deinstall: jmp     $0000
+tgi_init:       jmp    $0000
+tgi_post:       jmp    $0000
+tgi_control:    jmp    $0000
+tgi_clear:      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
+
+
+;----------------------------------------------------------------------------
+; Setup the TGI driver once it is loaded.
+
+tgi_setup:
+       lda     _tgi_drv
+       sta     ptr1
+       lda     _tgi_drv+1
+       sta     ptr1+1
+
+        ldy     #TGI_HDR_JUMPTAB
+        ldx     #1
+
+@L1:    lda     (ptr1),y
+        sta     tgi_install,x
+        iny
+        inx
+        lda     (ptr1),y
+        sta     tgi_install,x
+        inx
+        cpx     #(TGI_HDR_JMPCOUNT*3)
+        bne     @L1
+
+        lda     #$00
+        sta     _tgi_error
+
+        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.
+
+tgi_fetch_error:
+        jsr     tgi_set_ptr
+       ldy     #TGI_HDR_ERROR
+       lda     (ptr1),y
+       sta     _tgi_error
+       rts
+
+;----------------------------------------------------------------------------
+; Load the pointer to the tgi driver into ptr1.
+
+tgi_set_ptr:
+       lda     _tgi_drv
+       sta     ptr1
+       lda     _tgi_drv+1
+       sta     ptr1+1
+        rts
+
diff --git a/libsrc/tgi/tgi_geterror.s b/libsrc/tgi/tgi_geterror.s
new file mode 100644 (file)
index 0000000..b559570
--- /dev/null
@@ -0,0 +1,13 @@
+;
+; Ullrich von Bassewitz, 21.06.2002
+;
+; unsigned char __fastcall__ tgi_geterror (void);
+; /* Return the error code for the last operation. */
+
+        .include        "tgi-kernel.inc"
+
+
+_tgi_geterror:
+        lda     _tgi_error
+        rts
+
diff --git a/libsrc/tgi/tgi_getmaxx.s b/libsrc/tgi/tgi_getmaxx.s
new file mode 100644 (file)
index 0000000..bbfa3d6
--- /dev/null
@@ -0,0 +1,20 @@
+;
+; Ullrich von Bassewitz, 21.06.2002
+;
+; unsigned __fastcall__ tgi_getmaxx (void);
+; /* Return the maximum x coordinate. The resolution in x direction is
+;  * getmaxx() + 1
+;  */
+
+        .include        "tgi-kernel.inc"
+        .export         _tgi_getmaxx
+        .import         _tgi_getxres
+        .import         decax1
+
+
+_tgi_getmaxx:
+        jsr     _tgi_getxres
+        jmp     decax1
+
+
+
diff --git a/libsrc/tgi/tgi_getmaxy.s b/libsrc/tgi/tgi_getmaxy.s
new file mode 100644 (file)
index 0000000..23e55ba
--- /dev/null
@@ -0,0 +1,19 @@
+;
+; Ullrich von Bassewitz, 21.06.2002
+;
+; unsigned __fastcall__ tgi_getmaxy (void);
+; /* Return the maximum y coordinate. The resolution in y direction is
+;  * getmaxy() + 1
+;  */
+
+        .include        "tgi-kernel.inc"
+        .export         _tgi_getmaxy
+        .import         _tgi_getyres
+        .import         decax
+
+
+_tgi_getmaxy:
+        jsr     _tgi_getyres
+        jmp     decax1
+
+
diff --git a/libsrc/tgi/tgi_getxres.s b/libsrc/tgi/tgi_getxres.s
new file mode 100644 (file)
index 0000000..0bb58fe
--- /dev/null
@@ -0,0 +1,19 @@
+;
+; Ullrich von Bassewitz, 21.06.2002
+;
+; unsigned __fastcall__ tgi_getxres (void);
+; /* Return the resolution in X direction */
+
+
+        .include        "tgi-kernel.inc"
+        .export         _tgi_getxres
+        .import         ldaxidx
+
+
+_tgi_getxres:
+        lda     _tgi_drv
+        ldx     _tgi_drv+1
+        ldy     #TGI_HDR_XRES+1
+        jmp     ldaxidx
+
+
diff --git a/libsrc/tgi/tgi_getyres.s b/libsrc/tgi/tgi_getyres.s
new file mode 100644 (file)
index 0000000..4b8b26d
--- /dev/null
@@ -0,0 +1,19 @@
+;
+; Ullrich von Bassewitz, 21.06.2002
+;
+; unsigned __fastcall__ tgi_getyres (void);
+; /* Return the resolution in Y direction */
+
+
+        .include        "tgi-kernel.inc"
+        .export         _tgi_getyres
+        .import         ldaxidx
+
+
+_tgi_getyres:
+        lda     _tgi_drv
+        ldx     _tgi_drv+1
+        ldy     #TGI_HDR_YRES+1
+        jmp     ldaxidx
+
+
diff --git a/libsrc/tgi/tgi_map_mode.s b/libsrc/tgi/tgi_map_mode.s
new file mode 100644 (file)
index 0000000..3e1fa11
--- /dev/null
@@ -0,0 +1,48 @@
+;
+; Ullrich von Bassewitz, 31.05.2002
+;
+; const char* __fastcall__ tgi_map_mode (unsigned char mode);
+; /* Map tgi mode codes to driver names */
+;
+
+       .export         _tgi_map_mode
+        .import         _tgi_mode_table
+        .import         return0
+        .importzp       tmp1
+
+;----------------------------------------------------------------------------
+; BEWARE: The current implementation of tgi_map_mode does not work with tables
+; larger that 255 bytes!
+
+.code
+
+_tgi_map_mode:
+        sta     tmp1                    ; Save mode
+        ldy     #$00
+
+@L0:    lda     _tgi_mode_table,y
+        beq     NotFound                ; Branch if mode code zero
+        cmp     tmp1
+        beq     Found
+
+; Skip the name
+
+@L1:    iny
+        lda     _tgi_mode_table,y
+        bne     @L1                     ; Loop until end marker found
+        iny                             ; Skip end marker
+        bne     @L0                     ; Branch always
+
+; Mode not found
+
+NotFound:
+        jmp     return0
+
+; Mode found
+
+Found:  tya
+        ldx     #>_tgi_mode_table
+        sec                             ; Account for the mode byte
+        adc     #<_tgi_mode_table       ; Return pointer to file name
+        rts
+