(MESS) Homelab, vc4000, d6800: fixed memory leak

This commit is contained in:
Robbbert 2013-04-28 04:29:12 +00:00
parent 7a87b2b361
commit df1bd363d8
3 changed files with 115 additions and 94 deletions

View File

@ -338,11 +338,12 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 )
{ {
address_space &space = m_maincpu->space(AS_PROGRAM); address_space &space = m_maincpu->space(AS_PROGRAM);
int i; int i;
int quick_addr = 0x0200; int quick_addr = 0x200;
int exec_addr = 0xc000; int exec_addr = 0xc000;
int quick_length; int quick_length;
UINT8 *quick_data; UINT8 *quick_data;
int read_; int read_;
int result = IMAGE_INIT_FAIL;
quick_length = image.length(); quick_length = image.length();
quick_data = (UINT8*)malloc(quick_length); quick_data = (UINT8*)malloc(quick_length);
@ -350,27 +351,34 @@ QUICKLOAD_LOAD_MEMBER( d6800_state, d6800 )
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
image.message(" Cannot open file"); image.message(" Cannot open file");
return IMAGE_INIT_FAIL;
} }
else
read_ = image.fread( quick_data, quick_length);
if (read_ != quick_length)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); read_ = image.fread( quick_data, quick_length);
image.message(" Cannot read the file"); if (read_ != quick_length)
return IMAGE_INIT_FAIL; {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
image.message(" Cannot read the file");
}
else
{
for (i = 0; i < quick_length; i++)
if ((quick_addr + i) < 0x800)
space.write_byte(i + quick_addr, quick_data[i]);
/* display a message about the loaded quickload */
image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length,quick_addr,quick_addr+quick_length,exec_addr);
// Start the quickload
m_maincpu->set_pc(exec_addr);
result = IMAGE_INIT_PASS;
}
free( quick_data );
} }
for (i = 0; i < quick_length; i++) return result;
if ((quick_addr + i) < 0x800)
space.write_byte(i + quick_addr, quick_data[i]);
/* display a message about the loaded quickload */
image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length,quick_addr,quick_addr+quick_length,exec_addr);
// Start the quickload
m_maincpu->set_pc(exec_addr);
return IMAGE_INIT_PASS;
} }
static MACHINE_CONFIG_START( d6800, d6800_state ) static MACHINE_CONFIG_START( d6800, d6800_state )

View File

@ -10,6 +10,7 @@
ToDO: ToDO:
- HTP files should be a cassette format, not a quickload. - HTP files should be a cassette format, not a quickload.
- Quickloads cause the emulated machine to hang or reboot.
- homelab2 - cassette to fix. - homelab2 - cassette to fix.
Note that rom code 0x40-48 is meaningless garbage, Note that rom code 0x40-48 is meaningless garbage,
had to patch to stop it crashing. Need a new dump. had to patch to stop it crashing. Need a new dump.
@ -661,6 +662,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
image.message(" Cannot open file"); image.message(" Cannot open file");
free(quick_data);
return IMAGE_INIT_FAIL; return IMAGE_INIT_FAIL;
} }
@ -669,6 +671,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
image.message(" Cannot read the file"); image.message(" Cannot read the file");
free(quick_data);
return IMAGE_INIT_FAIL; return IMAGE_INIT_FAIL;
} }
@ -678,6 +681,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
image.message(" Invalid header"); image.message(" Invalid header");
free(quick_data);
return IMAGE_INIT_FAIL; return IMAGE_INIT_FAIL;
} }
@ -687,6 +691,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File name too long"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File name too long");
image.message(" File name too long"); image.message(" File name too long");
free(quick_data);
return IMAGE_INIT_FAIL; return IMAGE_INIT_FAIL;
} }
@ -700,6 +705,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Unexpected EOF while getting file size"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Unexpected EOF while getting file size");
image.message(" Unexpected EOF while getting file size"); image.message(" Unexpected EOF while getting file size");
free(quick_data);
return IMAGE_INIT_FAIL; return IMAGE_INIT_FAIL;
} }
@ -711,6 +717,7 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too large"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too large");
image.message(" File too large"); image.message(" File too large");
free(quick_data);
return IMAGE_INIT_FAIL; return IMAGE_INIT_FAIL;
} }
@ -726,11 +733,13 @@ QUICKLOAD_LOAD_MEMBER( homelab_state,homelab)
snprintf(message, ARRAY_LENGTH(message), "%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j); snprintf(message, ARRAY_LENGTH(message), "%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j);
image.seterror(IMAGE_ERROR_INVALIDIMAGE, message); image.seterror(IMAGE_ERROR_INVALIDIMAGE, message);
image.message("%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j); image.message("%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j);
free(quick_data);
return IMAGE_INIT_FAIL; return IMAGE_INIT_FAIL;
} }
space.write_byte(j, ch); space.write_byte(j, ch);
} }
free(quick_data);
return IMAGE_INIT_PASS; return IMAGE_INIT_PASS;
} }

View File

@ -533,6 +533,7 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
int quick_length; int quick_length;
UINT8 *quick_data; UINT8 *quick_data;
int read_; int read_;
int result = IMAGE_INIT_FAIL;
quick_length = image.length(); quick_length = image.length();
quick_data = (UINT8*)malloc(quick_length); quick_data = (UINT8*)malloc(quick_length);
@ -540,90 +541,93 @@ QUICKLOAD_LOAD_MEMBER( vc4000_state,vc4000)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
image.message(" Cannot open file"); image.message(" Cannot open file");
return IMAGE_INIT_FAIL;
}
read_ = image.fread( quick_data, quick_length);
if (read_ != quick_length)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
image.message(" Cannot read the file");
return IMAGE_INIT_FAIL;
}
if (mame_stricmp(image.filetype(), "tvc")==0)
{
if (quick_data[0] != 2)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
image.message(" Invalid header");
return IMAGE_INIT_FAIL;
}
quick_addr = quick_data[1] * 256 + quick_data[2];
exec_addr = quick_data[3] * 256 + quick_data[4];
space.write_byte(0x08be, quick_data[3]);
space.write_byte(0x08bf, quick_data[4]);
for (i = 0; i < quick_length - 5; i++)
if ((quick_addr + i) < 0x1600)
space.write_byte(i + quick_addr, quick_data[i+5]);
/* display a message about the loaded quickload */
image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length-5,quick_addr,quick_addr+quick_length-5,exec_addr);
// Start the quickload
m_maincpu->set_pc(exec_addr);
return IMAGE_INIT_PASS;
} }
else else
if (mame_stricmp(image.filetype(), "pgm")==0)
{ {
if (quick_data[0] != 0) read_ = image.fread( quick_data, quick_length);
if (read_ != quick_length)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
image.message(" Invalid header"); image.message(" Cannot read the file");
return IMAGE_INIT_FAIL;
} }
else
exec_addr = quick_data[1] * 256 + quick_data[2];
if (exec_addr >= quick_length)
{ {
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); if (mame_stricmp(image.filetype(), "tvc")==0)
image.message(" Exec address beyond end of file"); {
return IMAGE_INIT_FAIL; if (quick_data[0] != 2)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
image.message(" Invalid header");
}
else
{
quick_addr = quick_data[1] * 256 + quick_data[2];
exec_addr = quick_data[3] * 256 + quick_data[4];
space.write_byte(0x08be, quick_data[3]);
space.write_byte(0x08bf, quick_data[4]);
for (i = 0; i < quick_length - 5; i++)
if ((quick_addr + i) < 0x1600)
space.write_byte(i + quick_addr, quick_data[i+5]);
/* display a message about the loaded quickload */
image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length-5,quick_addr,quick_addr+quick_length-5,exec_addr);
// Start the quickload
m_maincpu->set_pc(exec_addr);
result = IMAGE_INIT_PASS;
}
}
else
if (mame_stricmp(image.filetype(), "pgm")==0)
{
if (quick_data[0] != 0)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
image.message(" Invalid header");
}
else
{
exec_addr = quick_data[1] * 256 + quick_data[2];
if (exec_addr >= quick_length)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
image.message(" Exec address beyond end of file");
}
else
if (quick_length < 0x904)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
image.message(" File too short");
}
else
// some programs store data in PVI memory and other random places. This is not supported.
if (quick_length > 0x1600)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
image.message(" File too long");
}
else
{
for (i = quick_addr; i < quick_length; i++)
if (i < 0x1600)
space.write_byte(i, quick_data[i]);
/* display a message about the loaded quickload */
image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
// Start the quickload
m_maincpu->set_pc(exec_addr);
result = IMAGE_INIT_PASS;
}
}
}
} }
free (quick_data);
if (quick_length < 0x904)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
image.message(" File too short");
return IMAGE_INIT_FAIL;
}
// some programs store data in PVI memory and other random places. This is not supported.
if (quick_length > 0x1600)
{
image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
image.message(" File too long");
return IMAGE_INIT_FAIL;
}
for (i = quick_addr; i < quick_length; i++)
if (i < 0x1600)
space.write_byte(i, quick_data[i]);
/* display a message about the loaded quickload */
image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
// Start the quickload
m_maincpu->set_pc(exec_addr);
return IMAGE_INIT_PASS;
} }
else return result;
return IMAGE_INIT_FAIL;
} }