16
16
* You should have received a copy of the GNU General Public License
17
17
* along with this program; if not, write to the Free Software
18
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
* DSOUNDV1/FL-TR8MA boards (32K WRAM, 8/16M), 178 mapper boards (8K WRAM, 4/8M)
21
* Various Education Cartridges
21
25
#include "mapinc.h"
23
27
static uint8 reg[4];
24
29
static uint8 *WRAM = NULL;
25
30
static uint32 WRAMSIZE;
33
static uint8 pcm_enable = 0;
34
static int16 pcm_latch = 0x3F6, pcm_clock = 0x3F6;
35
static writefunc pcmwrite;
27
37
static SFORMAT StateRegs[] =
29
39
{ reg, 4, "REGS" },
43
static int16 step_size[49] = {
44
16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
45
41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
46
107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
47
279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
48
724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
50
static int32 step_adj[16] = { -1, -1, -1, -1, 2, 5, 7, 9, -1, -1, -1, -1, 2, 5, 7, 9 };
53
static int32 jedi_table[16 * 49];
54
static int32 acc = 0; //ADPCM accumulator, initial condition must be 0
55
static int32 decstep = 0; //ADPCM decoding step, initial condition must be 0
57
static void jedi_table_init() {
60
for (step = 0; step < 49; step++) {
61
for (nib = 0; nib < 16; nib++) {
62
int value = (2 * (nib & 0x07) + 1) * step_size[step] / 8;
63
jedi_table[step * 16 + nib] = ((nib & 0x08) != 0) ? -value : value;
68
static uint8 decode(uint8 code) {
69
acc += jedi_table[decstep + code];
70
if ((acc & ~0x7ff) != 0) // acc is > 2047
73
decstep += step_adj[code & 7] * 16;
74
if (decstep < 0) decstep = 0;
75
if (decstep > 48 * 16) decstep = 48 * 16;
76
return (acc >> 8) & 0xff;
33
79
static void Sync(void) {
34
uint8 bank = (reg[2] & 3) << 3;
80
uint32 sbank = reg[1] & 0x7;
81
uint32 bbank = reg[2];
83
setprg8r(0x10, 0x6000, reg[3] & 3);
84
if (reg[0] & 2) { // UNROM mode
85
setprg16(0x8000, (bbank << 3) | sbank);
87
setprg16(0xC000, (bbank << 3) | 6 | (reg[1] & 1));
89
setprg16(0xC000, (bbank << 3) | 7);
91
uint32 bank = (bbank << 3) | sbank;
93
setprg16(0x8000, bank);
94
setprg16(0xC000, bank);
96
setprg32(0x8000, bank >> 1);
35
98
setmirror((reg[0] & 1) ^ 1);
36
setprg8r(0x10, 0x6000, 0);
39
setprg16(0x8000, (reg[1] & 7) | bank);
40
setprg16(0xC000, ((~0) & 7) | bank);
42
setprg16(0x8000, (reg[1] & 6) | bank);
43
setprg16(0xC000, (reg[1] & 6) | bank | 1);
47
101
static DECLFW(M178Write) {
103
// FCEU_printf("cmd %04x:%02x\n", A, V);
107
static DECLFW(M178WriteSnd) {
111
// pcmwrite(0x4011, (V & 0xF) << 3);
112
pcmwrite(0x4011, decode(V & 0xf));
116
FCEU_printf("misc %04x:%02x\n", A, V);
119
static DECLFR(M178ReadSnd) {
121
return (X.DB & 0xBF) | ((pcm_enable ^ 1) << 6);
52
126
static void M178Power(void) {
127
reg[0] = reg[1] = reg[2] = reg[3] = 0;
58
SetReadHandler(0x6000, 0x7FFF, CartBR);
59
SetWriteHandler(0x6000, 0x7FFF, CartBW);
60
SetReadHandler(0x8000, 0xFFFF, CartBR);
61
SetWriteHandler(0x4800, 0x4803, M178Write);
129
pcmwrite = GetWriteHandler(0x4011);
130
SetWriteHandler(0x4800, 0x4fff, M178Write);
131
SetWriteHandler(0x5800, 0x5fff, M178WriteSnd);
132
SetReadHandler(0x5800, 0x5fff, M178ReadSnd);
133
SetReadHandler(0x6000, 0x7fff, CartBR);
134
SetWriteHandler(0x6000, 0x7fff, CartBW);
135
SetReadHandler(0x8000, 0xffff, CartBR);
138
static void M178SndClk(int a) {
141
if (pcm_latch <= 0) {
142
pcm_latch += pcm_clock;
64
148
static void M178Close(void) {