]> git.sur5r.net Git - cc65/commitdiff
Started to add text output functions
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 3 Oct 2002 11:18:23 +0000 (11:18 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 3 Oct 2002 11:18:23 +0000 (11:18 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1427 b7a2c559-68d2-44c3-8de9-860c34a00d81

14 files changed:
libsrc/tgi/Makefile
libsrc/tgi/tgi-kernel.s
libsrc/tgi/tgi_circle.s
libsrc/tgi/tgi_curtoxy.s [new file with mode: 0644]
libsrc/tgi/tgi_getset.s
libsrc/tgi/tgi_init.s
libsrc/tgi/tgi_line.s
libsrc/tgi/tgi_lineto.s
libsrc/tgi/tgi_outtext.s [new file with mode: 0644]
libsrc/tgi/tgi_outtextxy.s [new file with mode: 0644]
libsrc/tgi/tgi_popxy.s [new file with mode: 0644]
libsrc/tgi/tgi_popxy2.s [new file with mode: 0644]
libsrc/tgi/tgi_textsize.s [new file with mode: 0644]
libsrc/tgi/tgi_textstyle.s [new file with mode: 0644]

index 8639852990de3a7b817769b65ee98db744347810..e1d0b5eee48b5b2ad9c8efd0b0a63a839e519d47 100644 (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)
 
+
index acc46c08b900f7918f3c1beb5c7d1203dc7671b8..59fb5135edea8440b66f1a5e773dd8b51e0bb1b8 100644 (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
 
index 12bc41740bcef53d4d9ae6208d6dd99d7a0c08fd..4908000c9bb290d7859ab9cefd703239eb13f5c6 100644 (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
 
 
diff --git a/libsrc/tgi/tgi_curtoxy.s b/libsrc/tgi/tgi_curtoxy.s
new file mode 100644 (file)
index 0000000..1a4cf9b
--- /dev/null
@@ -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
+
index 1d6353b90f94a772a1c0fcc6e599a9a69e068e30..4ebabaa9615d0e94e5ef8daf5260f3a4b884bd74 100644 (file)
 
 
 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
 
index 68254785b7e2ee46778175c269e75c1b998ad502..c21b669da43284e04f20742adb6b7f2ae48118dd 100644 (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
index 8a96025468ae7de3d0d75b118515309e11a358d7..24295eed287706aff24e9b4b1ed4df629a5ed1d7 100644 (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
 
 
index 1add867443e83bf2a3303e58d16bc46447ba9e2d..4799d793a4ce0fc3b86bbf84b6f57ea2ac1fe386 100644 (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
 
 
diff --git a/libsrc/tgi/tgi_outtext.s b/libsrc/tgi/tgi_outtext.s
new file mode 100644 (file)
index 0000000..4c087bc
--- /dev/null
@@ -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
+
+
diff --git a/libsrc/tgi/tgi_outtextxy.s b/libsrc/tgi/tgi_outtextxy.s
new file mode 100644 (file)
index 0000000..6348210
--- /dev/null
@@ -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
+
+
diff --git a/libsrc/tgi/tgi_popxy.s b/libsrc/tgi/tgi_popxy.s
new file mode 100644 (file)
index 0000000..3e29003
--- /dev/null
@@ -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
+
+
diff --git a/libsrc/tgi/tgi_popxy2.s b/libsrc/tgi/tgi_popxy2.s
new file mode 100644 (file)
index 0000000..d74c8e9
--- /dev/null
@@ -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
+
diff --git a/libsrc/tgi/tgi_textsize.s b/libsrc/tgi/tgi_textsize.s
new file mode 100644 (file)
index 0000000..1ed4d22
--- /dev/null
@@ -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
+
+
diff --git a/libsrc/tgi/tgi_textstyle.s b/libsrc/tgi/tgi_textstyle.s
new file mode 100644 (file)
index 0000000..ddb1aa6
--- /dev/null
@@ -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
+