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:
Wed Sep 26 04:12:57 2012 +0000
Parent:
8:f356684767ef
Child:
10:bda85442b674
Commit message:
PS/2 keyboard now receives scan codes at least

Changed in this revision

PS2.lib Show annotated file Show diff for this revision Revisions of this file
forth_machine.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbedconsole.h 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
shell.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PS2.lib	Wed Sep 26 04:12:57 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/PS2/#e8048e31eaff
--- a/forth_machine.cpp	Sat Sep 22 04:14:01 2012 +0000
+++ b/forth_machine.cpp	Wed Sep 26 04:12:57 2012 +0000
@@ -76,7 +76,27 @@
     return pl_dictionary_count++;
 }
 
-
+int pl_tempstack[MAXTEMPSTACK];
+int pl_temppos=0;
+void pl_temppush(int val)
+{
+    if(pl_temppos>=MAXTEMPSTACK)
+    {
+        vputs("Temporary stack overflow\n");
+        return;
+    }
+    pl_tempstack[pl_temppos]=val;
+    pl_temppos++;
+}
+int pl_temppop()
+{
+    if(pl_temppos<=0)
+    {
+        vputs("Temporary stack underflow\n");
+        return 0;
+    }
+    return pl_tempstack[pl_temppos--];
+}
 
 int forth_execute(uint8_t* block, int length)
 {
@@ -118,7 +138,7 @@
                 pl_push(*(uint32_t*)&block[pos]);
                 pos+=4;
                 break;
-            case Pop:
+            case Drop:
                 pos++;
                 pl_pop();
                 break;
@@ -166,12 +186,38 @@
                 pos++;
                 pl_push(pl_pop()!=pl_pop());
                 break;
-            case CallInt:
+            case CallInt:{
                 pos++;
                 uint32_t tmp=*(uint32_t*)&block[pos];
                 ((BuiltinFunction)tmp)();
                 pos+=4;
+                break;}
+            case Swap:{
+                pos++;
+                int tmp=pl_pop();
+                int tmp2=pl_pop();
+                pl_push(tmp);
+                pl_push(tmp2);
                 break;
+                }
+            case PushTemp:
+                pos++;
+                pl_temppush(pl_pop());
+                break;
+            case PopTemp:
+                pos++;
+                pl_push(pl_temppop());
+            case Pick:{
+                pos++;
+                int tmp=pl_pop();
+                if(pl_stackpos-tmp>0){
+                    pl_push(pl_stack[pl_stackpos-tmp]);
+                    
+                }else{
+                    pl_push(0);
+                    vputs("Stack underflow on pick\n");
+                }
+                break;}
             case Ret:
                 return 0;
             
--- a/main.cpp	Sat Sep 22 04:14:01 2012 +0000
+++ b/main.cpp	Wed Sep 26 04:12:57 2012 +0000
@@ -1,19 +1,29 @@
 #include "mbedconsole.h"
-
-
-
+#include "clock.h"
+#include "i2s.h"
+#include "nvic.h"
+ 
+ 
+PS2Keyboard *ps2kb;
 DigitalOut myled(LED1);
 
 
 Serial serial(USBTX, USBRX);
-
+ConsoleStream console;
 
 
 
 int main() {
     init_vga();
     serial.baud(115200);
+    serial.printf("Initializing PS/2..");
+    ps2kb=new PS2Keyboard(p12, p11); // CLK, DAT
+    fl_select_clock_i2s(FL_CLOCK_DIV1); // assume 100MHz
+    fl_i2s_set_tx_rate(1,4);            // set 25 MHz pixel clock 
     
+    
+    NVIC_SetPriority( EINT3_IRQn, 255 ); 
+    serial.printf("Done\n");
     vga_cls();
     
     while(1)
--- a/mbedconsole.h	Sat Sep 22 04:14:01 2012 +0000
+++ b/mbedconsole.h	Wed Sep 26 04:12:57 2012 +0000
@@ -3,6 +3,7 @@
 
 #include "mbed.h"
 #include "vga640x480g.h"
+#include "PS2Keyboard.h"
 
 void vputc(char c);
 void vputs(char *s);
@@ -14,11 +15,32 @@
 
 void shell_begin();
 
+extern PS2Keyboard *ps2kb;
 
 
 
 extern Serial serial;
 
 
+class ConsoleStream : public Stream //do this so we get printf and other goodies. Uses C functions for VGA and PS/2
+{
+    public:
+    ConsoleStream(){}
+    protected:
+ 
+    // Stream implementation functions
+    virtual int _putc(int value)
+    {
+        vputc((char)value);
+        return 1;
+    }
+    virtual int _getc()
+    {
+        return 0; //not yet implemented
+    }
+};
+
+extern ConsoleStream console;
+
 
 #endif
\ No newline at end of file
--- a/plEarlz.cpp	Sat Sep 22 04:14:01 2012 +0000
+++ b/plEarlz.cpp	Wed Sep 26 04:12:57 2012 +0000
@@ -188,8 +188,19 @@
                 pl_push(pl_pop()>0);
             }else if(word[0]=='$'){
                 //print string (address on stack
+            }else if(word[0]=='['){
+                //begin quotation
+                push_opcode(Push);
+                push_opcode_word(pl_blockpos+3);
+                push_opcode(Branch);
+                push_target(pl_blockpos);
+                push_opcode_word(0);
+            }else if(word[0] == ']'){
+                //end quotation
+                push_opcode(Ret);
+                write_blockword(last_target->target, pl_blockpos);
+                pop_target();
             }
-        
         }else if(strlcmp("if", word, 3)==0){
             push_opcode(BranchFalse);
             push_target(pl_blockpos);
@@ -204,6 +215,20 @@
         }else if(strlcmp("end", word, 4)==0){
             write_blockword(last_target->target,(uint16_t)pl_blockpos);
             pop_target();
+        }else if(strlcmp("tif", word, 4)==0){
+            /**
+            swap value 2 behind stack to front
+            call.true 1 from stack
+            call.false top of stack
+            _label:
+            **/
+            //alloca(10);
+            push_opcode(Push);
+            push_opcode_dword(3);
+            push_opcode(Pick);
+            push_opcode(BranchFalse);
+            //push_opcode_word(pl_blockpos+
+            
         }else{
             vputs("I don't know the word '");
             vputs(word);
@@ -251,6 +276,11 @@
             word[wordpos]=c;
             wordpos++;
         }else if(is_quote(c)){
+            push_opcode(LoadStr);
+            for(;i<len;i++)
+            {
+                //char c=line[
+            }
             vputs("This isn't supported yet foo!");
             return;
         }else{
@@ -277,7 +307,7 @@
     printheapstats();
     vputs("\n");
     char *line=(char*)malloc(MAXLINELENGTH);
-    sprintf(line, "Stack Size: %i; Max Recursion Level %i; Loaded WORDs: %i", MAXSTACK, MAXCALLS, 0);
+    sprintf(line, "Stack Size: %i; Max Recursion Level %i; Loaded WORDs: %i", MAXSTACK, MAXTEMPSTACK, 0);
     vputs(line);
     sprintf(line, "Max line length: %i\n", MAXLINELENGTH);
     vputs(line);
--- a/plEarlz.h	Sat Sep 22 04:14:01 2012 +0000
+++ b/plEarlz.h	Wed Sep 26 04:12:57 2012 +0000
@@ -2,7 +2,7 @@
 #define PLEARLZ_H
 
 #define MAXSTACK 64
-#define MAXCALLS 32
+#define MAXTEMPSTACK 64
 #define MAXLINELENGTH 128
 #define DICTIONARYSTEP 4 //how much memory to reserve when doing a reallocation for resizing
 #define CODEBLOCKSTEP 16
@@ -21,8 +21,10 @@
     BranchTrue, //argument is 16 bit vaddress
     BranchFalse, //argument is 16bit vaddress
     Branch,
+    PushTemp, //pops from stack and pushes onto the temporary stack
+    PopTemp, //pushes onto stack from temporary stack
     Push, //argument is 32bit number
-    Pop, //trashes top value on stack
+    Drop, //trashes top value on stack
     Call, //call. argument is WORD entry pointer in dictionary
     CallInt, //call internal argument is function pointer
     Add,
@@ -40,10 +42,12 @@
     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, 
+    Store,
+    Swap, 
     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. 
+    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
     Ret //exit
 };
 
--- a/shell.cpp	Sat Sep 22 04:14:01 2012 +0000
+++ b/shell.cpp	Wed Sep 26 04:12:57 2012 +0000
@@ -1,5 +1,6 @@
 #include "mbedconsole.h"
 #include "plEarlz.h"
+#include "PS2Keyboard.h"
 
 
 LocalFileSystem local("local");
@@ -43,6 +44,18 @@
         
                 // Drive should be restored. this is the same as just returning from main
             wait(5);
+        }else if(strlcmp(cmd, "test2", 6)==0){
+            PS2Keyboard::keyboard_event_t evt_kb;
+            while (1) {
+                //serial.putc('.');
+                if (ps2kb->processing(&evt_kb)) {
+                    console.printf("[%d]:", evt_kb.type);
+                    for (int i = 0; i < evt_kb.length; i++) {
+                        console.printf("%02x ", evt_kb.scancode[i]);
+                    }
+                    console.printf("\r\n");
+                }
+            }
         }else if(strlcmp(cmd, "plearlz", 8)==0){
             valid=1;
             pl_shell();