|
|
1.1 ! root 1: /* $Id: x_cio.c,v 1.10 2004/09/22 04:03:06 deuce Exp $ */ ! 2: ! 3: /**************************************************************************** ! 4: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 5: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 6: * * ! 7: * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html * ! 8: * * ! 9: * This library is free software; you can redistribute it and/or * ! 10: * modify it under the terms of the GNU Lesser General Public License * ! 11: * as published by the Free Software Foundation; either version 2 * ! 12: * of the License, or (at your option) any later version. * ! 13: * See the GNU Lesser General Public License for more details: lgpl.txt or * ! 14: * http://www.fsf.org/copyleft/lesser.html * ! 15: * * ! 16: * Anonymous FTP access to the most recent released source is available at * ! 17: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 18: * * ! 19: * Anonymous CVS access to the development source and modification history * ! 20: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 21: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 22: * (just hit return, no password is necessary) * ! 23: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 24: * * ! 25: * For Synchronet coding style and modification guidelines, see * ! 26: * http://www.synchro.net/source.html * ! 27: * * ! 28: * You are encouraged to submit any modifications (preferably in Unix diff * ! 29: * format) via e-mail to [email protected] * ! 30: * * ! 31: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 32: ****************************************************************************/ ! 33: ! 34: #include <stdarg.h> ! 35: #include <stdio.h> ! 36: ! 37: #include <threadwrap.h> ! 38: ! 39: #include "ciolib.h" ! 40: #include "x_cio.h" ! 41: #include "console.h" ! 42: WORD x_curr_attr=0x0700; ! 43: ! 44: const int x_tabs[10]={9,17,25,33,41,49,57,65,73,80}; ! 45: ! 46: int x_puttext(int sx, int sy, int ex, int ey, void *fill) ! 47: { ! 48: int x,y; ! 49: unsigned char *out; ! 50: WORD sch; ! 51: struct text_info ti; ! 52: ! 53: gettextinfo(&ti); ! 54: ! 55: if( sx < 1 ! 56: || sy < 1 ! 57: || ex < 1 ! 58: || ey < 1 ! 59: || sx > ti.screenwidth ! 60: || sy > ti.screenheight ! 61: || sx > ex ! 62: || sy > ey ! 63: || ex > ti.screenwidth ! 64: || ey > ti.screenheight ! 65: || fill==NULL) ! 66: return(0); ! 67: ! 68: out=fill; ! 69: for(y=sy-1;y<ey;y++) { ! 70: for(x=sx-1;x<ex;x++) { ! 71: sch=*(out++); ! 72: sch |= (*(out++))<<8; ! 73: vmem[y*DpyCols+x]=sch; ! 74: } ! 75: } ! 76: } ! 77: ! 78: int x_gettext(int sx, int sy, int ex, int ey, void *fill) ! 79: { ! 80: int x,y; ! 81: unsigned char *out; ! 82: WORD sch; ! 83: struct text_info ti; ! 84: ! 85: gettextinfo(&ti); ! 86: ! 87: if( sx < 1 ! 88: || sy < 1 ! 89: || ex < 1 ! 90: || ey < 1 ! 91: || sx > ti.screenwidth ! 92: || sy > ti.screenheight ! 93: || sx > ex ! 94: || sy > ey ! 95: || ex > ti.screenwidth ! 96: || ey > ti.screenheight ! 97: || fill==NULL) ! 98: return(0); ! 99: ! 100: out=fill; ! 101: for(y=sy-1;y<ey;y++) { ! 102: for(x=sx-1;x<ex;x++) { ! 103: sch=vmem[y*DpyCols+x]; ! 104: *(out++)=sch & 0xff; ! 105: *(out++)=sch >> 8; ! 106: } ! 107: } ! 108: } ! 109: ! 110: void x_textattr(int attr) ! 111: { ! 112: x_curr_attr=attr<<8; ! 113: } ! 114: ! 115: int x_kbhit(void) ! 116: { ! 117: return(tty_kbhit()); ! 118: } ! 119: ! 120: void x_delay(long msec) ! 121: { ! 122: usleep(msec*1000); ! 123: } ! 124: ! 125: int x_wherey(void) ! 126: { ! 127: return(CursRow+1); ! 128: } ! 129: ! 130: int x_wherex(void) ! 131: { ! 132: return(CursCol+1); ! 133: } ! 134: ! 135: /* Put the character _c on the screen at the current cursor position. ! 136: * The special characters return, linefeed, bell, and backspace are handled ! 137: * properly, as is line wrap and scrolling. The cursor position is updated. ! 138: */ ! 139: int x_putch(int ch) ! 140: { ! 141: struct text_info ti; ! 142: WORD sch; ! 143: int i; ! 144: ! 145: sch=x_curr_attr|ch; ! 146: ! 147: switch(ch) { ! 148: case '\r': ! 149: gettextinfo(&ti); ! 150: CursCol=ti.winleft-1; ! 151: break; ! 152: case '\n': ! 153: gettextinfo(&ti); ! 154: if(wherey()==ti.winbottom-ti.wintop+1) ! 155: wscroll(); ! 156: else ! 157: CursRow++; ! 158: break; ! 159: case '\b': ! 160: if(CursCol>0) ! 161: CursCol--; ! 162: vmem[CursCol+CursRow*DpyCols]=x_curr_attr|' '; ! 163: break; ! 164: case 7: /* Bell */ ! 165: tty_beep(); ! 166: break; ! 167: case '\t': ! 168: for(i=0;i<10;i++) { ! 169: if(x_tabs[i]>wherex()) { ! 170: while(wherex()<x_tabs[i]) { ! 171: putch(' '); ! 172: } ! 173: break; ! 174: } ! 175: } ! 176: if(i==10) { ! 177: putch('\r'); ! 178: putch('\n'); ! 179: } ! 180: break; ! 181: default: ! 182: gettextinfo(&ti); ! 183: if(wherey()==ti.winbottom-ti.wintop+1 ! 184: && wherex()==ti.winright-ti.winleft+1) { ! 185: vmem[CursCol+CursRow*DpyCols]=sch; ! 186: wscroll(); ! 187: gotoxy(ti.winleft,wherey()); ! 188: } ! 189: else { ! 190: if(wherex()==ti.winright-ti.winleft+1) { ! 191: vmem[CursCol+CursRow*DpyCols]=sch; ! 192: gotoxy(ti.winleft,ti.cury+1); ! 193: } ! 194: else { ! 195: vmem[CursCol+CursRow*DpyCols]=sch; ! 196: gotoxy(ti.curx+1,ti.cury); ! 197: } ! 198: } ! 199: break; ! 200: } ! 201: ! 202: return(ch); ! 203: } ! 204: ! 205: void x_gotoxy(int x, int y) ! 206: { ! 207: CursRow=y-1; ! 208: CursCol=x-1; ! 209: } ! 210: ! 211: void x_gettextinfo(struct text_info *info) ! 212: { ! 213: info->currmode=CurrMode; ! 214: info->screenheight=DpyRows+1; ! 215: info->screenwidth=DpyCols; ! 216: info->curx=wherex(); ! 217: info->cury=wherey(); ! 218: info->attribute=x_curr_attr>>8; ! 219: } ! 220: ! 221: void x_setcursortype(int type) ! 222: { ! 223: switch(type) { ! 224: case _NOCURSOR: ! 225: CursStart=0xff; ! 226: CursEnd=0; ! 227: break; ! 228: case _SOLIDCURSOR: ! 229: CursStart=0; ! 230: CursEnd=FH-1; ! 231: break; ! 232: default: ! 233: CursStart = InitCS; ! 234: CursEnd = InitCE; ! 235: break; ! 236: } ! 237: } ! 238: ! 239: int x_getch(void) ! 240: { ! 241: return(tty_read(TTYF_BLOCK)); ! 242: } ! 243: ! 244: int x_getche(void) ! 245: { ! 246: int ch; ! 247: ! 248: if(x_nextchar) ! 249: return(x_getch()); ! 250: ch=x_getch(); ! 251: if(ch) ! 252: putch(ch); ! 253: return(ch); ! 254: } ! 255: ! 256: int x_beep(void) ! 257: { ! 258: tty_beep(); ! 259: return(0); ! 260: } ! 261: ! 262: void x_textmode(int mode) ! 263: { ! 264: console_new_mode=mode; ! 265: sem_wait(&console_mode_changed); ! 266: } ! 267: ! 268: void x_settitle(const char *title) ! 269: { ! 270: x_win_title(title); ! 271: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.