More DOS Commands

Added MKDIR, DEL, CD, and PWD
This commit is contained in:
Peter Weingartner 2021-10-14 20:26:16 -04:00
parent 0ad2ff8c6c
commit 22e19bcea6
7 changed files with 6770 additions and 6352 deletions

View file

@ -43,28 +43,31 @@ extern short cmd_showint(short channel, int argc, char * argv[]);
short g_current_channel = 0;
const t_cli_command g_cli_commands[] = {
{ "?", "? -- print this helpful message", cmd_help },
{ "HELP", "HELP -- print this helpful message", cmd_help },
{ "CLS", "CLS -- clear the screen", cmd_cls },
// { "DEL", "DEL <path> -- delete a file or directory", cmd_del },
{ "DIR", "DIR <path> -- print directory listing", cmd_dir },
{ "DUMP", "DUMP <address> [<count>] -- print a memory dump", mem_cmd_dump},
{ "LOAD", "LOAD <path> -- load a file into memory", cmd_load },
// { "MKDIR", "MKDIR <path> -- create a directory", cmd_mkdir },
{ "PEEK8", "PEEK8 <address> -- print the byte at the address in memory", mem_cmd_peek8 },
{ "PEEK16", "PEEK16 <address> -- print the 16-bit word at the address in memory", mem_cmd_peek16 },
{ "PEEK32", "PEEK32 <address> -- print the 32-bit long word at the address in memory", mem_cmd_peek32 },
{ "POKE8", "POKE8 <address> <value> -- write the byte value to the address in memory", mem_cmd_poke8 },
{ "POKE16", "POKE16 <address> <value> -- write the 16-bit word value to the address in memory", mem_cmd_poke16 },
{ "POKE32", "POKE32 <address> <value> -- write the 32-bit long word value to the address in memory", mem_cmd_poke32 },
// { "REN", "REN <old path> <new path> -- rename a file or directory", cmd_rename },
{ "RUN", "RUN <path> -- execute a binary file", cmd_run },
{ "GETTIME", "GETTIME -- prints the current time", cmd_gettime },
{ "SETTIME", "SETTIME -- sets the current time", cmd_settime },
{ "SHOWINT", "SHOWINT -- Show information about the interrupt registers", cmd_showint },
{ "SYSINFO", "SYSINFO -- prints information about the system", cmd_sysinfo },
{ "TESTIDE", "TESTIDE -- fetches and prints the IDE MBR repeatedly", cmd_testide },
{ "TYPE", "TYPE <path> -- print the contents of a text file", cmd_type },
{ "?", "? : print this helpful message", cmd_help },
{ "HELP", "HELP : print this helpful message", cmd_help },
{ "CD", "CD <path> : sets the current directory", cmd_cd },
{ "CLS", "CLS : clear the screen", cmd_cls },
{ "DEL", "DEL <path> : delete a file or directory", cmd_del },
{ "DIR", "DIR <path> : print directory listing", cmd_dir },
{ "DUMP", "DUMP <addr> [<count>] : print a memory dump", mem_cmd_dump},
{ "LOAD", "LOAD <path> : load a file into memory", cmd_load },
{ "MKDIR", "MKDIR <path> : create a directory", cmd_mkdir },
{ "PEEK8", "PEEK8 <addr> : print the byte at the address in memory", mem_cmd_peek8 },
{ "PEEK16", "PEEK16 <addr> : print the 16-bit word at the address in memory", mem_cmd_peek16 },
{ "PEEK32", "PEEK32 <addr> : print the 32-bit long word at the address in memory", mem_cmd_peek32 },
{ "POKE8", "POKE8 <addr> <value> : write the byte value to the address in memory", mem_cmd_poke8 },
{ "POKE16", "POKE16 <addr> <value> : write the 16-bit value to the address in memory", mem_cmd_poke16 },
{ "POKE32", "POKE32 <addr> <value> : write the 32-bit value to the address in memory", mem_cmd_poke32 },
{ "PWD", "PWD : prints the current directory", cmd_pwd },
// { "REN", "REN <old path> <new path> : rename a file or directory", cmd_rename },
{ "RUN", "RUN <path> : execute a binary file", cmd_run },
{ "GETTIME", "GETTIME : prints the current time", cmd_gettime },
{ "SETTIME", "SETTIME : sets the current time", cmd_settime },
{ "SHOWINT", "SHOWINT : Show information about the interrupt registers", cmd_showint },
{ "SYSINFO", "SYSINFO : prints information about the system", cmd_sysinfo },
{ "TESTIDE", "TESTIDE : fetches and prints the IDE MBR repeatedly", cmd_testide },
{ "TESTCREATE", "TESTCREATE <path> : tries to create a file", cmd_testcreate },
{ "TYPE", "TYPE <path> : print the contents of a text file", cmd_type },
{ 0, 0 }
};

View file

@ -43,6 +43,39 @@ short cmd_testide(short screen, int argc, char * argv[]) {
}
}
/*
* Test file creation
*/
short cmd_testcreate(short screen, int argc, char * argv[]) {
short n;
if (argc > 1) {
short channel = fsys_open(argv[1], FA_CREATE_NEW | FA_WRITE);
if (channel >= 0) {
char * message = "Hello, world!\n";
n = chan_write(channel, message, strlen(message));
if (n <= 0) {
print(screen, "Unable to write to file: ");
print_hex_16(screen, n);
print(screen, "\n");
}
fsys_close(channel);
return 0;
} else {
print(screen, "Unable to open file: ");
print_hex_16(screen, channel);
print(screen, "\n");
return -1;
}
} else {
print(screen, "USAGE: TESTCREATE <path>\n");
return -1;
}
}
short cmd_run(short screen, int argc, char * argv[]) {
TRACE("cmd_run");
@ -68,9 +101,10 @@ short cmd_mkdir(short screen, int argc, char * argv[]) {
log_num(LOG_ERROR, "Unable to create directory: ", result);
return result;
}
} else {
print(screen, "USAGE: MKDIR <path>\n");
return -1;
}
return 0;
}
/*
@ -86,11 +120,55 @@ short cmd_del(short screen, int argc, char * argv[]) {
log_num(LOG_ERROR, "Unable to delete: ", result);
return result;
}
} else {
print(screen, "USAGE: DEL <path>\n");
return -1;
}
}
/*
* Change the directory
*/
short cmd_cd(short screen, int argc, char * argv[]) {
TRACE("cmd_cd");
if (argc > 1) {
short result = fsys_setcwd(argv[1]);
if (result < 0) {
log_num(LOG_ERROR, "Unable to change directory: ", result);
return result;
} else {
print(screen, "Changed to: ");
print(screen, argv[1]);
print(screen, "\n");
}
} else {
print(screen, "USAGE: CD <path>\n");
return -1;
}
return 0;
}
/*
* Change the directory
*/
short cmd_pwd(short screen, int argc, char * argv[]) {
char buffer[128];
TRACE("cmd_pwd");
short result = fsys_getcwd(buffer, 128);
if (result < 0) {
log_num(LOG_ERROR, "Unable to get directory: ", result);
return result;
} else {
print(screen, buffer);
return 0;
}
}
/*
* Rename a file or directory
*/
@ -138,6 +216,7 @@ short cmd_dir(short screen, int argc, char * argv[]) {
if ((my_file.attributes & AM_HID) == 0) {
if (my_file.attributes & AM_DIR) {
sprintf(buffer, "%s/\n", my_file.name);
chan_write(screen, buffer, strlen(buffer));
} else {
if (my_file.size < 1024) {

View file

@ -10,6 +10,11 @@
*/
extern short cmd_testide(short screen, int argc, char * argv[]);
/*
* Test file creation
*/
extern short cmd_testcreate(short screen, int argc, char * argv[]);
/*
* Execute a binary file
*/
@ -30,6 +35,16 @@ extern short cmd_mkdir(short screen, int argc, char * argv[]);
*/
extern short cmd_del(short screen, int argc, char * argv[]);
/*
* Set the current working directory
*/
extern short cmd_cd(short screen, int argc, char * argv[]);
/*
* Print the current working directory
*/
extern short cmd_pwd(short screen, int argc, char * argv[]);
/*
* Rename a file or directory
*/

View file

@ -176,7 +176,13 @@ short fsys_opendir(const char * path) {
return ERR_OUT_OF_HANDLES;
} else {
/* Try to open the directory */
fres = f_opendir(&g_directory[dir], path);
if (path[0] == 0) {
char cwd[128];
fsys_getcwd(cwd, 128);
fres = f_opendir(&g_directory[dir], cwd);
} else {
fres = f_opendir(&g_directory[dir], path);
}
if (fres != FR_OK) {
/* If there was a problem, return an error number */
return fatfs_to_foenix(fres);
@ -286,7 +292,18 @@ short fsys_findnext(short dir, p_file_info file) {
* 0 on success, negative number on failure.
*/
short fsys_mkdir(const char * path) {
return -1;
FRESULT result;
TRACE("fsys_mkdir");
result = f_mkdir(path);
if (result == FR_OK) {
log_num(LOG_ERROR, "fsys_mkdir error: ", result);
return 0;
} else {
log_num(LOG_ERROR, "fsys_mkdir error: ", result);
return fatfs_to_foenix(result);
}
}
/**
@ -299,7 +316,15 @@ short fsys_mkdir(const char * path) {
* 0 on success, negative number on failure.
*/
short fsys_delete(const char * path) {
return -1;
FRESULT result;
result = f_unlink(path);
if (result == FR_OK) {
return 0;
} else {
log_num(LOG_ERROR, "fsys_delete error: ", result);
return fatfs_to_foenix(result);
}
}
/**
@ -326,7 +351,15 @@ short fsys_rename(const char * old_path, const char * new_path) {
* 0 on success, negative number on failure.
*/
short fsys_setcwd(const char * path) {
return -1;
FRESULT result;
result = f_chdir(path);
if (result == FR_OK) {
return 0;
} else {
log_num(LOG_ERROR, "fsys_setcwd error: ", result);
return fatfs_to_foenix(result);
}
}
/**
@ -340,7 +373,16 @@ short fsys_setcwd(const char * path) {
* 0 on success, negative number on failure.
*/
short fsys_getcwd(char * path, short size) {
return -1;
FRESULT result;
f_chdrive("");
result = f_getcwd(path);
if (result == FR_OK) {
return 0;
} else {
log_num(LOG_ERROR, "fsys_setcwd error: ", result);
return fatfs_to_foenix(result);
}
}
short fchan_init() {
@ -427,6 +469,7 @@ short fchan_write(p_channel chan, const unsigned char * buffer, short size) {
if (result == FR_OK) {
return (short)total_written;
} else {
log_num(LOG_ERROR, "fchan_write error: ", result);
return fatfs_to_foenix(result);
}
}

View file

@ -153,7 +153,7 @@
/ on character encoding. When LFN is not enabled, these options have no effect. */
#define FF_FS_RPATH 0
#define FF_FS_RPATH 2
/* This option configures support for relative path.
/
/ 0: Disable relative path and remove related functions.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff