5a222a7d18da7f3199023c7eeb5df65dd0edb958
[Chiptunes-pms150c.git] / bsv.c
1 typedef unsigned char u8;
2
3 u8 i0, i1, i2; //MEM
4 u8 acc; //ACC
5
6 u8 notes[] = {
7 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58,
8 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
9 };
10
11 void g(u8 t){
12 u8 notes_ix = t & 0x7;
13 if(3&i2)
14 notes_ix += 8;
15 u8 result = ((i1<<8|i0)*notes[notes_ix])>>8; // keep hi byte
16 acc = result;
17 }
18 void main(void){
19 i0 = i1 = i2 = 0;
20 for(;;) {
21 u8 sample;
22 u8 n = i2<<2 | i1>>6;
23 u8 s = i2>>1;
24
25 g(n);
26 acc >>= 4;
27 acc &= 1&3;
28 sample = acc;
29
30 { u8 tmp;
31 tmp = i2<<3 | i1>>5;
32 tmp ^= n;
33 g(tmp);
34 acc >>= 2;
35 acc &= s&3;
36 sample += acc;
37 } //tmp
38
39 { u8 tmp1 = s/3;
40 u8 tmp2;
41 tmp2 = (i2<<5|i1>>3)%3;
42 tmp2 += n;
43 g(tmp2);
44 acc >>= 2;
45 acc &= tmp1&3;
46 sample += acc;
47 } //tmp1, tmp2
48
49 { u8 tmp1 = s/5;
50 u8 tmp2 = n;
51 { u8 tmp3 = (i2<<6|i1>>2)%3;
52 tmp2 -= tmp3;
53 } // tmp3
54 tmp2 += 8;
55 g(tmp2);
56 acc >>= 1;
57 acc &= tmp1&3;
58 sample += acc;
59 } //tmp1, tmp2
60
61 putchar(sample<<4);
62
63 i0++;
64 i1 += !i0;
65 i2 += !i1 && !i0;
66 }
67 }
Imprint / Impressum