1 /* 2 * Small C+ Library 3 * 4 * conio.h - old apps compatibility 5 * 6 * This helps expecially with the kbhit() instruction 7 * it exists on many old compilers; the mingw port has it 8 * on "conio.h", so here it is ! 9 * 10 * stefano - 18/3/2004 11 * 12 * $Id: conio.h,v 1.10 2013-06-20 08:25:45 stefano Exp $ 13 */ 14 15 #ifndef __CONIO_H__ 16 #define __CONIO_H__ 17 18 // this is used by getch, putch and ungetch. 19 #include <sys/compiler.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 //#include <graphics.h> 23 #include <dos.h> 24 #include <X11/Xz88dk.h> 25 26 27 #define MAXCOLORS 15 28 enum colors { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, DARKGRAY, 29 LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE }; 30 31 32 33 #ifdef __CONIO_VT100 34 // Much faster shortcut passing the colors in vt-ansi mode (equivalent to a "set text rendition" ESC sequence) 35 extern void __LIB__ vtrendition(unsigned int attribute) __z88dk_fastcall; 36 37 // Color translation table 38 static int PCDOS_COLORS[]={0,4,2,6,1,5,1,7,4,6,2,6,1,5,3,7}; 39 40 // QUICK C syntax 41 #define settextcolor(a) vtrendition(PCDOS_COLORS[a]+30) 42 43 // TURBO C syntax 44 #define textcolor(a) vtrendition(PCDOS_COLORS[a]+30) 45 #define textbackground(a) vtrendition(PCDOS_COLORS[a]+40) 46 47 #define textattr(a) vtrendition(PCDOS_COLORS[a&0xF]+30); vtrendition(PCDOS_COLORS[a>>4]+40) 48 49 #define highvideo() vtrendition(1) 50 #define lowvideo() vtrendition(2) 51 #define normvideo() vtrendition(0) 52 #define clreol() printf("\033[K") 53 54 // Useless, DL is not fully implemented in the VT-ansi engine 55 //#define delline() printf("\033[M") 56 57 #define clrscr() fputc_cons(12) 58 #else 59 // Definitions for VT52/generic console, these set common variables for both VT100 and 60 // VT52, but may drag in more code than intended. 61 62 extern void __LIB__ textcolor(int c) __z88dk_fastcall; 63 extern void __LIB__ textbackground(int c) __z88dk_fastcall; 64 #define clrscr() fputc_cons(12) 65 #endif 66 67 68 69 extern int __LIB__ wherex (void); 70 extern int __LIB__ wherey (void); 71 extern void __LIB__ gotoxy(unsigned int x, unsigned int y) __smallc; 72 extern void __LIB__ gotoxy_callee(unsigned int x, unsigned int y) __smallc __z88dk_callee; 73 74 extern void __LIB__ screensize(unsigned int *x, unsigned int *y) __smallc; 75 extern void __LIB__ screensize_callee(unsigned char *x, unsigned char *y) __smallc __z88dk_callee; 76 77 #define gotoxy(a,b) gotoxy_callee(a,b) 78 #define screensize(a,b) screensize_callee(a,b) 79 80 81 /* The leading underscores are for compatibility with the 82 * Digital Mars library */ 83 84 extern int __LIB__ cprintf(const char *fmt,...) __vasmallc; 85 #define _cprintf cprintf 86 extern void __LIB__ cputs(const char *message); 87 #define _cputs cputs 88 extern void __LIB__ cgets(char *dest); 89 #define _cgets cgets 90 91 #define cscanf scanf 92 #define _cscanf scanf 93 94 /* Reads a character directly from the console, (with echo ?) */ 95 #define getche() getch() // not sure about this one... 96 #define _getche() getch() // not sure about this one... 97 // Direct output to console 98 #define putch(a) fputc_cons(a) 99 #define _putch(a) fputc_cons(a) 100 101 // can't be fixed easily.. i.e. the simplified gets won't work 102 //#define ungetch(bp) ungetc(bp,stdin) // this one doesn't work 103 //#define _ungetch(bp) ungetc(bp,stdin) // this one doesn't work 104 105 #define random(a) rand()%a 106 107 extern int __LIB__ kbhit(void); 108 extern int __LIB__ getch(void); 109 110 // Get the character that is on screen at the specified location 111 extern int __LIB__ cvpeek(int x, int y) __smallc; 112 113 114 // Get the character that is on screen at the specified location (no charset 115 // translations will be made) 116 extern int __LIB__ cvpeekr(int x, int y) __smallc; 117 118 // Set the border colour, may not be implemented on all ports 119 extern int __LIB__ bordercolor(int c) __z88dk_fastcall; 120 121 // Missing functions, not implemented 122 //extern int __LIB__ movetext (int _left, int _top, int _right, int _bottom, int _destleft, int _desttop); 123 //extern int __LIB__ gettext (int left, int top, int right, int bottom, void *destin); 124 125 126 // CC65 compatibility 127 #define cgetc() getch() 128 #define cputc(a) fputc_cons(a) 129 130 131 #endif /* _CONIO_H */ 132