From 39e5bd0c18a347a5974d7800b640b61325ac294d Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 12 Sep 2013 00:04:51 +0200 Subject: [PATCH] testcode/lib/tinyshell.c: add 'verbose' and 'cls' commands; add SP check --- testcode/lib/tinyshell.c | 75 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/testcode/lib/tinyshell.c b/testcode/lib/tinyshell.c index f4a18126b..c325f3947 100644 --- a/testcode/lib/tinyshell.c +++ b/testcode/lib/tinyshell.c @@ -5,12 +5,15 @@ #define VERSION_ASC "0.90" -#define KEYB_BUFSZ 80 -#define PROMPT ">>> " #ifdef __ATARI__ #define UPPERCASE /* define (e.g. for Atari) to convert filenames etc. to upper case */ #endif +#define CHECK_SP + +#define KEYB_BUFSZ 80 +#define PROMPT ">>> " + #include #include #include @@ -26,6 +29,10 @@ #include #include +#ifdef CHECK_SP +extern unsigned int getsp(void); /* comes from getsp.s */ +#endif + #define CMD_NOTHING 0 #define CMD_INVALID 1 #define CMD_HELP 2 @@ -38,7 +45,10 @@ #define CMD_RENAME 9 #define CMD_COPY 10 #define CMD_PWD 11 +#define CMD_CLS 12 +#define CMD_VERBOSE 13 +static unsigned char verbose; static unsigned char terminate; static unsigned char cmd; static unsigned char *cmd_asc, *arg1, *arg2, *arg3; @@ -68,6 +78,10 @@ struct cmd_table { { "mv", CMD_RENAME }, { "ren", CMD_RENAME }, { "pwd", CMD_PWD }, +#ifdef __CC65__ + { "cls", CMD_CLS }, +#endif + { "verbose", CMD_VERBOSE }, { NULL, 0 } }; @@ -82,6 +96,22 @@ static void get_command(void) { unsigned char i = 0; +#ifdef CHECK_SP + static char firstcall = 1; + static unsigned int good_sp; + unsigned int sp; + if (firstcall) + sp = good_sp = getsp(); + else + sp = getsp(); + + if (sp != good_sp) { + printf("SP: 0x%04X ***MISMATCH*** 0x%04X\n", sp, good_sp); + } + else if (verbose) + printf("SP: 0x%04X\n", sp); +#endif + arg1 = arg2 = arg3 = NULL; /* issue prompt */ @@ -132,6 +162,10 @@ static void cmd_help(void) puts("cd, chdir - change directory or drive"); puts("md, mkdir - make directory or drive"); puts("rd, rmdir - remove directory or drive"); +#ifdef __CC65__ + puts("cls - clear screen"); +#endif + puts("verbose - set verbosity level"); puts("sorry, you cannot start programs here"); } @@ -173,6 +207,8 @@ static void cmd_ls(void) else arg = "."; + if (verbose) + printf("Buffer addr: %p\n", arg); dir = opendir(arg); #ifdef __ATARI__ if (need_free) free(arg); @@ -262,6 +298,8 @@ static void cmd_pwd(void) printf("malloc %u bytes failed: %s\n", MAXPATHLEN, strerror(errno)); return; } + if (verbose) + printf("Buffer addr: %p\n", buf); if (!getcwd(buf, MAXPATHLEN)) { printf("getcwd failed: %s\n", strerror(errno)); free(buf); @@ -309,6 +347,8 @@ static void cmd_copy(void) printf("malloc %u bytes failed: %s\n", cpbuf_sz, strerror(errno)); return; } + if (verbose) + printf("Buffer addr: %p\n", buf); while (1) { if (srcfd == -1) { @@ -349,6 +389,33 @@ static void cmd_copy(void) if (dstfd >= 0) close(dstfd); } +#ifdef __CC65__ +static void cmd_cls(void) +{ + printf("\f"); +} +#endif + +static void cmd_verbose(void) +{ + unsigned long verb; + char *endptr; + + if (!arg1 || arg2) { + puts("usage: verbose "); + return; + } + + verb = strtoul(arg1, &endptr, 10); + if (verb > 255 || *endptr) { + printf("invalid verbosity level 0x%x\n", *endptr); + return; + } + + verbose = verb; + printf("verbosity level set to %d\n", verbose); +} + static void run_command(void) { switch (cmd) { @@ -365,6 +432,10 @@ static void run_command(void) case CMD_PWD: cmd_pwd(); return; case CMD_RENAME: cmd_rename(); return; case CMD_COPY: cmd_copy(); return; +#ifdef __CC65__ + case CMD_CLS: cmd_cls(); return; +#endif + case CMD_VERBOSE: cmd_verbose(); return; } } -- 2.39.5