1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Found optimal 8-bit and 16-bit versions of atan2.

This commit is contained in:
Jesper Gravgaard 2019-06-28 22:45:26 +02:00
parent 83ed437553
commit f25e0bde3b
3 changed files with 19 additions and 7 deletions

View File

@ -0,0 +1,2 @@
cmp #0
beq {la1}

View File

@ -20,7 +20,7 @@ word atan2_16(signed word x, signed word y) {
signed word yi = (y>0)?y:-y;
signed word xi = (x>0)?x:-x;
word angle = 0;
for( byte i: 0..CORDIC_ITERATIONS_16) {
for( byte i: 0..CORDIC_ITERATIONS_16-1) {
if(yi==0) {
// We found the correct angle!
break;
@ -62,7 +62,7 @@ byte atan2_8(signed byte x, signed byte y) {
signed byte yi = (y>0)?y:-y;
signed byte xi = (x>0)?x:-x;
byte angle = 0;
for( byte i: 0..CORDIC_ITERATIONS_8) {
for( byte i: 0..CORDIC_ITERATIONS_8-1) {
if(yi==0) {
// We found the correct angle!
break;

View File

@ -4,6 +4,7 @@
import "font-hex"
import "atan2"
import "c64"
import "print"
const byte* CHARSET = 0x2000;
const byte* SCREEN = 0x2800;
@ -15,27 +16,36 @@ kickasm(pc SCREEN_REF) {{
.byte round(256*atan2(y, x)/PI/2)
}}
void main() {
init_font_hex(CHARSET);
*D018 = toD018(SCREEN, CHARSET);
byte* screen = SCREEN;
byte* screen_ref = SCREEN_REF;
//word diff_sum = 0;
for(signed byte y: -12..12) {
for(signed byte x: -19..20) {
//byte angle_b = atan2_8(x, y);
byte angle_b = atan2_8(x, y);
signed word xw = (signed word)(word){ (byte)x, 0 };
signed word yw = (signed word)(word){ (byte)y, 0 };
word angle_w = atan2_16(xw, yw);
byte ang_w = >(angle_w+0x0080);
//*screen++ = (>angle_w)-angle_b;
//*screen++ = >angle_w;
*screen++ = (>(angle_w+0x0080)) - *screen_ref++;
*screen++ = >angle_w;
//diff_sum += diff(ang_w, *screen_ref);
//diff_sum += diff(angle_b, *screen_ref);
//*screen++ = ang_w - *screen_ref++;
//*screen++ = angle_b - *screen_ref++;
//*screen++ = angle_b;
//*screen++ = *screen_ref++;
}
}
//print_word(diff_sum);
byte* col00 = COLS+12*40+19;
while(true) (*col00)++;
}
byte diff(byte bb1, byte bb2) {
return (bb1<bb2)?(bb2-bb1):bb1-bb2;
}