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;
46a8d83c
TG
16void g(int i) {
17 // g(i, x, t, o) -> t
63363195 18 u8 tmp;
0f219114 19 ANDI (t, 0x07)
32632e61 20 MOV (tmp, i2)
63363195 21 ANDI (tmp, 3)
09cf3949
TG
22 TST (tmp)
23 BREQ (skip)
24 SUBI (t, -8)
25 skip:
c616f0c2 26 t = data[t];
c616f0c2
TG
27 t = (i*t) >> o;
28 AND (t, x)
29 ANDI (t, 3)
46a8d83c 30 RET
61fab018
TG
31};
32
33int main(void) {
5dd8b8ff 34 int i = 0;
c65ddced
TG
35 unsigned short n;
36 unsigned short s;
ab6fe4c2 37 u8 acc;
5dd8b8ff 38 for (;;) {
ab6fe4c2 39 acc = 0;
fe9a76e4
TG
40 n = i >> 14;
41 s = i >> 17;
3b86ca43
TG
42
43 //voice 1:
44 LDI (x, 1)
45 MOV (t, n)
46 LDI (o, 12)
46a8d83c
TG
47 RCALL g(i);
48 MOV (acc, t)
3b86ca43
TG
49
50 //voice 2:
51 MOV (x, s)
52 t = n ^ i >> 13;
53 LDI (o, 10)
46a8d83c
TG
54 RCALL g(i);
55 ADD (acc, t)
3b86ca43
TG
56
57 //voice 3:
58 x = s / 3;
59 t = n + ((i >> 11) % 3);
60 LDI (o, 10)
46a8d83c
TG
61 RCALL g(i);
62 ADD (acc, t)
3b86ca43
TG
63
64 //voice 4:
65 x = s / 5;
66 t = 8 + n - ((i >> 10) % 3);
67 LDI (o, 9)
46a8d83c
TG
68 RCALL g(i);
69 ADD (acc, t)
bfce2f8c 70
ab6fe4c2 71 putchar(acc<<4);
06aad1ff
TG
72 i++;
73 i0 = i;
74 i1 = i>>8;
75 i2 = i>>16;
76 i3 = i>>24;
fe9a76e4 77 }
61fab018 78}
Imprint / Impressum