Allow loadTape to return fail status

This commit is contained in:
folkert van heusden 2023-03-26 10:43:28 +02:00
parent afd187acc3
commit f9ff9b24ba
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
3 changed files with 19 additions and 9 deletions

View file

@ -137,12 +137,12 @@ void setBootLoader(bus *const b, const bootloader_t which)
c -> setRegister(7, start);
}
uint16_t loadTape(bus *const b, const std::string & file)
std::optional<uint16_t> loadTape(bus *const b, const std::string & file)
{
FILE *fh = fopen(file.c_str(), "rb");
if (!fh) {
DOLOG(ll_error, true, "Cannot open %s", file.c_str());
return -1;
return { };
}
uint16_t start = 0, end = 0;
@ -154,12 +154,15 @@ uint16_t loadTape(bus *const b, const std::string & file)
break;
int count = (buffer[3] << 8) | buffer[2];
int p = (buffer[5] << 8) | buffer[4];
int p = (buffer[5] << 8) | buffer[4];
uint8_t csum = 0;
for(int i=2; i<6; i++)
csum += buffer[i];
if (count == 0 || p == 1)
break;
if (count == 6) { // eg no data
if (p != 1) {
DOLOG(info, true, "Setting start address to %o", p);

View file

@ -1,3 +1,4 @@
#include <optional>
#include <stdint.h>
#include <string>
@ -6,7 +7,7 @@
typedef enum { BL_NONE, BL_RK05, BL_RL02 } bootloader_t;
void loadbin(bus *const b, uint16_t base, const char *const file);
void setBootLoader(bus *const b, const bootloader_t which);
uint16_t loadTape(bus *const b, const std::string & file);
void load_p11_x11(bus *const b, const std::string & file);
void loadbin(bus *const b, uint16_t base, const char *const file);
void setBootLoader(bus *const b, const bootloader_t which);
std::optional<uint16_t> loadTape(bus *const b, const std::string & file);
void load_p11_x11(bus *const b, const std::string & file);

View file

@ -206,8 +206,14 @@ int main(int argc, char *argv[])
std::atomic_bool interrupt_emulation { false };
if (tape.empty() == false)
c->setRegister(7, loadTape(b, tape));
if (tape.empty() == false) {
auto addr = loadTape(b, tape);
if (addr.has_value() == false)
return 1; // fail
c->setRegister(7, addr.value());
}
if (sa_set)
c->setRegister(7, start_addr);