new version
[Chiptunes.git] / foo.c
CommitLineData
61fab018 1#include <stdio.h>
da32ed67 2#include "fakeasm.h"
61fab018 3typedef unsigned char u8;
da32ed67 4
24abdcbb
TG
5u8 data[] = {
6 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58,
7 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
8};
06aad1ff
TG
9u8 i0;
10u8 i1;
11u8 i2;
12u8 i3;
3b86ca43
TG
13u8 x;
14u8 t;
15u8 o;
16u8 g(int i) {
63363195 17 u8 tmp;
0f219114 18 ANDI (t, 0x07)
32632e61 19 MOV (tmp, i2)
63363195 20 ANDI (tmp, 3)
09cf3949
TG
21 TST (tmp)
22 BREQ (skip)
23 SUBI (t, -8)
24 skip:
c616f0c2 25 t = data[t];
c616f0c2
TG
26 t = (i*t) >> o;
27 AND (t, x)
28 ANDI (t, 3)
29 return t;
61fab018
TG
30};
31
32int main(void) {
5dd8b8ff 33 int i = 0;
c65ddced
TG
34 unsigned short n;
35 unsigned short s;
ab6fe4c2 36 u8 acc;
5dd8b8ff 37 for (;;) {
ab6fe4c2 38 acc = 0;
fe9a76e4
TG
39 n = i >> 14;
40 s = i >> 17;
3b86ca43
TG
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);
bfce2f8c 65
ab6fe4c2 66 putchar(acc<<4);
06aad1ff
TG
67 i++;
68 i0 = i;
69 i1 = i>>8;
70 i2 = i>>16;
71 i3 = i>>24;
fe9a76e4 72 }
61fab018 73}
Imprint / Impressum