mirror of
https://github.com/nippur72/apple1-videocard-lib.git
synced 2025-01-15 02:29:57 +00:00
SD handle break output by keyboard
This commit is contained in:
parent
46a0824ddc
commit
ffc1ebdfb7
@ -175,6 +175,7 @@ const int CMD_DEL = 11;
|
|||||||
const int CMD_LS = 12;
|
const int CMD_LS = 12;
|
||||||
const int CMD_CD = 13;
|
const int CMD_CD = 13;
|
||||||
const int CMD_MKDIR = 14;
|
const int CMD_MKDIR = 14;
|
||||||
|
const int CMD_PWD = 19;
|
||||||
const int CMD_RMDIR = 15;
|
const int CMD_RMDIR = 15;
|
||||||
|
|
||||||
const int ERR_RESPONSE = 255;
|
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() {
|
void comando_cd() {
|
||||||
Serial.println(F("command CD received from CPU"));
|
Serial.println(F("command CD received from CPU"));
|
||||||
|
|
||||||
@ -722,24 +719,35 @@ void comando_cd() {
|
|||||||
|
|
||||||
// CD without arguments
|
// CD without arguments
|
||||||
if(filename[0] == 0) {
|
if(filename[0] == 0) {
|
||||||
// does nothing simply prints the path
|
// ok response
|
||||||
send_cd_path();
|
send_byte_to_cpu(OK_RESPONSE);
|
||||||
return;
|
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 /
|
// CD /
|
||||||
if(filename[0] == '/' && filename[1] == 0) {
|
if(filename[0] == '/' && filename[1] == 0) {
|
||||||
// changes to the root directory
|
// changes to the root directory
|
||||||
if(SD.chdir()) {
|
if(SD.chdir()) {
|
||||||
// set root working directory
|
// set root working directory
|
||||||
strcpy(cd_path, filename);
|
strcpy(cd_path, filename);
|
||||||
send_cd_path();
|
|
||||||
Serial.print(F("dir changed to:"));
|
Serial.print(F("dir changed to:"));
|
||||||
Serial.println(cd_path);
|
Serial.println(cd_path);
|
||||||
|
send_byte_to_cpu(OK_RESPONSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println(F("error changing dir"));
|
Serial.println(F("error changing dir"));
|
||||||
|
send_byte_to_cpu(ERR_RESPONSE);
|
||||||
send_string_to_cpu(CANT_CD_DIR);
|
send_string_to_cpu(CANT_CD_DIR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -748,28 +756,32 @@ void comando_cd() {
|
|||||||
// CD dirname
|
// CD dirname
|
||||||
if(SD.chdir(filename)) {
|
if(SD.chdir(filename)) {
|
||||||
// update working directory
|
// update working directory
|
||||||
if(filename[0] == '/') {
|
if(filename[0] == '/') {
|
||||||
// replace cwd
|
strcpy(cd_path, filename); // path is absolute, replace cwd
|
||||||
strcpy(cd_path, filename);
|
|
||||||
}
|
}
|
||||||
else {
|
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);
|
sprintf(tmp, "%s/%s", cd_path, filename);
|
||||||
strcpy(cd_path, tmp);
|
strcpy(cd_path, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// print working directory
|
|
||||||
send_cd_path();
|
|
||||||
Serial.print(F("dir changed to:"));
|
Serial.print(F("dir changed to:"));
|
||||||
Serial.println(cd_path);
|
Serial.println(cd_path);
|
||||||
|
send_byte_to_cpu(OK_RESPONSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// errors
|
// errors
|
||||||
|
|
||||||
|
send_byte_to_cpu(ERR_RESPONSE);
|
||||||
|
|
||||||
// check if the directory exists
|
// check if the directory exists
|
||||||
if(!SD.exists(filename)) {
|
if(!SD.exists(filename)) {
|
||||||
Serial.println(F("dir not found"));
|
Serial.println(F("dir not found"));
|
||||||
send_string_to_cpu(DIR_NOT_FOUND);
|
send_string_to_cpu(DIR_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -779,15 +791,26 @@ void comando_cd() {
|
|||||||
myFile.close();
|
myFile.close();
|
||||||
|
|
||||||
if(!isDir) {
|
if(!isDir) {
|
||||||
Serial.println(F("not a directory"));
|
Serial.println(F("not a directory"));
|
||||||
send_string_to_cpu(NOT_A_DIRECTORY);
|
send_string_to_cpu(NOT_A_DIRECTORY);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println(F("error changing dir"));
|
Serial.println(F("error changing dir"));
|
||||||
send_string_to_cpu(CANT_CD_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 **********************************************
|
// ********************************* LOOP **********************************************
|
||||||
@ -800,12 +823,15 @@ void loop() {
|
|||||||
int data = receive_byte_from_cpu();
|
int data = receive_byte_from_cpu();
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
unsigned long start_time = millis();
|
||||||
|
|
||||||
if(data == CMD_READ) comando_read();
|
if(data == CMD_READ) comando_read();
|
||||||
else if(data == CMD_WRITE) comando_write();
|
else if(data == CMD_WRITE) comando_write();
|
||||||
else if(data == CMD_DEL) comando_del();
|
else if(data == CMD_DEL) comando_del();
|
||||||
else if(data == CMD_RMDIR) comando_rmdir();
|
else if(data == CMD_RMDIR) comando_rmdir();
|
||||||
else if(data == CMD_MKDIR) comando_mkdir();
|
else if(data == CMD_MKDIR) comando_mkdir();
|
||||||
else if(data == CMD_CD) comando_cd();
|
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_DIR) comando_dir(data);
|
||||||
else if(data == CMD_LS) comando_dir(data);
|
else if(data == CMD_LS) comando_dir(data);
|
||||||
else {
|
else {
|
||||||
@ -813,6 +839,9 @@ void loop() {
|
|||||||
Serial.print(data);
|
Serial.print(data);
|
||||||
Serial.println(F(" received"));
|
Serial.println(F(" received"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serial.print(F("command processing time: "));
|
||||||
|
Serial.println(millis() - start_time);
|
||||||
|
|
||||||
if(TIMEOUT) Serial.println(F("TIMEOUT during command"));
|
if(TIMEOUT) Serial.println(F("TIMEOUT during command"));
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,5 @@ void comando_dir(byte cmd) {
|
|||||||
send_string_to_MCU(filename);
|
send_string_to_MCU(filename);
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
print_string_response();
|
print_string_response_brk();
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,13 @@ void comando_dump() {
|
|||||||
|
|
||||||
// get file bytes
|
// get file bytes
|
||||||
byte row = 0;
|
byte row = 0;
|
||||||
|
byte print_on = 1;
|
||||||
for(word t=0;t!=tmpword;t++) {
|
for(word t=0;t!=tmpword;t++) {
|
||||||
byte data = receive_byte_from_MCU();
|
byte data = receive_byte_from_MCU();
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
if(!(t>=start_address && t<=end_address)) continue;
|
if(!(t>=start_address && t<=end_address)) continue;
|
||||||
|
if(!print_on) continue;
|
||||||
|
|
||||||
if(row == 0) {
|
if(row == 0) {
|
||||||
woz_putc('\r');
|
woz_putc('\r');
|
||||||
@ -50,7 +52,7 @@ void comando_dump() {
|
|||||||
|
|
||||||
if(apple1_readkey()) {
|
if(apple1_readkey()) {
|
||||||
woz_puts("*BRK*\r");
|
woz_puts("*BRK*\r");
|
||||||
break;
|
print_on = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,15 @@ void comando_type() {
|
|||||||
receive_word_from_mcu();
|
receive_word_from_mcu();
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
// get file bytes
|
// get file bytes
|
||||||
|
byte print_on = 1;
|
||||||
for(word t=0;t!=tmpword;t++) {
|
for(word t=0;t!=tmpword;t++) {
|
||||||
byte data = receive_byte_from_MCU();
|
byte data = receive_byte_from_MCU();
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
woz_putc(data);
|
if(print_on) woz_putc(data);
|
||||||
if(apple1_readkey()) {
|
if(apple1_readkey()) {
|
||||||
woz_puts("*BRK*\r");
|
woz_puts("*BRK*\r");
|
||||||
break;
|
print_on = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
call ..\..\tools\build sdcard
|
call ..\..\tools\build sdcard
|
||||||
|
copy out\sdcard.prg ..\..\..\apple1-emu\software\sdcard.prg /y
|
||||||
|
@ -114,9 +114,20 @@ void print_string_response() {
|
|||||||
if(TIMEOUT) break;
|
if(TIMEOUT) break;
|
||||||
if(data == 0) break; // string terminator
|
if(data == 0) break; // string terminator
|
||||||
else woz_putc(data);
|
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()) {
|
if(apple1_readkey()) {
|
||||||
woz_puts("*BRK*\r");
|
woz_puts("*BRK*\r");
|
||||||
break;
|
print_on = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user