From 104ce990cba6d321340a713a9ed469519b466173 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 7 Jul 2002 10:30:31 +0000 Subject: [PATCH] More work on the graphics subsystem git-svn-id: svn://svn.cc65.org/cc65/trunk@1334 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- asminc/tgi-error.inc | 4 +- asminc/tgi-kernel.inc | 31 ++++++++------ include/tgi.h | 74 ++++++++++++++++++---------------- include/tgi/tgi-error.h | 1 + include/tgi/tgi-kernel.h | 4 ++ libsrc/tgi/Makefile | 4 ++ libsrc/tgi/tgi-kernel.s | 70 ++++++++++++++------------------ libsrc/tgi/tgi_done.s | 5 ++- libsrc/tgi/tgi_getcolorcount.s | 2 +- libsrc/tgi/tgi_getdefpalette.s | 15 +++++++ libsrc/tgi/tgi_geterror.s | 11 +++-- libsrc/tgi/tgi_getmaxcolor.s | 5 ++- libsrc/tgi/tgi_getpagecount.s | 16 ++++++++ libsrc/tgi/tgi_getpalette.s | 17 ++++++++ libsrc/tgi/tgi_init.s | 31 +++++++++++--- libsrc/tgi/tgi_setpalette.s | 21 ++++++++++ 16 files changed, 209 insertions(+), 102 deletions(-) create mode 100644 libsrc/tgi/tgi_getdefpalette.s create mode 100644 libsrc/tgi/tgi_getpagecount.s create mode 100644 libsrc/tgi/tgi_getpalette.s create mode 100644 libsrc/tgi/tgi_setpalette.s diff --git a/asminc/tgi-error.inc b/asminc/tgi-error.inc index 530bacb77..258c0c24c 100644 --- a/asminc/tgi-error.inc +++ b/asminc/tgi-error.inc @@ -32,7 +32,7 @@ ;*****************************************************************************/ - + ; Error constants TGI_ERR_OK = 0 ; No error TGI_ERR_NO_DRIVER = 1 ; No driver available @@ -40,6 +40,6 @@ 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_ERR_INV_FUNC = 6 ; Function not supported diff --git a/asminc/tgi-kernel.inc b/asminc/tgi-kernel.inc index bed920317..da96603c2 100644 --- a/asminc/tgi-kernel.inc +++ b/asminc/tgi-kernel.inc @@ -50,18 +50,22 @@ 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_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 @@ -84,11 +88,15 @@ TGI_HDR_JUMPCOUNT = 14 ; Number of jump vectors .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 @@ -100,7 +108,6 @@ TGI_HDR_JUMPCOUNT = 14 ; Number of jump vectors ; ASM functions .global tgi_emu_bar - .global tgi_fetch_error .global tgi_getset .global tgi_inv_arg .global tgi_linepop diff --git a/include/tgi.h b/include/tgi.h index f69d453f1..fe3fdb9a5 100644 --- a/include/tgi.h +++ b/include/tgi.h @@ -47,20 +47,6 @@ -/*****************************************************************************/ -/* Data */ -/*****************************************************************************/ - - - -struct palettetype { - unsigned char r; /* Red component */ - unsigned char g; /* Green component */ - unsigned char b; /* Blue component */ -}; - - - /*****************************************************************************/ /* Functions */ /*****************************************************************************/ @@ -79,7 +65,7 @@ void __fastcall__ tgi_load_driver (const char* name); */ 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. */ @@ -93,49 +79,67 @@ unsigned char __fastcall__ tgi_geterror (void); */ 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. */ diff --git a/include/tgi/tgi-error.h b/include/tgi/tgi-error.h index 2c6ec1514..25365a4d3 100644 --- a/include/tgi/tgi-error.h +++ b/include/tgi/tgi-error.h @@ -50,6 +50,7 @@ #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 */ diff --git a/include/tgi/tgi-kernel.h b/include/tgi/tgi-kernel.h index bf83d49aa..de9f6041a 100644 --- a/include/tgi/tgi-kernel.h +++ b/include/tgi/tgi-kernel.h @@ -64,11 +64,15 @@ typedef struct { 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 */ diff --git a/libsrc/tgi/Makefile b/libsrc/tgi/Makefile index df324661e..863985299 100644 --- a/libsrc/tgi/Makefile +++ b/libsrc/tgi/Makefile @@ -21,10 +21,13 @@ S_OBJS = tgi-kernel.o \ 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 \ @@ -37,6 +40,7 @@ S_OBJS = tgi-kernel.o \ tgi_map_mode.o \ tgi_setcolor.o \ tgi_setdrawpage.o \ + tgi_setpalette.o \ tgi_setpixel.o \ tgi_setdrawpage.o \ tgi_unload.o diff --git a/libsrc/tgi/tgi-kernel.s b/libsrc/tgi/tgi-kernel.s index c2be3d473..80592faa5 100644 --- a/libsrc/tgi/tgi-kernel.s +++ b/libsrc/tgi/tgi-kernel.s @@ -16,36 +16,40 @@ .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 ;---------------------------------------------------------------------------- @@ -103,27 +107,13 @@ _tgi_setup: 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 diff --git a/libsrc/tgi/tgi_done.s b/libsrc/tgi/tgi_done.s index 463e93b79..e3abf53fd 100644 --- a/libsrc/tgi/tgi_done.s +++ b/libsrc/tgi/tgi_done.s @@ -5,6 +5,7 @@ ; /* End graphics mode, switch back to text mode. Will NOT unload the driver! */ .include "tgi-kernel.inc" + .include "tgi-error.inc" .export _tgi_done @@ -12,7 +13,9 @@ _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 diff --git a/libsrc/tgi/tgi_getcolorcount.s b/libsrc/tgi/tgi_getcolorcount.s index 8059e2d3b..0661a43f0 100644 --- a/libsrc/tgi/tgi_getcolorcount.s +++ b/libsrc/tgi/tgi_getcolorcount.s @@ -9,7 +9,7 @@ _tgi_getcolorcount: - lda _tgi_colors + lda _tgi_colorcount ldx #0 rts diff --git a/libsrc/tgi/tgi_getdefpalette.s b/libsrc/tgi/tgi_getdefpalette.s new file mode 100644 index 000000000..f1bf1c999 --- /dev/null +++ b/libsrc/tgi/tgi_getdefpalette.s @@ -0,0 +1,15 @@ +; +; 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 + + diff --git a/libsrc/tgi/tgi_geterror.s b/libsrc/tgi/tgi_geterror.s index e291cf879..0aa12e17c 100644 --- a/libsrc/tgi/tgi_geterror.s +++ b/libsrc/tgi/tgi_geterror.s @@ -11,8 +11,11 @@ .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 diff --git a/libsrc/tgi/tgi_getmaxcolor.s b/libsrc/tgi/tgi_getmaxcolor.s index dda4fb243..679311920 100644 --- a/libsrc/tgi/tgi_getmaxcolor.s +++ b/libsrc/tgi/tgi_getmaxcolor.s @@ -4,14 +4,15 @@ ; 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 diff --git a/libsrc/tgi/tgi_getpagecount.s b/libsrc/tgi/tgi_getpagecount.s new file mode 100644 index 000000000..de59e9b58 --- /dev/null +++ b/libsrc/tgi/tgi_getpagecount.s @@ -0,0 +1,16 @@ +; +; 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 + diff --git a/libsrc/tgi/tgi_getpalette.s b/libsrc/tgi/tgi_getpalette.s new file mode 100644 index 000000000..46eaa30d9 --- /dev/null +++ b/libsrc/tgi/tgi_getpalette.s @@ -0,0 +1,17 @@ +; +; 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 + + + diff --git a/libsrc/tgi/tgi_init.s b/libsrc/tgi/tgi_init.s index c0876f0c5..68254785b 100644 --- a/libsrc/tgi/tgi_init.s +++ b/libsrc/tgi/tgi_init.s @@ -8,6 +8,7 @@ .include "tgi-kernel.inc" .include "tgi-error.inc" + .importzp ptr1 .import _tgi_done .import _tgi_setcolor .export _tgi_init @@ -18,14 +19,34 @@ _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 diff --git a/libsrc/tgi/tgi_setpalette.s b/libsrc/tgi/tgi_setpalette.s new file mode 100644 index 000000000..baa572b21 --- /dev/null +++ b/libsrc/tgi/tgi_setpalette.s @@ -0,0 +1,21 @@ +; +; 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 + + -- 2.39.5