From 5d38d8c6ec65fd53d8dfc562260bfc486b25eda9 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Thu, 18 Oct 2018 23:28:59 +0200 Subject: [PATCH] Changed rotate to use 8-bit sine and 8x8 bit multiplication. --- src/main/fragment/vwsz1=vbsaa_plus_vbuc1.asm | 15 +++++++++++++++ src/main/fragment/vwsz1=vwsz1_rol_1.asm | 2 ++ src/main/fragment/vwsz1=vwsz1_rol_2.asm | 4 ++++ src/main/fragment/vwsz1=vwsz2_rol_1.asm | 6 ++++++ src/test/kc/examples/rotate/rotate.kc | 16 ++++++++-------- 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/main/fragment/vwsz1=vbsaa_plus_vbuc1.asm create mode 100644 src/main/fragment/vwsz1=vwsz1_rol_1.asm create mode 100644 src/main/fragment/vwsz1=vwsz1_rol_2.asm create mode 100644 src/main/fragment/vwsz1=vwsz2_rol_1.asm diff --git a/src/main/fragment/vwsz1=vbsaa_plus_vbuc1.asm b/src/main/fragment/vwsz1=vbsaa_plus_vbuc1.asm new file mode 100644 index 000000000..126b62c53 --- /dev/null +++ b/src/main/fragment/vwsz1=vbsaa_plus_vbuc1.asm @@ -0,0 +1,15 @@ +sta {z1} +// sign-extend the byte +ora #$7f +bmi !+ +lda #0 +!: +sta {z1}+1 +// add the constant +lda {z1} +clc +adc #{c1} +sta {z1} +lda {z1}+1 +adc #0 +sta {z1}+1 diff --git a/src/main/fragment/vwsz1=vwsz1_rol_1.asm b/src/main/fragment/vwsz1=vwsz1_rol_1.asm new file mode 100644 index 000000000..041644ce5 --- /dev/null +++ b/src/main/fragment/vwsz1=vwsz1_rol_1.asm @@ -0,0 +1,2 @@ +asl {z1} +rol {z1}+1 diff --git a/src/main/fragment/vwsz1=vwsz1_rol_2.asm b/src/main/fragment/vwsz1=vwsz1_rol_2.asm new file mode 100644 index 000000000..e7f769c78 --- /dev/null +++ b/src/main/fragment/vwsz1=vwsz1_rol_2.asm @@ -0,0 +1,4 @@ +asl {z1} +rol {z1}+1 +asl {z1} +rol {z1}+1 diff --git a/src/main/fragment/vwsz1=vwsz2_rol_1.asm b/src/main/fragment/vwsz1=vwsz2_rol_1.asm new file mode 100644 index 000000000..0b0cf9a30 --- /dev/null +++ b/src/main/fragment/vwsz1=vwsz2_rol_1.asm @@ -0,0 +1,6 @@ +lda {z2} +asl +sta {z1} +lda {z2}+1 +rol +sta {z1}+1 \ No newline at end of file diff --git a/src/test/kc/examples/rotate/rotate.kc b/src/test/kc/examples/rotate/rotate.kc index 056b04563..e0d7d1fef 100644 --- a/src/test/kc/examples/rotate/rotate.kc +++ b/src/test/kc/examples/rotate/rotate.kc @@ -40,18 +40,18 @@ void anim() { signed word max = -1000; byte angle = 0; - signed word x = 89; // signed fixed[15.0] - signed word y = 0; + signed byte x = 89; // signed fixed[7.0] + signed byte y = 0; while(true) { while(*RASTER!=$ff) {} (*BORDERCOL)++; - signed word sin_a = (signed word) { SIN_HI[angle], SIN_LO[angle] }; // signed fixed[0.15] - signed word cos_a = (signed word) { COS_HI[angle], COS_LO[angle] }; // signed fixed[0.15] - signed dword xr = mulf16s(cos_a, x)<<1 - mulf16s(sin_a, y)<<1; // signed fixed[16.16] - signed dword yr = mulf16s(cos_a, y)<<1 + mulf16s(sin_a, x)<<1; // signed fixed[16.16] - signed word xpos = ((signed word) >xr) + 89 + 24 + 60; - signed word ypos = ((signed word) >yr) + 89 + 51; + signed byte sin_a = (signed byte) SIN_HI[angle]; // signed fixed[0.7] + signed byte cos_a = (signed byte) COS_HI[angle]; // signed fixed[0.7] + signed word xr = mulf8s(cos_a, x)<<1 - mulf8s(sin_a, y)<<1; // signed fixed[8.8] + signed word yr = mulf8s(cos_a, y)<<1 + mulf8s(sin_a, x)<<1; // signed fixed[8.8] + signed word xpos = ((signed byte) >xr) + 89 + 24 + 60; + signed word ypos = ((signed byte) >yr) + 89 + 51; SPRITES_XPOS[0] = xpos; SPRITES_YPOS[0] =