]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_vectorchar.s
Working on the TGI API, adding vector fonts. Only roughly tested!
[cc65] / libsrc / tgi / tgi_vectorchar.s
1 ;
2 ; Ullrich von Bassewitz, 2009-11-02
3 ;
4 ; void __fastcall__ tgi_vectorchar (const unsigned char* Ops);
5 ; /* Draw one character of the vector font at the current graphics cursor
6 ;  * position using the current font magnification.
7 ;  */
8 ;
9
10         .export         _tgi_vectorchar
11
12         .import         push0ax, tosmuleax
13
14         .include        "tgi-kernel.inc"
15         .include        "zeropage.inc"
16
17
18 ;----------------------------------------------------------------------------
19 ; Data
20
21 Ops     = regbank
22 Flag    = regbank+2
23
24 .bss
25 X1:     .res    2
26 Y1:     .res    2
27 X2:     .res    2
28 Y2:     .res    2
29
30
31
32 ;----------------------------------------------------------------------------
33 ;
34
35 .code
36 .proc   _tgi_vectorchar
37
38 ; Since we will call tgi_lineto, which uses the zero page, and we do also
39 ; need the zero page, make room in the register bank.
40
41         tay
42         lda     Ops
43         pha
44         lda     Ops+1
45         pha
46         lda     Flag
47         pha
48
49 ; Save the pointer
50
51         sty     Ops
52         stx     Ops+1
53
54 ; Main loop executing vector operations
55
56 Loop:   lda     _tgi_textscalew+0
57         ldx     _tgi_textscalew+1
58         jsr     GetProcessedCoord
59
60 ; X2 = tgi_curx + XMag * XDelta.
61
62         clc
63         adc     _tgi_curx+0
64         sta     X2+0
65         txa
66         adc     _tgi_curx+1
67         sta     X2+1
68
69 ; Process the Y value
70
71         lda     _tgi_textscaleh+0
72         ldx     _tgi_textscaleh+1
73         jsr     GetProcessedCoord
74
75 ; Y2 = tgi_cury - YMag * YDelta;
76 ; Y2 = tgi_cury + (~(YMag * YDelta) + 1);
77
78         eor     #$FF
79         sec                             ; + 1
80         adc     _tgi_cury+0
81         sta     Y2+0
82         txa
83         eor     #$FF
84         adc     _tgi_cury+1
85         sta     Y2+1
86
87 ; Do the actual operation
88
89         bit     Flag
90         bpl     @Move                   ; Jump if move only
91
92         ldy     #7                      ; Copy start coords into zp
93 :       lda     X1,y
94         sta     ptr1,y
95         dey
96         bpl     :-
97
98         jsr     tgi_line                ; Call the driver
99
100 ; Move the start position
101
102 @Move:  ldy     #3
103 :       lda     X2,y
104         sta     X1,y
105         dey
106         bpl     :-
107
108 ; Loop if not done
109
110         bit     Flag
111         bvc     Loop
112
113 ; Done. Restore zp and return.
114
115 @Done:  pla
116         sta     Flag
117         pla
118         sta     Ops+1
119         pla
120         sta     Ops
121         rts
122
123 .endproc
124
125 ;----------------------------------------------------------------------------
126 ; Get and process one coordinate value. The scale factor is passed in a/x
127
128 .proc   GetProcessedCoord
129
130 ; Push the scale factor
131
132         jsr     push0ax
133
134 ; Load delta value
135
136         ldy     #0
137         lda     (Ops),y
138         inc     Ops
139         bne     :+
140         inc     Ops+1
141
142 ; Move bit 7 into Flag
143
144 :       asl     a                       ; Flag into carry
145         ror     Flag
146
147 ; Sign extend the value
148
149         ldx     #0
150         cmp     #$80                    ; Sign bit into carry
151         bcc     :+
152         dex
153 :       ror     a                       ; Sign extend the value
154
155 ; Multiplicate with the scale factor.
156
157         stx     sreg
158         stx     sreg+1
159         jsr     tosmuleax               ; Multiplicate
160
161 ; The result is a 16.8 fixed point value. Round and return it.
162
163         cmp     #$80                    ; Check digits after the dec point
164         txa
165         adc     #$00
166         tay
167         lda     sreg
168         adc     #$00
169         tax
170         tya
171         rts
172
173 .endproc
174