1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-17 16:29:32 +00:00

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

@ -181,6 +181,7 @@ TGI_TEXT_VERTICAL = 1
.global _tgi_line
.global _tgi_lineto
.global _tgi_circle
.global _tgi_ellipse
.global _tgi_bar
.global _tgi_textscale
.global _tgi_textstyle

View File

@ -466,7 +466,7 @@ It does not declare any functions.
<sect1><tt/string.h/<label id="string.h"><p>
<itemize>
<item><ref id="_stroserror" name="_stroserror">
<item><ref id="bzero" name="bzero">
@ -512,6 +512,7 @@ It does not declare any functions.
<item><ref id="tgi_getcolorcount" name="tgi_getcolorcount">
<item><ref id="tgi_getdefpalette" name="tgi_getdefpalette">
<item><ref id="tgi_done" name="tgi_done">
<item><ref id="tgi_ellipse" name="tgi_ellipse">
<item><ref id="tgi_geterror" name="tgi_geterror">
<item><ref id="tgi_geterrormsg" name="tgi_geterrormsg">
<item><ref id="tgi_getmaxcolor" name="tgi_getmaxcolor">
@ -4888,12 +4889,13 @@ be used in presence of a prototype.
<tag/Availability/cc65
<tag/See also/Other tgi function
<tag/Example/<verb>
tgi_setcolor(COLOR_GREEN);
tgi_setcolor(TGI_COLOR_GREEN);
tgi_bar(10, 10, 100, 60);
</verb>
</descrip>
</quote>
<sect1>tgi_circle<label id="tgi_circle"><p>
<quote>
@ -4907,14 +4909,18 @@ tgi_bar(10, 10, 100, 60);
be used in presence of a prototype.
</itemize>
<tag/Availability/cc65
<tag/See also/Other tgi functions
<tag/See also/
<ref id="tgi_bar" name="tgi_bar">,
<ref id="tgi_ellipse" name="tgi_ellipse">,
<ref id="tgi_setcolor" name="tgi_setcolor">
<tag/Example/<verb>
tgi_setcolor(COLOR_BLACK);
tgi_setcolor(TGI_COLOR_BLACK);
tgi_circle(50, 40, 40);
</verb>
</descrip>
</quote>
<sect1>tgi_clear<label id="tgi_clear"><p>
<quote>
@ -4938,11 +4944,11 @@ be used in presence of a prototype.
<quote>
<descrip>
<tag/Function/End graphics mode, switch back to text mode.
Will NOT uninstall or unload the driver!
Will NOT uninstall or unload the driver!
<tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/
<tag/Declaration/<tt/void __fastcall__ tgi_done (void);/
<tag/Description/End graphics mode, switch back to text mode.
Will NOT uninstall or unload the driver!
Will NOT uninstall or unload the driver!
<tag/Limits/<itemize>
<item>The function is only available as fastcall function, so it may only
be used in presence of a prototype.
@ -4953,6 +4959,33 @@ be used in presence of a prototype.
</descrip>
</quote>
<sect1>tgi_ellipse<label id="tgi_ellipse"><p>
<quote>
<descrip>
<tag/Function/The function draws an ellipse in the current color.
<tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/
<tag/Declaration/<tt/void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry);/
<tag/Description/The function draws an ellipse at position x/y with radii
rx and ry, using the current drawing color.
<tag/Limits/<itemize>
<item>The function is only available as fastcall function, so it may only
be used in presence of a prototype.
</itemize>
<tag/Availability/cc65
<tag/See also/
<ref id="tgi_bar" name="tgi_bar">,
<ref id="tgi_circle" name="tgi_circle">,
<ref id="tgi_setcolor" name="tgi_setcolor">
<tag/Example/<verb>
tgi_setcolor(TGI_COLOR_RED);
tgi_ellipse (50, 40, 40, 20);
</verb>
</descrip>
</quote>
<sect1>tgi_getcolor<label id="tgi_getcolor"><p>
<quote>
@ -4962,10 +4995,10 @@ be used in presence of a prototype.
<tag/Declaration/<tt/unsigned char __fastcall__ tgi_getcolor (void);/
<tag/Description/The actual color is an index to a palette. During tgi_init
you will get a default palette. The number of colors depend on the platform.
All platforms recognize at least COLOR_BLACK and COLOR_WHITE. But some
platforms have many more predefined colors. If you paint using COLOR_GREEN
All platforms recognize at least TGI_COLOR_BLACK and TGI_COLOR_WHITE. But some
platforms have many more predefined colors. If you paint using TGI_COLOR_GREEN
and then you change the green of the palette to blue using tgi_setpalette then
after this painting in COLOR_GREEN will actually be blue.
after this painting in TGI_COLOR_GREEN will actually be blue.
<tag/Limits/<itemize>
<item>The function is only available as fastcall function, so it may only
be used in presence of a prototype.
@ -5009,8 +5042,8 @@ 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 COLOR_BLACK, COLOR_WHITE, COLOR_RED... need this palette to
work correctly.
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
be used in presence of a prototype.
@ -5303,7 +5336,7 @@ be used in presence of a prototype.
#define tgi_updatedisplay() tgi_ioctl(4, 1)
if (!tgi_busy()) {
tgi_sprite(&amp;background);
tgi_setcolor(COLOR_BLUE);
tgi_setcolor(TGI_COLOR_BLUE);
tgi_outttextxy(20,40,"Hello World");
tgi_updatedisplay();
}
@ -5448,9 +5481,9 @@ be used in presence of a prototype.
<tag/Availability/cc65
<tag/See also/Other tgi functions.
<tag/Example/<verb>
tgi_setcolor(COLOR_BLACK);
tgi_setcolor(TGI_COLOR_BLACK);
tgi_bar(0,0,30,30);
tgi_setcolor(COLOR_WHITE);
tgi_setcolor(TGI_COLOR_WHITE);
tgi_bar(10,10,20,20);
</verb>
</descrip>

View File

@ -213,6 +213,11 @@ void __fastcall__ tgi_lineto (int x2, int y2);
void __fastcall__ tgi_circle (int x, int y, unsigned char radius);
/* Draw a circle in the current drawing color. */
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_bar (int x1, int y1, int x2, int y2);
/* Draw a bar (a filled rectangle) using the current color. */
@ -228,7 +233,7 @@ void __fastcall__ tgi_textstyle (unsigned width, unsigned height,
* dir is one of the TGI_TEXT_XXX constants. font is one of the TGI_FONT_XXX
* constants.
*/
unsigned __fastcall__ tgi_textwidth (const char* s);
/* Calculate the width of the text in pixels according to the current text
* style.

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;
}
}