new version
[Chiptunes-pms150c.git] / bsv.c
CommitLineData
5ebb16dc
TG
1#include <stdio.h>
2#include "fakeasm.h"
b3a565e1
TG
3typedef unsigned char u8;
4
268e276e 5u8 i0, i1, i2; //MEM
7e02078f 6u8 n; //MEM
5ebb16dc 7u8 sample; //MEM
d17a26fd 8u8 tmp_1; //MEM
268e276e 9u8 acc; //ACC
f3768c26 10
c1873bed
TG
11u8 notes[] = {
12 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58,
13 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
14};
c320426f 15
b2ed0598
TG
16void g(void){
17 u8 notes_ix = acc & 0x7;
ac66812d
TG
18 if(3&i2)
19 notes_ix += 8;
fb819dd9 20 u8 result = ((i1<<8|i0)*notes[notes_ix])>>8; // keep hi byte
268e276e 21 acc = result;
c395d5c8 22}
f3768c26 23void main(void){
5ebb16dc
TG
24 CLEAR (i0)
25 CLEAR (i1)
26 CLEAR (i2)
f3768c26 27 for(;;) {
fc496164
TG
28 MOV (acc, i2)// "mov mem,mem"
29 MOV (n, acc)// does not exist
5ebb16dc
TG
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)
bd4f3b3e 38
b2ed0598
TG
39 MOV (acc, n)
40 CALL (g)
5ebb16dc
TG
41 SWAP (acc)
42 AND (acc, 0x1)
43 MOV (sample, acc)
bd4f3b3e 44
d17a26fd
TG
45 MOV (acc, i2)
46 SL (acc)
47 SL (acc)
48 SL (acc)
f5823e3f 49 MOV (tmp_1, acc) // fresh tmp_1:
d17a26fd
TG
50 MOV (acc, i1)
51 SWAP (acc)
52 AND (acc, 0xf)
53 SR (acc)
54 OR (acc, tmp_1) // tmp_1 done.
b2ed0598
TG
55 XOR (acc, n)
56 CALL (g)
5ebb16dc
TG
57 SR (acc)
58 AND (acc, i2)
59 SR (acc)
60 AND (acc, 3)
61 ADD (sample, acc)
bd4f3b3e 62
b2ed0598
TG
63 { u8 tmp2 = (i2<<5|i1>>3)%3;//TODO
64 MOV (acc, tmp2)
65 ADD (acc, n)
66 CALL (g)
f345ce49 67 } //tmp2
5ebb16dc
TG
68 SR (acc)
69 SR (acc)
c004ed39
TG
70 MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc
71 MOV (acc, i2)
72 // shift-divide by six
2ae98f0b 73 // note: i2 is max 0x78; so acc will <= 20. (breaks vor values >=128)
7e0dee10
TG
74 SR (acc)
75 ADD (acc, i2)
7e0dee10 76 SR (acc)
7e0dee10
TG
77 SR (acc)
78 ADD (acc, i2)
7e0dee10 79 SR (acc)
7e0dee10
TG
80 SR (acc)
81 ADD (acc, i2)
7e0dee10 82 SR (acc)
7e0dee10 83 SR (acc)
7e0dee10 84 SR (acc)
c004ed39
TG
85 // end divide by six
86 AND (acc, tmp_1) // acc restored from tmp_1
5ebb16dc
TG
87 AND (acc, 3)
88 ADD (sample, acc)
bd4f3b3e 89
b2ed0598 90 MOV (acc, n)
2d826e28 91 ADD (acc, 8)
b2ed0598
TG
92 { u8 tmp3 = (i2<<6|i1>>2)%3;
93 SUB (acc, tmp3)
94 } // tmp3
b2ed0598 95 CALL (g)
5ebb16dc 96 SR (acc)
c004ed39
TG
97 MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc
98 // shift-divide by ten
b29570af 99 // note: i2 is max 0x78; so acc will <= 12.
c004ed39
TG
100 acc = i2/10;//TODO
101 // end divide by ten
102 AND (acc, tmp_1) // acc restored from tmp_1
5ebb16dc
TG
103 AND (acc, 3)
104 ADD (sample, acc)
bd4f3b3e 105
be69f3a9
TG
106 MOV (acc, sample)
107 SWAP (acc)
108 putchar(acc);
ac66812d 109
42c6050e
TG
110 INC (i0)
111 i1 += !i0; // ADDC i1
112 i2 += !i1 && !i0; // ADDC i2
fef0e35b 113 }
c395d5c8 114}
Imprint / Impressum