Category : Assembly Language Source Code
Archive   : MSCPOPUP.ZIP
Filename : WINDOW.C

 
Output of file : WINDOW.C contained in archive : MSCPOPUP.ZIP
/* Window.c - General-purpose windowing routines for machines whose display
* adapter hardware is compatible with that of the IBM PC.
*
* By Paul Ketrick, with some help from David Cherin.
* You may use this code in any way you like, but please give David and
* myself credit for it at the beginning of your source code.
*
* This is code is designed for Microsoft's C compiler version 4.0 but will
* probably work on any compiler that outputs Microsoft-compatible .OBJ files
* (i.e. MSC 3.0, Lattice); it must be linked with the object file of
* window1.asm.
*
* This code was originally written for the DeSmet C compiler; hence the
* several short assembly language functions to speed up some of the low-
* level operations. The code is now messy in places, but seems to work very
* solidly.
*
* What this windowing library does:
*
* This library supports multiple "layers" of windows on the screen; that is,
* it displays data in windows as if some windows were physically "above"
* other windows. Data that is printed to a part of a window that is beneath
* another window is not actually shown on the screen; when the cursor is
* at a position such that it lies beneath another window, it too is not
* shown. When data in a window that lies beneath another window is scrolled,
* only the visible parts of the window are actually shown as scrolling, and
* so on.
*
* Windows are opened and closed in much the same manner as DOS file handles.
* When a window is opened, its display area is filled with spaces and its
* border is drawn. When a window is closed, whatever happens to be below
* the window is displayed in its place.
*
* The "current" window is the last window opened or the last window
* referenced in a call to the wset() function (see below). All windowing
* functions operate on this current window. If you wish to change this to a
* system in which the desired window is specified in each call to a
* windowing function, the changeover should be fairly easy to make.
*
* When the first window on the screen is opened, the current video
* screen is copied to a buffer which set up as window number zero and may
* referenced as such. While any windows are open, no screen output should
* be done with any functions other than the ones in this library (such as
* the standard library printf() function); doing so will result in whatever
* was printed being stomped over when the windows are closed.
*
* Functions included in this module:
* wopen(x1, y1, x2, y2, border)
* Opens on the screen a window whose upper left corner is at coordinate
* (x1,y1) on the screen and whose lower right corner is at coordinate
* (x2,y2). If "border" equals 1, a border is drawn around the window
* and all calls to wputchar(), wprintf(), etc. will only display data
* inside the window's border. If "border" equals 0, no border is drawn
* and all spaces occupied by the window may be printed to. wopen()
* returns a window "handle" which may be used later by the wset()
* function (see below) to reference the window. The newly opened
* window is made the "current" window.
*
* w_cls()
* If the current window was opened with a border, the space inside the
* border is cleared to spaces; if not, the window's entire space is
* set to spaces. The cursor is moved to the top left printable
* space in the window.
*
* wtop()
* The current window is brought to the top of the screen; that is,
* it is redrawn as if it were above all the other windows on the
* screen.
*
* wclose()
* The current window is closed and erased from the screen; whatever
* is below the erased window is drawn in in its place. Note that
* if there are any windows remaining on the screen, a call to wset()
* must be issued to determine which window further windowing function
* calls will operate on.
*
* wputchar(chr)
* The specified character is printed at the current cursor location
* in the current window and the cursor is advanced one character
* space. ASCII control characters 8 (backspace), 13 (CR) and 10 (LF)
* are recognized. Scrolling is performed if the cursor moved past the
* end of the last displayable line in the window; this scrolling is
* performed properly if the current window lies beneath one or more
* other windows, although it goes much faster if this is not the case.
*
* w_scrollu()
* Scrolls the current window up by one line; does not affect cursor
* location.
*
* s_redraw()
* Redraws all windows on the screen (including the "background," meaning
* whatever was on the screen when the first window was opened).
*
* wputattr(attr)
* Similar to wputchar(); changes the video attribute byte of the
* character under the cursor and moves the logical cursor forward one
* character space. Does not, however, move the physical cursor or
* scroll when the logical cursor moves past the end of the last line
* in the window.
*
* wsetattr(attr)
* Sets the current video attribute byte; all characters printed
* subsequently will have the specified attribute.
*
* wgetattr()
* Returns the current video attribute byte as an int.
*
* wset(handle)
* Makes the window with the specified handle the "current" window;
* all windowing functions operate on the "current" window which is
* set by both this and the wopen() functions.
*
* w_setxy(x, y)
* Moves the cursor to coordinates (x,y) within the current window's
* displayable space, coordinates (0,0) being the top left corner of
* the window's printable space. Both the window's logical cursor and
* the physical cursor are moved.
*
* w_getxy(xp, yp)
* Stores the current cursor's x and y coordinates within the current
* window's display space at *xp and *yp, respectively.
*
* The wprintf() function has been moved to a separate file, printf.c.
* It calls wputchar() to output characters to the current window.
*/

#include
#include


/* # D E F I N E S
*/

typedef unsigned char BYTE;

#define ERR (-1)
#define TRUE 1
#define FALSE 0
#define YES 1
#define NO 0

#define SCRN_COLS 80 /* Number of columns on the screen */
#define SCRN_ROWS 25 /* Number of rows on the screen */
#define BYTES_CHR 2 /* Bytes per character of video RAM */

#define FROM 1 /* Used by copyscrn() function */
#define TO 0 /* Ditto */
#define NO_BORD 0 /* Tells wopen() not to give the new window a border */
#define YES_BORD 1 /* Tells wopen() to give the new window a border */

#define NORMAL 7 /* Video attribute byte for white-on-black characters */
#define HIGHLITE 112 /* Video attribute byte for black-on-white characters */

#define MAX_WINS 10 /* Maximum of 10 different windows can be opened */

#define BORDER_TL 201 /* Character for top left corner of window border */
#define BORDER_T 205 /* Character used for top line of border */
#define BORDER_TR 187 /* Character for top right corner of border */
#define BORDER_L 186 /* Character used along left edge of border */
#define BORDER_R 186 /* Character used along right edge of border */
#define BORDER_BL 200 /* Character used for bottom left corner */
#define BORDER_B 205 /* Character used along bottom line of border */
#define BORDER_BR 188 /* Character used for bottom right corner */


/* The following #defines are macro functions that were too short
* to be made into real functions. Most of them deal with converting
* x-y coordinates, video memory addresses and window display buffer
* addresses to one another.
*/

#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

#define _getscrad(X, Y) (((Y) * SCRN_COLS + (X)) * BYTES_CHR + vidmoff)
/* Returns video memory offset of location (X,Y) on the screen */

#define get_bufad(HANDLE, X, Y) (((Y) + border_f) * window[HANDLE].width + (X) + border_f) * BYTES_CHR + window[HANDLE].buffer
/* Returns pointer in display buffer of desired window to
* location (X,Y). Note that if border_f is 0, location (0,0)
* represents the top left corner of the window's border.
* If border_f is 1, location (0,0) is the top left
* corner of the inside of the window. This function will
* change if buffering of output that falls outside the
* boundaries of a window ever becomes supported.
*/

#define get_scrad(HANDLE, X, Y) _getscrad((X) + window[HANDLE].leftx + border_f, (Y) + window[HANDLE].topy + border_f)
/* Returns pointer to video memory to location (X,Y) in the
* selected window. The status of border_f applies here as
* in the above function.
*/

#define mapaddr(X) ((X-vidmoff) / BYTES_CHR)
/* Converts video memory address to corresponding index in scrnmap[].
*/

#define mapindex(HANDLE, X, Y) mapaddr(get_scrad(HANDLE, X, Y))
/* Converts x & y coordinates within the specified window to

* the corresponding index in scrnmap[]. The status of border_f
* applies here as in the get_bufad() and get_scrad() functions
* above.
*/


/* D A T A S T R U C T U R E S
*/

struct wintbl { /* Window descriptor table */
char used; /* Flag to indicate if window handle is in use */
char has_bord; /* =1 if window has a border, 0 if not */
char overlapd; /* =TRUE if window is overlapped by another */
BYTE cur_attr; /* Current video attribute byte */
unsigned int leftx; /* x coordinate of left edge of window */
unsigned int topy; /* y coordinate of top edge of window */
unsigned int rightx; /* x coordinate of right edge of window */
unsigned int bottomy; /* y coordinate of bottom edge of window */
unsigned int width; /* width of the window, from left border to right */
unsigned int height; /* height of the window, from top border to bottom */
BYTE *buffer; /* Pointer to window's display buffer */

BYTE *cursor; /* pointer to the cursor's location within the
* display buffer (points to the character the
* cursor is under)
*/
unsigned int cursorx; /* x coordinate within window (meaning it is
* zero for the leftmost printable column of
* the window no matter what the window's location
* on the screen is) of window's current cursor
* location
*/
unsigned int cursory; /* y coordinate within window of current
* cursor location
*/
unsigned c_scradd; /* video memory offset of where the cursor is */
} window[MAX_WINS]; /* There are actually MAX_WINS - 1 windows that can be
* used by programs since window[0] always represents
* what the original screen was when the first window
* was opened. A window is referred to by a window
* "handle" which is just its index in the window[]
* structure array.
*/

unsigned int winlevel[MAX_WINS];
/* winlevel[] provides a means for determining which windows are above
* and below which other windows. winlevel[0] contains the window handle
* of the lowermost window on the screen - the window furthest towards
* the background, which actually will always be the original screen
* contents when the first window was opened. If there are three
* windows on the screen, winlevel[2] contains the window handle of
* the topmost window on the screen and winlevel[1] contains the
* handle of the window just below the topmost window.
*/

char scrnmap[SCRN_COLS * SCRN_ROWS];
/* scrnmap holds the window "handle" of the window that is currently
* viewable at each character location on the screen - that is, it
* contains the window handle of the "topmost" window on the screen
* at every screen location. The mapaddr() macro above shows
* how the mapping of video memory addresses to scrnmap[] entries
* works.
*/

BYTE scrnbuf[SCRN_COLS * SCRN_ROWS * BYTES_CHR];
/* scrnbuf holds the original screen that was being displayed when the
* first window was opened up. It appears to all windowing functions
* as just another window's display buffer.
*/
BYTE tempscrn[SCRN_COLS * SCRN_ROWS * BYTES_CHR];
/* Temporary screen buffer used by window scrolling, moving routines */


/* V A R I A B L E S
*/

int wincount = 0; /* Number of open windows on screen */
BYTE attr = 7; /* Current video attribute byte */
unsigned int vidmseg, vidmoff; /* Segment, offset of start of */
/* video mem. */
unsigned int crt_base; /* CRTC base I/O address */
int border_f = 0; /* =1 if current window has a */
/* border, 0 if it does not */
int dhandle = 0; /* Current (default) window handle */
struct wintbl *winptr; /* Points to current window's entry */
/* in the window descriptor table */


/* F U N C T I O N D E C L A R A T I O N S
*/

char *malloc();


/* O P E N A W I N D O W
*/

int wopen(leftx, topy, rightx, bottomy, border)
unsigned int leftx, topy, rightx, bottomy, border;

{
int handle; /* Window handle of the opened window */
int width, height; /* Width and height of the window */
BYTE *bufptr; /* Points to the window's display buffer */
char overlap[MAX_WINS]; /* Holds window[n].overlapd values */
register int i, k; /* General-use */
int j; /* General-use */

if (leftx >= SCRN_COLS || rightx >= SCRN_COLS ||
topy >= SCRN_ROWS || bottomy >= SCRN_ROWS ||
rightx - leftx < 2 || bottomy - topy < 2)
return(ERR);

width = rightx - leftx + 1;
height = bottomy - topy + 1;

if ((bufptr = malloc(width * height * BYTES_CHR)) == 0)
return(ERR);

if (wincount == 0) { /* If there are no windows currently on the
* screen, do the following initialization:
*/
if (getvmode() == 7) { /* If monochrome screen is being used */
vidmseg = 0xb000;
vidmoff = 0;
crt_base = 0x3b4;
} else { /* Assume CGA text mode */
vidmseg = 0xb800;
vidmoff = 0;
crt_base = 0x3d4;
}
copyscrn(TO, scrnbuf); /* Copy current video screen to scrnbuf[] */

for (i=0; i < SCRN_ROWS * SCRN_COLS; i++)
scrnmap[i] = 0; /* Initialize scrnmap[] array */

winptr=&window[0]; /* winptr points to window[0] structure */
winlevel[0] = 0; /* Initialize data for window 0 */
winptr->used = TRUE;
winptr->has_bord = FALSE;
winptr->cur_attr = NORMAL;
winptr->leftx = 0;
winptr->topy = 0;
winptr->rightx = SCRN_COLS - 1;
winptr->bottomy = SCRN_ROWS - 1;
winptr->width = SCRN_COLS;
winptr->height = SCRN_ROWS;
winptr->buffer = scrnbuf;
winptr->cursorx = 0;
winptr->cursory = 0;
winptr->cursor = scrnbuf;

/* Clear out tables for windows 1 thru MAX_WINS - 1 */
for (i=1; i < MAX_WINS; i++) {
window[i].used = FALSE;
winlevel[i] = -1;
}
}

for (handle=0; handle < MAX_WINS; handle++) {
if (window[handle].used == FALSE) /* Find an unused window handle */
break;
overlap[handle] = window[handle].overlapd;
}

if (handle >= MAX_WINS)
return(ERR); /* No window handles available */

if (border)
border = 1; /* Make sure border is either 0 or 1 */

winptr=&window[handle];
winptr->used = TRUE; /* Set up window descriptor table entry */
winptr->has_bord = border; /* Set has_bord based on border flag passed */
overlap[handle] = FALSE; /* New window will be placed on top of all
* other windows, so we know it will not
* be overlapped.
*/
overlap[0] = TRUE; /* New window will always overlap window 0 */
winptr->cur_attr = NORMAL;
winptr->leftx = leftx;
winptr->topy = topy;
winptr->rightx = rightx;
winptr->bottomy = bottomy;
winptr->width = width;
winptr->height = height;
winptr->buffer = bufptr;

for (i=0; i < MAX_WINS; i++)
if (winlevel[i] == -1)
break;

if (i != handle)
return(ERR); /* Indicates a rather fatal error in either the
* window[].used entries or the winlevel[] table.
* Put some kind of recovery routine here later.
*/

winlevel[i] = handle; /* Put new window on top in winlevel[] table */

wset(handle); /* Make the new window the current window */

border_f = 0; /* So we can access entire space occupied by
* the window, not just the space inside the
* border
*/

/* j represents the row # within the window, k the column #: */
for (j=0; j < height; j++) {
i = mapindex(handle, 0, j);

for (k=0; k < width; k++) {
overlap[scrnmap[i]] = TRUE;
scrnmap[i++] = handle;
}
}

for (i=0; i <= handle; ++i)
window[i].overlapd = overlap[i];

bufptr=get_bufad(handle, 0, 0);
for (i=0; i < width * height; i++) { /* Fill window with spaces */
*bufptr++=' '; /* first store character */
*bufptr++=NORMAL; /* then attribute byte */
}

/* Draw the window's border: */

if (winptr->has_bord) /* If a bordered window was specified */
drawbord(winptr->buffer, width, height);

w_redraw();
border_f = winptr->has_bord; /* After this, programs can only
* access areas inside the window
* (not the border, if any)
*/
w_setxy(0, 0);

++wincount; /* Increment open-windows counter */

return(handle);
}

w_cls() /* Clear current window's display area */
/* to spaces with white-on-black attr */
{
int handle, x, y;
BYTE *bufptr;

winptr = &window[handle = dhandle];
for (y=0; yheight - 2*border_f; ++y) {
bufptr=get_bufad(handle, 0, y);
for (x=0; x < winptr->width - 2*border_f; ++x) {
*bufptr++=' '; /* first store character */
*bufptr++=NORMAL; /* then attribute byte */
}
}
w_redraw();
w_setxy(0, 0);
return(0);
}

w_drawbord() /* Draws a border around the current window */
{
int handle;

winptr = &window[handle=dhandle];
drawbord(winptr->buffer, winptr->width, winptr->height);
w_redraw();
return(0);
}

drawbord(bufadd, width, height)
BYTE *bufadd;
int width, height;

{
int i, j;

*bufadd = BORDER_TL;
bufadd += BYTES_CHR;
for (i=0; i *bufadd = BORDER_T;
bufadd += BYTES_CHR;
}
*bufadd = BORDER_TR;
bufadd += BYTES_CHR;

for (j=0; j *bufadd = BORDER_L;
bufadd += (width-1)*BYTES_CHR;
*bufadd = BORDER_R;
bufadd += BYTES_CHR;
}

*bufadd = BORDER_BL;
bufadd += BYTES_CHR;
for (i=0; i *bufadd = BORDER_B;
bufadd += BYTES_CHR;
}
*bufadd = BORDER_BR;

return(0);
}

/* M O V E A W I N D O W T O
*
* T O P O F S C R E E N
*/

wtop()
{
int handle;
int index1, index2;
int i, j, k, overlap[MAX_WINS];

handle = dhandle; /* Use default window handle */
winptr = &window[handle];

if (winptr->used == FALSE)
return(ERR);

/* Find the selected window in winlevel[] */
for (index1=0; index1 < MAX_WINS; index1++)
if (winlevel[index1] == handle)
break;

if (index1 >= MAX_WINS)
return(ERR);

/* Move all windows that are above the selected window, down one level
* and place the selected window at the top of the list:
*/
index2 = index1 + 1;
while (index2 < MAX_WINS && winlevel[index2] != -1) {
winlevel[index2 - 1] = winlevel[index2];
++index2;
}

winlevel[index2 - 1] = handle;
border_f = 0;

for (i=0; i<=wincount; ++i)
overlap[i] = window[i].overlapd;

/* For every character location in the window, set the corresponding
* byte in scrnmap[] equal to the window's handle, bringing all the
* window's characters to the top of the screen:
*/
for (j=0; j < winptr->height; j++) {
i = mapindex(handle, 0, j);

for (k=0; k < winptr->width; k++) {
overlap[scrnmap[i]] = TRUE;
scrnmap[i++] = handle;
}
}
overlap[handle] = FALSE;
for (i=0; i<=wincount; ++i)
window[i].overlapd = overlap[i];

/* Finally, redraw the window on the screen to reflect the changes */
w_redraw();

border_f = winptr->has_bord; /* Reset border_f for return */
return(0);
}


/* C L O S E A W I N D O W
*/

wclose()
{
int handle;
int i,j;

if ((handle=dhandle) == 0)
return(ERR); /* Can't close window zero */
winptr = &window[handle];

if (winptr->used == FALSE) /* If current window handle is invalid */
return(ERR);

w_erase(handle);

free(window[handle].buffer); /* free memory allocated to display buffer */
window[handle].used = FALSE;

for (i=0; i < MAX_WINS; i++)
if (winlevel[i] == handle)
break;

if (i >= MAX_WINS)
return(ERR); /* Indicates some fatal error in the window[].used
* entry or the winlevel[] table. Put recovery
* routine here later.
*/
if (i < MAX_WINS-1) /* Delete closed window's entry in winlevel[] */
for (j=i + 1; j < MAX_WINS; j++)
winlevel[j-1] = winlevel[j];
else
winlevel[i] = -1;

redo_olp(); /* Recompute overlapping windows */
--wincount;
return(0);
}

/* E R A S E A W I N D O W
*/

BYTE *bufaddr; /* holds display buffer address of character that
* is replacing the character being erased. Should
* not be external in future versions.
*/
unsigned int scraddr; /* holds screen address of character being erased.
* Also should be automatic var. in future versions
*/

char *mapptr; /* points to location in scrnmap[]. */

w_erase(handle)
int handle;

{
int x, y;
int s_handle;
struct wintbl *s_winptr; /* pointer to window[] structure during search */
int winlev;
int i;

winptr = &window[handle];

if (winptr->used == FALSE)
return(ERR);

for (winlev=0; winlev < MAX_WINS; winlev++)
if (winlevel[winlev] == handle)
break;

if (winlev >= MAX_WINS)
return(ERR);

border_f=0;
for (y=winptr->topy; y <= winptr->bottomy; y++)
for (x=winptr->leftx; x <= winptr->rightx; x++)
if (scrnmap[mapaddr(scraddr=_getscrad(x, y))] == handle)
for (i=winlev-1; i >= 0; i--) {
s_winptr=&window[s_handle = winlevel[i]];
if (x >= s_winptr->leftx &&
x <= s_winptr->rightx &&
y >= s_winptr->topy &&
y <= s_winptr->bottomy) {
bufaddr=get_bufad(s_handle, x-s_winptr->leftx, y-s_winptr->topy);
copychar();
scrnmap[mapaddr(scraddr)] = s_handle;
break;
}
}
return(0);
}

redo_olp() /* Recompute which windows are overlapped by
* others
*/
{
int i, j;
struct wintbl *wp1, *wp2;

for (i=0; i<=wincount; ++i) {
wp1 = &window[winlevel[i]];
wp1->overlapd = FALSE; /* Initially assume window isn't overlapped */
for (j=i+1; j<=wincount; ++j) {
wp1 = &window[winlevel[i]];
wp2 = &window[winlevel[j]];
if (((wp2->leftx >= wp1->leftx && wp2->leftx <= wp1->rightx)
|| (wp2->rightx >= wp1->leftx && wp2->rightx <= wp1->rightx))
&& ((wp2->topy >= wp1->topy && wp2->topy <= wp1->bottomy)
|| (wp2->bottomy >= wp1->topy && wp2->bottomy <= wp1->bottomy))) {
wp1->overlapd = TRUE;
break;
}
}
}
return(0);
}

wputchar(chr)
BYTE chr;

{
int handle;
BYTE *scr_addr;

winptr = &window[handle=dhandle];

if (iscntrl(chr)) {
switch (chr) {
case 13:
winptr->cursorx = 0;
break;

case 10:
++winptr->cursory;
break;

case 8:
if (--winptr->cursorx < 0) {
winptr->cursorx = winptr->width - 1 - 2*border_f;
if (--winptr->cursory < 0)
winptr->cursory = 0;
}
break;
}
} else {
*winptr->cursor = chr;
*(winptr->cursor + 1) = attr;

dispchar(winptr->c_scradd, chr, handle);
winptr->c_scradd+=BYTES_CHR; /* update video memory address of cursor */
++winptr->cursorx;
}

if (winptr->cursorx >= winptr->width - 2 * border_f) {
winptr->cursorx = 0;
++winptr->cursory;
}

if (winptr->cursory >= winptr->height - 2 * border_f) {

--winptr->cursory;
w_scrollu();
}

winptr->cursor = get_bufad(handle, winptr->cursorx, winptr->cursory);
winptr->c_scradd = get_scrad(handle, winptr->cursorx, winptr->cursory);
res_csr(handle, winptr->c_scradd);
return(0);
}

w_scrollu()
{
int handle;
register BYTE *p1, *p2;
int i, border_t; /* Holds previous state of border_f */

winptr = &window[handle=dhandle];
border_t = border_f;
border_f = 0;
p1 = get_bufad(handle, 0, border_t);
p2 = p1 + winptr->width*BYTES_CHR;
i = winptr->width * (winptr->height - 1 - 2*border_t) * BYTES_CHR;
memcpy(p1, p2, i); /* Scroll window display buffer up */
p1 += i;
if (border_t)
p1 += BYTES_CHR;

for (i=0; i < winptr->width - 2*border_f; ++i) {
*p1++ = ' '; /* Blank out bottom line */
*p1++ = NORMAL;
}

if (!window[handle].overlapd) /* If the window is not overlapped, */
/* use fast assembly scroll function */
wscrollu(winptr->leftx+border_t, winptr->topy+border_t,
winptr->rightx-border_t, winptr->bottomy-border_t);
else
s_redraw(); /* Redraw entire screen */
border_f = border_t; /* Reset border_f to previous value */

return(0);
}

/* Redraw entire screen using scrnmap[] table and appropriate window
* buffers. Assumes that border_f = 0.
*/

s_redraw()
{
register BYTE *p1, *p2, *ip;
int x, y;
int handle0 = -1;
struct wintbl *winptr; /* Use local so global winptr is not changed */

ip = scrnmap;
p2 = tempscrn;
for (y=0; y for (x=0; x if (*ip != handle0) {
winptr = &window[handle0 = *ip];
p1=get_bufad(handle0, x-winptr->leftx, y-winptr->topy);
}
*p2++ = *p1++; /* Copy character byte */
*p2++ = *p1++; /* Copy attribute byte */
/* (Make this more portable later) */
++ip;
}
}

copyscrn(FROM, tempscrn);

return(0);
}

/* The function below writes an attribute byte only at the current window's
* cursor location. It updates the window's logical cursor but does not
* move the physical cursor. It also does not scroll when the cursor goes
* past the end of the bottom display line.
*/
wputattr(attr)
BYTE attr;

{
int handle;

winptr = &window[handle = dhandle];
*(winptr->cursor + 1) = attr;

dispattr(winptr->c_scradd, attr, handle);
winptr->c_scradd+=BYTES_CHR; /* update video memory address of cursor */
++winptr->cursorx;

if (winptr->cursorx >= winptr->width - 2 * border_f) {
winptr->cursorx = 0;
++winptr->cursory;
}

if (winptr->cursory >= winptr->height - 2 * border_f)
winptr->cursory = 0;

winptr->cursor = get_bufad(handle, winptr->cursorx, winptr->cursory);

return(0);
}

wsetattr(attrbyte)
int attrbyte;

{
int handle;

winptr = &window[handle = dhandle];
winptr->cur_attr = attr = attrbyte;

return(0);
}

wgetattr() /* Returns current display attribute */
{
int handle;

winptr = &window[handle = dhandle];
return(winptr->cur_attr);
}

wset(handle)
int handle;

{
if (handle < 0 || handle >= MAX_WINS || window[handle].used == FALSE)
return(ERR);

winptr = &window[dhandle = handle];
border_f = winptr->has_bord;
w_setxy(winptr->cursorx, winptr->cursory);
return(0);
}

w_setxy(x, y)
int x, y;

{
int handle = dhandle;

winptr = &window[handle];
winptr->cursorx = x;
winptr->cursory = y;
winptr->cursor = get_bufad(handle, winptr->cursorx, winptr->cursory);
winptr->c_scradd = get_scrad(handle, winptr->cursorx, winptr->cursory);
res_csr(handle, winptr->c_scradd);

return(0);
}

w_getxy(xp, yp) /* Returns current cursor x, y */
int *xp, *yp;

{
int handle = dhandle;

winptr = &window[handle];
*xp = winptr->cursorx;
*yp = winptr->cursory;

return(0);
}

/* Reposition the physical cursor to match the logical cursor of the
* current window:
*/

res_csr(handle, addr)
int handle;
unsigned int addr;

{
if (scrnmap[mapaddr(addr)] == handle)
mov_pcsr(addr); /* Position the physical cursor */
else
csr_off(); /* Turn cursor off if it's not visible */

return(0);
}

int width, height; /* Globals used by redraw() below */

w_redraw()
{
int handle;

handle=dhandle;
winptr=&window[handle];
width=winptr->width;
height=winptr->height;
scraddr=get_scrad(handle, 0, 0);
mapptr=&scrnmap[mapaddr(scraddr)];
bufaddr=get_bufad(handle, 0, 0);

redraw(); /* Call assembly language redraw function */

return(0);
}


  3 Responses to “Category : Assembly Language Source Code
Archive   : MSCPOPUP.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/