File: tgi_gettextwidth.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (100 lines) | stat: -rw-r--r-- 2,528 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;
; 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

        jsr     _strlen
        ldy     _tgi_charwidth+1
        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