From: cuz Date: Fri, 21 Jun 2002 16:25:56 +0000 (+0000) Subject: TGI Implementation X-Git-Tag: V2.12.0~2309 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=579e1ae26724969065be0dfc5d1efceb8e8642e9;p=cc65 TGI Implementation git-svn-id: svn://svn.cc65.org/cc65/trunk@1315 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/asminc/modload.inc b/asminc/modload.inc index 466f8e57e..38c8420da 100644 --- a/asminc/modload.inc +++ b/asminc/modload.inc @@ -59,8 +59,10 @@ MODCTRL_SIZE = 10 ; Total size of struct ; */ .global _mod_load -; void mod_free (struct mod_ctrl* ctrl); -; /* Free a loaded module. */ +; void mod_free (void* module); +; /* Free a loaded module. Note: The given pointer is the pointer to the +; * module memory, not a pointer to a control structure. +; */ .global _mod_free diff --git a/asminc/tgi-error.inc b/asminc/tgi-error.inc index 60129aa57..e5d461985 100644 --- a/asminc/tgi-error.inc +++ b/asminc/tgi-error.inc @@ -34,10 +34,11 @@ ; 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_MODE = 3 ; Mode not supported by driver +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 diff --git a/asminc/tgi-kernel.inc b/asminc/tgi-kernel.inc index ea71f5dbf..554cde196 100644 --- a/asminc/tgi-kernel.inc +++ b/asminc/tgi-kernel.inc @@ -89,5 +89,4 @@ TGI_HDR_JUMPCOUNT = 12 ; Number of jump vectors .global tgi_fetch_error .global tgi_set_ptr - .global tgi_setup diff --git a/include/modload.h b/include/modload.h index 2b2397dd4..334ecbad5 100644 --- a/include/modload.h +++ b/include/modload.h @@ -75,8 +75,10 @@ unsigned char mod_load (struct mod_ctrl* ctrl); * loaded. */ -void mod_free (struct mod_ctrl* ctrl); -/* Free a loaded module. */ +void mod_free (void* module); +/* Free a loaded module. Note: The given pointer is the pointer to the + * module memory, not a pointer to a control structure. + */ diff --git a/include/tgi/tgi-error.h b/include/tgi/tgi-error.h index 3615fffb4..83c92bb51 100644 --- a/include/tgi/tgi-error.h +++ b/include/tgi/tgi-error.h @@ -46,8 +46,9 @@ #define TGI_ERR_OK 0 /* No error */ #define TGI_ERR_NO_DRIVER 1 /* No driver available */ -#define TGI_ERR_LOAD_ERROR 2 /* Error loading driver */ -#define TGI_ERR_INV_MODE 3 /* Mode not supported by driver */ +#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 */ diff --git a/include/tgi/tgi-kernel.h b/include/tgi/tgi-kernel.h index 946b3ca02..263fac514 100644 --- a/include/tgi/tgi-kernel.h +++ b/include/tgi/tgi-kernel.h @@ -77,8 +77,8 @@ typedef struct { /* 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 */ @@ -91,6 +91,9 @@ extern unsigned char tgi_mode; /* Graphics mode or zero */ 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 */ @@ -99,4 +102,4 @@ const char* __fastcall__ tgi_map_mode (unsigned char mode); - + diff --git a/libsrc/Makefile b/libsrc/Makefile index 3fb344c8c..875b7bd6f 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -81,7 +81,7 @@ atmoslib: # C64 c64lib: - for i in c64 cbm common runtime conio dbg; do \ + for i in c64 cbm common runtime conio dbg tgi; do \ CC=$(CC) \ AS=$(AS) \ CFLAGS="-Osir -g -T -t c64 -I../../include" \ @@ -89,7 +89,7 @@ c64lib: $(MAKE) -C $$i || exit 1; \ done mv c64/crt0.o c64.o - for i in c64 cbm common runtime conio dbg; do \ + for i in c64 cbm common runtime conio dbg tgi; do \ $(AR) a c64.lib $$i/*.o;\ done diff --git a/libsrc/tgi/.cvsignore b/libsrc/tgi/.cvsignore new file mode 100644 index 000000000..c0c4ab4ec --- /dev/null +++ b/libsrc/tgi/.cvsignore @@ -0,0 +1 @@ +tgi_load.s diff --git a/libsrc/tgi/Makefile b/libsrc/tgi/Makefile index 5c0c8255b..30c6fc90d 100644 --- a/libsrc/tgi/Makefile +++ b/libsrc/tgi/Makefile @@ -1,5 +1,5 @@ # -# makefile for the TGI graphics kernel +# Makefile for the TGI graphics kernel # .SUFFIXES: .o .s .c @@ -11,7 +11,7 @@ %.o: %.s @$(AS) -g -o $@ $(AFLAGS) $< -C_OBJS = +C_OBJS = tgi_load.o S_OBJS = tgi-kernel.o \ tgi_bar.o \ diff --git a/libsrc/tgi/tgi-kernel.s b/libsrc/tgi/tgi-kernel.s index 5f968f860..3d1ab24b1 100644 --- a/libsrc/tgi/tgi-kernel.s +++ b/libsrc/tgi/tgi-kernel.s @@ -6,6 +6,7 @@ .include "tgi-kernel.inc" + .export _tgi_setup .importzp ptr1 @@ -20,13 +21,13 @@ _tgi_mode: .res 1 ; Graphics mode or zero .data - + ; Jump table for the driver functions. tgi_install: jmp $0000 tgi_deinstall: jmp $0000 tgi_init: jmp $0000 -tgi_post: jmp $0000 +tgi_done: jmp $0000 tgi_control: jmp $0000 tgi_clear: jmp $0000 tgi_setcolor: jmp $0000 @@ -38,27 +39,29 @@ 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 +; void __fastcall__ tgi_setup (void); +; /* Setup the driver and graphics kernel once the driver is loaded */ - ldy #TGI_HDR_JUMPTAB - ldx #1 -@L1: lda (ptr1),y +copy: lda (ptr1),y sta tgi_install,x iny inx - lda (ptr1),y - sta tgi_install,x - inx + rts + + +_tgi_setup: + jsr tgi_set_ptr + + ldy #TGI_HDR_JUMPTAB + ldx #0 + +@L1: inx ; Skip JMP opcode + jsr copy ; Copy one byte + jsr copy ; Copy one byte cpx #(TGI_HDR_JUMPCOUNT*3) bne @L1 - + ; Initialize variables lda #$00 @@ -71,7 +74,8 @@ tgi_setup: ;---------------------------------------------------------------------------- ; Fetch the error code from the driver and place it into the global error -; variable. +; 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 diff --git a/libsrc/tgi/tgi_done.s b/libsrc/tgi/tgi_done.s index 83a70b580..463e93b79 100644 --- a/libsrc/tgi/tgi_done.s +++ b/libsrc/tgi/tgi_done.s @@ -13,9 +13,8 @@ _tgi_done: beq @L1 ; Jump if not jsr tgi_done ; Call the driver routine jsr tgi_fetch_error ; Get the error code - lda _tgi_error ; Did we have an error? - bne @L1 ; Jump if yes - sta _tgi_mode ; Reset the current mode + bne @L1 ; Jump if we had an error + sta _tgi_mode ; Reset the current mode (A = 0) @L1: rts diff --git a/libsrc/tgi/tgi_geterror.s b/libsrc/tgi/tgi_geterror.s index 4b74f561a..e291cf879 100644 --- a/libsrc/tgi/tgi_geterror.s +++ b/libsrc/tgi/tgi_geterror.s @@ -2,12 +2,13 @@ ; Ullrich von Bassewitz, 21.06.2002 ; ; unsigned char __fastcall__ tgi_geterror (void); -; /* Return the error code for the last operation. This will also clear the -; * error. +; /* Return the error code for the last operation. This will also clear the +; * error. ; */ .include "tgi-kernel.inc" + .export _tgi_geterror _tgi_geterror: ldx #0 diff --git a/libsrc/tgi/tgi_init.s b/libsrc/tgi/tgi_init.s index a43bf9d04..e6716b99b 100644 --- a/libsrc/tgi/tgi_init.s +++ b/libsrc/tgi/tgi_init.s @@ -14,11 +14,12 @@ _tgi_init: pha ; Save mode jsr _tgi_done ; Switch off graphics if needed - jsr tgi_init ; Initialize the mode + pla + sta _tgi_mode ; Remember the mode + jsr tgi_init ; Go into graphics mode jsr tgi_fetch_error ; Get the error code - pla ; Restore the mode - ldx _tgi_error ; Did we have an error before? - bne @L1 ; Jump if yes - sta _tgi_mode ; Set the current mode if not + beq @L1 ; Jump if no error + lda #$00 + sta _tgi_mode ; Clear the mode if init was not successful @L1: rts diff --git a/libsrc/tgi/tgi_load.c b/libsrc/tgi/tgi_load.c new file mode 100644 index 000000000..828eb1d97 --- /dev/null +++ b/libsrc/tgi/tgi_load.c @@ -0,0 +1,90 @@ +/* + * TEST VERSION - CURRENTLY C64 SPECIFIC!!! + */ + + + +#include +#include +#include +#include +#include + + + +static unsigned char ReadInputBlock (struct mod_ctrl* C, void* Buf, unsigned Size) +{ + return (cbm_read (1, Buf, Size) != Size); +} + + + +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. + */ +{ + const char* name = tgi_map_mode (mode); + if (name == 0) { + /* No driver for this mode */ + tgi_error = TGI_ERR_NO_DRIVER; + } else { + /* Laod the driver */ + tgi_load_driver (name); + } +} + + + +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. + */ +{ + static const unsigned char marker[4] = { 0x74, 0x67, 0x69, 0x00 }; + + static struct mod_ctrl ctrl = { + ReadInputBlock /* read_block */ + }; + unsigned Res; + + /* Check if we do already have a driver loaded. If so, remove it. */ + if (tgi_drv != 0) { + tgi_unload (); + } + + /* Now open the file */ + if (cbm_open (1, 8, 2, name) != 0) { + tgi_error = TGI_ERR_CANNOT_LOAD; + return; + } + + /* Load the module */ + Res = mod_load (&ctrl); + cbm_close (1); + + /* Check the return code */ + if (Res == MLOAD_OK) { + + /* Get a pointer to the loaded driver */ + tgi_drv = (tgi_drv_header*) ctrl.module; + + /* 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; + + } +}