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 void g(int i) {
17 // g(i, x, t, o) -> t
18 u8 tmp;
19 ANDI (t, 0x07)
20 MOV (tmp, i2)
21 ANDI (tmp, 3)
22 TST (tmp)
23 BREQ (skip)
24 SUBI (t, -8)
25 skip:
26 t = data[t];
27 t = (i*t) >> o;
28 AND (t, x)
29 ANDI (t, 3)
30 RET
31 };
32
33 int main(void) {
34 int i = 0;
35 unsigned short n;
36 unsigned short s;
37 u8 acc;
38 //TODO: clear all vars/registers
39 for (;;) {
40 acc = 0;
41 n = (i2<<2 | i1>>6);
42 s = (i3<<7 | i2>>1);
43
44 //voice 1:
45 LDI (x, 1)
46 MOV (t, n)
47 LDI (o, 12)
48 RCALL g(i);
49 MOV (acc, t)
50
51 //voice 2:
52 MOV (x, s)
53 t = n ^ (i2<<3 | i1>>5);
54 LDI (o, 10)
55 RCALL g(i);
56 ADD (acc, t)
57
58 //voice 3:
59 x = s / 3;
60 t = n + ((i3<<13 | i2<<5 | i1>>3) % 3);
61 LDI (o, 10)
62 RCALL g(i);
63 ADD (acc, t)
64
65 //voice 4:
66 x = s / 5;
67 t = 8 + n - ((i3<<14 | i2<<6 | i1>>2) % 3);
68 LDI (o, 9)
69 RCALL g(i);
70 ADD (acc, t)
71
72 putchar(acc<<4);
73 i++;
74 #define tmp acc
75 LDI (tmp, 0)
76 SUBI (i0, -1)
77 ADC (i1, tmp, !i0)
78 ADC (i2, tmp, !i0&&!i1)
79 ADC (i3, tmp, !i0&&!i1&&!i2)
80 }
81 }
Imprint / Impressum