Started to add text output functions

git-svn-id: svn://svn.cc65.org/cc65/trunk@1427 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-10-03 11:18:23 +00:00
parent 4389b0c438
commit 2f44fb05a4
14 changed files with 256 additions and 40 deletions

View File

@ -17,6 +17,7 @@ S_OBJS = tgi-kernel.o \
tgi_bar.o \
tgi_circle.o \
tgi_clear.o \
tgi_curtoxy.o \
tgi_done.o \
tgi_emu_bar.o \
tgi_getcolor.o \
@ -38,11 +39,17 @@ S_OBJS = tgi-kernel.o \
tgi_linepop.o \
tgi_lineto.o \
tgi_map_mode.o \
tgi_outtext.o \
tgi_outtextxy.o \
tgi_popxy.o \
tgi_popxy2.o \
tgi_setcolor.o \
tgi_setdrawpage.o \
tgi_setpalette.o \
tgi_setpixel.o \
tgi_setdrawpage.o \
tgi_textsize.o \
tgi_textstyle.o \
tgi_unload.o
@ -54,3 +61,4 @@ clean:
@rm -f $(C_OBJS)
@rm -f $(S_OBJS)

View File

@ -22,10 +22,19 @@ _tgi_mode: .res 1 ; Graphics mode or zero
_tgi_curx: .res 2 ; Current drawing cursor X
_tgi_cury: .res 2 ; Current drawing cursor Y
_tgi_color: .res 1 ; Current drawing color
_tgi_textdir: .res 1 ; Current text direction
_tgi_textmagx: .res 1 ; Text magnification in X dir
_tgi_textmagy: .res 1 ; Text magnification in Y dir
; The following variables are copied from the driver header for faster access
tgi_driver_vars:
_tgi_xres: .res 2 ; X resolution of the current mode
_tgi_yres: .res 2 ; Y resolution of the current mode
_tgi_colorcount: .res 1 ; Number of available colors
_tgi_pagecount: .res 1 ; Number of available screen pages
_tgi_fontsizex: .res 1 ; System font X size
_tgi_fontsizey: .res 1 ; System font Y size
tgi_driver_var_size = * - tgi_driver_vars
.data
@ -51,6 +60,8 @@ tgi_horline: jmp $0000
tgi_line: jmp $0000
tgi_bar: jmp $0000
tgi_circle: jmp $0000
tgi_textstyle: jmp $0000
tgi_outtext: jmp $0000
;----------------------------------------------------------------------------
@ -94,17 +105,17 @@ _tgi_setup:
@L2: ldy #TGI_HDR_XRES
ldx #0
@L3: lda (ptr1),y
sta _tgi_xres,x
sta tgi_driver_vars,x
iny
inx
cpx #6
cpx #tgi_driver_var_size
bne @L3
; Initialize variables
lda #$00
ldx #6-1
@L4: sta _tgi_error,x ; Clear error/mode/curx/cury
ldx #7-1
@L4: sta _tgi_error,x ; Clear error/mode/curx/cury/textdir
dex
bpl @L4

View File

@ -7,18 +7,13 @@
.include "tgi-kernel.inc"
.import popax
.importzp ptr1, ptr2, tmp1
.importzp tmp1
.export _tgi_circle
_tgi_circle:
sta tmp1 ; Get the coordinates
jsr popax
sta ptr2
stx ptr2+1
jsr popax
sta ptr1
stx ptr1+1
jsr tgi_popxy ; Pop X/Y into ptr1/ptr2
jmp tgi_circle ; Call the driver

22
libsrc/tgi/tgi_curtoxy.s Normal file
View File

@ -0,0 +1,22 @@
;
; Ullrich von Bassewitz, 02.10.2002
;
; Helper function for tgi functions. Moves the current X/Y pos to ptr1/ptr2
;
.include "tgi-kernel.inc"
.importzp ptr1, ptr2
tgi_curtoxy:
ldy _tgi_curx ; X1
sty ptr1
ldy _tgi_curx+1
sty ptr1+1
ldy _tgi_cury ; Y1
sty ptr2
ldy _tgi_cury+1
sty ptr2+1
rts

View File

@ -12,18 +12,13 @@
tgi_getset:
sta ptr2 ; Y
stx ptr2+1
jsr popax
sta ptr1 ; X
stx ptr1+1
jsr tgi_popxy ; Pop X/Y into ptr1/ptr2
; Are the coordinates are out of range? First check if any ccord is negative.
; Are the coordinates out of range? First check if any coord is negative.
txa
ora ptr2+1
asl a
bcs @L9 ; Bail out if negative
bmi @L9 ; Bail out if negative
; Check if X is larger than the maximum x coord. If so, bail out

View File

@ -40,6 +40,16 @@ _tgi_init:
txa
jsr _tgi_setcolor ; tgi_setcolor (tgi_getmaxcolor ());
; Set the text style
lda #TGI_TEXT_HORIZONTAL
sta _tgi_textdir
ldx #1
stx _tgi_textmagx
ldy #1
sty _tgi_textmagy
jsr tgi_textstyle ; Tell the driver about the text style
; Clear the screen
jmp tgi_clear

View File

@ -8,19 +8,12 @@
.include "tgi-kernel.inc"
.import popax
.importzp ptr1, ptr2
.export _tgi_line
_tgi_line:
jsr tgi_linepop ; Pop/store Y2/X2
jsr popax
sta ptr2
stx ptr2+1
jsr popax
sta ptr1
stx ptr1+1
jsr tgi_popxy ; Pop/store X1/Y1 into ptr1/ptr2
jmp tgi_line ; Call the driver

View File

@ -9,22 +9,11 @@
.include "tgi-kernel.inc"
.import popax
.importzp ptr1, ptr2, ptr3, ptr4
.export _tgi_lineto
_tgi_lineto:
ldy _tgi_curx ; X1
sty ptr1
ldy _tgi_curx+1
sty ptr1+1
ldy _tgi_cury ; Y1
sty ptr2
ldy _tgi_cury+1
sty ptr2+1
jsr tgi_linepop
jsr tgi_curtoxy ; Copy curx/cury into ptr1/ptr2
jsr tgi_linepop ; Pop x2/y2 into ptr3/ptr4 and curx/cury
jmp tgi_line ; Call the driver

20
libsrc/tgi/tgi_outtext.s Normal file
View File

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 21.06.2002
;
; void __fastcall__ tgi_outtext (const char* s);
; /* Output text at the current graphics cursor position. */
.include "tgi-kernel.inc"
.import popax
.importzp ptr3
.export _tgi_outtext
_tgi_outtext:
sta ptr3
stx ptr3+1 ; Save s
jsr tgi_curtoxy ; Copy curx/cury into ptr1/ptr2
jmp tgi_outtext ; Call the driver

View File

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 21.06.2002
;
; void __fastcall__ tgi_outtextxy (int x, int y, const char* s);
; /* Output text at the given position. */
.include "tgi-kernel.inc"
.import popax
.importzp ptr3
.export _tgi_outtextxy
_tgi_outtextxy:
sta ptr3
stx ptr3+1 ; Save s
jsr tgi_popxy ; Pop x/y into ptr1/ptr2
jmp tgi_outtext ; Call the driver

20
libsrc/tgi/tgi_popxy.s Normal file
View File

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 02.10.2002
;
; Helper function for tgi functions. Pops X/Y from stack into ptr1/ptr2
;
.include "tgi-kernel.inc"
.import popax
.importzp ptr1, ptr2
tgi_popxy:
sta ptr2 ; Y
stx ptr2+1
jsr popax
sta ptr1 ; X
stx ptr1+1
rts

19
libsrc/tgi/tgi_popxy2.s Normal file
View File

@ -0,0 +1,19 @@
;
; Ullrich von Bassewitz, 02.10.2002
;
; Helper function for tgi functions. Pops X/Y from stack into ptr3/ptr4
;
.include "tgi-kernel.inc"
.import popax
.importzp ptr3, ptr4
tgi_popxy2:
sta ptr4 ; Y
stx ptr4+1
jsr popax
sta ptr3 ; X
stx ptr3+1
rts

73
libsrc/tgi/tgi_textsize.s Normal file
View File

@ -0,0 +1,73 @@
;
; Ullrich von Bassewitz, 22.06.2002
;
.include "tgi-kernel.inc"
.import _strlen, pushax, tosumulax
.export _tgi_textwidth
.export _tgi_textheight
;-----------------------------------------------------------------------------
; unsigned __fastcall__ tgi_textwidth (const char* s);
; /* Calculate the width of the text in pixels according to the current text
; * style.
; */
_tgi_textwidth:
ldy _tgi_textdir ; Get text direction
bne height
; Result is
;
; strlen (s) * tgi_textmagx * tgi_fontsizex
;
; Since we don't expect textmagx to have large values, we do the multiplication
; by looping.
width: jsr _strlen
jsr pushax
lda #0
tax
ldy _tgi_textmagx
@L1: clc
adc _tgi_fontsizex
bcc @L2
inx
@L2: dey
bne @L1
jmp tosumulax ; Result * strlen (s)
;-----------------------------------------------------------------------------
; unsigned __fastcall__ tgi_textheight (const char* s);
; /* Calculate the height of the text in pixels according to the current text
; * style.
; */
_tgi_textheight:
ldy _tgi_textdir ; Get text direction
bne width ; Jump if vertical
; Result is
;
; tgi_textmagy * tgi_fontsizey
;
; Since we don't expect textmagx to have large values, we do the multiplication
; by looping.
height: lda #0
tax
ldy _tgi_textmagy
@L1: clc
adc _tgi_fontsizey
bcc @L2
inx
@L2: dey
bne @L1
rts

View File

@ -0,0 +1,41 @@
;
; Ullrich von Bassewitz, 22.06.2002
;
; void __fastcall__ tgi_textstyle (unsigned char magx, unsigned char magy,
; unsigned char dir);
; /* Set the style for text output. */
.include "tgi-kernel.inc"
.import popax, incsp2
.export _tgi_textstyle
_tgi_textstyle:
pha
jsr popax ; Get magx/magy in one call
tay
pla
; A = textdir, X = textmagx, Y = textmagy
cmp #TGI_TEXT_HORIZONTAL
beq DirOk
cmp #TGI_TEXT_VERTICAL
beq DirOk
Fail: jmp tgi_inv_arg ; Invalid argument
DirOk: cpy #$00
beq Fail ; Cannot have magnification of zero
cpx #$00
beq Fail ; Cannot have magnification of zero
; Parameter check ok, store them
stx _tgi_textmagx
sty _tgi_textmagy
sta _tgi_textdir
; Call the driver, parameters are passed in registers
jmp tgi_textstyle