new version
[Chiptunes-pms150c.git] / bsv.c
1 #include <stdio.h>
2 #include "fakeasm.h"
3 typedef unsigned char u8;
4
5 u8 i0, i1, i2; //MEM
6 u8 n; //MEM
7 u8 sample; //MEM
8 u8 acc; //ACC
9
10 u8 notes[] = {
11 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58,
12 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
13 };
14
15 void g(u8 t){
16 u8 notes_ix = t & 0x7;
17 if(3&i2)
18 notes_ix += 8;
19 u8 result = ((i1<<8|i0)*notes[notes_ix])>>8; // keep hi byte
20 acc = result;
21 }
22 void main(void){
23 CLEAR (i0)
24 CLEAR (i1)
25 CLEAR (i2)
26 for(;;) {
27 /*n = i2<<2 | i1>>6;*/
28 MOV (n, i2)
29 SL (n)
30 SL (n)
31 MOV (acc, i1)
32 SWAP (acc)
33 AND (acc, 0xf)
34 SR (acc)
35 SR (acc)
36 OR (n, acc)
37
38 g(n);
39 //^TODO
40 SWAP (acc)
41 AND (acc, 0x1)
42 MOV (sample, acc)
43
44 { u8 tmp;
45 tmp = i2<<3 | i1>>5;
46 tmp ^= n;
47 g(tmp);
48 //^TODO
49 } //tmp
50 SR (acc)
51 AND (acc, i2)
52 SR (acc)
53 AND (acc, 3)
54 ADD (sample, acc)
55
56 { u8 tmp2;
57 tmp2 = (i2<<5|i1>>3)%3;
58 tmp2 += n;
59 g(tmp2);
60 //^TODO
61 } //tmp2
62 SR (acc)
63 SR (acc)
64 { u8 tmp1 = i2/6;
65 AND (acc, tmp1)
66 } //tmp1
67 AND (acc, 3)
68 ADD (sample, acc)
69
70 { u8 tmp2 = n;
71 { u8 tmp3 = (i2<<6|i1>>2)%3;
72 tmp2 -= tmp3;
73 } // tmp3
74 tmp2 += 8;
75 g(tmp2);
76 } //tmp2
77 SR (acc)
78 { u8 tmp1 = i2/10;
79 AND (acc, tmp1)
80 } //tmp1
81 AND (acc, 3)
82 ADD (sample, acc)
83
84 putchar(sample<<4);
85
86 INC (i0)
87 i1 += !i0; // ADDC i1
88 i2 += !i1 && !i0; // ADDC i2
89 }
90 }
Imprint / Impressum