Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
conio.c
00001 /* 00002 conio.c 00003 Standard conio routines. 00004 Part of MicroVGA CONIO library / demo project 00005 Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com 00006 00007 This program is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "../h/conio.h" 00022 #include "../h/ui.h" 00023 #include "../h/kbd.h" 00024 00025 00026 00027 void clrscr(void) 00028 { 00029 _putch('\033'); 00030 _putch('['); 00031 _putch('2'); 00032 _putch('J'); 00033 } 00034 00035 void clreol(void) 00036 { 00037 _putch('\033'); 00038 _putch('['); 00039 _putch('K'); 00040 } 00041 00042 00043 void cursoron(void) 00044 { 00045 _putch('\033'); 00046 _putch('['); 00047 _putch('2'); 00048 _putch('5'); 00049 _putch('h'); 00050 } 00051 00052 void cursoroff(void) 00053 { 00054 _putch('\033'); 00055 _putch('['); 00056 _putch('2'); 00057 _putch('5'); 00058 _putch('l'); 00059 } 00060 00061 void textcolor(int color) 00062 { 00063 _putch('\033'); 00064 _putch('['); 00065 if (color & 0x8) 00066 _putch('1'); 00067 else _putch('2'); 00068 _putch('m'); 00069 00070 _putch('\033'); 00071 _putch('['); 00072 _putch('3'); 00073 _putch(((color&0x7)%10)+'0'); 00074 _putch('m'); 00075 } 00076 00077 void textbackground(int color) 00078 { 00079 _putch('\033'); 00080 _putch('['); 00081 if (color & 0x8) 00082 _putch('5'); 00083 else _putch('6'); 00084 _putch('m'); 00085 00086 _putch('\033'); 00087 _putch('['); 00088 _putch('4'); 00089 _putch((color&0x7)+'0'); 00090 _putch('m'); 00091 } 00092 00093 void textattr(int attr) 00094 { 00095 textcolor(attr&0xF); 00096 textbackground(attr>>4); 00097 } 00098 00099 void gotoxy(char x, char y) 00100 { 00101 if (x>MAX_X || y>MAX_Y) 00102 return; 00103 00104 x--; 00105 y--; 00106 00107 _putch(0x1B); 00108 _putch('['); 00109 _putch((y/10)+'0'); 00110 _putch((y%10)+'0'); 00111 _putch(';'); 00112 _putch((x/10)+'0'); 00113 _putch((x%10)+'0'); 00114 _putch('f'); 00115 } 00116 00117 00118 void _cputs(ROMDEF char *s) 00119 { 00120 while (*s != 0) 00121 _putch(*s++); 00122 } 00123 00124 char * _cgets(char *s) 00125 { 00126 char len; 00127 int ch; 00128 00129 len=0; 00130 00131 while (s[0]>len) 00132 { 00133 ch=_getch(); 00134 00135 if (ch==KB_ENTER) 00136 break; //enter hit, end of input 00137 00138 if (ch==KB_ESC) { 00139 s[1]=0; 00140 s[2]=0; 00141 return &s[2]; 00142 } 00143 00144 00145 if (ch==KB_BACK) 00146 { 00147 00148 if (len>0) 00149 { 00150 len--; 00151 //delete char and go back (if some chars left) 00152 _putch(KB_BACK); 00153 _putch(' '); 00154 _putch(KB_BACK); 00155 00156 } 00157 00158 continue; 00159 } 00160 00161 if (ch>0x80 || ch <' ') //skip functions keys 00162 continue; 00163 00164 _putch((char)0xff&ch); //print back to screen 00165 s[len+2]=(char)0xff&ch; 00166 len++; 00167 } 00168 00169 s[1]=len; 00170 s[len+2]=0; 00171 00172 return &s[2]; 00173 }
Generated on Thu Jul 14 2022 01:28:10 by
1.7.2