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

Committer:
earlz
Date:
2012-09-22
Revision:
7:2ac6752d47d2
Parent:
6:a4dff59ef214
Child:
8:f356684767ef

File content as of revision 7:2ac6752d47d2:

#ifndef PLEARLZ_H
#define PLEARLZ_H

#define MAXSTACK 64
#define MAXCALLS 32
#define MAXLINELENGTH 128
#define DICTIONARYSTEP 4 //how much memory to reserve when doing a reallocation for resizing
#define CODEBLOCKSTEP 16

enum ErrorType
{
    None,
    StackOverflow,
    StackUnderflow
};

//arguments are in the bytecode, not the stack! But, things like Add has no arguments and uses the stack
//pointers are assumed 32-bit?
enum Opcode
{
    BranchTrue, //argument is 16 bit vaddress
    BranchFalse, //argument is 16bit vaddress
    Branch,
    Push, //argument is 32bit number
    Pop, //trashes top value on stack
    Call, //call. argument is WORD entry pointer in dictionary
    CallInt, //call internal argument is function pointer
    Add,
    Sub,
    Mul,
    Div,
    Mod,
    Cgt, //takes two integers and compares for greater than pushes 1 if so, 0 if not
    Clt, //less than
    Cgte, //greater than or equal
    Clte,
    Ceq,
    Cneq,
    LoadStr, //argument is variable length string ending with 0. Pushes address onto stack
    LoadConst, //pushes the value pointed to by the argument
    StoreConst, //pops a value and stores it in the memory pointed to by the argument
    Load, //same as above, except the address is popped first. 
    Store, 
    New, //pushes a pointer to free memory for an integer
    NewVar, //pushes a pointer to memory. Size is specified by argument
    Delete, //pops a pointer and frees it. 
    Ret //exit
};

typedef void (*BuiltinFunction)(void);
typedef struct
{
    char name[12];
    enum Type{
        Constant,
        ConstantString,
        Builtin,
        Function
    } type;
    union valueunion{
        int intvalue;
        BuiltinFunction builtin;
        char *string;
    } value;
} WordKey;

/**
BranchTarget tracks branches/labels. 
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
When an ending structure is found, it replaces the branch target(which starts at -1) with the actual branch address,
**/
typedef struct TargetNode
{
    volatile uint16_t* target;
    volatile TargetNode* previous; //previous instead of next because we're going to "destroy" this list in reverse
} BranchTarget;  

extern ErrorType pl_error;

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=='\'');
}
int forth_execute(uint8_t* block, int length);
WordKey *pl_lookup(char* name);
int pl_pop();
void pl_push(int val);



//builtin functions
void bi_print();


#endif