2 ; Ullrich von Bassewitz, 2009-11-02
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.
10 .import _toascii, imul16x16r32, umul16x16r32, negax, negeax
12 .include "tgi-kernel.inc"
13 .include "tgi-vectorfont.inc"
14 .include "zeropage.inc"
18 ;----------------------------------------------------------------------------
31 ;----------------------------------------------------------------------------
37 ; Convert the character to ASCII, multiplicate by two and save into Y
43 ; Since we will call tgi_lineto, which uses the zero page, and we do also
44 ; need the zero page, make room in the register bank.
53 ; Calculate a pointer to the vector ops for the given char (now in Y).
58 jeq Done ; Bail out if no font installed
61 adc #<(TGI_VECTORFONT::CHARS - 2*TGI_VF_FIRSTCHAR)
64 adc #>(TGI_VECTORFONT::CHARS - 2*TGI_VF_FIRSTCHAR)
75 ; Main loop executing vector operations
77 Loop: lda _tgi_textscalew+0
81 ; X2 = tgi_curx + XMag * XDelta.
96 ; Y2 = tgi_cury - YMag * YDelta;
97 ; Y2 = tgi_cury + (~(YMag * YDelta) + 1);
108 ; Draw, then move - or just move
111 bpl @Move ; Jump if move only
113 ldy #7 ; Copy start coords into zp
119 jsr tgi_line ; Call the driver
121 ; Move the start position
134 ; Done. Restore zp and return.
146 ;----------------------------------------------------------------------------
147 ; Get and process one coordinate value. The scale factor is passed in a/x
149 .proc GetProcessedCoord
151 ; Save scale factor as left operand for multiplication
164 ; Move bit 7 into Flag
166 : asl a ; Flag into carry
169 ; Since we know that the scale factor is always positive, we will remember
170 ; the sign of the coordinate offset, make it positive, do an unsigned mul
171 ; and negate the result if the vector was negative. This is faster than
172 ; relying on the signed multiplication, which will do the same, but for
175 sta tmp1 ; Remember sign of vector offset
176 cmp #$80 ; Sign bit into carry
177 ror a ; Sign extend the value
182 : ldx #$00 ; High byte is always zero
184 ; Multiplicate with the scale factor.
186 jsr umul16x16r32 ; Multiplicate
188 ; The result is a 16.8 fixed point value. Round it.
190 cmp #$80 ; frac(val) >= 0.5?
198 bit tmp1 ; Check sign
200 jmp negax ; Negate result if necessary