Moved fixed point multiplication and rounding into an asm module.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4447 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2009-11-05 20:16:43 +00:00
parent de6050f21d
commit 787f069738
6 changed files with 75 additions and 17 deletions

View file

@ -170,6 +170,7 @@ TGI_TEXT_VERTICAL = 1
.global _tgi_getxres
.global _tgi_getyres
.global _tgi_gotoxy
.global _tgi_imulround
.global _tgi_init
.global _tgi_install
.global _tgi_ioctl

View file

@ -218,6 +218,14 @@ void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry)
* 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).
*/
void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);
/* Draw a bar (a filled rectangle) using the current color. */

View file

@ -44,7 +44,7 @@
/* TGI kernel variables */
/* TGI kernel variables */
extern void* tgi_drv; /* Pointer to driver */
extern unsigned char tgi_error; /* Last error code */
extern unsigned char tgi_gmode; /* Flag: Graphics mode active */
@ -68,6 +68,11 @@ extern unsigned tgi_aspectratio;/* Aspect ratio as fixed point 8.8 */
const char* __fastcall__ tgi_map_mode (unsigned char mode);
/* Map a tgi mode to a driver name. Returns NULL if no driver available. */
int __fastcall__ tgi_imulround (int rhs, int lhs);
/* Helper function for functions using sine/cosine: Multiply two values, one
* being an 8.8 fixed point one, and return the rounded and scaled result.
*/
/* End of tgi-kernel.h */

View file

@ -58,6 +58,7 @@ S_OBJS = tgi-kernel.o \
tgi_getxres.o \
tgi_getyres.o \
tgi_gotoxy.o \
tgi_imulround.o \
tgi_init.o \
tgi_ioctl.o \
tgi_line.o \

View file

@ -34,6 +34,7 @@
#include <tgi.h>
#include <tgi/tgi-kernel.h>
#include <cc65.h>
@ -44,18 +45,6 @@
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
@ -81,16 +70,16 @@ void __fastcall__ tgi_arc (int x, int y, unsigned char rx, unsigned char ry,
}
/* Calculate the start coords */
x1 = x + RoundMul (rx, cc65_cos (sa));
y1 = y + RoundMul (ry, cc65_sin (sa));
x1 = x + tgi_imulround (rx, cc65_cos (sa));
y1 = y + tgi_imulround (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));
x2 = x + tgi_imulround (rx, cc65_cos (sa));
y2 = y - tgi_imulround (ry, cc65_sin (sa));
tgi_line (x1, y1, x2, y2);
x1 = x2;
y1 = y2;

View file

@ -0,0 +1,54 @@
;
; Ullrich von Bassewitz, 2009-11-05
;
; Helper function for functions using sine/cosine: Multiply two values, one
; being an 8.8 fixed point one, and return the rounded and scaled result.
;
.export _tgi_imulround
.import popax, imul16x16r32
.include "zeropage.inc"
;----------------------------------------------------------------------------
;
.code
.proc _tgi_imulround
; Get arguments
sta ptr1
stx ptr1+1 ; Save lhs
jsr popax ; Get rhs
; Multiplicate
jsr imul16x16r32
; Round the result
cmp #$80 ; Frac(x) >= 0.5?
txa
ldy sreg+1 ; Check sign
bmi @L1
adc #$00
tay
lda sreg
adc #$00
tax
tya
rts
@L1: sbc #$00
tay
lda sreg
sbc #$00
tax
tya
rts
.endproc