mirror of
https://github.com/cc65/cc65.git
synced 2025-03-01 11:29:27 +00:00
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:
parent
de6050f21d
commit
787f069738
@ -170,6 +170,7 @@ TGI_TEXT_VERTICAL = 1
|
|||||||
.global _tgi_getxres
|
.global _tgi_getxres
|
||||||
.global _tgi_getyres
|
.global _tgi_getyres
|
||||||
.global _tgi_gotoxy
|
.global _tgi_gotoxy
|
||||||
|
.global _tgi_imulround
|
||||||
.global _tgi_init
|
.global _tgi_init
|
||||||
.global _tgi_install
|
.global _tgi_install
|
||||||
.global _tgi_ioctl
|
.global _tgi_ioctl
|
||||||
|
@ -218,6 +218,14 @@ void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry)
|
|||||||
* drawing color.
|
* 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);
|
void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);
|
||||||
/* Draw a bar (a filled rectangle) using the current color. */
|
/* Draw a bar (a filled rectangle) using the current color. */
|
||||||
|
|
||||||
|
@ -68,6 +68,11 @@ extern unsigned tgi_aspectratio;/* Aspect ratio as fixed point 8.8 */
|
|||||||
const char* __fastcall__ tgi_map_mode (unsigned char mode);
|
const char* __fastcall__ tgi_map_mode (unsigned char mode);
|
||||||
/* Map a tgi mode to a driver name. Returns NULL if no driver available. */
|
/* 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 */
|
/* End of tgi-kernel.h */
|
||||||
|
@ -58,6 +58,7 @@ S_OBJS = tgi-kernel.o \
|
|||||||
tgi_getxres.o \
|
tgi_getxres.o \
|
||||||
tgi_getyres.o \
|
tgi_getyres.o \
|
||||||
tgi_gotoxy.o \
|
tgi_gotoxy.o \
|
||||||
|
tgi_imulround.o \
|
||||||
tgi_init.o \
|
tgi_init.o \
|
||||||
tgi_ioctl.o \
|
tgi_ioctl.o \
|
||||||
tgi_line.o \
|
tgi_line.o \
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <tgi.h>
|
#include <tgi.h>
|
||||||
|
#include <tgi/tgi-kernel.h>
|
||||||
#include <cc65.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,
|
void __fastcall__ tgi_arc (int x, int y, unsigned char rx, unsigned char ry,
|
||||||
unsigned sa, unsigned ea)
|
unsigned sa, unsigned ea)
|
||||||
/* Draw an ellipse arc with center at x/y and radii rx/ry using the current
|
/* 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 */
|
/* Calculate the start coords */
|
||||||
x1 = x + RoundMul (rx, cc65_cos (sa));
|
x1 = x + tgi_imulround (rx, cc65_cos (sa));
|
||||||
y1 = y + RoundMul (ry, cc65_sin (sa));
|
y1 = y + tgi_imulround (ry, cc65_sin (sa));
|
||||||
do {
|
do {
|
||||||
sa += inc;
|
sa += inc;
|
||||||
if (sa >= ea) {
|
if (sa >= ea) {
|
||||||
sa = ea;
|
sa = ea;
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
x2 = x + RoundMul (rx, cc65_cos (sa));
|
x2 = x + tgi_imulround (rx, cc65_cos (sa));
|
||||||
y2 = y - RoundMul (ry, cc65_sin (sa));
|
y2 = y - tgi_imulround (ry, cc65_sin (sa));
|
||||||
tgi_line (x1, y1, x2, y2);
|
tgi_line (x1, y1, x2, y2);
|
||||||
x1 = x2;
|
x1 = x2;
|
||||||
y1 = y2;
|
y1 = y2;
|
||||||
|
54
libsrc/tgi/tgi_imulround.s
Normal file
54
libsrc/tgi/tgi_imulround.s
Normal 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
|
Loading…
x
Reference in New Issue
Block a user