Allow loadTape to return fail status
This commit is contained in:
parent
afd187acc3
commit
f9ff9b24ba
3 changed files with 19 additions and 9 deletions
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
10
main.cpp
10
main.cpp
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue