mirror of
https://github.com/nippur72/apple1-videocard-lib.git
synced 2024-09-27 06:54:25 +00:00
Compare commits
No commits in common. "db9f38b72206c7272b976890272178c90168d4ba" and "c83a357ab662880c4897f5aa89f807c15f50d912" have entirely different histories.
db9f38b722
...
c83a357ab6
@ -46,7 +46,7 @@ RUN STARTREK
|
||||
|
||||
Loads a file from the SD card. `filename` refers to a "tagged file name" described above. For convenience, `filename` can be partially given, the first matching file will be loaded.
|
||||
|
||||
`SAVE filename [start] [end]`
|
||||
`SAVE filename start end`
|
||||
|
||||
Saves a file to the SD card. If `start` and `end` are specified, a binary file with tag `#06` will be created with the memory content from the address range `start`-`end` (included).
|
||||
If `start` and `end` are not specified, the BASIC program currently loaded in memory will be created with the corresponding `#F1` tag.
|
||||
|
@ -245,10 +245,6 @@ const char *DIR_CREATED = " (DIR) CREATED";
|
||||
const char *CANT_CD_DIR = "?CAN'T CHANGE DIR";
|
||||
const char *NOT_A_DIRECTORY = "?NOT A DIRECTORY";
|
||||
|
||||
// file structures used to operate with the SD card
|
||||
File myFile;
|
||||
File myDir;
|
||||
|
||||
void setup() {
|
||||
// debug on serial
|
||||
Serial.begin(9600);
|
||||
@ -289,7 +285,76 @@ void setup() {
|
||||
// **************************************************************************************
|
||||
// **************************************************************************************
|
||||
|
||||
int list_files;
|
||||
/*
|
||||
// recursive print directory
|
||||
void printDirectory(File dir, int numTabs) {
|
||||
|
||||
while (true) {
|
||||
if(TIMEOUT) break;
|
||||
|
||||
File entry = dir.openNextFile();
|
||||
if (! entry) {
|
||||
// no more files
|
||||
break;
|
||||
}
|
||||
|
||||
// indentazione delle sottodirectory
|
||||
for (uint8_t i = 0; i < numTabs; i++) {
|
||||
Serial.print('\t');
|
||||
send_byte_to_cpu(32);
|
||||
send_byte_to_cpu(32);
|
||||
send_byte_to_cpu(32);
|
||||
}
|
||||
|
||||
// nome del file
|
||||
char *msg;
|
||||
entry.getName(filename, 64);
|
||||
msg = filename;
|
||||
|
||||
Serial.print(msg);
|
||||
for(int t=0; t<strlen(msg); t++) {
|
||||
send_byte_to_cpu(msg[t]);
|
||||
}
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
Serial.println("/");
|
||||
send_byte_to_cpu('/');
|
||||
send_byte_to_cpu('\r');
|
||||
printDirectory(entry, numTabs + 1);
|
||||
} else {
|
||||
// files have sizes, directories do not
|
||||
Serial.print("\t\t");
|
||||
send_byte_to_cpu(' ');
|
||||
send_byte_to_cpu(' ');
|
||||
|
||||
// file size
|
||||
//Serial.println(entry.size(), DEC);
|
||||
//msg = itoa(entry.size());
|
||||
//for(int t=0; t<strlen(msg); t++) {
|
||||
// send_byte_to_cpu(msg[t]);
|
||||
//}
|
||||
send_byte_to_cpu('\r');
|
||||
|
||||
}
|
||||
entry.close();
|
||||
}
|
||||
}
|
||||
|
||||
// versione ricorsiva (disabilitata)
|
||||
void comando_dir_alternate() {
|
||||
Serial.println(F("command DIR received from CPU"));
|
||||
|
||||
File root = SD.open("/");
|
||||
printDirectory(root, 0);
|
||||
root.close();
|
||||
|
||||
// terminates
|
||||
send_byte_to_cpu(0);
|
||||
Serial.println(F("command DIR ended"));
|
||||
}
|
||||
*/
|
||||
|
||||
// versione tipo MS-DOS
|
||||
void comando_dir(int command) {
|
||||
Serial.println(F("command DIR received from CPU"));
|
||||
|
||||
@ -297,152 +362,128 @@ void comando_dir(int command) {
|
||||
receive_string_from_cpu(filename);
|
||||
if(TIMEOUT) return;
|
||||
Serial.print(F("dir to read: "));
|
||||
Serial.println(filename);
|
||||
Serial.println(filename);
|
||||
|
||||
File dir;
|
||||
|
||||
if(filename[0]==0) {
|
||||
// no argument given, use cd_path
|
||||
strcpy(filename, cd_path);
|
||||
}
|
||||
|
||||
myDir = SD.open(filename);
|
||||
dir = SD.open(filename);
|
||||
|
||||
if(!myDir) {
|
||||
if(!dir) {
|
||||
Serial.println(F("dir not found"));
|
||||
send_byte_to_cpu(ERR_RESPONSE);
|
||||
send_string_to_cpu(DIR_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
// dir opened OK
|
||||
send_byte_to_cpu(OK_RESPONSE);
|
||||
// *** lists directories first
|
||||
print_dir_entry(dir, 0, command);
|
||||
if(TIMEOUT) return;
|
||||
|
||||
// *** then files
|
||||
dir.rewind();
|
||||
print_dir_entry(dir, 1, command);
|
||||
dir.close();
|
||||
|
||||
list_files = 0; // starts listing dirs (0) then files (1)
|
||||
if(TIMEOUT) return;
|
||||
|
||||
while(true) {
|
||||
int c = receive_byte_from_cpu();
|
||||
if(TIMEOUT) {
|
||||
Serial.println(F("timeout while receiving 'next line' byte"));
|
||||
break;
|
||||
} else if(c == WAIT_RESPONSE) {
|
||||
// do nothing, just keep listening
|
||||
continue;
|
||||
} else if(c == ERR_RESPONSE) {
|
||||
// user asked to abort dir listing
|
||||
Serial.println(F("dir interrupted by the user"));
|
||||
break;
|
||||
} else if(c == OK_RESPONSE) {
|
||||
if(!send_next_dir_line(command)) {
|
||||
Serial.println(F("dir terminated"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
myDir.close();
|
||||
// terminates
|
||||
send_byte_to_cpu(0);
|
||||
Serial.println(F("command DIR ended"));
|
||||
}
|
||||
|
||||
int send_next_dir_line(int command) {
|
||||
// user wants a new line of dir listing
|
||||
void print_dir_entry(File dir, int list_files, int command) {
|
||||
while (true) {
|
||||
File entry = dir.openNextFile();
|
||||
|
||||
while(1) {
|
||||
myFile = myDir.openNextFile();
|
||||
if(!entry) {
|
||||
// no more files
|
||||
break;
|
||||
}
|
||||
|
||||
// send file size or directory
|
||||
entry.getName(filename, 64);
|
||||
strtoupper(filename);
|
||||
|
||||
if(!myFile) {
|
||||
if(list_files==0) {
|
||||
list_files++;
|
||||
myDir.rewind();
|
||||
continue;
|
||||
if((list_files == 0 && entry.isDirectory()) || (list_files == 1 && !entry.isDirectory())) {
|
||||
if(entry.isDirectory()) {
|
||||
if(command != CMD_DIR) {
|
||||
sprintf(tmp, "(DIR) %s\r", filename);
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.println(tmp);
|
||||
}
|
||||
else {
|
||||
sprintf(tmp, "%-15s (DIR)\r", filename);
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.println(tmp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no more lines to send
|
||||
myDir.close();
|
||||
send_byte_to_cpu(ERR_RESPONSE);
|
||||
return 0; // no more lines
|
||||
}
|
||||
}
|
||||
if(command != CMD_DIR) {
|
||||
// BUG the following line does not work
|
||||
// sprintf(tmp, "%5d %s", entry.size(), filename);
|
||||
// use this instead
|
||||
sprintf(tmp, "%5d ", entry.size());
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.print(tmp);
|
||||
|
||||
if(myFile.isDirectory() && list_files == 0) break;
|
||||
if(!myFile.isDirectory() && list_files == 1) break;
|
||||
}
|
||||
|
||||
// send the text line
|
||||
send_byte_to_cpu(OK_RESPONSE);
|
||||
send_directory_entry(command);
|
||||
myFile.close();
|
||||
return 1; // more lines to send
|
||||
}
|
||||
print_string_to_cpu(filename);
|
||||
Serial.println(filename);
|
||||
|
||||
void send_directory_entry(int command) {
|
||||
myFile.getName(filename, 64);
|
||||
strtoupper(filename);
|
||||
|
||||
if(myFile.isDirectory()) {
|
||||
if(command != CMD_DIR) {
|
||||
sprintf(tmp, "(DIR) %s\r", filename);
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.println(tmp);
|
||||
}
|
||||
else {
|
||||
sprintf(tmp, "%-15s (DIR)\r", filename);
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.println(tmp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(command != CMD_DIR) {
|
||||
// BUG the following line does not work
|
||||
// sprintf(tmp, "%5d %s", entry.size(), filename);
|
||||
// use this instead
|
||||
sprintf(tmp, "%5d ", myFile.size());
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.print(tmp);
|
||||
|
||||
print_string_to_cpu(filename);
|
||||
Serial.println(filename);
|
||||
|
||||
send_byte_to_cpu('\r');
|
||||
}
|
||||
else {
|
||||
char type[5];
|
||||
char address[5];
|
||||
|
||||
strcpy(type,"");
|
||||
strcpy(address, "");
|
||||
|
||||
char *x = strchr(filename, '#');
|
||||
if(x != NULL) {
|
||||
*x++ = 0;
|
||||
if(x[0]=='0' && x[1]=='6') {
|
||||
strcpy(type,"BIN ");
|
||||
strcpy(address,x+2);
|
||||
send_byte_to_cpu('\r');
|
||||
}
|
||||
else if(x[0]=='F' && x[1]=='1') {
|
||||
strcpy(type,"BAS ");
|
||||
strcpy(address,x+2);
|
||||
}
|
||||
else {
|
||||
strcpy(type,"??? ");
|
||||
|
||||
char type[5];
|
||||
char address[5];
|
||||
|
||||
strcpy(type,"");
|
||||
strcpy(address, "");
|
||||
|
||||
char *x = strchr(filename, '#');
|
||||
if(x != NULL) {
|
||||
*x++ = 0;
|
||||
if(x[0]=='0' && x[1]=='6') {
|
||||
strcpy(type,"BIN ");
|
||||
strcpy(address,x+2);
|
||||
}
|
||||
else if(x[0]=='F' && x[1]=='1') {
|
||||
strcpy(type,"BAS ");
|
||||
strcpy(address,x+2);
|
||||
}
|
||||
else {
|
||||
strcpy(type,"??? ");
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(tmp, "%-15s", filename);
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.print(filename);
|
||||
|
||||
sprintf(tmp, "%6d ", entry.size());
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.print(tmp);
|
||||
|
||||
print_string_to_cpu(type);
|
||||
Serial.print(type);
|
||||
|
||||
print_string_to_cpu(address);
|
||||
Serial.println(address);
|
||||
|
||||
send_byte_to_cpu('\r');
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(tmp, "%-15s", filename);
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.print(filename);
|
||||
|
||||
sprintf(tmp, "%6d ", myFile.size());
|
||||
print_string_to_cpu(tmp);
|
||||
Serial.print(tmp);
|
||||
|
||||
print_string_to_cpu(type);
|
||||
Serial.print(type);
|
||||
|
||||
print_string_to_cpu(address);
|
||||
Serial.println(address);
|
||||
|
||||
send_byte_to_cpu('\r');
|
||||
}
|
||||
if(TIMEOUT) break;
|
||||
}
|
||||
}
|
||||
entry.close();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
|
||||
|
||||
// **************************************************************************************
|
||||
// **************************************************************************************
|
||||
// ********************************* CMD_READ ******************************************
|
||||
@ -466,7 +507,7 @@ void comando_read() {
|
||||
}
|
||||
|
||||
// open the file
|
||||
myFile = SD.open(filename);
|
||||
File myFile = SD.open(filename);
|
||||
if(!myFile) {
|
||||
Serial.println(F("error opening file"));
|
||||
send_byte_to_cpu(ERR_RESPONSE);
|
||||
@ -562,7 +603,7 @@ void comando_write() {
|
||||
}
|
||||
|
||||
// open the file
|
||||
myFile = SD.open(filename, FILE_WRITE);
|
||||
File myFile = SD.open(filename, FILE_WRITE);
|
||||
if(!myFile) {
|
||||
Serial.println(F("error opening file for write"));
|
||||
send_byte_to_cpu(ERR_RESPONSE);
|
||||
@ -638,7 +679,7 @@ void comando_load() {
|
||||
}
|
||||
|
||||
// open the file
|
||||
myFile = SD.open(filename);
|
||||
File myFile = SD.open(filename);
|
||||
if(!myFile) {
|
||||
Serial.println(F("error opening file"));
|
||||
send_byte_to_cpu(ERR_RESPONSE);
|
||||
@ -728,72 +769,50 @@ int matchname(char *filename, char *dest) {
|
||||
else Serial.println(F("scanning the file_path directory"));
|
||||
|
||||
// open the directory containing the file
|
||||
myDir = SD.open(strlen(file_path)==0 ? cd_path : file_path);
|
||||
File dir = SD.open(strlen(file_path)==0 ? cd_path : file_path);
|
||||
|
||||
if(!myDir) return 0;
|
||||
if(!dir) return 0;
|
||||
|
||||
Serial.println(F("dir opened"));
|
||||
|
||||
// scans twice: scanmode=0 for exact match, scanmode=1 for partial match
|
||||
for(int scanmode=0;scanmode<=1;scanmode++) {
|
||||
if(scanmode==0) Serial.println(F("scanning for exact match..."));
|
||||
if(scanmode==1) Serial.println(F("scanning for partial match..."));
|
||||
|
||||
// scan all the directory
|
||||
while(1) {
|
||||
// scan all the directory
|
||||
while(1) {
|
||||
|
||||
send_byte_to_cpu(WAIT_RESPONSE);
|
||||
if(TIMEOUT) return 0;
|
||||
|
||||
myFile = myDir.openNextFile();
|
||||
|
||||
// end of directory
|
||||
if(!myFile) {
|
||||
if(scanmode == 0) {
|
||||
// exact match not found, rewind the directory and scan fot partial match
|
||||
myDir.rewind();
|
||||
break;
|
||||
}
|
||||
else if(scanmode == 1) {
|
||||
// match not found even with partial match, return error
|
||||
myDir.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// copy filename in dest and closes it
|
||||
myFile.getName(dest, 64);
|
||||
strtoupper(dest);
|
||||
myFile.close();
|
||||
|
||||
Serial.print(F("file entry: "));
|
||||
Serial.println(dest);
|
||||
|
||||
// verify the match
|
||||
int len = strlen(filename);
|
||||
bool match_found = strncmp(file_name, dest, len) == 0;
|
||||
|
||||
// enforce exact match
|
||||
if(scanmode == 0) match_found = match_found && dest[strlen(filename)] == '#';
|
||||
|
||||
if(match_found) {
|
||||
if(scanmode==0) Serial.println(F("found an exact match"));
|
||||
if(scanmode==1) Serial.println(F("found a partial match"));
|
||||
|
||||
// matching, dest already contains the matched file name
|
||||
|
||||
// if file_path is empty then it's current directory, do nothing
|
||||
// else file_path needs to be combined with file name
|
||||
if(file_path[0]!=0) {
|
||||
Serial.println(F("not on current dir, joining paths"));
|
||||
strcpy(filename, dest);
|
||||
if(file_path[0]=='/' && file_path[1]==0) sprintf(dest,"/%s", filename); // case of root folder
|
||||
else sprintf(dest,"%s/%s", file_path, filename); // case of normal nested folder
|
||||
}
|
||||
myDir.close();
|
||||
return 1;
|
||||
}
|
||||
send_byte_to_cpu(WAIT_RESPONSE);
|
||||
if(TIMEOUT) return 0;
|
||||
|
||||
File F = dir.openNextFile();
|
||||
|
||||
// end of directory
|
||||
if(!F) {
|
||||
dir.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// copy filename in dest and closes it
|
||||
F.getName(dest, 64);
|
||||
strtoupper(dest);
|
||||
F.close();
|
||||
|
||||
Serial.println(F("file entry:"));
|
||||
Serial.println(dest);
|
||||
|
||||
// verify the match
|
||||
if(strncmp(file_name, dest, strlen(filename))==0) {
|
||||
Serial.println(F("it is matching!"));
|
||||
// matching, dest already contains the matched file name
|
||||
|
||||
// if file_path is empty then it's current directory, do nothing
|
||||
// else file_path needs to be combined with file name
|
||||
if(file_path[0]!=0) {
|
||||
Serial.println(F("not on current dir, joining paths"));
|
||||
strcpy(filename, dest);
|
||||
if(file_path[0]=='/' && file_path[1]==0) sprintf(dest,"/%s", filename); // case of root folder
|
||||
else sprintf(dest,"%s/%s", file_path, filename); // case of normal nested folder
|
||||
}
|
||||
dir.close();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -821,7 +840,7 @@ void comando_del() {
|
||||
if(TIMEOUT) return;
|
||||
|
||||
// open the file for deletion
|
||||
myFile = SD.open(filename, FILE_WRITE);
|
||||
File myFile = SD.open(filename, FILE_WRITE);
|
||||
if(!myFile) {
|
||||
Serial.println(F("error opening file for deletion"));
|
||||
send_string_to_cpu(CANT_DELETE_FILE);
|
||||
@ -1007,7 +1026,7 @@ void comando_cd() {
|
||||
return;
|
||||
}
|
||||
|
||||
myFile = SD.open(filename);
|
||||
File myFile = SD.open(filename);
|
||||
bool isDir = myFile.isDirectory();
|
||||
myFile.close();
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
void comando_dir(byte cmd) {
|
||||
// send DIR command
|
||||
void comando_dir(byte cmd) {
|
||||
send_byte_to_MCU(cmd);
|
||||
if(TIMEOUT) return;
|
||||
|
||||
@ -8,49 +6,5 @@ void comando_dir(byte cmd) {
|
||||
send_string_to_MCU(filename);
|
||||
if(TIMEOUT) return;
|
||||
|
||||
// get MCU response
|
||||
byte data = receive_byte_from_MCU();
|
||||
if(data == ERR_RESPONSE) {
|
||||
print_string_response();
|
||||
return;
|
||||
}
|
||||
|
||||
byte paused = 0;
|
||||
while(1) {
|
||||
if(!paused) {
|
||||
// ask for a text line
|
||||
send_byte_to_MCU(OK_RESPONSE);
|
||||
if(TIMEOUT) break;
|
||||
|
||||
// get MCU response byte
|
||||
data = receive_byte_from_MCU();
|
||||
if(TIMEOUT) break;
|
||||
|
||||
if(data == ERR_RESPONSE) break; // no more lines of text
|
||||
|
||||
// OK_RESPONSE, MCU will send a line of text terminated by '\r'
|
||||
|
||||
while(1) {
|
||||
data = receive_byte_from_MCU();
|
||||
if(TIMEOUT) return;
|
||||
woz_putc(data);
|
||||
if(data == '\r') break; // line terminator
|
||||
data = apple1_readkey();
|
||||
if(data==27) paused = 27;
|
||||
else if(data!=0) paused = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(paused==27) {
|
||||
send_byte_to_MCU(ERR_RESPONSE);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
send_byte_to_MCU(WAIT_RESPONSE);
|
||||
data = apple1_readkey();
|
||||
if(data == 13) paused = 0;
|
||||
else if(data == 27) paused = 27;
|
||||
}
|
||||
}
|
||||
}
|
||||
print_string_response_brk();
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ void console() {
|
||||
// do not print extra newline for commands that do not have output (CD)
|
||||
if(cmd != CMD_CD) woz_putc('\r');
|
||||
|
||||
// prints the current path before the prompt
|
||||
// performs a PWD
|
||||
comando_pwd();
|
||||
|
||||
apple1_input_line_prompt(KEYBUF, KEYBUFLEN);
|
||||
@ -251,11 +251,8 @@ void console() {
|
||||
}
|
||||
TIMEOUT_MAX = tmpword;
|
||||
}
|
||||
woz_puts("TIMEOUT MAX:");
|
||||
woz_puts("TIMEOUT_MAX: ");
|
||||
woz_print_hexword(TIMEOUT_MAX);
|
||||
woz_puts(" CURR:");
|
||||
woz_print_hexword(TIMEOUT_RANGE);
|
||||
TIMEOUT_RANGE = 0;
|
||||
}
|
||||
else if(cmd == CMD_LOAD || cmd == CMD_RUN) {
|
||||
get_token(filename, 32); // parse filename
|
||||
|
@ -69,7 +69,6 @@ __address(14) word len;
|
||||
__address(16) byte hex_to_word_ok;
|
||||
__address(17) byte cmd;
|
||||
__address(18) byte *token_ptr;
|
||||
__address(20) word TIMEOUT_RANGE = 0;
|
||||
|
||||
#define MCU_STROBE_HIGH 128
|
||||
#define MCU_STROBE_LOW 0
|
||||
@ -80,7 +79,6 @@ void wait_mcu_strobe(byte v) {
|
||||
TIMEOUT_CNT = 0;
|
||||
while(v ^ MCU_STROBE) {
|
||||
TIMEOUT_CNT++;
|
||||
if(TIMEOUT_CNT > TIMEOUT_RANGE) TIMEOUT_RANGE = TIMEOUT_CNT;
|
||||
if(TIMEOUT_CNT > TIMEOUT_MAX) {
|
||||
TIMEOUT = 1;
|
||||
break;
|
||||
@ -143,7 +141,6 @@ void print_string_response() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// print a string sent by the MCU, breakable via keyboard
|
||||
void print_string_response_brk() {
|
||||
byte print_on = 1;
|
||||
@ -158,34 +155,6 @@ void print_string_response_brk() {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
//
|
||||
void print_string_response_linebyline() {
|
||||
byte paused = 0;
|
||||
byte print_on = 1;
|
||||
while(1) {
|
||||
// ask for a line of text
|
||||
send_byte_to_MCU(OK_RESPONSE);
|
||||
if(TIMEOUT) break;
|
||||
|
||||
// get MCU response byte
|
||||
byte data = receive_byte_from_MCU();
|
||||
if(TIMEOUT) break;
|
||||
if(data == ERR_RESPONSE) break; // no more lines of text
|
||||
|
||||
// next is a line of text as a string
|
||||
print_string_response();
|
||||
if(TIMEOUT) break;
|
||||
|
||||
if(apple1_readkey()) {
|
||||
woz_puts("*BRK*\r");
|
||||
print_on = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void receive_word_from_mcu() {
|
||||
*((byte *)&tmpword) = receive_byte_from_MCU();
|
||||
|
Loading…
Reference in New Issue
Block a user