home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
archiver
/
peek_221.arj
/
SETCMODE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-30
|
4KB
|
209 lines
#include "peeker.h"
#include "timers.h"
int _fastcall _wherex (void);
int _fastcall _wherey (void);
void _fastcall _sleep (int secs);
void _fastcall cursor (int x, int y);
void _fastcall curr_cursor (int *x, int *y);
char * _fastcall avatar2ansi (int avatarcode);
char * _fastcall assign (char *d,char *a);
char * _fastcall add_backslash (char *d);
void _fastcall stat_line (void);
void _fastcall time_line (void);
ulong _fastcall getxbbstime(void);
int cdecl dprintf (int x,int y,char attr,char *string,...);
int _fastcall dputs (int x,int y,char attr,char *string);
extern void _fastcall (*pause_mtask)(void);
int _fastcall ansi_out(char *str);
extern char graphics;
extern char username[36];
extern unsigned int timelimit;
int _fastcall
_wherex (void)
{
_AX = 0x0300;
_BX = 0;
geninterrupt(16);
return _DL;
}
int _fastcall
_wherey (void)
{
_AX = 0x0300;
_BX = 0;
geninterrupt(16);
return _DH;
}
void _fastcall
_sleep (int secs)
{ /* snooze a while */
clock_t t1;
t1 = clock () + ((clock_t) secs * (clock_t) CLOCKS_PER_SEC);
while (clock () < t1)
(*pause_mtask)();
}
/* Position cursor */
void _fastcall cursor (int x, int y) {
pos_hardcursor(x,y);
}
/* Return cursor position */
void _fastcall curr_cursor (int *x, int *y) {
_AX = 0x0300;
_BX = 0;
geninterrupt(0x10);
*x = _DL;
*y = _DH;
}
static int av_trans[] = {0,4,2,6,1,5,3,7};
char * _fastcall avatar2ansi (int avatarcode) {
int foreg;
int backg;
static char temp[13];
static char ansi[21];
if(!graphics) return "";
avatarcode &= 255; /* 127 to strip high bit */
strcpy(ansi,"\x1b[");
backg = (avatarcode & (64 | 32 | 16)) / 16;
foreg = (avatarcode & (4 | 2 | 1));
if (avatarcode & 8) {
strcat(ansi,"0;1;");
}
else strcat(ansi,"0;");
sprintf(temp,"%d",av_trans[foreg]);
if (!backg) {
strcat(ansi,"3");
strcat(ansi,temp);
}
else {
strcat(ansi,"3");
strcat(ansi,temp);
strcat(ansi,";4");
sprintf(temp,"%d",av_trans[backg]);
strcat(ansi,temp);
}
strcat(ansi,"m");
return ansi;
}
char * _fastcall assign (char *d,char *a) {
char *b;
if(d) free(d);
b = strdup(a);
if(!b) {
ansi_out("\r\n\04Out of memory\r\n");
exit(1);
}
return b;
}
char * _fastcall add_backslash (char *d) {
char *t;
if(!d) return d;
t = malloc(strlen(d) + 2);
if(t) {
sprintf(t,"%s\\",d);
free(d);
return t;
}
else {
ansi_out("\r\n\04Out of memory\r\n");
exit(1);
}
}
void _fastcall stat_line (void) {
int oldx,oldy;
curr_cursor(&oldx,&oldy);
dprintf(0,realmaxy - 1,7 * 16," (XBBS) Peeker 2.21 \04 %-58.58s",username);
time_line();
cursor(oldx,oldy);
}
void _fastcall time_line (void) {
dprintf(realmaxx - 11,realmaxy - 1,7 * 16,
"\04 %3ld mins",((long)timelimit - (getxbbstime() / 60L)));
}
int cdecl dprintf (int x,int y,char attr,char *string,...) {
char buffer[134];
va_list ap;
va_start(ap,string);
vsprintf(buffer,string,ap);
va_end(ap);
return dputs(x,y,attr,buffer);
}
int _fastcall dputs (int x,int y,char attr,char *string) {
char *b = string;
int oldx,oldy;
if(b) {
curr_cursor(&oldx,&oldy);
while(*b) {
put_char(*b,attr,x,y);
b++;
x++;
}
cursor(oldx,oldy);
return ((int)b - (int)string);
}
return -1;
}