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); 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"); FILE *fh = fopen(file.c_str(), "rb");
if (!fh) { if (!fh) {
DOLOG(ll_error, true, "Cannot open %s", file.c_str()); DOLOG(ll_error, true, "Cannot open %s", file.c_str());
return -1; return { };
} }
uint16_t start = 0, end = 0; uint16_t start = 0, end = 0;
@ -160,6 +160,9 @@ uint16_t loadTape(bus *const b, const std::string & file)
for(int i=2; i<6; i++) for(int i=2; i<6; i++)
csum += buffer[i]; csum += buffer[i];
if (count == 0 || p == 1)
break;
if (count == 6) { // eg no data if (count == 6) { // eg no data
if (p != 1) { if (p != 1) {
DOLOG(info, true, "Setting start address to %o", p); DOLOG(info, true, "Setting start address to %o", p);

View file

@ -1,3 +1,4 @@
#include <optional>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
@ -8,5 +9,5 @@ typedef enum { BL_NONE, BL_RK05, BL_RL02 } bootloader_t;
void loadbin(bus *const b, uint16_t base, const char *const file); void loadbin(bus *const b, uint16_t base, const char *const file);
void setBootLoader(bus *const b, const bootloader_t which); void setBootLoader(bus *const b, const bootloader_t which);
uint16_t loadTape(bus *const b, const std::string & file); std::optional<uint16_t> loadTape(bus *const b, const std::string & file);
void load_p11_x11(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 }; std::atomic_bool interrupt_emulation { false };
if (tape.empty() == false) if (tape.empty() == false) {
c->setRegister(7, loadTape(b, tape)); auto addr = loadTape(b, tape);
if (addr.has_value() == false)
return 1; // fail
c->setRegister(7, addr.value());
}
if (sa_set) if (sa_set)
c->setRegister(7, start_addr); c->setRegister(7, start_addr);