Skip to content

Commit

Permalink
misc: Added proper error messages to COM quickload (MT 08915) [Robbbert]
Browse files Browse the repository at this point in the history
  • Loading branch information
happppp committed Sep 18, 2024
1 parent 8f39f07 commit 9a593dd
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 89 deletions.
35 changes: 18 additions & 17 deletions src/mame/altos/altos5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,37 +302,38 @@ void altos5_state::port09_w(uint8_t data)

QUICKLOAD_LOAD_MEMBER(altos5_state::quickload_cb)
{
address_space& prog_space = m_maincpu->space(AS_PROGRAM);

if (image.length() >= 0xfd00)
return std::make_pair(image_error::INVALIDLENGTH, std::string());

setup_banks(2);

/* Avoid loading a program if CP/M-80 is not in memory */
address_space& prog_space = m_maincpu->space(AS_PROGRAM);

// Avoid loading a program if CP/M-80 is not in memory
if ((prog_space.read_byte(0) != 0xc3) || (prog_space.read_byte(5) != 0xc3))
{
machine_reset();
return std::make_pair(image_error::UNSUPPORTED, std::string());
return std::make_pair(image_error::UNSUPPORTED, "CP/M must already be running");
}

/* Load image to the TPA (Transient Program Area) */
const int mem_avail = 256 * prog_space.read_byte(7) + prog_space.read_byte(6) - 512;
if (mem_avail < image.length())
return std::make_pair(image_error::UNSPECIFIED, "Insufficient memory available");

// Load image to the TPA (Transient Program Area)
uint16_t quickload_size = image.length();
for (uint16_t i = 0; i < quickload_size; i++)
{
uint8_t data;

if (image.fread( &data, 1) != 1)
return std::make_pair(image_error::UNSPECIFIED, std::string());
prog_space.write_byte(i+0x100, data);
if (image.fread(&data, 1) != 1)
return std::make_pair(image_error::BADSOFTWARE, "Problem reading the image at offset " + std::to_string(i));
prog_space.write_byte(i + 0x100, data);
}

/* clear out command tail */
prog_space.write_byte(0x80, 0); prog_space.write_byte(0x81, 0);
// clear out command tail
prog_space.write_byte(0x80, 0);
prog_space.write_byte(0x81, 0);

/* Roughly set SP basing on the BDOS position */
m_maincpu->set_state_int(Z80_SP, 256 * prog_space.read_byte(7) - 300);
m_maincpu->set_pc(0x100); // start program
// Roughly set SP basing on the BDOS position
m_maincpu->set_state_int(Z80_SP, mem_avail + 384);
m_maincpu->set_pc(0x100); // start program

return std::make_pair(std::error_condition(), std::string());
}
Expand Down
40 changes: 21 additions & 19 deletions src/mame/ausnz/aussiebyte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,40 +398,42 @@ static void aussiebyte_floppies(device_slot_interface &device)

QUICKLOAD_LOAD_MEMBER(aussiebyte_state::quickload_cb)
{
address_space& prog_space = m_maincpu->space(AS_PROGRAM);

if (image.length() >= 0xfd00)
return std::make_pair(image_error::INVALIDLENGTH, std::string());

/* RAM must be banked in */
m_port15 = true; // disable boot rom
// RAM must be banked in
m_port15 = true; // disable boot rom
m_port1a = 4;
m_bankr0->set_entry(m_port1a); /* enable correct program bank */
m_bankr0->set_entry(m_port1a); // enable correct program bank
m_bankw0->set_entry(m_port1a);

/* Avoid loading a program if CP/M-80 is not in memory */
address_space& prog_space = m_maincpu->space(AS_PROGRAM);

// Avoid loading a program if CP/M-80 is not in memory
if ((prog_space.read_byte(0) != 0xc3) || (prog_space.read_byte(5) != 0xc3))
{
machine_reset();
return std::make_pair(image_error::UNSUPPORTED, std::string());
return std::make_pair(image_error::UNSUPPORTED, "CP/M must already be running");
}

/* Load image to the TPA (Transient Program Area) */
const int mem_avail = 256 * prog_space.read_byte(7) + prog_space.read_byte(6) - 512;
if (mem_avail < image.length())
return std::make_pair(image_error::UNSPECIFIED, "Insufficient memory available");

// Load image to the TPA (Transient Program Area)
u16 quickload_size = image.length();
for (u16 i = 0; i < quickload_size; i++)
{
u8 data;
if (image.fread( &data, 1) != 1)
return std::make_pair(image_error::UNSPECIFIED, std::string());
prog_space.write_byte(i+0x100, data);
if (image.fread(&data, 1) != 1)
return std::make_pair(image_error::BADSOFTWARE, "Problem reading the image at offset " + std::to_string(i));
prog_space.write_byte(i + 0x100, data);
}

/* clear out command tail */
prog_space.write_byte(0x80, 0); prog_space.write_byte(0x81, 0);
// clear out command tail
prog_space.write_byte(0x80, 0);
prog_space.write_byte(0x81, 0);

/* Roughly set SP basing on the BDOS position */
m_maincpu->set_state_int(Z80_SP, 256 * prog_space.read_byte(7) - 0x400);
m_maincpu->set_pc(0x100); // start program
// Roughly set SP basing on the BDOS position
m_maincpu->set_state_int(Z80_SP, mem_avail + 384);
m_maincpu->set_pc(0x100); // start program

return std::make_pair(std::error_condition(), std::string());
}
Expand Down
24 changes: 14 additions & 10 deletions src/mame/kaypro/kaypro_m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,27 +300,31 @@ QUICKLOAD_LOAD_MEMBER(kaypro_state::quickload_cb)

address_space& prog_space = m_maincpu->space(AS_PROGRAM);

/* Avoid loading a program if CP/M-80 is not in memory */
// Avoid loading a program if CP/M-80 is not in memory
if ((prog_space.read_byte(0) != 0xc3) || (prog_space.read_byte(5) != 0xc3))
return std::make_pair(image_error::UNSUPPORTED, std::string());
return std::make_pair(image_error::UNSUPPORTED, "CP/M must already be running");

if (image.length() >= 0xfd00)
return std::make_pair(image_error::INVALIDLENGTH, std::string());
// Check for sufficient RAM based on position of CPM
const int mem_avail = 256 * prog_space.read_byte(7) + prog_space.read_byte(6) - 512;
if (mem_avail < image.length())
return std::make_pair(image_error::UNSPECIFIED, "Insufficient memory available");

/* Load image to the TPA (Transient Program Area) */
// Load image to the TPA (Transient Program Area)
u16 quickload_size = image.length();
for (u16 i = 0; i < quickload_size; i++)
{
u8 data;
if (image.fread(&data, 1) != 1)
return std::make_pair(image_error::UNSPECIFIED, std::string());
prog_space.write_byte(i+0x100, data);
return std::make_pair(image_error::BADSOFTWARE, "Problem reading the image at offset " + std::to_string(i));
prog_space.write_byte(i + 0x100, data);
}

prog_space.write_byte(0x80, 0); prog_space.write_byte(0x81, 0); // clear out command tail
// clear out command tail
prog_space.write_byte(0x80, 0);
prog_space.write_byte(0x81, 0);

m_maincpu->set_pc(0x100); // start program
m_maincpu->set_state_int(Z80_SP, 256 * prog_space.read_byte(7) - 300); // put the stack a bit before BDOS
m_maincpu->set_state_int(Z80_SP, mem_avail + 384); // put the stack a bit before BDOS
m_maincpu->set_pc(0x100); // start program

return std::make_pair(std::error_condition(), std::string());
}
23 changes: 12 additions & 11 deletions src/mame/ncr/dmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,27 +402,28 @@ UPD7220_DRAW_TEXT_LINE_MEMBER( dmv_state::hgdc_draw_text )

QUICKLOAD_LOAD_MEMBER(dmv_state::quickload_cb)
{
/* Avoid loading a program if CP/M-80 is not in memory */
// Avoid loading a program if CP/M-80 is not in memory
if ((m_ram->base()[0] != 0xc3) || (m_ram->base()[5] != 0xc3))
return std::make_pair(image_error::UNSUPPORTED, std::string());
return std::make_pair(image_error::UNSUPPORTED, "CP/M must already be running");

if (image.length() >= 0xfd00)
return std::make_pair(image_error::INVALIDLENGTH, std::string());
const int mem_avail = 256 * m_ram->base()[7] + m_ram->base()[6] - 512;
if (mem_avail < image.length())
return std::make_pair(image_error::UNSPECIFIED, "Insufficient memory available");

/* Load image to the TPA (Transient Program Area) */
// Load image to the TPA (Transient Program Area)
uint16_t quickload_size = image.length();
for (uint16_t i = 0; i < quickload_size; i++)
{
uint8_t data;
if (image.fread( &data, 1) != 1)
return std::make_pair(image_error::UNSPECIFIED, std::string());
m_ram->base()[i+0x100] = data;
if (image.fread(&data, 1) != 1)
return std::make_pair(image_error::BADSOFTWARE, "Problem reading the image at offset " + std::to_string(i));
m_ram->base()[i + 0x100] = data;
}

m_ram->base()[0x80] = m_ram->base()[0x81] = 0; // clear out command tail
m_ram->base()[0x80] = m_ram->base()[0x81] = 0; // clear out command tail

m_maincpu->set_pc(0x100); // start program
m_maincpu->set_state_int(Z80_SP, 256 * m_ram->base()[7] - 300); // put the stack a bit before BDOS
m_maincpu->set_state_int(Z80_SP, mem_avail + 384); // put the stack a bit before BDOS
m_maincpu->set_pc(0x100); // start program

return std::make_pair(std::error_condition(), std::string());
}
Expand Down
33 changes: 17 additions & 16 deletions src/mame/sony/smc777.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,34 +419,35 @@ QUICKLOAD_LOAD_MEMBER(smc777_state::quickload_cb)
{
address_space& prog_space = m_maincpu->space(AS_PROGRAM);

if (image.length() >= 0xfd00)
return std::make_pair(image_error::INVALIDLENGTH, std::string());

/* The right RAM bank must be active */

/* Avoid loading a program if CP/M-80 is not in memory */
// Avoid loading a program if CP/M-80 is not in memory
if ((prog_space.read_byte(0) != 0xc3) || (prog_space.read_byte(5) != 0xc3))
{
machine_reset();
return std::make_pair(image_error::UNSUPPORTED, std::string());
return std::make_pair(image_error::UNSUPPORTED, "CP/M must already be running");
}

/* Load image to the TPA (Transient Program Area) */
// Check for sufficient RAM based on position of CPM
const int mem_avail = 256 * prog_space.read_byte(7) + prog_space.read_byte(6) - 512;
if (mem_avail < image.length())
return std::make_pair(image_error::UNSPECIFIED, "Insufficient memory available");

// Load image to the TPA (Transient Program Area)
uint16_t quickload_size = image.length();
for (uint16_t i = 0; i < quickload_size; i++)
{
uint8_t data;
if (image.fread( &data, 1) != 1)
return std::make_pair(image_error::UNSPECIFIED, std::string());
prog_space.write_byte(i+0x100, data);
if (image.fread(&data, 1) != 1)
return std::make_pair(image_error::BADSOFTWARE, "Problem reading the image at offset " + std::to_string(i));
prog_space.write_byte(i + 0x100, data);
}

/* clear out command tail */
prog_space.write_byte(0x80, 0); prog_space.write_byte(0x81, 0);
// clear out command tail */
prog_space.write_byte(0x80, 0);
prog_space.write_byte(0x81, 0);

/* Roughly set SP basing on the BDOS position */
m_maincpu->set_state_int(Z80_SP, 256 * prog_space.read_byte(7) - 300);
m_maincpu->set_pc(0x100); // start program
// Roughly set SP basing on the BDOS position
m_maincpu->set_state_int(Z80_SP, mem_avail + 384);
m_maincpu->set_pc(0x100); // start program

return std::make_pair(std::error_condition(), std::string());
}
Expand Down
2 changes: 1 addition & 1 deletion src/mame/trs/coco3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void coco3_state::coco3(machine_config &config)

// monitor
SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
m_screen->set_raw(28.636363_MHz_XTAL/2, 912, 0, 640, 262, 1, 241-1);
m_screen->set_raw(28.636363_MHz_XTAL/2, 912, 0, 640, 262, 1, 240);
m_screen->set_screen_update(FUNC(coco3_state::screen_update));

// internal ram
Expand Down
32 changes: 17 additions & 15 deletions src/mame/xerox/xerox820.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,36 +380,38 @@ static const z80_daisy_config xerox820_daisy_chain[] =

QUICKLOAD_LOAD_MEMBER(xerox820_state::quickload_cb)
{
if (image.length() >= 0xfd00)
return std::make_pair(image_error::INVALIDLENGTH, std::string());
m_view.select(0);

address_space &prog_space = m_maincpu->space(AS_PROGRAM);

m_view.select(0);

/* Avoid loading a program if CP/M-80 is not in memory */
// Avoid loading a program if CP/M-80 is not in memory
if ((prog_space.read_byte(0) != 0xc3) || (prog_space.read_byte(5) != 0xc3))
{
machine_reset();
return std::make_pair(image_error::UNSUPPORTED, std::string());
return std::make_pair(image_error::UNSUPPORTED, "CP/M must already be running");
}

/* Load image to the TPA (Transient Program Area) */
const int mem_avail = 256 * prog_space.read_byte(7) + prog_space.read_byte(6) - 512;
if (mem_avail < image.length())
return std::make_pair(image_error::UNSPECIFIED, "Insufficient memory available");

// Load image to the TPA (Transient Program Area)
uint16_t quickload_size = image.length();
for (uint16_t i = 0; i < quickload_size; i++)
{
uint8_t data;
if (image.fread( &data, 1) != 1)
return std::make_pair(image_error::UNSPECIFIED, std::string());
prog_space.write_byte(i+0x100, data);
if (image.fread(&data, 1) != 1)
return std::make_pair(image_error::BADSOFTWARE, "Problem reading the image at offset " + std::to_string(i));
prog_space.write_byte(i + 0x100, data);
}

/* clear out command tail */
prog_space.write_byte(0x80, 0); prog_space.write_byte(0x81, 0);
// clear out command tail */
prog_space.write_byte(0x80, 0);
prog_space.write_byte(0x81, 0);

/* Roughly set SP basing on the BDOS position */
m_maincpu->set_state_int(Z80_SP, 256 * prog_space.read_byte(7) - 300);
m_maincpu->set_pc(0x100); // start program
// Roughly set SP basing on the BDOS position
m_maincpu->set_state_int(Z80_SP, mem_avail + 384);
m_maincpu->set_pc(0x100); // start program

return std::make_pair(std::error_condition(), std::string());
}
Expand Down

0 comments on commit 9a593dd

Please sign in to comment.