1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-27 19:55:09 +00:00

Working on the TGI API, adding vector fonts. Only roughly tested!

git-svn-id: svn://svn.cc65.org/cc65/trunk@4432 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2009-11-02 22:29:49 +00:00
parent fdc7604d8f
commit 87866e3099
8 changed files with 247 additions and 31 deletions

View File

@ -98,9 +98,10 @@ TGI_TEXT_VERTICAL = 1
.global _tgi_curx ; Current drawing cursor X
.global _tgi_cury ; Current drawing cursor Y
.global _tgi_color ; Current drawing color
.global _tgi_font ; Which font to use
.global _tgi_textdir ; Current text direction
.global _tgi_textmagw ; Text magnification for the width
.global _tgi_textmagh ; Text magnification for the height
.global _tgi_textscalew ; Text magnification for the width
.global _tgi_textscaleh ; Text magnification for the height
.global _tgi_charwidth ; Width of scaled system font char
.global _tgi_charheight ; Height of scaled system font char
.global _tgi_xres ; X resolution of the current mode
@ -181,6 +182,7 @@ TGI_TEXT_VERTICAL = 1
.global _tgi_lineto
.global _tgi_circle
.global _tgi_bar
.global _tgi_textscale
.global _tgi_textstyle
.global _tgi_textwidth
.global _tgi_textheight

View File

@ -216,10 +216,17 @@ void __fastcall__ tgi_circle (int x, int y, unsigned char radius);
void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);
/* Draw a bar (a filled rectangle) using the current color. */
void __fastcall__ tgi_textstyle (unsigned magwidth, unsigned magheight,
unsigned char dir);
void __fastcall__ tgi_textscale (unsigned width, unsigned height);
/* Set the scaling for text output. The scaling factors for width and height
* are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
*/
void __fastcall__ tgi_textstyle (unsigned width, unsigned height,
unsigned char dir, unsigned char font);
/* Set the style for text output. The scaling factors for width and height
* are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
* dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX
* constants.
*/
unsigned __fastcall__ tgi_textwidth (const char* s);

View File

@ -70,6 +70,19 @@ struct tgi_vectorfont {
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void __fastcall__ tgi_vectorchar (const unsigned char* Ops);
/* Draw one character of the vector font at the current graphics cursor
* position using the current font magnification.
*/
/* End of tgi-vectorfont.h */
#endif

View File

@ -76,7 +76,8 @@ S_OBJS = tgi-kernel.o \
tgi_textheight.o \
tgi_textwidth.o \
tgi_textstyle.o \
tgi_unload.o
tgi_unload.o \
tgi_vectorchar.o
#--------------------------------------------------------------------------

View File

@ -22,13 +22,14 @@ _tgi_gmode: .res 1 ; Flag: Graphics mode active
_tgi_curx: .res 2 ; Current drawing cursor X
_tgi_cury: .res 2 ; Current drawing cursor Y
_tgi_color: .res 1 ; Current drawing color
_tgi_font: .res 1 ; Which font to use
_tgi_textdir: .res 1 ; Current text direction
; The following two store an 8.8 fixed point value in the first two bytes,
; and a rounded integer value in the third byte. The latter is passed to the
; driver to scale the bitmap font. The variables are expected to be in
; this order and adjacent.
_tgi_textmagw: .res 3 ; Text magnification for the width
_tgi_textmagh: .res 3 ; Text magnification for the height
_tgi_textscalew: .res 3 ; Text scale for the width
_tgi_textscaleh: .res 3 ; Text scale for the height
; The following two must also be in exactly this order
_tgi_charwidth: .res 1 ; Char width of system font

View File

@ -8,7 +8,7 @@
.include "tgi-kernel.inc"
.include "tgi-error.inc"
.import pushax
.import pushax, pusha
.importzp ptr1
.proc _tgi_init
@ -48,7 +48,8 @@
ldx #>$100
jsr pushax ; Width scale
jsr pushax ; Heigh scale
jsr _tgi_textstyle ; A = Direction = TEXT_VERTICAL
jsr pusha ; Text direction = TGI_TEXT_VERTICAL
jsr _tgi_textstyle ; A = Font = TGI_FONT_BITMAP
; Clear the screen

View File

@ -1,16 +1,11 @@
;
; Ullrich von Bassewitz, 2009-20-30
; Ullrich von Bassewitz, 2009-10-30
;
; void __fastcall__ tgi_textstyle (unsigned magwidth, unsigned magheight,
; unsigned char dir);
; /* Set the style for text output. The scaling factors for width and height
; * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
; */
.include "tgi-kernel.inc"
.import popax
.import popa, popax
;-----------------------------------------------------------------------------
@ -32,40 +27,61 @@
.endproc
;-----------------------------------------------------------------------------
; void __fastcall__ tgi_textstyle (unsigned width, unsigned height,
; unsigned char dir, unsigned char font);
; /* Set the style for text output. The scaling factors for width and height
; * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
; * dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX
; * constants.
; */
;
.proc _tgi_textstyle
sta _tgi_font ; Remember the font to use
jsr popa
sta _tgi_textdir ; Remember the direction
; The magheight value is in 8.8 fixed point. Store it and calculate a rounded
; Pop the height and run directly into tgi_textscale
jsr popax
.endproc
;-----------------------------------------------------------------------------
; void __fastcall__ tgi_textscale (unsigned width, unsigned height);
; /* Set the scaling for text output. The scaling factors for width and height
; * are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc.
; */
.proc _tgi_textscale
; The height value is in 8.8 fixed point. Store it and calculate a rounded
; value for scaling the bitmapped system font in the driver.
jsr popax ; magheight
sta _tgi_textmagh+0
stx _tgi_textmagh+1
sta _tgi_textscaleh+0
stx _tgi_textscaleh+1
asl a ; Check value behind comma
bcc @L1
inx ; Round
@L1: stx _tgi_textmagh+2 ; Store rounded value
@L1: stx _tgi_textscaleh+2 ; Store rounded value
; Calculate the total height of the bitmapped font and remember it.
ldy #1
jsr charsize_helper
; The magwidth value is in 8.8 fixed point. Store it and calculate a rounded
; The width value is in 8.8 fixed point. Store it and calculate a rounded
; value for scaling the bitmapped system font in the driver.
jsr popax ; magheight
sta _tgi_textmagw+0
stx _tgi_textmagw+1
jsr popax ; height
sta _tgi_textscalew+0
stx _tgi_textscalew+1
asl a ; Check value behind comma
bcc @L2
inx ; Round
@L2: stx _tgi_textmagw+2 ; Store rounded value
@L2: stx _tgi_textscalew+2 ; Store rounded value
; Calculate the total width of the bitmapped font and remember it.
@ -74,10 +90,11 @@
; Load values and call the driver, parameters are passed in registers
ldx _tgi_textmagw+2
ldy _tgi_textmagh+2
ldx _tgi_textscalew+2
ldy _tgi_textscaleh+2
lda _tgi_textdir
jmp tgi_textstyle
.endproc

174
libsrc/tgi/tgi_vectorchar.s Normal file
View File

@ -0,0 +1,174 @@
;
; Ullrich von Bassewitz, 2009-11-02
;
; void __fastcall__ tgi_vectorchar (const unsigned char* Ops);
; /* Draw one character of the vector font at the current graphics cursor
; * position using the current font magnification.
; */
;
.export _tgi_vectorchar
.import push0ax, tosmuleax
.include "tgi-kernel.inc"
.include "zeropage.inc"
;----------------------------------------------------------------------------
; Data
Ops = regbank
Flag = regbank+2
.bss
X1: .res 2
Y1: .res 2
X2: .res 2
Y2: .res 2
;----------------------------------------------------------------------------
;
.code
.proc _tgi_vectorchar
; Since we will call tgi_lineto, which uses the zero page, and we do also
; need the zero page, make room in the register bank.
tay
lda Ops
pha
lda Ops+1
pha
lda Flag
pha
; Save the pointer
sty Ops
stx Ops+1
; Main loop executing vector operations
Loop: lda _tgi_textscalew+0
ldx _tgi_textscalew+1
jsr GetProcessedCoord
; X2 = tgi_curx + XMag * XDelta.
clc
adc _tgi_curx+0
sta X2+0
txa
adc _tgi_curx+1
sta X2+1
; Process the Y value
lda _tgi_textscaleh+0
ldx _tgi_textscaleh+1
jsr GetProcessedCoord
; Y2 = tgi_cury - YMag * YDelta;
; Y2 = tgi_cury + (~(YMag * YDelta) + 1);
eor #$FF
sec ; + 1
adc _tgi_cury+0
sta Y2+0
txa
eor #$FF
adc _tgi_cury+1
sta Y2+1
; Do the actual operation
bit Flag
bpl @Move ; Jump if move only
ldy #7 ; Copy start coords into zp
: lda X1,y
sta ptr1,y
dey
bpl :-
jsr tgi_line ; Call the driver
; Move the start position
@Move: ldy #3
: lda X2,y
sta X1,y
dey
bpl :-
; Loop if not done
bit Flag
bvc Loop
; Done. Restore zp and return.
@Done: pla
sta Flag
pla
sta Ops+1
pla
sta Ops
rts
.endproc
;----------------------------------------------------------------------------
; Get and process one coordinate value. The scale factor is passed in a/x
.proc GetProcessedCoord
; Push the scale factor
jsr push0ax
; Load delta value
ldy #0
lda (Ops),y
inc Ops
bne :+
inc Ops+1
; Move bit 7 into Flag
: asl a ; Flag into carry
ror Flag
; Sign extend the value
ldx #0
cmp #$80 ; Sign bit into carry
bcc :+
dex
: ror a ; Sign extend the value
; Multiplicate with the scale factor.
stx sreg
stx sreg+1
jsr tosmuleax ; Multiplicate
; The result is a 16.8 fixed point value. Round and return it.
cmp #$80 ; Check digits after the dec point
txa
adc #$00
tay
lda sreg
adc #$00
tax
tya
rts
.endproc