Skip to content

Commit

Permalink
Add trailing CR byte to M-R response
Browse files Browse the repository at this point in the history
Gets a CR added, like other command channel data.
  • Loading branch information
thierer committed Apr 30, 2024
1 parent 4ad9bbb commit dd6d8be
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/doscmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ static void handle_memexec(void) {
static void handle_memread(void) {
FRESULT res;
uint16_t address, check;
uint8_t drive_type;
uint8_t drive_type, bytes;
magic_value_t *p;

if (command_length < 5)
Expand All @@ -1365,6 +1365,11 @@ static void handle_memread(void) {
if (command_length == 5)
command_buffer[5] = 1;

/* Clamp maximum read length to buffer size - 1 */
bytes = command_buffer[5];
if (bytes >= sizeof(error_buffer))
bytes = sizeof(error_buffer) - 1;

address = command_buffer[3] + (command_buffer[4]<<8);

if (address >= 0x8000 && rom_filename[0] != 0) {
Expand Down Expand Up @@ -1402,11 +1407,6 @@ static void handle_memread(void) {
if (res != FR_OK)
goto use_internal;

/* Clamp maximum read length to buffer size */
uint8_t bytes = command_buffer[5];
if (bytes > sizeof(error_buffer))
bytes = sizeof(error_buffer);

UINT bytesread;
res = f_read(&romfile, error_buffer, bytes, &bytesread);
if (res != FR_OK || bytesread != bytes)
Expand Down Expand Up @@ -1451,11 +1451,10 @@ static void handle_memread(void) {
custom_magic.drives = 0;
}

/* possibly the host wants to read more bytes than error_buffer size */
/* we ignore this knowing that we return nonsense in this case */
buffers[ERRORBUFFER_IDX].data = error_buffer;
buffers[ERRORBUFFER_IDX].position = 0;
buffers[ERRORBUFFER_IDX].lastused = command_buffer[5]-1;
buffers[ERRORBUFFER_IDX].lastused = bytes;
error_buffer[bytes] = 13;
}

/* --- M-W --- */
Expand Down

0 comments on commit dd6d8be

Please sign in to comment.