mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-08 12:30:58 +00:00
Found optimal 8-bit and 16-bit versions of atan2.
This commit is contained in:
parent
83ed437553
commit
f25e0bde3b
2
src/main/fragment/vbsaa_eq_0_then_la1.asm
Normal file
2
src/main/fragment/vbsaa_eq_0_then_la1.asm
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
cmp #0
|
||||||
|
beq {la1}
|
@ -20,7 +20,7 @@ word atan2_16(signed word x, signed word y) {
|
|||||||
signed word yi = (y>0)?y:-y;
|
signed word yi = (y>0)?y:-y;
|
||||||
signed word xi = (x>0)?x:-x;
|
signed word xi = (x>0)?x:-x;
|
||||||
word angle = 0;
|
word angle = 0;
|
||||||
for( byte i: 0..CORDIC_ITERATIONS_16) {
|
for( byte i: 0..CORDIC_ITERATIONS_16-1) {
|
||||||
if(yi==0) {
|
if(yi==0) {
|
||||||
// We found the correct angle!
|
// We found the correct angle!
|
||||||
break;
|
break;
|
||||||
@ -62,7 +62,7 @@ byte atan2_8(signed byte x, signed byte y) {
|
|||||||
signed byte yi = (y>0)?y:-y;
|
signed byte yi = (y>0)?y:-y;
|
||||||
signed byte xi = (x>0)?x:-x;
|
signed byte xi = (x>0)?x:-x;
|
||||||
byte angle = 0;
|
byte angle = 0;
|
||||||
for( byte i: 0..CORDIC_ITERATIONS_8) {
|
for( byte i: 0..CORDIC_ITERATIONS_8-1) {
|
||||||
if(yi==0) {
|
if(yi==0) {
|
||||||
// We found the correct angle!
|
// We found the correct angle!
|
||||||
break;
|
break;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
import "font-hex"
|
import "font-hex"
|
||||||
import "atan2"
|
import "atan2"
|
||||||
import "c64"
|
import "c64"
|
||||||
|
import "print"
|
||||||
|
|
||||||
const byte* CHARSET = 0x2000;
|
const byte* CHARSET = 0x2000;
|
||||||
const byte* SCREEN = 0x2800;
|
const byte* SCREEN = 0x2800;
|
||||||
@ -15,27 +16,36 @@ kickasm(pc SCREEN_REF) {{
|
|||||||
.byte round(256*atan2(y, x)/PI/2)
|
.byte round(256*atan2(y, x)/PI/2)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
init_font_hex(CHARSET);
|
init_font_hex(CHARSET);
|
||||||
*D018 = toD018(SCREEN, CHARSET);
|
*D018 = toD018(SCREEN, CHARSET);
|
||||||
|
|
||||||
byte* screen = SCREEN;
|
byte* screen = SCREEN;
|
||||||
byte* screen_ref = SCREEN_REF;
|
byte* screen_ref = SCREEN_REF;
|
||||||
|
//word diff_sum = 0;
|
||||||
for(signed byte y: -12..12) {
|
for(signed byte y: -12..12) {
|
||||||
for(signed byte x: -19..20) {
|
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 xw = (signed word)(word){ (byte)x, 0 };
|
||||||
signed word yw = (signed word)(word){ (byte)y, 0 };
|
signed word yw = (signed word)(word){ (byte)y, 0 };
|
||||||
word angle_w = atan2_16(xw, yw);
|
word angle_w = atan2_16(xw, yw);
|
||||||
|
byte ang_w = >(angle_w+0x0080);
|
||||||
//*screen++ = (>angle_w)-angle_b;
|
//*screen++ = (>angle_w)-angle_b;
|
||||||
//*screen++ = >angle_w;
|
*screen++ = >angle_w;
|
||||||
*screen++ = (>(angle_w+0x0080)) - *screen_ref++;
|
//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_ref++;
|
||||||
|
|
||||||
|
//*screen++ = angle_b;
|
||||||
//*screen++ = *screen_ref++;
|
//*screen++ = *screen_ref++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//print_word(diff_sum);
|
||||||
byte* col00 = COLS+12*40+19;
|
byte* col00 = COLS+12*40+19;
|
||||||
while(true) (*col00)++;
|
while(true) (*col00)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte diff(byte bb1, byte bb2) {
|
||||||
|
return (bb1<bb2)?(bb2-bb1):bb1-bb2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user