(MESS) nes.c: shuffled around the loading code (very preliminary step towards slotification).

also, temporarily made famicom driver to only support disks.
This commit is contained in:
Fabio Priuli 2013-02-11 10:13:14 +00:00
parent e4f37ea7ba
commit 0e937ed6b4
10 changed files with 1628 additions and 1055 deletions

2
.gitattributes vendored
View File

@ -7332,6 +7332,8 @@ src/mess/machine/nes.c svneol=native#text/plain
src/mess/machine/nes_ines.c svneol=native#text/plain
src/mess/machine/nes_mmc.c svneol=native#text/plain
src/mess/machine/nes_pcb.c svneol=native#text/plain
src/mess/machine/nes_slot.c svneol=native#text/plain
src/mess/machine/nes_slot.h svneol=native#text/plain
src/mess/machine/nes_unif.c svneol=native#text/plain
src/mess/machine/nextkbd.c svneol=native#text/plain
src/mess/machine/nextkbd.h svneol=native#text/plain

View File

@ -15,7 +15,6 @@
#include "includes/nes.h"
//#include "includes/nes_mmc.h"
#include "cpu/m6502/n2a03.h"
#include "imagedev/cartslot.h"
#include "sound/nes_apu.h"
#include "imagedev/flopdrv.h"
#include "formats/nes_dsk.h"
@ -53,7 +52,9 @@ static ADDRESS_MAP_START( nes_map, AS_PROGRAM, 8, nes_state )
AM_RANGE(0x4016, 0x4016) AM_READWRITE(nes_IN0_r, nes_IN0_w) /* IN0 - input port 1 */
AM_RANGE(0x4017, 0x4017) AM_READ(nes_IN1_r) /* IN1 - input port 2 */
AM_RANGE(0x4017, 0x4017) AM_WRITE(psg_4017_w) /* PSG second control register */
AM_RANGE(0x4100, 0x5fff) AM_READWRITE(nes_low_mapper_r, nes_low_mapper_w) /* Perform unholy acts on the machine */
// 0x4100-0x5fff -> LOW HANDLER defined on a pcb base
// 0x6000-0x7fff -> MID HANDLER defined on a pcb base
// 0x8000-0xffff -> HIGH HANDLER defined on a pcb base
ADDRESS_MAP_END
@ -442,6 +443,14 @@ static const floppy_interface nes_floppy_interface =
};
static const nes_cart_interface nes_crt_interface =
{
};
static SLOT_INTERFACE_START(nes_cart)
SLOT_INTERFACE("rom", NES_ROM)
SLOT_INTERFACE_END
static MACHINE_CONFIG_START( nes, nes_state )
/* basic machine hardware */
MCFG_CPU_ADD("maincpu", N2A03, NTSC_CLOCK)
@ -470,12 +479,7 @@ static MACHINE_CONFIG_START( nes, nes_state )
MCFG_SOUND_CONFIG(nes_apu_interface)
MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
MCFG_CARTSLOT_ADD("cart")
MCFG_CARTSLOT_EXTENSION_LIST("nes,unf")
MCFG_CARTSLOT_MANDATORY
MCFG_CARTSLOT_INTERFACE("nes_cart")
MCFG_CARTSLOT_LOAD(nes_state,nes_cart)
MCFG_CARTSLOT_PARTIALHASH(nes_partialhash)
MCFG_NES_CARTRIDGE_ADD("nes_slot", nes_crt_interface, nes_cart, NULL, NULL)
MCFG_SOFTWARE_LIST_ADD("cart_list","nes")
MACHINE_CONFIG_END
@ -522,20 +526,13 @@ static MACHINE_CONFIG_DERIVED( dendy, nes )
MACHINE_CONFIG_END
static MACHINE_CONFIG_DERIVED( famicom, nes )
MCFG_CARTSLOT_MODIFY("cart")
MCFG_CARTSLOT_EXTENSION_LIST("nes,unf")
MCFG_CARTSLOT_NOT_MANDATORY
MCFG_CARTSLOT_LOAD(nes_state,nes_cart)
MCFG_CARTSLOT_PARTIALHASH(nes_partialhash)
MCFG_DEVICE_REMOVE( "nes_slot" )
// MCFG_FC_CARTRIDGE_ADD("nes_slot", nes_crt_interface, nes_cart, NULL, NULL) // here we need a non-mandatory cart...
MCFG_LEGACY_FLOPPY_DRIVE_ADD(FLOPPY_0, nes_floppy_interface)
MCFG_SOFTWARE_LIST_ADD("flop_list","famicom_flop")
MACHINE_CONFIG_END
//static MACHINE_CONFIG_DERIVED( nes_test, nes )
//MACHINE_CONFIG_END
/* rom regions are just place-holders: they get removed and re-allocated when a cart is loaded */
ROM_START( nes )
@ -588,7 +585,6 @@ ROM_START( dendy )
ROM_REGION( 0x800, "ciram", ROMREGION_ERASE00 ) /* CI RAM */
ROM_END
//#define rom_nes_test rom_nes
/***************************************************************************
@ -604,5 +600,3 @@ CONS( 1986, famitwin, nes, 0, famicom, famicom, nes_state, famicom, "Sh
CONS( 198?, m82, nes, 0, nes, nes, driver_device, 0, "Nintendo", "M82 Display Unit", GAME_IMPERFECT_GRAPHICS | GAME_NOT_WORKING )
CONS( 1996, drpcjr, nes, 0, famicom, famicom, nes_state, famicom, "Bung", "Doctor PC Jr", GAME_IMPERFECT_GRAPHICS )
CONS( 1992, dendy, nes, 0, dendy, nes, driver_device, 0, "Steepler", "Dendy Classic", GAME_IMPERFECT_GRAPHICS )
//CONS( 1985, nes_test, 0, 0, nes_test, nes, driver_device, 0, "Nintendo", "Nintendo Entertainment System (Testdriver)", GAME_IMPERFECT_GRAPHICS )

View File

@ -10,6 +10,7 @@
#define NES_H_
#include "includes/nes_mmc.h"
#include "machine/nes_slot.h"
/***************************************************************************
@ -54,7 +55,9 @@ class nes_state : public nes_carts_state
{
public:
nes_state(const machine_config &mconfig, device_type type, const char *tag)
: nes_carts_state(mconfig, type, tag) { }
: nes_carts_state(mconfig, type, tag),
m_cartslot(*this, "nes_slot")
{ }
/* input_related - this part has to be cleaned up (e.g. in_2 and in_3 are not really necessary here...) */
nes_input m_in_0, m_in_1, m_in_2, m_in_3;
@ -74,8 +77,6 @@ public:
DECLARE_READ8_MEMBER(nes_chr_r);
DECLARE_WRITE8_MEMBER(nes_nt_w);
DECLARE_READ8_MEMBER(nes_nt_r);
DECLARE_WRITE8_MEMBER(nes_low_mapper_w);
DECLARE_READ8_MEMBER(nes_low_mapper_r);
/* misc */
write8_delegate m_mmc_write_low;
@ -114,7 +115,6 @@ public:
DECLARE_WRITE8_MEMBER(nes_vh_sprite_dma_w);
DECLARE_DRIVER_INIT(famicom);
virtual void machine_start();
virtual void machine_stop();
virtual void machine_reset();
virtual void video_start();
virtual void video_reset();
@ -126,7 +126,6 @@ public:
DECLARE_WRITE8_MEMBER(psg_4015_w);
DECLARE_WRITE8_MEMBER(psg_4017_w);
void nes_banks_restore();
DECLARE_DEVICE_IMAGE_LOAD_MEMBER(nes_cart);
DECLARE_DEVICE_IMAGE_LOAD_MEMBER(nes_disk);
DECLARE_DEVICE_IMAGE_UNLOAD_MEMBER(nes_disk);
@ -144,16 +143,18 @@ public:
ioport_port *m_io_zapper2_y;
ioport_port *m_io_paddle;
optional_device<nes_cart_slot_device> m_cartslot; //mandatory
private:
/* devices */
// cpu_device *m_maincpu;
// ppu2c0x_device *m_ppu;
// device_t *m_sound;
device_t *m_cart;
// emu_timer *m_irq_timer;
memory_bank *m_prg_bank_mem[5];
};
/*----------- defined in machine/nes.c -----------*/

View File

@ -1,6 +1,8 @@
#ifndef __MMC_H
#define __MMC_H
#include "video/ppu2c0x.h"
/* Boards */
enum
{
@ -109,7 +111,7 @@ enum
// these are used to setup the proper PCB ID, for each supported type of files
int nes_get_pcb_id(running_machine &machine, const char *feature); // for softlist
void unif_mapr_setup(running_machine &machine, const char *board); // for UNIF files
void unif_mapr_setup(const char *board, int *pcb_id, int *battery, int *prgram, int *vram_chunks); // for UNIF files
int nes_get_mmc_id(running_machine &machine, int mapper); // for iNES files
// these are used to setup handlers and callbacks necessary to the emulation (resp. at start and reset)
@ -610,6 +612,4 @@ public:
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -209,24 +209,6 @@ READ8_MEMBER(nes_state::nes_nt_r)
return m_nt_page[page].access[offset & 0x3ff];
}
WRITE8_MEMBER(nes_state::nes_low_mapper_w)
{
if (!m_mmc_write_low.isnull())
(m_mmc_write_low)(space, offset, data, mem_mask);
else
logerror("Unimplemented LOW mapper write, offset: %04x, data: %02x\n", offset + 0x4100, data);
}
READ8_MEMBER(nes_state::nes_low_mapper_r)
{
if (!m_mmc_read_low.isnull())
return (m_mmc_read_low)(space, offset, mem_mask);
else
logerror("Unimplemented LOW mapper read, offset: %04x\n", offset + 0x4100);
return 0;
}
/*************************************************************
Helpers to handle MMC

1231
src/mess/machine/nes_slot.c Normal file

File diff suppressed because it is too large Load Diff

230
src/mess/machine/nes_slot.h Normal file
View File

@ -0,0 +1,230 @@
#ifndef __NES_SLOT_H__
#define __NES_SLOT_H__
#include "includes/nes_mmc.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
// ======================> nes_cart_interface
struct nes_cart_interface
{
};
// ======================> device_nes_cart_interface
class device_nes_cart_interface : public device_slot_card_interface
{
public:
// construction/destruction
device_nes_cart_interface(const machine_config &mconfig, device_t &device);
virtual ~device_nes_cart_interface();
// reading and writing
virtual DECLARE_READ8_MEMBER(read_l) { return 0xff; }
virtual DECLARE_READ8_MEMBER(read_m) { return 0xff; }
virtual DECLARE_READ8_MEMBER(read_h) { return 0xff; }
virtual DECLARE_WRITE8_MEMBER(write_l) { }
virtual DECLARE_WRITE8_MEMBER(write_m) { }
virtual DECLARE_WRITE8_MEMBER(write_h) { }
virtual void prg_alloc(running_machine &machine, size_t size);
virtual void prgram_alloc(running_machine &machine, size_t size);
virtual void vrom_alloc(running_machine &machine, size_t size);
virtual void vram_alloc(running_machine &machine, size_t size);
virtual void battery_alloc(running_machine &machine, size_t size);
virtual void mapper_ram_alloc(running_machine &machine, size_t size);
virtual void mapper_bram_alloc(running_machine &machine, size_t size);
virtual int get_mirroring() { return m_mirroring; }
virtual void set_mirroring(int val) { m_mirroring = val; }
virtual int get_four_screen_vram() { return m_four_screen_vram; }
virtual void set_four_screen_vram(int val) { m_four_screen_vram = val; }
virtual UINT8* get_prg_base() { return m_prg; }
virtual UINT8* get_prgram_base() { return m_prgram; }
virtual UINT8* get_vrom_base() { return m_vrom; }
virtual UINT8* get_vram_base() { return m_vram; }
virtual UINT8* get_battery_base() { return m_battery; }
virtual UINT8* get_mapper_ram_base() { return m_mapper_ram; }
virtual UINT8* get_mapper_bram_base() { return m_mapper_bram; }
virtual UINT32 get_prg_size() { return m_prg_size; }
virtual UINT32 get_prgram_size() { return m_prgram_size; }
virtual UINT32 get_vrom_size() { return m_vrom_size; }
virtual UINT32 get_vram_size() { return m_vram_size; }
virtual UINT32 get_battery_size() { return m_battery_size; }
virtual UINT32 get_mapper_ram_size() { return m_mapper_ram_size; }
virtual UINT32 get_mapper_bram_size() { return m_mapper_bram_size; }
//private:
// internal state
UINT8 *m_prg;
UINT8 *m_prgram;
UINT8 *m_vrom;
UINT8 *m_vram;
UINT8 *m_battery;
UINT8 *m_mapper_ram;
UINT8 *m_mapper_bram;
UINT32 m_prg_size;
UINT32 m_prgram_size;
UINT32 m_vrom_size;
UINT32 m_vram_size;
UINT32 m_battery_size;
UINT32 m_mapper_ram_size;
UINT32 m_mapper_bram_size;
int m_mirroring, m_four_screen_vram;
bool m_has_battery, m_has_prgram;
};
// ======================> nes_cart_slot_device
class base_nes_cart_slot_device : public device_t,
public nes_cart_interface,
public device_image_interface,
public device_slot_interface
{
public:
// construction/destruction
base_nes_cart_slot_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
virtual ~base_nes_cart_slot_device();
// device-level overrides
virtual void device_start();
virtual void device_config_complete();
// image-level overrides
virtual bool call_load();
virtual void call_unload();
virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry);
virtual iodevice_t image_type() const { return IO_CARTSLOT; }
virtual bool is_readable() const { return 1; }
virtual bool is_writeable() const { return 0; }
virtual bool is_creatable() const { return 0; }
virtual bool must_be_loaded() const { return 1; }
virtual bool is_reset_on_load() const { return 0; }
virtual const char *image_interface() const { return "nes_cart"; }
virtual const char *file_extensions() const { return "nes,unf,unif"; }
virtual const option_guide *create_option_guide() const { return NULL; }
// slot interface overrides
virtual const char * get_default_card_software(const machine_config &config, emu_options &options);
// reading and writing
virtual DECLARE_READ8_MEMBER(read_l);
virtual DECLARE_READ8_MEMBER(read_m);
virtual DECLARE_READ8_MEMBER(read_h);
virtual DECLARE_WRITE8_MEMBER(write_l);
virtual DECLARE_WRITE8_MEMBER(write_m);
virtual DECLARE_WRITE8_MEMBER(write_h);
int get_pcb_id() { return m_pcb_id; };
// temporarily here
int m_chr_open_bus;
int m_ce_mask;
int m_ce_state;
int m_vrc_ls_prg_a;
int m_vrc_ls_prg_b;
int m_vrc_ls_chr;
int m_crc_hack;
virtual int get_chr_open_bus() { return m_chr_open_bus; };
virtual int get_ce_mask() { return m_ce_mask; };
virtual int get_ce_state() { return m_ce_state; };
virtual int get_vrc_ls_prg_a() { return m_vrc_ls_prg_a; };
virtual int get_vrc_ls_prg_b() { return m_vrc_ls_prg_b; };
virtual int get_vrc_ls_chr() { return m_vrc_ls_chr; };
virtual int get_crc_hack() { return m_crc_hack; };
//private:
device_nes_cart_interface* m_cart;
int m_pcb_id;
};
// ======================> nes_cart_slot_device
class nes_cart_slot_device : public base_nes_cart_slot_device
{
public:
// construction/destruction
nes_cart_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
virtual bool must_be_loaded() const { return 1; }
};
// ======================> fc_cart_slot_device
class fc_cart_slot_device : public base_nes_cart_slot_device
{
public:
// construction/destruction
fc_cart_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
virtual bool must_be_loaded() const { return 0; }
};
// device type definition
extern const device_type NES_CART_SLOT;
extern const device_type FC_CART_SLOT; // same but not mandatory
/***************************************************************************
DEVICE CONFIGURATION MACROS
***************************************************************************/
#define MCFG_NES_CARTRIDGE_ADD(_tag,_config,_slot_intf,_def_slot,_def_inp) \
MCFG_DEVICE_ADD(_tag, NES_CART_SLOT, 0) \
MCFG_DEVICE_CONFIG(_config) \
MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, _def_inp, false)
#define MCFG_FC_CARTRIDGE_ADD(_tag,_config,_slot_intf,_def_slot,_def_inp) \
MCFG_DEVICE_ADD(_tag, FC_CART_SLOT, 0) \
MCFG_DEVICE_CONFIG(_config) \
MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, _def_inp, false)
// CART DEVICE [TO BE MOVED TO SEPARATE SOURCE LATER]
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
// ======================> nes_rom_device
class nes_rom_device : public device_t,
public device_nes_cart_interface
{
public:
// construction/destruction
nes_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
nes_rom_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
//protected:
// device-level overrides
virtual void device_start();
virtual void device_config_complete() { m_shortname = "nes_rom"; }
// nescart_interface overrides
// virtual DECLARE_READ8_MEMBER(read_l);
// virtual DECLARE_READ8_MEMBER(read_m);
// virtual DECLARE_READ8_MEMBER(read_h);
// virtual DECLARE_WRITE8_MEMBER(write_l);
// virtual DECLARE_WRITE8_MEMBER(write_m);
// virtual DECLARE_WRITE8_MEMBER(write_h);
};
// device type definition
extern const device_type NES_ROM;
#endif

View File

@ -158,25 +158,20 @@ const unif *nes_unif_lookup( const char *board )
*************************************************************/
void unif_mapr_setup( running_machine &machine, const char *board )
void unif_mapr_setup( const char *board, int *pcb_id, int *battery, int *prgram, int *vram_chunks )
{
nes_state *state = machine.driver_data<nes_state>();
const unif *unif_board = nes_unif_lookup(board);
logerror("%s\n", board);
const unif *unif_board = nes_unif_lookup(board);
if (unif_board == NULL)
fatalerror("Unknown UNIF board %s.\n", board);
state->m_pcb_id = unif_board->board_idx;
state->m_battery = unif_board->nvwram; // we should implement battery banks based on the size of this...
state->m_battery_size = NES_BATTERY_SIZE; // FIXME: we should allow for smaller battery!
state->m_prg_ram = unif_board->wram; // we should implement WRAM banks based on the size of this...
*pcb_id = unif_board->board_idx;
*battery = unif_board->nvwram; // we should implement battery banks based on the size of this...
*prgram = unif_board->wram; // we should implement WRAM banks based on the size of this...
if (unif_board->chrram <= CHRRAM_8)
state->m_vram_chunks = 1;
*vram_chunks = 1;
else if (unif_board->chrram == CHRRAM_16)
state->m_vram_chunks = 2;
*vram_chunks = 2;
else if (unif_board->chrram == CHRRAM_32)
state->m_vram_chunks = 4;
*vram_chunks = 4;
}

View File

@ -1417,6 +1417,7 @@ $(MESSOBJ)/next.a: \
$(MESSOBJ)/nintendo.a: \
$(MESS_MACHINE)/nes_mmc.o \
$(MESS_MACHINE)/nes_slot.o \
$(MESS_VIDEO)/nes.o \
$(MESS_MACHINE)/nes.o \
$(MESS_DRIVERS)/nes.o \