apple1-videocard-lib/demos/sdcard/cmd_read.h

58 lines
1.3 KiB
C
Raw Normal View History

2022-02-07 07:50:35 +00:00
// READ:
// CPU sends CMD_READ + filename as 0 terminated string
// MCU sends $00 + 2 bytes file length (MSB first) + file data bytes (if OK)
// MCU sends $FF + string error description (if error)
//
2022-02-10 16:06:16 +00:00
// global start_address
// global len
// global token_ptr
void comando_read() {
2022-02-07 07:50:35 +00:00
// send command byte
send_byte_to_MCU(CMD_READ);
if(TIMEOUT) return;
// send filename
send_string_to_MCU(filename);
if(TIMEOUT) return;
// response
byte response = receive_byte_from_MCU();
if(TIMEOUT) return;
if(response == ERR_RESPONSE) {
// error with file, print message
print_string_response();
return;
}
2022-02-10 16:06:16 +00:00
// get file length in tmpword
receive_word_from_mcu();
2022-02-07 07:50:35 +00:00
if(TIMEOUT) return;
// get file bytes
2022-02-10 16:06:16 +00:00
token_ptr = (byte *) start_address;
for(word t=0;t!=tmpword;t++) {
2022-02-07 07:50:35 +00:00
byte data = receive_byte_from_MCU();
if(TIMEOUT) return;
2022-02-10 16:06:16 +00:00
*token_ptr++ = data;
2022-02-07 07:50:35 +00:00
}
2022-02-10 16:06:16 +00:00
// decrease by one for display result
token_ptr--;
2022-02-07 07:50:35 +00:00
// print feedback to user
woz_putc('\r');
woz_puts(filename);
2022-03-25 13:56:58 +00:00
woz_puts("\r$");
2022-02-10 16:06:16 +00:00
woz_print_hexword(start_address);
2022-03-25 13:56:58 +00:00
woz_puts("-$");
2022-02-10 16:06:16 +00:00
woz_print_hexword((word)token_ptr);
2022-02-07 07:50:35 +00:00
woz_puts(" (");
2022-02-10 16:06:16 +00:00
utoa(tmpword, filename, 10); // use filename as string buffer
2022-02-07 07:50:35 +00:00
woz_puts(filename);
woz_puts(" BYTES)\rOK");
}