]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_outtext.s
Restore src/cc65/locals.c:278 to its orignal state
[cc65] / libsrc / tgi / tgi_outtext.s
1 ;
2 ; Ullrich von Bassewitz, 21.06.2002
3 ;
4 ; void __fastcall__ tgi_outtext (const char* s);
5 ; /* Output text at the current graphics cursor position. */
6
7
8         .include        "tgi-kernel.inc"
9         .include        "tgi-vectorfont.inc"
10         .include        "zeropage.inc"
11
12         .import         _toascii
13         .import         popax, negax
14
15
16 ;----------------------------------------------------------------------------
17 ; Data
18
19 text    := regbank
20 font    := regbank              ; Same as text
21 widths  := regbank+2
22
23 ;----------------------------------------------------------------------------
24 ;
25
26 .proc   _tgi_outtext
27
28         ldy     _tgi_font               ; Bit or vectorfont?
29         bne     VectorFont
30
31 ; Handle bitmapped font output
32
33         sta     ptr3
34         stx     ptr3+1                  ; Pass s in ptr3 to driver
35         pha
36         txa
37         pha                             ; Save s on stack for later
38
39         jsr     tgi_curtoxy             ; Copy curx/cury into ptr1/ptr2
40         jsr     tgi_outtext             ; Call the driver
41
42         pla
43         tax
44         pla                             ; Restore s
45         jsr     _tgi_gettextwidth       ; Get width of text string
46
47 ; Move the graphics cursor by the amount in a/x
48
49 MoveCursor:
50         ldy     _tgi_textdir            ; Horizontal or vertical text?
51         beq     @L1                     ; Jump if horizontal
52
53 ; Move graphics cursor for vertical text
54
55         jsr     negax
56         ldy     #2                      ; Point to _tgi_cury
57
58 ; Move graphics cursor for horizontal text
59
60 @L1:    clc
61         adc     _tgi_curx,y
62         sta     _tgi_curx,y
63         txa
64         adc     _tgi_curx+1,y
65         sta     _tgi_curx+1,y
66 Done:   rts
67
68 ; Handle vector font output. First, check if we really have a registered
69 ; vector font. Bail out if this is not the case.
70
71 VectorFont:
72         tay
73         lda     _tgi_vectorfont         ; Do we have a vector font?
74         ora     _tgi_vectorfont+1
75         beq     Done                    ; Bail out if not
76
77 ; Check if the font in the given size is partially out of the screen. We
78 ; do this in vertical direction here, and in horizontal direction before
79 ; outputting a character.
80
81         ; (todo)
82
83 ; Save zero page variable on stack and save
84
85         lda     text
86         pha
87         lda     text+1
88         pha
89         lda     widths
90         pha
91         lda     widths+1
92         pha
93
94         sty     text
95         stx     text+1                  ; Store pointer to string
96
97         lda     _tgi_vectorfont
98         clc
99         adc     #<(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR)
100         sta     widths
101         lda     _tgi_vectorfont+1
102         adc     #>(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR)
103         sta     widths+1
104
105 ; Output the text string
106
107 @L1:    ldy     #0
108         lda     (text),y                ; Get next character from string
109         beq     EndOfText
110         jsr     _toascii                ; Convert to ascii
111         pha                             ; Save char in A
112         jsr     _tgi_vectorchar         ; Output it
113         pla
114
115 ; Move the graphics cursor by the width of the char
116
117         tay
118         lda     (widths),y              ; Get width of this char
119         sta     ptr1
120         lda     #0
121         sta     ptr1+1
122         lda     _tgi_textscalew
123         ldx     _tgi_textscalew+1       ; Get scale factor
124         jsr     tgi_imulround           ; Multiplcate and round
125         jsr     MoveCursor              ; Move the graphics cursor
126
127 ; Next char in string
128                                         
129         inc     text
130         bne     @L1
131         inc     text+1
132         bne     @L1
133
134 ; Done. Restore registers and return
135
136 EndOfText:
137         pla
138         sta     widths+1
139         pla
140         sta     widths
141         pla
142         sta     text+1
143         pla
144         sta     text
145         rts
146
147 .endproc
148