SD handle break output by keyboard

This commit is contained in:
nino-porcino 2022-02-16 08:58:59 +01:00
parent 46a0824ddc
commit ffc1ebdfb7
6 changed files with 68 additions and 24 deletions

View File

@ -175,6 +175,7 @@ const int CMD_DEL = 11;
const int CMD_LS = 12;
const int CMD_CD = 13;
const int CMD_MKDIR = 14;
const int CMD_PWD = 19;
const int CMD_RMDIR = 15;
const int ERR_RESPONSE = 255;
@ -705,10 +706,6 @@ void comando_mkdir() {
// **************************************************************************************
// **************************************************************************************
void send_cd_path() {
send_string_to_cpu(cd_path);
}
void comando_cd() {
Serial.println(F("command CD received from CPU"));
@ -722,24 +719,35 @@ void comando_cd() {
// CD without arguments
if(filename[0] == 0) {
// does nothing simply prints the path
send_cd_path();
// ok response
send_byte_to_cpu(OK_RESPONSE);
return;
}
// CD ..
if(filename[0] == '.' && filename[1] == '.' && filename[2] == 0) {
strcpy(filename, cd_path);
for(int t=strlen(filename)-1;t>=1;t--) {
int c = filename[t];
filename[t] = 0;
if(c == '/') break;
}
}
// CD /
if(filename[0] == '/' && filename[1] == 0) {
// changes to the root directory
if(SD.chdir()) {
// set root working directory
strcpy(cd_path, filename);
send_cd_path();
Serial.print(F("dir changed to:"));
Serial.println(cd_path);
send_byte_to_cpu(OK_RESPONSE);
return;
}
else {
Serial.println(F("error changing dir"));
send_byte_to_cpu(ERR_RESPONSE);
send_string_to_cpu(CANT_CD_DIR);
return;
}
@ -748,28 +756,32 @@ void comando_cd() {
// CD dirname
if(SD.chdir(filename)) {
// update working directory
if(filename[0] == '/') {
// replace cwd
strcpy(cd_path, filename);
if(filename[0] == '/') {
strcpy(cd_path, filename); // path is absolute, replace cwd
}
else {
// append to cwd
// path is relative, append to cwd
if(cd_path[0] == '/' && cd_path[1] == 0) {
cd_path[0] = 0; // avoid the double slash ("//DIR") when cwd is root
}
sprintf(tmp, "%s/%s", cd_path, filename);
strcpy(cd_path, tmp);
}
// print working directory
send_cd_path();
Serial.print(F("dir changed to:"));
Serial.println(cd_path);
send_byte_to_cpu(OK_RESPONSE);
return;
}
// errors
send_byte_to_cpu(ERR_RESPONSE);
// check if the directory exists
if(!SD.exists(filename)) {
Serial.println(F("dir not found"));
Serial.println(F("dir not found"));
send_string_to_cpu(DIR_NOT_FOUND);
return;
}
@ -779,15 +791,26 @@ void comando_cd() {
myFile.close();
if(!isDir) {
Serial.println(F("not a directory"));
Serial.println(F("not a directory"));
send_string_to_cpu(NOT_A_DIRECTORY);
}
else {
Serial.println(F("error changing dir"));
Serial.println(F("error changing dir"));
send_string_to_cpu(CANT_CD_DIR);
}
}
// **************************************************************************************
// **************************************************************************************
// ********************************* @CMD_PWD *******************************************
// **************************************************************************************
// **************************************************************************************
void comando_pwd() {
Serial.println(F("command PWD received from CPU"));
send_string_to_cpu(cd_path);
}
// **************************************************************************************
// **************************************************************************************
// ********************************* LOOP **********************************************
@ -800,12 +823,15 @@ void loop() {
int data = receive_byte_from_cpu();
if(TIMEOUT) return;
unsigned long start_time = millis();
if(data == CMD_READ) comando_read();
else if(data == CMD_WRITE) comando_write();
else if(data == CMD_DEL) comando_del();
else if(data == CMD_RMDIR) comando_rmdir();
else if(data == CMD_MKDIR) comando_mkdir();
else if(data == CMD_CD) comando_cd();
else if(data == CMD_PWD) comando_pwd();
else if(data == CMD_DIR) comando_dir(data);
else if(data == CMD_LS) comando_dir(data);
else {
@ -813,6 +839,9 @@ void loop() {
Serial.print(data);
Serial.println(F(" received"));
}
Serial.print(F("command processing time: "));
Serial.println(millis() - start_time);
if(TIMEOUT) Serial.println(F("TIMEOUT during command"));
}

View File

@ -6,5 +6,5 @@ void comando_dir(byte cmd) {
send_string_to_MCU(filename);
if(TIMEOUT) return;
print_string_response();
print_string_response_brk();
}

View File

@ -30,11 +30,13 @@ void comando_dump() {
// get file bytes
byte row = 0;
byte print_on = 1;
for(word t=0;t!=tmpword;t++) {
byte data = receive_byte_from_MCU();
if(TIMEOUT) return;
if(!(t>=start_address && t<=end_address)) continue;
if(!print_on) continue;
if(row == 0) {
woz_putc('\r');
@ -50,7 +52,7 @@ void comando_dump() {
if(apple1_readkey()) {
woz_puts("*BRK*\r");
break;
print_on = 0;
}
}
}

View File

@ -22,14 +22,15 @@ void comando_type() {
receive_word_from_mcu();
if(TIMEOUT) return;
// get file bytes
// get file bytes
byte print_on = 1;
for(word t=0;t!=tmpword;t++) {
byte data = receive_byte_from_MCU();
if(TIMEOUT) return;
woz_putc(data);
if(print_on) woz_putc(data);
if(apple1_readkey()) {
woz_puts("*BRK*\r");
break;
print_on = 0;
}
}
}

View File

@ -1 +1,2 @@
call ..\..\tools\build sdcard
call ..\..\tools\build sdcard
copy out\sdcard.prg ..\..\..\apple1-emu\software\sdcard.prg /y

View File

@ -114,9 +114,20 @@ void print_string_response() {
if(TIMEOUT) break;
if(data == 0) break; // string terminator
else woz_putc(data);
}
}
// print a string sent by the MCU, breakable via keyboard
void print_string_response_brk() {
byte print_on = 1;
while(1) {
byte data = receive_byte_from_MCU();
if(TIMEOUT) break;
if(data == 0) break; // string terminator
if(print_on) woz_putc(data);
if(apple1_readkey()) {
woz_puts("*BRK*\r");
break;
woz_puts("*BRK*\r");
print_on = 0;
}
}
}