This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
/
midcsd.cpp
185 lines (148 loc) · 3.7 KB
/
midcsd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Cheap Squeak Deluxe audio module
// based on MAME sources by Aaron Giles
#include "burnint.h"
#include "m68000_intf.h"
#include "6821pia.h"
#include "dac.h"
static UINT16 dacvalue;
static UINT16 csd_status;
static INT32 csd_in_reset;
static INT32 csd_is_intialized = 0;
static void csd_porta_w(UINT16, UINT8 data)
{
dacvalue = (data << 2) | (dacvalue & 3);
// if (dacvalue !=0) bprintf(0, _T("%X,"), dacvalue);
if (dacvalue == 0x02 || dacvalue == 0x03) dacvalue = 0xFE; // silly hack gets rid of pops in spyhunter when the music starts/stops
DACWrite16Signed(0, dacvalue << 6);
}
static void csd_portb_w(UINT16, UINT8 data)
{
dacvalue = (dacvalue & ~0x3) | (data >> 6);
// if (dacvalue !=0) bprintf(0, _T("%X,"), dacvalue);
if (dacvalue == 0x02 || dacvalue == 0x03) dacvalue = 0xFE; // see "silly hack", above
DACWrite16Signed(0, dacvalue << 6);
//if (~pia_get_ddr_b(0) & 0x30) csd_status = (data >> 4) & 3;
UINT8 z_mask = pia_get_ddr_b(0);
if (~z_mask & 0x10) csd_status = (csd_status & ~1) | ((data >> 4) & 1);
if (~z_mask & 0x20) csd_status = (csd_status & ~2) | ((data >> 4) & 2);
}
static void csd_irq(int state)
{
SekSetIRQLine(4, state ? CPU_IRQSTATUS_ACK : CPU_IRQSTATUS_NONE);
}
void csd_reset_write(int state)
{
if (csd_is_intialized == 0) return;
csd_in_reset = state;
if (state) {
INT32 cpu_active = SekGetActive();
if (cpu_active == -1) SekOpen(0);
SekReset();
if (cpu_active == -1) SekClose();
}
}
static void __fastcall csd_write_word(UINT32 address, UINT16 data)
{
if ((address & 0x1fff8) == 0x18000) {
pia_write(0, (address / 2) & 3, data & 0xff);
return;
}
}
static void __fastcall csd_write_byte(UINT32 address, UINT8 data)
{
if ((address & 0x1fff8) == 0x18000) {
pia_write(0, (address / 2) & 3, data);
return;
}
}
static UINT16 __fastcall csd_read_word(UINT32 address)
{
if ((address & 0x1fff8) == 0x18000) {
UINT8 ret = pia_read(0, (address / 2) & 3);
return ret | (ret << 8);
}
return 0;
}
static UINT8 __fastcall csd_read_byte(UINT32 address)
{
if ((address & 0x1fff8) == 0x18000) {
return pia_read(0, (address / 2) & 3);
}
return 0;
}
void csd_data_write(UINT16 data)
{
if (csd_is_intialized == 0) return;
pia_set_input_b(0, data & 0x0f);
pia_set_input_ca1(0, ~data & 0x10);
}
UINT8 csd_status_read()
{
if (csd_is_intialized == 0) return 0;
return csd_status;
}
INT32 csd_reset_status()
{
if (csd_is_intialized == 0) return 1;
return csd_in_reset;
}
INT32 csd_initialized()
{
return csd_is_intialized;
}
void csd_reset()
{
if (csd_is_intialized == 0) return;
SekOpen(0);
SekReset();
DACReset();
SekClose();
pia_reset();
csd_status = 0;
csd_in_reset = 0;
dacvalue = 0;
}
static const pia6821_interface pia_intf = {
0, 0, 0, 0, 0, 0,
csd_porta_w, csd_portb_w, 0, 0,
csd_irq, csd_irq
};
void csd_init(UINT8 *rom, UINT8 *ram)
{
SekInit(0, 0x68000);
SekOpen(0);
SekMapMemory(rom, 0x000000, 0x007fff, MAP_ROM);
SekMapMemory(ram, 0x01c000, 0x01cfff, MAP_RAM);
SekSetWriteWordHandler(0, csd_write_word);
SekSetWriteByteHandler(0, csd_write_byte);
SekSetReadWordHandler(0, csd_read_word);
SekSetReadByteHandler(0, csd_read_byte);
SekClose();
pia_init();
pia_config(0, PIA_ALTERNATE_ORDERING, &pia_intf);
DACInit(0, 0, 1, SekTotalCycles, 8000000);
DACSetRoute(0, 1.00, BURN_SND_ROUTE_BOTH);
DACDCBlock(1);
csd_is_intialized = 1;
}
void csd_exit()
{
if (csd_is_intialized == 0) return;
SekExit();
pia_init();
DACExit();
csd_is_intialized = 0;
}
void csd_scan(INT32 nAction, INT32 *pnMin)
{
if (csd_is_intialized == 0) return;
if (nAction & ACB_VOLATILE)
{
SekScan(nAction);
DACScan(nAction, pnMin);
pia_scan(nAction, pnMin);
SCAN_VAR(csd_status);
SCAN_VAR(csd_in_reset);
SCAN_VAR(dacvalue);
}
}