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@20:13556e5bac04, 2013-04-15 (annotated)
- Committer:
- earlz
- Date:
- Mon Apr 15 02:37:02 2013 +0000
- Revision:
- 20:13556e5bac04
- Parent:
- 16:370b9e559f92
Finally got SD card support working. WOW that was trickier than I expected
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
earlz | 16:370b9e559f92 | 1 | /* |
earlz | 16:370b9e559f92 | 2 | <Copyright Header> |
earlz | 16:370b9e559f92 | 3 | Copyright (c) 2012 Jordan "Earlz" Earls <http://lastyearswishes.com> |
earlz | 16:370b9e559f92 | 4 | All rights reserved. |
earlz | 16:370b9e559f92 | 5 | |
earlz | 16:370b9e559f92 | 6 | Redistribution and use in source and binary forms, with or without |
earlz | 16:370b9e559f92 | 7 | modification, are permitted provided that the following conditions |
earlz | 16:370b9e559f92 | 8 | are met: |
earlz | 16:370b9e559f92 | 9 | |
earlz | 16:370b9e559f92 | 10 | 1. Redistributions of source code must retain the above copyright |
earlz | 16:370b9e559f92 | 11 | notice, this list of conditions and the following disclaimer. |
earlz | 16:370b9e559f92 | 12 | 2. Redistributions in binary form must reproduce the above copyright |
earlz | 16:370b9e559f92 | 13 | notice, this list of conditions and the following disclaimer in the |
earlz | 16:370b9e559f92 | 14 | documentation and/or other materials provided with the distribution. |
earlz | 16:370b9e559f92 | 15 | 3. The name of the author may not be used to endorse or promote products |
earlz | 16:370b9e559f92 | 16 | derived from this software without specific prior written permission. |
earlz | 16:370b9e559f92 | 17 | |
earlz | 16:370b9e559f92 | 18 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
earlz | 16:370b9e559f92 | 19 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
earlz | 16:370b9e559f92 | 20 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
earlz | 16:370b9e559f92 | 21 | THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
earlz | 16:370b9e559f92 | 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
earlz | 16:370b9e559f92 | 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
earlz | 16:370b9e559f92 | 24 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
earlz | 16:370b9e559f92 | 25 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
earlz | 16:370b9e559f92 | 26 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
earlz | 16:370b9e559f92 | 27 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
earlz | 16:370b9e559f92 | 28 | |
earlz | 16:370b9e559f92 | 29 | This file is part of the MbedConsole project |
earlz | 16:370b9e559f92 | 30 | */ |
earlz | 16:370b9e559f92 | 31 | |
earlz | 3:2bc2b0dce10e | 32 | #ifndef PLEARLZ_H |
earlz | 3:2bc2b0dce10e | 33 | #define PLEARLZ_H |
earlz | 3:2bc2b0dce10e | 34 | |
earlz | 6:a4dff59ef214 | 35 | #define MAXSTACK 64 |
earlz | 9:4211d638b2e9 | 36 | #define MAXTEMPSTACK 64 |
earlz | 6:a4dff59ef214 | 37 | #define MAXLINELENGTH 128 |
earlz | 6:a4dff59ef214 | 38 | #define DICTIONARYSTEP 4 //how much memory to reserve when doing a reallocation for resizing |
earlz | 6:a4dff59ef214 | 39 | #define CODEBLOCKSTEP 16 |
earlz | 6:a4dff59ef214 | 40 | |
earlz | 6:a4dff59ef214 | 41 | enum ErrorType |
earlz | 6:a4dff59ef214 | 42 | { |
earlz | 6:a4dff59ef214 | 43 | None, |
earlz | 6:a4dff59ef214 | 44 | StackOverflow, |
earlz | 6:a4dff59ef214 | 45 | StackUnderflow |
earlz | 6:a4dff59ef214 | 46 | }; |
earlz | 6:a4dff59ef214 | 47 | |
earlz | 6:a4dff59ef214 | 48 | //arguments are in the bytecode, not the stack! But, things like Add has no arguments and uses the stack |
earlz | 6:a4dff59ef214 | 49 | //pointers are assumed 32-bit? |
earlz | 6:a4dff59ef214 | 50 | enum Opcode |
earlz | 6:a4dff59ef214 | 51 | { |
earlz | 6:a4dff59ef214 | 52 | BranchTrue, //argument is 16 bit vaddress |
earlz | 6:a4dff59ef214 | 53 | BranchFalse, //argument is 16bit vaddress |
earlz | 6:a4dff59ef214 | 54 | Branch, |
earlz | 9:4211d638b2e9 | 55 | PushTemp, //pops from stack and pushes onto the temporary stack |
earlz | 9:4211d638b2e9 | 56 | PopTemp, //pushes onto stack from temporary stack |
earlz | 6:a4dff59ef214 | 57 | Push, //argument is 32bit number |
earlz | 9:4211d638b2e9 | 58 | Drop, //trashes top value on stack |
earlz | 6:a4dff59ef214 | 59 | Call, //call. argument is WORD entry pointer in dictionary |
earlz | 6:a4dff59ef214 | 60 | CallInt, //call internal argument is function pointer |
earlz | 6:a4dff59ef214 | 61 | Add, |
earlz | 6:a4dff59ef214 | 62 | Sub, |
earlz | 6:a4dff59ef214 | 63 | Mul, |
earlz | 6:a4dff59ef214 | 64 | Div, |
earlz | 6:a4dff59ef214 | 65 | Mod, |
earlz | 6:a4dff59ef214 | 66 | Cgt, //takes two integers and compares for greater than pushes 1 if so, 0 if not |
earlz | 6:a4dff59ef214 | 67 | Clt, //less than |
earlz | 6:a4dff59ef214 | 68 | Cgte, //greater than or equal |
earlz | 6:a4dff59ef214 | 69 | Clte, |
earlz | 6:a4dff59ef214 | 70 | Ceq, |
earlz | 6:a4dff59ef214 | 71 | Cneq, |
earlz | 6:a4dff59ef214 | 72 | LoadStr, //argument is variable length string ending with 0. Pushes address onto stack |
earlz | 7:2ac6752d47d2 | 73 | LoadConst, //pushes the value pointed to by the argument |
earlz | 7:2ac6752d47d2 | 74 | StoreConst, //pops a value and stores it in the memory pointed to by the argument |
earlz | 7:2ac6752d47d2 | 75 | Load, //same as above, except the address is popped first. |
earlz | 9:4211d638b2e9 | 76 | Store, |
earlz | 9:4211d638b2e9 | 77 | Swap, |
earlz | 6:a4dff59ef214 | 78 | New, //pushes a pointer to free memory for an integer |
earlz | 6:a4dff59ef214 | 79 | NewVar, //pushes a pointer to memory. Size is specified by argument |
earlz | 6:a4dff59ef214 | 80 | Delete, //pops a pointer and frees it. |
earlz | 9:4211d638b2e9 | 81 | 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 | 82 | Ret //exit |
earlz | 6:a4dff59ef214 | 83 | }; |
earlz | 6:a4dff59ef214 | 84 | |
earlz | 6:a4dff59ef214 | 85 | typedef void (*BuiltinFunction)(void); |
earlz | 6:a4dff59ef214 | 86 | typedef struct |
earlz | 6:a4dff59ef214 | 87 | { |
earlz | 6:a4dff59ef214 | 88 | char name[12]; |
earlz | 6:a4dff59ef214 | 89 | enum Type{ |
earlz | 6:a4dff59ef214 | 90 | Constant, |
earlz | 6:a4dff59ef214 | 91 | ConstantString, |
earlz | 6:a4dff59ef214 | 92 | Builtin, |
earlz | 6:a4dff59ef214 | 93 | Function |
earlz | 6:a4dff59ef214 | 94 | } type; |
earlz | 6:a4dff59ef214 | 95 | union valueunion{ |
earlz | 6:a4dff59ef214 | 96 | int intvalue; |
earlz | 6:a4dff59ef214 | 97 | BuiltinFunction builtin; |
earlz | 6:a4dff59ef214 | 98 | char *string; |
earlz | 6:a4dff59ef214 | 99 | } value; |
earlz | 6:a4dff59ef214 | 100 | } WordKey; |
earlz | 6:a4dff59ef214 | 101 | |
earlz | 7:2ac6752d47d2 | 102 | /** |
earlz | 7:2ac6752d47d2 | 103 | BranchTarget tracks branches/labels. |
earlz | 7:2ac6752d47d2 | 104 | 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 | 105 | When an ending structure is found, it replaces the branch target(which starts at -1) with the actual branch address, |
earlz | 7:2ac6752d47d2 | 106 | **/ |
earlz | 7:2ac6752d47d2 | 107 | typedef struct TargetNode |
earlz | 7:2ac6752d47d2 | 108 | { |
earlz | 8:f356684767ef | 109 | 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 | 110 | TargetNode* previous; //previous instead of next because we're going to "destroy" this list in reverse |
earlz | 7:2ac6752d47d2 | 111 | } BranchTarget; |
earlz | 7:2ac6752d47d2 | 112 | |
earlz | 6:a4dff59ef214 | 113 | extern ErrorType pl_error; |
earlz | 3:2bc2b0dce10e | 114 | |
earlz | 3:2bc2b0dce10e | 115 | int pl_shell(); |
earlz | 3:2bc2b0dce10e | 116 | |
earlz | 3:2bc2b0dce10e | 117 | static inline int is_whitespace(char c){ |
earlz | 6:a4dff59ef214 | 118 | return (c==' ') || (c=='\t') || (c=='\n') || (c=='\r'); |
earlz | 3:2bc2b0dce10e | 119 | } |
earlz | 3:2bc2b0dce10e | 120 | |
earlz | 3:2bc2b0dce10e | 121 | static inline int is_numeric(char c){ |
earlz | 6:a4dff59ef214 | 122 | return (c>='0') && (c<='9'); |
earlz | 3:2bc2b0dce10e | 123 | } |
earlz | 3:2bc2b0dce10e | 124 | |
earlz | 3:2bc2b0dce10e | 125 | static inline int is_alpha(char c){ |
earlz | 6:a4dff59ef214 | 126 | return ((c>='a') && (c<='z')) || ((c>='A') && (c<='Z')); |
earlz | 3:2bc2b0dce10e | 127 | } |
earlz | 3:2bc2b0dce10e | 128 | |
earlz | 3:2bc2b0dce10e | 129 | static inline int is_identifier(char c){ |
earlz | 6:a4dff59ef214 | 130 | return is_alpha(c) || is_numeric(c) || (c=='_'); |
earlz | 3:2bc2b0dce10e | 131 | } |
earlz | 3:2bc2b0dce10e | 132 | |
earlz | 3:2bc2b0dce10e | 133 | static inline int is_quote(char c){ |
earlz | 6:a4dff59ef214 | 134 | return (c=='\"') || (c=='\''); |
earlz | 3:2bc2b0dce10e | 135 | } |
earlz | 6:a4dff59ef214 | 136 | int forth_execute(uint8_t* block, int length); |
earlz | 6:a4dff59ef214 | 137 | WordKey *pl_lookup(char* name); |
earlz | 6:a4dff59ef214 | 138 | int pl_pop(); |
earlz | 6:a4dff59ef214 | 139 | void pl_push(int val); |
earlz | 6:a4dff59ef214 | 140 | |
earlz | 6:a4dff59ef214 | 141 | |
earlz | 6:a4dff59ef214 | 142 | |
earlz | 6:a4dff59ef214 | 143 | //builtin functions |
earlz | 6:a4dff59ef214 | 144 | void bi_print(); |
earlz | 3:2bc2b0dce10e | 145 | |
earlz | 3:2bc2b0dce10e | 146 | |
earlz | 3:2bc2b0dce10e | 147 | #endif |