mirror of
https://github.com/nippur72/apple1-videocard-lib.git
synced 2024-09-29 19:56:11 +00:00
new sd card commands
This commit is contained in:
parent
65f31e94ea
commit
8f211570f0
@ -13,6 +13,7 @@ COPY
|
|||||||
|
|
||||||
## DIR
|
## DIR
|
||||||
DIR
|
DIR
|
||||||
|
LS
|
||||||
CD
|
CD
|
||||||
MKDIR
|
MKDIR
|
||||||
RMDIR
|
RMDIR
|
||||||
@ -20,12 +21,9 @@ RMDIR
|
|||||||
## MISC
|
## MISC
|
||||||
HELP
|
HELP
|
||||||
JMP
|
JMP
|
||||||
|
BAS
|
||||||
STAT
|
STAT
|
||||||
MOUNT
|
MOUNT
|
||||||
TIME
|
TIME
|
||||||
EXIT
|
EXIT
|
||||||
|
|
||||||
/*
|
|
||||||
1234567890123456789012345678901234567890
|
|
||||||
0000: 00 00 00 00 00 00 00 00 12345678
|
|
||||||
*/
|
|
||||||
|
@ -168,6 +168,39 @@ void send_byte_to_cpu(int data) {
|
|||||||
// *********************************************************************************************
|
// *********************************************************************************************
|
||||||
// *********************************************************************************************
|
// *********************************************************************************************
|
||||||
|
|
||||||
|
const int CMD_READ = 0;
|
||||||
|
const int CMD_WRITE = 1;
|
||||||
|
const int CMD_DIR = 2;
|
||||||
|
const int CMD_DEL = 11;
|
||||||
|
const int CMD_LS = 12;
|
||||||
|
const int CMD_CD = 13;
|
||||||
|
const int CMD_MKDIR = 14;
|
||||||
|
const int CMD_RMDIR = 15;
|
||||||
|
|
||||||
|
const int ERR_RESPONSE = 255;
|
||||||
|
const int OK_RESPONSE = 0;
|
||||||
|
|
||||||
|
char filename[64];
|
||||||
|
char tmp[64];
|
||||||
|
char cd_path[64];
|
||||||
|
|
||||||
|
// fixed messages
|
||||||
|
const char *FILE_NOT_FOUND = "?FILE NOT FOUND";
|
||||||
|
const char *CANT_OPEN_FILE = "?CAN'T OPEN FILE";
|
||||||
|
const char *ALREADY_EXISTS = "?FILE ALREADY EXISTS";
|
||||||
|
const char *CANT_CREATE_FILE = "?CAN'T CREATE FILE";
|
||||||
|
const char *WRITE_ERROR = "?WRITE ERROR";
|
||||||
|
const char *CANT_DELETE_FILE = "?CAN'T DELETE FILE";
|
||||||
|
const char *FILE_DELETED = " DELETED";
|
||||||
|
const char *DIR_NOT_FOUND = "?DIR NOT FOUND";
|
||||||
|
const char *CANT_REMOVE_DIR = "?CAN'T REMOVE DIR";
|
||||||
|
const char *DIR_REMOVED = " (DIR) REMOVED";
|
||||||
|
const char *DIR_ALREADY_EXISTS = "?DIR ALREADY EXISTS";
|
||||||
|
const char *CANT_MAKE_DIR = "?CAN'T MAKE DIR";
|
||||||
|
const char *DIR_CREATED = " (DIR) CREATED";
|
||||||
|
const char *CANT_CD_DIR = "?CAN'T CHANGE DIR";
|
||||||
|
const char *NOT_A_DIRECTORY = "?NOT A DIRECTORY";
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// debug on serial
|
// debug on serial
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@ -187,31 +220,25 @@ void setup() {
|
|||||||
set_data_port_direction(DIR_INPUT);
|
set_data_port_direction(DIR_INPUT);
|
||||||
|
|
||||||
MatchState ms;
|
MatchState ms;
|
||||||
char buf [100] = { F("The quick brown fox jumps over the lazy wolf") };
|
char buf [100] = { "The quick " };
|
||||||
ms.Target (buf);
|
ms.Target (buf);
|
||||||
char result = ms.Match ("f.x");
|
char result = ms.Match ("f.x");
|
||||||
if(result >0) {
|
if(result >0) {
|
||||||
Serial.println("match!");
|
Serial.println("match!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set working directory to root
|
||||||
|
strcpy(cd_path, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
const int CMD_READ = 0;
|
|
||||||
const int CMD_WRITE = 1;
|
|
||||||
const int CMD_DIR = 2;
|
|
||||||
const int CMD_DEL = 11;
|
|
||||||
|
|
||||||
const int ERR_RESPONSE = 255;
|
|
||||||
const int OK_RESPONSE = 0;
|
|
||||||
|
|
||||||
char filename[64];
|
|
||||||
char tmp[64];
|
|
||||||
|
|
||||||
// **************************************************************************************
|
// **************************************************************************************
|
||||||
// **************************************************************************************
|
// **************************************************************************************
|
||||||
// ********************************* DIR ***********************************************
|
// ********************************* @CMD_DIR ******************************************
|
||||||
// **************************************************************************************
|
// **************************************************************************************
|
||||||
// **************************************************************************************
|
// **************************************************************************************
|
||||||
|
|
||||||
|
/*
|
||||||
// recursive print directory
|
// recursive print directory
|
||||||
void printDirectory(File dir, int numTabs) {
|
void printDirectory(File dir, int numTabs) {
|
||||||
|
|
||||||
@ -253,14 +280,12 @@ void printDirectory(File dir, int numTabs) {
|
|||||||
send_byte_to_cpu(' ');
|
send_byte_to_cpu(' ');
|
||||||
send_byte_to_cpu(' ');
|
send_byte_to_cpu(' ');
|
||||||
|
|
||||||
/*
|
|
||||||
// file size
|
// file size
|
||||||
Serial.println(entry.size(), DEC);
|
//Serial.println(entry.size(), DEC);
|
||||||
msg = itoa(entry.size());
|
//msg = itoa(entry.size());
|
||||||
for(int t=0; t<strlen(msg); t++) {
|
//for(int t=0; t<strlen(msg); t++) {
|
||||||
send_byte_to_cpu(msg[t]);
|
// send_byte_to_cpu(msg[t]);
|
||||||
}
|
//}
|
||||||
*/
|
|
||||||
send_byte_to_cpu('\r');
|
send_byte_to_cpu('\r');
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -280,23 +305,40 @@ void comando_dir_alternate() {
|
|||||||
send_byte_to_cpu(0);
|
send_byte_to_cpu(0);
|
||||||
Serial.println(F("command DIR ended"));
|
Serial.println(F("command DIR ended"));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// versione tipo MS-DOS
|
// versione tipo MS-DOS
|
||||||
void comando_dir() {
|
void comando_dir(int command) {
|
||||||
Serial.println(F("command DIR received from CPU"));
|
Serial.println(F("command DIR received from CPU"));
|
||||||
|
|
||||||
|
// reads filename as 0 terminated string
|
||||||
|
receive_string_from_cpu(filename);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
Serial.print(F("dir to read: "));
|
||||||
|
Serial.println(filename);
|
||||||
|
|
||||||
File dir;
|
File dir;
|
||||||
|
|
||||||
// lists directories first
|
if(filename[0]==0) {
|
||||||
dir = SD.open("/");
|
// no argument given, use cd_path
|
||||||
print_dir_entry(dir, 0);
|
strcpy(filename, cd_path);
|
||||||
dir.close();
|
}
|
||||||
|
|
||||||
|
dir = SD.open(filename);
|
||||||
|
|
||||||
|
if(!dir) {
|
||||||
|
Serial.println(F("dir not found"));
|
||||||
|
send_string_to_cpu(DIR_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// *** lists directories first
|
||||||
|
print_dir_entry(dir, 0, command);
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
// then files
|
// *** then files
|
||||||
dir = SD.open("/");
|
dir.rewind();
|
||||||
print_dir_entry(dir, 1);
|
print_dir_entry(dir, 1, command);
|
||||||
dir.close();
|
dir.close();
|
||||||
|
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
@ -306,7 +348,7 @@ void comando_dir() {
|
|||||||
Serial.println(F("command DIR ended"));
|
Serial.println(F("command DIR ended"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_dir_entry(File dir, int list_files) {
|
void print_dir_entry(File dir, int list_files, int command) {
|
||||||
while (true) {
|
while (true) {
|
||||||
File entry = dir.openNextFile();
|
File entry = dir.openNextFile();
|
||||||
|
|
||||||
@ -320,20 +362,45 @@ void print_dir_entry(File dir, int list_files) {
|
|||||||
|
|
||||||
if((list_files == 0 && entry.isDirectory()) || (list_files == 1 && !entry.isDirectory())) {
|
if((list_files == 0 && entry.isDirectory()) || (list_files == 1 && !entry.isDirectory())) {
|
||||||
if(entry.isDirectory()) {
|
if(entry.isDirectory()) {
|
||||||
sprintf(tmp, "(DIR) %s\r", filename);
|
if(command != CMD_DIR) {
|
||||||
print_string_to_cpu(tmp);
|
sprintf(tmp, "(DIR) %s\r", filename);
|
||||||
Serial.println(tmp);
|
print_string_to_cpu(tmp);
|
||||||
|
Serial.println(tmp);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprintf(tmp, "%-15s (DIR)\r", filename);
|
||||||
|
print_string_to_cpu(tmp);
|
||||||
|
Serial.println(tmp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// BUG the following line does not work
|
if(command != CMD_DIR) {
|
||||||
// sprintf(tmp, "%5d %s", entry.size(), filename);
|
// BUG the following line does not work
|
||||||
// use this instead
|
// sprintf(tmp, "%5d %s", entry.size(), filename);
|
||||||
sprintf(tmp, "%5d ", entry.size());
|
// use this instead
|
||||||
print_string_to_cpu(tmp);
|
sprintf(tmp, "%5d ", entry.size());
|
||||||
Serial.print(tmp);
|
print_string_to_cpu(tmp);
|
||||||
print_string_to_cpu(filename);
|
Serial.print(tmp);
|
||||||
send_byte_to_cpu('\r');
|
|
||||||
Serial.println(filename);
|
print_string_to_cpu(filename);
|
||||||
|
Serial.println(filename);
|
||||||
|
|
||||||
|
send_byte_to_cpu('\r');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// BUG the following line does not work
|
||||||
|
// sprintf(tmp, "%5d %s", entry.size(), filename);
|
||||||
|
// use this instead
|
||||||
|
sprintf(tmp, "%-15s", filename);
|
||||||
|
print_string_to_cpu(tmp);
|
||||||
|
Serial.print(filename);
|
||||||
|
|
||||||
|
sprintf(tmp, "%6d", entry.size());
|
||||||
|
print_string_to_cpu(tmp);
|
||||||
|
Serial.println(tmp);
|
||||||
|
|
||||||
|
send_byte_to_cpu('\r');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(TIMEOUT) break;
|
if(TIMEOUT) break;
|
||||||
}
|
}
|
||||||
@ -361,7 +428,7 @@ void comando_read() {
|
|||||||
if(!SD.exists(filename)) {
|
if(!SD.exists(filename)) {
|
||||||
Serial.println(F("error opening file"));
|
Serial.println(F("error opening file"));
|
||||||
send_byte_to_cpu(ERR_RESPONSE);
|
send_byte_to_cpu(ERR_RESPONSE);
|
||||||
send_string_to_cpu((char *)F("?FILE NOT FOUND"));
|
send_string_to_cpu(FILE_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +437,7 @@ void comando_read() {
|
|||||||
if(!myFile) {
|
if(!myFile) {
|
||||||
Serial.println(F("error opening file"));
|
Serial.println(F("error opening file"));
|
||||||
send_byte_to_cpu(ERR_RESPONSE);
|
send_byte_to_cpu(ERR_RESPONSE);
|
||||||
send_string_to_cpu((char *)F("?CAN'T OPEN FILE"));
|
send_string_to_cpu(CANT_OPEN_FILE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.println(F("file opened on the SD card"));
|
Serial.println(F("file opened on the SD card"));
|
||||||
@ -457,7 +524,7 @@ void comando_write() {
|
|||||||
if(SD.exists(filename)) {
|
if(SD.exists(filename)) {
|
||||||
Serial.println(F("file already exist"));
|
Serial.println(F("file already exist"));
|
||||||
send_byte_to_cpu(ERR_RESPONSE);
|
send_byte_to_cpu(ERR_RESPONSE);
|
||||||
send_string_to_cpu((char *)F("?ALREADY EXISTS"));
|
send_string_to_cpu(ALREADY_EXISTS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,7 +533,7 @@ void comando_write() {
|
|||||||
if(!myFile) {
|
if(!myFile) {
|
||||||
Serial.println(F("error opening file for write"));
|
Serial.println(F("error opening file for write"));
|
||||||
send_byte_to_cpu(ERR_RESPONSE);
|
send_byte_to_cpu(ERR_RESPONSE);
|
||||||
send_string_to_cpu((char *)F("?CAN'T CREATE FILE"));
|
send_string_to_cpu(CANT_CREATE_FILE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.println(F("file opened for write on the SD card"));
|
Serial.println(F("file opened for write on the SD card"));
|
||||||
@ -500,7 +567,7 @@ void comando_write() {
|
|||||||
Serial.println(F("file write error"));
|
Serial.println(F("file write error"));
|
||||||
send_byte_to_cpu(ERR_RESPONSE);
|
send_byte_to_cpu(ERR_RESPONSE);
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
send_string_to_cpu("?WRITE ERROR");
|
send_string_to_cpu(WRITE_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,7 +592,7 @@ void comando_del() {
|
|||||||
|
|
||||||
if(!SD.exists(filename)) {
|
if(!SD.exists(filename)) {
|
||||||
Serial.println(F("file does not exist"));
|
Serial.println(F("file does not exist"));
|
||||||
send_string_to_cpu((char *)F("?FILE NOT FOUND"));
|
send_string_to_cpu(FILE_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,7 +602,7 @@ void comando_del() {
|
|||||||
File myFile = SD.open(filename, FILE_WRITE);
|
File myFile = SD.open(filename, FILE_WRITE);
|
||||||
if(!myFile) {
|
if(!myFile) {
|
||||||
Serial.println(F("error opening file for deletion"));
|
Serial.println(F("error opening file for deletion"));
|
||||||
send_string_to_cpu((char *)F("?CAN'T DELETE FILE"));
|
send_string_to_cpu(CANT_DELETE_FILE);
|
||||||
myFile.close();
|
myFile.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -544,7 +611,7 @@ void comando_del() {
|
|||||||
|
|
||||||
if(!myFile.remove()) {
|
if(!myFile.remove()) {
|
||||||
Serial.println(F("error removing file"));
|
Serial.println(F("error removing file"));
|
||||||
send_string_to_cpu((char *)F("?CAN'T DELETE FILE"));
|
send_string_to_cpu(CANT_DELETE_FILE);
|
||||||
myFile.close();
|
myFile.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -553,11 +620,179 @@ void comando_del() {
|
|||||||
myFile.close();
|
myFile.close();
|
||||||
|
|
||||||
print_string_to_cpu(filename);
|
print_string_to_cpu(filename);
|
||||||
send_string_to_cpu((char *)F(" DELETED"));
|
send_string_to_cpu(FILE_DELETED);
|
||||||
|
|
||||||
Serial.println(F("file deleted"));
|
Serial.println(F("file deleted"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// **************************************************************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
// ********************************* CMD_RMDIR ******************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
|
||||||
|
void comando_rmdir() {
|
||||||
|
Serial.println(F("command RMDIR received from CPU"));
|
||||||
|
|
||||||
|
// reads filename as 0 terminated string
|
||||||
|
receive_string_from_cpu(filename);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
Serial.print(F("directory to delete: "));
|
||||||
|
Serial.println(filename);
|
||||||
|
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
// check if the directory exists
|
||||||
|
if(!SD.exists(filename)) {
|
||||||
|
Serial.println(F("dir does not exist"));
|
||||||
|
send_string_to_cpu(DIR_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// removes the directory
|
||||||
|
if(!SD.rmdir(filename)) {
|
||||||
|
Serial.println(F("error removing dir"));
|
||||||
|
send_string_to_cpu(CANT_REMOVE_DIR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_string_to_cpu(filename);
|
||||||
|
send_string_to_cpu(DIR_REMOVED);
|
||||||
|
|
||||||
|
Serial.println(F("dir removed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
// ********************************* CMD_MKDIR ******************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
|
||||||
|
void comando_mkdir() {
|
||||||
|
Serial.println(F("command MKDIR received from CPU"));
|
||||||
|
|
||||||
|
// reads filename as 0 terminated string
|
||||||
|
receive_string_from_cpu(filename);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
Serial.print(F("directory to create: "));
|
||||||
|
Serial.println(filename);
|
||||||
|
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
// check if the directory exists
|
||||||
|
if(SD.exists(filename)) {
|
||||||
|
Serial.println(F("dir already exist"));
|
||||||
|
send_string_to_cpu(DIR_ALREADY_EXISTS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// removes the directory
|
||||||
|
if(!SD.mkdir(filename)) {
|
||||||
|
Serial.println(F("error creating"));
|
||||||
|
send_string_to_cpu(CANT_MAKE_DIR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_string_to_cpu(filename);
|
||||||
|
send_string_to_cpu(DIR_CREATED);
|
||||||
|
|
||||||
|
Serial.println(F("dir created"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
// ********************************* @CMD_CD ********************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
// **************************************************************************************
|
||||||
|
|
||||||
|
void send_cd_path() {
|
||||||
|
if(cd_path[0]==0) {
|
||||||
|
send_string_to_cpu("/");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
send_string_to_cpu(cd_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void comando_cd() {
|
||||||
|
Serial.println(F("command CD received from CPU"));
|
||||||
|
|
||||||
|
// reads filename as 0 terminated string
|
||||||
|
receive_string_from_cpu(filename);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
Serial.print(F("directory to change to: "));
|
||||||
|
Serial.println(filename);
|
||||||
|
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
// CD without arguments
|
||||||
|
if(filename[0] == 0) {
|
||||||
|
// does nothing simply prints the path
|
||||||
|
send_cd_path();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CD /
|
||||||
|
if(filename[0] == '/' && filename[1] == 0) {
|
||||||
|
// changes to the root directory
|
||||||
|
if(SD.chdir()) {
|
||||||
|
// set root working directory
|
||||||
|
strcpy(cd_path[0], filename);
|
||||||
|
send_cd_path();
|
||||||
|
Serial.print(F("dir changed to:"));
|
||||||
|
Serial.println(cd_path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.println(F("error changing dir"));
|
||||||
|
send_string_to_cpu(CANT_CD_DIR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CD dirname
|
||||||
|
if(SD.chdir(filename)) {
|
||||||
|
// update working directory
|
||||||
|
if(filename[0] == '/') {
|
||||||
|
// replace cwd
|
||||||
|
strcpy(cd_path, filename);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// append to cwd
|
||||||
|
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);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// errors
|
||||||
|
|
||||||
|
// check if the directory exists
|
||||||
|
if(!SD.exists(filename)) {
|
||||||
|
Serial.println(F("dir not found"));
|
||||||
|
send_string_to_cpu(DIR_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File myFile = SD.open(filename);
|
||||||
|
bool isDir = myFile.isDirectory();
|
||||||
|
myFile.close();
|
||||||
|
|
||||||
|
if(!isDir) {
|
||||||
|
Serial.println(F("not a directory"));
|
||||||
|
send_string_to_cpu(NOT_A_DIRECTORY);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.println(F("error changing dir"));
|
||||||
|
send_string_to_cpu(CANT_CD_DIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// **************************************************************************************
|
// **************************************************************************************
|
||||||
// **************************************************************************************
|
// **************************************************************************************
|
||||||
// ********************************* LOOP **********************************************
|
// ********************************* LOOP **********************************************
|
||||||
@ -570,25 +805,19 @@ void loop() {
|
|||||||
int data = receive_byte_from_cpu();
|
int data = receive_byte_from_cpu();
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
if(data == CMD_READ) {
|
if(data == CMD_READ) comando_read();
|
||||||
comando_read();
|
else if(data == CMD_WRITE) comando_write();
|
||||||
if(TIMEOUT) Serial.println(F("TIMEOUT during CMD_READ"));
|
else if(data == CMD_DEL) comando_del();
|
||||||
}
|
else if(data == CMD_RMDIR) comando_rmdir();
|
||||||
else if(data == CMD_WRITE) {
|
else if(data == CMD_MKDIR) comando_mkdir();
|
||||||
comando_write();
|
else if(data == CMD_CD) comando_cd();
|
||||||
if(TIMEOUT) Serial.println(F("TIMEOUT during CMD_WRITE"));
|
else if(data == CMD_DIR) comando_dir(data);
|
||||||
}
|
else if(data == CMD_LS) comando_dir(data);
|
||||||
else if(data == CMD_DIR) {
|
|
||||||
comando_dir();
|
|
||||||
if(TIMEOUT) Serial.println(F("TIMEOUT during DIR"));
|
|
||||||
}
|
|
||||||
else if(data == CMD_DEL) {
|
|
||||||
comando_del();
|
|
||||||
if(TIMEOUT) Serial.println(F("TIMEOUT during DEL"));
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
Serial.print(F("unknown command "));
|
Serial.print(F("unknown command "));
|
||||||
Serial.print(data);
|
Serial.print(data);
|
||||||
Serial.println(F(" received"));
|
Serial.println(F(" received"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(TIMEOUT) Serial.println(F("TIMEOUT during command"));
|
||||||
}
|
}
|
||||||
|
12
demos/sdcard/cmd_chdir.h
Normal file
12
demos/sdcard/cmd_chdir.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
void comando_cd() {
|
||||||
|
// send command byte
|
||||||
|
send_byte_to_MCU(CMD_CD);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
// send filename
|
||||||
|
send_string_to_MCU(filename);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
print_string_response();
|
||||||
|
return;
|
||||||
|
}
|
@ -1,5 +1,10 @@
|
|||||||
void comando_dir(byte cmd) {
|
void comando_dir(byte cmd) {
|
||||||
send_byte_to_MCU(cmd);
|
send_byte_to_MCU(cmd);
|
||||||
if(TIMEOUT) return;
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
// send filename
|
||||||
|
send_string_to_MCU(filename);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
print_string_response();
|
print_string_response();
|
||||||
}
|
}
|
||||||
|
12
demos/sdcard/cmd_mkdir.h
Normal file
12
demos/sdcard/cmd_mkdir.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
void comando_mkdir() {
|
||||||
|
// send command byte
|
||||||
|
send_byte_to_MCU(CMD_MKDIR);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
// send filename
|
||||||
|
send_string_to_MCU(filename);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
print_string_response();
|
||||||
|
return;
|
||||||
|
}
|
12
demos/sdcard/cmd_rmdir.h
Normal file
12
demos/sdcard/cmd_rmdir.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
void comando_rmdir() {
|
||||||
|
// send command byte
|
||||||
|
send_byte_to_MCU(CMD_RMDIR);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
// send filename
|
||||||
|
send_string_to_MCU(filename);
|
||||||
|
if(TIMEOUT) return;
|
||||||
|
|
||||||
|
print_string_response();
|
||||||
|
return;
|
||||||
|
}
|
@ -31,7 +31,14 @@ const byte CMD_JMP = 9;
|
|||||||
const byte CMD_BAS = 10;
|
const byte CMD_BAS = 10;
|
||||||
const byte CMD_DEL = 11;
|
const byte CMD_DEL = 11;
|
||||||
const byte CMD_LS = 12;
|
const byte CMD_LS = 12;
|
||||||
const byte CMD_EXIT = 13;
|
const byte CMD_CD = 13;
|
||||||
|
const byte CMD_MKDIR = 14;
|
||||||
|
const byte CMD_RMDIR = 15;
|
||||||
|
const byte CMD_RM = 16;
|
||||||
|
const byte CMD_MD = 17;
|
||||||
|
const byte CMD_RD = 18;
|
||||||
|
const byte CMD_PWD = 19;
|
||||||
|
const byte CMD_EXIT = 16;
|
||||||
|
|
||||||
// the list of recognized commands
|
// the list of recognized commands
|
||||||
byte *DOS_COMMANDS[] = {
|
byte *DOS_COMMANDS[] = {
|
||||||
@ -48,6 +55,13 @@ byte *DOS_COMMANDS[] = {
|
|||||||
"BAS",
|
"BAS",
|
||||||
"DEL",
|
"DEL",
|
||||||
"LS",
|
"LS",
|
||||||
|
"CD",
|
||||||
|
"MKDIR",
|
||||||
|
"RMDIR",
|
||||||
|
"RM",
|
||||||
|
"MD",
|
||||||
|
"RD",
|
||||||
|
"PWD",
|
||||||
"EXIT"
|
"EXIT"
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -83,13 +97,9 @@ void get_token(byte *dest, byte max) {
|
|||||||
token_ptr += i+1;
|
token_ptr += i+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// looks "command" into table "DOS_COMMANDS" and
|
||||||
|
// if found sets the index in "cmd", 0xFF if not found
|
||||||
void find_command() {
|
void find_command() {
|
||||||
/*
|
|
||||||
for(cmd=0; cmd<sizeof(DOS_COMMANDS); cmd++) {
|
|
||||||
if(strcmp(command, DOS_COMMANDS[cmd]) == 0) return;
|
|
||||||
}
|
|
||||||
cmd = 0xFF;
|
|
||||||
*/
|
|
||||||
for(cmd=0; cmd<sizeof(DOS_COMMANDS); cmd++) {
|
for(cmd=0; cmd<sizeof(DOS_COMMANDS); cmd++) {
|
||||||
byte *ptr = DOS_COMMANDS[cmd];
|
byte *ptr = DOS_COMMANDS[cmd];
|
||||||
for(byte j=0;;j++) {
|
for(byte j=0;;j++) {
|
||||||
@ -120,17 +130,16 @@ void hex_to_word(byte *str) {
|
|||||||
#include "cmd_save.h"
|
#include "cmd_save.h"
|
||||||
#include "cmd_type.h"
|
#include "cmd_type.h"
|
||||||
#include "cmd_dump.h"
|
#include "cmd_dump.h"
|
||||||
#include "cmd_dir.h"
|
|
||||||
#include "cmd_del.h"
|
#include "cmd_del.h"
|
||||||
|
#include "cmd_dir.h"
|
||||||
|
#include "cmd_mkdir.h"
|
||||||
|
#include "cmd_rmdir.h"
|
||||||
|
#include "cmd_chdir.h"
|
||||||
|
|
||||||
void console() {
|
void console() {
|
||||||
|
|
||||||
VIA_init();
|
VIA_init();
|
||||||
|
|
||||||
// 1234567890123456789012345678901234567890
|
|
||||||
//woz_puts("\rREAD,WRITE,LOAD,RUN,SAVE,TYPE,DUMP,DIR\r"
|
|
||||||
// "TIME,JMP,EXIT\r");
|
|
||||||
|
|
||||||
woz_puts("\r\r*** SD CARD OS 1.0\r");
|
woz_puts("\r\r*** SD CARD OS 1.0\r");
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
@ -139,10 +148,9 @@ void console() {
|
|||||||
// clear input buffer
|
// clear input buffer
|
||||||
for(byte i=0; i<KEYBUFLEN; i++) KEYBUF[i] = 0;
|
for(byte i=0; i<KEYBUFLEN; i++) KEYBUF[i] = 0;
|
||||||
|
|
||||||
// input from keyboard
|
|
||||||
woz_puts("\r]");
|
|
||||||
apple1_input_line(KEYBUF, KEYBUFLEN);
|
|
||||||
woz_putc('\r');
|
woz_putc('\r');
|
||||||
|
apple1_input_line_prompt(KEYBUF, KEYBUFLEN);
|
||||||
|
if(KEYBUF[0]!=0) woz_putc('\r');
|
||||||
|
|
||||||
// decode command
|
// decode command
|
||||||
token_ptr = KEYBUF;
|
token_ptr = KEYBUF;
|
||||||
@ -196,6 +204,7 @@ void console() {
|
|||||||
comando_write();
|
comando_write();
|
||||||
}
|
}
|
||||||
else if(cmd == CMD_DIR || cmd == CMD_LS) {
|
else if(cmd == CMD_DIR || cmd == CMD_LS) {
|
||||||
|
get_token(filename, 32); // parse filename
|
||||||
comando_dir(cmd);
|
comando_dir(cmd);
|
||||||
}
|
}
|
||||||
else if(cmd == CMD_TIME) {
|
else if(cmd == CMD_TIME) {
|
||||||
@ -273,7 +282,7 @@ void console() {
|
|||||||
woz_puts("BAS ");
|
woz_puts("BAS ");
|
||||||
bas_info();
|
bas_info();
|
||||||
}
|
}
|
||||||
else if(cmd == CMD_DEL) {
|
else if(cmd == CMD_DEL || cmd == CMD_RM) {
|
||||||
get_token(filename, 32); // parse filename
|
get_token(filename, 32); // parse filename
|
||||||
if(filename[0] == 0) {
|
if(filename[0] == 0) {
|
||||||
woz_puts("?MISSING FILENAME");
|
woz_puts("?MISSING FILENAME");
|
||||||
@ -281,6 +290,31 @@ void console() {
|
|||||||
}
|
}
|
||||||
comando_del();
|
comando_del();
|
||||||
}
|
}
|
||||||
|
else if(cmd == CMD_MKDIR || cmd == CMD_MD) {
|
||||||
|
get_token(filename, 32); // parse filename
|
||||||
|
if(filename[0] == 0) {
|
||||||
|
woz_puts("?MISSING FILENAME");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
comando_mkdir();
|
||||||
|
}
|
||||||
|
else if(cmd == CMD_RMDIR || cmd == CMD_RD) {
|
||||||
|
get_token(filename, 32); // parse filename
|
||||||
|
if(filename[0] == 0) {
|
||||||
|
woz_puts("?MISSING FILENAME");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
comando_rmdir();
|
||||||
|
}
|
||||||
|
else if(cmd == CMD_CD) {
|
||||||
|
get_token(filename, 32); // parse filename
|
||||||
|
comando_cd();
|
||||||
|
}
|
||||||
|
else if(cmd == CMD_PWD) {
|
||||||
|
// PWD is a CD with no args
|
||||||
|
filename[0] = 0;
|
||||||
|
comando_cd();
|
||||||
|
}
|
||||||
else if(cmd == CMD_EXIT) {
|
else if(cmd == CMD_EXIT) {
|
||||||
woz_puts("BYE\r");
|
woz_puts("BYE\r");
|
||||||
woz_mon();
|
woz_mon();
|
||||||
|
Loading…
Reference in New Issue
Block a user