A project to implement a console using the Mbed using VGA for video output and a PS/2 keyboard for the input. The eventual goal is to also include tools for managing SD cards, and a semi-self-hosting programming environment.
Dependencies: PS2_MbedConsole fastlib SDFileSystem vga640x480g_mbedconsole lightvm mbed
MbedConsole is a cool little project to have a self-contained computer all on an Mbed. So far it has VGA and PS/2 support and can stand alone without a computer powering it. Next planned features are SD card support and a lightweight programmable VM complete with a file editor and self-hosted assembler.
You can view additional details about it at http://earlz.net/tags/mbedconsole
Revision 3:2bc2b0dce10e, committed 2012-09-19
- Comitter:
- earlz
- Date:
- Wed Sep 19 04:44:07 2012 +0000
- Parent:
- 2:e2a4c5d17d59
- Child:
- 4:b44c27404035
- Commit message:
- Adding a small forth interpreter
Changed in this revision
--- a/mbedconsole.h Mon Sep 17 04:45:10 2012 +0000 +++ b/mbedconsole.h Wed Sep 19 04:44:07 2012 +0000 @@ -14,6 +14,9 @@ void shell_begin(); + + + extern Serial serial;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plEarlz.cpp Wed Sep 19 04:44:07 2012 +0000 @@ -0,0 +1,107 @@ +#include "mbedconsole.h" +#include "plEarlz.h" +#include <stdarg.h> +//Basically a non-conforming take on Forth, btw. + +inline int internal_captureline(void* pBuffer, char const* pFormatString, ...) +{ + char* pStringEnd = (char*)pBuffer + strlen((char*)pBuffer); + va_list valist; + + va_start(valist, pFormatString); + + return vsprintf(pStringEnd, pFormatString, valist); +} +void printheapstats() +{ + char buffer[256]; + __heapstats(internal_captureline, buffer); + vputs("Memory info: "); + vputs(buffer); +} + +struct pl_word +{ + +}; + +#define MAXSTACK 256 +#define MAXCALLS 64 +#define MAXLINELENGTH 128 + +int stackpos=0; +int pl_stack[MAXSTACK]; + +//int *pl_callstack[MAXCALLS]; + +enum WordType +{ + Unknown, + Number, + Word, + Quote +}; + +void execute_word(char *word) +{ + + +} + +void parse_line(char *line) +{ + int len=strlen(line); + char word[16]; + word[0]=0; + int wordpos=0; + WordType type=Unknown; + for(int i=0;i<len;i++) + { + char c=line[i]; + if(is_whitespace(c)) + { + if(word[0]!=0) + { + execute_word(word); + word[0]=0; + type=Unknown; + } + }else if(is_numeric(c)){ + type=Number; + word[wordpos]=c; + wordpos++; + }else if(is_quote(c)){ + vputs("This isn't supported yet foo!"); + }else{ + type=Word; + word[wordpos]=c; + wordpos++; + } + } +} + + + +int pl_shell() +{ + vputs(">>plEarlz -- A forth-ish shell<<\n"); + printheapstats(); + vputs("\n"); + char *line=(char*)malloc(MAXLINELENGTH); + sprintf(line, "Stack Size: %i; Max Recursion Level %i; Loaded WORDs: %i", MAXSTACK, MAXCALLS, 0); + vputs(line); + sprintf(line, "Max line length: %i", MAXLINELENGTH); + vputs(line); + char *tmp=(char*)malloc(32); //for constructing words/elements + while(1) + { + vputs("cmd> "); + vgetsl(line, MAXLINELENGTH); + line[MAXLINELENGTH-1]=0; + parse_line(line); + + } + return 0; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plEarlz.h Wed Sep 19 04:44:07 2012 +0000 @@ -0,0 +1,28 @@ +#ifndef PLEARLZ_H +#define PLEARLZ_H + + +int pl_shell(); + +static inline int is_whitespace(char c){ + return (c==' ') || (c=='\t') || (c=='\n') || (c=='\r'); +} + +static inline int is_numeric(char c){ + return (c>='0') && (c<='9'); +} + +static inline int is_alpha(char c){ + return ((c>='a') && (c<='z')) || ((c>='A') && (c<='Z')); +} + +static inline int is_identifier(char c){ + return is_alpha(c) || is_numeric(c) || (c=='_'); +} + +static inline int is_quote(char c){ + return (c=='\"') || (c=='\''); +} + + +#endif \ No newline at end of file
--- a/shell.cpp Mon Sep 17 04:45:10 2012 +0000 +++ b/shell.cpp Wed Sep 19 04:44:07 2012 +0000 @@ -1,51 +1,57 @@ -#include "mbedconsole.h" -LocalFileSystem local("local"); -void shell_begin(){ - vputs(">>Micro eMBEDded Shell v0.1<<\n"); - char *cmd=(char*)malloc(128); - bool valid=false; - while(1){ - vputs("> "); - vgetsl(cmd, 128); - vputc('\n'); - valid=false; - if(strlcmp(cmd, "help", 5)==0){ - valid=true; - vputs("Command list:\n"); - vputs("help -- this text \n"); - vputs("cls -- clear the screen\n"); - }else if(strlcmp(cmd,"cls",4)==0){ - valid=true; - vga_cls(); - vsetcursor(0,0); - }else if(strlcmp(cmd,"test", 5)==0){ - valid=true; - vputs("Opening File...Screen may flicker!\n"); // Drive should be marked as removed - wait(5); - FILE *fp = fopen("/local/test.txt", "w"); - if(!fp) { - vputs("File /local/test.txt could not be opened!\n"); - exit(1); - } - - wait(5.0); - - vputs("Writing Data...\n"); - fprintf(fp, "Hello World!"); - - wait(5.0); - - vputs("Closing File...\n"); - fclose(fp); - - // Drive should be restored. this is the same as just returning from main - wait(5); - } - if(!valid){ - vputs("invalid command!\n"); - } - } -} - - - +#include "mbedconsole.h" +#include "plEarlz.h" + + +LocalFileSystem local("local"); +void shell_begin(){ + vputs(">>Micro eMBEDded Shell v0.1<<\n"); + char *cmd=(char*)malloc(128); + bool valid=false; + while(1){ + vputs("> "); + vgetsl(cmd, 128); + vputc('\n'); + valid=false; + if(strlcmp(cmd, "help", 5)==0){ + valid=true; + vputs("Command list:\n"); + vputs("help -- this text \n"); + vputs("cls -- clear the screen\n"); + }else if(strlcmp(cmd,"cls",4)==0){ + valid=true; + vga_cls(); + vsetcursor(0,0); + }else if(strlcmp(cmd,"test", 5)==0){ + valid=true; + vputs("Opening File...Screen may flicker!\n"); // Drive should be marked as removed + wait(5); + FILE *fp = fopen("/local/test.txt", "w"); + if(!fp) { + vputs("File /local/test.txt could not be opened!\n"); + exit(1); + } + + wait(5.0); + + vputs("Writing Data...\n"); + fprintf(fp, "Hello World!"); + + wait(5.0); + + vputs("Closing File...\n"); + fclose(fp); + + // Drive should be restored. this is the same as just returning from main + wait(5); + }else if(strlcmp(cmd, "plearlz", 8)==0){ + valid=1; + pl_shell(); + } + if(!valid){ + vputs("invalid command!\n"); + } + } +} + + +