Category : C Source Code
Archive   : WIND.ZIP
Filename : W_INIT.C

 
Output of file : W_INIT.C contained in archive : WIND.ZIP
/* w_init.c -- part of Windows package; this module contains w_init, w_create,
* w_draw, w_error, w_clear, w_show, w_border, w_title, and the global
* variables
*/

#define NDEBUG

#include
#include
#include
#include
#include
#include "windows.h"

/* these are the globals available to any function using the package
*/
int *vidMem, layers_w, snowFlag, insertFlag, beepFlag;
Window *main_w, *top_w;
unsigned char cols;

/*
* w_init() -- initialization routine; must be called first to use windows
* calls: int86(), w_create(), w_draw()
* sets: vidMem, cols, main_w, top_w
* notes: sets up full screen as main_w & top_w; determines
* which mode and page are active; initializes vidMem
* & cols accordingly; screen will be blank
*/

void w_init()
{
union REGS r;
unsigned char mode, page;

r.h.ah = 15; /* find out mode, active page, row width */
int86(0x10, &r, &r);
mode = r.h.al;
cols = r.h.ah;
page = r.h.bh;
vidMem = (int *) (mode == 7 ? MONO_BASE : COLOR_BASE)
+ page * PAGE_SIZE;
snowFlag = (mode == 7) ? 0 : 1;
main_w = top_w = w_create(0, 0, ROWS - 1, cols - 1, none, "");
main_w->open = 1;
main_w->next = NULL;
w_draw(main_w);
}

/*
* w_create -- creates space for window information; sets values passed
* passed: coordinates for window, border type, window title
* calls: malloc(), w_error(), w_clear(), assert()
* returns: pointer to window record
* sets: members of window record
* uses: cols
* notes: checks to make sure enough memory is available; also
* does some error checking on parameters with assert();
* does not actually display window
*/

Window *w_create(t, l, b, r, border, title)
unsigned int t, l, b, r; /* coordinates for window: top, left, bottom, right */
Border border;
char *title;
{
Window *w;
if ((w = (Window *) malloc(sizeof(Window))) == NULL)
w_error();
w->rect.top = t;
w->rect.left = l;
w->rect.bottom = b;
w->rect.right = r;
w->cursor.row = 0;
w->cursor.col = 0;
w->bord = border;
w->rows = b - t + 1;
w->cols = r - l + 1;
w->title = title;
w->open = 0;
w->data_size = w->rows * w->cols;
if ((w->data = (int *) malloc(w->data_size * sizeof(int))) == NULL)
w_error();
w->attribute = NORMAL;
assert(b >= t && b < ROWS);
assert(r >= l && r < cols);
w_clear(w);
return w;
}

/*
* w_clear -- sets window's data to spaces
* passed: pointer to window structure
* notes: does not change contents of window on screen;
* uses reverse video if so indicated in w->attribute
*/

void w_clear(w)
Window *w;
{
register int count = w->data_size;
register int *p = w->data;
unsigned int value = w->attribute | ' ';

while (count--)
*p++ = value;
}

/*
* w_draw() -- shows a window's data and border on the screen
* passed: pointer to window structure
* calls: w_show(), w_border()
*/

void w_draw(w)
Window *w;
{
w_show(w);
w_border(w);
}

/*
* w_show -- copies contents of window's data to the screen
* passed: pointer to window structure
* calls: w_memcpy()
* uses: cols
*/

void w_show(w)
Window *w;
{
register int row_count;
int *mem_ptr;
VideoLocation vid_loc;

mem_ptr = w->data;
vid_loc = cols * w->rect.top + w->rect.left;
row_count = w->rows;

while (row_count--) {
w_memcpy(vid_loc, (void *) mem_ptr, w->cols);
mem_ptr += w->cols;
vid_loc += cols;
}
}

/*
* w_border() -- draws a window's border & title on the screen
* passed: pointer to window structure
* calls: w_title(), w_putw()
* uses: cols
* notes: takes no action if window uses no border
*/

void w_border(w)
Window *w;
{
/* graphic characters for borders */
static unsigned char UL[] = {0xDA, 0xC9}, /* upper left */
UR[] = {0xBF, 0xBB}, /* upper right */
LL[] = {0xC0, 0xC8}, /* lower left */
LR[] = {0xD9, 0xBC}, /* lower right */
HOR[] = {0xC4, 0xCD}, /* horizontal */
VERT[] = {0xB3, 0xBA}; /* vertical */
register int i;
register VideoLocation ptr;

if (w->bord == none)
return;
ptr = w->rect.top * cols + w->rect.left - cols - 1;
w_putw(UL[w->bord] | w->attribute, ptr++);
for (i = w->cols; i; i--)
w_putw(HOR[w->bord] | w->attribute, ptr++);
w_putw(UR[w->bord] | w->attribute, ptr);
for (i = w->rows; i; i--)
w_putw(VERT[w->bord] | w->attribute, ptr += cols);
w_putw(LR[w->bord] | w->attribute, ptr += cols);
for (i = w->cols; i; i--)
w_putw(HOR[w->bord] | w->attribute, --ptr);
w_putw(LL[w->bord] | w->attribute, --ptr);
for (i = w->rows; i; i--)
w_putw(VERT[w->bord] | w->attribute, ptr -= cols);
w_title(w);
}

/* w_title() -- places window's title at top border
* passed: pointer to window structure
* calls: assert(), strlen()
* uses: cols
* notes: assumes the title is not longer than the window is
* wide; call to assert checks this assumption
*/

void w_title(w)
Window *w;
{
register VideoLocation vid_ptr;
register char *t = w->title;

assert(strlen(t) <= w->cols);
vid_ptr = (w->rect.top - 1) * cols + w->rect.left +
(w->cols - strlen(t)) / 2;
while (*t)
w_putw(*t++ | w->attribute, vid_ptr++);
}

/*
* w_error() -- prints error message if memory runs out; exits
* calls: w_putw(), exit()
* uses: cols
*/

void w_error()
{
char *cp = "Insufficient memory for window management";
VideoLocation p;

for (p = 0; p < cols * ROWS; p++)
w_putw(NORMAL | ' ', p);
for (p = 0; cp[p]; p++)
w_putw(cp[p] | 0x0700, p + cols);
exit(1);
}


  3 Responses to “Category : C Source Code
Archive   : WIND.ZIP
Filename : W_INIT.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/