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:
Sat Sep 22 03:00:55 2012 +0000
Revision:
7:2ac6752d47d2
Parent:
6:a4dff59ef214
Child:
8:f356684767ef
fuck pointers

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 7:2ac6752d47d2 40 LoadConst, //pushes the value pointed to by the argument
earlz 7:2ac6752d47d2 41 StoreConst, //pops a value and stores it in the memory pointed to by the argument
earlz 7:2ac6752d47d2 42 Load, //same as above, except the address is popped first.
earlz 7:2ac6752d47d2 43 Store,
earlz 6:a4dff59ef214 44 New, //pushes a pointer to free memory for an integer
earlz 6:a4dff59ef214 45 NewVar, //pushes a pointer to memory. Size is specified by argument
earlz 6:a4dff59ef214 46 Delete, //pops a pointer and frees it.
earlz 6:a4dff59ef214 47 Ret //exit
earlz 6:a4dff59ef214 48 };
earlz 6:a4dff59ef214 49
earlz 6:a4dff59ef214 50 typedef void (*BuiltinFunction)(void);
earlz 6:a4dff59ef214 51 typedef struct
earlz 6:a4dff59ef214 52 {
earlz 6:a4dff59ef214 53 char name[12];
earlz 6:a4dff59ef214 54 enum Type{
earlz 6:a4dff59ef214 55 Constant,
earlz 6:a4dff59ef214 56 ConstantString,
earlz 6:a4dff59ef214 57 Builtin,
earlz 6:a4dff59ef214 58 Function
earlz 6:a4dff59ef214 59 } type;
earlz 6:a4dff59ef214 60 union valueunion{
earlz 6:a4dff59ef214 61 int intvalue;
earlz 6:a4dff59ef214 62 BuiltinFunction builtin;
earlz 6:a4dff59ef214 63 char *string;
earlz 6:a4dff59ef214 64 } value;
earlz 6:a4dff59ef214 65 } WordKey;
earlz 6:a4dff59ef214 66
earlz 7:2ac6752d47d2 67 /**
earlz 7:2ac6752d47d2 68 BranchTarget tracks branches/labels.
earlz 7:2ac6752d47d2 69 When a beginning conditional/looping structure is found, it adds a branch target to the list with `target` set to point to the relevant branch target in codeblock
earlz 7:2ac6752d47d2 70 When an ending structure is found, it replaces the branch target(which starts at -1) with the actual branch address,
earlz 7:2ac6752d47d2 71 **/
earlz 7:2ac6752d47d2 72 typedef struct TargetNode
earlz 7:2ac6752d47d2 73 {
earlz 7:2ac6752d47d2 74 volatile uint16_t* target;
earlz 7:2ac6752d47d2 75 volatile TargetNode* previous; //previous instead of next because we're going to "destroy" this list in reverse
earlz 7:2ac6752d47d2 76 } BranchTarget;
earlz 7:2ac6752d47d2 77
earlz 6:a4dff59ef214 78 extern ErrorType pl_error;
earlz 3:2bc2b0dce10e 79
earlz 3:2bc2b0dce10e 80 int pl_shell();
earlz 3:2bc2b0dce10e 81
earlz 3:2bc2b0dce10e 82 static inline int is_whitespace(char c){
earlz 6:a4dff59ef214 83 return (c==' ') || (c=='\t') || (c=='\n') || (c=='\r');
earlz 3:2bc2b0dce10e 84 }
earlz 3:2bc2b0dce10e 85
earlz 3:2bc2b0dce10e 86 static inline int is_numeric(char c){
earlz 6:a4dff59ef214 87 return (c>='0') && (c<='9');
earlz 3:2bc2b0dce10e 88 }
earlz 3:2bc2b0dce10e 89
earlz 3:2bc2b0dce10e 90 static inline int is_alpha(char c){
earlz 6:a4dff59ef214 91 return ((c>='a') && (c<='z')) || ((c>='A') && (c<='Z'));
earlz 3:2bc2b0dce10e 92 }
earlz 3:2bc2b0dce10e 93
earlz 3:2bc2b0dce10e 94 static inline int is_identifier(char c){
earlz 6:a4dff59ef214 95 return is_alpha(c) || is_numeric(c) || (c=='_');
earlz 3:2bc2b0dce10e 96 }
earlz 3:2bc2b0dce10e 97
earlz 3:2bc2b0dce10e 98 static inline int is_quote(char c){
earlz 6:a4dff59ef214 99 return (c=='\"') || (c=='\'');
earlz 3:2bc2b0dce10e 100 }
earlz 6:a4dff59ef214 101 int forth_execute(uint8_t* block, int length);
earlz 6:a4dff59ef214 102 WordKey *pl_lookup(char* name);
earlz 6:a4dff59ef214 103 int pl_pop();
earlz 6:a4dff59ef214 104 void pl_push(int val);
earlz 6:a4dff59ef214 105
earlz 6:a4dff59ef214 106
earlz 6:a4dff59ef214 107
earlz 6:a4dff59ef214 108 //builtin functions
earlz 6:a4dff59ef214 109 void bi_print();
earlz 3:2bc2b0dce10e 110
earlz 3:2bc2b0dce10e 111
earlz 3:2bc2b0dce10e 112 #endif