From: cuz Date: Sat, 22 Jun 2002 21:40:24 +0000 (+0000) Subject: Working on the TGI library X-Git-Tag: V2.12.0~2301 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bf944755ddae9f97a000f2f71a868bef9e1136ab;p=cc65 Working on the TGI library git-svn-id: svn://svn.cc65.org/cc65/trunk@1323 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/asminc/tgi-error.inc b/asminc/tgi-error.inc index e5d461985..530bacb77 100644 --- a/asminc/tgi-error.inc +++ b/asminc/tgi-error.inc @@ -32,13 +32,14 @@ ;*****************************************************************************/ - + ; 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 diff --git a/asminc/tgi-kernel.inc b/asminc/tgi-kernel.inc index 96183bf69..bd81082e2 100644 --- a/asminc/tgi-kernel.inc +++ b/asminc/tgi-kernel.inc @@ -40,9 +40,10 @@ TGI_HDR_ID = 0 ; Contains 0x74, 0x67, 0x69 ("tgi") 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 @@ -51,14 +52,16 @@ 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_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 @@ -66,8 +69,14 @@ TGI_HDR_JUMPCOUNT = 12 ; Number of jump vectors .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 @@ -78,6 +87,8 @@ TGI_HDR_JUMPCOUNT = 12 ; Number of jump vectors .global tgi_done .global tgi_control .global tgi_clear + .global tgi_setviewpage + .global tgi_setdrawpage .global tgi_setcolor .global tgi_setpixel .global tgi_getpixel @@ -89,6 +100,10 @@ TGI_HDR_JUMPCOUNT = 12 ; Number of jump vectors ;------------------------------------------------------------------------------ ; ASM functions + .global tgi_emu_bar .global tgi_fetch_error + .global tgi_getset + .global tgi_inv_arg + .global tgi_linepop .global tgi_set_ptr diff --git a/include/tgi.h b/include/tgi.h index 64db5fcbd..da1a87187 100644 --- a/include/tgi.h +++ b/include/tgi.h @@ -95,6 +95,12 @@ unsigned char __fastcall__ tgi_geterror (void); 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). @@ -110,6 +116,9 @@ unsigned __fastcall__ tgi_getmaxy (void); * 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 */ diff --git a/include/tgi/tgi-error.h b/include/tgi/tgi-error.h index 83c92bb51..2c6ec1514 100644 --- a/include/tgi/tgi-error.h +++ b/include/tgi/tgi-error.h @@ -49,6 +49,7 @@ #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 */ diff --git a/include/tgi/tgi-kernel.h b/include/tgi/tgi-kernel.h index 3e11ba94f..ff534737a 100644 --- a/include/tgi/tgi-kernel.h +++ b/include/tgi/tgi-kernel.h @@ -54,9 +54,10 @@ typedef struct { 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 */ @@ -65,6 +66,8 @@ typedef struct { 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 */ @@ -77,11 +80,17 @@ 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 */ +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 */ diff --git a/libsrc/tgi/Makefile b/libsrc/tgi/Makefile index 85fdfa031..6f436fc87 100644 --- a/libsrc/tgi/Makefile +++ b/libsrc/tgi/Makefile @@ -19,16 +19,20 @@ S_OBJS = tgi-kernel.o \ 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 \ diff --git a/libsrc/tgi/tgi-kernel.s b/libsrc/tgi/tgi-kernel.s index af448398f..298108932 100644 --- a/libsrc/tgi/tgi-kernel.s +++ b/libsrc/tgi/tgi-kernel.s @@ -19,9 +19,13 @@ _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 @@ -95,8 +99,10 @@ _tgi_setup: ; 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 diff --git a/libsrc/tgi/tgi_getcolor.s b/libsrc/tgi/tgi_getcolor.s new file mode 100644 index 000000000..32efd5511 --- /dev/null +++ b/libsrc/tgi/tgi_getcolor.s @@ -0,0 +1,15 @@ +; +; 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 + diff --git a/libsrc/tgi/tgi_getpixel.s b/libsrc/tgi/tgi_getpixel.s index 6af67a816..b70516732 100644 --- a/libsrc/tgi/tgi_getpixel.s +++ b/libsrc/tgi/tgi_getpixel.s @@ -7,18 +7,12 @@ .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 diff --git a/libsrc/tgi/tgi_getset.s b/libsrc/tgi/tgi_getset.s new file mode 100644 index 000000000..1d6353b90 --- /dev/null +++ b/libsrc/tgi/tgi_getset.s @@ -0,0 +1,44 @@ +; +; 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 + + diff --git a/libsrc/tgi/tgi_init.s b/libsrc/tgi/tgi_init.s index e6716b99b..c0876f0c5 100644 --- a/libsrc/tgi/tgi_init.s +++ b/libsrc/tgi/tgi_init.s @@ -9,6 +9,7 @@ .include "tgi-error.inc" .import _tgi_done + .import _tgi_setcolor .export _tgi_init _tgi_init: @@ -18,8 +19,13 @@ _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 diff --git a/libsrc/tgi/tgi_line.s b/libsrc/tgi/tgi_line.s index 3f90ef5a2..8a9602546 100644 --- a/libsrc/tgi/tgi_line.s +++ b/libsrc/tgi/tgi_line.s @@ -8,15 +8,12 @@ .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 diff --git a/libsrc/tgi/tgi_linepop.s b/libsrc/tgi/tgi_linepop.s new file mode 100644 index 000000000..f0779c5f9 --- /dev/null +++ b/libsrc/tgi/tgi_linepop.s @@ -0,0 +1,24 @@ +; +; 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 + + diff --git a/libsrc/tgi/tgi_lineto.s b/libsrc/tgi/tgi_lineto.s new file mode 100644 index 000000000..1add86744 --- /dev/null +++ b/libsrc/tgi/tgi_lineto.s @@ -0,0 +1,30 @@ +; +; 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 + + diff --git a/libsrc/tgi/tgi_setcolor.s b/libsrc/tgi/tgi_setcolor.s index 0d430f76a..242f07826 100644 --- a/libsrc/tgi/tgi_setcolor.s +++ b/libsrc/tgi/tgi_setcolor.s @@ -6,13 +6,13 @@ .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 - + diff --git a/libsrc/tgi/tgi_setpixel.s b/libsrc/tgi/tgi_setpixel.s index cab5618cd..d72c05dfc 100644 --- a/libsrc/tgi/tgi_setpixel.s +++ b/libsrc/tgi/tgi_setpixel.s @@ -7,16 +7,13 @@ .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 + +