diff --git a/configure.ac b/configure.ac index 9134f0c..0870f14 100644 --- a/configure.ac +++ b/configure.ac @@ -18,10 +18,17 @@ AC_ARG_ENABLE(slang, [ --enable-slang slang graphics support (default enabled)]) AC_ARG_ENABLE(ncurses, [ --enable-ncurses ncurses graphics support (default disabled)]) +AC_ARG_ENABLE(conio, + [ --enable-conio DOS conio.h graphics support (default disabled)]) USE_SLANG=false USE_NCURSES=false -if test "${enable_ncurses}" = "yes"; then +USE_CONIO=false +if test "${enable_conio}" = "yes"; then + AC_CHECK_HEADER(conio.h,:,AC_MSG_ERROR([cannot find conio.h header])) + AC_DEFINE(USE_CONIO, 1, Define if the backend driver is conio.h) + USE_CONIO=: +elif test "${enable_ncurses}" = "yes"; then AC_CHECK_HEADER(ncurses.h,:,AC_MSG_ERROR([cannot find ncurses headers])) AC_CHECK_LIB(ncurses,initscr,:,AC_MSG_ERROR([cannot find ncurses library])) AC_DEFINE(USE_NCURSES, 1, Define if the backend driver is ncurses) diff --git a/libee/conic.c b/libee/conic.c index 460c0e8..a54e675 100644 --- a/libee/conic.c +++ b/libee/conic.c @@ -28,8 +28,13 @@ # include #endif +#ifdef HAVE_INTTYPES_H +# include +#else +typedef unsigned char uint8_t; +#endif + #include -#include #include "ee.h" diff --git a/libee/ee.c b/libee/ee.c index 3d39c8e..009fe97 100644 --- a/libee/ee.c +++ b/libee/ee.c @@ -26,6 +26,10 @@ # include #elif USE_NCURSES # include +#elif USE_CONIO +# include +#else +# error "no graphics library detected" #endif #include @@ -37,6 +41,9 @@ #include "ee.h" static int _ee_delay; +#ifdef USE_CONIO +static struct text_info ti; +#endif int ee_init(void) { @@ -97,8 +104,12 @@ int ee_init(void) init_pair(EE_CYAN, COLOR_CYAN, COLOR_BLACK); init_pair(EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); -#else - /* Dummy driver */ +#elif USE_CONIO + _wscroll = 0; + _setcursortype(_NOCURSOR); + clrscr(); + gettextinfo(&ti); +//window(2, 2, 20, 20); #endif _ee_delay = 0; @@ -117,8 +128,8 @@ int ee_get_width(void) return SLtt_Screen_Cols; #elif USE_NCURSES return COLS; -#else - return 80; +#elif USE_CONIO + return ti.screenwidth; #endif } @@ -129,10 +140,11 @@ int ee_get_height(void) #elif USE_NCURSES return LINES; #else - return 25; + return ti.screenheight; #endif } +#ifndef USE_CONIO static int64_t local_time(void) { struct timeval tv; @@ -144,9 +156,11 @@ static int64_t local_time(void) now += tv.tv_usec; return now; } +#endif void ee_refresh(void) { +#ifndef USE_CONIO static int64_t local_clock = 0; int64_t now; @@ -160,15 +174,17 @@ void ee_refresh(void) { /* If we are late, we shouldn't display anything */ } +#endif #ifdef USE_SLANG SLsmg_refresh(); #elif USE_NCURSES refresh(); -#else - /* Use dummy driver */ +#elif USE_CONIO + /* Do nothing? */ #endif +#ifndef USE_CONIO now = local_time(); if(now < local_clock + _ee_delay - 10000) @@ -177,6 +193,7 @@ void ee_refresh(void) } local_clock += _ee_delay; +#endif } void ee_end(void) @@ -188,8 +205,11 @@ void ee_end(void) #elif USE_NCURSES curs_set(1); endwin(); -#else - /* Use dummy driver */ +#elif USE_CONIO + _wscroll = 1; + ee_set_color(EE_WHITE); + ee_putstr(ee_get_width(), ee_get_height()-1, "\r\n"); + _setcursortype(_NORMALCURSOR); #endif } diff --git a/libee/graphics.c b/libee/graphics.c index 3fd0938..468e5f0 100644 --- a/libee/graphics.c +++ b/libee/graphics.c @@ -26,6 +26,10 @@ # include #elif USE_NCURSES # include +#elif USE_CONIO +# include +#else +# error "no graphics library detected" #endif #include @@ -34,6 +38,21 @@ #include "ee.h" static int ee_color = 0; +#ifdef USE_CONIO +static enum COLORS dos_colors[] = { + 0, + BLACK, + GREEN, + YELLOW, + WHITE, + RED, + DARKGRAY, + LIGHTGRAY, + BLUE, + CYAN, + MAGENTA +}; +#endif void ee_set_color(int color) { @@ -42,8 +61,9 @@ void ee_set_color(int color) SLsmg_set_color(color); #elif USE_NCURSES attrset(COLOR_PAIR(color)); -#else - /* Use dummy driver */ +#elif USE_CONIO + if(color >= 1 && color <= 10) + textcolor(dos_colors[color]); #endif } @@ -60,8 +80,9 @@ void ee_putchar(int x, int y, char c) #elif USE_NCURSES move(y,x); addch(c); -#else - /* Use dummy driver */ +#elif USE_CONIO + gotoxy(x+1,y+1); + putch(c); #endif } @@ -73,15 +94,15 @@ void ee_putstr(int x, int y, char *s) #elif USE_NCURSES move(y,x); addstr(s); -#else - /* Use dummy driver */ +#elif USE_CONIO + gotoxy(x+1,y+1); + cputs(s); #endif } void ee_clear(void) { -#if defined(USE_SLANG) || defined(USE_NCURSES) - /* We could use SLsmg_cls(), but drawing empty lines is much faster */ + /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */ int x = ee_get_width(), y = ee_get_height(); char *empty_line = malloc((x + 1) * sizeof(char)); @@ -94,8 +115,5 @@ void ee_clear(void) } free(empty_line); -#else - /* Use dummy driver */ -#endif } diff --git a/libee/io.c b/libee/io.c index 43aaedb..54dd4d3 100644 --- a/libee/io.c +++ b/libee/io.c @@ -26,6 +26,10 @@ # include #elif USE_NCURSES # include +#elif USE_CONIO +# include +#else +# error "no graphics library detected" #endif #include "ee.h" @@ -44,8 +48,8 @@ char ee_get_key(void) { return key; } -#else - return 0; +#elif USE_CONIO + return _conio_kbhit() ? getch() : 0; #endif diff --git a/libee/line.c b/libee/line.c index c2e79f9..f73333e 100644 --- a/libee/line.c +++ b/libee/line.c @@ -28,7 +28,12 @@ # include #endif -#include +#ifdef HAVE_INTTYPES_H +# include +#else +typedef unsigned char uint8_t; +#endif + #include #include "ee.h"