;*****************************************************************************/
-
+
; Error constants
TGI_ERR_OK = 0 ; No error
TGI_ERR_NO_DRIVER = 1 ; No driver available
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
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
.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
; ASM functions
.global tgi_emu_bar
- .global tgi_fetch_error
.global tgi_getset
.global tgi_inv_arg
.global tgi_linepop
-/*****************************************************************************/
-/* Data */
-/*****************************************************************************/
-
-
-
-struct palettetype {
- unsigned char r; /* Red component */
- unsigned char g; /* Green component */
- unsigned char b; /* Blue component */
-};
-
-
-
/*****************************************************************************/
/* Functions */
/*****************************************************************************/
*/
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. */
*/
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. */
#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 */
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 */
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 \
tgi_map_mode.o \
tgi_setcolor.o \
tgi_setdrawpage.o \
+ tgi_setpalette.o \
tgi_setpixel.o \
tgi_setdrawpage.o \
tgi_unload.o
.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
;----------------------------------------------------------------------------
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
; /* End graphics mode, switch back to text mode. Will NOT unload the driver! */
.include "tgi-kernel.inc"
+ .include "tgi-error.inc"
.export _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
_tgi_getcolorcount:
- lda _tgi_colors
+ lda _tgi_colorcount
ldx #0
rts
--- /dev/null
+;
+; 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
+
+
.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
; 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
--- /dev/null
+;
+; 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
+
--- /dev/null
+;
+; 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
+
+
+
.include "tgi-kernel.inc"
.include "tgi-error.inc"
+ .importzp ptr1
.import _tgi_done
.import _tgi_setcolor
.export _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
--- /dev/null
+;
+; 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
+
+