Commit 1f36554a authored by deuce's avatar deuce
Browse files

Add SDL ciolib add-on. Currently only build with *nix builds.

parent 3c87deb3
# Find SDL headers!
ifndef WITHOUT_SDL
ifndef SDL_CONFIG
ifeq ($(shell sdl12-config --cflags > /dev/null && echo YES),YES)
SDL_CONFIG := sdl12-config
WITH_SDL := 1
else
ifeq ($(shell sdl11-config --cflags > /dev/null && echo YES),YES)
SDL_CONFIG := sdl11-config
WITH_SDL := 1
else
ifeq ($(shell sdl-config --cflags > /dev/null && echo YES),YES)
SDL_CONFIG := sdl-config
WITH_SDL := 1
endif
endif
endif
ifdef WITH_SDL
ifdef SDL_CONFIG
ifeq ($(shell ${SDL_CONFIG} --cflags > /dev/null && echo YES),YES)
CIOLIB-MT_CFLAGS += -DWITH_SDL
CIOLIB-MT_CFLAGS += $(shell $(SDL_CONFIG) --cflags)
ifdef STATIC_SDL
CIOLIB-MT_LIBS += $(shell $(SDL_CONFIG) --static-libs)
else
CIOLIB-MT_LIBS += $(shell $(SDL_CONFIG) --libs)
endif
endif
endif
endif
endif
endif
ifeq ($(os),sunos)
X_PATH ?= /usr/X
else
......
......@@ -12,6 +12,11 @@ else
OBJS += $(MTOBJODIR)$(DIRSEP)console$(OFILE) \
$(MTOBJODIR)$(DIRSEP)x_cio$(OFILE)
endif
ifdef WITH_SDL
OBJS += $(MTOBJODIR)$(DIRSEP)sdl_con$(OFILE)
endif
ifeq ($(os),netbsd)
CFLAGS += -DN_CURSES_LIB
endif
......
......@@ -40,6 +40,9 @@
#define CIOLIB_NO_MACROS
#include "ciolib.h"
#ifdef WITH_SDL
#include "sdl_con.h"
#endif
#ifdef _WIN32
#include "win32cio.h"
#else
......@@ -99,6 +102,37 @@ char *ciolib_getcliptext(void);
#define CIOLIB_INIT() { if(!initialized) initciolib(CIOLIB_MODE_AUTO); }
#ifdef WITH_SDL
int try_sdl_init(int mode)
{
if(!sdl_init()) {
cio_api.mode=CIOLIB_MODE_SDL;
cio_api.mouse=1;
cio_api.puttext=sdl_puttext;
cio_api.gettext=sdl_gettext;
cio_api.textattr=sdl_textattr;
cio_api.kbhit=sdl_kbhit;
cio_api.delay=sdl_delay;
cio_api.wherey=sdl_wherey;
cio_api.wherex=sdl_wherex;
cio_api.putch=sdl_putch;
cio_api.gotoxy=sdl_gotoxy;
cio_api.gettextinfo=sdl_gettextinfo;
cio_api.setcursortype=sdl_setcursortype;
cio_api.getch=sdl_getch;
cio_api.getche=sdl_getche;
cio_api.textmode=sdl_textmode;
cio_api.showmouse=sdl_showmouse;
cio_api.hidemouse=sdl_hidemouse;
cio_api.settitle=sdl_settitle;
cio_api.copytext=NULL;
cio_api.getcliptext=NULL;
return(1);
}
return(0);
}
#endif
#ifndef _WIN32
#ifndef NO_X
int try_x_init(int mode)
......@@ -227,15 +261,19 @@ int initciolib(int mode)
{
switch(mode) {
case CIOLIB_MODE_AUTO:
#ifdef WITH_SDL
if(!try_sdl_init(mode))
#endif
#ifdef _WIN32
if(!try_conio_init(mode))
if(!try_conio_init(mode))
#else
#ifndef NO_X
if(!try_x_init(mode))
if(!try_x_init(mode))
#endif
if(!try_curses_init(mode))
if(!try_curses_init(mode))
#endif
try_ansi_init(mode);
try_ansi_init(mode);
break;
#ifdef _WIN32
case CIOLIB_MODE_CONIO:
......
......@@ -44,6 +44,7 @@ enum {
,CIOLIB_MODE_ANSI
,CIOLIB_MODE_X
,CIOLIB_MODE_CONIO
,CIOLIB_MODE_SDL
};
#if defined(_WIN32) /* presumably, Win32 */
......
......@@ -117,7 +117,6 @@
#include "keys.h"
#include "mouse.h"
#include "vgafont.h"
#define CONSOLE_MAX_ROWS 61
#define CONSOLE_MAX_COLS 81
......
OBJS = $(MTOBJODIR)$(DIRSEP)ansi_cio$(OFILE)\
$(MTOBJODIR)$(DIRSEP)ciolib$(OFILE)\
$(MTOBJODIR)$(DIRSEP)cterm$(OFILE)\
$(MTOBJODIR)$(DIRSEP)vidmodes$(OFILE)\
$(MTOBJODIR)$(DIRSEP)mouse$(OFILE)
This diff is collapsed.
#ifndef _SDL_CON_H_
#define _SDL_CON_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Low-Level stuff (Shouldn't be used by ciolib programs */
int sdl_init(void);
int sdl_load_font(char *filename, int width, int height, double scale);
int sdl_init_mode(int mode);
int sdl_setup_colours(void);
int sdl_draw_char(unsigned short vch, int xpos, int ypos);
int sdl_screen_redraw(void);
/* High-level stuff */
int sdl_puttext(int sx, int sy, int ex, int ey, void *fill);
int sdl_gettext(int sx, int sy, int ex, int ey, void *fill);
void sdl_textattr(int attr);
int sdl_kbhit(void);
void sdl_delay(long msec);
int sdl_wherey(void);
int sdl_wherex(void);
int sdl_putch(int ch);
void sdl_gotoxy(int x, int y);
void sdl_initciolib(long inmode);
void sdl_gettextinfo(struct text_info *info);
void sdl_setcursortype(int type);
int sdl_getch(void);
int sdl_getche(void);
int sdl_beep(void);
void sdl_textmode(int mode);
void sdl_settitle(const char *title);
int sdl_hidemouse(void);
int sdl_showmouse(void);
#if 0
void sdl_copytext(const char *text, size_t buflen);
char *sdl_getcliptext(void);
#endif
#ifdef __cplusplus
}
#endif
#endif
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU Lesser General Public License for more details: lgpl.txt or *
* http://www.fsf.org/copyleft/lesser.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include "vidmodes.h"
#define B_00000000_B 0x00
#define B_10000000_B 0x01
......@@ -10792,3 +10761,151 @@ char vga_font_bitmap8[2048]={
,B_00000000_B
};
struct video_params vparams[36] = {
/* BW 40x25 */
{BW40, GREYSCALE_PALETTE, 40, 25, 14, 15, 16, 8},
/* CO 40x25 */
{C40, COLOUR_PALETTE, 40, 25, 14, 15, 16, 8},
/* BW 80x25 */
{BW80, GREYSCALE_PALETTE, 80, 25, 14, 15, 16, 8},
/* CO 80x25 */
{C80, COLOUR_PALETTE, 80, 25, 14, 15, 16, 8},
/* MONO */
{MONO, 0, 80, 25, 14, 15, 16, 8},
/* CO 40x14 */
{C40X14, COLOUR_PALETTE, 40, 14, 14, 15, 16, 8},
/* CO 40x21 */
{C40X21, COLOUR_PALETTE, 40, 21, 14, 15, 16, 8},
/* CO 40x28 */
{C40X28, COLOUR_PALETTE, 40, 28, 12, 13, 14, 8},
/* CO 40x43 */
{C40X43, COLOUR_PALETTE, 40, 43, 7, 7, 8, 8},
/* CO 40x50 */
{C40X50, COLOUR_PALETTE, 40, 50, 7, 7, 8, 8},
/* CO 40x60 */
{C40X60, COLOUR_PALETTE, 40, 60, 7, 7, 8, 8},
/* CO 80x14 */
{C80X14, COLOUR_PALETTE, 80, 14, 14, 15, 16, 8},
/* CO 80x21 */
{C80X21, COLOUR_PALETTE, 80, 21, 14, 15, 16, 8},
/* CO 80x28 */
{C80X28, COLOUR_PALETTE, 80, 28, 12, 13, 14, 8},
/* CO 80x43 */
{C80X43, COLOUR_PALETTE, 80, 43, 7, 7, 8, 8},
/* CO 80x50 */
{C80X50, COLOUR_PALETTE, 80, 50, 7, 7, 8, 8},
/* CO 80x60 */
{C80X60, COLOUR_PALETTE, 80, 60, 7, 7, 8, 8},
/* B 40x14 */
{BW40X14, GREYSCALE_PALETTE, 40, 14, 14, 15, 16, 8},
/* BW 40x21 */
{BW40X21, GREYSCALE_PALETTE, 40, 21, 14, 15, 16, 8},
/* BW 40x28 */
{BW40X28, GREYSCALE_PALETTE, 40, 28, 12, 13, 14, 8},
/* BW 40x43 */
{BW40X43, GREYSCALE_PALETTE, 40, 43, 7, 7, 8, 8},
/* BW 40x50 */
{BW40X50, GREYSCALE_PALETTE, 40, 50, 7, 7, 8, 8},
/* BW 40x60 */
{BW40X60, GREYSCALE_PALETTE, 40, 60, 7, 7, 8, 8},
/* BW 80x14 */
{BW80X14, GREYSCALE_PALETTE, 80, 14, 14, 15, 16, 8},
/* BW 80x21 */
{BW80X21, GREYSCALE_PALETTE, 80, 21, 14, 15, 16, 8},
/* BW 80x28 */
{BW80X28, GREYSCALE_PALETTE, 80, 28, 12, 13, 14, 8},
/* BW 80x43 */
{BW80X43, GREYSCALE_PALETTE, 80, 43, 7, 7, 8, 8},
/* BW 80x50 */
{BW80X50, GREYSCALE_PALETTE, 80, 50, 7, 7, 8, 8},
/* BW 80x60 */
{BW80X60, GREYSCALE_PALETTE, 80, 60, 7, 7, 8, 8},
/* MONO 80x14 */
{MONO14, MONO_PALETTE, 80, 14, 14, 15, 16, 8},
/* MONO 80x21 */
{MONO21, MONO_PALETTE, 80, 21, 14, 15, 16, 8},
/* MONO 80x28 */
{MONO28, MONO_PALETTE, 80, 28, 12, 13, 14, 8},
/* MONO 80x43 */
{MONO43, MONO_PALETTE, 80, 43, 7, 7, 8, 8},
/* MONO 80x50 */
{MONO50, MONO_PALETTE, 80, 50, 7, 7, 8, 8},
/* MONO 80x60 */
{MONO60, MONO_PALETTE, 80, 60, 7, 7, 8, 8},
/* Magical C4350 Mode */
{C4350, COLOUR_PALETTE, 80, 50, 7, 7, 8, 8},
};
unsigned char palettes[3][16] = {
/* Mono */
{ 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
},
/* Black and White */
{ 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f
},
/* Colour */
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
}
};
struct dac_colors dac_default16[16] = {
{0, 0, 0}, {0, 0, 42}, {0, 42, 0}, {0, 42, 42},
{42, 0, 0}, {42, 0, 42}, {42, 21, 0}, {42, 42, 42},
{21, 21, 21}, {21, 21, 63}, {21, 63, 21}, {21, 63, 63},
{63, 21, 21}, {63, 21, 63}, {63, 63, 21}, {63, 63, 63}
};
struct dac_colors dac_default256[16] = {
{0, 0, 0}, {0, 0, 168}, {0, 168, 0}, {0, 168, 168},
{168, 0, 0}, {168, 0, 168}, {168, 84, 0}, {168, 168, 168},
{84, 84, 84}, {84, 84, 255}, {84, 255, 84}, {84, 255, 255},
{255, 84, 84}, {255, 84, 255}, {255, 255, 84}, {255, 255, 255}
};
int find_vmode(int mode)
{
unsigned i;
for (i = 0; i < NUMMODES; i++)
if (vparams[i].mode == mode)
return i;
return -1;
}
int load_vmode(struct video_stats *vs, int mode)
{
int i;
unsigned short *newvmem;
i=find_vmode(mode);
if(i==-1)
return(-1);
newvmem=(unsigned short *)realloc(vs->vmem, vparams[i].cols*vparams[i].rows*sizeof(unsigned short));
if(newvmem==NULL)
return(-1);
vs->vmem=newvmem;
vs->rows=vparams[i].rows;
vs->cols=vparams[i].cols;
vs->curs_start=vparams[i].curs_start;
vs->curs_end=vparams[i].curs_end;
vs->default_curs_start=vparams[i].curs_start;
vs->default_curs_end=vparams[i].curs_end;
if(vs->curs_row < 0)
vs->curs_row=0;
if(vs->curs_row >= vparams[i].rows)
vs->curs_row=vparams[i].rows-1;
if(vs->curs_col < 0)
vs->curs_col=0;
if(vs->curs_col >= vparams[i].cols)
vs->curs_col=vparams[i].cols-1;
vs->palette=palettes[vparams[i].palette];
vs->charheight=vparams[i].charheight;
vs->charwidth=vparams[i].charwidth;
vs->mode=mode;
return(0);
}
......@@ -47,127 +47,54 @@ struct video_params {
int charwidth;
};
enum {
MONO_PALETTE
,GREYSCALE_PALETTE
,COLOUR_PALETTE
};
static struct video_params vparams[] = {
/* BW 40x25 */
{BW40, GREYSCALE_PALETTE, 40, 25, 14, 15, 16, 8},
/* CO 40x25 */
{C40, COLOUR_PALETTE, 40, 25, 14, 15, 16, 8},
/* BW 80x25 */
{BW80, GREYSCALE_PALETTE, 80, 25, 14, 15, 16, 8},
/* CO 80x25 */
{C80, COLOUR_PALETTE, 80, 25, 14, 15, 16, 8},
/* MONO */
{MONO, 0, 80, 25, 14, 15, 16, 8},
/* CO 40x14 */
{C40X14, COLOUR_PALETTE, 40, 14, 14, 15, 16, 8},
/* CO 40x21 */
{C40X21, COLOUR_PALETTE, 40, 21, 14, 15, 16, 8},
/* CO 40x28 */
{C40X28, COLOUR_PALETTE, 40, 28, 12, 13, 14, 8},
/* CO 40x43 */
{C40X43, COLOUR_PALETTE, 40, 43, 7, 7, 8, 8},
/* CO 40x50 */
{C40X50, COLOUR_PALETTE, 40, 50, 7, 7, 8, 8},
/* CO 40x60 */
{C40X60, COLOUR_PALETTE, 40, 60, 7, 7, 8, 8},
/* CO 80x14 */
{C80X14, COLOUR_PALETTE, 80, 14, 14, 15, 16, 8},
/* CO 80x21 */
{C80X21, COLOUR_PALETTE, 80, 21, 14, 15, 16, 8},
/* CO 80x28 */
{C80X28, COLOUR_PALETTE, 80, 28, 12, 13, 14, 8},
/* CO 80x43 */
{C80X43, COLOUR_PALETTE, 80, 43, 7, 7, 8, 8},
/* CO 80x50 */
{C80X50, COLOUR_PALETTE, 80, 50, 7, 7, 8, 8},
/* CO 80x60 */
{C80X60, COLOUR_PALETTE, 80, 60, 7, 7, 8, 8},
/* B 40x14 */
{BW40X14, GREYSCALE_PALETTE, 40, 14, 14, 15, 16, 8},
/* BW 40x21 */
{BW40X21, GREYSCALE_PALETTE, 40, 21, 14, 15, 16, 8},
/* BW 40x28 */
{BW40X28, GREYSCALE_PALETTE, 40, 28, 12, 13, 14, 8},
/* BW 40x43 */
{BW40X43, GREYSCALE_PALETTE, 40, 43, 7, 7, 8, 8},
/* BW 40x50 */
{BW40X50, GREYSCALE_PALETTE, 40, 50, 7, 7, 8, 8},
/* BW 40x60 */
{BW40X60, GREYSCALE_PALETTE, 40, 60, 7, 7, 8, 8},
/* BW 80x14 */
{BW80X14, GREYSCALE_PALETTE, 80, 14, 14, 15, 16, 8},
/* BW 80x21 */
{BW80X21, GREYSCALE_PALETTE, 80, 21, 14, 15, 16, 8},
/* BW 80x28 */
{BW80X28, GREYSCALE_PALETTE, 80, 28, 12, 13, 14, 8},
/* BW 80x43 */
{BW80X43, GREYSCALE_PALETTE, 80, 43, 7, 7, 8, 8},
/* BW 80x50 */
{BW80X50, GREYSCALE_PALETTE, 80, 50, 7, 7, 8, 8},
/* BW 80x60 */
{BW80X60, GREYSCALE_PALETTE, 80, 60, 7, 7, 8, 8},
/* MONO 80x14 */
{MONO14, MONO_PALETTE, 80, 14, 14, 15, 16, 8},
/* MONO 80x21 */
{MONO21, MONO_PALETTE, 80, 21, 14, 15, 16, 8},
/* MONO 80x28 */
{MONO28, MONO_PALETTE, 80, 28, 12, 13, 14, 8},
/* MONO 80x43 */
{MONO43, MONO_PALETTE, 80, 43, 7, 7, 8, 8},
/* MONO 80x50 */
{MONO50, MONO_PALETTE, 80, 50, 7, 7, 8, 8},
/* MONO 80x60 */
{MONO60, MONO_PALETTE, 80, 60, 7, 7, 8, 8},
/* Magical C4350 Mode */
{C4350, COLOUR_PALETTE, 80, 50, 7, 7, 8, 8},
};
#define NUMMODES (sizeof(vparams) / sizeof(struct video_params))
static unsigned char palettes[][16] = {
/* Mono */
{ 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
},
/* Black and White */
{ 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f
},
/* Colour */
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
}
struct video_stats {
int rows;
int cols;
int curs_row;
int curs_col;
int curs_start;
int curs_end;
int default_curs_start;
int default_curs_end;
int mode;
int charheight;
int charwidth;
int blink;
int currattr;
int scaling;
unsigned char *palette;
unsigned short *vmem;
};
/* Entry type for the DAC table. Each value is actually 6 bits wide. */
/* Entry type for the DAC table. */
struct dac_colors {
BYTE red;
BYTE green;
BYTE blue;
unsigned char red;
unsigned char green;
unsigned char blue;
};
static struct dac_colors dac_default16[] = {
{0, 0, 0}, {0, 0, 42}, {0, 42, 0}, {0, 42, 42},
{42, 0, 0}, {42, 0, 42}, {42, 21, 0}, {42, 42, 42},
{21, 21, 21}, {21, 21, 63}, {21, 63, 21}, {21, 63, 63},
{63, 21, 21}, {63, 21, 63}, {63, 63, 21}, {63, 63, 63}
enum {
MONO_PALETTE
,GREYSCALE_PALETTE
,COLOUR_PALETTE
};
static int find_vmode(int mode)
{
unsigned i;
for (i = 0; i < NUMMODES; i++)
if (vparams[i].mode == mode)
return i;
extern struct video_params vparams[36];
#define NUMMODES (sizeof(vparams) / sizeof(struct video_params))
extern unsigned char palettes[3][16];
extern struct dac_colors dac_default16[16];
extern struct dac_colors dac_default256[16];
extern char vga_font_bitmap[4096];
extern char vga_font_bitmap14[3584];
extern char vga_font_bitmap8[2048];
return -1;
#ifdef __cplusplus
extern "C" {
#endif
int find_vmode(int mode);
int load_vmode(struct video_stats *vs, int mode);
#ifdef __cplusplus
}
#endif
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment