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
plEarlz.h@11:fede136943a9, 2012-09-28 (annotated)
- Committer:
- earlz
- Date:
- Fri Sep 28 04:03:54 2012 +0000
- Revision:
- 11:fede136943a9
- Parent:
- 9:4211d638b2e9
- Child:
- 16:370b9e559f92
Finally have keyboard support, AND it plays nice with VGA
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:4211d638b2e9 | 5 | #define MAXTEMPSTACK 64 |
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 | 9:4211d638b2e9 | 24 | PushTemp, //pops from stack and pushes onto the temporary stack |
earlz | 9:4211d638b2e9 | 25 | PopTemp, //pushes onto stack from temporary stack |
earlz | 6:a4dff59ef214 | 26 | Push, //argument is 32bit number |
earlz | 9:4211d638b2e9 | 27 | Drop, //trashes top value on stack |
earlz | 6:a4dff59ef214 | 28 | Call, //call. argument is WORD entry pointer in dictionary |
earlz | 6:a4dff59ef214 | 29 | CallInt, //call internal argument is function pointer |
earlz | 6:a4dff59ef214 | 30 | Add, |
earlz | 6:a4dff59ef214 | 31 | Sub, |
earlz | 6:a4dff59ef214 | 32 | Mul, |
earlz | 6:a4dff59ef214 | 33 | Div, |
earlz | 6:a4dff59ef214 | 34 | Mod, |
earlz | 6:a4dff59ef214 | 35 | Cgt, //takes two integers and compares for greater than pushes 1 if so, 0 if not |
earlz | 6:a4dff59ef214 | 36 | Clt, //less than |
earlz | 6:a4dff59ef214 | 37 | Cgte, //greater than or equal |
earlz | 6:a4dff59ef214 | 38 | Clte, |
earlz | 6:a4dff59ef214 | 39 | Ceq, |
earlz | 6:a4dff59ef214 | 40 | Cneq, |
earlz | 6:a4dff59ef214 | 41 | LoadStr, //argument is variable length string ending with 0. Pushes address onto stack |
earlz | 7:2ac6752d47d2 | 42 | LoadConst, //pushes the value pointed to by the argument |
earlz | 7:2ac6752d47d2 | 43 | StoreConst, //pops a value and stores it in the memory pointed to by the argument |
earlz | 7:2ac6752d47d2 | 44 | Load, //same as above, except the address is popped first. |
earlz | 9:4211d638b2e9 | 45 | Store, |
earlz | 9:4211d638b2e9 | 46 | Swap, |
earlz | 6:a4dff59ef214 | 47 | New, //pushes a pointer to free memory for an integer |
earlz | 6:a4dff59ef214 | 48 | NewVar, //pushes a pointer to memory. Size is specified by argument |
earlz | 6:a4dff59ef214 | 49 | Delete, //pops a pointer and frees it. |
earlz | 9:4211d638b2e9 | 50 | Pick, //takes an integer position from the stack. Goes that many slots back in the stack and peeks at the value, and then pushes it on the top of the stack |
earlz | 6:a4dff59ef214 | 51 | Ret //exit |
earlz | 6:a4dff59ef214 | 52 | }; |
earlz | 6:a4dff59ef214 | 53 | |
earlz | 6:a4dff59ef214 | 54 | typedef void (*BuiltinFunction)(void); |
earlz | 6:a4dff59ef214 | 55 | typedef struct |
earlz | 6:a4dff59ef214 | 56 | { |
earlz | 6:a4dff59ef214 | 57 | char name[12]; |
earlz | 6:a4dff59ef214 | 58 | enum Type{ |
earlz | 6:a4dff59ef214 | 59 | Constant, |
earlz | 6:a4dff59ef214 | 60 | ConstantString, |
earlz | 6:a4dff59ef214 | 61 | Builtin, |
earlz | 6:a4dff59ef214 | 62 | Function |
earlz | 6:a4dff59ef214 | 63 | } type; |
earlz | 6:a4dff59ef214 | 64 | union valueunion{ |
earlz | 6:a4dff59ef214 | 65 | int intvalue; |
earlz | 6:a4dff59ef214 | 66 | BuiltinFunction builtin; |
earlz | 6:a4dff59ef214 | 67 | char *string; |
earlz | 6:a4dff59ef214 | 68 | } value; |
earlz | 6:a4dff59ef214 | 69 | } WordKey; |
earlz | 6:a4dff59ef214 | 70 | |
earlz | 7:2ac6752d47d2 | 71 | /** |
earlz | 7:2ac6752d47d2 | 72 | BranchTarget tracks branches/labels. |
earlz | 7:2ac6752d47d2 | 73 | 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 | 74 | When an ending structure is found, it replaces the branch target(which starts at -1) with the actual branch address, |
earlz | 7:2ac6752d47d2 | 75 | **/ |
earlz | 7:2ac6752d47d2 | 76 | typedef struct TargetNode |
earlz | 7:2ac6752d47d2 | 77 | { |
earlz | 8:f356684767ef | 78 | int target; //position inside of codeblock. Can't use pointers because life is cruel and the block could be reallocated at anytime. |
earlz | 8:f356684767ef | 79 | TargetNode* previous; //previous instead of next because we're going to "destroy" this list in reverse |
earlz | 7:2ac6752d47d2 | 80 | } BranchTarget; |
earlz | 7:2ac6752d47d2 | 81 | |
earlz | 6:a4dff59ef214 | 82 | extern ErrorType pl_error; |
earlz | 3:2bc2b0dce10e | 83 | |
earlz | 3:2bc2b0dce10e | 84 | int pl_shell(); |
earlz | 3:2bc2b0dce10e | 85 | |
earlz | 3:2bc2b0dce10e | 86 | static inline int is_whitespace(char c){ |
earlz | 6:a4dff59ef214 | 87 | return (c==' ') || (c=='\t') || (c=='\n') || (c=='\r'); |
earlz | 3:2bc2b0dce10e | 88 | } |
earlz | 3:2bc2b0dce10e | 89 | |
earlz | 3:2bc2b0dce10e | 90 | static inline int is_numeric(char c){ |
earlz | 6:a4dff59ef214 | 91 | return (c>='0') && (c<='9'); |
earlz | 3:2bc2b0dce10e | 92 | } |
earlz | 3:2bc2b0dce10e | 93 | |
earlz | 3:2bc2b0dce10e | 94 | static inline int is_alpha(char c){ |
earlz | 6:a4dff59ef214 | 95 | return ((c>='a') && (c<='z')) || ((c>='A') && (c<='Z')); |
earlz | 3:2bc2b0dce10e | 96 | } |
earlz | 3:2bc2b0dce10e | 97 | |
earlz | 3:2bc2b0dce10e | 98 | static inline int is_identifier(char c){ |
earlz | 6:a4dff59ef214 | 99 | return is_alpha(c) || is_numeric(c) || (c=='_'); |
earlz | 3:2bc2b0dce10e | 100 | } |
earlz | 3:2bc2b0dce10e | 101 | |
earlz | 3:2bc2b0dce10e | 102 | static inline int is_quote(char c){ |
earlz | 6:a4dff59ef214 | 103 | return (c=='\"') || (c=='\''); |
earlz | 3:2bc2b0dce10e | 104 | } |
earlz | 6:a4dff59ef214 | 105 | int forth_execute(uint8_t* block, int length); |
earlz | 6:a4dff59ef214 | 106 | WordKey *pl_lookup(char* name); |
earlz | 6:a4dff59ef214 | 107 | int pl_pop(); |
earlz | 6:a4dff59ef214 | 108 | void pl_push(int val); |
earlz | 6:a4dff59ef214 | 109 | |
earlz | 6:a4dff59ef214 | 110 | |
earlz | 6:a4dff59ef214 | 111 | |
earlz | 6:a4dff59ef214 | 112 | //builtin functions |
earlz | 6:a4dff59ef214 | 113 | void bi_print(); |
earlz | 3:2bc2b0dce10e | 114 | |
earlz | 3:2bc2b0dce10e | 115 | |
earlz | 3:2bc2b0dce10e | 116 | #endif |