1
/* Mednafen - Multi-system Emulator
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
MCGenjin_CS_Device::MCGenjin_CS_Device()
26
MCGenjin_CS_Device::~MCGenjin_CS_Device()
31
void MCGenjin_CS_Device::Power(void)
36
void MCGenjin_CS_Device::EndFrame(int32 timestamp)
41
int MCGenjin_CS_Device::StateAction(StateMem *sm, int load, int data_only, const char *sname)
47
uint8 MCGenjin_CS_Device::Read(int32 timestamp, uint32 A)
52
void MCGenjin_CS_Device::Write(int32 timestamp, uint32 A, uint8 V)
57
uint32 MCGenjin_CS_Device::GetNVSize(void)
62
void MCGenjin_CS_Device::ReadNV(uint8 *buffer, uint32 offset, uint32 count)
64
memset(buffer, 0, count);
67
void MCGenjin_CS_Device::WriteNV(const uint8 *buffer, uint32 offset, uint32 count)
72
class MCGenjin_CS_Device_RAM : public MCGenjin_CS_Device
76
MCGenjin_CS_Device_RAM(uint32 size, bool nv)
78
assert(round_up_pow2(size) == size);
84
virtual ~MCGenjin_CS_Device_RAM()
89
virtual void Power(void)
92
ram.assign(ram.size(), 0xFF);
97
virtual int StateAction(StateMem *sm, int load, int data_only, const char *sname)
101
SFARRAY(&ram[0], ram.size()),
107
ret &= MDFNSS_StateAction(sm, load, data_only, StateRegs, sname);
113
virtual uint8 Read(int32 timestamp, uint32 A)
115
return ram[(A | (bank_select << 18)) & (ram.size() - 1)];
118
virtual void Write(int32 timestamp, uint32 A, uint8 V)
123
ram[(A | (bank_select << 18)) & (ram.size() - 1)] = V;
126
virtual uint32 GetNVSize(void)
128
return nonvolatile ? ram.size() : 0;
131
virtual void ReadNV(uint8 *buffer, uint32 offset, uint32 count)
135
*buffer = ram[offset % ram.size()];
142
virtual void WriteNV(const uint8 *buffer, uint32 offset, uint32 count)
146
ram[offset % ram.size()] = *buffer;
154
std::vector<uint8> ram;
159
#include "mcgenjin_ym2413.inc"
161
void MCGenjin::Power(void)
166
for(unsigned i = 0; i < 2; i++)
170
void MCGenjin::EndFrame(int32 timestamp)
172
for(unsigned i = 0; i < 2; i++)
173
cs[i]->EndFrame(timestamp);
176
uint32 MCGenjin::GetNVSize(const unsigned di)
178
return cs[di]->GetNVSize();
182
void MCGenjin::ReadNV(const unsigned di, uint8 *buffer, uint32 offset, uint32 count)
184
cs[di]->ReadNV(buffer, offset, count);
187
void MCGenjin::WriteNV(const unsigned di, const uint8 *buffer, uint32 offset, uint32 count)
189
cs[di]->WriteNV(buffer, offset, count);
192
MCGenjin::MCGenjin(Blip_Buffer *bb, const uint8 *rr, uint32 rr_size)
194
uint8 revision, num256_pages, region, cs_di[2];
197
throw MDFN_Error(0, _("MCGenjin ROM size is too small!"));
199
if(memcmp(rr + 0x1FD0, "MCGENJIN", 8))
200
throw MDFN_Error(0, _("MC Genjin header magic missing!"));
202
rom.resize(round_up_pow2(rr_size));
204
memcpy(&rom[0], rr, rr_size);
206
revision = rom[0x1FD8];
207
num256_pages = rom[0x1FD9];
208
region = rom[0x1FDA];
209
cs_di[0] = rom[0x1FDB];
210
cs_di[1] = rom[0x1FDC];
212
for(unsigned i = 0; i < 2; i++)
217
for(unsigned si = 0; si < i; si++) // FIXME: auto ptr to make this not necessary
220
throw MDFN_Error(0, _("Unsupported MCGENJIN device on CS%d: 0x%02x"), i, cs_di[i]);
224
MDFN_printf(_("CS%d: Unused\n"), i);
225
cs[i] = new MCGenjin_CS_Device();
230
MDFN_printf(_("CS%d: %uKiB %sRAM\n"), i, 8 << (cs_di[i] & 0xF), (cs_di[i] & 0x20) ? "Nonvolatile " : "");
231
cs[i] = new MCGenjin_CS_Device_RAM(8192 << (cs_di[i] & 0xF), (bool)(cs_di[i] & 0x20));
237
MCGenjin::~MCGenjin()
239
for(unsigned i = 0; i < 2; i++)
243
int MCGenjin::StateAction(StateMem *sm, int load, int data_only)
245
SFORMAT StateRegs[] =
253
ret &= MDFNSS_StateAction(sm, load, data_only, StateRegs, "MCGENJIN");
255
for(unsigned i = 0; i < 2; i++)
256
ret &= MDFNSS_StateAction(sm, load, data_only, StateRegs, i ? "MCGENJIN_CS1" : "MCGENJIN_CS0");