;* */
;* */
;* */
-;* (C) 2002 Ullrich von Bassewitz */
-;* Wacholderweg 14 */
-;* D-70597 Stuttgart */
-;* EMail: uz@musoftware.de */
+;* (C) 2002-2003 Ullrich von Bassewitz */
+;* Römerstrasse 52 */
+;* D-70794 Filderstadt */
+;* EMail: uz@cc65.org */
;* */
;* */
;* This software is provided 'as-is', without any expressed or implied */
TGI_HDR_JUMPTAB = 16
TGI_HDR_INSTALL = TGI_HDR_JUMPTAB+0 ; INSTALL routine
-TGI_HDR_DEINSTALL = TGI_HDR_JUMPTAB+2 ; DEINSTALL routine
+TGI_HDR_UNINSTALL = TGI_HDR_JUMPTAB+2 ; UNINSTALL routine
TGI_HDR_INIT = TGI_HDR_JUMPTAB+4 ; INIT routine
TGI_HDR_DONE = TGI_HDR_JUMPTAB+6 ; DONE routine
TGI_HDR_GETERROR = TGI_HDR_JUMPTAB+8 ; GETERROR routine
; Driver entry points
.global tgi_install
- .global tgi_deinstall
+ .global tgi_uninstall
.global tgi_init
.global tgi_done
.global tgi_geterror
.global tgi_emu_bar
.global tgi_getset
.global tgi_inv_arg
+ .global tgi_inv_drv
.global tgi_linepop
.global tgi_set_ptr
.global tgi_popxy
.global tgi_popxy2
.global tgi_curtoxy
+;------------------------------------------------------------------------------
+; C callable functions
+
+ .global _tgi_load
+ .global _tgi_load_driver
+ .global _tgi_unload
+ .global _tgi_install
+ .global _tgi_uninstall
+ .global _tgi_init
+ .global _tgi_done
+ .global _tgi_geterror
+ .global _tgi_clear
+ .global _tgi_getpagecount
+ .global _tgi_setviewpage
+ .global _tgi_setdrawpage
+ .global _tgi_getcolorcount
+ .global _tgi_getmaxcolor
+ .global _tgi_setcolor
+ .global _tgi_getcolor
+ .global _tgi_setpalette
+ .global _tgi_getpalette
+ .global _tgi_getdefpalette
+ .global _tgi_getxres
+ .global _tgi_getmaxx
+ .global _tgi_getyres
+ .global _tgi_getmaxy
+ .global _tgi_getpixel
+ .global _tgi_setpixel
+ .global _tgi_gotoxy
+ .global _tgi_line
+ .global _tgi_lineto
+ .global _tgi_circle
+ .global _tgi_bar
+ .global _tgi_textstyle
+ .global _tgi_textwidth
+ .global _tgi_textheight
+ .global _tgi_outtext
+ .global _tgi_outtextxy
+
+
/* */
/* */
/* */
-/* (C) 2002 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2002-2003 Ullrich von Bassewitz */
+/* Römerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
void __fastcall__ tgi_load (unsigned char mode);
-/* Install the matching driver for the given mode. Will just load the driver
- * and check if loading was successul. Will not switch to gaphics mode.
+/* Load and install the matching driver for the given mode. Will just load
+ * the driver and check if loading was successul. Will not switch to gaphics
+ * mode.
*/
void __fastcall__ tgi_load_driver (const char* name);
-/* Install the given driver. This function is identical to tgi_load with the
- * only difference that the name of the driver is specified explicitly. You
- * should NOT use this function in most cases, use tgi_load() instead.
+/* Load and install the given driver. This function is identical to tgi_load
+ * with the only difference that the name of the driver is specified
+ * explicitly. You should NOT use this function in most cases, use tgi_load()
+ * instead.
*/
void __fastcall__ tgi_unload (void);
-/* Unload the currently loaded driver. Will call tgi_done if necessary. */
+/* Uninstall, then unload the currently loaded driver. Will call tgi_done if
+ * necessary.
+ */
+
+void __fastcall__ tgi_install (void* driver);
+/* Install an already loaded driver. */
+
+void __fastcall__ tgi_uninstall (void);
+/* Uninstall the currently loaded driver but do not unload it. Will call
+ * tgi_done if necessary.
+ */
void __fastcall__ tgi_init (void);
-/* Initialize the already loaded graphics driver */
+/* Initialize the already loaded graphics driver. */
void __fastcall__ tgi_done (void);
-/* End graphics mode, switch back to text mode. Will NOT unload the driver! */
+/* End graphics mode, switch back to text mode. Will NOT uninstall or unload
+ * the driver!
+ */
unsigned char __fastcall__ tgi_geterror (void);
/* Return the error code for the last operation. This will also clear the
/* */
/* */
/* */
-/* (C) 2002 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2002-2003 Ullrich von Bassewitz */
+/* Römerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* A structure that describes the header of a graphics driver loaded into
* memory.
- */
+ */
typedef struct {
/* Data that describes the capabilities of the driver */
/* Jump vectors. Note that these are not C callable */
void* install; /* INSTALL routine */
- void* deinstall; /* DEINSTALL routine */
+ void* uninstall; /* UNINSTALL routine */
void* init; /* INIT routine */
void* done; /* DONE routine */
void* geterror; /* GETERROR routine */
const char* __fastcall__ tgi_map_mode (unsigned char mode);
/* Map a tgi mode to a driver name. Returns NULL if no driver available. */
-void __fastcall__ tgi_setup (void);
-/* Setup the driver and graphics kernel once the driver is loaded */
-
/* End of tgi-kernel.h */
.include "tgi-kernel.inc"
.include "tgi-error.inc"
- .export _tgi_setup
+ .export tgi_clear_ptr
.importzp ptr1
; Jump table for the driver functions.
tgi_install: jmp $0000
-tgi_deinstall: jmp $0000
+tgi_uninstall: jmp $0000
tgi_init: jmp $0000
tgi_done: jmp $0000
tgi_geterror: jmp $0000
tgi_textstyle: jmp $0000
tgi_outtext: jmp $0000
+; Driver header signature
+.rodata
+tgi_sig: .byte $74, $67, $69, $00 ; "tgi", version
+tgi_sig_len = * - tgi_sig
+
;----------------------------------------------------------------------------
-; void __fastcall__ tgi_setup (void);
-; /* Setup the driver and graphics kernel once the driver is loaded */
+; void __fastcall__ tgi_install (void* driver);
+; /* Install an already loaded driver. */
-copy: lda (ptr1),y
- sta tgi_install,x
- iny
- inx
- rts
+_tgi_install:
+ sta _tgi_drv
+ sta ptr1
+ stx _tgi_drv+1
+ stx ptr1+1
+; Check the driver signature
-_tgi_setup:
- jsr tgi_set_ptr ; load _tgi_drv into ptr1
+ ldy #tgi_sig_len-1
+@L0: lda (ptr1),y
+ cmp tgi_sig,y
+ bne tgi_inv_drv
+ dey
+ bpl @L0
; Copy the jump vectors
rts
-;----------------------------------------------------------------------------
-; Load the pointer to the tgi driver into ptr1.
+; Copy one byte from the jump vectors
-tgi_set_ptr:
- lda _tgi_drv
- sta ptr1
- lda _tgi_drv+1
- sta ptr1+1
+copy: lda (ptr1),y
+ sta tgi_install,x
+ iny
+ inx
rts
;----------------------------------------------------------------------------
sta _tgi_error
rts
+;----------------------------------------------------------------------------
+; Set an invalid driver error
+
+tgi_inv_drv:
+ lda #TGI_ERR_INV_DRIVER
+ 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
+
+;----------------------------------------------------------------------------
+; void __fastcall__ tgi_uninstall (void);
+; /* Uninstall the currently loaded driver but do not unload it. Will call
+; * tgi_done if necessary.
+; */
+
+_tgi_uninstall:
+ jsr _tgi_done ; Switch off graphics
+ jsr tgi_uninstall ; Allow the driver to clean up
+
+; Clear driver pointer and error code
+
+tgi_clear_ptr: ; External entry point
+ lda #$00
+ sta _tgi_drv
+ sta _tgi_drv+1
+ sta _tgi_error
+
+ rts
+
+
.importzp ptr1, ptr2, ptr3, ptr4
.import popax
- .import _tgi_getmaxx, _tgi_getmaxy
- .export _tgi_bar
-_tgi_bar:
+
+.proc _tgi_bar
+
sta ptr4 ; Y2
stx ptr4+1
@L9: rts
-
+.endproc
.import popax
.importzp tmp1
- .export _tgi_circle
-_tgi_circle:
+.proc _tgi_circle
+
sta tmp1 ; Get the coordinates
jsr popax
jsr tgi_popxy ; Pop X/Y into ptr1/ptr2
jmp tgi_circle ; Call the driver
-
+.endproc
.include "tgi-kernel.inc"
- .export _tgi_clear
-
_tgi_clear = tgi_clear ; Call the driver
.include "tgi-kernel.inc"
.include "tgi-error.inc"
- .export _tgi_done
+.proc _tgi_done
-_tgi_done:
lda _tgi_gmode ; Is a graphics mode active?
beq @L1 ; Jump if not
jsr tgi_done ; Call the driver routine
sta _tgi_gmode ; Reset the graph mode flag (A = 0)
@L1: rts
-
+.endproc
.include "tgi-kernel.inc"
.importzp ptr1, ptr2, ptr3, ptr4
- .export tgi_emu_bar
-tgi_emu_bar:
+.proc tgi_emu_bar
+
lda ptr4
sta Y2
lda ptr4+1
@L4: rts
+.endproc
+
;-----------------------------------------------------------------------------
; Data
.include "tgi-kernel.inc"
- .export _tgi_getcolor
-_tgi_getcolor:
+.proc _tgi_getcolor
+
lda _tgi_color ; Get the current drawing color
ldx #0 ; Clear high byte
rts
+.endproc
; /* Get the number of available colors */
.include "tgi-kernel.inc"
- .export _tgi_getcolorcount
+.proc _tgi_getcolorcount
-_tgi_getcolorcount:
lda _tgi_colorcount
ldx #0
rts
+.endproc
+
;
.include "tgi-kernel.inc"
- .export _tgi_getdefpalette
_tgi_getdefpalette = tgi_getdefpalette ; Call the driver
.include "tgi-kernel.inc"
- .export _tgi_geterror
+.proc _tgi_geterror
-_tgi_geterror:
lda _tgi_drv ; Check if we have a driver
ora _tgi_drv+1
beq @L1
stx _tgi_error ; Clear high level error code
@L2: rts
+.endproc
+
; 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
+.proc _tgi_getmaxcolor
-_tgi_getmaxcolor:
ldx _tgi_colorcount
dex
txa
ldx #0
rts
-
+.endproc
; */
.include "tgi-kernel.inc"
- .export _tgi_getmaxx
- .import _tgi_getxres
+
.import decax1
-_tgi_getmaxx:
+.proc _tgi_getmaxx
+
jsr _tgi_getxres
jmp decax1
+.endproc
; */
.include "tgi-kernel.inc"
- .export _tgi_getmaxy
- .import _tgi_getyres
.import decax1
+.proc _tgi_getmaxy
-_tgi_getmaxy:
jsr _tgi_getyres
jmp decax1
+.endproc
;
.include "tgi-kernel.inc"
- .export _tgi_getpagecount
+.proc _tgi_getpagecount
-_tgi_getpagecount:
lda _tgi_pagecount
ldx #0
rts
+.endproc
+
;
.include "tgi-kernel.inc"
- .export _tgi_getpalette
-
_tgi_getpalette = tgi_getpalette ; Call the driver
-
.include "tgi-kernel.inc"
-
+
.import return0
- .export _tgi_getpixel
-_tgi_getpixel:
+.proc _tgi_getpixel
+
jsr tgi_getset ; Pop args, check range
bcs @L9
jmp tgi_getpixel ; Call the driver
@L9: jmp return0 ; Assume bg color
+.endproc
+
.importzp ptr1, ptr2
-tgi_getset:
+.proc tgi_getset
+
jsr tgi_popxy ; Pop X/Y into ptr1/ptr2
; Are the coordinates out of range? First check if any coord is negative.
sbc _tgi_yres+1
@L9: rts
+.endproc
.include "tgi-kernel.inc"
- .export _tgi_getxres
+.proc _tgi_getxres
-_tgi_getxres:
lda _tgi_xres
ldx _tgi_xres+1
rts
+.endproc
.include "tgi-kernel.inc"
- .export _tgi_getyres
- .import ldaxidx
+.proc _tgi_getyres
-_tgi_getyres:
lda _tgi_yres
ldx _tgi_yres+1
rts
+.endproc
.include "tgi-kernel.inc"
.import popax
- .export _tgi_gotoxy
-_tgi_gotoxy:
+.proc _tgi_gotoxy
+
sta _tgi_cury ; Y
stx _tgi_cury+1
jsr popax
stx _tgi_curx+1
rts
+.endproc
-
.include "tgi-error.inc"
.importzp ptr1
- .import _tgi_done
- .import _tgi_setcolor
- .export _tgi_init
-_tgi_init:
+.proc _tgi_init
+
jsr _tgi_done ; Switch off graphics if needed
jsr tgi_init ; Go into graphics mode
jsr tgi_geterror ; Get the error code
@L9: rts
+.endproc
+
+
.include "tgi-kernel.inc"
.import popax
- .export _tgi_line
-_tgi_line:
+.proc _tgi_line
+
jsr tgi_linepop ; Pop/store Y2/X2
jsr popax
jsr tgi_popxy ; Pop/store X1/Y1 into ptr1/ptr2
jmp tgi_line ; Call the driver
+.endproc
+
.import popax
.importzp ptr3, ptr4
-tgi_linepop:
+.proc tgi_linepop
+
sta ptr4 ; Y2
stx ptr4+1
sta _tgi_cury
stx _tgi_curx+1
rts
+.endproc
.include "tgi-kernel.inc"
.import popax
- .export _tgi_lineto
-_tgi_lineto:
+.proc _tgi_lineto
+
jsr tgi_curtoxy ; Copy curx/cury into ptr1/ptr2
jsr tgi_linepop ; Pop x2/y2 into ptr3/ptr4 and curx/cury
jmp tgi_line ; Call the driver
+.endproc
* should NOT use this function in most cases, use tgi_load() instead.
*/
{
- static const unsigned char marker[4] = { 0x74, 0x67, 0x69, 0x00 };
-
static struct mod_ctrl ctrl = {
read /* Read from disk */
};
/* Now open the file */
ctrl.callerdata = open (name, O_RDONLY);
- if (ctrl.callerdata < 0) {
- tgi_error = TGI_ERR_CANNOT_LOAD;
- return;
- }
+ if (ctrl.callerdata >= 0) {
- /* Load the module */
- Res = mod_load (&ctrl);
+ /* Load the module */
+ Res = mod_load (&ctrl);
- /* Close the input file */
- close (ctrl.callerdata);
+ /* Close the input file */
+ close (ctrl.callerdata);
- /* Check the return code */
- if (Res == MLOAD_OK) {
+ /* Check the return code */
+ if (Res == MLOAD_OK) {
- /* Get a pointer to the loaded driver */
- tgi_drv = (tgi_drv_header*) ctrl.module;
+ /* Check the driver signature, install the driver */
+ tgi_install (ctrl.module);
+ return;
- /* Check the header */
- if (memcmp (tgi_drv, marker, sizeof (marker)) != 0) {
- /* Invalid driver */
- mod_free (tgi_drv);
- tgi_drv = 0;
- tgi_error = TGI_ERR_INV_DRIVER;
- } else {
- /* Driver is ok do setup */
- tgi_setup ();
}
-
- } else {
-
- /* Error loading the driver */
- tgi_error = TGI_ERR_CANNOT_LOAD;
-
}
+
+ /* Error loading the driver */
+ tgi_error = TGI_ERR_CANNOT_LOAD;
}
.code
-_tgi_map_mode:
+.proc _tgi_map_mode
+
sta tmp1 ; Save mode
ldy #$00
inx
@L1: rts
-
+.endproc
+
+
.import popax
.importzp ptr3
- .export _tgi_outtext
-_tgi_outtext:
+.proc _tgi_outtext
+
sta ptr3
stx ptr3+1 ; Save s
jsr tgi_curtoxy ; Copy curx/cury into ptr1/ptr2
jmp tgi_outtext ; Call the driver
+.endproc
.import popax
.importzp ptr3
- .export _tgi_outtextxy
-_tgi_outtextxy:
+.proc _tgi_outtextxy
+
sta ptr3
stx ptr3+1 ; Save s
jsr popax ; get y from stack
jsr tgi_popxy ; Pop x/y into ptr1/ptr2
jmp tgi_outtext ; Call the driver
+.endproc
.import popax
.importzp ptr1, ptr2
-tgi_popxy:
+.proc tgi_popxy
+
sta ptr2 ; Y
stx ptr2+1
jsr popax
stx ptr1+1
rts
+.endproc
.import popax
.importzp ptr3, ptr4
-tgi_popxy2:
+.proc tgi_popxy2
+
sta ptr4 ; Y
stx ptr4+1
jsr popax
stx ptr3+1
rts
+.endproc
+
+
.include "tgi-kernel.inc"
- .export _tgi_setcolor
-_tgi_setcolor:
+.proc _tgi_setcolor
+
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
+.endproc
.include "tgi-kernel.inc"
- .export _tgi_setdrawpage
-_tgi_setdrawpage:
+.proc _tgi_setdrawpage
+
cmp _tgi_pagecount ; Compare to available pages
bcs @L1
jmp tgi_setdrawpage ; Call the driver
@L1: jmp tgi_inv_arg ; Invalid argument
-
+.endproc
.include "tgi-kernel.inc"
.importzp ptr1
- .export _tgi_setpalette
+.proc _tgi_setpalette
-_tgi_setpalette:
sta ptr1
stx ptr1+1
jmp tgi_setpalette ; Call the driver
+.endproc
.include "tgi-kernel.inc"
- .export _tgi_setpixel
+.proc _tgi_setpixel
-_tgi_setpixel:
jsr tgi_getset ; Pop args, check range
bcs @L9
jmp tgi_setpixel ; Call the driver
@L9: rts
+.endproc
.include "tgi-kernel.inc"
- .export _tgi_setviewpage
-_tgi_setviewpage:
+.proc _tgi_setviewpage
+
cmp _tgi_pagecount ; Compare to available pages
bcs @L1
jmp tgi_setviewpage ; Call the driver
@L1: jmp tgi_inv_arg ; Invalid argument
+.endproc
-;
+;
; Ullrich von Bassewitz, 22.06.2002
;
.include "tgi-kernel.inc"
.import _strlen, pushax, tosumulax
- .export _tgi_textwidth
- .export _tgi_textheight
;-----------------------------------------------------------------------------
; unsigned __fastcall__ tgi_textwidth (const char* s);
_tgi_textwidth:
+
ldy _tgi_textdir ; Get text direction
bne height
.include "tgi-kernel.inc"
.import popax, incsp2
- .export _tgi_textstyle
-_tgi_textstyle:
+.proc _tgi_textstyle
+
pha
jsr popax ; Get magx/magy in one call
tay
jmp tgi_textstyle
+.endproc
+
.include "tgi-kernel.inc"
.include "modload.inc"
- .import _tgi_done
- .export _tgi_unload
+ .import tgi_clear_ptr
+.proc _tgi_unload
-_tgi_unload:
jsr _tgi_done ; Switch off graphics
- jsr tgi_deinstall ; Allow the driver to clean up
+ jsr tgi_uninstall ; Allow the driver to clean up
lda _tgi_drv
ldx _tgi_drv+1
jsr _mod_free ; Free the driver
-; Clear variables
-
- lda #$00
- sta _tgi_drv
- sta _tgi_drv+1
- sta _tgi_error
-
- rts
+ jmp tgi_clear_ptr ; Clear the driver pointer and exit
+.endproc