From c41d2e4e1cc52036a757facab198d49ed371ca02 Mon Sep 17 00:00:00 2001 From: Wilbert Pol Date: Sat, 4 May 2013 18:34:31 +0000 Subject: [PATCH] (MESS) electron.c: Added cartridge support. [Wilbert Pol] --- src/mess/drivers/electron.c | 13 ++++++++- src/mess/includes/electron.h | 1 + src/mess/machine/electron.c | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/mess/drivers/electron.c b/src/mess/drivers/electron.c index 87d34b9031d..1b9f52bd620 100644 --- a/src/mess/drivers/electron.c +++ b/src/mess/drivers/electron.c @@ -13,9 +13,11 @@ Incomplete: - Graphics (seems to be wrong for several games) - 1 MHz bus is not emulated - Bus claiming by ULA is not implemented + - Currently the cartridge support always loads the upper rom in page 12 + and the lower rom in page 0. This might need further documentation in + the software list and loading code. Missing: - - Support for ROM images - Support for floppy disks - Other peripherals - Keyboard is missing the 'Break' key @@ -26,6 +28,7 @@ Missing: #include "cpu/m6502/m6502.h" #include "includes/electron.h" #include "imagedev/cassette.h" +#include "imagedev/cartslot.h" #include "formats/uef_cas.h" #include "sound/beep.h" @@ -196,6 +199,14 @@ static MACHINE_CONFIG_START( electron, electron_state ) MCFG_SOUND_ROUTE( ALL_OUTPUTS, "mono", 1.00 ) MCFG_CASSETTE_ADD( "cassette", electron_cassette_interface ) + + MCFG_CARTSLOT_ADD("cart") + MCFG_CARTSLOT_EXTENSION_LIST("bin") + MCFG_CARTSLOT_NOT_MANDATORY + MCFG_CARTSLOT_LOAD(electron_state, electron_cart) + MCFG_CARTSLOT_INTERFACE("electron_cart") + /* software lists */ + MCFG_SOFTWARE_LIST_ADD("cart_list","electron_cart") MACHINE_CONFIG_END diff --git a/src/mess/includes/electron.h b/src/mess/includes/electron.h index 2fbdb5acea9..52c1249397f 100644 --- a/src/mess/includes/electron.h +++ b/src/mess/includes/electron.h @@ -90,6 +90,7 @@ public: inline UINT8 read_vram( UINT16 addr ); inline void electron_plot_pixel(bitmap_ind16 &bitmap, int x, int y, UINT32 color); void electron_interrupt_handler(int mode, int interrupt); + DECLARE_DEVICE_IMAGE_LOAD_MEMBER( electron_cart ); }; diff --git a/src/mess/machine/electron.c b/src/mess/machine/electron.c index f2884fa78ed..f27a14ece4d 100644 --- a/src/mess/machine/electron.c +++ b/src/mess/machine/electron.c @@ -338,3 +338,54 @@ void electron_state::machine_start() machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(electron_state::setup_beep),this)); m_tape_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(electron_state::electron_tape_timer_handler),this)); } + +DEVICE_IMAGE_LOAD_MEMBER( electron_state, electron_cart ) +{ + UINT8 *user1 = memregion("user1")->base() + 0x4000; + + if (image.software_entry() == NULL) + { + UINT32 filesize = image.length(); + + if ( filesize != 16384 ) + { + image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size. Only size 16384 is supported"); + return IMAGE_INIT_FAIL; + } + + if (image.fread( user1 + 12 * 16384, filesize) != filesize) + { + image.seterror(IMAGE_ERROR_UNSPECIFIED, "Error loading file"); + return IMAGE_INIT_FAIL; + } + + return IMAGE_INIT_PASS; + } + + int upsize = image.get_software_region_length("uprom"); + int losize = image.get_software_region_length("lorom"); + + if ( upsize != 16384 && upsize != 0 ) + { + image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size for uprom"); + return IMAGE_INIT_FAIL; + } + + if ( losize != 16384 && losize != 0 ) + { + image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size for lorom"); + return IMAGE_INIT_FAIL; + } + + if ( upsize ) + { + memcpy( user1 + 12 * 16384, image.get_software_region("uprom"), upsize ); + } + + if ( losize ) + { + memcpy( user1 + 0 * 16384, image.get_software_region("lorom"), losize ); + } + + return IMAGE_INIT_PASS; +}