conio.c (3676B)
1 /* $Id: //depot/blt/lib/conio.c#2 $ 2 ** 3 ** Copyright 1998 Brian J. Swetland 4 ** All rights reserved. 5 ** 6 ** Redistribution and use in source and binary forms, with or without 7 ** modification, are permitted provided that the following conditions 8 ** are met: 9 ** 1. Redistributions of source code must retain the above copyright 10 ** notice, this list of conditions, and the following disclaimer. 11 ** 2. Redistributions in binary form must reproduce the above copyright 12 ** notice, this list of conditions, and the following disclaimer in the 13 ** documentation and/or other materials provided with the distribution. 14 ** 3. The name of the author may not be used to endorse or promote products 15 ** derived from this software without specific prior written permission. 16 ** 17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <blt/conio.h> 30 31 static int attr = 1, px = 0, py = 24; 32 static char *screen = (char *) CON_SCREEN; 33 static char *posn = (char *) CON_SCREEN + 80*24*2; 34 35 static void scrollup(void) 36 { 37 for(posn = screen + 160; posn <= screen + 80*25*2; posn++) 38 *(posn - 160) = *posn; 39 for(posn = screen + 80*24*2; posn <= screen + 80*25*2; posn++){ 40 *posn++ = ' '; 41 *posn = attr; 42 } 43 } 44 45 void con_attr(int a) 46 { 47 attr = a; 48 } 49 50 #define con_init() { con_attr(CON_WHITE); con_clear(); } 51 52 void con_start(unsigned int video) 53 { 54 screen = (char *) video; 55 con_attr(CON_WHITE); 56 con_clear(); 57 } 58 59 60 void con_clear(void) 61 { 62 int i; 63 64 for(posn = screen, i=0;i<80*25;i++){ 65 *posn++ = ' '; 66 *posn++ = attr; 67 } 68 px = 0; 69 py = 24; 70 posn = screen + (24*80)*2; 71 } 72 73 void con_goto(int x, int y) 74 { 75 posn = screen + ((y*80)+x)*2; 76 px = x; 77 py = y; 78 79 } 80 81 /* 82 void con_putc(char ch) 83 { 84 if(ch == '\n'){ 85 goto roll0; 86 } 87 *posn++ = ch; 88 *posn++ = attr; 89 px++; 90 if(px == 80){ 91 roll0: 92 px = 0; 93 if(py == 24) 94 scrollup(); 95 else 96 py++; 97 posn = screen + (py*80+px)*2; 98 } 99 } 100 */ 101 void con_puts(char *s) 102 { 103 while(*s){ 104 if(*s == '\n'){ 105 s++; 106 goto roll1; 107 } 108 *posn++ = *s++; 109 *posn++ = attr; 110 px++; 111 if(px == 80){ 112 roll1: 113 px = 0; 114 if(py == 24) 115 scrollup(); 116 else 117 py++; 118 posn = screen + (py*80+px)*2; 119 } 120 } 121 } 122 /* 123 static char pbuf[9]; 124 125 void con_putp(unsigned int p) 126 { 127 int i; 128 129 pbuf[8] = 0; 130 131 for(i=7;i>=0;i--){ 132 pbuf[i] = (0x0F & p); 133 if(pbuf[i] > 9) pbuf[i] += 'A'-10; 134 else pbuf[i] += '0'; 135 p >>= 4; 136 } 137 con_puts(pbuf); 138 } 139 140 void con_putx(unsigned char x) 141 { 142 pbuf[0] = (x & 0xF0) >> 4; 143 if(pbuf[0] > 9) pbuf[0] += 'A'-10; 144 else pbuf[0] += '0'; 145 pbuf[1] = (x & 0x0F); 146 if(pbuf[1] > 9) pbuf[1] += 'A'-10; 147 else pbuf[1] += '0'; 148 pbuf[2] = 0; 149 con_puts(pbuf); 150 } 151 */ 152 153 void cprintf(char *fmt, ...) 154 { 155 char buf[256]; 156 va_list pvar; 157 va_start(pvar,fmt); 158 va_snprintf(buf,256,fmt,pvar); 159 va_end(pver); 160 con_puts(buf); 161 } 162