コード例 #1
0
ファイル: cartridge.cpp プロジェクト: DragonMinded/mame
bool msx_slot_cartridge_device::call_load()
{
	if ( m_cartridge )
	{
		if ( software_entry() )
		{
			UINT32 length;

			// Allocate and copy rom contents
			length = get_software_region_length("rom");
			m_cartridge->rom_alloc( length );
			if (length > 0)
			{
				UINT8 *rom_base = m_cartridge->get_rom_base();
				memcpy(rom_base, get_software_region("rom"), length);
			}

			// Allocate and copy vlm5030 rom contents
			length = get_software_region_length("vlm5030");
			m_cartridge->rom_vlm5030_alloc(length);
			if (length > 0)
			{
				UINT8 *rom_base = m_cartridge->get_rom_vlm5030_base();
				memcpy(rom_base, get_software_region("vlm5030"), length);
			}

			// Allocate ram
			length = get_software_region_length("ram");
			m_cartridge->ram_alloc( length );

			// Allocate sram
			length = get_software_region_length("sram");
			m_cartridge->sram_alloc( length );
		}
		else
		{
			UINT32 length = this->length();

			// determine how much space to allocate
			UINT32 length_aligned = 0x10000;

			if (length <= 0x2000)
				length_aligned = 0x2000;
			else if (length <= 0x4000)
				length_aligned = 0x4000;
			else if (length <= 0x8000)
				length_aligned = 0x8000;
			else if (length <= 0xc000)
				length_aligned = 0xc000;
			else
			{
				while (length_aligned < length )
					length_aligned *= 2;
			}

			m_cartridge->rom_alloc(length_aligned);
			m_cartridge->ram_alloc(0);
			m_cartridge->sram_alloc(0);

			if (fread(m_cartridge->get_rom_base(), length) != length)
			{
				seterror(IMAGE_ERROR_UNSPECIFIED, "Unable to fully read file");
				return IMAGE_INIT_FAIL;
			}

			// Check if there's some mapper related
			std::string extrainfo;
			if (hashfile_extrainfo(*this, extrainfo))
			{
			}
		}

		m_cartridge->set_out_irq_cb(DEVCB_WRITELINE(msx_slot_cartridge_device, irq_out));
		m_cartridge->initialize_cartridge();

		if (m_cartridge->get_sram_size() > 0)
		{
			battery_load(m_cartridge->get_sram_base(), m_cartridge->get_sram_size(), 0x00);
		}
	}
	return IMAGE_INIT_PASS;
}
コード例 #2
0
ファイル: sega8_slot.cpp プロジェクト: PugsyMAME/mame
image_init_result sega8_cart_slot_device::call_load()
{
	if (m_cart)
	{
		uint32_t len = !loaded_through_softlist() ? length() : get_software_region_length("rom");
		uint32_t offset = 0;
		uint8_t *ROM;

		if (m_is_card && len > 0x8000)
		{
			seterror(IMAGE_ERROR_UNSPECIFIED, "Attempted loading a card larger than 32KB");
			return image_init_result::FAIL;
		}

		// check for header
		if ((len % 0x4000) == 512)
		{
			offset = 512;
			len -= 512;
		}

		// make sure that we only get complete (0x4000) rom banks
		if (len & 0x3fff)
			len = ((len >> 14) + 1) << 14;

		m_cart->rom_alloc(len, tag());
		ROM = m_cart->get_rom_base();

		if (!loaded_through_softlist())
		{
			fseek(offset, SEEK_SET);
			fread(ROM, len);
		}
		else
			memcpy(ROM, get_software_region("rom"), get_software_region_length("rom"));

		/* check the image */
		if (verify_cart(ROM, len) != image_verify_result::PASS)
			logerror("Warning loading image: verify_cart failed\n");

		if (loaded_through_softlist())
			m_type = sega8_get_pcb_id(get_feature("slot") ? get_feature("slot") : "rom");
		else
			m_type = get_cart_type(ROM, len);

		set_lphaser_xoffset(ROM, len);

		setup_ram();

		// Check for gamegear cartridges with PIN 42 set to SMS mode
		if (loaded_through_softlist())
		{
			const char *pin_42 = get_feature("pin_42");
			if (pin_42 && !strcmp(pin_42, "sms_mode"))
				m_cart->set_sms_mode(1);
		}

		// when loading from fullpath m_late_battery_enable can be true and in that case
		// we attempt to load a battery because the game might have it!
		if (m_cart->get_ram_size() && (m_cart->get_has_battery() || m_cart->get_late_battery()))
			battery_load(m_cart->get_ram_base(), m_cart->get_ram_size(), 0x00);

		//printf("Type: %s\n", sega8_get_slot(type));

		internal_header_logging(ROM + offset, len, m_cart->get_ram_size());

		return image_init_result::PASS;
	}

	return image_init_result::PASS;
}
コード例 #3
0
ファイル: nes_pcb.c プロジェクト: Ilgrim/MAMEHub
void nes_cart_slot_device::call_load_pcb()
{
	UINT32 vram_size = 0, prgram_size = 0, battery_size = 0, mapper_sram_size = 0;
	// SETUP step 1: getting PRG, VROM, VRAM sizes
	UINT32 prg_size = get_software_region_length("prg");
	UINT32 vrom_size = get_software_region_length("chr");
	vram_size = get_software_region_length("vram");
	vram_size += get_software_region_length("vram2");

	// validate the xml fields
	if (!prg_size)
		fatalerror("No PRG entry for this software! Please check if the xml list got corrupted\n");
	if (prg_size < 0x8000)
		fatalerror("PRG entry is too small! Please check if the xml list got corrupted\n");

	// SETUP step 2: getting PCB and other settings
	if (get_feature("slot"))
		m_pcb_id = nes_get_pcb_id(get_feature("slot"));
	else
		m_pcb_id = NO_BOARD;

	// SETUP step 3: storing the info needed for emulation
	if (get_software_region("bwram") != NULL)
		battery_size = get_software_region_length("bwram");

	if (m_pcb_id == BANDAI_LZ93EX1 || m_pcb_id == BANDAI_LZ93EX2)
	{
		// allocate the 24C01 or 24C02 EEPROM
		battery_size += 0x2000;
	}

	if (m_pcb_id == BANDAI_DATACH)
	{
		// allocate the 24C01 and 24C02 EEPROM
		battery_size += 0x4000;
	}

	if (get_software_region("wram") != NULL)
		prgram_size = get_software_region_length("wram");

	if (get_feature("mirroring"))
	{
		const char *mirroring = get_feature("mirroring");
		if (!strcmp(mirroring, "horizontal"))
			m_cart->set_mirroring(PPU_MIRROR_HORZ);
		if (!strcmp(mirroring, "vertical"))
			m_cart->set_mirroring(PPU_MIRROR_VERT);
		if (!strcmp(mirroring, "high"))
			m_cart->set_mirroring(PPU_MIRROR_HIGH);
		if (!strcmp(mirroring, "low"))
			m_cart->set_mirroring(PPU_MIRROR_LOW);
		if (!strcmp(mirroring, "4screen"))
		{
			// A few boards uses 4-screen mirroring: Gauntlet (DDROM or TRR1ROM or Tengen 800004),
			// Rad Racer II (TVROM), and Napoleon Senki (IREM LROG017 with 74*161/161/21/138)
			m_cart->set_four_screen_vram(TRUE);
			m_cart->set_mirroring(PPU_MIRROR_4SCREEN);
		}
		if (!strcmp(mirroring, "pcb_controlled"))
		{
			// A few boards have variants with hardcoded mirroring and variants with mapper
			// controlled mirroring. We use a variable to avoid the need of dupe devices.
			// See e.g. HES 6-in-1 vs other HES games, Irem Major League vs other G-101 games,
			// Sunsoft-2 Shanghai vs Mito Koumon, Camerica BF9093 games vs BF9097 games, etc.
			// Boards where all games control mirroring do not make real use of this.
			m_cart->set_pcb_ctrl_mirror(TRUE);
		}
	}

	/* Check for pins in specific boards which require them */
	if (m_pcb_id == STD_CNROM)
	{
		int mask = 0, state = 0;

		if (get_feature("chr-pin26") != NULL)
		{
			mask |= 0x01;
			state |= !strcmp(get_feature("chr-pin26"), "CE") ? 0x01 : 0;
		}
		if (get_feature("chr-pin27") != NULL)
		{
			mask |= 0x02;
			state |= !strcmp(get_feature("chr-pin27"), "CE") ? 0x02 : 0;
		}

		m_cart->set_ce(mask, state);
	}

	if (m_pcb_id == TAITO_X1_005 && get_feature("x1-pin17") != NULL && get_feature("x1-pin31") != NULL)
	{
		if (!strcmp(get_feature("x1-pin17"), "CIRAM A10") && !strcmp(get_feature("x1-pin31"), "NC"))
			m_cart->set_x1_005_alt(TRUE);
	}

	if (m_pcb_id == KONAMI_VRC2)
	{
		m_cart->set_vrc_lines(nes_cart_get_line(get_feature("vrc2-pin3")),
						nes_cart_get_line(get_feature("vrc2-pin4")),
						(nes_cart_get_line(get_feature("vrc2-pin21")) != 10) ? 1 : 0);
//      mame_printf_error("VRC-2, pin3: A%d, pin4: A%d, pin21: %d\n", nes_cart_get_line(get_feature("vrc2-pin3")), nes_cart_get_line(get_feature("vrc2-pin4")),
//                              nes_cart_get_line(get_feature("vrc2-pin21")));
	}

	if (m_pcb_id == KONAMI_VRC4)
	{
		m_cart->set_vrc_lines(nes_cart_get_line(get_feature("vrc4-pin3")),
						nes_cart_get_line(get_feature("vrc4-pin4")),
						0);
//      mame_printf_error("VRC-4, pin3: A%d, pin4: A%d\n", nes_cart_get_line(get_feature("vrc4-pin3"), nes_cart_get_line(get_feature("vrc4-pin4"));
	}

	if (m_pcb_id == KONAMI_VRC6)
	{
		m_cart->set_vrc_lines(nes_cart_get_line(get_feature("vrc6-pin9")),
						nes_cart_get_line(get_feature("vrc6-pin10")),
						0);
//      mame_printf_error("VRC-6, pin9: A%d, pin10: A%d\n", nes_cart_get_line(get_feature("vrc6-pin9"), nes_cart_get_line(get_feature("vrc6-pin10"));
	}

	if (m_pcb_id == STD_HKROM || m_pcb_id == TAITO_X1_017)
		mapper_sram_size = m_cart->get_mapper_sram_size();

	if (m_pcb_id == TAITO_X1_005 || m_pcb_id == NAMCOT_163)
	{
		if (get_feature("batt"))
			mapper_sram_size = m_cart->get_mapper_sram_size();
	}


	// pirate variants of boards with bus conflict are often not suffering from it
	// and actually games glitch if bus conflict is emulated...
	if (get_feature("bus_conflict") && !strcmp(get_feature("bus_conflict"), "no"))
		m_cart->set_bus_conflict(FALSE);


	// SETUP step 4: logging what we have found
	logerror("Loaded game from softlist:\n");
	logerror("-- PCB: %s", get_feature("pcb"));
	if (m_pcb_id == UNSUPPORTED_BOARD)
		logerror(" (currently not supported by MESS)");
	logerror("\n-- PRG 0x%x (%d x 16k chunks)\n", prg_size, prg_size / 0x4000);
	logerror("-- VROM 0x%x (%d x 8k chunks)\n", vrom_size, vrom_size / 0x2000);
	logerror("-- VRAM 0x%x (%d x 8k chunks)\n", vram_size, vram_size / 0x2000);
	logerror("-- PRG NVWRAM: %d\n", m_cart->get_battery_size());
	logerror("-- PRG WRAM: %d\n",  m_cart->get_prgram_size());

	// SETUP steps 5/6: allocate pointers for PRG/VROM and load the data!
	m_cart->prg_alloc(machine(), prg_size);
	memcpy(m_cart->get_prg_base(), get_software_region("prg"), prg_size);
	if (vrom_size)
	{
		m_cart->vrom_alloc(machine(), vrom_size);
		memcpy(m_cart->get_vrom_base(), get_software_region("chr"), vrom_size);
	}

	// SETUP steps 7: allocate the remaining pointer, when needed
	if (vram_size)
		m_cart->vram_alloc(machine(), vram_size);
	if (prgram_size)
		m_cart->prgram_alloc(machine(), prgram_size);

	// also nes_smb2j_device needs WRAM initialized to 0xff? check!
	if (m_pcb_id == UNL_SMB2J)
		memset(m_cart->get_prgram_base(), 0xff, prgram_size);

	// Attempt to load a battery file for this ROM
	// A few boards have internal RAM with a battery (MMC6, Taito X1-005 & X1-017, etc.)
	if (battery_size || mapper_sram_size)
	{
		UINT32 tot_size = battery_size + mapper_sram_size;
		UINT8 *temp_nvram = auto_alloc_array(machine(), UINT8, tot_size);
		battery_load(temp_nvram, tot_size, 0x00);
		if (battery_size)
		{
			m_cart->battery_alloc(machine(), battery_size);
			memcpy(m_cart->get_battery_base(), temp_nvram, battery_size);
		}
		if (mapper_sram_size)
			memcpy(m_cart->get_mapper_sram_base(), temp_nvram + battery_size, mapper_sram_size);

		if (temp_nvram)
			auto_free(machine(), temp_nvram);
	}
}
コード例 #4
0
ファイル: gba_slot.c プロジェクト: jiangzhonghui/mame
bool gba_cart_slot_device::call_load()
{
	if (m_cart)
	{
		UINT8 *ROM = (UINT8 *)m_cart->get_rom_base();
		UINT32 cart_size;

		if (software_entry() == NULL)
		{
			cart_size = length();
			if (cart_size > 0x2000000)
			{
				seterror(IMAGE_ERROR_UNSPECIFIED, "Attempted loading a cart larger than 32MB");
				return IMAGE_INIT_FAIL;
			}
			fread(ROM, cart_size);
			m_cart->set_rom_size(cart_size);    // we store the actual game size...

			m_type = get_cart_type(ROM, cart_size);
		}
		else
		{
			const char *pcb_name = get_feature("slot");

			cart_size = get_software_region_length("rom");
			if (cart_size > 0x2000000)
			{
				seterror(IMAGE_ERROR_UNSPECIFIED, "Attempted loading a cart larger than 32MB");
				return IMAGE_INIT_FAIL;
			}
			memcpy(ROM, get_software_region("rom"), cart_size);
			m_cart->set_rom_size(cart_size);    // we store the actual game size...

			if (pcb_name)
				m_type = gba_get_pcb_id(pcb_name);

			//printf("Type: %s\n", gba_get_slot(m_type));

			mame_printf_info("GBA: Detected (XML) %s\n", pcb_name ? pcb_name : "NONE");
		}

		if (m_type == GBA_SRAM)
			m_cart->nvram_alloc(machine(), 0x10000);

		// mirror the ROM
		switch (cart_size)
		{
			case 2 * 1024 * 1024:
				memcpy(ROM + 0x200000, ROM, 0x200000);
				// intentional fall-through
			case 4 * 1024 * 1024:
				memcpy(ROM + 0x400000, ROM, 0x400000);
				// intentional fall-through
			case 8 * 1024 * 1024:
				memcpy(ROM + 0x800000, ROM, 0x800000);
				// intentional fall-through
			case 16 * 1024 * 1024:
				memcpy(ROM + 0x1000000, ROM, 0x1000000);
				break;
		}

		if (m_cart->get_nvram_size())
			battery_load(m_cart->get_nvram_base(), m_cart->get_nvram_size(), 0x00);

		return IMAGE_INIT_PASS;
	}

	return IMAGE_INIT_PASS;
}