new version
[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;
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;
36 acc &= 3;
37 sample += acc;
38 } //tmp
39
40 { u8 tmp1 = s/3;
41 u8 tmp2;
42 tmp2 = (i2<<5|i1>>3)%3;
43 tmp2 += n;
44 g(tmp2);
45 acc >>= 2;
46 acc &= tmp1;
47 acc &= 3;
48 sample += acc;
49 } //tmp1, tmp2
50
51 { u8 tmp1 = s/5;
52 u8 tmp2 = n;
53 { u8 tmp3 = (i2<<6|i1>>2)%3;
54 tmp2 -= tmp3;
55 } // tmp3
56 tmp2 += 8;
57 g(tmp2);
58 acc >>= 1;
59 acc &= tmp1;
60 acc &= 3;
61 sample += acc;
62 } //tmp1, tmp2
63
64 putchar(sample<<4);
65
66 i0++;
67 i1 += !i0;
68 i2 += !i1 && !i0;
69 }
70 }
Imprint / Impressum