Skip to content

Commit

Permalink
rainbow: fixed FILE_WRITE and FILE_APPEND commands
Browse files Browse the repository at this point in the history
  • Loading branch information
BrokeStudio committed Nov 6, 2023
1 parent 0fdd273 commit 194b062
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 21 additions & 4 deletions Core/NES/Mappers/Homebrew/RainbowESP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,16 +850,15 @@ void BrokeStudioFirmware::processBufferedMessage()
break;
case toesp_cmds_t::FILE_WRITE:
UDBG("[Rainbow] ESP received command FILE_WRITE");
if(message_size >= 3 && this->working_file.active) {
if(message_size >= 2 && this->working_file.active) {
this->writeFile(this->rx_buffer.begin() + 2, this->rx_buffer.begin() + message_size + 1);
this->working_file.offset += message_size - 1;
}
break;
case toesp_cmds_t::FILE_APPEND:
UDBG("[Rainbow] ESP received command FILE_APPEND");
if(message_size >= 3 && this->working_file.active) {
UDBG("[Rainbow] ESP command FILE_APPEND not implemented");
//this->appendFile(this->rx_buffer.begin() + 2, this->rx_buffer.begin() + message_size + 1);
if(message_size >= 2 && this->working_file.active) {
this->appendFile(this->rx_buffer.begin() + 2, this->rx_buffer.begin() + message_size + 1);
}
break;
case toesp_cmds_t::FILE_COUNT:
Expand Down Expand Up @@ -1301,6 +1300,24 @@ void BrokeStudioFirmware::writeFile(I data_begin, I data_end)
}
}

template<class I>
void BrokeStudioFirmware::appendFile(I data_begin, I data_end)
{
if(this->working_file.active == false) {
return;
}

auto const data_size = data_end - data_begin;
size_t file_size = this->working_file.file->data.size();
uint32_t const offset_end = file_size + data_size;
this->working_file.file->data.resize(offset_end, 0);

for(vector<uint8_t>::size_type i = file_size; i < offset_end; ++i) {
this->working_file.file->data[i] = *data_begin;
++data_begin;
}
}

void BrokeStudioFirmware::saveFiles()
{
#ifdef _WIN32
Expand Down
2 changes: 2 additions & 0 deletions Core/NES/Mappers/Homebrew/RainbowESP.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ class BrokeStudioFirmware
void readFile(uint8_t n);
template<class I>
void writeFile(I data_begin, I data_end);
template<class I>
void appendFile(I data_begin, I data_end);
void saveFiles();
void saveFile(uint8_t drive, char const* filename);
void loadFiles();
Expand Down

0 comments on commit 194b062

Please sign in to comment.