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

Committer:
earlz
Date:
Fri Sep 21 04:53:45 2012 +0000
Revision:
6:a4dff59ef214
Parent:
3:2bc2b0dce10e
Child:
7:2ac6752d47d2
Switched a virtual machine instead of trying to interpret directly. This is much easier for development, and should amazingly make it both faster and use less memory  :D

Who changed what in which revision?

UserRevisionLine numberNew contents of line
earlz 3:2bc2b0dce10e 1 #ifndef PLEARLZ_H
earlz 3:2bc2b0dce10e 2 #define PLEARLZ_H
earlz 3:2bc2b0dce10e 3
earlz 6:a4dff59ef214 4 #define MAXSTACK 64
earlz 6:a4dff59ef214 5 #define MAXCALLS 32
earlz 6:a4dff59ef214 6 #define MAXLINELENGTH 128
earlz 6:a4dff59ef214 7 #define DICTIONARYSTEP 4 //how much memory to reserve when doing a reallocation for resizing
earlz 6:a4dff59ef214 8 #define CODEBLOCKSTEP 16
earlz 6:a4dff59ef214 9
earlz 6:a4dff59ef214 10 enum ErrorType
earlz 6:a4dff59ef214 11 {
earlz 6:a4dff59ef214 12 None,
earlz 6:a4dff59ef214 13 StackOverflow,
earlz 6:a4dff59ef214 14 StackUnderflow
earlz 6:a4dff59ef214 15 };
earlz 6:a4dff59ef214 16
earlz 6:a4dff59ef214 17 //arguments are in the bytecode, not the stack! But, things like Add has no arguments and uses the stack
earlz 6:a4dff59ef214 18 //pointers are assumed 32-bit?
earlz 6:a4dff59ef214 19 enum Opcode
earlz 6:a4dff59ef214 20 {
earlz 6:a4dff59ef214 21 BranchTrue, //argument is 16 bit vaddress
earlz 6:a4dff59ef214 22 BranchFalse, //argument is 16bit vaddress
earlz 6:a4dff59ef214 23 Branch,
earlz 6:a4dff59ef214 24 Push, //argument is 32bit number
earlz 6:a4dff59ef214 25 Pop, //trashes top value on stack
earlz 6:a4dff59ef214 26 Call, //call. argument is WORD entry pointer in dictionary
earlz 6:a4dff59ef214 27 CallInt, //call internal argument is function pointer
earlz 6:a4dff59ef214 28 Add,
earlz 6:a4dff59ef214 29 Sub,
earlz 6:a4dff59ef214 30 Mul,
earlz 6:a4dff59ef214 31 Div,
earlz 6:a4dff59ef214 32 Mod,
earlz 6:a4dff59ef214 33 Cgt, //takes two integers and compares for greater than pushes 1 if so, 0 if not
earlz 6:a4dff59ef214 34 Clt, //less than
earlz 6:a4dff59ef214 35 Cgte, //greater than or equal
earlz 6:a4dff59ef214 36 Clte,
earlz 6:a4dff59ef214 37 Ceq,
earlz 6:a4dff59ef214 38 Cneq,
earlz 6:a4dff59ef214 39 LoadStr, //argument is variable length string ending with 0. Pushes address onto stack
earlz 6:a4dff59ef214 40 Load, //pushes the value pointed to by the argument
earlz 6:a4dff59ef214 41 Store, //pops a value and stores it in the memory pointed to by the argument
earlz 6:a4dff59ef214 42 New, //pushes a pointer to free memory for an integer
earlz 6:a4dff59ef214 43 NewVar, //pushes a pointer to memory. Size is specified by argument
earlz 6:a4dff59ef214 44 Delete, //pops a pointer and frees it.
earlz 6:a4dff59ef214 45 Ret //exit
earlz 6:a4dff59ef214 46 };
earlz 6:a4dff59ef214 47
earlz 6:a4dff59ef214 48 typedef void (*BuiltinFunction)(void);
earlz 6:a4dff59ef214 49 typedef struct
earlz 6:a4dff59ef214 50 {
earlz 6:a4dff59ef214 51 char name[12];
earlz 6:a4dff59ef214 52 enum Type{
earlz 6:a4dff59ef214 53 Constant,
earlz 6:a4dff59ef214 54 ConstantString,
earlz 6:a4dff59ef214 55 Builtin,
earlz 6:a4dff59ef214 56 Function
earlz 6:a4dff59ef214 57 } type;
earlz 6:a4dff59ef214 58 union valueunion{
earlz 6:a4dff59ef214 59 int intvalue;
earlz 6:a4dff59ef214 60 BuiltinFunction builtin;
earlz 6:a4dff59ef214 61 char *string;
earlz 6:a4dff59ef214 62 } value;
earlz 6:a4dff59ef214 63 } WordKey;
earlz 6:a4dff59ef214 64
earlz 6:a4dff59ef214 65 extern ErrorType pl_error;
earlz 3:2bc2b0dce10e 66
earlz 3:2bc2b0dce10e 67 int pl_shell();
earlz 3:2bc2b0dce10e 68
earlz 3:2bc2b0dce10e 69 static inline int is_whitespace(char c){
earlz 6:a4dff59ef214 70 return (c==' ') || (c=='\t') || (c=='\n') || (c=='\r');
earlz 3:2bc2b0dce10e 71 }
earlz 3:2bc2b0dce10e 72
earlz 3:2bc2b0dce10e 73 static inline int is_numeric(char c){
earlz 6:a4dff59ef214 74 return (c>='0') && (c<='9');
earlz 3:2bc2b0dce10e 75 }
earlz 3:2bc2b0dce10e 76
earlz 3:2bc2b0dce10e 77 static inline int is_alpha(char c){
earlz 6:a4dff59ef214 78 return ((c>='a') && (c<='z')) || ((c>='A') && (c<='Z'));
earlz 3:2bc2b0dce10e 79 }
earlz 3:2bc2b0dce10e 80
earlz 3:2bc2b0dce10e 81 static inline int is_identifier(char c){
earlz 6:a4dff59ef214 82 return is_alpha(c) || is_numeric(c) || (c=='_');
earlz 3:2bc2b0dce10e 83 }
earlz 3:2bc2b0dce10e 84
earlz 3:2bc2b0dce10e 85 static inline int is_quote(char c){
earlz 6:a4dff59ef214 86 return (c=='\"') || (c=='\'');
earlz 3:2bc2b0dce10e 87 }
earlz 6:a4dff59ef214 88 int forth_execute(uint8_t* block, int length);
earlz 6:a4dff59ef214 89 WordKey *pl_lookup(char* name);
earlz 6:a4dff59ef214 90 int pl_pop();
earlz 6:a4dff59ef214 91 void pl_push(int val);
earlz 6:a4dff59ef214 92
earlz 6:a4dff59ef214 93
earlz 6:a4dff59ef214 94
earlz 6:a4dff59ef214 95 //builtin functions
earlz 6:a4dff59ef214 96 void bi_print();
earlz 3:2bc2b0dce10e 97
earlz 3:2bc2b0dce10e 98
earlz 3:2bc2b0dce10e 99 #endif