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

Files at this revision

API Documentation at this revision

Comitter:
earlz
Date:
Sat Sep 22 04:14:01 2012 +0000
Parent:
7:2ac6752d47d2
Child:
9:4211d638b2e9
Commit message:
IF statements now work, which makes loops trivial. Also added a few opcodes

Changed in this revision

forth_machine.cpp Show annotated file Show diff for this revision Revisions of this file
plEarlz.cpp Show annotated file Show diff for this revision Revisions of this file
plEarlz.h Show annotated file Show diff for this revision Revisions of this file
--- a/forth_machine.cpp	Sat Sep 22 03:00:55 2012 +0000
+++ b/forth_machine.cpp	Sat Sep 22 04:14:01 2012 +0000
@@ -81,11 +81,12 @@
 int forth_execute(uint8_t* block, int length)
 {
     uint16_t pos=0;
+    printf("block length: %x\r\n",length);
     while(pos<length)
     {
-        serial.getc();
+        //serial.getc();
         Opcode op=(Opcode)block[pos];
-        printf("opcode: %x\r\n",(int)op);
+        printf("pos: %x -- opcode: %x\r\n",(int)pos, (int)op);
         switch(op)
         {
             case BranchTrue:
@@ -100,6 +101,7 @@
             case BranchFalse:
                 if(!pl_pop()){
                     pos++;
+                    serial.printf("branch false %x\r\n",(int)pos);
                     pos=*((uint16_t*)&block[pos]);
                     serial.printf("branch false %x\r\n",(int)pos);
                 }else{
@@ -140,6 +142,30 @@
                 pos++;
                 pl_push(pl_pop()%pl_pop());
                 break;
+            case Cgt:
+                pos++;
+                pl_push(pl_pop()>pl_pop());
+                break;
+            case Clt:
+                pos++;
+                pl_push(pl_pop()<pl_pop());
+                break;
+            case Cgte:
+                pos++;
+                pl_push(pl_pop()>=pl_pop());
+                break;
+            case Clte:
+                pos++;
+                pl_push(pl_pop()<=pl_pop());
+                break;
+            case Ceq:
+                pos++;
+                pl_push(pl_pop()==pl_pop());
+                break;
+            case Cneq:
+                pos++;
+                pl_push(pl_pop()!=pl_pop());
+                break;
             case CallInt:
                 pos++;
                 uint32_t tmp=*(uint32_t*)&block[pos];
@@ -147,7 +173,7 @@
                 pos+=4;
                 break;
             case Ret:
-                return;
+                return 0;
             
                 
             default:
--- a/plEarlz.cpp	Sat Sep 22 03:00:55 2012 +0000
+++ b/plEarlz.cpp	Sat Sep 22 04:14:01 2012 +0000
@@ -25,7 +25,7 @@
 
 
 
-volatile BranchTarget *last_target=NULL;   
+BranchTarget *last_target=NULL;   
 
 ErrorType pl_error=None;
 
@@ -127,9 +127,9 @@
 }
  
 
-void push_target(uint16_t* address)
+void push_target(int address)
 {
-    volatile BranchTarget* target=(BranchTarget*)malloc(sizeof(BranchTarget));
+    BranchTarget* target=(BranchTarget*)malloc(sizeof(BranchTarget));
     target->previous=last_target;
     target->target=address;
     last_target=target;
@@ -145,6 +145,10 @@
     last_target=last_target->previous;
     free((void*)tmp);
 }
+inline void write_blockword(int pos,uint16_t val)
+{
+    *(uint16_t*)&pl_codeblock[pos]=val;
+}
 
 int compile_word(char *word, WordType type) //returns 0 for success, 1 for ending word found, -1 for error
 {
@@ -187,19 +191,18 @@
             }
         
         }else if(strlcmp("if", word, 3)==0){
-            printf("if statement %x\r\n", pl_blockpos);
             push_opcode(BranchFalse);
-            push_target(push_opcode_word(0));
+            push_target(pl_blockpos);
+            push_opcode_word(0);
         }else if(strlcmp("else", word, 5)==0){
-            printf("else statement %x\r\n", pl_blockpos);
             push_opcode(Branch);
-            uint16_t* tmp=push_opcode_word(0); 
-            volatile uint16_t* tmp2=last_target->target;
-            *tmp2=pl_blockpos;
+            int tmp=pl_blockpos;
+            push_opcode_word(0); 
+            write_blockword(last_target->target,pl_blockpos);
             pop_target(); 
             push_target(tmp); //have to do it after we pop it or we fall into an infinite loop!
         }else if(strlcmp("end", word, 4)==0){
-            *(last_target->target)=pl_blockpos;
+            write_blockword(last_target->target,(uint16_t)pl_blockpos);
             pop_target();
         }else{
             vputs("I don't know the word '");
@@ -270,15 +273,6 @@
 
 int pl_shell()
 {
-    uint8_t* tmpf[20];
-    push_target((uint16_t*)&tmpf[2]);
-    *last_target->target=50;
-    pop_target();
-    push_target((uint16_t*)&tmpf[4]);
-    *last_target->target=200;
-    pop_target();
-    
-    printf("foo: %i %i\r\n", (int)*(uint16_t*)&tmpf[2], (int)*(uint16_t*)&tmpf[4]);
     vputs(">>plEarlz -- A forth-ish shell<<\n");
     printheapstats();
     vputs("\n");
--- a/plEarlz.h	Sat Sep 22 03:00:55 2012 +0000
+++ b/plEarlz.h	Sat Sep 22 04:14:01 2012 +0000
@@ -71,8 +71,8 @@
 **/
 typedef struct TargetNode
 {
-    volatile uint16_t* target;
-    volatile TargetNode* previous; //previous instead of next because we're going to "destroy" this list in reverse
+    int target; //position inside of codeblock. Can't use pointers because life is cruel and the block could be reallocated at anytime. 
+    TargetNode* previous; //previous instead of next because we're going to "destroy" this list in reverse
 } BranchTarget;  
 
 extern ErrorType pl_error;