Anders Hörnfeldt
/
coniolib
Port of Conio.h
Revision 0:6c1bc9b3a347, committed 2010-04-19
- Comitter:
- hornfeldt
- Date:
- Mon Apr 19 20:20:10 2010 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r 6c1bc9b3a347 aa.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aa.c Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,26 @@ +/* + aa.c + Demo ASCII art picture. + Part of MicroVGA CONIO library / demo project + Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "conio.h" + +static const ROMDEF unsigned char ascii_art_str[] = ""; + + +/* */ \ No newline at end of file
diff -r 000000000000 -r 6c1bc9b3a347 h/conio.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h/conio.h Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,128 @@ +/* + conio.h + Standard conio routines. + Part of MicroVGA CONIO library / demo project + Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _INC_CONIO +#define _INC_CONIO + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(__COLORS) +#define __COLORS +// Compatible with DOS/WIN CONIO.H +enum COLORS { + BLACK = 0, /* dark colors */ + RED, + GREEN, + BROWN, + BLUE, + MAGENTA, + CYAN, + LIGHTGRAY, + DARKGRAY, /* light colors */ + LIGHTRED, + LIGHTGREEN, + YELLOW, + LIGHTBLUE, + LIGHTMAGENTA, + LIGHTCYAN, + WHITE +}; + +#define BLINK 128 +#endif + +//defines max coordinates for checking overflow +#define MAX_X 80 +#define MAX_Y 25 + +// Compatible with Unix Curses +#define ACS_ULCORNER (0xDA) /* upper left corner */ +#define ACS_LLCORNER (0xC0) /* lower left corner */ +#define ACS_URCORNER (0xBF) /* upper right corner */ +#define ACS_LRCORNER (0xD9) /* lower right corner */ +#define ACS_HLINE (0xC4) /* horizontal line */ +#define ACS_VLINE (0xB3) /* vertical line */ +#define ACS_LTEE (acs_map['t']) /* tee pointing right */ +#define ACS_RTEE (acs_map['u']) /* tee pointing left */ +#define ACS_BTEE (acs_map['v']) /* tee pointing up */ +#define ACS_TTEE (acs_map['w']) /* tee pointing down */ +#define ACS_PLUS (acs_map['n']) /* large plus or crossover */ +#define ACS_S1 (acs_map['o']) /* scan line 1 */ +#define ACS_S9 (acs_map['s']) /* scan line 9 */ +#define ACS_DIAMOND (acs_map['`']) /* diamond */ +#define ACS_CKBOARD (acs_map['a']) /* checker board (stipple) */ +#define ACS_DEGREE (acs_map['f']) /* degree symbol */ +#define ACS_PLMINUS (acs_map['g']) /* plus/minus */ +#define ACS_BULLET (acs_map['~']) /* bullet */ +/* Teletype 5410v1 symbols begin here */ +#define ACS_LARROW (acs_map[',']) /* arrow pointing left */ +#define ACS_RARROW (acs_map['+']) /* arrow pointing right */ +#define ACS_DARROW (acs_map['.']) /* arrow pointing down */ +#define ACS_UARROW (acs_map['-']) /* arrow pointing up */ +#define ACS_BOARD (acs_map['h']) /* board of squares */ +#define ACS_LANTERN (acs_map['i']) /* lantern symbol */ +#define ACS_BLOCK (acs_map['0']) /* solid square block */ + + +/* + Low-level hardware routines + Have to be defined by user +*/ + +extern void _putch (char ch); /* Writes a character directly to the console. */ +extern int _getch (void); /* Reads a character directly from the console, without echo. */ +extern int _kbhit (void); /* Determines if a keyboard key was pressed.*/ +extern int get_esc_sec (void); + +#ifdef PIC18 +#define ROMDEF const rom +#else +#define ROMDEF const +#endif + +/* + Standard conio routines + Hardware/architecture/compiler independent +*/ +extern void _cputs(ROMDEF char *s); /* Outputs a string directly to the console. */ +extern char* _cgets(char *s); /* Gets a string directly from the console. */ + +extern void clrscr(void); +extern void clreol(void); + +extern void gotoxy(char x, char y); + +extern void cursoron(void); +extern void cursoroff(void); + + +extern void textcolor(int color); +extern void textbackground(int color); +extern void textattr(int attr); + + +#ifdef __cplusplus +} +#endif + + +#endif /* _INC_CONIO */
diff -r 000000000000 -r 6c1bc9b3a347 h/kbd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h/kbd.h Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,110 @@ +/* + kbd.h + Keyboard codes descriptions (defines). + Part of MicroVGA CONIO library / demo project + Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#define KB_ESC 0x1B +#define KB_ENTER 0x0A +#define KB_TAB 0x09 +#define KB_BACK 0x08 +#define KB_SPACE 0x20 + +#define KB_F1 (0X100|59) +#define KB_F2 (0X100|60) +#define KB_F3 (0X100|61) +#define KB_F4 (0X100|62) +#define KB_F5 (0X100|63) +#define KB_F6 (0X100|64) +#define KB_F7 (0X100|65) +#define KB_F8 (0X100|66) +#define KB_F9 (0X100|67) +#define KB_F10 (0X100|68) +#define KB_F11 (0X100|133) +#define KB_F12 (0X100|134) + +#define KB_SHIFT_F1 (0X100|84) +#define KB_SHIFT_F2 (0X100|85) +#define KB_SHIFT_F3 (0X100|86) +#define KB_SHIFT_F4 (0X100|87) +#define KB_SHIFT_F5 (0X100|88) +#define KB_SHIFT_F6 (0X100|89) +#define KB_SHIFT_F7 (0X100|90) +#define KB_SHIFT_F8 (0X100|91) +#define KB_SHIFT_F9 (0X100|92) +#define KB_SHIFT_F10 (0X100|93) +#define KB_SHIFT_F11 (0X100|135) +#define KB_SHIFT_F12 (0X100|136) + +#define KB_CTRL_F1 (0X100|94) +#define KB_CTRL_F2 (0X100|95) +#define KB_CTRL_F3 (0X100|96) +#define KB_CTRL_F4 (0X100|97) +#define KB_CTRL_F5 (0X100|98) +#define KB_CTRL_F6 (0X100|99) +#define KB_CTRL_F7 (0X100|100) +#define KB_CTRL_F8 (0X100|101) +#define KB_CTRL_F9 (0X100|102) +#define KB_CTRL_F10 (0X100|103) +#define KB_CTRL_F11 (0X100|137) +#define KB_CTRL_F12 (0X100|138) + +#define KB_ALT_F1 (0X100|104) +#define KB_ALT_F2 (0X100|105) +#define KB_ALT_F3 (0X100|106) +#define KB_ALT_F4 (0X100|107) +#define KB_ALT_F5 (0X100|108) +#define KB_ALT_F6 (0X100|109) +#define KB_ALT_F7 (0X100|110) +#define KB_ALT_F8 (0X100|111) +#define KB_ALT_F9 (0X100|112) +#define KB_ALT_F10 (0X100|113) +#define KB_ALT_F11 (0X100|139) +#define KB_ALT_F12 (0X100|140) + +#define KB_UP (0X100|72) +#define KB_LEFT (0X100|75) +#define KB_RIGHT (0X100|77) +#define KB_DOWN (0X100|80) +#define KB_HOME (0X100|71) +#define KB_END (0X100|79) +#define KB_PGUP (0X100|73) +#define KB_PGDN (0X100|81) +#define KB_INSERT (0X100|82) +#define KB_DELETE (0X100|83) + +#define KB_CTRL_UP (0X100|132) +#define KB_CTRL_LEFT (0X100|115) +#define KB_CTRL_RIGHT (0X100|116) +#define KB_CTRL_DOWN (0X100|145) +#define KB_CTRL_HOME (0X100|119) +#define KB_CTRL_END (0X100|117) +#define KB_CTRL_PGUP (0X100|132) +#define KB_CTRL_PGDN (0X100|118) +#define KB_CTRL_INSERT (0X100|146) +#define KB_CTRL_DELETE (0X100|147) + +#define KB_ALT_UP (0X100|152) +#define KB_ALT_LEFT (0X100|155) +#define KB_ALT_RIGHT (0X100|157) +#define KB_ALT_DOWN (0X100|154) +#define KB_ALT_HOME (0X100|151) +#define KB_ALT_END (0X100|159) +#define KB_ALT_PGUP (0X100|153) +#define KB_ALT_PGDN (0X100|161) +#define KB_ALT_INSERT (0X100|162) +#define KB_ALT_DELETE (0X100|163) \ No newline at end of file
diff -r 000000000000 -r 6c1bc9b3a347 h/ui.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h/ui.h Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,31 @@ +/* + ui.h + User interface functions. + Part of MicroVGA CONIO library / demo project + Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +//Display Northon Commander like function key menu on bottom of the screen. +void drawfkeys(ROMDEF char *fkeys[]); + +//Display text-based selection menu on the screen. +//int runmenu(char x, char y, const char *menu[], int defaultitem); +int runmenu(char x, char y,ROMDEF char *menu[], int defaultitem); + +//Display empty frame on the screen. +void drawframe(int x, int y, int width, int height, int color); + +/* */ \ No newline at end of file
diff -r 000000000000 -r 6c1bc9b3a347 hw_mbed.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hw_mbed.c Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" +#include "conio.h" + +Serial pc(USBTX, USBRX); + +int get_esc_sec () { + int ch; + if (pc.scanf("\x1b\x5b%c",ch) == 0) + return 0; + else + return ch; +} + +int _kbhit (void) { + return pc.readable(); +} + + +void _putch (char ch) { + pc.putc(ch); +} + +int _getch (void) { + int ret; + + while (!_kbhit()); //wait and read new char + ret = pc.getc(); + if (ret==0) { + while (!_kbhit()); //wait and read new char + ret = pc.getc(); + ret = ret | 0x100; + } + + return ret; +} + + +void MCU_Init(void) { + pc.baud(19200); +} \ No newline at end of file
diff -r 000000000000 -r 6c1bc9b3a347 lib/conio.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/conio.c Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,173 @@ +/* + conio.c + Standard conio routines. + Part of MicroVGA CONIO library / demo project + Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "../h/conio.h" +#include "../h/ui.h" +#include "../h/kbd.h" + + + +void clrscr(void) +{ + _putch('\033'); + _putch('['); + _putch('2'); + _putch('J'); +} + +void clreol(void) +{ + _putch('\033'); + _putch('['); + _putch('K'); +} + + +void cursoron(void) +{ + _putch('\033'); + _putch('['); + _putch('2'); + _putch('5'); + _putch('h'); +} + +void cursoroff(void) +{ + _putch('\033'); + _putch('['); + _putch('2'); + _putch('5'); + _putch('l'); +} + +void textcolor(int color) +{ + _putch('\033'); + _putch('['); + if (color & 0x8) + _putch('1'); + else _putch('2'); + _putch('m'); + + _putch('\033'); + _putch('['); + _putch('3'); + _putch(((color&0x7)%10)+'0'); + _putch('m'); +} + +void textbackground(int color) +{ + _putch('\033'); + _putch('['); + if (color & 0x8) + _putch('5'); + else _putch('6'); + _putch('m'); + + _putch('\033'); + _putch('['); + _putch('4'); + _putch((color&0x7)+'0'); + _putch('m'); +} + +void textattr(int attr) +{ + textcolor(attr&0xF); + textbackground(attr>>4); +} + +void gotoxy(char x, char y) +{ + if (x>MAX_X || y>MAX_Y) + return; + + x--; + y--; + + _putch(0x1B); + _putch('['); + _putch((y/10)+'0'); + _putch((y%10)+'0'); + _putch(';'); + _putch((x/10)+'0'); + _putch((x%10)+'0'); + _putch('f'); +} + + +void _cputs(ROMDEF char *s) +{ + while (*s != 0) + _putch(*s++); +} + +char * _cgets(char *s) +{ + char len; + int ch; + + len=0; + + while (s[0]>len) + { + ch=_getch(); + + if (ch==KB_ENTER) + break; //enter hit, end of input + + if (ch==KB_ESC) { + s[1]=0; + s[2]=0; + return &s[2]; + } + + + if (ch==KB_BACK) + { + + if (len>0) + { + len--; + //delete char and go back (if some chars left) + _putch(KB_BACK); + _putch(' '); + _putch(KB_BACK); + + } + + continue; + } + + if (ch>0x80 || ch <' ') //skip functions keys + continue; + + _putch((char)0xff&ch); //print back to screen + s[len+2]=(char)0xff&ch; + len++; + } + + s[1]=len; + s[len+2]=0; + + return &s[2]; +} \ No newline at end of file
diff -r 000000000000 -r 6c1bc9b3a347 lib/ui.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/ui.c Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,166 @@ +/* + ui.c + User interface functions. + Part of MicroVGA CONIO library / demo project + Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "conio.h" +#include "ui.h" +#include "kbd.h" + + +int runmenu(char x, char y, ROMDEF char *menu[], int defaultitem) +{ + int keys[3], i,j, itemno; + int nitems, width; + ROMDEF char *s; + + itemno = defaultitem-1; + width = 20; + + width = 10; + nitems = 0; + while (menu[nitems] != 0) { + for (j=0;menu[nitems][j];j++); + if (j>width) + width = j; + nitems++; + } + width+=2; + + if (itemno < 0 || itemno > nitems) + itemno = 0; + + while (1) { + + + cursoroff(); + textattr(CYAN<<4 | BLACK); + gotoxy(x,y); + _putch(ACS_ULCORNER); + for (i=0;i<width+2;i++) + _putch(ACS_HLINE); + _putch(ACS_URCORNER); + + for (i = 0;i<nitems;i++) { + gotoxy(x,y+i+1); + _putch(ACS_VLINE); + _putch(' '); + if (i == itemno) + textattr(YELLOW); + s = 0; + for (j=0;j<width;j++) { + if (s && *s) + _putch(*s++); + else _putch(' '); + if (s == 0) + s = (ROMDEF char *)menu[i]; + } + textattr(CYAN<<4 | BLACK); + _putch(' '); + _putch(ACS_VLINE); + } + + gotoxy(x,y+nitems+1); + _putch(ACS_LLCORNER); + for (i=0;i<width+2;i++) + _putch(ACS_HLINE); + _putch(ACS_LRCORNER); + + + while (!_kbhit()) ; + + if (_kbhit()) { + keys[0] = keys[1]; + keys[1] = keys[2]; + keys[2] = _getch(); + if (keys[0] == 0x1b && keys[1] == 0x5b) + { + switch (keys[2]) { + case 'A': if (itemno>0) itemno--; else itemno = nitems-1; break; + case 'B': itemno++; itemno %= nitems; break; + } + } + else + switch(keys[0]) { + case KB_ENTER : cursoron(); return itemno+1; + case KB_ESC: cursoron(); return 0; + } + } + } +} + + + +void drawfkeys(ROMDEF char *fkeys[]) +{ + ROMDEF char *s; + int i, j; + + gotoxy(1,25); + for (i=0;i<10;i++) { + textcolor(WHITE); + textbackground(BLACK); + if (i!= 0) + _putch(' '); + if (i== 9) { + _putch('1'); + _putch('0'); + } else + _putch((i%10)+'1'); + textcolor(BLACK); + textbackground(CYAN); + + s = fkeys[i] ? fkeys[i] : 0; + for (j=0;j<6;j++) { + if (s && *s) + _putch(*s++); + else _putch(' '); + } + } +} + +void drawframe(int x, int y, int width, int height, int color) +{ + int i,j; + + textattr(color); + gotoxy(x,y); + + _putch(ACS_ULCORNER); + for (i=0;i<width+2;i++) + _putch(ACS_HLINE); + _putch(ACS_URCORNER); + + for (i = 0;i<height;i++) { + gotoxy(x,y+i+1); + _putch(ACS_VLINE); + _putch(' '); + + for (j=0;j<width;j++) { + _putch(' '); + } + _putch(' '); + _putch(ACS_VLINE); + } + + gotoxy(x,y+height+1); + _putch(ACS_LLCORNER); + for (i=0;i<width+2;i++) + _putch(ACS_HLINE); + _putch(ACS_LRCORNER); +} \ No newline at end of file
diff -r 000000000000 -r 6c1bc9b3a347 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,378 @@ +/* + main.c + Main demo file. Using conio functions to display demo userinterface. + Part of MicroVGA CONIO library / demo project + Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "conio.h" +#include "kbd.h" +#include "ui.h" + +#ifdef AVR_MCU //WinAvr - AVR MCU - has to be defined in project settings +#define LOWMEM 1 +#endif + +#ifdef __ICC78K__ +#define LOWMEM 1 +#endif + +#if RENESAS_C //Renessa High performance Emb. Workshop- has to be defined in project settings +#define LOWMEM 1 +#endif + +#ifndef LOWMEM +#include "aa.c" //ascii art +#endif + +extern void MCU_Init(void); + + +/*const static char *nc_fkeys[10] = +{"Help","Menu","View","Edit","Copy","RenMov","Mkdir","Delete","Setup","Quit"}; +*/ + +ROMDEF static char *memview_fkeys[10] = +{"Help",0,0,0,"DynMem",0,0,0,0,"Quit"}; + +ROMDEF static char *mainmenu[] = +{ + "Memory viewer", + "Console debug demo", + "Speed test", + "Test sub menu", + "Command line interface", + "ASCII-Art test", + "Input dialog test", + 0 +}; + +ROMDEF static char *submenu1[] = +//far const rom char *submenu1[] = +{ + "Menu item number 1", + "Menu item number 2", + "Some other menu", + "And finally last menu item", + 0 +}; + +const static char hexchars[] = "0123456789ABCDEF"; + +void drawmem(const unsigned char *mem) +{ + const unsigned char *mptr; + int i,j; + + + textbackground(BLUE); + for (i=0;i<23 && !_kbhit();i++) { + mptr = &mem[i*16]; + gotoxy(1,i+2); + textcolor(YELLOW); + j = 8; + do { + j--; + _putch(hexchars[ (((int)mptr)>>(j*4)) &0xF] ); + } while (j>0); + _cputs(": "); + textcolor(WHITE); + + for (j=0;j<16;j++) { + _putch(hexchars[*mptr>>4]); + _putch(hexchars[*mptr&0xF]); + mptr++; + _putch(' '); + if (j == 7) { + _putch('-'); + _putch(' '); + } + } + + _putch(179); + _putch(' '); + + mptr = &mem[i*16]; + for (j=0;j<16;j++) { + if (*mptr >= ' ') + _putch(*mptr); + else _putch('.'); + mptr++; + } + + clreol(); + } +} + + +void memviewer(void *start) +{ +#ifndef LOWMEM + int key; + const unsigned char *mem; + + textattr(LIGHTGRAY | BLUE <<4); + clrscr(); + textcolor(BLACK); + textbackground(CYAN); + _cputs("Memory viewer"); + clreol(); + + cursoroff(); + drawfkeys(memview_fkeys); + + mem=(const unsigned char *)start; + for (;;) { + drawmem(mem); + + if (_kbhit()) { + key = _getch(); + switch(key) { + case KB_LEFT: if ((int)mem > 0 ) (int)mem--; break; + case KB_RIGHT: mem++; break; + case KB_UP: if (mem >= (unsigned char const *)16) mem-=16; break; + case KB_DOWN: mem+=16; break; + case KB_PGUP: if (mem >= (unsigned char const *)(16*23)) mem-=16*23; break; + case KB_PGDN: mem+=16*23; break; + case KB_F10: cursoron(); return ; + } + } + + } + #else + textattr(LIGHTGRAY); + clrscr(); + _cputs("Not enought memory for this feature"); + + while (_getch() != KB_ESC); + #endif +} + +void debugdemo() +{ + int key; + + textattr(LIGHTGRAY); + clrscr(); + + while (1) { + _cputs("Debug line 1\r\n"); + if (_kbhit()) { + key = _getch(); + _cputs("You have pressed key"); + _putch(key); + _cputs("\r\n"); + if (key == KB_ESC) + return ; + } + } +} + + +void cli() +{ + char buffer[40]; + char * out; + + textattr(LIGHTGRAY); + + clrscr(); + + while (1) { + //read data + buffer[0]=40; + + textattr(YELLOW); + _cputs("uVGA> "); + textattr(LIGHTGRAY); + out=_cgets(buffer); + + if (out != 0 && out[0] == 'q' && out[1] == 0) + return ; + + textattr(WHITE); + _cputs("\r\nUnsupported command. Only "); + textattr(LIGHTRED); + _cputs("q"); + textattr(WHITE); + _cputs(" (exit) is supported.\r\n"); + } +} + + +void speedtest(void) +{ + unsigned int i; + + gotoxy(1,1); + textattr(GREEN<<4 | YELLOW); + + for (i=0;i<50000;i++) { + _cputs("TEST50=>"); + _putch(((i/10000)%10) + '0'); + _putch(((i/1000)%10) + '0'); + _cputs("\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08"); + } +} + + +void submenutest() +{ +int item; + + item = 0; + + while (1) { + + item = runmenu(8,10, submenu1, item); + switch (item) { + case 0: return ; + } + } +} + + +void ascii_art() +{ + #ifndef LOWMEM + textattr(LIGHTGRAY); + clrscr(); + +// _cputs((const char *)ascii_art_str); + + while (_getch() != KB_ESC); + #else + textattr(LIGHTGRAY); + clrscr(); + _cputs("Not enought memory for this feature"); + + while (_getch() != KB_ESC); + #endif +} + +void testCGetS() +{ + char buffer[40]; + char * out; + int i; + + //draw input dialog (frame) + drawframe(10, 10, 40, 9, WHITE | RED <<4); + gotoxy(12,12); + _cputs("Enter your name:"); + gotoxy(12,14); + textattr(WHITE | BLACK <<4); + for (i=0;i<40;i++) + _putch(' '); + + //read data + gotoxy(12,14); + buffer[0]=40; + + out=_cgets(buffer); + + //write read data + gotoxy(12,16); + if (buffer[1]==0) + { + textattr((WHITE | RED <<4)|BLINK); + _cputs("You didn't enter your name!"); + } + else + { + textattr((WHITE | RED <<4)); + _cputs("Your name is:\n"); + gotoxy(12,17); + _cputs(out); + } + cursoroff(); + + gotoxy(23,19); + textattr((WHITE | RED <<4)|BLINK); + _cputs("PRESS ESC TO EXIT"); + + //wait for ESC press + while (_getch() != KB_ESC); +} + +#ifndef LOWMEM +static ROMDEF char *uvga_logo= +" ## ## #### # " +" ## ## ## ## ### " +" ## ## ## # ## ## " +" ## ## ## ## ## ## ##" +" ## ## ## ## ## ## ##" +" ## ## ## ## ## #### #######" +" ## ## ## ## ## ## ## ##" +" ## ## ## ## ## ## ## ##" +" ##### #### ## ## ## ##" +" ## ## ### # ## ##" +" ## MicroVGA demo application" +"## " +"www.MicroVGA.com, www.secons.com"; +#endif + +void main() +{ + int i,j; + int item; + +//////////// Main routine + + MCU_Init(); + + + item = 0; + + while (1) { + + textbackground(BLUE); + clrscr(); + textcolor(BLACK); + textbackground(CYAN); + _cputs("MicroVGA demo app"); + + clreol(); + textbackground(BLUE); + textcolor(GREEN); + + +#ifndef LOWMEM + // draw "logo" + for (i=0;i<13;i++) { + gotoxy(46,12+i); + for (j=0;j<32;j++) { + if (uvga_logo[i*32+ j] == '#') + _putch(219); + else _putch(uvga_logo[i*32+ j]); + } + } +#endif + + + item = runmenu(5,5, mainmenu, item); + switch (item) { + case 1: memviewer(0); break; + case 2: debugdemo(); break; + case 3: speedtest(); break; + case 4: submenutest(); break; + case 5: cli(); break; + case 6: ascii_art(); break; + case 7: testCGetS(); break; + + } + } +}
diff -r 000000000000 -r 6c1bc9b3a347 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 19 20:20:10 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0