new version
authorTobias Girstmair <tobi@isticktoit.net>
Thu, 4 Mar 2021 01:02:38 +0000 (02:02 +0100)
committerTobias Girstmair <tobi@isticktoit.net>
Thu, 4 Mar 2021 01:02:49 +0000 (02:02 +0100)
bsv.c
fakeasm.h [new file with mode: 0644]

diff --git a/bsv.c b/bsv.c
index e954cb24b6080332c037abfb5bc81e53e3ab99f0..9a3c60841667b60a23f5388f750b07a851ad17e6 100644 (file)
--- a/bsv.c
+++ b/bsv.c
@@ -1,7 +1,10 @@
+#include <stdio.h>
+#include "fakeasm.h"
 typedef unsigned char u8;
 
 u8 i0, i1, i2; //MEM
 u8 n; //MEM
+u8 sample; //MEM
 u8 acc; //ACC
 
 u8 notes[] = {
@@ -17,31 +20,26 @@ void g(u8 t){
        acc = result;
 }
 void main(void){
-       i0 = i1 = i2 = 0;
-       // clear i0
-       // clear i1
-       // clear i2
+       CLEAR   (i0)
+       CLEAR   (i1)
+       CLEAR   (i2)
        for(;;) {
-               u8 sample;
-               n = i2<<2 | i1>>6;
-               // mov n, i2
-               // sl n
-               // sl n
-               // mov acc, i1
-               // swap acc
-               // and acc, 0xf
-               // sr acc
-               // sr acc
-               // or n, acc
+               /*n = i2<<2 | i1>>6;*/
+               MOV     (n, i2)
+               SL      (n)
+               SL      (n)
+               MOV     (acc, i1)
+               SWAP    (acc)
+               AND     (acc, 0xf)
+               SR      (acc)
+               SR      (acc)
+               OR      (n, acc)
 
                g(n);
                //^TODO
-               acc >>= 4;
-               // swap acc
-               acc &= 1;
-               // and acc, 0x1
-               sample = acc;
-               // mov sample, acc
+               SWAP    (acc)
+               AND     (acc, 0x1)
+               MOV     (sample, acc)
 
                { u8 tmp;
                  tmp = i2<<3 | i1>>5;
@@ -49,16 +47,11 @@ void main(void){
                g(tmp);
                //^TODO
                } //tmp
-               acc >>= 1;
-               // sr acc
-               acc &= i2;
-               // and acc, i2
-               acc >>= 1;
-               // sr acc
-               acc &= 3;
-               // and acc, 3
-               sample += acc;
-               // add sample, acc
+               SR      (acc)
+               AND     (acc, i2)
+               SR      (acc)
+               AND     (acc, 3)
+               ADD     (sample, acc)
 
                { u8 tmp2;
                  tmp2 = (i2<<5|i1>>3)%3;
@@ -66,17 +59,13 @@ void main(void){
                g(tmp2);
                //^TODO
                } //tmp2
-               acc >>= 2;
-               // sr acc
-               // sr acc
+               SR      (acc)
+               SR      (acc)
                { u8 tmp1 = i2/6;
-               acc &= tmp1;
-               //^TODO
+               AND     (acc, tmp1)
                } //tmp1
-               acc &= 3;
-               // and acc, 3
-               sample += acc;
-               // add sample, acc
+               AND     (acc, 3)
+               ADD     (sample, acc)
 
                { u8 tmp2 = n;
                  { u8 tmp3 = (i2<<6|i1>>2)%3;
@@ -85,12 +74,12 @@ void main(void){
                  tmp2 += 8;
                g(tmp2);
                } //tmp2
-               acc >>= 1;
+               SR      (acc)
                { u8 tmp1 = i2/10;
-               acc &= tmp1;
+               AND     (acc, tmp1)
                } //tmp1
-               acc &= 3;
-               sample += acc;
+               AND     (acc, 3)
+               ADD     (sample, acc)
 
                putchar(sample<<4);
 
diff --git a/fakeasm.h b/fakeasm.h
new file mode 100644 (file)
index 0000000..946be8a
--- /dev/null
+++ b/fakeasm.h
@@ -0,0 +1,8 @@
+#define MOV(dst, src)  dst = src;
+#define SL(dst)                dst <<= 1;
+#define SR(dst)                dst >>= 1;
+#define SWAP(dst)      dst = (dst<<4 | dst>>4); //XXX: only for ACC!
+#define AND(dst, src)  dst &= src;  //xxx: overloaded for acc/mem/imm
+#define OR(dst, src)   dst |= src;
+#define CLEAR(dst)     dst = 0;
+#define ADD(dst, src)  dst += src; //xxx: overloaded for acc/mem/imm
Imprint / Impressum