+ Added a note about dos cross-compilation. * configure.ac: + Added a check for ScreenUpdate in <pc.h>. * libee/graphics.c libee/ee.c: + Improved the conio port thanks to ScreenUpdate().tags/v0.99.beta14
@@ -6,6 +6,10 @@ Building ttyvaders | |||
--enable-slang: use the SLang library (default) | |||
--enable-ncurses: use the ncurses library | |||
--enable-conio: use MS-DOS conio.h | |||
Cross-compilation example: | |||
./configure --enable-conio --host=i386-pc-msdosdjgpp | |||
History of textmode games | |||
@@ -14,6 +14,10 @@ AM_PROG_CC_C_O | |||
AC_PROG_CPP | |||
AC_PROG_RANLIB | |||
dnl AC_PROG_EGREP only exists in autoconf 2.54+, so we use AC_EGREP_CPP right | |||
dnl now otherwise it might be set in an obscure if statement. | |||
AC_EGREP_CPP(foo,foo) | |||
AC_ARG_ENABLE(slang, | |||
[ --enable-slang slang graphics support (default enabled)]) | |||
AC_ARG_ENABLE(ncurses, | |||
@@ -26,6 +30,12 @@ USE_NCURSES=false | |||
USE_CONIO=false | |||
if test "${enable_conio}" = "yes"; then | |||
AC_CHECK_HEADER(conio.h,:,AC_MSG_ERROR([cannot find conio.h header])) | |||
AC_MSG_CHECKING(for ScreenUpdate in pc.h) | |||
AC_EGREP_HEADER(ScreenUpdate,pc.h,[ | |||
AC_MSG_RESULT(yes) | |||
AC_DEFINE(SCREENUPDATE_IN_PC_H, 1, | |||
Define if <pc.h> defines ScreenUpdate.)],[ | |||
AC_MSG_RESULT(no)]) | |||
AC_DEFINE(USE_CONIO, 1, Define if the backend driver is conio.h) | |||
USE_CONIO=: | |||
elif test "${enable_ncurses}" = "yes"; then | |||
@@ -22,12 +22,16 @@ | |||
#include "config.h" | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
# include <slang.h> | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
# include <curses.h> | |||
#elif USE_CONIO | |||
#elif defined(USE_CONIO) | |||
# include <dos.h> | |||
# include <conio.h> | |||
# if defined(SCREENUPDATE_IN_PC_H) | |||
# include <pc.h> | |||
# endif | |||
#else | |||
# error "no graphics library detected" | |||
#endif | |||
@@ -41,13 +45,14 @@ | |||
#include "ee.h" | |||
static int _ee_delay; | |||
#ifdef USE_CONIO | |||
#if defined(USE_CONIO) | |||
static struct text_info ti; | |||
char *_screen_buffer; | |||
#endif | |||
int ee_init(void) | |||
{ | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
static char * colors[] = { "black", "green", "yellow", "white", | |||
"red", "gray", "lightgray", "blue", "cyan", "magenta", NULL }; | |||
int i; | |||
@@ -81,7 +86,7 @@ int ee_init(void) | |||
SLtt_set_color(i + 1, NULL, colors[i], "black"); | |||
} | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
/* Initialize ncurses library */ | |||
initscr(); | |||
keypad(stdscr, TRUE); | |||
@@ -104,12 +109,13 @@ int ee_init(void) | |||
init_pair(EE_CYAN, COLOR_CYAN, COLOR_BLACK); | |||
init_pair(EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); | |||
#elif USE_CONIO | |||
#elif defined(USE_CONIO) | |||
_wscroll = 0; | |||
_setcursortype(_NOCURSOR); | |||
clrscr(); | |||
gettextinfo(&ti); | |||
//window(2, 2, 20, 20); | |||
_screen_buffer = malloc(ee_get_width() * ee_get_height() * 2); | |||
ScreenRetrieve(_screen_buffer); | |||
#endif | |||
_ee_delay = 0; | |||
@@ -117,34 +123,34 @@ int ee_init(void) | |||
return 0; | |||
} | |||
void ee_set_delay(int delay) | |||
void ee_set_delay(int usec) | |||
{ | |||
_ee_delay = delay; | |||
_ee_delay = usec; | |||
} | |||
int ee_get_width(void) | |||
{ | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
return SLtt_Screen_Cols; | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
return COLS; | |||
#elif USE_CONIO | |||
#elif defined(USE_CONIO) | |||
return ti.screenwidth; | |||
#endif | |||
} | |||
int ee_get_height(void) | |||
{ | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
return SLtt_Screen_Rows; | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
return LINES; | |||
#else | |||
return ti.screenheight; | |||
#endif | |||
} | |||
#ifndef USE_CONIO | |||
#if !defined(USE_CONIO) | |||
static int64_t local_time(void) | |||
{ | |||
struct timeval tv; | |||
@@ -160,7 +166,7 @@ static int64_t local_time(void) | |||
void ee_refresh(void) | |||
{ | |||
#ifndef USE_CONIO | |||
#if !defined(USE_CONIO) | |||
static int64_t local_clock = 0; | |||
int64_t now; | |||
@@ -176,15 +182,15 @@ void ee_refresh(void) | |||
} | |||
#endif | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
SLsmg_refresh(); | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
refresh(); | |||
#elif USE_CONIO | |||
/* Do nothing? */ | |||
#elif defined(USE_CONIO) | |||
ScreenUpdate(_screen_buffer); | |||
#endif | |||
#ifndef USE_CONIO | |||
#if !defined(USE_CONIO) | |||
now = local_time(); | |||
if(now < local_clock + _ee_delay - 10000) | |||
@@ -193,22 +199,27 @@ void ee_refresh(void) | |||
} | |||
local_clock += _ee_delay; | |||
#else | |||
delay(5); | |||
#endif | |||
} | |||
void ee_end(void) | |||
{ | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
SLtt_set_cursor_visibility(1); | |||
SLang_reset_tty(); | |||
SLsmg_reset_smg(); | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
curs_set(1); | |||
endwin(); | |||
#elif USE_CONIO | |||
#elif defined(USE_CONIO) | |||
ScreenUpdate(_screen_buffer); | |||
_wscroll = 1; | |||
ee_set_color(EE_WHITE); | |||
ee_putstr(ee_get_width(), ee_get_height()-1, "\r\n"); | |||
textcolor((enum COLORS)WHITE); | |||
textbackground((enum COLORS)BLACK); | |||
gotoxy(ee_get_width(), ee_get_height()); | |||
cputs("\r\n"); | |||
_setcursortype(_NORMALCURSOR); | |||
#endif | |||
} | |||
@@ -22,11 +22,11 @@ | |||
#include "config.h" | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
# include <slang.h> | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
# include <curses.h> | |||
#elif USE_CONIO | |||
#elif defined(USE_CONIO) | |||
# include <conio.h> | |||
#else | |||
# error "no graphics library detected" | |||
@@ -38,7 +38,7 @@ | |||
#include "ee.h" | |||
static int ee_color = 0; | |||
#ifdef USE_CONIO | |||
#if defined(USE_CONIO) | |||
static enum COLORS dos_colors[] = { | |||
0, | |||
BLACK, | |||
@@ -57,11 +57,11 @@ static enum COLORS dos_colors[] = { | |||
void ee_set_color(int color) | |||
{ | |||
ee_color = color; | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
SLsmg_set_color(color); | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
attrset(COLOR_PAIR(color)); | |||
#elif USE_CONIO | |||
#elif defined(USE_CONIO) | |||
if(color >= 1 && color <= 10) | |||
textcolor(dos_colors[color]); | |||
#endif | |||
@@ -72,31 +72,45 @@ int ee_get_color(void) | |||
return ee_color; | |||
} | |||
extern char *_screen_buffer; | |||
void ee_putchar(int x, int y, char c) | |||
{ | |||
#ifdef USE_SLANG | |||
#if defined(USE_SLANG) | |||
SLsmg_gotorc(y,x); | |||
SLsmg_write_char(c); | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
move(y,x); | |||
addch(c); | |||
#elif USE_CONIO | |||
gotoxy(x+1,y+1); | |||
putch(c); | |||
#elif defined(USE_CONIO) | |||
if(x<0 || x>=ee_get_width() || y<0 || y>=ee_get_height()) | |||
return; | |||
_screen_buffer[2 * (x + y * ee_get_width())] = c; | |||
_screen_buffer[2 * (x + y * ee_get_width()) + 1] = dos_colors[ee_color]; | |||
// gotoxy(x+1,y+1); | |||
// putch(c); | |||
#endif | |||
} | |||
void ee_putstr(int x, int y, char *s) | |||
{ | |||
#ifdef USE_SLANG | |||
if(y<0 || y>=ee_get_height()) | |||
return; | |||
#if defined(USE_SLANG) | |||
SLsmg_gotorc(y,x); | |||
SLsmg_write_string(s); | |||
#elif USE_NCURSES | |||
#elif defined(USE_NCURSES) | |||
move(y,x); | |||
addstr(s); | |||
#elif USE_CONIO | |||
gotoxy(x+1,y+1); | |||
cputs(s); | |||
#elif defined(USE_CONIO) | |||
char *buf = _screen_buffer + 2 * (x + y * ee_get_width()); | |||
while(*s) | |||
{ | |||
*buf++ = *s++; | |||
*buf++ = dos_colors[ee_color]; | |||
} | |||
// gotoxy(x+1,y+1); | |||
// cputs(s); | |||
#endif | |||
} | |||