(MESS) consolidation + cleanup, part2. nw.

This commit is contained in:
Fabio Priuli 2014-09-29 18:01:24 +00:00
parent 116cfaedb3
commit c3e67737f8
10 changed files with 106 additions and 91 deletions

View File

@ -759,7 +759,7 @@ WRITE8_MEMBER(nes_asn_device::write_h)
READ8_MEMBER(nes_asn_device::read_m)
{
LOG_MMC(("Ai Senshi Nicol read_m, offset: %04x\n", offset));
return m_prg[((m_latch * 0x2000) + (offset & 0x1fff)) & (m_prg.count() - 1)];
return m_prg[((m_latch * 0x2000) + (offset & 0x1fff)) & (m_prg_size - 1)];
}
@ -923,7 +923,7 @@ WRITE8_MEMBER(nes_whirl2706_device::write_h)
READ8_MEMBER(nes_whirl2706_device::read_m)
{
LOG_MMC(("whirl2706 read_m, offset: %04x\n", offset));
return m_prg[(m_latch * 0x2000 + (offset & 0x1fff)) & (m_prg.count() - 1)];
return m_prg[(m_latch * 0x2000 + (offset & 0x1fff)) & (m_prg_size - 1)];
}
/*-------------------------------------------------
@ -1060,7 +1060,7 @@ WRITE8_MEMBER(nes_smb2ja_device::write_h)
READ8_MEMBER(nes_smb2ja_device::read_m)
{
LOG_MMC(("smb2ja read_m, offset: %04x\n", offset));
return m_prg[(0xfe * 0x2000 + (offset & 0x1fff)) & (m_prg.count() - 1)];
return m_prg[(0xfe * 0x2000 + (offset & 0x1fff)) & (m_prg_size - 1)];
}
/*-------------------------------------------------
@ -1118,7 +1118,7 @@ WRITE8_MEMBER(nes_smb2jb_device::write_l)
READ8_MEMBER(nes_smb2jb_device::read_m)
{
LOG_MMC(("smb2jb read_m, offset: %04x\n", offset));
return m_prg[((0x0f * 0x2000) + (offset & 0x1fff)) & (m_prg.count() - 1)];
return m_prg[((0x0f * 0x2000) + (offset & 0x1fff)) & (m_prg_size - 1)];
}
/* This goes to 0x4020-0x403f & 0x40a0-0x40bf */

View File

@ -378,7 +378,7 @@ WRITE8_MEMBER(nes_ks7032_device::ks7032_write)
READ8_MEMBER(nes_ks7032_device::read_m)
{
LOG_MMC(("ks7032 read_m, offset: %04x\n", offset));
return m_prg[((m_reg[4] * 0x2000) + (offset & 0x1fff)) & (m_prg.count() - 1)];
return m_prg[((m_reg[4] * 0x2000) + (offset & 0x1fff)) & (m_prg_size - 1)];
}
/*-------------------------------------------------

View File

@ -380,19 +380,19 @@ inline UINT8 nes_exrom_device::base_chr_r(int bank, UINT32 offset)
break;
}
return m_vrom[helper & (m_vrom.bytes() - 1)];
return m_vrom[helper & (m_vrom_size - 1)];
}
inline UINT8 nes_exrom_device::split_chr_r(UINT32 offset)
{
UINT32 helper = (m_split_bank * 0x1000) + (offset & 0x3f8) + (m_split_yst & 7);
return m_vrom[helper & (m_vrom.bytes() - 1)];
return m_vrom[helper & (m_vrom_size - 1)];
}
inline UINT8 nes_exrom_device::bg_ex1_chr_r(UINT32 offset)
{
UINT32 helper = (m_ex1_bank * 0x1000) + (offset & 0xfff);
return m_vrom[helper & (m_vrom.bytes() - 1)];
return m_vrom[helper & (m_vrom_size - 1)];
}
READ8_MEMBER(nes_exrom_device::chr_r)

View File

@ -718,9 +718,9 @@ void nes_cart_slot_device::call_load_ines()
// SETUP step 5: allocate pointers for PRG/VROM
if (prg_size)
m_cart->prg_alloc(prg_size);
m_cart->prg_alloc(prg_size, tag());
if (vrom_size)
m_cart->vrom_alloc(vrom_size);
m_cart->vrom_alloc(vrom_size, tag());
// if there is a trainer, skip it for the moment
if (m_cart->get_trainer())

View File

@ -556,11 +556,11 @@ void nes_cart_slot_device::call_load_pcb()
logerror("-- PRG WRAM: %d\n", prgram_size);
// SETUP steps 5/6: allocate pointers for PRG/VROM and load the data!
m_cart->prg_alloc(prg_size);
m_cart->prg_alloc(prg_size, tag());
memcpy(m_cart->get_prg_base(), get_software_region("prg"), prg_size);
if (vrom_size)
{
m_cart->vrom_alloc(vrom_size);
m_cart->vrom_alloc(vrom_size, tag());
memcpy(m_cart->get_vrom_base(), get_software_region("chr"), vrom_size);
}

View File

@ -104,7 +104,11 @@ const device_type NES_CART_SLOT = &device_creator<nes_cart_slot_device>;
device_nes_cart_interface::device_nes_cart_interface(const machine_config &mconfig, device_t &device)
: device_slot_card_interface(mconfig, device),
m_prg(NULL),
m_vrom(NULL),
m_ciram(NULL),
m_prg_size(0),
m_vrom_size(0),
m_mapper_sram(NULL),
m_mapper_sram_size(0),
m_ce_mask(0),
@ -140,66 +144,84 @@ device_nes_cart_interface::~device_nes_cart_interface()
// pointer allocators
//-------------------------------------------------
void device_nes_cart_interface::prg_alloc(size_t size)
void device_nes_cart_interface::prg_alloc(size_t size, const char *tag)
{
m_prg.resize(size);
m_prg_chunks = size / 0x4000;
if (size % 0x2000)
if (m_prg == NULL)
{
// A few pirate carts have PRG made of 32K + 2K or some weird similar config
// in this case we treat the banking as if this 'extra' PRG is not present and
// the pcb code has to handle it by accessing directly m_prg!
printf("Warning! The loaded PRG has size not a multiple of 8KB (0x%X)\n", (UINT32)size);
m_prg_chunks--;
}
m_prg_mask = ((m_prg_chunks << 1) - 1);
astring tempstring(tag);
tempstring.cat(NESSLOT_PRGROM_REGION_TAG);
m_prg = device().machine().memory().region_alloc(tempstring, size, 1, ENDIANNESS_LITTLE)->base();
m_prg_size = size;
m_prg_chunks = size / 0x4000;
if (size % 0x2000)
{
// A few pirate carts have PRG made of 32K + 2K or some weird similar config
// in this case we treat the banking as if this 'extra' PRG is not present and
// the pcb code has to handle it by accessing directly m_prg!
printf("Warning! The loaded PRG has size not a multiple of 8KB (0x%X)\n", (UINT32)size);
m_prg_chunks--;
}
m_prg_mask = ((m_prg_chunks << 1) - 1);
// printf("first mask %x!\n", m_prg_mask);
if ((m_prg_chunks << 1) & m_prg_mask)
{
int mask_bits = 0, temp = (m_prg_chunks << 1), mapsize;
// contrary to what happens with later systems, like e.g. SNES or MD,
// only half a dozen of NES carts have PRG which is not a power of 2
// so we use this bank_map only as an exception
if ((m_prg_chunks << 1) & m_prg_mask)
{
int mask_bits = 0, temp = (m_prg_chunks << 1), mapsize;
// contrary to what happens with later systems, like e.g. SNES or MD,
// only half a dozen of NES carts have PRG which is not a power of 2
// so we use this bank_map only as an exception
// printf("uneven rom!\n");
// 1. redefine mask as (next power of 2)-1
for (; temp; )
{
mask_bits++;
temp >>= 1;
}
m_prg_mask = (1 << mask_bits) - 1;
// 1. redefine mask as (next power of 2)-1
for (; temp; )
{
mask_bits++;
temp >>= 1;
}
m_prg_mask = (1 << mask_bits) - 1;
// printf("new mask %x!\n", m_prg_mask);
mapsize = (1 << mask_bits)/2;
// 2. create a bank_map for banks in the range mask/2 -> mask
m_prg_bank_map.resize(mapsize);
// 3. fill the bank_map accounting for mirrors
int j;
for (j = mapsize; j < (m_prg_chunks << 1); j++)
m_prg_bank_map[j - mapsize] = j;
while (j % mapsize)
{
int k = 0, repeat_banks;
while ((j % (mapsize >> k)) && k < mask_bits)
k++;
repeat_banks = j % (mapsize >> (k - 1));
for (int l = 0; l < repeat_banks; l++)
m_prg_bank_map[(j - mapsize) + l] = m_prg_bank_map[(j - mapsize) + l - repeat_banks];
j += repeat_banks;
}
// check bank map!
mapsize = (1 << mask_bits)/2;
// 2. create a bank_map for banks in the range mask/2 -> mask
m_prg_bank_map.resize(mapsize);
// 3. fill the bank_map accounting for mirrors
int j;
for (j = mapsize; j < (m_prg_chunks << 1); j++)
m_prg_bank_map[j - mapsize] = j;
while (j % mapsize)
{
int k = 0, repeat_banks;
while ((j % (mapsize >> k)) && k < mask_bits)
k++;
repeat_banks = j % (mapsize >> (k - 1));
for (int l = 0; l < repeat_banks; l++)
m_prg_bank_map[(j - mapsize) + l] = m_prg_bank_map[(j - mapsize) + l - repeat_banks];
j += repeat_banks;
}
// check bank map!
// for (int i = 0; i < mapsize; i++)
// {
// printf("bank %3d = %3d\t", i, m_prg_bank_map[i]);
// if ((i%8) == 7)
// printf("\n");
// }
}
}
}
void device_nes_cart_interface::vrom_alloc(size_t size, const char *tag)
{
if (m_vrom == NULL)
{
astring tempstring(tag);
tempstring.cat(NESSLOT_CHRROM_REGION_TAG);
m_vrom = device().machine().memory().region_alloc(tempstring, size, 1, ENDIANNESS_LITTLE)->base();
m_vrom_size = size;
m_vrom_chunks = size / 0x2000;
}
}
@ -208,12 +230,6 @@ void device_nes_cart_interface::prgram_alloc(size_t size)
m_prgram.resize(size);
}
void device_nes_cart_interface::vrom_alloc(size_t size)
{
m_vrom.resize(size);
m_vrom_chunks = size / 0x2000;
}
void device_nes_cart_interface::vram_alloc(size_t size)
{
m_vram.resize(size);
@ -669,7 +685,7 @@ void device_nes_cart_interface::pcb_start(running_machine &machine, UINT8 *ciram
{
if (m_prg_bank_mem[i])
{
m_prg_bank_mem[i]->configure_entries(0, m_prg.count() / 0x2000, m_prg, 0x2000);
m_prg_bank_mem[i]->configure_entries(0, m_prg_size / 0x2000, m_prg, 0x2000);
m_prg_bank_mem[i]->set_entry(i);
m_prg_bank[i] = i;
}
@ -732,8 +748,7 @@ nes_cart_slot_device::nes_cart_slot_device(const machine_config &mconfig, const
device_slot_interface(mconfig, *this),
m_crc_hack(0),
m_pcb_id(NO_BOARD),
m_must_be_loaded(1),
m_empty(TRUE)
m_must_be_loaded(1)
{
}
@ -770,7 +785,7 @@ void nes_cart_slot_device::device_config_complete()
void nes_cart_slot_device::pcb_start(UINT8 *ciram_ptr)
{
if (m_cart)
m_cart->pcb_start(machine(), ciram_ptr, cart_mounted());
m_cart->pcb_start(machine(), ciram_ptr, exists());
}
void nes_cart_slot_device::pcb_reset()
@ -835,7 +850,6 @@ bool nes_cart_slot_device::call_load()
}
call_load_ines();
m_empty = FALSE;
}
else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */
{
@ -846,7 +860,6 @@ bool nes_cart_slot_device::call_load()
}
call_load_unif();
m_empty = FALSE;
}
else
{
@ -855,10 +868,7 @@ bool nes_cart_slot_device::call_load()
}
}
else
{
call_load_pcb();
m_empty = FALSE;
}
}
return IMAGE_INIT_PASS;

View File

@ -176,9 +176,9 @@ public:
// hack until disk system is made modern!
virtual void disk_flip_side() { }
void prg_alloc(size_t size);
void prg_alloc(size_t size, const char *tag);
void vrom_alloc(size_t size, const char *tag);
void prgram_alloc(size_t size);
void vrom_alloc(size_t size);
void vram_alloc(size_t size);
void battery_alloc(size_t size);
@ -204,9 +204,9 @@ public:
UINT8* get_battery_base() { return m_battery; }
UINT8* get_mapper_sram_base() { return m_mapper_sram; }
UINT32 get_prg_size() { return m_prg.bytes(); }
UINT32 get_prg_size() { return m_prg_size; }
UINT32 get_prgram_size() { return m_prgram.bytes(); }
UINT32 get_vrom_size() { return m_vrom.bytes(); }
UINT32 get_vrom_size() { return m_vrom_size; }
UINT32 get_vram_size() { return m_vram.bytes(); }
UINT32 get_battery_size() { return m_battery.bytes(); }
UINT32 get_mapper_sram_size() { return m_mapper_sram_size; }
@ -226,12 +226,14 @@ public:
protected:
// internal state
dynamic_buffer m_prg;
UINT8 *m_prg;
UINT8 *m_vrom;
UINT8 *m_ciram;
dynamic_buffer m_prgram;
dynamic_buffer m_vrom;
dynamic_buffer m_vram;
dynamic_buffer m_battery;
UINT8 *m_ciram;
UINT32 m_prg_size;
UINT32 m_vrom_size;
// HACK: to reduce tagmap lookups for PPU-related IRQs, we add a hook to the
// main NES CPU here, even if it does not belong to this device.
@ -364,7 +366,6 @@ public:
const char * get_default_card_unif(UINT8 *ROM, UINT32 len);
const char * nes_get_slot(int pcb_id);
int nes_get_pcb_id(const char *slot);
bool cart_mounted() { return !m_empty; }
// reading and writing
virtual DECLARE_READ8_MEMBER(read_l);
@ -396,7 +397,6 @@ public:
device_nes_cart_interface* m_cart;
int m_pcb_id;
bool m_must_be_loaded;
bool m_empty;
};
// device type definition
@ -407,6 +407,10 @@ extern const device_type NES_CART_SLOT;
DEVICE CONFIGURATION MACROS
***************************************************************************/
#define NESSLOT_PRGROM_REGION_TAG ":cart:prg_rom"
#define NESSLOT_CHRROM_REGION_TAG ":cart:chr_rom"
#define MCFG_NES_CARTRIDGE_ADD(_tag, _slot_intf, _def_slot) \
MCFG_DEVICE_ADD(_tag, NES_CART_SLOT, 0) \
MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
@ -414,6 +418,7 @@ extern const device_type NES_CART_SLOT;
#define MCFG_NES_CARTRIDGE_NOT_MANDATORY \
static_cast<nes_cart_slot_device *>(device)->set_must_be_loaded(FALSE);
// Hacky configuration to add a slot with fixed disksys interface
#define MCFG_DISKSYS_ADD(_tag, _slot_intf, _def_slot) \
MCFG_DEVICE_ADD(_tag, NES_CART_SLOT, 0) \

View File

@ -466,13 +466,13 @@ void nes_cart_slot_device::call_load_unif()
// SETUP steps 5/6: allocate pointers for PRG/VROM and load the data!
if (prg_size == 0x4000)
{
m_cart->prg_alloc(0x8000);
m_cart->prg_alloc(0x8000, tag());
memcpy(m_cart->get_prg_base(), temp_prg, 0x4000);
memcpy(m_cart->get_prg_base() + 0x4000, m_cart->get_prg_base(), 0x4000);
}
else
{
m_cart->prg_alloc(prg_size);
m_cart->prg_alloc(prg_size, tag());
memcpy(m_cart->get_prg_base(), temp_prg, prg_size);
}
@ -481,7 +481,7 @@ void nes_cart_slot_device::call_load_unif()
if (vrom_size)
{
m_cart->vrom_alloc(vrom_size);
m_cart->vrom_alloc(vrom_size, tag());
memcpy(m_cart->get_vrom_base(), temp_chr, vrom_size);
}

View File

@ -555,7 +555,7 @@ READ8_MEMBER(nes_sunsoft_fme7_device::read_m)
LOG_MMC(("Sunsoft FME7 read_m, offset: %04x\n", offset));
if (!(m_wram_bank & 0x40)) // is PRG ROM
return m_prg[((bank * 0x2000) + offset) & (m_prg.count() - 1)];
return m_prg[((bank * 0x2000) + offset) & (m_prg_size - 1)];
else if (m_wram_bank & 0x80) // is PRG RAM
{
if (m_battery)

View File

@ -39,7 +39,7 @@ UINT32 nes_state::screen_update_nes(screen_device &screen, bitmap_ind16 &bitmap,
// if this is a disk system game, check for the flip-disk key
if (m_cartslot &&
(m_cartslot->get_pcb_id() == STD_DISKSYS // first scenario = disksys in m_cartslot (= famicom)
|| !m_cartslot->cart_mounted())) // second scenario = disk via fixed internal option (= fds)
|| !m_cartslot->exists())) // second scenario = disk via fixed internal option (= fds)
{
// latch this input so it doesn't go at warp speed
if ((m_io_disksel->read_safe(0) & 0x01) && (!m_last_frame_flip))
@ -60,7 +60,7 @@ UINT32 nes_state::screen_update_famitwin(screen_device &screen, bitmap_ind16 &bi
// render the ppu
m_ppu->render(bitmap, 0, 0, 0, 0);
if (m_cartslot2 && !m_cartslot2->cart_mounted())
if (m_cartslot2 && !m_cartslot2->exists())
{
// latch this input so it doesn't go at warp speed
if ((m_io_disksel->read_safe(0) & 0x01) && (!m_last_frame_flip))