From 897c1d8523455d2f7a2ab1f7ff6c6fdd4135eebc Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 22 Jun 2002 13:10:02 +0000 Subject: [PATCH] Added emulation and more clipping for the BAR function. Copy colors and page count into local storage from the driver. Added more functions. git-svn-id: svn://svn.cc65.org/cc65/trunk@1322 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/tgi/Makefile | 37 +++++++++------- libsrc/tgi/tgi-kernel.s | 46 +++++++++++++------ libsrc/tgi/tgi_bar.s | 37 ++++++++++++---- libsrc/tgi/tgi_emu_bar.s | 80 ++++++++++++++++++++++++++++++++++ libsrc/tgi/tgi_getcolorcount.s | 15 +++++++ libsrc/tgi/tgi_getmaxcolor.s | 21 +++++++++ libsrc/tgi/tgi_setcolor.s | 10 +++-- libsrc/tgi/tgi_setdrawpage.s | 18 ++++++++ libsrc/tgi/tgi_setviewpage.s | 18 ++++++++ 9 files changed, 241 insertions(+), 41 deletions(-) create mode 100644 libsrc/tgi/tgi_emu_bar.s create mode 100644 libsrc/tgi/tgi_getcolorcount.s create mode 100644 libsrc/tgi/tgi_getmaxcolor.s create mode 100644 libsrc/tgi/tgi_setdrawpage.s create mode 100644 libsrc/tgi/tgi_setviewpage.s diff --git a/libsrc/tgi/Makefile b/libsrc/tgi/Makefile index 30c6fc90d..85fdfa031 100644 --- a/libsrc/tgi/Makefile +++ b/libsrc/tgi/Makefile @@ -13,22 +13,27 @@ C_OBJS = tgi_load.o -S_OBJS = tgi-kernel.o \ - tgi_bar.o \ - tgi_circle.o \ - tgi_clear.o \ - tgi_done.o \ - tgi_geterror.o \ - tgi_getmaxx.o \ - tgi_getmaxy.o \ - tgi_getpixel.o \ - tgi_getxres.o \ - tgi_getyres.o \ - tgi_init.o \ - tgi_line.o \ - tgi_map_mode.o \ - tgi_setcolor.o \ - tgi_setpixel.o \ +S_OBJS = tgi-kernel.o \ + tgi_bar.o \ + tgi_circle.o \ + tgi_clear.o \ + tgi_done.o \ + tgi_emu_bar.o \ + tgi_getcolorcount.o \ + tgi_geterror.o \ + tgi_getmaxcolor.o \ + tgi_getmaxx.o \ + tgi_getmaxy.o \ + tgi_getpixel.o \ + tgi_getxres.o \ + tgi_getyres.o \ + tgi_init.o \ + tgi_line.o \ + tgi_map_mode.o \ + tgi_setcolor.o \ + tgi_setdrawpage.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 521ecb741..af448398f 100644 --- a/libsrc/tgi/tgi-kernel.s +++ b/libsrc/tgi/tgi-kernel.s @@ -5,6 +5,7 @@ ; .include "tgi-kernel.inc" + .include "tgi-error.inc" .export _tgi_setup .importzp ptr1 @@ -20,7 +21,9 @@ _tgi_error: .res 1 ; Last error code _tgi_mode: .res 1 ; Graphics mode or zero _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_pagecount: .res 1 ; Number of available screen pages + .data @@ -32,6 +35,8 @@ 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 @@ -65,20 +70,27 @@ _tgi_setup: cpx #(TGI_HDR_JUMPCOUNT*3) bne @L1 -; Copy the screen dimensions +; Check for emulation vectors needed - ldy #TGI_HDR_XRES - lda (ptr1),y - sta _tgi_xres + lda tgi_bar+1 + ora tgi_bar+2 ; Do we have a BAR vector? + bne @L2 ; Jump if yes + lda #tgi_emu_bar + sta tgi_bar+2 + +; Copy variables. Beware: We are using internal knowledge about variable +; layout here! + +@L2: ldy #TGI_HDR_XRES + ldx #0 +@L3: lda (ptr1),y + sta _tgi_xres,x iny - lda (ptr1),y - sta _tgi_xres+1 - ldy #TGI_HDR_YRES - lda (ptr1),y - sta _tgi_yres - iny - lda (ptr1),y - sta _tgi_yres+1 + inx + cpx #6 + bne @L3 ; Initialize variables @@ -112,3 +124,11 @@ tgi_set_ptr: sta ptr1+1 rts +;---------------------------------------------------------------------------- +; Set an invalid argument error + +tgi_inv_arg: + lda #TGI_ERR_INV_ARG + sta _tgi_error + rts + diff --git a/libsrc/tgi/tgi_bar.s b/libsrc/tgi/tgi_bar.s index 439aa9d69..1b6ffb0e7 100644 --- a/libsrc/tgi/tgi_bar.s +++ b/libsrc/tgi/tgi_bar.s @@ -68,44 +68,63 @@ _tgi_bar: ; Check if X1 is negative. If so, clip it to the left border (zero). - lda #$00 bit ptr1+1 bpl @L3 + lda #$00 sta ptr1 sta ptr1+1 + beq @L4 ; Branch always, skip following test -; Dito for Y1 +; Check if X1 is beyond the right border. If so, the bar is invisible. -@L3: bit ptr2+1 - bpl @L4 +@L3: lda ptr1 + cmp _tgi_xres + lda ptr1+1 + sbc _tgi_xres + bcs @L9 ; Bail out if invisible + +; Check if Y1 is negative. If so, clip it to the top border (zero). + +@L4: bit ptr2+1 + bpl @L5 + lda #$00 sta ptr2 sta ptr2+1 + beq @L6 ; Branch always, skip following test + +; Check if Y1 is beyond the bottom border. If so, the bar is invisible. + +@L5: lda ptr2 + cmp _tgi_yres + lda ptr2+1 + sbc _tgi_yres + bcs @L9 ; Bail out if invisible ; Check if X2 is larger than the maximum x coord. If so, clip it. -@L4: lda ptr3 +@L6: lda ptr3 cmp _tgi_xres lda ptr3+1 sbc _tgi_xres+1 - bcs @L5 + bcc @L7 jsr _tgi_getmaxx sta ptr3 stx ptr3+1 ; Check if Y2 is larger than the maximum y coord. If so, clip it. -@L5: lda ptr4 +@L7: lda ptr4 cmp _tgi_yres lda ptr4+1 sbc _tgi_yres+1 - bcs @L6 + bcc @L8 jsr _tgi_getmaxy sta ptr4 stx ptr4+1 ; The coordinates are now valid. Call the driver. -@L6: jmp tgi_bar +@L8: jmp tgi_bar ; Error exit diff --git a/libsrc/tgi/tgi_emu_bar.s b/libsrc/tgi/tgi_emu_bar.s new file mode 100644 index 000000000..6af7cc336 --- /dev/null +++ b/libsrc/tgi/tgi_emu_bar.s @@ -0,0 +1,80 @@ +; +; Ullrich von Bassewitz, 22.06.2002 +; +; Emulation for tgi_bar. +; + + .include "tgi-kernel.inc" + + .importzp ptr1, ptr2, ptr3, ptr4 + .export tgi_emu_bar + +tgi_emu_bar: + lda ptr4 + sta Y2 + lda ptr4+1 + sta Y2+1 + + lda ptr3 + sta X2 + lda ptr3+1 + sta X2+1 + + lda ptr2 + sta ptr4 + sta Y1 + lda ptr2+1 + sta ptr4+1 + sta Y1+1 + + lda ptr1 + sta X1 + lda ptr1+1 + sta X1+1 + +@L1: jsr tgi_line + + lda Y1 + cmp Y2 + bne @L2 + lda Y1 + cmp Y2 + beq @L4 + +@L2: inc Y1 + bne @L3 + inc Y1+1 + +@L3: lda Y1 + sta ptr2 + sta ptr4 + lda Y1+1 + sta ptr2+1 + sta ptr4+1 + + lda X1 + sta ptr1 + lda X1+1 + sta ptr1+1 + + lda X2 + sta ptr3 + lda X2+1 + sta ptr3+1 + jmp @L1 + +@L4: rts + +;----------------------------------------------------------------------------- +; Data + +.bss + +DY: .res 2 +X1: .res 2 +X2: .res 2 +Y1: .res 2 +Y2: .res 2 + + + diff --git a/libsrc/tgi/tgi_getcolorcount.s b/libsrc/tgi/tgi_getcolorcount.s new file mode 100644 index 000000000..8059e2d3b --- /dev/null +++ b/libsrc/tgi/tgi_getcolorcount.s @@ -0,0 +1,15 @@ +; +; Ullrich von Bassewitz, 22.06.2002 +; +; unsigned char __fastcall__ tgi_getcolorcount (void); +; /* Get the number of available colors */ + + .include "tgi-kernel.inc" + .export _tgi_getcolorcount + + +_tgi_getcolorcount: + lda _tgi_colors + ldx #0 + rts + diff --git a/libsrc/tgi/tgi_getmaxcolor.s b/libsrc/tgi/tgi_getmaxcolor.s new file mode 100644 index 000000000..dda4fb243 --- /dev/null +++ b/libsrc/tgi/tgi_getmaxcolor.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 22.06.2002 +; +; 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 + dex + txa + ldx #0 + rts + + + diff --git a/libsrc/tgi/tgi_setcolor.s b/libsrc/tgi/tgi_setcolor.s index abf054abc..0d430f76a 100644 --- a/libsrc/tgi/tgi_setcolor.s +++ b/libsrc/tgi/tgi_setcolor.s @@ -6,9 +6,13 @@ .include "tgi-kernel.inc" - + .include "tgi-error.inc" .export _tgi_setcolor -_tgi_setcolor = tgi_setcolor ; Call the driver - +_tgi_setcolor: + cmp _tgi_colors ; Compare to available colors + bcs @L1 + jmp tgi_setcolor ; Call the driver +@L1: jmp tgi_inv_arg ; Invalid argument + diff --git a/libsrc/tgi/tgi_setdrawpage.s b/libsrc/tgi/tgi_setdrawpage.s new file mode 100644 index 000000000..90522580e --- /dev/null +++ b/libsrc/tgi/tgi_setdrawpage.s @@ -0,0 +1,18 @@ +; +; Ullrich von Bassewitz, 22.06.2002 +; +; void __fastcall__ tgi_setdrawpage (unsigned char page); +; /* Set the drawable page */ + + + .include "tgi-kernel.inc" + .export _tgi_setdrawpage + +_tgi_setdrawpage: + cmp _tgi_pagecount ; Compare to available pages + bcs @L1 + jmp tgi_setdrawpage ; Call the driver +@L1: jmp tgi_inv_arg ; Invalid argument + + + diff --git a/libsrc/tgi/tgi_setviewpage.s b/libsrc/tgi/tgi_setviewpage.s new file mode 100644 index 000000000..d8fdb54ba --- /dev/null +++ b/libsrc/tgi/tgi_setviewpage.s @@ -0,0 +1,18 @@ +; +; Ullrich von Bassewitz, 22.06.2002 +; +; void __fastcall__ tgi_setviewpage (unsigned char page); +; /* Set the visible page. */ + + + + .include "tgi-kernel.inc" + .export _tgi_setviewpage + +_tgi_setviewpage: + cmp _tgi_pagecount ; Compare to available pages + bcs @L1 + jmp tgi_setviewpage ; Call the driver +@L1: jmp tgi_inv_arg ; Invalid argument + +