From 87866e3099e43668530bba22efc2796f9a293499 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 2 Nov 2009 22:29:49 +0000 Subject: [PATCH] Working on the TGI API, adding vector fonts. Only roughly tested! git-svn-id: svn://svn.cc65.org/cc65/trunk@4432 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- asminc/tgi-kernel.inc | 8 +- include/tgi.h | 13 ++- include/tgi/tgi-vectorfont.h | 13 +++ libsrc/tgi/Makefile | 3 +- libsrc/tgi/tgi-kernel.s | 5 +- libsrc/tgi/tgi_init.s | 5 +- libsrc/tgi/tgi_textstyle.s | 57 ++++++++---- libsrc/tgi/tgi_vectorchar.s | 174 +++++++++++++++++++++++++++++++++++ 8 files changed, 247 insertions(+), 31 deletions(-) create mode 100644 libsrc/tgi/tgi_vectorchar.s diff --git a/asminc/tgi-kernel.inc b/asminc/tgi-kernel.inc index 4b6215a02..410293e79 100644 --- a/asminc/tgi-kernel.inc +++ b/asminc/tgi-kernel.inc @@ -79,7 +79,7 @@ TGI_API_VERSION = $03 ;------------------------------------------------------------------------------ ; Color and text constants - + TGI_COLOR_BLACK = 0 TGI_COLOR_WHITE = 1 @@ -98,9 +98,10 @@ TGI_TEXT_VERTICAL = 1 .global _tgi_curx ; Current drawing cursor X .global _tgi_cury ; Current drawing cursor Y .global _tgi_color ; Current drawing color + .global _tgi_font ; Which font to use .global _tgi_textdir ; Current text direction - .global _tgi_textmagw ; Text magnification for the width - .global _tgi_textmagh ; Text magnification for the height + .global _tgi_textscalew ; Text magnification for the width + .global _tgi_textscaleh ; Text magnification for the height .global _tgi_charwidth ; Width of scaled system font char .global _tgi_charheight ; Height of scaled system font char .global _tgi_xres ; X resolution of the current mode @@ -181,6 +182,7 @@ TGI_TEXT_VERTICAL = 1 .global _tgi_lineto .global _tgi_circle .global _tgi_bar + .global _tgi_textscale .global _tgi_textstyle .global _tgi_textwidth .global _tgi_textheight diff --git a/include/tgi.h b/include/tgi.h index 2999c1ad0..589ad12cc 100644 --- a/include/tgi.h +++ b/include/tgi.h @@ -216,12 +216,19 @@ void __fastcall__ tgi_circle (int x, int y, unsigned char radius); void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2); /* Draw a bar (a filled rectangle) using the current color. */ -void __fastcall__ tgi_textstyle (unsigned magwidth, unsigned magheight, - unsigned char dir); -/* Set the style for text output. The scaling factors for width and height +void __fastcall__ tgi_textscale (unsigned width, unsigned height); +/* Set the scaling for text output. The scaling factors for width and height * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc. */ +void __fastcall__ tgi_textstyle (unsigned width, unsigned height, + unsigned char dir, unsigned char font); +/* Set the style for text output. The scaling factors for width and height + * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc. + * dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX + * constants. + */ + unsigned __fastcall__ tgi_textwidth (const char* s); /* Calculate the width of the text in pixels according to the current text * style. diff --git a/include/tgi/tgi-vectorfont.h b/include/tgi/tgi-vectorfont.h index 73a5bf5f1..6801b7b34 100644 --- a/include/tgi/tgi-vectorfont.h +++ b/include/tgi/tgi-vectorfont.h @@ -70,6 +70,19 @@ struct tgi_vectorfont { +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void __fastcall__ tgi_vectorchar (const unsigned char* Ops); +/* Draw one character of the vector font at the current graphics cursor + * position using the current font magnification. + */ + + + /* End of tgi-vectorfont.h */ #endif diff --git a/libsrc/tgi/Makefile b/libsrc/tgi/Makefile index 6f7b955b3..c24b00c52 100644 --- a/libsrc/tgi/Makefile +++ b/libsrc/tgi/Makefile @@ -76,7 +76,8 @@ S_OBJS = tgi-kernel.o \ tgi_textheight.o \ tgi_textwidth.o \ tgi_textstyle.o \ - tgi_unload.o + tgi_unload.o \ + tgi_vectorchar.o #-------------------------------------------------------------------------- diff --git a/libsrc/tgi/tgi-kernel.s b/libsrc/tgi/tgi-kernel.s index fa926895f..9eb697b6a 100644 --- a/libsrc/tgi/tgi-kernel.s +++ b/libsrc/tgi/tgi-kernel.s @@ -22,13 +22,14 @@ _tgi_gmode: .res 1 ; Flag: Graphics mode active _tgi_curx: .res 2 ; Current drawing cursor X _tgi_cury: .res 2 ; Current drawing cursor Y _tgi_color: .res 1 ; Current drawing color +_tgi_font: .res 1 ; Which font to use _tgi_textdir: .res 1 ; Current text direction ; The following two store an 8.8 fixed point value in the first two bytes, ; and a rounded integer value in the third byte. The latter is passed to the ; driver to scale the bitmap font. The variables are expected to be in ; this order and adjacent. -_tgi_textmagw: .res 3 ; Text magnification for the width -_tgi_textmagh: .res 3 ; Text magnification for the height +_tgi_textscalew: .res 3 ; Text scale for the width +_tgi_textscaleh: .res 3 ; Text scale for the height ; The following two must also be in exactly this order _tgi_charwidth: .res 1 ; Char width of system font diff --git a/libsrc/tgi/tgi_init.s b/libsrc/tgi/tgi_init.s index 5aab06a83..65e6e2d98 100644 --- a/libsrc/tgi/tgi_init.s +++ b/libsrc/tgi/tgi_init.s @@ -8,7 +8,7 @@ .include "tgi-kernel.inc" .include "tgi-error.inc" - .import pushax + .import pushax, pusha .importzp ptr1 .proc _tgi_init @@ -48,7 +48,8 @@ ldx #>$100 jsr pushax ; Width scale jsr pushax ; Heigh scale - jsr _tgi_textstyle ; A = Direction = TEXT_VERTICAL + jsr pusha ; Text direction = TGI_TEXT_VERTICAL + jsr _tgi_textstyle ; A = Font = TGI_FONT_BITMAP ; Clear the screen diff --git a/libsrc/tgi/tgi_textstyle.s b/libsrc/tgi/tgi_textstyle.s index 501b02340..47a58a380 100644 --- a/libsrc/tgi/tgi_textstyle.s +++ b/libsrc/tgi/tgi_textstyle.s @@ -1,16 +1,11 @@ ; -; Ullrich von Bassewitz, 2009-20-30 +; Ullrich von Bassewitz, 2009-10-30 ; -; void __fastcall__ tgi_textstyle (unsigned magwidth, unsigned magheight, -; unsigned char dir); -; /* Set the style for text output. The scaling factors for width and height -; * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc. -; */ .include "tgi-kernel.inc" - .import popax + .import popa, popax ;----------------------------------------------------------------------------- @@ -32,40 +27,61 @@ .endproc - ;----------------------------------------------------------------------------- +; void __fastcall__ tgi_textstyle (unsigned width, unsigned height, +; unsigned char dir, unsigned char font); +; /* Set the style for text output. The scaling factors for width and height +; * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc. +; * dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX +; * constants. +; */ ; .proc _tgi_textstyle + sta _tgi_font ; Remember the font to use + jsr popa sta _tgi_textdir ; Remember the direction -; The magheight value is in 8.8 fixed point. Store it and calculate a rounded +; Pop the height and run directly into tgi_textscale + + jsr popax + +.endproc + +;----------------------------------------------------------------------------- +; void __fastcall__ tgi_textscale (unsigned width, unsigned height); +; /* Set the scaling for text output. The scaling factors for width and height +; * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc. +; */ + +.proc _tgi_textscale + +; The height value is in 8.8 fixed point. Store it and calculate a rounded ; value for scaling the bitmapped system font in the driver. - jsr popax ; magheight - sta _tgi_textmagh+0 - stx _tgi_textmagh+1 + sta _tgi_textscaleh+0 + stx _tgi_textscaleh+1 asl a ; Check value behind comma bcc @L1 inx ; Round -@L1: stx _tgi_textmagh+2 ; Store rounded value +@L1: stx _tgi_textscaleh+2 ; Store rounded value ; Calculate the total height of the bitmapped font and remember it. ldy #1 jsr charsize_helper -; The magwidth value is in 8.8 fixed point. Store it and calculate a rounded +; The width value is in 8.8 fixed point. Store it and calculate a rounded ; value for scaling the bitmapped system font in the driver. - jsr popax ; magheight - sta _tgi_textmagw+0 - stx _tgi_textmagw+1 + jsr popax ; height + sta _tgi_textscalew+0 + stx _tgi_textscalew+1 asl a ; Check value behind comma bcc @L2 inx ; Round -@L2: stx _tgi_textmagw+2 ; Store rounded value +@L2: stx _tgi_textscalew+2 ; Store rounded value ; Calculate the total width of the bitmapped font and remember it. @@ -74,10 +90,11 @@ ; Load values and call the driver, parameters are passed in registers - ldx _tgi_textmagw+2 - ldy _tgi_textmagh+2 + ldx _tgi_textscalew+2 + ldy _tgi_textscaleh+2 lda _tgi_textdir jmp tgi_textstyle .endproc + diff --git a/libsrc/tgi/tgi_vectorchar.s b/libsrc/tgi/tgi_vectorchar.s new file mode 100644 index 000000000..dafef75b2 --- /dev/null +++ b/libsrc/tgi/tgi_vectorchar.s @@ -0,0 +1,174 @@ +; +; Ullrich von Bassewitz, 2009-11-02 +; +; void __fastcall__ tgi_vectorchar (const unsigned char* Ops); +; /* Draw one character of the vector font at the current graphics cursor +; * position using the current font magnification. +; */ +; + + .export _tgi_vectorchar + + .import push0ax, tosmuleax + + .include "tgi-kernel.inc" + .include "zeropage.inc" + + +;---------------------------------------------------------------------------- +; Data + +Ops = regbank +Flag = regbank+2 + +.bss +X1: .res 2 +Y1: .res 2 +X2: .res 2 +Y2: .res 2 + + + +;---------------------------------------------------------------------------- +; + +.code +.proc _tgi_vectorchar + +; Since we will call tgi_lineto, which uses the zero page, and we do also +; need the zero page, make room in the register bank. + + tay + lda Ops + pha + lda Ops+1 + pha + lda Flag + pha + +; Save the pointer + + sty Ops + stx Ops+1 + +; Main loop executing vector operations + +Loop: lda _tgi_textscalew+0 + ldx _tgi_textscalew+1 + jsr GetProcessedCoord + +; X2 = tgi_curx + XMag * XDelta. + + clc + adc _tgi_curx+0 + sta X2+0 + txa + adc _tgi_curx+1 + sta X2+1 + +; Process the Y value + + lda _tgi_textscaleh+0 + ldx _tgi_textscaleh+1 + jsr GetProcessedCoord + +; Y2 = tgi_cury - YMag * YDelta; +; Y2 = tgi_cury + (~(YMag * YDelta) + 1); + + eor #$FF + sec ; + 1 + adc _tgi_cury+0 + sta Y2+0 + txa + eor #$FF + adc _tgi_cury+1 + sta Y2+1 + +; Do the actual operation + + bit Flag + bpl @Move ; Jump if move only + + ldy #7 ; Copy start coords into zp +: lda X1,y + sta ptr1,y + dey + bpl :- + + jsr tgi_line ; Call the driver + +; Move the start position + +@Move: ldy #3 +: lda X2,y + sta X1,y + dey + bpl :- + +; Loop if not done + + bit Flag + bvc Loop + +; Done. Restore zp and return. + +@Done: pla + sta Flag + pla + sta Ops+1 + pla + sta Ops + rts + +.endproc + +;---------------------------------------------------------------------------- +; Get and process one coordinate value. The scale factor is passed in a/x + +.proc GetProcessedCoord + +; Push the scale factor + + jsr push0ax + +; Load delta value + + ldy #0 + lda (Ops),y + inc Ops + bne :+ + inc Ops+1 + +; Move bit 7 into Flag + +: asl a ; Flag into carry + ror Flag + +; Sign extend the value + + ldx #0 + cmp #$80 ; Sign bit into carry + bcc :+ + dex +: ror a ; Sign extend the value + +; Multiplicate with the scale factor. + + stx sreg + stx sreg+1 + jsr tosmuleax ; Multiplicate + +; The result is a 16.8 fixed point value. Round and return it. + + cmp #$80 ; Check digits after the dec point + txa + adc #$00 + tay + lda sreg + adc #$00 + tax + tya + rts + +.endproc + -- 2.39.5