Skip to content

Commit

Permalink
Converting loadsave to use C++-style string management and filesystem…
Browse files Browse the repository at this point in the history
… paths.
  • Loading branch information
indigodarkwolf committed Jul 19, 2024
1 parent 8788a8a commit 354514c
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ void LOAD()
RAM[STATUS] = 0;
state6502.a = 0;
} else {
char filename[PATH_MAX];
const int len = MIN(RAM[FNLEN], PATH_MAX - 1);
memcpy(filename, kernal_filename, len);
filename[len] = 0;

std::filesystem::path filepath = Options.fsroot_path / filename;
const int len = RAM[FNLEN];
const std::filesystem::path filename = std::string_view(kernal_filename, len);
const std::filesystem::path filepath = Options.fsroot_path / filename;

x16file *f = x16open(filepath.generic_string().c_str(), "rb");
if (f == nullptr) {
Expand Down Expand Up @@ -227,13 +224,9 @@ void LOAD()
void SAVE()
{
char const *kernal_filename = (char *)&RAM[RAM[FNADR] | RAM[FNADR + 1] << 8];

char filename[PATH_MAX];
const int len = MIN(RAM[FNLEN], PATH_MAX - 1);
memcpy(filename, kernal_filename, len);
filename[len] = '\0';

std::filesystem::path filepath = Options.fsroot_path / filename;
const int len = RAM[FNLEN];
const std::filesystem::path filename = std::string_view(kernal_filename, len);
const std::filesystem::path filepath = Options.fsroot_path / filename;

uint16_t start = RAM[state6502.a] | RAM[state6502.a + 1] << 8;
uint16_t end = state6502.x | state6502.y << 8;
Expand Down

0 comments on commit 354514c

Please sign in to comment.