1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-22 12:30:41 +00:00

Implementing TGI

git-svn-id: svn://svn.cc65.org/cc65/trunk@1311 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-06-21 12:46:52 +00:00
parent 8c8f0ba06f
commit e50b24d46a
11 changed files with 323 additions and 15 deletions

View File

@ -33,25 +33,60 @@
;------------------------------------------------------------------------------
; Offsets into the driver header
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_RES = 9 ; Reserved for extensions
TGI_HDR_ERROR = 9 ; Error code
TGI_HDR_RES = 10 ; Reserved for extensions
TGI_HDR_INSTALL = 16 ; INSTALL routine
TGI_HDR_DEINSTALL = 18 ; DEINSTALL routine
TGI_HDR_INIT = 20 ; INIT routine
TGI_HDR_POST = 22 ; POST routine
TGI_HDR_CONTROL = 24 ; CONTROL routine
TGI_HDR_CLEAR = 26 ; CLEAR routine
TGI_HDR_SETCOLOR = 28 ; SETCOLOR routine
TGI_HDR_SETPIXEL = 30 ; SETPIXEL routine
TGI_HDR_GETPIXEL = 32 ; GETPIXEL routine
TGI_HDR_LINE = 34 ; LINE routine
TGI_HDR_BAR = 36 ; BAR routine
TGI_HDR_CIRCLE = 38 ; CIRCLE routine
TGI_HDR_JUMPTAB = 16
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_POST = TGI_HDR_JUMPTAB+6 ; POST 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_JUMPCOUNT = 12 ; Number of jump vectors
;------------------------------------------------------------------------------
; Variables
.global _tgi_drv ; Pointer to driver
.global _tgi_error ; Last error code
;------------------------------------------------------------------------------
; Driver entry points
.global tgi_install
.global tgi_deinstall
.global tgi_init
.global tgi_post
.global tgi_control
.global tgi_clear
.global tgi_setcolor
.global tgi_setpixel
.global tgi_getpixel
.global tgi_line
.global tgi_bar
.global tgi_circle
;------------------------------------------------------------------------------
; ASM functions
.global tgi_fetch_error
.global tgi_set_ptr
.global tgi_setup

View File

@ -87,7 +87,7 @@ void __fastcall__ tgi_init (unsigned char mode);
void __fastcall__ tgi_done (void);
/* End graphics mode, switch back to text mode. Will NOT unload the driver! */
unsigned char __fastcall__ tgi_error (void);
unsigned char __fastcall__ tgi_geterror (void);
/* Return the error code for the last operation. */
void __fastcall__ tgi_clear (void);

View File

@ -55,7 +55,8 @@ typedef struct {
unsigned xres; /* X resolution */
unsigned yres; /* Y resolution */
unsigned char colors; /* Number of available colors */
unsigned char res[7]; /* Reserved for extensions */
unsigned char error; /* Error code */
unsigned char res[6]; /* Reserved for extensions */
/* Jump vectors. Note that these are not C callable */
void* install; /* INSTALL routine */
@ -75,6 +76,23 @@ typedef struct {
/* TGI kernel variables */
extern tgi_drv_header tgi_drv; /* Pointer to driver */
extern unsigned char tgi_error; /* Last error code */
/*****************************************************************************/
/* Code */
/*****************************************************************************/
const char* __fastcall__ tgi_map_mode (unsigned char mode);
/* Map a tgi mode to a driver name. Returns NULL if no driver available. */
/* End of tgi-kernel.h */
#endif

32
libsrc/tgi/Makefile Normal file
View File

@ -0,0 +1,32 @@
#
# makefile for the TGI graphics kernel
#
.SUFFIXES: .o .s .c
%.o: %.c
@$(CC) $(CFLAGS) $<
@$(AS) -g -o $@ $(AFLAGS) $(*).s
%.o: %.s
@$(AS) -g -o $@ $(AFLAGS) $<
C_OBJS =
S_OBJS = tgi-kernel.o \
tgi_geterror.o \
tgi_getmaxx.o \
tgi_getmaxy.o \
tgi_getxres.o \
tgi_getyres.o \
tgi_map_mode.o
all: $(C_OBJS) $(S_OBJS)
clean:
@rm -f *~
@rm -f $(C_OBJS:.o=.s)
@rm -f $(C_OBJS)
@rm -f $(S_OBJS)

85
libsrc/tgi/tgi-kernel.s Normal file
View File

@ -0,0 +1,85 @@
;
; Ullrich von Bassewitz, 21.06.2002
;
; Common functions of the tgi graphics kernel.
;
.include "tgi-kernel.inc"
;----------------------------------------------------------------------------
; Variables
.bss
_tgi_drv: .res 2 ; Pointer to driver
_tgi_error: .res 1 ; Last error code
.data
; Jump table for the driver functions.
tgi_install: jmp $0000
tgi_deinstall: jmp $0000
tgi_init: jmp $0000
tgi_post: jmp $0000
tgi_control: jmp $0000
tgi_clear: 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
;----------------------------------------------------------------------------
; Setup the TGI driver once it is loaded.
tgi_setup:
lda _tgi_drv
sta ptr1
lda _tgi_drv+1
sta ptr1+1
ldy #TGI_HDR_JUMPTAB
ldx #1
@L1: lda (ptr1),y
sta tgi_install,x
iny
inx
lda (ptr1),y
sta tgi_install,x
inx
cpx #(TGI_HDR_JMPCOUNT*3)
bne @L1
lda #$00
sta _tgi_error
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.
tgi_fetch_error:
jsr tgi_set_ptr
ldy #TGI_HDR_ERROR
lda (ptr1),y
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

13
libsrc/tgi/tgi_geterror.s Normal file
View File

@ -0,0 +1,13 @@
;
; Ullrich von Bassewitz, 21.06.2002
;
; unsigned char __fastcall__ tgi_geterror (void);
; /* Return the error code for the last operation. */
.include "tgi-kernel.inc"
_tgi_geterror:
lda _tgi_error
rts

20
libsrc/tgi/tgi_getmaxx.s Normal file
View File

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 21.06.2002
;
; unsigned __fastcall__ tgi_getmaxx (void);
; /* Return the maximum x coordinate. The resolution in x direction is
; * getmaxx() + 1
; */
.include "tgi-kernel.inc"
.export _tgi_getmaxx
.import _tgi_getxres
.import decax1
_tgi_getmaxx:
jsr _tgi_getxres
jmp decax1

19
libsrc/tgi/tgi_getmaxy.s Normal file
View File

@ -0,0 +1,19 @@
;
; Ullrich von Bassewitz, 21.06.2002
;
; unsigned __fastcall__ tgi_getmaxy (void);
; /* Return the maximum y coordinate. The resolution in y direction is
; * getmaxy() + 1
; */
.include "tgi-kernel.inc"
.export _tgi_getmaxy
.import _tgi_getyres
.import decax
_tgi_getmaxy:
jsr _tgi_getyres
jmp decax1

19
libsrc/tgi/tgi_getxres.s Normal file
View File

@ -0,0 +1,19 @@
;
; Ullrich von Bassewitz, 21.06.2002
;
; unsigned __fastcall__ tgi_getxres (void);
; /* Return the resolution in X direction */
.include "tgi-kernel.inc"
.export _tgi_getxres
.import ldaxidx
_tgi_getxres:
lda _tgi_drv
ldx _tgi_drv+1
ldy #TGI_HDR_XRES+1
jmp ldaxidx

19
libsrc/tgi/tgi_getyres.s Normal file
View File

@ -0,0 +1,19 @@
;
; Ullrich von Bassewitz, 21.06.2002
;
; unsigned __fastcall__ tgi_getyres (void);
; /* Return the resolution in Y direction */
.include "tgi-kernel.inc"
.export _tgi_getyres
.import ldaxidx
_tgi_getyres:
lda _tgi_drv
ldx _tgi_drv+1
ldy #TGI_HDR_YRES+1
jmp ldaxidx

48
libsrc/tgi/tgi_map_mode.s Normal file
View File

@ -0,0 +1,48 @@
;
; Ullrich von Bassewitz, 31.05.2002
;
; const char* __fastcall__ tgi_map_mode (unsigned char mode);
; /* Map tgi mode codes to driver names */
;
.export _tgi_map_mode
.import _tgi_mode_table
.import return0
.importzp tmp1
;----------------------------------------------------------------------------
; BEWARE: The current implementation of tgi_map_mode does not work with tables
; larger that 255 bytes!
.code
_tgi_map_mode:
sta tmp1 ; Save mode
ldy #$00
@L0: lda _tgi_mode_table,y
beq NotFound ; Branch if mode code zero
cmp tmp1
beq Found
; Skip the name
@L1: iny
lda _tgi_mode_table,y
bne @L1 ; Loop until end marker found
iny ; Skip end marker
bne @L0 ; Branch always
; Mode not found
NotFound:
jmp return0
; Mode found
Found: tya
ldx #>_tgi_mode_table
sec ; Account for the mode byte
adc #<_tgi_mode_table ; Return pointer to file name
rts