From: uz Date: Sun, 17 Jul 2011 18:36:12 +0000 (+0000) Subject: Renamed tgi_textheight -> tgi_gettextheight, tgi_textwidth -> tgi_gettextwidth X-Git-Tag: V2.13.3~372 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9c555865692992e9c452b4c8d6b4c451add60f45;p=cc65 Renamed tgi_textheight -> tgi_gettextheight, tgi_textwidth -> tgi_gettextwidth tgi_textstyle -> tgi_settextstyle and tgi_textscale -> tgi_settextscale. git-svn-id: svn://svn.cc65.org/cc65/trunk@5090 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/asminc/tgi-kernel.inc b/asminc/tgi-kernel.inc index 9dd0dd453..15a32e8bf 100644 --- a/asminc/tgi-kernel.inc +++ b/asminc/tgi-kernel.inc @@ -134,6 +134,7 @@ TGI_CLIP_TOP = $08 .global _tgi_fontwidth ; System font width .global _tgi_fontheight ; System font height .global _tgi_aspectratio ; Aspect ratio, fixed point 8.8 + .global _tgi_flags ; TGI driver flags ;------------------------------------------------------------------------------ ; ASM accessible variables @@ -202,6 +203,8 @@ TGI_CLIP_TOP = $08 .global _tgi_getpagecount .global _tgi_getpalette .global _tgi_getpixel + .global _tgi_gettextheight + .global _tgi_gettextwidth .global _tgi_getxres .global _tgi_getyres .global _tgi_gotoxy @@ -221,10 +224,8 @@ TGI_CLIP_TOP = $08 .global _tgi_setdrawpage .global _tgi_setpalette .global _tgi_setpixel + .global _tgi_settextscale + .global _tgi_settextstyle .global _tgi_setviewpage - .global _tgi_textheight - .global _tgi_textscale - .global _tgi_textstyle - .global _tgi_textwidth .global _tgi_uninstall .global _tgi_unload diff --git a/include/tgi.h b/include/tgi.h index 90f8f2e85..bd312dc63 100644 --- a/include/tgi.h +++ b/include/tgi.h @@ -228,25 +228,25 @@ void __fastcall__ tgi_pieslice (int x, int y, unsigned char rx, unsigned char ry 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_textscale (unsigned width, unsigned height); +void __fastcall__ tgi_settextscale (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); +void __fastcall__ tgi_settextstyle (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); +unsigned __fastcall__ tgi_gettextwidth (const char* s); /* Calculate the width of the text in pixels according to the current text * style. */ -unsigned __fastcall__ tgi_textheight (const char* s); +unsigned __fastcall__ tgi_gettextheight (const char* s); /* Calculate the height of the text in pixels according to the current text * style. */ diff --git a/libsrc/tgi/Makefile b/libsrc/tgi/Makefile index 904c61212..e84d88b17 100644 --- a/libsrc/tgi/Makefile +++ b/libsrc/tgi/Makefile @@ -56,6 +56,8 @@ S_OBJS = tgi-kernel.o \ tgi_getpalette.o \ tgi_getpixel.o \ tgi_getset.o \ + tgi_gettextheight.o \ + tgi_gettextwidth.o \ tgi_getxres.o \ tgi_getyres.o \ tgi_gotoxy.o \ @@ -76,10 +78,8 @@ S_OBJS = tgi-kernel.o \ tgi_setdrawpage.o \ tgi_setpalette.o \ tgi_setpixel.o \ + tgi_settextstyle.o \ tgi_setviewpage.o \ - tgi_textheight.o \ - tgi_textwidth.o \ - tgi_textstyle.o \ tgi_unload.o \ tgi_vectorchar.o diff --git a/libsrc/tgi/tgi_gettextheight.s b/libsrc/tgi/tgi_gettextheight.s new file mode 100644 index 000000000..8daad941b --- /dev/null +++ b/libsrc/tgi/tgi_gettextheight.s @@ -0,0 +1,52 @@ +; +; Ullrich von Bassewitz, 2009-10-30 +; + + + .include "tgi-kernel.inc" + .include "tgi-vectorfont.inc" + .include "zeropage.inc" + + +;----------------------------------------------------------------------------- +; unsigned __fastcall__ tgi_gettextheight (const char* s); +; /* Calculate the height of the text in pixels according to the current text +; * style. +; */ +; + +.proc _tgi_gettextheight + + ldy _tgi_font + bne @L2 ; Jump if vector font + +; Return the height for the bitmap font + + lda _tgi_charheight + ldx #0 +@L1: rts + +; Return the height for the vector font + +@L2: lda _tgi_vectorfont + tax + ora _tgi_vectorfont+1 + beq @L1 ; Return zero if no font + + stx ptr1 + lda _tgi_vectorfont+1 + sta ptr1+1 + ldy #TGI_VECTORFONT::HEIGHT + lda (ptr1),y ; Get height of font + + sta ptr1 + lda #0 + sta ptr1+1 ; Save base height in ptr1 + + lda _tgi_textscaleh + ldx _tgi_textscaleh+1 ; Get scale factor ... + jmp tgi_imulround ; ... and return scaled result + +.endproc + + diff --git a/libsrc/tgi/tgi_gettextwidth.s b/libsrc/tgi/tgi_gettextwidth.s new file mode 100644 index 000000000..9b39fb6a6 --- /dev/null +++ b/libsrc/tgi/tgi_gettextwidth.s @@ -0,0 +1,103 @@ +; +; Ullrich von Bassewitz, 2009-10-30 +; + + + .include "tgi-kernel.inc" + .include "tgi-vectorfont.inc" + .include "zeropage.inc" + + .import _strlen, _toascii + .import umul8x16r16 + +;----------------------------------------------------------------------------- +; Aliases for zero page locations + +Width := ptr1 +WTab := ptr2 +Text := ptr3 + + + +;----------------------------------------------------------------------------- +; unsigned __fastcall__ tgi_gettextwidth (const char* s); +; /* Calculate the width of the text in pixels according to the current text +; * style. +; */ +; +; Result is strlen (s) * tgi_textmagw * tgi_fontsizex +; + +.code +.proc _tgi_gettextwidth + + ldy _tgi_font + bne @L1 ; Jump if vector font + +; Return the width of the string for the bitmap font + + ldy _tgi_charwidth + sta ptr1 + jsr _strlen + jsr umul8x16r16 + ldy _tgi_textscalew+2 ; Get rounded scale factor + sty ptr1 + jmp umul8x16r16 + +; Return the width of the string for the vector font. To save some code, we +; will add up all the character widths and then multiply by the scale factor. +; Since the output routine will scale each single character, the result may +; be slightly different. + +@L1: sta Text + stx Text+1 ; Save pointer to string + + lda _tgi_vectorfont+1 + tax + ora _tgi_vectorfont + beq @L9 ; Return zero if no font + + lda _tgi_vectorfont + clc + adc #<(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR) + sta WTab + txa + adc #>(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR) + sta WTab+1 + + ldy #0 + sty Width + sty Width+1 ; Zero the total width + +; Sum up the widths of the single characters + +@L2: ldy #0 + lda (Text),y ; Get next char + beq @L4 ; Bail out if end of text reached + jsr _toascii ; Convert to ascii + tay + lda (WTab),y ; Get width of this char + clc + adc Width + sta Width + bcc @L3 + inc Width+1 +@L3: inc Text + bne @L2 + inc Text+1 + bne @L2 + +; We have the total width now, scale and return it + +@L4: lda _tgi_textscalew + ldx _tgi_textscalew+1 + jmp tgi_imulround + +; Exit point if no font installed + +@L9: rts + +.endproc + + + diff --git a/libsrc/tgi/tgi_init.s b/libsrc/tgi/tgi_init.s index 14e1bd9f9..2100d06e1 100644 --- a/libsrc/tgi/tgi_init.s +++ b/libsrc/tgi/tgi_init.s @@ -65,7 +65,7 @@ jsr pushax ; Width scale = 1.0 jsr pushax ; Heigh scale = 1.0 jsr pusha ; Text direction = TGI_TEXT_HORIZONTAL - jmp _tgi_textstyle ; A = Font = TGI_FONT_BITMAP + jmp _tgi_settextstyle ; A = Font = TGI_FONT_BITMAP ; Error exit diff --git a/libsrc/tgi/tgi_outtext.s b/libsrc/tgi/tgi_outtext.s index 76fbf78ad..079cea3af 100644 --- a/libsrc/tgi/tgi_outtext.s +++ b/libsrc/tgi/tgi_outtext.s @@ -25,35 +25,35 @@ widths := regbank+2 .proc _tgi_outtext - ldy _tgi_font ; Bit or vectorfont? + ldy _tgi_font ; Bit or vectorfont? bne VectorFont ; Handle bitmapped font output sta ptr3 - stx ptr3+1 ; Pass s in ptr3 to driver + stx ptr3+1 ; Pass s in ptr3 to driver pha txa - pha ; Save s on stack for later + pha ; Save s on stack for later - jsr tgi_curtoxy ; Copy curx/cury into ptr1/ptr2 - jsr tgi_outtext ; Call the driver + jsr tgi_curtoxy ; Copy curx/cury into ptr1/ptr2 + jsr tgi_outtext ; Call the driver pla tax - pla ; Restore s - jsr _tgi_textwidth ; Get width of text string + pla ; Restore s + jsr _tgi_gettextwidth ; Get width of text string ; Move the graphics cursor by the amount in a/x MoveCursor: - ldy _tgi_textdir ; Horizontal or vertical text? - beq @L1 ; Jump if horizontal + ldy _tgi_textdir ; Horizontal or vertical text? + beq @L1 ; Jump if horizontal ; Move graphics cursor for vertical text jsr negax - ldy #2 ; Point to _tgi_cury + ldy #2 ; Point to _tgi_cury ; Move graphics cursor for horizontal text @@ -125,7 +125,7 @@ VectorFont: jsr MoveCursor ; Move the graphics cursor ; Next char in string - + inc text bne @L1 inc text+1 diff --git a/libsrc/tgi/tgi_settextstyle.s b/libsrc/tgi/tgi_settextstyle.s new file mode 100644 index 000000000..ba3cb188b --- /dev/null +++ b/libsrc/tgi/tgi_settextstyle.s @@ -0,0 +1,106 @@ +; +; Ullrich von Bassewitz, 2009-10-30 +; + + + .include "zeropage.inc" + .include "tgi-kernel.inc" + + .import umul8x16r24 + .import popa, popax + + .macpack cpu + +;----------------------------------------------------------------------------- +; void __fastcall__ tgi_settextstyle (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_settextstyle + + sta _tgi_font ; Remember the font to use + jsr popa + sta _tgi_textdir ; Remember the direction + +; Pop the height and run directly into tgi_textscale + + jsr popax + +.endproc + +;----------------------------------------------------------------------------- +; void __fastcall__ tgi_settextscale (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_settextscale + +; Setup the height + + ldy _tgi_fontheight ; Get height of bitmap font in pixels + sty ptr1 ; Save for later + ldy #6 ; Address the height + jsr process_onedim ; Process height + +; Setup the width + + jsr popax ; Get width scale into a/x + ldy _tgi_fontwidth ; Get width of bitmap font in pixels + sty ptr1 ; Save for later + ldy #0 ; Address the width + +; Process one character dimension. That means: +; +; - Store the vector font dimension in 8.8 format +; - If necessary, round up/down to next integer +; - Store the bitmap font dimension in 8.8 format +; - Multiply by size of bitmap char in pixels +; - Store the bitmap font size in 8.8 format +; + +process_onedim: + + jsr store ; Store vector font scale factor + bit _tgi_flags ; Fine grained scaling support avail? + bmi @L2 ; Jump if yes + + asl a ; Round to nearest full integer + bcc @L1 + inx +@L1: lda #0 + +@L2: jsr store ; Store bitmap font scale factor + +; The size of the font in pixels in the selected dimension is already in ptr1 +; So if we call umul8x16r24 we get the size in pixels in 16.8 fixed point. +; Disallowing characters larger than 256 pixels, we just drop the high byte +; and remember the low 16 bit as size in 8.8 format. + +.if (.cpu .bitand ::CPU_ISET_65SC02) + phy ; Save Y + jsr umul8x16r24 + ply ; Restore Y +.else + sty tmp1 ; Save Y + jsr umul8x16r24 + ldy tmp1 ; Restore Y +.endif + +store: sta _tgi_textscalew,y + iny + pha + txa + sta _tgi_textscalew,y + iny + pla + rts + +.endproc + + diff --git a/libsrc/tgi/tgi_textheight.s b/libsrc/tgi/tgi_textheight.s deleted file mode 100644 index 7e0aee935..000000000 --- a/libsrc/tgi/tgi_textheight.s +++ /dev/null @@ -1,52 +0,0 @@ -; -; Ullrich von Bassewitz, 2009-10-30 -; - - - .include "tgi-kernel.inc" - .include "tgi-vectorfont.inc" - .include "zeropage.inc" - - -;----------------------------------------------------------------------------- -; unsigned __fastcall__ tgi_textheight (const char* s); -; /* Calculate the height of the text in pixels according to the current text -; * style. -; */ -; - -.proc _tgi_textheight - - ldy _tgi_font - bne @L2 ; Jump if vector font - -; Return the height for the bitmap font - - lda _tgi_charheight - ldx #0 -@L1: rts - -; Return the height for the vector font - -@L2: lda _tgi_vectorfont - tax - ora _tgi_vectorfont+1 - beq @L1 ; Return zero if no font - - stx ptr1 - lda _tgi_vectorfont+1 - sta ptr1+1 - ldy #TGI_VECTORFONT::HEIGHT - lda (ptr1),y ; Get height of font - - sta ptr1 - lda #0 - sta ptr1+1 ; Save base height in ptr1 - - lda _tgi_textscaleh - ldx _tgi_textscaleh+1 ; Get scale factor ... - jmp tgi_imulround ; ... and return scaled result - -.endproc - - diff --git a/libsrc/tgi/tgi_textstyle.s b/libsrc/tgi/tgi_textstyle.s deleted file mode 100644 index 8b65057c8..000000000 --- a/libsrc/tgi/tgi_textstyle.s +++ /dev/null @@ -1,106 +0,0 @@ -; -; Ullrich von Bassewitz, 2009-10-30 -; - - - .include "zeropage.inc" - .include "tgi-kernel.inc" - - .import umul8x16r24 - .import popa, popax - - .macpack cpu - -;----------------------------------------------------------------------------- -; 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 - -; 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 - -; Setup the height - - ldy _tgi_fontheight ; Get height of bitmap font in pixels - sty ptr1 ; Save for later - ldy #6 ; Address the height - jsr process_onedim ; Process height - -; Setup the width - - jsr popax ; Get width scale into a/x - ldy _tgi_fontwidth ; Get width of bitmap font in pixels - sty ptr1 ; Save for later - ldy #0 ; Address the width - -; Process one character dimension. That means: -; -; - Store the vector font dimension in 8.8 format -; - If necessary, round up/down to next integer -; - Store the bitmap font dimension in 8.8 format -; - Multiply by size of bitmap char in pixels -; - Store the bitmap font size in 8.8 format -; - -process_onedim: - - jsr store ; Store vector font scale factor - bit _tgi_flags ; Fine grained scaling support avail? - bmi @L2 ; Jump if yes - - asl a ; Round to nearest full integer - bcc @L1 - inx -@L1: lda #0 - -@L2: jsr store ; Store bitmap font scale factor - -; The size of the font in pixels in the selected dimension is already in ptr1 -; So if we call umul8x16r24 we get the size in pixels in 16.8 fixed point. -; Disallowing characters larger than 256 pixels, we just drop the high byte -; and remember the low 16 bit as size in 8.8 format. - -.if (.cpu .bitand ::CPU_ISET_65SC02) - phy ; Save Y - jsr umul8x16r24 - ply ; Restore Y -.else - sty tmp1 ; Save Y - jsr umul8x16r24 - ldy tmp1 ; Restore Y -.endif - -store: sta _tgi_textscalew,y - iny - pha - txa - sta _tgi_textscalew,y - iny - pla - rts - -.endproc - - diff --git a/libsrc/tgi/tgi_textwidth.s b/libsrc/tgi/tgi_textwidth.s deleted file mode 100644 index b75468114..000000000 --- a/libsrc/tgi/tgi_textwidth.s +++ /dev/null @@ -1,103 +0,0 @@ -; -; Ullrich von Bassewitz, 2009-10-30 -; - - - .include "tgi-kernel.inc" - .include "tgi-vectorfont.inc" - .include "zeropage.inc" - - .import _strlen, _toascii - .import umul8x16r16 - -;----------------------------------------------------------------------------- -; Aliases for zero page locations - -Width := ptr1 -WTab := ptr2 -Text := ptr3 - - - -;----------------------------------------------------------------------------- -; unsigned __fastcall__ tgi_textwidth (const char* s); -; /* Calculate the width of the text in pixels according to the current text -; * style. -; */ -; -; Result is strlen (s) * tgi_textmagw * tgi_fontsizex -; - -.code -.proc _tgi_textwidth - - ldy _tgi_font - bne @L1 ; Jump if vector font - -; Return the width of the string for the bitmap font - - ldy _tgi_charwidth - sta ptr1 - jsr _strlen - jsr umul8x16r16 - ldy _tgi_textscalew+2 ; Get rounded scale factor - sty ptr1 - jmp umul8x16r16 - -; Return the width of the string for the vector font. To save some code, we -; will add up all the character widths and then multiply by the scale factor. -; Since the output routine will scale each single character, the result may -; be slightly different. - -@L1: sta Text - stx Text+1 ; Save pointer to string - - lda _tgi_vectorfont+1 - tax - ora _tgi_vectorfont - beq @L9 ; Return zero if no font - - lda _tgi_vectorfont - clc - adc #<(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR) - sta WTab - txa - adc #>(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR) - sta WTab+1 - - ldy #0 - sty Width - sty Width+1 ; Zero the total width - -; Sum up the widths of the single characters - -@L2: ldy #0 - lda (Text),y ; Get next char - beq @L4 ; Bail out if end of text reached - jsr _toascii ; Convert to ascii - tay - lda (WTab),y ; Get width of this char - clc - adc Width - sta Width - bcc @L3 - inc Width+1 -@L3: inc Text - bne @L2 - inc Text+1 - bne @L2 - -; We have the total width now, scale and return it - -@L4: lda _tgi_textscalew - ldx _tgi_textscalew+1 - jmp tgi_imulround - -; Exit point if no font installed - -@L9: rts - -.endproc - - -