new version
[Chiptunes.git] / foo.c
1 #include <stdio.h>
2 #include "fakeasm.h"
3 typedef unsigned char u8;
4
5 u8 data[] = {
6 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58,
7 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
8 };
9 u8 i0;
10 u8 i1;
11 u8 i2;
12 u8 i3;
13 u8 x;
14 u8 t;
15 u8 o;
16 u8 g(int i) {
17 u8 tmp;
18 ANDI (t, 0x07)
19 tmp = i2;
20 ANDI (tmp, 3)
21 TST (tmp)
22 BREQ (skip)
23 SUBI (t, -8)
24 skip:
25 t = data[t];
26 t = (i*t) >> o;
27 AND (t, x)
28 ANDI (t, 3)
29 return t;
30 };
31
32 int main(void) {
33 int i = 0;
34 unsigned short n;
35 unsigned short s;
36 u8 acc;
37 for (;;) {
38 acc = 0;
39 n = i >> 14;
40 s = i >> 17;
41
42 //voice 1:
43 LDI (x, 1)
44 MOV (t, n)
45 LDI (o, 12)
46 acc += g(i);
47
48 //voice 2:
49 MOV (x, s)
50 t = n ^ i >> 13;
51 LDI (o, 10)
52 acc += g(i);
53
54 //voice 3:
55 x = s / 3;
56 t = n + ((i >> 11) % 3);
57 LDI (o, 10)
58 acc += g(i);
59
60 //voice 4:
61 x = s / 5;
62 t = 8 + n - ((i >> 10) % 3);
63 LDI (o, 9)
64 acc += g(i);
65
66 putchar(acc<<4);
67 i++;
68 i0 = i;
69 i1 = i>>8;
70 i2 = i>>16;
71 i3 = i>>24;
72 }
73 }
Imprint / Impressum