Example #1
0
image_init_result channelf_cart_slot_device::call_load()
{
    if (m_cart)
    {
        uint32_t len = (software_entry() == nullptr) ? length() : get_software_region_length("rom");
        m_cart->rom_alloc(len, tag());

        if (software_entry() == nullptr)
            fread(m_cart->get_rom_base(), len);
        else
            memcpy(m_cart->get_rom_base(), get_software_region("rom"), len);

        if (software_entry() == nullptr)
        {
            // we default to "chess" slot because some homebrew programs have been written to run
            // on PCBs with RAM at $2000-$2800 as Saba Schach!
            if (len == 0x40000)
                m_type = CF_MULTI;  // TODO1: differentiate multicart final and earlier from fullpath
            else
                m_type = CF_CHESS;  // TODO2: is there any way to detect Maze and Hangman from fullpath?

            m_cart->ram_alloc(0x800);
        }
        else
        {
            const char *pcb_name = get_feature("slot");
            if (pcb_name)
                m_type = chanf_get_pcb_id(pcb_name);

            if (get_software_region("ram"))
                m_cart->ram_alloc(get_software_region_length("ram"));
        }

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

        return image_init_result::PASS;
    }

    return image_init_result::PASS;
}
Example #2
0
int harddisk_image_device::internal_load_hd()
{
	astring tempstring;
	chd_error err = CHDERR_NONE;

	m_chd = NULL;

	if (m_hard_disk_handle)
		hard_disk_close(m_hard_disk_handle);

	/* open the CHD file */
	if (software_entry() != NULL)
	{
		m_chd  = get_disk_handle(device().machine(), device().subtag(tempstring,"harddriv"));
	}
	else
	{
		err = m_origchd.open(*image_core_file(), true);
		if (err == CHDERR_NONE)
		{
			m_chd = &m_origchd;
		}
		else if (err == CHDERR_FILE_NOT_WRITEABLE)
		{
			err = m_origchd.open(*image_core_file(), false);
			if (err == CHDERR_NONE)
			{
				err = open_disk_diff(device().machine().options(), basename_noext(), m_origchd, m_diffchd);
				if (err == CHDERR_NONE)
				{
					m_chd = &m_diffchd;
				}
			}
		}
	}

	if (m_chd != NULL)
	{
		/* open the hard disk file */
		m_hard_disk_handle = hard_disk_open(m_chd);
		if (m_hard_disk_handle != NULL)
			return IMAGE_INIT_PASS;
	}

	/* if we had an error, close out the CHD */
	m_origchd.close();
	m_diffchd.close();
	m_chd = NULL;
	seterror(IMAGE_ERROR_UNSPECIFIED, chd_file::error_string(err));

	return IMAGE_INIT_FAIL;
}
bool device_image_interface::open_image_file(emu_options &options)
{
	const char* path = options.value(instance_name());
	if (strlen(path)>0)
	{
		set_init_phase();
		if (load_internal(path, FALSE, 0, NULL, TRUE)==IMAGE_INIT_PASS)
		{
			if (software_entry()==NULL) return true;
		}
	}
	return false;
}
Example #4
0
bool device_image_interface::open_image_file(emu_options &options)
{
	const char* path = options.value(instance_name());
	if (*path != 0)
	{
		set_init_phase();
		if (load_internal(path, false, 0, nullptr, true) == image_init_result::PASS)
		{
			if (software_entry()==nullptr) return true;
		}
	}
	return false;
}
Example #5
0
image_init_result harddisk_image_device::internal_load_hd()
{
	chd_error err = CHDERR_NONE;

	m_chd = nullptr;

	if (m_hard_disk_handle)
		hard_disk_close(m_hard_disk_handle);

	/* open the CHD file */
	if (software_entry() != nullptr)
	{
		m_chd = machine().rom_load().get_disk_handle(device().subtag("harddriv").c_str());
	}
	else
	{
		err = m_origchd.open(image_core_file(), true);
		if (err == CHDERR_NONE)
		{
			m_chd = &m_origchd;
		}
		else if (err == CHDERR_FILE_NOT_WRITEABLE)
		{
			err = m_origchd.open(image_core_file(), false);
			if (err == CHDERR_NONE)
			{
				err = open_disk_diff(device().machine().options(), basename_noext(), m_origchd, m_diffchd);
				if (err == CHDERR_NONE)
				{
					m_chd = &m_diffchd;
				}
			}
		}
	}

	if (m_chd != nullptr)
	{
		/* open the hard disk file */
		m_hard_disk_handle = hard_disk_open(m_chd);
		if (m_hard_disk_handle != nullptr)
			return image_init_result::PASS;
	}

	/* if we had an error, close out the CHD */
	m_origchd.close();
	m_diffchd.close();
	m_chd = nullptr;
	seterror(IMAGE_ERROR_UNSPECIFIED, chd_file::error_string(err));

	return image_init_result::FAIL;
}
Example #6
0
bool cbm2_expansion_slot_device::call_load()
{
	size_t size = 0;

	if (m_card)
	{
		if (software_entry() == NULL)
		{
			size = length();

			if (!mame_stricmp(filetype(), "20"))
			{
				fread(m_card->cbm2_bank1_pointer(machine(), size), size);
			}
			else if (!mame_stricmp(filetype(), "40"))
			{
				fread(m_card->cbm2_bank2_pointer(machine(), size), size);
			}
			else if (!mame_stricmp(filetype(), "60"))
			{
				fread(m_card->cbm2_bank3_pointer(machine(), size), size);
			}
		}
		else
		{
			size = get_software_region_length("bank1");
			if (size) memcpy(m_card->cbm2_bank1_pointer(machine(), size), get_software_region("bank1"), size);

			size = get_software_region_length("bank2");
			if (size) memcpy(m_card->cbm2_bank2_pointer(machine(), size), get_software_region("bank2"), size);

			size = get_software_region_length("bank3");
			if (size) memcpy(m_card->cbm2_bank3_pointer(machine(), size), get_software_region("bank3"), size);

			size = get_software_region_length("ram");
			if (size) memset(m_card->cbm2_ram_pointer(machine(), size), 0, size);

			size = get_software_region_length("nvram");
			if (size) memset(m_card->cbm2_nvram_pointer(machine(), size), 0, size);
		}
	}

	return IMAGE_INIT_PASS;
}
Example #7
0
bool plus4_expansion_slot_device::call_load()
{
	if (m_card)
	{
		if (software_entry() == NULL)
		{
			// TODO
		}
		else
		{
			load_software_region("c1l", m_card->m_c1l);
			load_software_region("c1h", m_card->m_c1h);
			load_software_region("c2l", m_card->m_c2l);
			load_software_region("c2h", m_card->m_c2h);
		}
	}

	return IMAGE_INIT_PASS;
}
Example #8
0
File: exp.cpp Project: Enverex/mame
image_init_result vic20_expansion_slot_device::call_load()
{
	if (m_card)
	{
		if (software_entry() == nullptr)
		{
			if (is_filetype("20")) fread(m_card->m_blk1, 0x2000);
			else if (is_filetype("40")) fread(m_card->m_blk2, 0x2000);
			else if (is_filetype("60")) fread(m_card->m_blk3, 0x2000);
			else if (is_filetype("70")) fread(m_card->m_blk3, 0x2000, 0x1000);
			else if (is_filetype("a0")) fread(m_card->m_blk5, 0x2000);
			else if (is_filetype("b0")) fread(m_card->m_blk5, 0x2000, 0x1000);
			else if (is_filetype("crt"))
			{
				// read the header
				uint8_t header[2];
				fread(&header, 2);
				uint16_t address = (header[1] << 8) | header[0];

				switch (address)
				{
				case 0x2000: fread(m_card->m_blk1, 0x2000); break;
				case 0x4000: fread(m_card->m_blk2, 0x2000); break;
				case 0x6000: fread(m_card->m_blk3, 0x2000); break;
				case 0x7000: fread(m_card->m_blk3, 0x2000, 0x1000); break;
				case 0xa000: fread(m_card->m_blk5, 0x2000); break;
				case 0xb000: fread(m_card->m_blk5, 0x2000, 0x1000); break;
				default: return image_init_result::FAIL;
				}
			}
		}
		else
		{
			load_software_region("blk1", m_card->m_blk1);
			load_software_region("blk2", m_card->m_blk2);
			load_software_region("blk3", m_card->m_blk3);
			load_software_region("blk5", m_card->m_blk5);
		}
	}

	return image_init_result::PASS;
}
Example #9
0
bool vic20_expansion_slot_device::call_load()
{
	if (m_card)
	{
		if (software_entry() == NULL)
		{
			if (!core_stricmp(filetype(), "20")) fread(m_card->m_blk1, 0x2000);
			else if (!core_stricmp(filetype(), "40")) fread(m_card->m_blk2, 0x2000);
			else if (!core_stricmp(filetype(), "60")) fread(m_card->m_blk3, 0x2000);
			else if (!core_stricmp(filetype(), "70")) fread(m_card->m_blk3, 0x2000, 0x1000);
			else if (!core_stricmp(filetype(), "a0")) fread(m_card->m_blk5, 0x2000);
			else if (!core_stricmp(filetype(), "b0")) fread(m_card->m_blk5, 0x2000, 0x1000);
			else if (!core_stricmp(filetype(), "crt"))
			{
				// read the header
				UINT8 header[2];
				fread(&header, 2);
				UINT16 address = (header[1] << 8) | header[0];

				switch (address)
				{
				case 0x2000: fread(m_card->m_blk1, 0x2000); break;
				case 0x4000: fread(m_card->m_blk2, 0x2000); break;
				case 0x6000: fread(m_card->m_blk3, 0x2000); break;
				case 0x7000: fread(m_card->m_blk3, 0x2000, 0x1000); break;
				case 0xa000: fread(m_card->m_blk5, 0x2000); break;
				case 0xb000: fread(m_card->m_blk5, 0x2000, 0x1000); break;
				default: return IMAGE_INIT_FAIL;
				}
			}
		}
		else
		{
			load_software_region("blk1", m_card->m_blk1);
			load_software_region("blk2", m_card->m_blk2);
			load_software_region("blk3", m_card->m_blk3);
			load_software_region("blk5", m_card->m_blk5);
		}
	}

	return IMAGE_INIT_PASS;
}
Example #10
0
File: rom.c Project: dinkc64/mame
bool ql_rom_cartridge_slot_t::call_load()
{
    if (m_card)
    {
        size_t size = 0;

        if (software_entry() == NULL)
        {
            size = length();

            m_card->m_rom.allocate(size);
            fread(m_card->m_rom, size);
        }
        else
        {
            load_software_region("rom", m_card->m_rom);
        }
    }

    return IMAGE_INIT_PASS;
}
Example #11
0
bool cdrom_image_device::call_load()
{
	chd_error   err = (chd_error)0;
	chd_file    *chd = NULL;
	astring tempstring;

	if (m_cdrom_handle)
		cdrom_close(m_cdrom_handle);

	if (software_entry() == NULL)
	{
		if (strstr(m_image_name,".chd") && is_loaded()) {
			err = m_self_chd.open( *image_core_file() );    /* CDs are never writeable */
			if ( err )
				goto error;
			chd = &m_self_chd;
		}
	} else {
		chd  = get_disk_handle(device().machine(), device().subtag(tempstring,"cdrom"));
	}

	/* open the CHD file */
	if (chd) {
		m_cdrom_handle = cdrom_open( chd );
	} else {
		m_cdrom_handle = cdrom_open( m_image_name );
	}
	if ( ! m_cdrom_handle )
		goto error;

	return IMAGE_INIT_PASS;

error:
	if ( chd && chd == &m_self_chd )
		m_self_chd.close( );
	if ( err )
		seterror( IMAGE_ERROR_UNSPECIFIED, chd_file::error_string( err ) );
	return IMAGE_INIT_FAIL;
}
Example #12
0
// 128K for Dizzy The Adventurer, 256K for the others
bool nes_aladdin_slot_device::call_load()
{
	if (m_cart)
	{
		UINT8 *ROM = m_cart->get_cart_base();
		UINT32 size = 0;

		if (!ROM)
			return IMAGE_INIT_FAIL;

		if (software_entry() == NULL)
		{
			if (length() != 0x20010 && length() != 0x40010)
				return IMAGE_INIT_FAIL;

			UINT8 temp[0x40010];
			size = length() - 0x10;
			fread(&temp, length());
			memcpy(ROM, temp + 0x10, size);

			// double check that iNES files are really mapper 71 or 232
			{
				UINT8 mapper = (temp[6] & 0xf0) >> 4;
				mapper |= temp[7] & 0xf0;
				if (mapper != 71 && mapper != 232)
					return IMAGE_INIT_FAIL;
			}
		}
		else
		{
			if (get_software_region_length("rom") != 0x20000 && get_software_region_length("rom") != 0x40000)
				return IMAGE_INIT_FAIL;

			size = get_software_region_length("rom");
			memcpy(ROM, get_software_region("rom"), size);
		}

		m_cart->set_cart_size(size);
	}
Example #13
0
image_init_result cdrom_image_device::call_load()
{
	chd_error   err = (chd_error)0;
	chd_file    *chd = nullptr;

	if (m_cdrom_handle)
		cdrom_close(m_cdrom_handle);

	if (software_entry() == nullptr)
	{
		if (is_filetype("chd") && is_loaded()) {
			err = m_self_chd.open( image_core_file() );    /* CDs are never writeable */
			if ( err )
				goto error;
			chd = &m_self_chd;
		}
	} else {
		chd = device().machine().rom_load().get_disk_handle(device().subtag("cdrom").c_str());
	}

	/* open the CHD file */
	if (chd) {
		m_cdrom_handle = cdrom_open( chd );
	} else {
		m_cdrom_handle = cdrom_open(m_image_name.c_str());
	}
	if ( ! m_cdrom_handle )
		goto error;

	return image_init_result::PASS;

error:
	if ( chd && chd == &m_self_chd )
		m_self_chd.close( );
	if ( err )
		seterror( IMAGE_ERROR_UNSPECIFIED, chd_file::error_string( err ) );
	return image_init_result::FAIL;
}
Example #14
0
bool cococart_slot_device::call_load()
{
	if (m_cart)
	{
		offs_t read_length = 0;
		if (software_entry() == NULL)
		{
			read_length = fread(m_cart->get_cart_base(), 0x8000);
		}
		else
		{
			read_length = get_software_region_length("rom");
			memcpy(m_cart->get_cart_base(), get_software_region("rom"), read_length);
		}
		while(read_length < 0x8000)
		{
			offs_t len = MIN(read_length, 0x8000 - read_length);
			memcpy(m_cart->get_cart_base() + read_length, m_cart->get_cart_base(), len);
			read_length += len;
		}
	}
	return IMAGE_INIT_PASS;
}
Example #15
0
bool adam_expansion_slot_device::call_load()
{
	if (m_cart)
	{
		size_t size = 0;

		if (software_entry() == NULL)
		{
			size = length();

			fread(m_cart->adam_rom_pointer(machine(), size), size);
		}
		else
		{
			size = get_software_region_length("rom");
			if (size) memcpy(m_cart->adam_rom_pointer(machine(), size), get_software_region("rom"), size);

			size = get_software_region_length("ram");
			if (size) memcpy(m_cart->adam_ram_pointer(machine(), size), get_software_region("ram"), size);
		}
	}

	return IMAGE_INIT_PASS;
}
Example #16
0
bool cbm2_expansion_slot_device::call_load()
{
	size_t size = 0;

	if (m_card)
	{
		if (software_entry() == NULL)
		{
			size = length();

			if (!core_stricmp(filetype(), "20"))
			{
				m_card->m_bank1.allocate(size);
				fread(m_card->m_bank1, size);
			}
			else if (!core_stricmp(filetype(), "40"))
			{
				m_card->m_bank2.allocate(size);
				fread(m_card->m_bank2, size);
			}
			else if (!core_stricmp(filetype(), "60"))
			{
				m_card->m_bank3.allocate(size);
				fread(m_card->m_bank3, size);
			}
		}
		else
		{
			load_software_region("bank1", m_card->m_bank1);
			load_software_region("bank2", m_card->m_bank2);
			load_software_region("bank3", m_card->m_bank3);
		}
	}

	return IMAGE_INIT_PASS;
}
Example #17
0
image_init_result cbm2_expansion_slot_device::call_load()
{
	size_t size;

	if (m_card)
	{
		if (software_entry() == nullptr)
		{
			size = length();

			if (is_filetype("20"))
			{
				m_card->m_bank1.allocate(size);
				fread(m_card->m_bank1, size);
			}
			else if (is_filetype("40"))
			{
				m_card->m_bank2.allocate(size);
				fread(m_card->m_bank2, size);
			}
			else if (is_filetype("60"))
			{
				m_card->m_bank3.allocate(size);
				fread(m_card->m_bank3, size);
			}
		}
		else
		{
			load_software_region("bank1", m_card->m_bank1);
			load_software_region("bank2", m_card->m_bank2);
			load_software_region("bank3", m_card->m_bank3);
		}
	}

	return image_init_result::PASS;
}
Example #18
0
File: exp.cpp Project: Enverex/mame
image_init_result videobrain_expansion_slot_device::call_load()
{
	if (m_cart)
	{
		size_t size;

		if (software_entry() == nullptr)
		{
			size = length();

			fread(m_cart->videobrain_rom_pointer(machine(), size), size);
		}
		else
		{
			size = get_software_region_length("rom");
			if (size) memcpy(m_cart->videobrain_rom_pointer(machine(), size), get_software_region("rom"), size);

			size = get_software_region_length("ram");
			if (size) memset(m_cart->videobrain_ram_pointer(machine(), size), 0, size);
		}
	}

	return image_init_result::PASS;
}
Example #19
0
bool c64_expansion_slot_device::call_load()
{
	if (m_card)
	{
		size_t size = 0;

		if (software_entry() == NULL)
		{
			size = length();

			if (!mame_stricmp(filetype(), "80"))
			{
				fread(m_card->m_roml, size);
				m_card->m_exrom = (0);

				if (size == 0x4000)
				{
					m_card->m_game = 0;
				}
			}
			else if (!mame_stricmp(filetype(), "a0"))
			{
				fread(m_card->m_romh, 0x2000);

				m_card->m_exrom = 0;
				m_card->m_game = 0;
			}
			else if (!mame_stricmp(filetype(), "e0"))
			{
				fread(m_card->m_romh, 0x2000);

				m_card->m_game = 0;
			}
			else if (!mame_stricmp(filetype(), "crt"))
			{
				size_t roml_size = 0;
				size_t romh_size = 0;
				int exrom = 1;
				int game = 1;

				if (cbm_crt_read_header(m_file, &roml_size, &romh_size, &exrom, &game))
				{
					UINT8 *roml = NULL;
					UINT8 *romh = NULL;

					m_card->m_roml.allocate(roml_size);
					m_card->m_romh.allocate(romh_size);

					if (roml_size) roml = m_card->m_roml;
					if (romh_size) romh = m_card->m_roml;

					cbm_crt_read_data(m_file, roml, romh);
				}

				m_card->m_exrom = exrom;
				m_card->m_game = game;
			}
		}
		else
		{
			size = get_software_region_length("uprom");

			if (size)
			{
				// Ultimax (VIC-10) cartridge
				load_software_region("lorom", m_card->m_roml);
				load_software_region("uprom", m_card->m_romh);

				m_card->m_exrom = 1;
				m_card->m_game = 0;
			}
			else
			{
				// Commodore 64/128 cartridge
				load_software_region("roml", m_card->m_roml);
				load_software_region("romh", m_card->m_romh);
				load_software_region("nvram", m_card->m_nvram);

				if (get_feature("exrom") != NULL) m_card->m_exrom = atol(get_feature("exrom"));
				if (get_feature("game") != NULL) m_card->m_game = atol(get_feature("game"));
			}
		}
	}

	return IMAGE_INIT_PASS;
}
Example #20
0
bool vcs_cart_slot_device::call_load()
{
	UINT8 *ROM;
	UINT32 len;

	if (software_entry() != NULL)
		len = get_software_region_length("rom");
	else
		len = length();

	//printf("Size: 0x%X\n", len);

	// check that filesize is among the supported ones
	switch (len)
	{
	case 0x00800:
	case 0x01000:
	case 0x02000:
	case 0x028ff:
	case 0x02900:
	case 0x03000:
	case 0x04000:
	case 0x08000:
	case 0x10000:
	case 0x80000:
		break;

	default:
		seterror(IMAGE_ERROR_UNSUPPORTED, "Invalid rom file size" );
		return IMAGE_INIT_FAIL;
	}

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

	if (software_entry() != NULL)
	{
		const char *pcb_name;
		memcpy(ROM, get_software_region("rom"), len);

		if ((pcb_name = get_feature("slot")) != NULL)
			m_type = vcs_get_pcb_id(pcb_name);
		else
		{
			// identify type based on size
			switch (len)
			{
				case 0x800:
					m_type = A26_2K;
					break;
				case 0x1000:
					m_type = A26_4K;
					break;
				case 0x2000:
					m_type = A26_F8;
					break;
				case 0x28ff:
				case 0x2900:
					m_type = A26_DPC;
					break;
				case 0x3000:
					m_type = A26_FA;
					break;
				case 0x4000:
					m_type = A26_F6;
					break;
				case 0x8000:
					m_type = A26_F4;
					break;
				case 0x10000:
					m_type = A26_32IN1;
					break;
				case 0x80000:
					m_type = A26_3F;
					break;
				default:
					m_type = A26_4K;
					printf("Unrecognized cart type!\n");
					break;
			}
			
		}
	}
	else
	{
		fread(ROM, len);
		m_type = identify_cart_type(ROM, len);
	}

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

	// check for Special Chip (128bytes of RAM)
	if (len == 0x2000 || len == 0x4000 || len == 0x8000)
		if (detect_super_chip(ROM, len))
		{
			m_cart->ram_alloc(0x80);
			//printf("Super Chip detected!\n");
		}
	// Super chip games:
	// dig dig, crystal castles, millipede, stargate, defender ii, jr. Pac Man,
	// desert falcon, dark chambers, super football, sprintmaster, fatal run,
	// off the wall, shooting arcade, secret quest, radar lock, save mary, klax

	// add CBS RAM+ (128bytes of RAM)
	if (m_type == A26_FA)
		m_cart->ram_alloc(0x100);
	// add M Network RAM
	else if (m_type == A26_E7)
		m_cart->ram_alloc(0x800);
	// add Commavid RAM
	else if (m_type == A26_CV)
		m_cart->ram_alloc(0x400);
	// add Starpath Superchager RAM
	else if (m_type == A26_SS)
		m_cart->ram_alloc(0x1800);
	// add Boulder Dash RAM
	else if (m_type == A26_3E)
		m_cart->ram_alloc(0x8000);

	// pass a pointer to the now allocated ROM for the DPC chip
	if (m_type == A26_DPC)
		m_cart->setup_addon_ptr((UINT8 *)m_cart->get_rom_base() + 0x2000);

	return IMAGE_INIT_PASS;
}
Example #21
0
void sega8_cart_slot_device::internal_header_logging(UINT8 *ROM, UINT32 len, UINT32 nvram_len)
{
	static const char *const system_region[] =
	{
		"",
		"",
		"",
		"Master System Japan",
		"Master System Export",
		"Game Gear Japan",
		"Game Gear Export",
		"Game Gear International",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		""
	};

	static int csum_length[] =
	{
		0x40000,
		0x80000,
		0x100000,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0x1ff0,
		0x3ff0,
		0x7ff0,
		0xcff0,
		0x10000,
		0x20000,
	};

	char reserved[10];
	UINT8 version, csum_size, region, serial[3];
	UINT16 checksum, csum = 0;
	UINT32 csum_end;

	// LOG FILE DETAILS
	logerror("FILE DETAILS\n" );
	logerror("============\n" );
	logerror("Name: %s\n", basename());
	logerror("File Size: 0x%08x\n", (software_entry() == nullptr) ? (int)length() : (int)get_software_region_length("rom"));
	logerror("Detected type: %s\n", sega8_get_slot(m_type));
	logerror("ROM (Allocated) Size: 0x%X\n", len);
	logerror("RAM: %s\n", nvram_len ? "Yes" : "No");
	if (nvram_len)
		logerror("RAM (Allocated) Size: 0x%X - Battery: %s\n", nvram_len, m_cart->get_has_battery() ? "Yes" : "No");
	logerror("\n" );


	// LOG HEADER DETAILS
	if (len < 0x8000)
		return;

	for (int i = 0; i < 10; i++)
		reserved[i] = ROM[0x7ff0 + i];

	checksum = ROM[0x7ffa] | (ROM[0x7ffb] << 8);

	for (int i = 0; i < 3; i++)
		serial[i] = ROM[0x7ffc + i];
	serial[2] &= 0x0f;

	version = (ROM[0x7ffe] & 0xf0) >> 4;

	csum_size = ROM[0x7fff] & 0x0f;
	csum_end = csum_length[csum_size];
	if (!csum_end || csum_end > len)
		csum_end = len;

	region = (ROM[0x7fff] & 0xf0) >> 4;

	// compute cart checksum to compare with expected one
	for (int i = 0; i < csum_end; i++)
	{
		if (i < 0x7ff0 || i >= 0x8000)
		{
			csum += ROM[i];
			csum &= 0xffff;
		}
	}

	logerror("INTERNAL HEADER\n" );
	logerror("===============\n" );
	logerror("Reserved String: %.10s\n", reserved);
	logerror("Region: %s\n", system_region[region]);
	logerror("Checksum: (Expected) 0x%x - (Computed) 0x%x\n", checksum, csum);
	logerror("   [checksum over 0x%X bytes]\n", csum_length[csum_size]);
	logerror("Serial String: %X\n", serial[0] | (serial[1] << 8) | (serial[2] << 16));
	logerror("Software Revision: %x\n", version);
	logerror("\n" );


	if (m_type == SEGA8_CODEMASTERS)
	{
		UINT8 day, month, year, hour, minute;
		csum = 0;

		day = ROM[0x7fe1];
		month = ROM[0x7fe2];
		year = ROM[0x7fe3];
		hour = ROM[0x7fe4];
		minute = ROM[0x7fe5];
		checksum = ROM[0x7fe6] | (ROM[0x7fe7] << 8);
		csum_size = ROM[0x7fe0];

		// compute cart checksum to compare with expected one
		for (int i = 0; i < len; i += 2)
		{
			if (i < 0x7ff0 || i >= 0x8000)
			{
				csum += (ROM[i] | (ROM[i + 1] << 8));
				csum &= 0xffff;
			}
		}

		logerror("CODEMASTERS HEADER\n" );
		logerror("==================\n" );
		logerror("Build date & time: %x/%x/%x %.2x:%.2x\n", day, month, year, hour, minute);
		logerror("Checksum: (Expected) 0x%x - (Computed) 0x%x\n", checksum, csum);
		logerror("   [checksum over 0x%X bytes]\n", csum_size * 0x4000);
		logerror("\n" );
	}
}
Example #22
0
image_init_result sega8_cart_slot_device::call_load()
{
	if (m_cart)
	{
		UINT32 len = (software_entry() == nullptr) ? length() : get_software_region_length("rom");
		UINT32 offset = 0;
		UINT8 *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 (software_entry() == nullptr)
		{
			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 (software_entry() != nullptr)
			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 (software_entry() != nullptr)
		{
			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;
}
Example #23
0
void sega8_cart_slot_device::setup_ram()
{
	if (software_entry() == nullptr)
	{
		if (m_type == SEGA8_CASTLE)
		{
			m_cart->ram_alloc(0x2000);
			m_cart->set_has_battery(FALSE);
		}
		else if (m_type == SEGA8_OTHELLO)
		{
			m_cart->ram_alloc(0x800);
			m_cart->set_has_battery(FALSE);
		}
		else if (m_type == SEGA8_BASIC_L3)
		{
			m_cart->ram_alloc(0x8000);
			m_cart->set_has_battery(FALSE);
		}
		else if (m_type == SEGA8_MUSIC_EDITOR)
		{
			m_cart->ram_alloc(0x2800);
			m_cart->set_has_battery(FALSE);
		}
		else if (m_type == SEGA8_DAHJEE_TYPEA)
		{
			m_cart->ram_alloc(0x2400);
			m_cart->set_has_battery(FALSE);
		}
		else if (m_type == SEGA8_DAHJEE_TYPEB)
		{
			m_cart->ram_alloc(0x2000);
			m_cart->set_has_battery(FALSE);
		}
		else if (m_type == SEGA8_CODEMASTERS)
		{
			// Codemasters cart can have 64KB of RAM (Ernie Els Golf? or 8KB?) and no battery
			m_cart->ram_alloc(0x10000);
			m_cart->set_has_battery(FALSE);
		}
		else
		{
			// for generic carts loaded from fullpath we have no way to know exactly if there was RAM,
			// how much RAM was in the cart and if there was a battery so we always alloc 32KB and
			// we save its content only if the game enable the RAM
			m_cart->set_late_battery(TRUE);
			m_cart->ram_alloc(0x08000);
		}
	}
	else
	{
		// from softlist we rely on the xml to only allocate the correct amount of RAM and to save it only if a battery was present
		const char *battery = get_feature("battery");
		m_cart->set_late_battery(FALSE);

		if (get_software_region_length("ram"))
			m_cart->ram_alloc(get_software_region_length("ram"));

		if (battery && !strcmp(battery, "yes"))
			m_cart->set_has_battery(TRUE);
	}
}
Example #24
0
File: exp.cpp Project: Enverex/mame
image_init_result c64_expansion_slot_device::call_load()
{
	if (m_card)
	{
		size_t size;

		if (software_entry() == nullptr)
		{
			size = length();

			if (is_filetype("80"))
			{
				fread(m_card->m_roml, size);
				m_card->m_exrom = (0);

				if (size == 0x4000)
				{
					m_card->m_game = 0;
				}
			}
			else if (is_filetype("a0"))
			{
				fread(m_card->m_romh, 0x2000);

				m_card->m_exrom = 0;
				m_card->m_game = 0;
			}
			else if (is_filetype("e0"))
			{
				fread(m_card->m_romh, 0x2000);

				m_card->m_game = 0;
			}
			else if (is_filetype("crt"))
			{
				size_t roml_size = 0;
				size_t romh_size = 0;
				int exrom = 1;
				int game = 1;

				if (cbm_crt_read_header(*m_file, &roml_size, &romh_size, &exrom, &game))
				{
					uint8_t *roml = nullptr;
					uint8_t *romh = nullptr;

					m_card->m_roml.allocate(roml_size);
					m_card->m_romh.allocate(romh_size);

					if (roml_size) roml = m_card->m_roml;
					if (romh_size) romh = m_card->m_roml;

					cbm_crt_read_data(*m_file, roml, romh);
				}

				m_card->m_exrom = exrom;
				m_card->m_game = game;
			}
		}
		else
		{
			size = get_software_region_length("uprom");

			if (size)
			{
				// Ultimax (VIC-10) cartridge
				load_software_region("lorom", m_card->m_roml);
				load_software_region("uprom", m_card->m_romh);

				m_card->m_exrom = 1;
				m_card->m_game = 0;
			}
			else
			{
				// Commodore 64/128 cartridge
				load_software_region("roml", m_card->m_roml);
				load_software_region("romh", m_card->m_romh);
				load_software_region("nvram", m_card->m_nvram);

				if (get_feature("exrom") != nullptr) m_card->m_exrom = atol(get_feature("exrom"));
				if (get_feature("game") != nullptr) m_card->m_game = atol(get_feature("game"));
			}
		}
	}

	return image_init_result::PASS;
}
Example #25
0
bool cassette_image_device::call_load()
{
	casserr_t err;
	int cassette_flags;
	const char *extension;
	int is_writable;
	device_image_interface *image = nullptr;
	interface(image);

	if ((has_been_created()) || (length() == 0))
	{
		/* creating an image */
		err = cassette_create((void *)image, &image_ioprocs, &wavfile_format, m_create_opts, CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT, &m_cassette);
		if (err)
			goto error;
	}
	else
	{
		/* opening an image */
		do
		{
			is_writable = !is_readonly();
			cassette_flags = is_writable ? (CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT) : CASSETTE_FLAG_READONLY;
			std::string fname;
			if (software_entry()==nullptr) {
				extension = filetype();
			} else {
				fname = m_mame_file->filename();
				int loc = fname.find_last_of('.');
				if (loc!=-1) {
					extension = fname.substr(loc + 1,fname.length()-loc).c_str();
				} else {
					extension = "";
				}
			}
			err = cassette_open_choices((void *)image, &image_ioprocs, extension, m_formats, cassette_flags, &m_cassette);

			/* this is kind of a hack */
			if (err && is_writable)
				make_readonly();
		}
		while(err && is_writable);

		if (err)
			goto error;
	}

	/* set to default state, but only change the UI state */
	change_state(m_default_state, CASSETTE_MASK_UISTATE);

	/* reset the position */
	m_position = 0.0;
	m_position_time = device().machine().time().as_double();

	/* default channel to 0, speed multiplier to 1 */
	m_channel = 0;
	m_speed = 1;
	m_direction = 1;

	return IMAGE_INIT_PASS;

error:
	image_error_t imgerr = IMAGE_ERROR_UNSPECIFIED;
	switch(err)
	{
		case CASSETTE_ERROR_INTERNAL:
			imgerr = IMAGE_ERROR_INTERNAL;
			break;
		case CASSETTE_ERROR_UNSUPPORTED:
			imgerr = IMAGE_ERROR_UNSUPPORTED;
			break;
		case CASSETTE_ERROR_OUTOFMEMORY:
			imgerr = IMAGE_ERROR_OUTOFMEMORY;
			break;
		case CASSETTE_ERROR_INVALIDIMAGE:
			imgerr = IMAGE_ERROR_INVALIDIMAGE;
			break;
		default:
			imgerr = IMAGE_ERROR_UNSPECIFIED;
			break;
	}
	image->seterror(imgerr, "" );
	return IMAGE_INIT_FAIL;
}
Example #26
0
File: slot.cpp Project: ursine/mame
bool crvision_cart_slot_device::call_load()
{
	if (m_cart)
	{
		UINT32 size = (software_entry() == nullptr) ? length() : get_software_region_length("rom");

		if (size > 0x4800)
		{
			seterror(IMAGE_ERROR_UNSPECIFIED, "Image extends beyond the expected size for an APF cart");
			return IMAGE_INIT_FAIL;
		}

		m_cart->rom_alloc(size, tag());

		if (software_entry() == nullptr)
			fread(m_cart->get_rom_base(), size);
		else
			memcpy(m_cart->get_rom_base(), get_software_region("rom"), size);

		if (software_entry() == nullptr)
		{
			m_type = CRV_4K;

			switch (size)
			{
				case 0x4800:
					m_type = CRV_18K;
					break;
				case 0x4000:
					m_type = CRV_16K;
					break;
				case 0x3000:
					m_type = CRV_12K;
					break;
				case 0x2800:
					m_type = CRV_10K;
					break;
				case 0x2000:
					m_type = CRV_8K;
					break;
				case 0x1800:
					m_type = CRV_6K;
					break;
				case 0x1000:
				default:
					break;
			}
		}
		else
		{
			const char *pcb_name = get_feature("slot");
			if (pcb_name)
				m_type = crvision_get_pcb_id(pcb_name);
		}

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

		return IMAGE_INIT_PASS;
	}

	return IMAGE_INIT_PASS;
}
Example #27
0
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;
}
Example #28
0
bool a78_cart_slot_device::call_load()
{
	if (m_cart)
	{
		UINT32 len;

		if (software_entry() != nullptr)
		{
			const char *pcb_name;
			bool has_ram = get_software_region("ram") ? TRUE : FALSE;
			bool has_nvram = get_software_region("nvram") ? TRUE : FALSE;
			len = get_software_region_length("rom");

			m_cart->rom_alloc(len, tag());
			memcpy(m_cart->get_rom_base(), get_software_region("rom"), len);

			if ((pcb_name = get_feature("slot")) != nullptr)
				m_type = a78_get_pcb_id(pcb_name);
			else
				m_type = A78_TYPE0;

			if (has_ram)
				m_cart->ram_alloc(get_software_region_length("ram"));
			if (has_nvram)
			{
				m_cart->nvram_alloc(get_software_region_length("nvram"));
				battery_load(m_cart->get_nvram_base(), get_software_region_length("nvram"), 0xff);
			}
		}
		else
		{
			// Load and check the header
			int mapper;
			char head[128];
			fread(head, 128);

			if (verify_header((char *)head) == IMAGE_VERIFY_FAIL)
				return IMAGE_INIT_FAIL;

			len = (head[49] << 24) | (head[50] << 16) | (head[51] << 8) | head[52];
			if (len + 128 > length())
			{
				logerror("Invalid length in the header. The game might be corrupted.\n");
				len = length() - 128;
			}

			// let's try to auto-fix some common errors in the header
			mapper = validate_header((head[53] << 8) | head[54], TRUE);

			switch (mapper & 0x2e)
			{
				case 0x0000:
					m_type = BIT(mapper, 0) ? A78_TYPE1 : A78_TYPE0;
					break;
				case 0x0002:
					m_type = BIT(mapper, 0) ? A78_TYPE3 : A78_TYPE2;
					break;
				case 0x0006:
					m_type = A78_TYPE6;
					break;
				case 0x000a:
					m_type = A78_TYPEA;
					break;
				case 0x0022:
				case 0x0026:
					if (len > 0x40000)
						m_type = A78_MEGACART;
					else
						m_type = A78_VERSABOARD;
					break;
			}

			// check if cart has a POKEY at $0450 (typically a VersaBoard variant)
			if (mapper & 0x40)
			{
				if (m_type != A78_TYPE2)
				{
					m_type &= ~0x02;
					m_type += A78_POKEY0450;
				}
			}

			// check special bits, which override the previous
			if ((mapper & 0xff00) == 0x0100)
				m_type = A78_ACTIVISION;
			else if ((mapper & 0xff00) == 0x0200)
				m_type = A78_ABSOLUTE;

			logerror("Cart type: 0x%x\n", m_type);

			if (head[58] == 1)
			{
				osd_printf_info("This cart supports external NVRAM using HSC.\n");
				osd_printf_info("Run it with the High Score Cart mounted to exploit this feature.\n");
			}
			else if (head[58] == 2)
			{
				osd_printf_info("This cart supports external NVRAM using SaveKey.\n");
				osd_printf_info("This is not supported in MAME currently.\n");
			}

			if (head[63])
			{
				osd_printf_info("This cart requires XBoarD / XM expansion\n");
				osd_printf_info("Run it through the expansion to exploit this feature.\n");
			}

			internal_header_logging((UINT8 *)head, length());

			m_cart->rom_alloc(len, tag());
			fread(m_cart->get_rom_base(), len);

			if (m_type == A78_TYPE6)
				m_cart->ram_alloc(0x4000);
			if (m_type == A78_MEGACART || (m_type >= A78_VERSABOARD && m_type <= A78_VERSA_POK450))
				m_cart->ram_alloc(0x8000);
			if (m_type == A78_XB_BOARD || m_type == A78_XM_BOARD)
				m_cart->ram_alloc(0x20000);
			if (m_type == A78_HSC || m_type == A78_XM_BOARD)
			{
				m_cart->nvram_alloc(0x800);
				battery_load(m_cart->get_nvram_base(), 0x800, 0xff);
			}
		}

		//printf("Type: %s\n", a78_get_slot(m_type));
	}
	return IMAGE_INIT_PASS;
}
Example #29
0
int cartslot_image_device::load_cartridge(const rom_entry *romrgn, const rom_entry *roment, bool load)
{
	const char *region;
	const char *type;
	UINT32 flags;
	offs_t offset, size, read_length, pos = 0, len;
	UINT8 *ptr;
	UINT8 clear_val;
	int datawidth, littleendian, i, j;
	device_t *cpu;

	astring regiontag;
	device().siblingtag(regiontag, ROMREGION_GETTAG(romrgn));
	region = regiontag.cstr();
	offset = ROM_GETOFFSET(roment);
	size = ROM_GETLENGTH(roment);
	flags = ROM_GETFLAGS(roment);
	ptr = ((UINT8 *) device().machine().root_device().memregion(region)->base()) + offset;

	if (load)
	{
		if (software_entry() == NULL)
		{
			/* must this be full size */
			if (flags & ROM_FULLSIZE)
			{
				if (length() != size)
					return IMAGE_INIT_FAIL;
			}

			/* read the ROM */
			pos = read_length = fread(ptr, size);

			/* reset the ROM to the initial point. */
			/* eventually, we could add a flag to allow the ROM to continue instead of restarting whenever a new cart region is present */
			fseek(0, SEEK_SET);
		}
		else
		{
			/* must this be full size */
			if (flags & ROM_FULLSIZE)
			{
				if (get_software_region_length("rom") != size)
					return IMAGE_INIT_FAIL;
			}

			/* read the ROM */
			pos = read_length = get_software_region_length("rom");
			memcpy(ptr, get_software_region("rom"), read_length);
		}

		/* do we need to mirror the ROM? */
		if (flags & ROM_MIRROR)
		{
			while(pos < size)
			{
				len = MIN(read_length, size - pos);
				memcpy(ptr + pos, ptr, len);
				pos += len;
			}
		}

		/* postprocess this region */
		type = regiontag.cstr();
		littleendian = ROMREGION_ISLITTLEENDIAN(romrgn);
		datawidth = ROMREGION_GETWIDTH(romrgn) / 8;

		/* if the region is inverted, do that now */
		device_memory_interface *memory;
		cpu = device().machine().device(type);
		if (cpu!=NULL && cpu->interface(memory))
		{
			datawidth = cpu->memory().space_config(AS_PROGRAM)->m_databus_width / 8;
			littleendian = (cpu->memory().space_config()->m_endianness == ENDIANNESS_LITTLE);
		}

		/* swap the endianness if we need to */
#ifdef LSB_FIRST
		if (datawidth > 1 && !littleendian)
#else
		if (datawidth > 1 && littleendian)
#endif
		{
			for (i = 0; i < size; i += datawidth)
			{
				UINT8 temp[8];
				memcpy(temp, &ptr[i], datawidth);
				for (j = datawidth - 1; j >= 0; j--)
					ptr[i + j] = temp[datawidth - 1 - j];
			}
		}
	}

	/* clear out anything that remains */
	if (!(flags & ROM_NOCLEAR))
	{
		clear_val = (flags & ROM_FILL_FF) ? 0xFF : 0x00;
		memset(ptr + pos, clear_val, size - pos);
	}
	return IMAGE_INIT_PASS;
}
Example #30
0
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;
}