summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2022-03-31 15:21:08 -0400
committer AJR <ajrhacker@users.noreply.github.com>2022-03-31 15:21:14 -0400
commit51586b043c35f9af82810254a75da5a6b7fbc949 (patch)
treed8613de7f2ffdafaaab4fbe5fa715162282b8eb1
parentf5d61ddcbe778ad5444fb57524d49325c2a862f8 (diff)
homelab.cpp, ssem.cpp, machine/z80bin.cpp: Eliminate use of fgetc in quickload processing
-rw-r--r--src/mame/drivers/homelab.cpp7
-rw-r--r--src/mame/drivers/ssem.cpp22
-rw-r--r--src/mame/machine/z80bin.cpp19
3 files changed, 26 insertions, 22 deletions
diff --git a/src/mame/drivers/homelab.cpp b/src/mame/drivers/homelab.cpp
index 4bf40d3af27..63eba19be6d 100644
--- a/src/mame/drivers/homelab.cpp
+++ b/src/mame/drivers/homelab.cpp
@@ -684,15 +684,16 @@ QUICKLOAD_LOAD_MEMBER(homelab_state::quickload_cb)
u16 args[2];
image.fseek(0x100, SEEK_SET);
- u8 ch = image.fgetc();
- if (ch != 0xA5)
+ u8 ch = 0;
+ u32 bytes = image.fread(&ch, 1);
+ if (bytes != 1 || ch != 0xA5)
{
image.seterror(image_error::INVALIDIMAGE, "Invalid header");
image.message(" Invalid header");
return image_init_result::FAIL;
}
- while((ch = image.fgetc()))
+ while ((bytes = image.fread(&ch, 1)) != 0 && ch != 0)
{
if (i >= (std::size(pgmname) - 1))
{
diff --git a/src/mame/drivers/ssem.cpp b/src/mame/drivers/ssem.cpp
index cf8e9abd94d..9032d312c0a 100644
--- a/src/mame/drivers/ssem.cpp
+++ b/src/mame/drivers/ssem.cpp
@@ -12,6 +12,7 @@
#include "emupal.h"
#include "screen.h"
#include "softlist_dev.h"
+#include <sstream>
class ssem_state : public driver_device
@@ -35,7 +36,7 @@ private:
uint32_t screen_update_ssem(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
DECLARE_QUICKLOAD_LOAD_MEMBER(quickload_cb);
inline uint32_t reverse(uint32_t v);
- std::string read_line(device_image_interface *image);
+ std::string read_line(device_image_interface &image);
void ssem_map(address_map &map);
@@ -516,25 +517,26 @@ uint32_t ssem_state::screen_update_ssem(screen_device &screen, bitmap_rgb32 &bit
* Image helper functions *
\****************************************************/
-std::string ssem_state::read_line(device_image_interface *image)
+std::string ssem_state::read_line(device_image_interface &image)
{
- std::string holder;
+ std::ostringstream stream;
for (u8 i = 0; i < 100; i++)
{
- char c = image->fgetc();
+ char c = 0;
+ if (image.fread(&c, 1) != 1)
+ break;
// convert opcode to lower case
if (c >= 'A' && c <= 'Z')
c += 32;
if (c >= 32)
- holder.push_back(c);
+ stream << c;
else
{
- c = image->fgetc(); // skip LF
+ image.fread(&c, 1); // skip LF
break;
}
}
- holder.push_back(0);
- return holder;
+ return std::move(stream).str();
}
@@ -548,7 +550,7 @@ QUICKLOAD_LOAD_MEMBER(ssem_state::quickload_cb)
std::string buffer;
u32 num_lines = 0;
- std::string image_line = read_line(&image);
+ std::string image_line = read_line(image);
if (image_line.empty())
{
image.message("No data in line 1");
@@ -566,7 +568,7 @@ QUICKLOAD_LOAD_MEMBER(ssem_state::quickload_cb)
for (u32 i = 0; i < num_lines; i++)
{
u32 line = 0, word = 0;
- image_line = read_line(&image);
+ image_line = read_line(image);
u32 length = image_line.length();
if (length < 9)
diff --git a/src/mame/machine/z80bin.cpp b/src/mame/machine/z80bin.cpp
index 98489ca31a5..ac6c2290e12 100644
--- a/src/mame/machine/z80bin.cpp
+++ b/src/mame/machine/z80bin.cpp
@@ -10,7 +10,6 @@
image_init_result z80bin_load_file(device_image_interface &image, address_space &space, uint16_t &exec_addr, uint16_t &start_addr, uint16_t &end_addr)
{
- int ch = 0;
uint16_t args[3]{};
uint16_t i = 0U, j = 0U, size = 0U;
uint8_t data = 0U;
@@ -19,15 +18,10 @@ image_init_result z80bin_load_file(device_image_interface &image, address_space
image.fseek(7, SEEK_SET);
- while((ch = image.fgetc()) != 0x1A)
+ char ch = '\0';
+ uint32_t bytes = 0;
+ while ((bytes = image.fread(&ch, 1)) != 0 && ch != 0x1A)
{
- if (ch == EOF)
- {
- image.seterror(image_error::INVALIDIMAGE, "Unexpected EOF while getting file name");
- image.message(" Unexpected EOF while getting file name");
- return image_init_result::FAIL;
- }
-
if (ch != '\0')
{
if (i >= (std::size(pgmname) - 1))
@@ -42,6 +36,13 @@ image_init_result z80bin_load_file(device_image_interface &image, address_space
}
}
+ if (bytes == 0)
+ {
+ image.seterror(image_error::INVALIDIMAGE, "Unexpected EOF while getting file name");
+ image.message(" Unexpected EOF while getting file name");
+ return image_init_result::FAIL;
+ }
+
pgmname[i] = '\0'; /* terminate string with a null */
if (image.fread(args, sizeof(args)) != sizeof(args))