From de6050f21d61d58cc2d15022e1f00c1a88f3cb44 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 5 Nov 2009 19:52:18 +0000 Subject: [PATCH] Added a tgi_arc function. Removed the old ellipse code and create a new 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 | 55 ++++++++++++------------- doc/funcref.sgml | 38 ++++++++++++++++- libsrc/tgi/Makefile | 3 +- libsrc/tgi/{tgi_ellipse.c => tgi_arc.c} | 49 +++++++++++++--------- libsrc/tgi/tgi_ellipse.s | 28 +++++++++++++ 5 files changed, 123 insertions(+), 50 deletions(-) rename libsrc/tgi/{tgi_ellipse.c => tgi_arc.c} (74%) create mode 100644 libsrc/tgi/tgi_ellipse.s diff --git a/asminc/tgi-kernel.inc b/asminc/tgi-kernel.inc index 012dfdc10..8d9151dcb 100644 --- a/asminc/tgi-kernel.inc +++ b/asminc/tgi-kernel.inc @@ -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 diff --git a/doc/funcref.sgml b/doc/funcref.sgml index 67b6ef633..13293d6b8 100644 --- a/doc/funcref.sgml +++ b/doc/funcref.sgml @@ -505,6 +505,7 @@ It does not declare any functions.

+ @@ -4872,6 +4873,39 @@ be used in presence of a prototype. +tgi_arc

+ + + +/ + +The function is only available as fastcall function, so it may only +be used in presence of a prototype. +The function behaves unexpectedly or may crash if the angles are out +of range. + +, +, +, + + +/* Draw the upper half of an ellipse */ +tgi_setcolor(TGI_COLOR_BLUE); +tgi_arc (50, 50, 40, 20, 0, 180); + + + + + tgi_bar

@@ -4910,6 +4944,7 @@ be used in presence of a prototype. , , , @@ -4975,6 +5010,7 @@ be used in presence of a prototype. , , , @@ -5042,7 +5078,7 @@ if (tgi_getcolorcount() == 2) { / The function is only available as fastcall function, so it may only diff --git a/libsrc/tgi/Makefile b/libsrc/tgi/Makefile index 9a8147436..4f15e3d20 100644 --- a/libsrc/tgi/Makefile +++ b/libsrc/tgi/Makefile @@ -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_ellipse.c b/libsrc/tgi/tgi_arc.c similarity index 74% rename from libsrc/tgi/tgi_ellipse.c rename to libsrc/tgi/tgi_arc.c index 6f42b1a49..1ce239fc4 100644 --- a/libsrc/tgi/tgi_ellipse.c +++ b/libsrc/tgi/tgi_arc.c @@ -1,8 +1,8 @@ /*****************************************************************************/ /* */ -/* tgi_ellipse.c */ +/* tgi_arc.c */ /* */ -/* Draw a full ellipse */ +/* Draw an ellipse arc */ /* */ /* */ /* */ @@ -56,36 +56,45 @@ static int RoundMul (int rhs, int lhs) -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. +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 angle; unsigned char inc; - unsigned size = rx + ry; + unsigned char done = 0; - if (size >= 128) { + /* 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 if (size >= 32) { - inc = 15; - } else if (size >= 12) { - inc = 20; } else { - inc = 45; + inc = 24; } - 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)); + /* 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.s b/libsrc/tgi/tgi_ellipse.s new file mode 100644 index 000000000..1471f9156 --- /dev/null +++ b/libsrc/tgi/tgi_ellipse.s @@ -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 -- 2.39.5