Added tgi_circle and tgi_ellipse functions. The latter works, but could be

optimized.



git-svn-id: svn://svn.cc65.org/cc65/trunk@4445 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2009-11-05 17:14:29 +00:00
parent a08b7d4daf
commit 78070d8bfb
6 changed files with 157 additions and 20 deletions

View File

@@ -29,7 +29,8 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
#--------------------------------------------------------------------------
# Object files
C_OBJS = tgi_load.o \
C_OBJS = tgi_ellipse.o \
tgi_load.o \
tgi_load_driver.o \
tgi_load_vectorfont.o

View File

@@ -1,16 +1,21 @@
;
; Ullrich von Bassewitz, 21.06.2002
; Ullrich von Bassewitz, 2009-11-05
;
; void __fastcall__ tgi_circle (int x, int y, unsigned char radius);
; /* Draw a circle in the current drawing color */
.include "tgi-kernel.inc"
.import incsp4
.import pusha
;----------------------------------------------------------------------------
;
.code
.proc _tgi_circle
; For now
jmp incsp4
jsr pusha ; Push as rx
jmp _tgi_ellipse ; Draw an ellipse with rx=ry
.endproc

92
libsrc/tgi/tgi_ellipse.c Normal file
View File

@@ -0,0 +1,92 @@
/*****************************************************************************/
/* */
/* 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;
}
}