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;
89f35588 38 //TODO: clear all vars/registers
5dd8b8ff 39 for (;;) {
ab6fe4c2 40 acc = 0;
0eba146b 41 n = (i2<<2 | i1>>6);
b67a2de3 42 s = (i3<<7 | i2>>1);
3b86ca43
TG
43
44 //voice 1:
45 LDI (x, 1)
46 MOV (t, n)
47 LDI (o, 12)
46a8d83c
TG
48 RCALL g(i);
49 MOV (acc, t)
3b86ca43
TG
50
51 //voice 2:
52 MOV (x, s)
53c905aa 53 t = n ^ (i2<<3 | i1>>5);
3b86ca43 54 LDI (o, 10)
46a8d83c
TG
55 RCALL g(i);
56 ADD (acc, t)
3b86ca43
TG
57
58 //voice 3:
59 x = s / 3;
d9218a18 60 t = n + ((i3<<13 | i2<<5 | i1>>3) % 3);
3b86ca43 61 LDI (o, 10)
46a8d83c
TG
62 RCALL g(i);
63 ADD (acc, t)
3b86ca43
TG
64
65 //voice 4:
66 x = s / 5;
704b11ab 67 t = 8 + n - ((i3<<14 | i2<<6 | i1>>2) % 3);
3b86ca43 68 LDI (o, 9)
46a8d83c
TG
69 RCALL g(i);
70 ADD (acc, t)
bfce2f8c 71
ab6fe4c2 72 putchar(acc<<4);
06aad1ff 73 i++;
89f35588
TG
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)
fe9a76e4 80 }
61fab018 81}
Imprint / Impressum