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
textio.cpp@16:370b9e559f92, 2012-09-30 (annotated)
- Committer:
- earlz
- Date:
- Sun Sep 30 16:48:41 2012 +0000
- Revision:
- 16:370b9e559f92
- Parent:
- 13:442bd2fb4ea0
Added BSD license notice
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 | 12:3ee3062cc11c | 32 | #include "mbedconsole.h" |
earlz | 12:3ee3062cc11c | 33 | #include "keyboard.h" |
earlz | 12:3ee3062cc11c | 34 | |
earlz | 12:3ee3062cc11c | 35 | #define FONTHEIGHT 16 |
earlz | 12:3ee3062cc11c | 36 | #define FONTWIDTH 8 |
earlz | 12:3ee3062cc11c | 37 | |
earlz | 13:442bd2fb4ea0 | 38 | int console_x=0, console_y=(250/15); |
earlz | 12:3ee3062cc11c | 39 | int console_color=WHITE; //text color |
earlz | 12:3ee3062cc11c | 40 | |
earlz | 12:3ee3062cc11c | 41 | |
earlz | 12:3ee3062cc11c | 42 | void vsetcursor(int x, int y) |
earlz | 12:3ee3062cc11c | 43 | { |
earlz | 12:3ee3062cc11c | 44 | console_x=x; |
earlz | 12:3ee3062cc11c | 45 | console_y=y; |
earlz | 12:3ee3062cc11c | 46 | } |
earlz | 12:3ee3062cc11c | 47 | |
earlz | 12:3ee3062cc11c | 48 | void vrawputc(char c) |
earlz | 12:3ee3062cc11c | 49 | { |
earlz | 12:3ee3062cc11c | 50 | //fuck that shitv |
earlz | 12:3ee3062cc11c | 51 | if(console_x>80) |
earlz | 12:3ee3062cc11c | 52 | { |
earlz | 12:3ee3062cc11c | 53 | return; |
earlz | 12:3ee3062cc11c | 54 | } |
earlz | 12:3ee3062cc11c | 55 | //shift left for fast multiply |
earlz | 12:3ee3062cc11c | 56 | vga_putchar(console_x<<3, console_y<<4, c, console_color); |
earlz | 12:3ee3062cc11c | 57 | } |
earlz | 12:3ee3062cc11c | 58 | void vputc(char c) |
earlz | 12:3ee3062cc11c | 59 | { |
earlz | 12:3ee3062cc11c | 60 | //shift left for fast multiply |
earlz | 12:3ee3062cc11c | 61 | if(console_x>=79) |
earlz | 12:3ee3062cc11c | 62 | { |
earlz | 12:3ee3062cc11c | 63 | console_x=0; |
earlz | 12:3ee3062cc11c | 64 | console_y++; |
earlz | 12:3ee3062cc11c | 65 | } |
earlz | 13:442bd2fb4ea0 | 66 | if(console_y>=29) |
earlz | 12:3ee3062cc11c | 67 | { |
earlz | 12:3ee3062cc11c | 68 | console_y--; |
earlz | 12:3ee3062cc11c | 69 | vga_scroll(); |
earlz | 12:3ee3062cc11c | 70 | } |
earlz | 12:3ee3062cc11c | 71 | switch(c){ |
earlz | 12:3ee3062cc11c | 72 | case '\n': |
earlz | 12:3ee3062cc11c | 73 | case '\r': |
earlz | 12:3ee3062cc11c | 74 | console_y++; |
earlz | 12:3ee3062cc11c | 75 | console_x=0; |
earlz | 12:3ee3062cc11c | 76 | break; |
earlz | 12:3ee3062cc11c | 77 | case '\b': |
earlz | 12:3ee3062cc11c | 78 | vrawputc(' '); |
earlz | 12:3ee3062cc11c | 79 | if(console_x>0) |
earlz | 12:3ee3062cc11c | 80 | { |
earlz | 12:3ee3062cc11c | 81 | console_x--; |
earlz | 12:3ee3062cc11c | 82 | } |
earlz | 12:3ee3062cc11c | 83 | vrawputc(' '); |
earlz | 12:3ee3062cc11c | 84 | break; |
earlz | 12:3ee3062cc11c | 85 | case '\t': |
earlz | 12:3ee3062cc11c | 86 | for(int i=0;i<4;i++) |
earlz | 12:3ee3062cc11c | 87 | { |
earlz | 12:3ee3062cc11c | 88 | console_x++; |
earlz | 12:3ee3062cc11c | 89 | vrawputc(' '); |
earlz | 12:3ee3062cc11c | 90 | } |
earlz | 12:3ee3062cc11c | 91 | default: |
earlz | 12:3ee3062cc11c | 92 | vga_putchar(console_x<<3, console_y<<4, c, console_color); |
earlz | 12:3ee3062cc11c | 93 | console_x++; |
earlz | 12:3ee3062cc11c | 94 | } |
earlz | 12:3ee3062cc11c | 95 | } |
earlz | 12:3ee3062cc11c | 96 | |
earlz | 12:3ee3062cc11c | 97 | void vputs(char *s){ |
earlz | 12:3ee3062cc11c | 98 | while(*s!=0){ |
earlz | 12:3ee3062cc11c | 99 | vputc(*s); |
earlz | 12:3ee3062cc11c | 100 | s++; |
earlz | 12:3ee3062cc11c | 101 | } |
earlz | 12:3ee3062cc11c | 102 | } |
earlz | 12:3ee3062cc11c | 103 | |
earlz | 12:3ee3062cc11c | 104 | char vgetc() |
earlz | 12:3ee3062cc11c | 105 | { |
earlz | 12:3ee3062cc11c | 106 | char tmp=kbd_GetKey(); |
earlz | 12:3ee3062cc11c | 107 | vputc(tmp); |
earlz | 12:3ee3062cc11c | 108 | return tmp; |
earlz | 12:3ee3062cc11c | 109 | } |
earlz | 12:3ee3062cc11c | 110 | int vgetsl(char *buf, int len) |
earlz | 12:3ee3062cc11c | 111 | { |
earlz | 12:3ee3062cc11c | 112 | int pos=0; |
earlz | 12:3ee3062cc11c | 113 | while(1){ |
earlz | 12:3ee3062cc11c | 114 | buf[pos]=kbd_GetKey(); |
earlz | 12:3ee3062cc11c | 115 | if(buf[pos]=='\r'){ |
earlz | 12:3ee3062cc11c | 116 | buf[pos]='\n'; |
earlz | 12:3ee3062cc11c | 117 | } |
earlz | 12:3ee3062cc11c | 118 | |
earlz | 12:3ee3062cc11c | 119 | vputc(buf[pos]); |
earlz | 12:3ee3062cc11c | 120 | if(buf[pos]=='\b'){ |
earlz | 12:3ee3062cc11c | 121 | buf[pos]=0; |
earlz | 12:3ee3062cc11c | 122 | if(pos>0){ |
earlz | 12:3ee3062cc11c | 123 | pos--; |
earlz | 12:3ee3062cc11c | 124 | buf[pos--]=0; |
earlz | 12:3ee3062cc11c | 125 | } |
earlz | 12:3ee3062cc11c | 126 | } |
earlz | 12:3ee3062cc11c | 127 | if(pos>len-1){ |
earlz | 12:3ee3062cc11c | 128 | break; |
earlz | 12:3ee3062cc11c | 129 | } |
earlz | 12:3ee3062cc11c | 130 | if(buf[pos]=='\n'){ |
earlz | 12:3ee3062cc11c | 131 | buf[pos]=0; |
earlz | 12:3ee3062cc11c | 132 | return 1; |
earlz | 12:3ee3062cc11c | 133 | } |
earlz | 12:3ee3062cc11c | 134 | pos++; |
earlz | 12:3ee3062cc11c | 135 | } |
earlz | 12:3ee3062cc11c | 136 | return 0; |
earlz | 12:3ee3062cc11c | 137 | } |
earlz | 12:3ee3062cc11c | 138 | |
earlz | 12:3ee3062cc11c | 139 | |
earlz | 12:3ee3062cc11c | 140 | |
earlz | 12:3ee3062cc11c | 141 | int strlcmp(const char *s1,const char *s2,size_t count){ |
earlz | 12:3ee3062cc11c | 142 | int i=0; |
earlz | 12:3ee3062cc11c | 143 | while((s1[i]!=0) && (s2[i]!=0)){ |
earlz | 12:3ee3062cc11c | 144 | if(s1[i]!=s2[i]){ |
earlz | 12:3ee3062cc11c | 145 | return -1; |
earlz | 12:3ee3062cc11c | 146 | } |
earlz | 12:3ee3062cc11c | 147 | if(i>=count){ |
earlz | 12:3ee3062cc11c | 148 | return -1; |
earlz | 12:3ee3062cc11c | 149 | } |
earlz | 12:3ee3062cc11c | 150 | i++; |
earlz | 12:3ee3062cc11c | 151 | |
earlz | 12:3ee3062cc11c | 152 | } |
earlz | 12:3ee3062cc11c | 153 | if(s1[i]!=s2[i]){ |
earlz | 12:3ee3062cc11c | 154 | return -1; |
earlz | 12:3ee3062cc11c | 155 | } |
earlz | 12:3ee3062cc11c | 156 | return 0; |
earlz | 12:3ee3062cc11c | 157 | } |
earlz | 12:3ee3062cc11c | 158 |