Category : C Source Code
Archive   : BCWINDOW.ZIP
Filename : WINDOW.C

 
Output of file : WINDOW.C contained in archive : BCWINDOW.ZIP
#pragma inline
#include
#include
#include
#include
#include
#include
#include


/* Window routines for turbo c v2.0 . Designed by Bill Crum. **
** **
** get_video_mode () sets up screen addresses and colors if needed. **
** push_window () puts window to the screen and creates pointer for **
** other routines. **
** push () puts window to screen with window pointer. **
** pop () removes window from screen restores screen. **
** cursor_off() turns off cursor. **
** cursor_on() turns on cursor. **
** clr_window() clear_screen for window pointed to. **
** w_printf() pseudo printf for window pointed to. **
** close_wind () clears window pointer and returns memory to dos. **
** scroll_window () moves window screen up or down 1 line. **
** save_screen () full screen save to buffer. **
** restore_screen () returns buffer saved to screen. **
** explode_frame () makes a window that appears to expand from zero. **
** unexplode_frame () shrinks window to zero size. **
** draw_frame () creates the window border. **
** clear_frame () erases the window border. **
** f_write () direct writes to screen memory. **
** getchx () returns hot key values by adding 300 to ascii. **
** **
** All the routines were written by myself in advanced c class except **
** for two which was taken from the book 'turbo c developers library'. **
** I am supplying the source in hopes of impressing someone into hiring **
** a junior level programmer. */


extern int
baseofscreen;

extern char
waitforretrace,
normal,
vidhigh,
reverse,
black,
blue,
green,
cyan,
red,
magenta,
brown,
white,
bwhite,
background;


struct WINDOW windo;

struct WINDOW *push_window (int x, int y, int width, int len, int type, int border, char *atr,
char *title, char winback)
{
struct WINDOW *pwindow; /* structure to passed around */

if ( ((x + width) > 80) || ((y + len) > 25) )
return ( 0 );
pwindow = (struct WINDOW *) malloc (sizeof(struct WINDOW));
pwindow->background = malloc ( width * len * 2 );
pwindow->foreground = malloc ( width * len * 2 );
pwindow->x = x;
pwindow->y = y;
pwindow->width = width;
pwindow->len = len;
pwindow->border = border;
pwindow->type = type;
pwindow->atr = atr;
pwindow->title = title;
pwindow->winback = winback;
gettext ( x, y, width + x - 1, len + y - 1, pwindow->background);
switch (type)
{
case 1:
explode_frame (pwindow);
break;
default:
draw_frame (x, y, width, len, border, atr, title, winback);
}
gettext ( x, y, width + x - 1, len + y - 1, pwindow->foreground);
return (pwindow);

}



int getchx (void) /* returns hot keys by adding 300 to ascii code */
{
char Cha;

if (( Cha = getch ()) != 0 )
{
return ( Cha );
}
else
{
return ( getch () + 300 );
}
}




void clr_window ( struct WINDOW *window )
{
char blanks[80] =
{" "};
int count;

blanks[window->width-2] = 0;
for (count = 0; count < window->len - 2 ; count++)
{
f_write ( window->x + 1, window->y + count + 1, window->winback, blanks);
}
gettext ( window->x, window->y, window->width + window->x - 1, window->len + window->y - 1, window->foreground);
}




void w_printf (struct WINDOW *window, int x, int y, char *str, char atr)
{
if (!window)
return;

if (( x >= (window->width - 2)) || ( y >= (window->len - 2)))
return;

if ( strlen (str) > (window->width - 2 - x))
*(str + (window->width - x ) - 2) = 0;

f_write ( window->x + x + 1, window->y + y + 1, window->winback | (atr >> 4) , str);
gettext ( window->x, window->y, window->width + window->x - 1, window->len + window->y - 1, window->foreground);

}

/* push () puts previous define window to screen */

void push (struct WINDOW *window)
{
if ( window )
{
gettext ( window->x,window->y, window->width + window->x - 1, window->len + window->y - 1, window->background);
switch (window->type)
{
case 1:
explode_frame (window);
break;
}
puttext ( window->x,window->y, window->width + window->x - 1, window->len + window->y - 1, window->foreground);
}
}


/* pop() removes previously defined window from screen */

void pop (struct WINDOW *window)
{
if ( window )
{
switch (window->type)
{
case 1:
unexplode_frame (window);
break;
default:
puttext ( window->x,window->y, window->width + window->x - 1, window->len + window->y - 1, window->background);
}
}
}

/* close_wind () nulls defined window and returns memory to dos. */

void close_wind (struct WINDOW *window)
{

if (window)
{
pop (window);
free ( window->background );
free ( window->foreground );
free ( window );
window = 0;
}
}



scroll_window (struct WINDOW *window, char up_down)
{
union REGS regs;

setmem (®s, sizeof (regs),0);

regs.h.bh = window->winback;
regs.h.ch = window->y;
regs.h.cl = window->x;
regs.h.dh = window->y + window->len - 3;
regs.h.dl = window->x + window->width - 3;
regs.h.al = 1;
if ( up_down )
{
regs.h.ah = 6;
}
else
{
regs.h.ah = 7;
}
int86 (0x10, ®s, ®s);
}



int oldcursor;

void cursor_off ()
{
union REGS regs;

setmem (®s, sizeof (regs), 0);

regs.h.ah = 0x03;
int86 (0x10, ®s, ®s);
oldcursor = regs.x.cx;
setmem (®s, sizeof (regs), 0);
regs.h.ah = 0x01;
regs.h.ch = 0x20;
int86 (0x10, ®s, ®s);
}


void cursor_on ()
{
union REGS regs;

setmem (®s, sizeof (regs), 0);

regs.h.ah = 0x01;
regs.x.cx = oldcursor;
int86 (0x10, ®s, ®s);
}


char *screen_buffer;


save_screen ()
{
screen_buffer = malloc (4000);
gettext ( 0,0,79,24, screen_buffer);
}


restore_screen ()
{
puttext ( 0,0,79,24, screen_buffer );
free (screen_buffer);
}



explode_frame (struct WINDOW *window)
{
int x, y, w, l;

x = (window->x + (window->width / 2));
y = (window->y + (window->len / 2));
w = l = 1;
while ( (w < window->width)||(l < window->len))
{
x -= 3;
if ( x < window->x )
x = window->x;
y--;
if ( y < window->y )
y = window->y;
w += 6;
if ( w > window->width)
w = window->width;
l += 2;
if ( l > window->len )
l = window->len;
draw_frame ( x, y, w, l, window->border, window->atr, window->title, window->winback );
}
}


unexplode_frame (struct WINDOW *window)
{
int x, y, w, l, a, b;

a = b = 0;
x = window->x;
y = window->y;
w = window->width;
l = window->len;
while ((w > a) && (l > b))
{
delay (15);
puttext ( window->x,window->y, window->width + window->x - 1, window->len + window->y - 1, window->background);
draw_frame ( x += 3, y++, w -= 6, l -= 2, window->border,window->atr, window->title, window->winback);
a += 3;
b++;
}
puttext ( window->x,window->y, window->width + window->x - 1, window->len + window->y - 1, window->background);
}


/* original version of draw_frame taken from Turbo C developers library book */

void draw_frame (int tlcx, int tlcy, int wide, int len, int lines,
char *atr, char *title, char winback)
{
char
batr[2],
box[6][7] = {"±±±±±±",
"ÚÀ³Ä¿Ù",
"ÉȺͻ¼",
"ÖӺķ½",
"ÕԳ͸¾",
"******"},
hline[100],
tline[100];

int c, rx;


wide -= 2;
len -=2;


if ((len > 0) && (wide > 0))
clear_frame (winback, tlcx + 1, tlcy + 1, wide, len);

hline[0] = box[lines][0];
for ( c = 1; c <= wide; hline[c] = box[lines][3], c++ );

hline[c++] = box[lines][4];
hline[c] = 0;
for ( c = 0; c <= 1; c++ )
{
switch (atr[c])
{
case 'N': case 'n': batr[c] = normal; break;
case 'R': case 'r': batr[c] = reverse; break;
case 'H': case 'h': batr[c] = vidhigh; break;
}
if ((waitforretrace) && (!c))
batr[c] = (batr[c] & 0x0f) | winback;
}
f_write (tlcx, tlcy, batr[0], hline);
hline[0] = box[lines][1];
hline[wide + 1] = box[lines][5];
f_write (tlcx, tlcy + len + 1, batr[0], hline);

len += tlcy;
rx = tlcx + wide + 1;
hline[0] = box[lines][2];
hline[1] = 0;
for (c = tlcy + 1; c <= len; c++)
{
f_write (tlcx, c, batr[0], hline);
f_write (rx, c, batr[0], hline);
}
strcpy (tline, title);
erase_white_end(tline);
erase_white_begin(tline);
if (strlen (tline) > 0)
{
cen (tline, hline, strlen(tline) + 2);
rx = (((wide + 2) - strlen(hline) >> 1) + tlcx);
f_write (rx, tlcy, batr[1], hline);
}

}

void clear_frame (char wincolor, int xtl, int ytl, int winwid, int windep)
{
char clearstring [100];
int c;

setmem (clearstring, winwid, 32);
clearstring[winwid] = 0;
ytl--;
for (c = 1; c <= windep; c++)
f_write(xtl, ytl + c, wincolor, clearstring);
background = wincolor;
}


char *erase_white_end ( char *st)
{
int c;

if (st[0])
{
for ( c = 0; st[c]; c++ );
for ( c--; ((c > 0) && ((unsigned) st[c] <= 32)); c-- );
if ((unsigned) st[c] > 32)
st[c + 1] = 0;
else
st[c] = 0;
}
return (st);
}

char *erase_white_begin (char *st)
{
int c, c1;

c1 = 0;
for (c= 0; (((unsigned)st[c] <= 32) && (st[c])); c++);
if (st[c])
{
while (st[c])
{
st[c1] = st[c];
c1++;
c++;
}
}
st[c1] = 0;
return (st);
}

char *cen(char *cstr, char *tstr, int fw)
{
int t, t1, ls, lc, rc;

ls = strlen (cstr);
if (ls <= fw)
{
lc = (t1 = fw - ls) >> 1;
rc = lc + (t1 & 0x0001);
for ( t = 0, lc--; t <= lc; t++)
tstr[t] = ' ';
for ( t1 = 0, ls--; t1 <= ls; t++, t1++ )
tstr[t] = cstr[t1];
for (rc += t; t < rc ; t++)
tstr[t] = ' ';
tstr[t] = 0;
}
else
{
for ( t = 0, fw--; t <= fw; t++ )
tstr[t] = cstr[t];
tstr[t] = 0;
}
return (tstr);
}


void get_video_mode()
{
/* struct vidcfgtype
{
char
normal,
vidhigh,
reverse,
black,
blue,
green,
cyan,
red,
magenta,
brown,
white,
bwhite,
background;
};
struct vidcfgtype
cfgvid;
*/
union REGS
procreg;

memset(&procreg, 0x00, sizeof (procreg));
procreg.h.ah = 0x0f;
int86(0x10, &procreg, &procreg);

switch (procreg.h.al)
{
case 0x07:
baseofscreen = 0xb000;
waitforretrace = 0x00;
normal = 0x07;
vidhigh = 0x0f;
reverse = 0x70;
black = blue = green = cyan = red =
magenta = brown = white = bwhite = 0x07;
background = black;
break;
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
baseofscreen = 0xb800;
waitforretrace = 0x00;
normal = 0x17;
vidhigh = 0x3f;
reverse = 0x57;
black = 0x00;
blue = 0x10;
green = 0x20;
cyan = 0x30;
red = 0x40;
magenta = 0x50;
brown = 0x60;
white = 0x70;
bwhite = 0xf0;
background = blue;
break;

case 0x08:
case 0x09:
case 0x0a:
case 0x0d:
case 0x0e:
case 0x0f:
baseofscreen = 0xb800;
waitforretrace = 0x01;
normal = 0x17;
vidhigh = 0x3f;
reverse = 0x41;
black = 0x00;
blue = 0x10;
green = 0x20;

cyan = 0x30;
red = 0x40;
magenta = 0x50;
brown = 0x60;
white = 0x70;
bwhite = 0xf0;
background = blue;
break;
default:
printf ("Must be in text mode\n");
exit (0);

}/* switch */

}

/* f_write is copied from Turbo C Developers library book */

void f_write (unsigned int x, unsigned int y, char attr, char *st)

{
asm mov al,00h
asm push ds
asm pop es
asm mov di, st
asm mov bx, di
asm mov cx, 0ffffh
asm cld
asm repne scasb
asm sub di, bx
asm mov bx, di
asm dec bx
asm mov si, st
asm mov ax, y
asm dec ax
asm mov cx, 0004h
asm shl ax,cl
asm mov cx,bx
asm mov bx,ax
asm shl ax, 1
asm shl ax, 1
asm add ax,bx
asm mov bx,x
asm dec bx
asm add ax,bx
asm shl ax,1
asm mov di,ax
asm mov dx,baseofscreen
asm mov es,dx
asm mov al,waitforretrace
asm mov si, st
asm jcxz Exit
asm mov ah,attr
asm cld
asm rcr al,1
asm jnc Mono
asm mov dx, 03dah
GetNext:
asm lodsb
asm mov bx,ax
asm mov ah, 09h
asm cli
Waith:
asm in al,dx
asm rcr al, 1
asm jc Waith
Waitv:
asm in al,dx
asm and al,ah
asm jz Waitv
asm mov ax,bx
asm stosw
asm sti
asm loop GetNext
asm jmp Exit
Mono:
asm lodsb
asm stosw
asm loop Mono
Exit:
/* asm pop ds */
;
}



  3 Responses to “Category : C Source Code
Archive   : BCWINDOW.ZIP
Filename : WINDOW.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/