]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_textstyle.s
501b0234080dc1364c8623f9f68c7b64f5a6c39a
[cc65] / libsrc / tgi / tgi_textstyle.s
1 ;
2 ; Ullrich von Bassewitz, 2009-20-30
3 ;
4 ; void __fastcall__ tgi_textstyle (unsigned magwidth, unsigned magheight,
5 ;                                  unsigned char dir);
6 ; /* Set the style for text output. The scaling factors for width and height
7 ;  * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
8 ;  */
9
10
11         .include        "tgi-kernel.inc"
12
13         .import         popax
14
15
16 ;-----------------------------------------------------------------------------
17 ; Calculate either the total height or the total width of a bitmapped
18 ; character, depending on the value in Y. On entry, X contains the scaling
19 ; factor. Since it is usually small, we multiplicate by doing repeated adds.
20 ; The function returns zero in X and the calculated value in A.
21
22 .proc   charsize_helper
23
24         lda     _tgi_fontwidth,y
25         jmp     @L2
26 @L1:    clc
27         adc     _tgi_fontwidth,y
28 @L2:    dex
29         bne     @L1
30         sta     _tgi_charwidth,y
31         rts
32
33 .endproc
34
35
36 ;-----------------------------------------------------------------------------
37 ;
38
39 .proc   _tgi_textstyle
40
41         sta     _tgi_textdir            ; Remember the direction
42
43 ; The magheight value is in 8.8 fixed point. Store it and calculate a rounded
44 ; value for scaling the bitmapped system font in the driver.
45
46         jsr     popax                   ; magheight
47         sta     _tgi_textmagh+0
48         stx     _tgi_textmagh+1
49         asl     a                       ; Check value behind comma
50         bcc     @L1
51         inx                             ; Round
52 @L1:    stx     _tgi_textmagh+2         ; Store rounded value
53
54 ; Calculate the total height of the bitmapped font and remember it.
55
56         ldy     #1
57         jsr     charsize_helper
58
59 ; The magwidth value is in 8.8 fixed point. Store it and calculate a rounded
60 ; value for scaling the bitmapped system font in the driver.
61
62         jsr     popax                   ; magheight
63         sta     _tgi_textmagw+0
64         stx     _tgi_textmagw+1
65         asl     a                       ; Check value behind comma
66         bcc     @L2
67         inx                             ; Round
68 @L2:    stx     _tgi_textmagw+2         ; Store rounded value
69
70 ; Calculate the total width of the bitmapped font and remember it.
71
72         ldy     #0
73         jsr     charsize_helper
74
75 ; Load values and call the driver, parameters are passed in registers
76
77         ldx     _tgi_textmagw+2
78         ldy     _tgi_textmagh+2
79         lda     _tgi_textdir
80         jmp     tgi_textstyle
81
82 .endproc
83