+ 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(). git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@158 92316355-f0b4-4df1-b90c-862c8a59935fmaster
@@ -6,6 +6,10 @@ Building ttyvaders | |||||
--enable-slang: use the SLang library (default) | --enable-slang: use the SLang library (default) | ||||
--enable-ncurses: use the ncurses library | --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 | History of textmode games | ||||
@@ -14,6 +14,10 @@ AM_PROG_CC_C_O | |||||
AC_PROG_CPP | AC_PROG_CPP | ||||
AC_PROG_RANLIB | 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, | AC_ARG_ENABLE(slang, | ||||
[ --enable-slang slang graphics support (default enabled)]) | [ --enable-slang slang graphics support (default enabled)]) | ||||
AC_ARG_ENABLE(ncurses, | AC_ARG_ENABLE(ncurses, | ||||
@@ -26,6 +30,12 @@ USE_NCURSES=false | |||||
USE_CONIO=false | USE_CONIO=false | ||||
if test "${enable_conio}" = "yes"; then | if test "${enable_conio}" = "yes"; then | ||||
AC_CHECK_HEADER(conio.h,:,AC_MSG_ERROR([cannot find conio.h header])) | 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) | AC_DEFINE(USE_CONIO, 1, Define if the backend driver is conio.h) | ||||
USE_CONIO=: | USE_CONIO=: | ||||
elif test "${enable_ncurses}" = "yes"; then | elif test "${enable_ncurses}" = "yes"; then | ||||
@@ -22,12 +22,16 @@ | |||||
#include "config.h" | #include "config.h" | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
# include <slang.h> | # include <slang.h> | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
# include <curses.h> | # include <curses.h> | ||||
#elif USE_CONIO | |||||
#elif defined(USE_CONIO) | |||||
# include <dos.h> | |||||
# include <conio.h> | # include <conio.h> | ||||
# if defined(SCREENUPDATE_IN_PC_H) | |||||
# include <pc.h> | |||||
# endif | |||||
#else | #else | ||||
# error "no graphics library detected" | # error "no graphics library detected" | ||||
#endif | #endif | ||||
@@ -41,13 +45,14 @@ | |||||
#include "ee.h" | #include "ee.h" | ||||
static int _ee_delay; | static int _ee_delay; | ||||
#ifdef USE_CONIO | |||||
#if defined(USE_CONIO) | |||||
static struct text_info ti; | static struct text_info ti; | ||||
char *_screen_buffer; | |||||
#endif | #endif | ||||
int ee_init(void) | int ee_init(void) | ||||
{ | { | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
static char * colors[] = { "black", "green", "yellow", "white", | static char * colors[] = { "black", "green", "yellow", "white", | ||||
"red", "gray", "lightgray", "blue", "cyan", "magenta", NULL }; | "red", "gray", "lightgray", "blue", "cyan", "magenta", NULL }; | ||||
int i; | int i; | ||||
@@ -81,7 +86,7 @@ int ee_init(void) | |||||
SLtt_set_color(i + 1, NULL, colors[i], "black"); | SLtt_set_color(i + 1, NULL, colors[i], "black"); | ||||
} | } | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
/* Initialize ncurses library */ | /* Initialize ncurses library */ | ||||
initscr(); | initscr(); | ||||
keypad(stdscr, TRUE); | keypad(stdscr, TRUE); | ||||
@@ -104,12 +109,13 @@ int ee_init(void) | |||||
init_pair(EE_CYAN, COLOR_CYAN, COLOR_BLACK); | init_pair(EE_CYAN, COLOR_CYAN, COLOR_BLACK); | ||||
init_pair(EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); | init_pair(EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); | ||||
#elif USE_CONIO | |||||
#elif defined(USE_CONIO) | |||||
_wscroll = 0; | _wscroll = 0; | ||||
_setcursortype(_NOCURSOR); | _setcursortype(_NOCURSOR); | ||||
clrscr(); | clrscr(); | ||||
gettextinfo(&ti); | gettextinfo(&ti); | ||||
//window(2, 2, 20, 20); | |||||
_screen_buffer = malloc(ee_get_width() * ee_get_height() * 2); | |||||
ScreenRetrieve(_screen_buffer); | |||||
#endif | #endif | ||||
_ee_delay = 0; | _ee_delay = 0; | ||||
@@ -117,34 +123,34 @@ int ee_init(void) | |||||
return 0; | 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) | int ee_get_width(void) | ||||
{ | { | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
return SLtt_Screen_Cols; | return SLtt_Screen_Cols; | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
return COLS; | return COLS; | ||||
#elif USE_CONIO | |||||
#elif defined(USE_CONIO) | |||||
return ti.screenwidth; | return ti.screenwidth; | ||||
#endif | #endif | ||||
} | } | ||||
int ee_get_height(void) | int ee_get_height(void) | ||||
{ | { | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
return SLtt_Screen_Rows; | return SLtt_Screen_Rows; | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
return LINES; | return LINES; | ||||
#else | #else | ||||
return ti.screenheight; | return ti.screenheight; | ||||
#endif | #endif | ||||
} | } | ||||
#ifndef USE_CONIO | |||||
#if !defined(USE_CONIO) | |||||
static int64_t local_time(void) | static int64_t local_time(void) | ||||
{ | { | ||||
struct timeval tv; | struct timeval tv; | ||||
@@ -160,7 +166,7 @@ static int64_t local_time(void) | |||||
void ee_refresh(void) | void ee_refresh(void) | ||||
{ | { | ||||
#ifndef USE_CONIO | |||||
#if !defined(USE_CONIO) | |||||
static int64_t local_clock = 0; | static int64_t local_clock = 0; | ||||
int64_t now; | int64_t now; | ||||
@@ -176,15 +182,15 @@ void ee_refresh(void) | |||||
} | } | ||||
#endif | #endif | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
SLsmg_refresh(); | SLsmg_refresh(); | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
refresh(); | refresh(); | ||||
#elif USE_CONIO | |||||
/* Do nothing? */ | |||||
#elif defined(USE_CONIO) | |||||
ScreenUpdate(_screen_buffer); | |||||
#endif | #endif | ||||
#ifndef USE_CONIO | |||||
#if !defined(USE_CONIO) | |||||
now = local_time(); | now = local_time(); | ||||
if(now < local_clock + _ee_delay - 10000) | if(now < local_clock + _ee_delay - 10000) | ||||
@@ -193,22 +199,27 @@ void ee_refresh(void) | |||||
} | } | ||||
local_clock += _ee_delay; | local_clock += _ee_delay; | ||||
#else | |||||
delay(5); | |||||
#endif | #endif | ||||
} | } | ||||
void ee_end(void) | void ee_end(void) | ||||
{ | { | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
SLtt_set_cursor_visibility(1); | SLtt_set_cursor_visibility(1); | ||||
SLang_reset_tty(); | SLang_reset_tty(); | ||||
SLsmg_reset_smg(); | SLsmg_reset_smg(); | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
curs_set(1); | curs_set(1); | ||||
endwin(); | endwin(); | ||||
#elif USE_CONIO | |||||
#elif defined(USE_CONIO) | |||||
ScreenUpdate(_screen_buffer); | |||||
_wscroll = 1; | _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); | _setcursortype(_NORMALCURSOR); | ||||
#endif | #endif | ||||
} | } | ||||
@@ -22,11 +22,11 @@ | |||||
#include "config.h" | #include "config.h" | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
# include <slang.h> | # include <slang.h> | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
# include <curses.h> | # include <curses.h> | ||||
#elif USE_CONIO | |||||
#elif defined(USE_CONIO) | |||||
# include <conio.h> | # include <conio.h> | ||||
#else | #else | ||||
# error "no graphics library detected" | # error "no graphics library detected" | ||||
@@ -38,7 +38,7 @@ | |||||
#include "ee.h" | #include "ee.h" | ||||
static int ee_color = 0; | static int ee_color = 0; | ||||
#ifdef USE_CONIO | |||||
#if defined(USE_CONIO) | |||||
static enum COLORS dos_colors[] = { | static enum COLORS dos_colors[] = { | ||||
0, | 0, | ||||
BLACK, | BLACK, | ||||
@@ -57,11 +57,11 @@ static enum COLORS dos_colors[] = { | |||||
void ee_set_color(int color) | void ee_set_color(int color) | ||||
{ | { | ||||
ee_color = color; | ee_color = color; | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
SLsmg_set_color(color); | SLsmg_set_color(color); | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
attrset(COLOR_PAIR(color)); | attrset(COLOR_PAIR(color)); | ||||
#elif USE_CONIO | |||||
#elif defined(USE_CONIO) | |||||
if(color >= 1 && color <= 10) | if(color >= 1 && color <= 10) | ||||
textcolor(dos_colors[color]); | textcolor(dos_colors[color]); | ||||
#endif | #endif | ||||
@@ -72,31 +72,45 @@ int ee_get_color(void) | |||||
return ee_color; | return ee_color; | ||||
} | } | ||||
extern char *_screen_buffer; | |||||
void ee_putchar(int x, int y, char c) | void ee_putchar(int x, int y, char c) | ||||
{ | { | ||||
#ifdef USE_SLANG | |||||
#if defined(USE_SLANG) | |||||
SLsmg_gotorc(y,x); | SLsmg_gotorc(y,x); | ||||
SLsmg_write_char(c); | SLsmg_write_char(c); | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
move(y,x); | move(y,x); | ||||
addch(c); | 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 | #endif | ||||
} | } | ||||
void ee_putstr(int x, int y, char *s) | 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_gotorc(y,x); | ||||
SLsmg_write_string(s); | SLsmg_write_string(s); | ||||
#elif USE_NCURSES | |||||
#elif defined(USE_NCURSES) | |||||
move(y,x); | move(y,x); | ||||
addstr(s); | 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 | #endif | ||||
} | } | ||||