_tgi_font: .res 1 ; Which font to use
_tgi_textdir: .res 1 ; Current text direction
_tgi_vectorfont: .res 2 ; Pointer to vector font
-; 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_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
-_tgi_charheight: .res 1 ; Char height of system font
+; The following are character scale/size variables in 8.8 fixed point
+; format. They are required to be in this order and adjacent.
+_tgi_textscalew: .res 2 ; Vector font width scale
+ .res 2 ; Bitmap font width scale
+_tgi_charwidth: .res 2 ; Full width of one bitmap char
+_tgi_textscaleh: .res 2 ; Vector font height scale
+ .res 2 ; Bitmap font height scale
+_tgi_charheight: .res 2 ; Full height of one bitmap char
; End of section that gets cleared when a new driver is loaded
csize = * - cstart
_tgi_xmax: .res 2
_tgi_ymax: .res 2
-; The following variables are copied from the driver header for faster access
+; 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
;
+ .include "zeropage.inc"
.include "tgi-kernel.inc"
+ .import umul8x16r24
.import popa, 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
+ .macpack cpu
;-----------------------------------------------------------------------------
; void __fastcall__ tgi_textstyle (unsigned width, unsigned height,
.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.
-
- sta _tgi_textscaleh+0
- stx _tgi_textscaleh+1
- asl a ; Check value behind comma
- bcc @L1
- inx ; Round
-@L1: stx _tgi_textscaleh+2 ; Store rounded value
-
-; Calculate the total height of the bitmapped font and remember it.
+; Setup the height
- ldy #1
- jsr charsize_helper
+ 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
-; 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.
+; Setup the width
- jsr popax ; height
- sta _tgi_textscalew+0
- stx _tgi_textscalew+1
- asl a ; Check value behind comma
- bcc @L2
- inx ; Round
-@L2: stx _tgi_textscalew+2 ; Store rounded value
+ 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
-; Calculate the total width of the bitmapped font and remember it.
+; 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
+;
- ldy #0
- jsr charsize_helper
+process_onedim:
-; Load values and call the driver, parameters are passed in registers
+ jsr store ; Store vector font scale factor
+ bit _tgi_flags ; Fine grained scaling support avail?
+ bmi @L2 ; Jump if yes
- ldx _tgi_textscalew+2
- ldy _tgi_textscaleh+2
- lda _tgi_textdir
- jmp tgi_textstyle
+ 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