+;------------------------------------------------------------------------------
; 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
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);
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 */
+/* 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
--- /dev/null
+#
+# 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)
+
--- /dev/null
+;
+; 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
+
--- /dev/null
+;
+; 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
+
--- /dev/null
+;
+; 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
+
+
+
--- /dev/null
+;
+; 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
+
+
--- /dev/null
+;
+; 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
+
+
--- /dev/null
+;
+; 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
+
+
--- /dev/null
+;
+; 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
+