;*****************************************************************************/
-
+
; 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
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
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
.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
.global tgi_done
.global tgi_control
.global tgi_clear
+ .global tgi_setviewpage
+ .global tgi_setdrawpage
.global tgi_setcolor
.global tgi_setpixel
.global tgi_getpixel
;------------------------------------------------------------------------------
; ASM functions
+ .global tgi_emu_bar
.global tgi_fetch_error
+ .global tgi_getset
+ .global tgi_inv_arg
+ .global tgi_linepop
.global tgi_set_ptr
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).
* 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 */
#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 */
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 */
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 */
/* 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 */
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 \
_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
; 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
--- /dev/null
+;
+; 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
+
.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
--- /dev/null
+;
+; 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
+
+
.include "tgi-error.inc"
.import _tgi_done
+ .import _tgi_setcolor
.export _tgi_init
_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
.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
--- /dev/null
+;
+; 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
+
+
--- /dev/null
+;
+; 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
+
+
.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
-
+
.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
+
+