]> git.gir.st - Chiptunes-pms150c.git/blob - bsv.c
a0a1caa782a566565f644d88cfdbb7c6dba8496b
[Chiptunes-pms150c.git] / bsv.c
1 #include <stdio.h>
2 #include "fakeasm.h"
3 typedef unsigned char u8;
4
5 u8 i0, i1, i2; //MEM
6 u8 n; //MEM
7 u8 sample; //MEM
8 u8 tmp_1; //MEM
9 u8 acc; //ACC
10
11 u8 notes[] = {
12 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58,
13 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
14 };
15
16 void g(void){
17 u8 notes_ix = acc & 0x7;
18 if(3&i2)
19 notes_ix += 8;
20 u8 result = ((i1<<8|i0)*notes[notes_ix])>>8; // keep hi byte
21 acc = result;
22 }
23 void main(void){
24 CLEAR (i0)
25 CLEAR (i1)
26 CLEAR (i2)
27 for(;;) {
28 MOV (acc, i2)// "mov mem,mem"
29 MOV (n, acc)// does not exist
30 SL (n)
31 SL (n)
32 MOV (acc, i1)
33 SWAP (acc)
34 AND (acc, 0xf)
35 SR (acc)
36 SR (acc)
37 OR (n, acc)
38
39 MOV (acc, n)
40 CALL (g)
41 SWAP (acc)
42 AND (acc, 0x1)
43 MOV (sample, acc)
44
45 MOV (acc, i2)
46 SL (acc)
47 SL (acc)
48 SL (acc)
49 MOV (tmp_1, acc) // fresh tmp_1:
50 MOV (acc, i1)
51 SWAP (acc)
52 AND (acc, 0xf)
53 SR (acc)
54 OR (acc, tmp_1) // tmp_1 done.
55 XOR (acc, n)
56 CALL (g)
57 SR (acc)
58 AND (acc, i2)
59 SR (acc)
60 AND (acc, 3)
61 ADD (sample, acc)
62
63 { u8 tmp2 = (i2<<5|i1>>3)%3;//TODO
64 MOV (acc, tmp2)
65 ADD (acc, n)
66 CALL (g)
67 } //tmp2
68 SR (acc)
69 SR (acc)
70 MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc
71 MOV (acc, i2)
72 // shift-divide by six
73 // note: i2 is max 0x78; so acc will <= 20.
74
75 acc >>= 1;
76 acc += i2;
77
78 acc >>= 1;
79 acc += 0;
80
81 acc >>= 1;
82 acc += i2;
83
84 acc >>= 1;
85 acc += 0;
86
87 acc >>= 1;
88 acc += i2;
89
90 acc >>= 1;
91 acc += 0;
92
93 acc >>= 1;
94 acc >>= 1;
95
96 // end divide by six
97 AND (acc, tmp_1) // acc restored from tmp_1
98 AND (acc, 3)
99 ADD (sample, acc)
100
101 MOV (acc, n)
102 ADD (acc, 8)
103 { u8 tmp3 = (i2<<6|i1>>2)%3;
104 SUB (acc, tmp3)
105 } // tmp3
106 CALL (g)
107 SR (acc)
108 MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc
109 // shift-divide by ten
110 // note: i2 is max 0x78; so acc will <= 12.
111 acc = i2/10;//TODO
112 // end divide by ten
113 AND (acc, tmp_1) // acc restored from tmp_1
114 AND (acc, 3)
115 ADD (sample, acc)
116
117 MOV (acc, sample)
118 SWAP (acc)
119 putchar(acc);
120
121 INC (i0)
122 i1 += !i0; // ADDC i1
123 i2 += !i1 && !i0; // ADDC i2
124 }
125 }
Imprint / Impressum