]> git.sur5r.net Git - cc65/commitdiff
Added a tgi_arc function. Removed the old ellipse code and create a new
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 5 Nov 2009 19:52:18 +0000 (19:52 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 5 Nov 2009 19:52:18 +0000 (19:52 +0000)
ellipse module that calls tgi_arc.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4446 b7a2c559-68d2-44c3-8de9-860c34a00d81

asminc/tgi-kernel.inc
doc/funcref.sgml
libsrc/tgi/Makefile
libsrc/tgi/tgi_arc.c [new file with mode: 0644]
libsrc/tgi/tgi_ellipse.c [deleted file]
libsrc/tgi/tgi_ellipse.s [new file with mode: 0644]

index 012dfdc100f799060736b5742fc5a986a16ac436..8d9151dcb1ed8f5b85f7214fd71abe819342932f 100644 (file)
@@ -150,44 +150,43 @@ TGI_TEXT_VERTICAL       = 1
 ;------------------------------------------------------------------------------
 ; C callable functions
 
-        .global _tgi_load
-        .global _tgi_load_driver
-        .global _tgi_unload
-        .global _tgi_install
-        .global _tgi_uninstall
-        .global _tgi_init
-        .global _tgi_ioctl
+        .global _tgi_arc
+        .global _tgi_bar
+        .global _tgi_circle
+        .global _tgi_clear
         .global _tgi_done
+        .global _tgi_ellipse
+        .global _tgi_getcolor
+        .global _tgi_getcolorcount
+        .global _tgi_getdefpalette
         .global _tgi_geterror
         .global _tgi_geterrormsg
-        .global _tgi_clear
-        .global _tgi_getpagecount
-        .global _tgi_setviewpage
-        .global _tgi_setdrawpage
-        .global _tgi_getcolorcount
         .global _tgi_getmaxcolor
-        .global _tgi_setcolor
-        .global _tgi_getcolor
-        .global _tgi_setpalette
-        .global _tgi_getpalette
-        .global _tgi_getdefpalette
-        .global _tgi_getxres
         .global _tgi_getmaxx
-        .global _tgi_getyres
         .global _tgi_getmaxy
+        .global _tgi_getpagecount
+        .global _tgi_getpalette
         .global _tgi_getpixel
-        .global _tgi_setpixel
+        .global _tgi_getxres
+        .global _tgi_getyres
         .global _tgi_gotoxy
+        .global _tgi_init
+        .global _tgi_install
+        .global _tgi_ioctl
         .global _tgi_line
         .global _tgi_lineto
-        .global _tgi_circle
-        .global _tgi_ellipse
-        .global _tgi_bar
+        .global _tgi_load
+        .global _tgi_load_driver
+        .global _tgi_outtext
+        .global _tgi_outtextxy
+        .global _tgi_setcolor
+        .global _tgi_setdrawpage
+        .global _tgi_setpalette
+        .global _tgi_setpixel
+        .global _tgi_setviewpage
+        .global _tgi_textheight
         .global _tgi_textscale
         .global _tgi_textstyle
         .global _tgi_textwidth
-        .global _tgi_textheight
-        .global _tgi_outtext
-        .global _tgi_outtextxy
-
-
+        .global _tgi_uninstall
+        .global _tgi_unload
index 67b6ef633fe3e163745c533075a970ea118d4223..13293d6b8ef4e6c4f3fa9d79fa4d4ad76c6c1b9d 100644 (file)
@@ -505,6 +505,7 @@ It does not declare any functions.
 <sect1><tt/tgi.h/<label id="tgi.h"><p>
 
 <itemize>
+<item><ref id="tgi_arc" name="tgi_arc">
 <item><ref id="tgi_bar" name="tgi_bar">
 <item><ref id="tgi_circle" name="tgi_circle">
 <item><ref id="tgi_clear" name="tgi_clear">
@@ -4872,6 +4873,39 @@ be used in presence of a prototype.
 </quote>
 
 
+<sect1>tgi_arc<label id="tgi_arc"><p>
+
+<quote>
+<descrip>
+<tag/Function/Draw an elliptic arc in the current color.
+<tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/
+<tag/Declaration/<tt/void __fastcall__ tgi_arc (int x, int y, 
+unsigned char rx, unsigned char ry, unsigned sa, unsigned ea);/
+<tag/Description/The function draws an elliptic arc with center at x/y and
+radii rx/ry using the current drawing color. The arc covers the angle 
+between sa and ea (startangle and endangle), which must be in the range
+0..360.
+<tag/Limits/<itemize>
+<item>The function is only available as fastcall function, so it may only
+be used in presence of a prototype.
+<item>The function behaves unexpectedly or may crash if the angles are out
+of range.
+</itemize>
+<tag/Availability/cc65
+<tag/See also/
+<ref id="tgi_bar" name="tgi_bar">,
+<ref id="tgi_circle" name="tgi_circle">,
+<ref id="tgi_ellipse" name="tgi_ellipse">,
+<ref id="tgi_setcolor" name="tgi_setcolor">
+<tag/Example/<verb>
+/* Draw the upper half of an ellipse */
+tgi_setcolor(TGI_COLOR_BLUE);
+tgi_arc (50, 50, 40, 20, 0, 180);
+</verb>
+</descrip>
+</quote>
+
+
 <sect1>tgi_bar<label id="tgi_bar"><p>
 
 <quote>
@@ -4910,6 +4944,7 @@ be used in presence of a prototype.
 </itemize>
 <tag/Availability/cc65
 <tag/See also/
+<ref id="tgi_arc" name="tgi_arc">,
 <ref id="tgi_bar" name="tgi_bar">,
 <ref id="tgi_ellipse" name="tgi_ellipse">,
 <ref id="tgi_setcolor" name="tgi_setcolor">
@@ -4975,6 +5010,7 @@ be used in presence of a prototype.
 </itemize>
 <tag/Availability/cc65
 <tag/See also/
+<ref id="tgi_arc" name="tgi_arc">,
 <ref id="tgi_bar" name="tgi_bar">,
 <ref id="tgi_circle" name="tgi_circle">,
 <ref id="tgi_setcolor" name="tgi_setcolor">
@@ -5042,7 +5078,7 @@ if (tgi_getcolorcount() == 2) {
 <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/
 <tag/Declaration/<tt/const unsigned char* __fastcall__ tgi_getdefpalette (void);/
 <tag/Description/The tgi driver has a default palette that is active at startup.
-The named colors TGI_COLOR_BLACK, TGI_COLOR_WHITE, TGI_COLOR_RED... need this 
+The named colors TGI_COLOR_BLACK, TGI_COLOR_WHITE, TGI_COLOR_RED... need this
 palette to work correctly.
 <tag/Limits/<itemize>
 <item>The function is only available as fastcall function, so it may only
index 9a814743604c89891618b60b292e679d62488cc0..4f15e3d2097577b0e5828846dd34aea400b10864 100644 (file)
@@ -29,7 +29,7 @@ CFLAGS        = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
 #--------------------------------------------------------------------------
 # Object files
 
-C_OBJS =        tgi_ellipse.o           \
+C_OBJS =        tgi_arc.o               \
                 tgi_load.o              \
                 tgi_load_driver.o       \
                 tgi_load_vectorfont.o
@@ -41,6 +41,7 @@ S_OBJS =              tgi-kernel.o            \
                 tgi_clipline.o          \
                 tgi_curtoxy.o           \
                 tgi_done.o              \
+                tgi_ellipse.o           \
                 tgi_free_vectorfont.o   \
                 tgi_getcolor.o          \
                 tgi_getcolorcount.o     \
diff --git a/libsrc/tgi/tgi_arc.c b/libsrc/tgi/tgi_arc.c
new file mode 100644 (file)
index 0000000..1ce239f
--- /dev/null
@@ -0,0 +1,101 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 tgi_arc.c                                 */
+/*                                                                           */
+/*                            Draw an ellipse arc                            */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2002-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#include <tgi.h>
+#include <cc65.h>
+
+
+
+/*****************************************************************************/
+/*                                   Code                                    */
+/*****************************************************************************/
+
+
+
+static int RoundMul (int rhs, int lhs)
+{
+    long res = cc65_imul16x16r32 (rhs, lhs);
+    if ((unsigned char)res & 0x80) {
+        return (int)(res >> 8) + 1;
+    } else {
+        return (int)(res >> 8);
+    }
+}
+
+
+
+void __fastcall__ tgi_arc (int x, int y, unsigned char rx, unsigned char ry,
+                           unsigned sa, unsigned ea)
+/* Draw an ellipse arc with center at x/y and radii rx/ry using the current
+ * drawing color. The arc covers the angle between sa and ea (startangle and
+ * endangle), which must be in the range 0..360 (otherwise the function may
+ * bevave unextectedly).
+ */
+{
+    int x1, y1, x2, y2;
+    unsigned char inc;
+    unsigned char done = 0;
+
+    /* Bail out if there's nothing to do */
+    if (sa > ea) {
+        return;
+    }
+
+    /* Determine the number of segments to use. This may be refined ... */
+    if (rx + ry >= 25) {
+        inc = 12;
+    } else {
+        inc = 24;
+    }
+
+    /* Calculate the start coords */
+    x1 = x + RoundMul (rx, cc65_cos (sa));
+    y1 = y + RoundMul (ry, cc65_sin (sa));
+    do {
+        sa += inc;
+        if (sa >= ea) {
+            sa = ea;
+            done = 1;
+        }
+        x2 = x + RoundMul (rx, cc65_cos (sa));
+        y2 = y - RoundMul (ry, cc65_sin (sa));
+        tgi_line (x1, y1, x2, y2);
+        x1 = x2;
+        y1 = y2;
+    } while (!done);
+}
+
+
+
diff --git a/libsrc/tgi/tgi_ellipse.c b/libsrc/tgi/tgi_ellipse.c
deleted file mode 100644 (file)
index 6f42b1a..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                               tgi_ellipse.c                               */
-/*                                                                           */
-/*                            Draw a full ellipse                            */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 2002-2009, Ullrich von Bassewitz                                      */
-/*                Roemerstrasse 52                                           */
-/*                D-70794 Filderstadt                                        */
-/* EMail:         uz@cc65.org                                                */
-/*                                                                           */
-/*                                                                           */
-/* This software is provided 'as-is', without any expressed or implied       */
-/* warranty.  In no event will the authors be held liable for any damages    */
-/* arising from the use of this software.                                    */
-/*                                                                           */
-/* Permission is granted to anyone to use this software for any purpose,     */
-/* including commercial applications, and to alter it and redistribute it    */
-/* freely, subject to the following restrictions:                            */
-/*                                                                           */
-/* 1. The origin of this software must not be misrepresented; you must not   */
-/*    claim that you wrote the original software. If you use this software   */
-/*    in a product, an acknowledgment in the product documentation would be  */
-/*    appreciated but is not required.                                       */
-/* 2. Altered source versions must be plainly marked as such, and must not   */
-/*    be misrepresented as being the original software.                      */
-/* 3. This notice may not be removed or altered from any source              */
-/*    distribution.                                                          */
-/*                                                                           */
-/*****************************************************************************/
-
-
-
-#include <tgi.h>
-#include <cc65.h>
-
-
-
-/*****************************************************************************/
-/*                                   Code                                    */
-/*****************************************************************************/
-
-
-
-static int RoundMul (int rhs, int lhs)
-{
-    long res = cc65_imul16x16r32 (rhs, lhs);
-    if ((unsigned char)res & 0x80) {
-        return (int)(res >> 8) + 1;
-    } else {
-        return (int)(res >> 8);
-    }
-}
-
-
-
-void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry)
-/* Draw a full ellipse with center at x/y and radii rx/ry using the current
- * drawing color.
- */
-{
-    int x1, y1, x2, y2;
-    unsigned angle;
-    unsigned char inc;
-    unsigned size = rx + ry;
-
-    if (size >= 128) {
-        inc = 12;
-    } else if (size >= 32) {
-        inc = 15;
-    } else if (size >= 12) {
-        inc = 20;
-    } else {
-        inc = 45;
-    }
-
-    x1 = x + rx;
-    y1 = y;
-    angle = 0;
-    for (angle = 0; angle <= 360; angle += inc) {
-        x2 = x + RoundMul (rx, cc65_cos (angle));
-        y2 = y + RoundMul (ry, cc65_sin (angle));
-        tgi_line (x1, y1, x2, y2);
-        x1 = x2;
-        y1 = y2;
-    }
-}
-
-
-
diff --git a/libsrc/tgi/tgi_ellipse.s b/libsrc/tgi/tgi_ellipse.s
new file mode 100644 (file)
index 0000000..1471f91
--- /dev/null
@@ -0,0 +1,28 @@
+;
+; Ullrich von Bassewitz, 2009-11-05
+;
+; void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry);
+; /* Draw a full ellipse with center at x/y and radii rx/ry using the current
+;  * drawing color.
+;  */
+;
+
+
+        .include        "tgi-kernel.inc"
+
+        .import         pusha, push0
+
+
+;----------------------------------------------------------------------------
+;
+
+.code
+.proc   _tgi_ellipse
+
+        jsr     pusha                   ; Push ry
+        jsr     push0                   ; Start angle is 0
+        lda     #<360
+        ldx     #>360                   ; End angle is 360
+        jmp     _tgi_arc
+
+.endproc