small cleanup (nw)

This commit is contained in:
Miodrag Milanovic 2013-03-04 15:09:43 +00:00
parent 2391fb9d68
commit 71a8c57c34
3 changed files with 87 additions and 97 deletions

View File

@ -234,10 +234,10 @@ struct st2_header
***************************************************************************/ ***************************************************************************/
/*------------------------------------------------- /*-------------------------------------------------
DEVICE_IMAGE_LOAD( st2_cartslot_load ) DEVICE_IMAGE_LOAD_MEMBER( studio2_state, st2_cartslot_load )
-------------------------------------------------*/ -------------------------------------------------*/
DEVICE_IMAGE_LOAD_LEGACY( st2_cartslot_load ) DEVICE_IMAGE_LOAD_MEMBER( studio2_state, st2_cartslot_load )
{ {
st2_header header; st2_header header;
@ -512,7 +512,7 @@ void mpt02_state::machine_reset()
DEVICE_IMAGE_LOAD_MEMBER( studio2_state, studio2_cart_load ) DEVICE_IMAGE_LOAD_MEMBER( studio2_state, studio2_cart_load )
{ {
if (image.software_entry() == NULL) if (image.software_entry() == NULL)
return device_load_st2_cartslot_load(image); return DEVICE_IMAGE_LOAD_MEMBER_NAME(st2_cartslot_load)(image);
else else
{ {
// WARNING: list code currently assume that cart mapping starts at 0x400. // WARNING: list code currently assume that cart mapping starts at 0x400.

View File

@ -174,98 +174,6 @@ struct timex_cart_t
static timex_cart_t timex_cart; static timex_cart_t timex_cart;
DEVICE_IMAGE_LOAD_LEGACY( timex_cart )
{
int file_size;
UINT8 * file_data;
int chunks_in_file = 0;
int i;
logerror ("Trying to load cart\n");
file_size = image.length();
if (file_size < 0x09)
{
logerror ("Bad file size\n");
return IMAGE_INIT_FAIL;
}
file_data = (UINT8 *)malloc(file_size);
if (file_data == NULL)
{
logerror ("Memory allocating error\n");
return IMAGE_INIT_FAIL;
}
image.fread(file_data, file_size);
for (i=0; i<8; i++)
if(file_data[i+1]&0x02) chunks_in_file++;
if (chunks_in_file*0x2000+0x09 != file_size)
{
free (file_data);
logerror ("File corrupted\n");
return IMAGE_INIT_FAIL;
}
switch (file_data[0x00])
{
case 0x00: logerror ("DOCK cart\n");
timex_cart.type = TIMEX_CART_DOCK;
timex_cart.data = (UINT8*) malloc (0x10000);
if (!timex_cart.data)
{
free (file_data);
logerror ("Memory allocate error\n");
return IMAGE_INIT_FAIL;
}
chunks_in_file = 0;
for (i=0; i<8; i++)
{
timex_cart.chunks = timex_cart.chunks | ((file_data[i+1]&0x01)<<i);
if (file_data[i+1]&0x02)
{
memcpy (timex_cart.data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000);
chunks_in_file++;
}
else
{
if (file_data[i+1]&0x01)
memset (timex_cart.data+i*0x2000, 0x00, 0x2000);
else
memset (timex_cart.data+i*0x2000, 0xff, 0x2000);
}
}
free (file_data);
break;
default: logerror ("Cart type not supported\n");
free (file_data);
timex_cart.type = TIMEX_CART_NONE;
return IMAGE_INIT_FAIL;
}
logerror ("Cart loaded\n");
logerror ("Chunks %02x\n", timex_cart.chunks);
return IMAGE_INIT_PASS;
}
DEVICE_IMAGE_UNLOAD_LEGACY( timex_cart )
{
if (timex_cart.data)
{
free (timex_cart.data);
timex_cart.data = NULL;
}
timex_cart.type = TIMEX_CART_NONE;
timex_cart.chunks = 0x00;
}
const timex_cart_t *timex_cart_data(void) const timex_cart_t *timex_cart_data(void)
{ {
return &timex_cart; return &timex_cart;
@ -712,13 +620,94 @@ MACHINE_RESET_MEMBER(spectrum_state,tc2048)
DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart ) DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart )
{ {
return device_load_timex_cart( image ); int file_size;
UINT8 * file_data;
int chunks_in_file = 0;
int i;
logerror ("Trying to load cart\n");
file_size = image.length();
if (file_size < 0x09)
{
logerror ("Bad file size\n");
return IMAGE_INIT_FAIL;
}
file_data = (UINT8 *)malloc(file_size);
if (file_data == NULL)
{
logerror ("Memory allocating error\n");
return IMAGE_INIT_FAIL;
}
image.fread(file_data, file_size);
for (i=0; i<8; i++)
if(file_data[i+1]&0x02) chunks_in_file++;
if (chunks_in_file*0x2000+0x09 != file_size)
{
free (file_data);
logerror ("File corrupted\n");
return IMAGE_INIT_FAIL;
}
switch (file_data[0x00])
{
case 0x00: logerror ("DOCK cart\n");
timex_cart.type = TIMEX_CART_DOCK;
timex_cart.data = (UINT8*) malloc (0x10000);
if (!timex_cart.data)
{
free (file_data);
logerror ("Memory allocate error\n");
return IMAGE_INIT_FAIL;
}
chunks_in_file = 0;
for (i=0; i<8; i++)
{
timex_cart.chunks = timex_cart.chunks | ((file_data[i+1]&0x01)<<i);
if (file_data[i+1]&0x02)
{
memcpy (timex_cart.data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000);
chunks_in_file++;
}
else
{
if (file_data[i+1]&0x01)
memset (timex_cart.data+i*0x2000, 0x00, 0x2000);
else
memset (timex_cart.data+i*0x2000, 0xff, 0x2000);
}
}
free (file_data);
break;
default: logerror ("Cart type not supported\n");
free (file_data);
timex_cart.type = TIMEX_CART_NONE;
return IMAGE_INIT_FAIL;
}
logerror ("Cart loaded\n");
logerror ("Chunks %02x\n", timex_cart.chunks);
return IMAGE_INIT_PASS;
} }
DEVICE_IMAGE_UNLOAD_MEMBER( spectrum_state, timex_cart ) DEVICE_IMAGE_UNLOAD_MEMBER( spectrum_state, timex_cart )
{ {
device_unload_timex_cart( image ); if (timex_cart.data)
{
free (timex_cart.data);
timex_cart.data = NULL;
}
timex_cart.type = TIMEX_CART_NONE;
timex_cart.chunks = 0x00;
} }

View File

@ -50,6 +50,7 @@ public:
DECLARE_READ_LINE_MEMBER( ef4_r ); DECLARE_READ_LINE_MEMBER( ef4_r );
DECLARE_WRITE_LINE_MEMBER( q_w ); DECLARE_WRITE_LINE_MEMBER( q_w );
DECLARE_INPUT_CHANGED_MEMBER( reset_w ); DECLARE_INPUT_CHANGED_MEMBER( reset_w );
DECLARE_DEVICE_IMAGE_LOAD_MEMBER( st2_cartslot_load );
DECLARE_DEVICE_IMAGE_LOAD_MEMBER( studio2_cart_load ); DECLARE_DEVICE_IMAGE_LOAD_MEMBER( studio2_cart_load );
/* keyboard state */ /* keyboard state */