Skip to content
Snippets Groups Projects
Commit f74e425f authored by deuce's avatar deuce
Browse files

Use Win32 API console functions instead of Borland-specific conio ones.

Known issues:
- textmode() is just a stub... this REALLY should do something usefull
- gettextinfo() *always* retruns C80 as the current mode
- Still dog slow (Why?)
- Probobly broken on NT-based systems to to large default buffer
parent c9ebbe5a
No related branches found
No related tags found
No related merge requests found
......@@ -161,19 +161,19 @@ int try_conio_init(int mode)
if(win32_initciolib(mode)) {
cio_api.mode=CIOLIB_MODE_CONIO;
cio_api.mouse=1;
cio_api.puttext=puttext;
cio_api.gettext=gettext;
cio_api.textattr=textattr;
cio_api.puttext=win32_puttext;
cio_api.gettext=win32_gettext;
cio_api.textattr=win32_textattr;
cio_api.kbhit=win32_kbhit;
cio_api.wherey=wherey;
cio_api.wherex=wherex;
cio_api.putch=putch;
cio_api.gotoxy=gotoxy;
cio_api.gettextinfo=gettextinfo;
cio_api.setcursortype=_setcursortype;
cio_api.wherey=win32_wherey;
cio_api.wherex=win32_wherex;
cio_api.putch=win32_putch;
cio_api.gotoxy=win32_gotoxy;
cio_api.gettextinfo=win32_gettextinfo;
cio_api.setcursortype=win32_setcursortype;
cio_api.getch=win32_getch;
cio_api.getche=win32_getche;
cio_api.textmode=textmode;
cio_api.textmode=win32_textmode;
cio_api.getmouse=win32_getmouse;
cio_api.showmouse=win32_showmouse;
cio_api.hidemouse=win32_hidemouse;
......@@ -729,7 +729,7 @@ void ciolib_delay(long a)
int ciolib_putch(unsigned char a)
{
CIOLIB_INIT();
return(cio_api.putch(a));
}
......
#include <windows.h> /* INPUT_RECORD, etc. */
#include <stdio.h> /* stdin */
#include "conio.h"
#define CIOLIB_NO_MACROS
#include "ciolib.h"
#include "keys.h"
#include "win32cio.h"
const int cio_tabs[10]={9,17,25,33,41,49,57,65,73,80};
static struct cio_mouse_event cio_last_button_press;
static struct cio_mouse_event last_mouse_click;
......@@ -11,6 +12,54 @@ static struct cio_mouse_event last_mouse_click;
static int lastch=0;
static int domouse=0;
static int currattr=7;
WORD DOStoWinAttr(int newattr)
{
WORD ret=0;
if(newattr&0x01)
ret|=FOREGROUND_BLUE;
if(newattr&0x02)
ret|=FOREGROUND_GREEN;
if(newattr&0x04)
ret|=FOREGROUND_RED;
if(newattr&0x08)
ret|=FOREGROUND_INTENSITY;
if(newattr&0x10)
ret|=BACKGROUND_BLUE;
if(newattr&0x20)
ret|=BACKGROUND_GREEN;
if(newattr&0x40)
ret|=BACKGROUND_RED;
if(newattr&0x80)
ret|=BACKGROUND_INTENSITY;
return(ret);
}
unsigned char WintoDOSAttr(WORD newattr)
{
unsigned char ret=0;
if(newattr&FOREGROUND_BLUE)
ret|=0x01;
if(newattr&FOREGROUND_GREEN)
ret|=0x02;
if(newattr&FOREGROUND_RED)
ret|=0x04;
if(newattr&FOREGROUND_INTENSITY)
ret|=0x08;
if(newattr&BACKGROUND_BLUE)
ret|=0x10;
if(newattr&BACKGROUND_GREEN)
ret|=0x20;
if(newattr&BACKGROUND_RED)
ret|=0x40;
if(newattr&BACKGROUND_INTENSITY)
ret|=0x80;
return(ret);
}
int win32_kbhit(void)
{
INPUT_RECORD input;
......@@ -141,7 +190,7 @@ int win32_initciolib(long inmode)
if(!isatty(fileno(stdin)))
return(0);
textmode(inmode);
win32_textmode(inmode);
if(!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &conmode))
return(0);
conmode&=~ENABLE_PROCESSED_INPUT;
......@@ -172,102 +221,198 @@ int win32_showmouse(void)
return(0);
}
#if !defined(__BORLANDC__)
void textmode(int mode)
{
}
void clreol(void)
void win32_textmode(int mode)
{
}
void clrscr(void)
int win32_gettext(int left, int top, int right, int bottom, void* buf)
{
CHAR_INFO *ci;
int x;
int y;
COORD bs;
COORD bc;
SMALL_RECT reg;
unsigned char *bu;
bu=buf;
bs.X=right-left+1;
bs.Y=bottom-top+1;
bc.X=0;
bc.Y=0;
reg.Left=left-1;
reg.Right=right-1;
reg.Top=top-1;
reg.Bottom=bottom-1;
ci=(CHAR_INFO *)malloc(sizeof(CHAR_INFO)*(bs.X*bs.Y));
ReadConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE),ci,bs,bc,&reg);
for(y=0;y<=(bottom-top);y++) {
for(x=0;x<=(right-left);x++) {
bu[((y*bs.X)+x)*2]=ci[(y*bs.X)+x].Char.AsciiChar;
bu[(((y*bs.X)+x)*2)+1]=WintoDOSAttr(ci[(y*bs.X)+x].Attributes);
}
}
free(ci);
return 1;
}
void delline(void)
void win32_gettextinfo(struct text_info* info)
{
}
CONSOLE_SCREEN_BUFFER_INFO bi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&bi);
int gettext(int left, int top, int right, int bottom, void* buf)
{
return 1;
/* ToDo Fix this! */
info->currmode=C80;
info->curx=bi.dwCursorPosition.X+1;
info->cury=bi.dwCursorPosition.Y+1;
info->attribute=currattr;
info->screenheight=bi.dwSize.Y;
info->screenwidth=bi.dwSize.X;
}
void gettextinfo(struct text_info* info)
void win32_gotoxy(int x, int y)
{
}
COORD cp;
void gotoxy(int x, int y)
{
cp.X=x-1;
cp.Y=y-1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),cp);
}
void highvideo(void)
void win32_highvideo(void)
{
win32_textattr(currattr|0x08);
}
void insline(void)
void win32_lowvideo(void)
{
win32_textattr(currattr&0xf8);
}
void lowvideo(void)
void win32_normvideo(void)
{
win32_textattr(7);
}
int movetext(int left, int top, int right, int bottom, int destleft, int desttop)
int win32_puttext(int left, int top, int right, int bottom, void* buf)
{
CHAR_INFO *ci;
int x;
int y;
COORD bs;
COORD bc;
SMALL_RECT reg;
unsigned char *bu;
bu=buf;
bs.X=right-left+1;
bs.Y=bottom-top+1;
bc.X=0;
bc.Y=0;
reg.Left=left-1;
reg.Right=right-1;
reg.Top=top-1;
reg.Bottom=bottom-1;
ci=(CHAR_INFO *)malloc(sizeof(CHAR_INFO)*(bs.X*bs.Y));
for(y=0;y<bs.Y;y++) {
for(x=0;x<bs.X;x++) {
ci[(y*bs.X)+x].Char.AsciiChar=bu[((y*bs.X)+x)*2];
ci[(y*bs.X)+x].Attributes=DOStoWinAttr(bu[(((y*bs.X)+x)*2)+1]);
}
}
WriteConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE),ci,bs,bc,&reg);
free(ci);
return 1;
}
void normvideo(void)
void win32_textattr(int newattr)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),DOStoWinAttr(newattr));
currattr=newattr;
}
int puttext(int left, int top, int right, int bottom, void* buf)
void win32_textbackground(int newcolor)
{
return 1;
win32_textattr((currattr&0x0f)|((newcolor&0xf0)<<4));
}
void textattr(int newattr)
void win32_textcolor(int newcolor)
{
win32_textattr((currattr&0xf0)|((newcolor&0x0f)<<4));
}
void textbackground(int newcolor)
void win32_setcursortype(int type)
{
}
CONSOLE_CURSOR_INFO ci;
void textcolor(int newcolor)
{
switch(type) {
case _NOCURSOR:
ci.bVisible=FALSE;
break;
case _SOLIDCURSOR:
ci.bVisible=TRUE;
ci.dwSize=100;
break;
default: /* Normal cursor */
ci.bVisible=TRUE;
ci.dwSize=13;
break;
}
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&ci);
}
void window(int left, int top, int right, int bottom)
int win32_wherex(void)
{
}
CONSOLE_SCREEN_BUFFER_INFO bi;
void _setcursortype(int type)
{
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&bi);
return bi.dwCursorPosition.X+1;
}
int wherex(void)
int win32_wherey(void)
{
return 0;
CONSOLE_SCREEN_BUFFER_INFO bi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&bi);
return bi.dwCursorPosition.Y+1;
}
int wherey(void)
int win32_putch(int ch)
{
return 0;
struct text_info ti;
WORD sch;
int i;
unsigned char buf[2];
DWORD wr;
buf[0]=ch;
buf[1]=currattr;
win32_gettextinfo(&ti);
switch(ch) {
case '\r':
gotoxy(1,ti.cury);
return('\r');
case '\n':
if(ti.cury==ti.screenheight) {
if(_wscroll)
wscroll();
gotoxy(ti.curx,ti.cury);
return('\n');
}
gotoxy(ti.curx,ti.cury+1);
return('\n');
default:
if(ti.curx==ti.screenwidth && ti.cury==ti.screenheight && !_wscroll)
return(0);
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),buf,1,&wr,NULL);
return(ch);
}
}
#endif
......@@ -11,40 +11,24 @@ int win32_getmouse(struct cio_mouse_event *mevent);
int win32_hidemouse(void);
int win32_showmouse(void);
#if !defined(__BORLANDC__)
void clreol(void);
void clrscr(void);
void delline(void);
int gettext(int left, int top, int right, int bottom, void*);
void gettextinfo(struct text_info*);
void gotoxy(int x, int y);
void highvideo(void);
void insline(void);
void lowvideo(void);
int movetext(int left, int top, int right, int bottom, int destleft, int desttop);
void normvideo(void);
int puttext(int left, int top, int right, int bottom, void*);
void textattr(int newattr);
void textbackground(int newcolor);
void textcolor(int newcolor);
void textmode(int newmode);
void window(int left, int top, int right, int bottom);
void _setcursortype(int);
char* cgets(char*);
int cprintf(const char*, ...);
int cputs(const char*);
int cscanf(const char*, ... );
int getch(void);
int getche(void);
char* getpass(const char*);
int kbhit(void);
int putch(int);
int ungetch(int);
int wherex(void);
int wherey(void);
#endif
int win32_gettext(int left, int top, int right, int bottom, void*);
void win32_gettextinfo(struct text_info*);
void win32_gotoxy(int x, int y);
void win32_highvideo(void);
void win32_lowvideo(void);
void win32_normvideo(void);
int win32_puttext(int left, int top, int right, int bottom, void*);
void win32_textattr(int newattr);
void win32_textbackground(int newcolor);
void win32_textcolor(int newcolor);
void win32_textmode(int newmode);
void win32_setcursortype(int);
int win32_getch(void);
int win32_getche(void);
int win32_kbhit(void);
int win32_putch(int);
int win32_wherex(void);
int win32_wherey(void);
#ifdef __cplusplus
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment