.global _tgi_getxres
.global _tgi_getyres
.global _tgi_gotoxy
+ .global _tgi_imulround
.global _tgi_init
.global _tgi_install
.global _tgi_ioctl
* 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. */
-/* 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 */
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 */
tgi_getxres.o \
tgi_getyres.o \
tgi_gotoxy.o \
+ tgi_imulround.o \
tgi_init.o \
tgi_ioctl.o \
tgi_line.o \
#include <tgi.h>
+#include <tgi/tgi-kernel.h>
#include <cc65.h>
-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
}
/* 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;
--- /dev/null
+;
+; 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