;* */
;* */
;* */
-;* (C) 2002-2004 Ullrich von Bassewitz */
-;* Römerstraße 52 */
-;* D-70794 Filderstadt */
-;* EMail: uz@cc65.org */
+;* (C) 2002-2009, Ullrich von Bassewitz */
+;* Roemerstrasse 52 */
+;* D-70794 Filderstadt */
+;* EMail: uz@cc65.org */
;* */
;* */
;* This software is provided 'as-is', without any expressed or implied */
YRES .word 1 ; Y resolution
COLORCOUNT .byte 1 ; Number of available colors
PAGECOUNT .byte 1 ; Number of screens available
- FONTSIZE_X .byte 1 ; System font size in X direction
- FONTSIZE_Y .byte 1 ; System font size in Y direction
+ FONTWIDTH .byte 1 ; System font width
+ FONTHEIGHT .byte 1 ; System font height
ASPECTRATIO .word 1 ; Fixed point 8.8 format
.endstruct
JUMPTAB .struct
.global _tgi_cury ; Current drawing cursor Y
.global _tgi_color ; Current drawing color
.global _tgi_textdir ; Current text direction
- .global _tgi_textmagx ; Text magnification in X dir
- .global _tgi_textmagy ; Text magnification in Y dir
+ .global _tgi_textmagw ; Text magnification for the width
+ .global _tgi_textmagh ; 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
.global _tgi_yres ; Y resolution of the current mode
.global _tgi_colorcount ; Number of available colors
.global _tgi_pagecount ; Number of available screen pages
- .global _tgi_fontsizex ; System font X size
- .global _tgi_fontsizey ; System font Y size
+ .global _tgi_fontwidth ; System font width
+ .global _tgi_fontheight ; System font height
.global _tgi_aspectratio ; Aspect ratio, fixed point 8.8
;------------------------------------------------------------------------------
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 char magx, unsigned char magy,
+void __fastcall__ tgi_textstyle (unsigned magwidth, unsigned magheight,
unsigned char dir);
-/* Set the style for text output. */
+/* 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.
+ */
unsigned __fastcall__ tgi_textwidth (const char* s);
/* Calculate the width of the text in pixels according to the current text
tgi_setviewpage.o \
tgi_stddrv.o \
tgi_stdmode.o \
- tgi_textsize.o \
+ tgi_textheight.o \
+ tgi_textwidth.o \
tgi_textstyle.o \
tgi_unload.o
_tgi_cury: .res 2 ; Current drawing cursor Y
_tgi_color: .res 1 ; Current drawing color
_tgi_textdir: .res 1 ; Current text direction
-_tgi_textmagx: .res 1 ; Text magnification in X dir
-_tgi_textmagy: .res 1 ; Text magnification in Y dir
+; 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
+
+; The following two must also be in exactly this order
+_tgi_charheight: .res 1 ; Char height of system font
+_tgi_charwidth: .res 1 ; Char width of system font
; The following variables are copied from the driver header for faster access
+; fontwidth and fontheight are expected to be in order and adjacent.
tgi_driver_vars:
_tgi_xres: .res 2 ; X resolution of the current mode
_tgi_yres: .res 2 ; Y resolution of the current mode
_tgi_colorcount: .res 1 ; Number of available colors
_tgi_pagecount: .res 1 ; Number of available screen pages
-_tgi_fontsizex: .res 1 ; System font X size
-_tgi_fontsizey: .res 1 ; System font Y size
+_tgi_fontwidth: .res 1 ; System font width in pixels
+_tgi_fontheight: .res 1 ; System font height in pixels
_tgi_aspectratio: .res 2 ; Aspect ratio in 8.8 fixed point
.include "tgi-kernel.inc"
.include "tgi-error.inc"
+ .import pushax
.importzp ptr1
.proc _tgi_init
; Set the text style
- lda #TGI_TEXT_HORIZONTAL
- sta _tgi_textdir
- ldx #1
- stx _tgi_textmagx
- ldy #1
- sty _tgi_textmagy
- jsr tgi_textstyle ; Tell the driver about the text style
+ lda #<$100
+ ldx #>$100
+ jsr pushax ; Width scale
+ jsr pushax ; Heigh scale
+ jsr _tgi_textstyle ; A = Direction = TEXT_VERTICAL
; Clear the screen
.include "tgi-kernel.inc"
- .import popax
+ .import popax, negax
.importzp ptr3
.proc _tgi_outtext
sta ptr3
- stx ptr3+1 ; Save s
+ stx ptr3+1 ; Pass s in ptr3 to driver
+ pha
+ txa
+ pha ; Save s on stack for later
+
jsr tgi_curtoxy ; Copy curx/cury into ptr1/ptr2
- jmp tgi_outtext ; Call the driver
+ jsr tgi_outtext ; Call the driver
+
+ pla
+ tax
+ pla ; Restore s
+ jsr _tgi_textwidth ; Get width of text string
+ 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
+
+; Move graphics cursor for horizontal text
+
+@L1: clc
+ adc _tgi_curx,y
+ sta _tgi_curx,y
+ txa
+ adc _tgi_curx+1,y
+ sta _tgi_curx+1,y
+ rts
.endproc
--- /dev/null
+;
+; Ullrich von Bassewitz, 2009-10-30
+;
+
+
+ .include "tgi-kernel.inc"
+
+
+;-----------------------------------------------------------------------------
+; unsigned __fastcall__ tgi_textheight (const char* s);
+; /* Calculate the width of the text in pixels according to the current text
+; * style.
+; */
+;
+
+.proc _tgi_textheight
+
+ lda _tgi_charheight
+ ldx #0
+ rts
+
+.endproc
+
+
+++ /dev/null
-;
-; Ullrich von Bassewitz, 22.06.2002
-;
-
-
- .include "tgi-kernel.inc"
-
- .import _strlen, pushax, tosumulax
-
-;-----------------------------------------------------------------------------
-; unsigned __fastcall__ tgi_textwidth (const char* s);
-; /* Calculate the width of the text in pixels according to the current text
-; * style.
-; */
-
-
-_tgi_textwidth:
-
- ldy _tgi_textdir ; Get text direction
- bne height
-
-; Result is
-;
-; strlen (s) * tgi_textmagx * tgi_fontsizex
-;
-; Since we don't expect textmagx to have large values, we do the multiplication
-; by looping.
-
-width: jsr _strlen
- jsr pushax
-
- lda #0
- tax
- ldy _tgi_textmagx
-@L1: clc
- adc _tgi_fontsizex
- bcc @L2
- inx
-@L2: dey
- bne @L1
-
- jmp tosumulax ; Result * strlen (s)
-
-;-----------------------------------------------------------------------------
-; unsigned __fastcall__ tgi_textheight (const char* s);
-; /* Calculate the height of the text in pixels according to the current text
-; * style.
-; */
-
-_tgi_textheight:
- ldy _tgi_textdir ; Get text direction
- bne width ; Jump if vertical
-
-; Result is
-;
-; tgi_textmagy * tgi_fontsizey
-;
-; Since we don't expect textmagx to have large values, we do the multiplication
-; by looping.
-
-height: lda #0
- tax
- ldy _tgi_textmagy
-@L1: clc
- adc _tgi_fontsizey
- bcc @L2
- inx
-@L2: dey
- bne @L1
- rts
-
-
;
-; Ullrich von Bassewitz, 22.06.2002
+; Ullrich von Bassewitz, 2009-20-30
;
-; void __fastcall__ tgi_textstyle (unsigned char magx, unsigned char magy,
+; void __fastcall__ tgi_textstyle (unsigned magwidth, unsigned magheight,
; unsigned char dir);
-; /* Set the style for text output. */
+; /* 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, incsp2
+ .import popax
+
+
+;-----------------------------------------------------------------------------
+; Calculate either the total height or the total width of a bitmapped
+; character, depending on the value in Y. On entry, X contains the scaling
+; factor. Since it is usually small, we multiplicate by doing repeated adds.
+; The function returns zero in X and the calculated value in A.
+
+.proc charsize_helper
+
+ lda _tgi_fontwidth,y
+ jmp @L2
+@L1: clc
+ adc _tgi_fontwidth,y
+@L2: dex
+ bne @L1
+ sta _tgi_charwidth,y
+ rts
+
+.endproc
+
+
+;-----------------------------------------------------------------------------
+;
.proc _tgi_textstyle
- pha
- jsr popax ; Get magx/magy in one call
- tay
- pla
+ sta _tgi_textdir ; Remember the direction
+
+; The magheight 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
+ asl a ; Check value behind comma
+ bcc @L1
+ inx ; Round
+@L1: stx _tgi_textmagh+2 ; Store rounded value
+
+; Calculate the total height of the bitmapped font and remember it.
+
+ ldy #1
+ jsr charsize_helper
-; A = textdir, X = textmagx, Y = textmagy
+; The magwidth value is in 8.8 fixed point. Store it and calculate a rounded
+; value for scaling the bitmapped system font in the driver.
- cmp #TGI_TEXT_HORIZONTAL
- beq DirOk
- cmp #TGI_TEXT_VERTICAL
- beq DirOk
-Fail: jmp tgi_inv_arg ; Invalid argument
-DirOk: cpy #$00
- beq Fail ; Cannot have magnification of zero
- cpx #$00
- beq Fail ; Cannot have magnification of zero
+ jsr popax ; magheight
+ sta _tgi_textmagw+0
+ stx _tgi_textmagw+1
+ asl a ; Check value behind comma
+ bcc @L2
+ inx ; Round
+@L2: stx _tgi_textmagw+2 ; Store rounded value
-; Parameter check ok, store them
+; Calculate the total width of the bitmapped font and remember it.
- stx _tgi_textmagx
- sty _tgi_textmagy
- sta _tgi_textdir
+ ldy #0
+ jsr charsize_helper
-; Call the driver, parameters are passed in registers
+; Load values and call the driver, parameters are passed in registers
+ ldx _tgi_textmagw+2
+ ldy _tgi_textmagh+2
+ lda _tgi_textdir
jmp tgi_textstyle
.endproc
--- /dev/null
+;
+; Ullrich von Bassewitz, 2009-10-30
+;
+
+
+ .include "tgi-kernel.inc"
+
+ .import _strlen, pushax, tosumula0
+
+;-----------------------------------------------------------------------------
+; 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
+;
+
+.proc _tgi_textwidth
+
+ jsr _strlen
+ jsr pushax
+ lda _tgi_charwidth
+ jmp tosumula0
+
+.endproc
+