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 x;
10 u8 t;
11 u8 o;
12 u8 g(int i) {
13 u8 tmp;
14 ANDI (t, 0x07)
15 tmp = i >> 16;
16 ANDI (tmp, 3)
17 TST (tmp)
18 BREQ (skip)
19 SUBI (t, -8)
20 skip:
21 t = data[t];
22 t = (i*t) >> o;
23 AND (t, x)
24 ANDI (t, 3)
25 return t;
26 };
27
28 int main(void) {
29 int i;
30 unsigned short n;
31 unsigned short s;
32 u8 acc;
33 for (i = 0;; i++) {
34 acc = 0;
35 n = i >> 14;
36 s = i >> 17;
37
38 //voice 1:
39 LDI (x, 1)
40 MOV (t, n)
41 LDI (o, 12)
42 acc += g(i);
43
44 //voice 2:
45 MOV (x, s)
46 t = n ^ i >> 13;
47 LDI (o, 10)
48 acc += g(i);
49
50 //voice 3:
51 x = s / 3;
52 t = n + ((i >> 11) % 3);
53 LDI (o, 10)
54 acc += g(i);
55
56 //voice 4:
57 x = s / 5;
58 t = 8 + n - ((i >> 10) % 3);
59 LDI (o, 9)
60 acc += g(i);
61 putchar(acc<<4);
62 }
63 }
Imprint / Impressum