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;
965274e2 16void g(void) {
46a8d83c 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];
965274e2 27 t = ((i3<<24|i2<<16|i1<<8|i0)*t) >> o;
c616f0c2
TG
28 AND (t, x)
29 ANDI (t, 3)
46a8d83c 30 RET
61fab018
TG
31};
32
33int main(void) {
a1631438
TG
34 u8 n;
35 u8 s;
ab6fe4c2 36 u8 acc;
89f35588 37 //TODO: clear all vars/registers
5dd8b8ff 38 for (;;) {
ab6fe4c2 39 acc = 0;
0eba146b 40 n = (i2<<2 | i1>>6);
b67a2de3 41 s = (i3<<7 | i2>>1);
3b86ca43
TG
42
43 //voice 1:
44 LDI (x, 1)
45 MOV (t, n)
46 LDI (o, 12)
965274e2 47 RCALL g();
46a8d83c 48 MOV (acc, t)
3b86ca43
TG
49
50 //voice 2:
51 MOV (x, s)
1b023e92 52 #define tmp o
94c4920f
TG
53 MOV (tmp, i2)
54 LSL (tmp)
55 LSL (tmp)
56 LSL (tmp)
57 MOV (t, i1)
4b0b7dc5
TG
58 SWAP (t)
59 ANDI (t, 0xf)
60 LSR (t)
94c4920f 61 OR (t, tmp)
1b023e92 62 #undef tmp
23872091 63 EOR (t, n)
3b86ca43 64 LDI (o, 10)
965274e2 65 RCALL g();
46a8d83c 66 ADD (acc, t)
3b86ca43
TG
67
68 //voice 3:
69 x = s / 3;
d9218a18 70 t = n + ((i3<<13 | i2<<5 | i1>>3) % 3);
3b86ca43 71 LDI (o, 10)
965274e2 72 RCALL g();
46a8d83c 73 ADD (acc, t)
3b86ca43
TG
74
75 //voice 4:
76 x = s / 5;
704b11ab 77 t = 8 + n - ((i3<<14 | i2<<6 | i1>>2) % 3);
3b86ca43 78 LDI (o, 9)
965274e2 79 RCALL g();
46a8d83c 80 ADD (acc, t)
bfce2f8c 81
ab6fe4c2 82 putchar(acc<<4);
89f35588
TG
83 #define tmp acc
84 LDI (tmp, 0)
85 SUBI (i0, -1)
86 ADC (i1, tmp, !i0)
87 ADC (i2, tmp, !i0&&!i1)
88 ADC (i3, tmp, !i0&&!i1&&!i2)
dd7bbc4a 89 #undef tmp
fe9a76e4 90 }
61fab018 91}
Imprint / Impressum