Category : Alternate Operating Systems - Quarterdeck DesqView, CP/M, etc
Archive   : VMIXUTL.ZIP
Filename : VW.C

 
Output of file : VW.C contained in archive : VMIXUTL.ZIP
/*****************************************************************************
* ComSoft Library -- vw.c
*
* DATE: Nov. 18, 1988 06-20-92
*
* NAME: vw - VMiX 386 window manager
*
* SYNOPSIS:
*
* FUNCTION:
*
* RETURNS:
* N/A
*
*****************************************************************************/

#include "c_bios.h"
#include "$_kernel.h"
#include "$_config.h"
#include "$_mem.h"
#include "$_proc.h"
#include "io_chan.h"
#include "io_irp.h"
#include "io_obj.h"


#define N_MAIN 5 /* number of main menu options */
#define N_SUB 12 /* number of sub-menu options */
#define N_LEVEL 2 /* number of pull-down levels */
#define N_MENU 8 /* number of menus per level */


/* Local prototypes */

int quit(void);
int system(void);
SYSCALL (*fpin)(void);
SYSCALL (*fpwr)(char *str);
LOCAL char digits[16] = "0123456789ABCDEF";


/* Global variables */

BYTE hi_attr, win_attr, lo_attr;
BYTE out_attr, attribute;
BYTE chratio, currvfnt, conbg, conwn;
char filepath[80];
int menu_opt = 0, pull_opt = 0, idx = 0;
int rtop, rbot, p386, hascon = TRUE, vflag = FALSE;
unsigned int currpid, mon_type;
struct CCB *cptr;
struct MEMINFO *mptr;
struct PCB *pptr;

struct WINDOW

{
BYTE x;
BYTE y;
unsigned int buffer[BYTES_80];
} win_inst[N_LEVEL];

struct MENU

{
char head[16];
char body[N_SUB] [32];
int (*fp[N_SUB])();
} m_menu[N_LEVEL][N_MENU] = {

" Advanced ", /* Menu options */
" Assign ", /* Menu sub-options */
" Chprio ",
" Dosjob -",
" Exec ",
" Kill ",
" Remote -",
" rShell ",
" sPawn ",
" sWap ",
" Quit ",
"",
"",
system, /* function that sub-option calls */
system,
system,
system,
system,
system,
system,
system,
system,
quit,
0,
0,

" Memory ",
" Memory Configuration ",
"________________________",
" ",
" Assign extended memory ",
" Free extended memory ",
" Size program space -",
" toggle 736K DOS space ",
"",
"",
"",
"",
"",
0,
0,
0,
system,
system,
system,
system,
0,
0,
0,
0,
0,

" Programs ",
" Process Control ",
"____________________",
" ",
" start Vmix shell -",
" start Dos shell -",
" Launch program -",
" Swap in/out ",
" set Priority ",
" Kill process ",
" Reset screen ",
" set Baud rate -",
"",
0,
0,
0,
system,
system,
system,
system,
system,
system,
system,
system,
0,

" Status ",
" Report Select ",
"_______________",
" ",
" Users ",
" Status ",
" Channels ",
" Registers ",
" Environment ",
" Files ",
" memory Map ",
" memory Pool ",
" memory Blocks ",
0,
0,
0,
system,
system,
system,
system,
system,
system,
system,
system,
system,

" Options ",
" Configuration ",
"__________________",
" ",
" Video modes ",
" screen Colors -",
" Window colors -",
" Resize window ",
" graphics Fonts ",
" Terminal modes ",
" remote Users -",
" Move console -",
" Status on/off ",
0,
0,
0,
system,
system,
system,
system,
system,
system,
system,
system,
system,

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,

"",
"",
"",
"",
"",

"",
"",
"",
"",
"",
"",
"",
"",
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,

"", /* second level pull-downs */
" Chans ",
"_______",
" ",
" COM1 ",
" COM2 ",
" COM3 ",
" COM4 ",
" COM0 ",
"",
"",
"",
"",
0,
0,
0,
quit,
quit,
quit,
quit,
quit,
0,
0,
0,
0,

"",
" Sizes ",
"_______",
" ",
" 128K ",
" 192K ",
" 256K ",
" 320K ",
" 384K ",
" 448K ",
" 512K ",
" 576K ",
" 640K ",
0,
0,
0,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
quit,

"",
" Foregnd ",
"_________",
" ",
" blacK ",
" Blue ",
" Green ",
" Cyan ",
" Red ",
" Magenta ",
" browN ",
" White ",
" Intense ",
0,
0,
0,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
quit,

"",
" Backgnd ",
"_________",
" ",
" blacK ",
" Blue ",
" Green ",
" Cyan ",
" Red ",
" Magenta ",
" browN ",
" White ",
"",
0,
0,
0,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
0,

"",
" Screen ",
"________",
" ",
" Window ",
" Full -",
" Remote ",
"",
"",
"",
"",
"",
"",
0,
0,
0,
quit,
quit,
quit,
0,
0,
0,
0,
0,
0,

"",
" VModes ",
"__________",
" ",
" teXt40 ",
" Text80 ",
" LoRes ",
" cgaBWres ",
" CgaCOres ",
" EgaRes ",
" egaSres ",
" VgaRes ",
" vgaHres ",
0,
0,
0,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
quit,

"",
" Page ",
"______",
" ",
" 0 ",
" 1 ",
" 2 ",
" 3 ",
"",
"",
"",
"",
"",
0,
0,
0,
quit,
quit,
quit,
quit,
0,
0,
0,
0,
0,

"",
" Bauds ",
"_________",
" ",
" 300B ",
" 1200B ",
" 2400B ",
" 4800B ",
" 9600B ",
" 19200I ",
" 38400I ",
" 115200I ",
"",
0,
0,
0,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
quit,
0
};


main(argc,argv)

int argc;
char **argv;

{
register unsigned int i, j;
char chr, *lptr, *aptr;
int tq = 3, curpos;
unsigned int type, envsiz;
long version;
struct OCB *optr;
union ADDRESS addr32, *ptr32;
void vmenu(int, int);
char *strnloci(char *, char *, unsigned int);
int get_screen(void);

version = sys_version();
if ((int)(version >> 16) != 1944) return(SYS_ERROR);

ptr32 = &addr32; /* pointer component union */

currpid = (unsigned int)sys_getpid(); /* get ourselves first */
pptr = sys_getpcb(currpid); /* our process block */
cptr = sys_getccb(pptr->chan); /* stdio channel */
io0ps_stdirp = cptr->irptr; /* dummy extern in sysgate */
rtop = io0ps_stdirp->wintop; /* look into the stdirp */
rbot = io0ps_stdirp->winbot; /* for active window info */
type = sys_getqkey(tq, cptr->uid); /* need object type to get */
optr = sys_getocb(type); /* the object control blk */
fpin = optr->obj_getc; /* input function for chan */
fpwr = optr->obj_write; /* write function for chan */

mptr = (struct MEMINFO *)sys_memreq(currpid, "info");
p386 = mptr->p386; /* get processor type */
hascon = pptr->psl & PSL_CONSOLE;

for (i = 1; i < argc; i++) /* parse all line arguments*/
for (j = 0; chr = tolower(argv[i][j]); j++) {
switch (chr) {
case 'i': /* interactive mode */
fpin = optr->obj_read;
break;
case 'm': /* monochrome mode */
vflag = TRUE;
break;
case '-':
break;
default: /* syntax error */
break;
}
}

get_screen(); /* current colors */
curpos = get_tcur();
/* disable cursor */
sys_chanreq(currpid, "cursor", pptr->chan, EMPTY);
sys_setcolors(attribute = lo_attr);
sys_clrwindow(rtop, rbot);

ptr32->fp.segment = mptr->code - 0x10; /* VMiX PSP */
ptr32->fp.offset = 0x2C; /* VMiX environment */
ptr32->fp.segment = *ptr32->fptr;
--ptr32->fp.segment;
ptr32->fp.offset = 3; /* environment size */
envsiz = *ptr32->fptr << 4;
++ptr32->fp.segment;
ptr32->fp.offset = 0; /* VMiX environment */

filepath[0] = 1;
filepath[1] = EOS;

if (lptr = strnloci(filepath, (char *)ptr32->fptr, envsiz))
if (*(++lptr) == EOS) {
++lptr;
if (aptr = strnloci("vm_boot", lptr, 80)) {
*aptr = EOS;
strcpy(filepath, lptr);
*aptr = 'V';
}
}

if (filepath[0] == '1') filepath[0] = EOS;
pptr->psl &= 0xFFFFFFEFL;
vmenu(N_MAIN, N_SUB);

sys_chanreq(currpid, "pos", pptr->chan, curpos); /* restore pos */
sys_chanreq(currpid, "cursor", pptr->chan, TRUE); /* cursor on */

pptr->psl |= PSL_EXEC;
return(SYS_OK);
}


void vmenu(n_mainopt, n_subopt)

int n_mainopt, n_subopt;

{
register int i, j;
char ch = 0, ltr;
int ext = 0, old_opt = 0;
int startx, cur_x, cur_y;
int found = FALSE, expert = TRUE;
void menu_bar(int, int, int);
void print(int, char *);
int get_screen(void);
int get_key(char *, int *);
int pull_down(struct MENU *, int);

menu_bar(rtop, rbot, n_mainopt);

cur_x = startx = (BYTE)rtop + 2;
cur_y = (BYTE)(rtop >> 8);

while (TRUE) { /* endless loop */
for (i = 0; i < n_mainopt; i++) {
j = 0;
while (ltr = m_menu[0][i].head[j++]) {
if (ch && ch == ltr) {
menu_opt = i;
found = TRUE;
}
}
}
if (ch == CR) expert = FALSE;

ch = 0;

if (old_opt != menu_opt) {
cur_x = startx + old_opt *
(strlen(m_menu[0][old_opt].head) + 3);
sys_setcolors(attribute = win_attr);

if (is_grmode(io0b_vmode)) {
sys_setfont(1);
if (cur_y) {
cur_y = 1 + (cur_y/3) * chratio;
if (currvfnt == 1) ++cur_y;
if (currvfnt == 2)
io0ps_stdirp->winbot = make_int((BYTE)rbot,
(BYTE)((rbot >> 8)/3) * chratio);
}
sys_clrwindow(make_int((BYTE)cur_x, (BYTE)cur_y),
make_int((BYTE)(cur_x - 1 +
strlen(m_menu[0][old_opt].head)),
(BYTE)cur_y));
}

print(make_int((BYTE)cur_x, (BYTE)cur_y),
m_menu[0][old_opt].head);
cur_x = startx + menu_opt *
(strlen(m_menu[0][menu_opt].head) + 3);
sys_setcolors(attribute = hi_attr);
if (is_grmode(io0b_vmode))
sys_clrwindow(make_int((BYTE)cur_x, (BYTE)cur_y),
make_int((BYTE)(cur_x - 1 +
strlen(m_menu[0][menu_opt].head)),
(BYTE)cur_y));
print(make_int((BYTE)cur_x, (BYTE)cur_y),
m_menu[0][menu_opt].head);

old_opt = menu_opt;

if (is_grmode(io0b_vmode)) {
cur_y = (BYTE)(rtop >> 8);
if (currvfnt == 2) io0ps_stdirp->winbot = rbot;
}

sys_setcolors(attribute = lo_attr);
sys_setfont(currvfnt);
}

cur_x = startx + menu_opt *
(strlen(m_menu[0][menu_opt].head) + 3);
sys_chanreq(currpid, "pos", pptr->chan, make_int(cur_x, cur_y));

if (!expert) found = TRUE;

if (found) { /* pull-down options */
pull_opt = 0;
ext = pull_down(m_menu[0], n_subopt);

/* hide cursor */
sys_chanreq(currpid, "cursor", pptr->chan, FALSE);
get_screen(); /* look in the stdirp for */
/* active window changes */
startx = (BYTE)rtop + 2;
cur_x = startx + menu_opt *
(strlen(m_menu[0][menu_opt].head) + 3);
cur_y = (BYTE)(rtop >> 8);

sys_chanreq(currpid, "pos", pptr->chan, make_int(cur_x,
cur_y));
if ((char)ext == BREAK) return;
if ((char)ext == ESC) expert = TRUE;
if ((char)ext == 'K' || (char)ext == 'M') expert = TRUE;
if ((char)ext == 'K') --menu_opt;
if ((char)ext == 'M') ++menu_opt;
ext = ch = 0;
}

if (!found) {
ch = 0;
get_key(&ch, &ext);
}

if (ch == ESC) {
if (rtop) sys_clrwindow(rtop, make_int((BYTE)rbot,
(BYTE)(rtop >> 8)));
return;
}

if ((char)ext == 'K' || (char)ext == 'M') expert = TRUE;
if ((char)ext == 'K') --menu_opt;
if ((char)ext == 'M') ++menu_opt;
if (menu_opt >= n_mainopt) menu_opt = 0;
if (menu_opt < 0) menu_opt = n_mainopt - 1;
if ((char)ext == 'P') expert = FALSE;
ext = 0;
found = FALSE;
}
}


int pull_down(menu, n_subopt)

struct MENU *menu;
int n_subopt;

{
register int i, j;
char ch = 0, ltr;
int type = 1, ext = 0, old_opt = 0;
int tx, ty, startx, starty, width, n_opt, found = FALSE;
int get_key(char *, int *);
int make_window(int, int, int);
int win_save(int);

n_opt = n_subopt;

for (i = 0; i < n_subopt; i++) /* find active options */
if (menu[menu_opt].body[i][0] == EOS) {
n_opt = i;
break;
}

startx = (BYTE)rtop + 2; /* where to draw pull-down box */
starty = (BYTE)(rtop >> 8) + 3;
for (i = 0; i < menu_opt; i++)
startx += strlen(menu[i].head)
? strlen(menu[i].head) + 3 : 0;

for (i = 0, width = 0; i < n_opt; i++) /* find width of window */
if (strlen(menu[menu_opt].body[i]) > width)
width = strlen(menu[menu_opt].body[i]);

/* move window left if */
/* it will spill off right side */

if (startx + width + 1 > (rbot & 0x00FF))
startx = (rbot & 0x00FF) - width - 1;

/* move window up if */
/* it will spill off the bottom */
if (starty + n_opt + 1 > (rbot >> 8))
starty = (io0ps_stdirp->wintop >> 8) + 6;

win_save('s');

if (io0b_vmode == 3) attribute = hi_attr;
else attribute = win_attr;
sys_setcolors(attribute);

tx = startx + 1;
ty = starty;
/* no scroll during make_window */
io0ps_stdirp->tcur[1] = (BYTE)(rbot >> 8);

if (menu != m_menu[0]) type = 2;
make_window(make_int(startx, starty), /* make pulldown */
make_int(startx + width - 1, starty + n_opt - 1), type);

while (menu[menu_opt].fp[pull_opt] == 0) /* skip display only */
old_opt = pull_opt = pull_opt < n_opt ? pull_opt + 1 : 0;

for (i = 0; i < n_opt; i++) {
if (i == pull_opt) attribute = out_attr;
else attribute = hi_attr;
sys_setcolors(attribute);
if (is_grmode(io0b_vmode))
sys_clrwindow(make_int((BYTE)tx, (BYTE)ty),
make_int((BYTE)(tx - 1 +
strlen(menu[menu_opt].body[old_opt])),
(BYTE)ty));
print(make_int(tx, ty++), menu[menu_opt].body[i]);
};
sys_setcolors(attribute = lo_attr);

while (TRUE) {
if (old_opt != pull_opt) {
ty = starty + old_opt;
sys_setcolors(attribute = hi_attr);
if (is_grmode(io0b_vmode))
sys_clrwindow(make_int((BYTE)tx, (BYTE)ty),
make_int((BYTE)(tx - 1 +
strlen(menu[menu_opt].body[old_opt])),
(BYTE)ty));
print(make_int(tx, ty), menu[menu_opt].body[old_opt]);

ty = starty + pull_opt;
if (ty > rbot >> 8) ty = rbot >> 8;
sys_setcolors(attribute = out_attr);
if (is_grmode(io0b_vmode))
sys_clrwindow(make_int((BYTE)tx, (BYTE)ty),
make_int((BYTE)(tx - 1 +
strlen(menu[menu_opt].body[pull_opt])),
(BYTE)ty));
print(make_int(tx, ty), menu[menu_opt].body[pull_opt]);

old_opt = pull_opt;
sys_setcolors(attribute = lo_attr);
}

ty = starty + pull_opt;
if (ty > rbot >> 8) ty = rbot >> 8;
sys_chanreq(currpid, "pos", pptr->chan, make_int(tx, ty));

if (found) {
if (menu[menu_opt].body[pull_opt]
[strlen(menu[menu_opt].body[pull_opt])-1] != '\x10')
win_save('r'); /* remove pulldown */

(*menu[menu_opt].fp[pull_opt])(); /* execute option */

if (menu[menu_opt].body[pull_opt]
[strlen(menu[menu_opt].body[pull_opt])-1] == '\x10')
win_save('r'); /* remove pulldown */

if (menu_opt == 0 && pull_opt == 9) return(BREAK);

return(ESC);
}

get_key(&ch, &ext); /* get a character */
if ((char)ext == 'P') { /* down arrow */
if (++pull_opt >= n_opt) pull_opt = 0;
while (menu[menu_opt].fp[pull_opt] == 0)
pull_opt = pull_opt < n_opt ? pull_opt + 1 : 0;
}
if ((char)ext == 'H') { /* up arrow */
if (--pull_opt < 0) pull_opt = n_opt - 1;
while (menu[menu_opt].fp[pull_opt] == 0)
pull_opt = pull_opt > 0 ? pull_opt - 1 : n_opt - 1;
}
if (ch == CR) found = TRUE;

for (i = 0; i < n_opt; i++) { /* match an option */
j = 0; /* look for a matched UC letter */
while ((ltr = menu[menu_opt].body[i][j++]) &&
menu[menu_opt].fp[i]) {
if (ch && ch == ltr) {
pull_opt = i;
found = TRUE;
i = n_opt;
break;
}
else if (ltr > 0x40 && ltr < 0x5B) break;
}
}

if ((char)ext == 'M' && menu[menu_opt].body[pull_opt]
[strlen(menu[menu_opt].body[pull_opt])-1]
== '\x10') found = TRUE;
else if ((char)ext == 'K'|| (char)ext == 'M') break;

if (ch == ESC) { /* exit if <-, ->, or ESC pressed */
if (menu == m_menu[0]) ext = ESC;
else ext = BREAK;
break;
}
ext = ch = 0;
}

win_save('r');
return(ext);
}


void menu_bar(top, bot, nopt)

int top, bot, nopt;

{
register int i = 0;
char str[4];
int x, y;

sys_setcolors(attribute = win_attr);

x = (BYTE)top + 2;
y = (BYTE)(top >> 8);
str[0] = 0xF0;
str[1] = str[2] = str[3] = EOS;

if (is_grmode(io0b_vmode)) {
sys_setfont(1);
if (y) {
y = 1 + (y/3) * chratio;
if (currvfnt == 1) ++y;
if (currvfnt == 2)
io0ps_stdirp->winbot = make_int((BYTE)bot,
(BYTE)((bot >> 8)/3) * chratio);
}
}

if (y) sys_clrwindow(make_int((BYTE)x - 1, (BYTE)y),
make_int((BYTE)bot, (BYTE)y));
else {
sys_setconwn(attribute = win_attr);
sys_setbwindow("");
sys_setconwn(attribute = conwn);
io0ps_stdirp->wintop = top;
}

for ( ; i < nopt; i++) {
if (i == menu_opt) attribute = hi_attr;
else attribute = win_attr;

sys_setcolors(attribute);
if (is_grmode(io0b_vmode))
sys_clrwindow(make_int((BYTE)x, (BYTE)y),
make_int((BYTE)(x - 1 +
strlen(m_menu[0][i].head) +
3 * (attribute == win_attr)),
(BYTE)y));
print(make_int((BYTE)x, (BYTE)y), m_menu[0][i].head);
x += strlen(m_menu[0][i].head) + 3;
}

sys_setcolors(attribute = hi_attr);
print(make_int((BYTE)top + 1, (BYTE)y), str);
str[0] = 0x1E;
str[1] = 0x1F;
print(make_int((BYTE)x, (BYTE)y), str);

if (is_grmode(io0b_vmode) && currvfnt == 2)
io0ps_stdirp->winbot = bot;

sys_setcolors(attribute = lo_attr);
sys_setfont(currvfnt);
}


int quit(void)

{
return(SYS_OK);
}


int get_dialog(str, pbuf)

char *str;
char **pbuf;

{
sys_clrwindow(rtop + 0x0100, rbot);
make_window(rtop + 0x202, make_int((BYTE)(rbot - 4),
(BYTE)((rtop + 0x500) >> 8)), 1);
sys_chanreq(currpid, "pos", pptr->chan, rtop + 0x403);

return((int)((long)sys_pinput(str, BLANK, 78, pbuf)));

}


int system(void)

{
register int n = 0;
char *buf, request[SYS_SHLBUF];
BYTE sav_attr, new_attr;
int old_menu = menu_opt, old_pull = pull_opt;
int ext, ntop = rtop, nbot = rbot;
int pause = FALSE, wait = FALSE, refresh = FALSE;
unsigned int pid;
struct PCB *nptr;
void menu_bar(int, int, int);
void print(int, char *);
void set_attributes(BYTE, BYTE);
void set_menu(int, int);
int fork(char *);
int get_dialog(char *, char **);
int make_window(int, int, int);
int pull_down(struct MENU *, int);
int service(char *);
int win_save(int);

request[0] = EOS;

switch (menu_opt) {
case 0: /* Advanced */
switch (pull_opt) {
case 0:
case 1:
case 4:
case 8:
case 9:
for ( ; n < SYS_SHLBUF && (request[n] =
tolower(m_menu[0][menu_opt].body[pull_opt][n]));
n++);
break;
case 2:
set_menu(4, 3);
ext = pull_down(m_menu[1], 5);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
sys_clrwindow(rtop + 0x0100, rbot);
sys_chanreq(currpid, "pos", pptr->chan,
rtop + 0x0100);
if (pull_opt == 3) buf = &request[3];
else buf = &request[6];
if (get_dialog(" Command?", &buf)) {
request[0] = 'd';
request[1] = 'o';
request[2] = BLANK;
if (pull_opt == 4) {
request[3] = '-';
request[4] = 'W';
request[5] = BLANK;
}

io0ps_stdirp->wintop = 0x0100;
service(request);
}

menu_opt = old_menu;
pull_opt = old_pull;
sys_clrwindow(rtop, rbot);
menu_bar(rtop, rbot, N_MAIN);
win_save('f');
win_save('s');
break;
case 3:
sys_chanreq(currpid, "pos", pptr->chan,
rtop + 0x0100);
buf = &request[3];
if (get_dialog(" Command?", &buf)) {
request[0] = 'e';
request[1] = 'x';
request[2] = BLANK;
fork(request);
wait = TRUE;
}
rbot = io0ps_stdirp->winbot;
sys_clrwindow(rtop + 0x0100, rbot);
break;
case 5:
set_menu(0, 3);
ext = pull_down(m_menu[1], 8);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
strcpy(request, "rem -c");
switch (pull_opt) {
case 3:
strcat(request, "1");
break;
case 4:
strcat(request, "2");
break;
case 5:
strcat(request, "3");
break;
case 6:
strcat(request, "4");
break;
case 7:
strcat(request, "0");
break;
default:
strcat(request, "0");
break;
}
sys_system(request);
request[0] = EOS;
break;
case 6:
strcpy(request, "exec /rsh");
fork(request);
wait = TRUE;
break;
case 7:
sys_chanreq(currpid, "pos", pptr->chan,
rtop + 0x0100);
buf = &request[6];
if (get_dialog(" Command?", &buf)) {
request[0] = 's';
request[1] = 'p';
request[2] = BLANK;
request[3] = '-';
request[4] = 'c';
request[5] = BLANK;

service(request);
}
break;
}
break;
case 1: /* Memory */
switch (pull_opt) {
case 3:
strcpy(request,
"set sys -m/ass memory/set sys -m");
pause = TRUE;
break;
case 4:
strcpy(request, "deass mem");
break;
case 5:
set_menu(1, mptr->maxlloc >= 0x9600
? 11
: (mptr->maxlloc >> 12) + 1);
ext = pull_down(m_menu[1], 12);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
strcpy(request, "exec -m");
itoa(128 + (pull_opt - 3) * 64,
request + 7, 10);
request[11] = EOS;
sys_system(request);
request[0] = EOS;
break;
case 6:
sys_chanreq(currpid, "pos", pptr->chan,
rtop + 0x0100);
strcpy(request, "set sys -v");
sys_system(request);
request[0] = EOS;
sys_clrwindow(rtop, rbot);
menu_bar(rtop, rbot, N_MAIN);
break;
}
break;
case 2: /* Programs */
switch (pull_opt) {
case 3:
case 4:
case 5:
set_menu(4, 3);
ext = pull_down(m_menu[1], 6);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
strcpy(request, "do ");
if (pull_opt == 4) {
strcat(request, "-W ");
pull_opt = old_pull;
menu_opt = old_menu;
set_menu(5, 4);
ext = pull_down(m_menu[1], 12);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
switch (pull_opt) {
case 3:
if (io0b_vmode != 1)
strcat(request,
"/set vi -m1");
break;
case 4:
if (io0b_vmode != 3)
strcat(request,
"/set vi -m3");
break;
case 5:
if (io0b_vmode != 13)
strcat(request,
"/set vi -m13");
break;
case 6:
if (io0b_vmode != 6)
strcat(request,
"/set vi -m6");
break;
case 7:
if (io0b_vmode != 14)
strcat(request,
"/set vi -m14");
break;
case 8:
if (io0b_vmode != 16 ||
currvfnt != 2)
strcat(request,
"/set vi -m16/set fo -t2");
break;
case 9:
if (io0b_vmode != 16 ||
currvfnt != 1)
strcat(request,
"/set vi -m16/set fo -t1");
break;
case 10:
if (io0b_vmode != 18 ||
currvfnt != 2)
strcat(request,
"/set vi -m18/set fo -t2");
break;
case 11:
if (io0b_vmode != 18 ||
currvfnt != 1)
strcat(request,
"/set vi -m18/set fo -t1");
break;
default:
strcat(request,
"set vi -m3");
break;
}

if (pull_opt < 5) {
pull_opt = old_pull;
menu_opt = old_menu;
set_menu(6, 3 + io0b_activepg);
ext = pull_down(m_menu[1], 7);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
strcat(request, "/set vi -p");
switch (pull_opt) {
case 3:
strcat(request, "0");
break;
case 4:
strcat(request, "1");
break;
case 5:
strcat(request, "2");
break;
case 6:
strcat(request, "3");
break;
default:
strcat(request, "0");
break;
}
}
pull_opt = 4;
}
else refresh = TRUE;

if (pull_opt == 5) {
if (p386 > 2) {
refresh = FALSE;
strcat(request, "-W ");
}
strcat(request, "/exec ");
strcat(request, filepath);
strcat(request, "vt");
}
else if (old_pull == 3)
strcat(request, "/rsh");
else if (old_pull == 4)
strcat(request,
"/exec cls/exec .");
else
if (get_dialog(" Filespec?",
&buf)) {
strcat(request, "/");
strcat(request, buf);
}
if (refresh) {
io0ps_stdirp->wintop = 0x0100;
service(request);
}

menu_opt = old_menu;
pull_opt = old_pull;

sys_clrwindow(rtop, rbot);
menu_bar(rtop, rbot, N_MAIN);
win_save('f');

if (!refresh) {
io0ps_stdirp->wintop = 0x0100;
service(request);
}

get_screen();
menu_opt = old_menu;
pull_opt = old_pull;
break;
case 6:
strcpy(request, "swap");
break;
case 7:
strcpy(request, "chprio");
break;
case 8:
strcpy(request, "kill");
break;
case 9:
io0ps_stdirp->wintop = rtop + 0x100;
strcpy(request, "set vi -W");

sys_system(request);
request[0] = EOS;
io0ps_stdirp->wintop = rtop;
nbot = rbot = io0ps_stdirp->winbot;
sys_clrwindow(rtop, rbot);
menu_bar(rtop, rbot, N_MAIN);
refresh = TRUE;
break;
case 10:
set_menu(0, 3);
ext = pull_down(m_menu[1], 7);
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
strcpy(request, "set baud -c");
n = pull_opt;
menu_opt = 7;
pull_opt = 7;
ext = pull_down(m_menu[1], 11);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
switch (n) {
case 3:
strcat(request, "1 ");
break;
case 4:
strcat(request, "2 ");
break;
case 5:
strcat(request, "3 ");
break;
case 6:
strcat(request, "4 ");
break;
default:
strcat(request, "1 ");
break;
}
if (pull_opt == 3)
strcat(request, " 300");
else if (pull_opt == 10)
strcat(request, " 115");
else itoa((2 << (pull_opt - 4))
* 6, request + 13, 10);
sys_system(request);
request[0] = EOS;
break;
}
break;
case 3: /* Status */
strcpy(request, "exec ");
strcat(request, filepath);

switch (pull_opt) {
case 3:
strcat(request, "ps");
fork(request);
wait = TRUE;
break;
case 4:
strcpy(request, "examine status");
pause = TRUE;
break;
case 5:
strcat(request, "dstat -a");
fork(request);
wait = TRUE;
break;
case 6:
strcat(request, "monitor -r");
fork(request);
wait = TRUE;
break;
case 7:
strcpy(request, "exec set");
fork(request);
wait = TRUE;
break;
case 8:
strcat(request, "monitor -f");
fork(request);
wait = TRUE;
break;
case 9:
strcat(request, "monitor -m");
fork(request);
wait = TRUE;
break;
case 10:
strcat(request, "monitor -p");
fork(request);
wait = TRUE;
break;
case 11:
strcpy(request, "examine mcb");
pause = TRUE;
break;
default:
request[0] = EOS;
break;
}
break;
case 4: /* Options */
switch (pull_opt) {
case 3:
strcpy(request, "set vi -m");
refresh = TRUE;
break;
case 4:
if (is_grmode(io0b_vmode)) break;
new_attr = (conbg & IWHITE) + 3;
set_menu(2, new_attr);
if (pull_opt > 10) pull_opt = 11;
ext = pull_down(m_menu[1], 12);
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') {
rtop = ntop;
break;
}
if (pull_opt > 10)
pull_opt = new_attr > 10 ?
(int)new_attr
: (int)new_attr + 8;
new_attr = (BYTE)pull_opt;
menu_opt = 3;
pull_opt = (int)((conbg & 0xF0) >> 4) + 3;
if (pull_opt > 10) pull_opt = 3;
ext = pull_down(m_menu[1], 11);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
conbg = make_attrib(new_attr - 3,
(BYTE)pull_opt - 3);
sys_setcolors(attribute = conbg);
sys_clrwindow(ntop, nbot);
set_attributes(conbg, conwn);
menu_opt = old_menu;
pull_opt = old_pull;
menu_bar(rtop = ntop, rbot, N_MAIN);
win_save('f');
win_save('s');
break;
case 5:
if (is_grmode(io0b_vmode)) break;
new_attr = (conwn & IWHITE) + 3;
set_menu(2, new_attr);
if (pull_opt > 10) pull_opt = 11;
ext = pull_down(m_menu[1], 12);
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') {
rtop = ntop;
break;
}
if (pull_opt > 10)
pull_opt = new_attr > 10 ?
(int)new_attr
: (int)new_attr + 8;
new_attr = (BYTE)pull_opt;
menu_opt = 3;
pull_opt = (int)((conwn & 0xF0) >> 4) + 3;
if (pull_opt > 10) pull_opt = 3;
ext = pull_down(m_menu[1], 11);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
conwn = make_attrib(new_attr - 3,
(BYTE)pull_opt - 3);
sys_setconwn(conwn);
sys_clrwindow(ntop, nbot);
set_attributes(conbg, conwn);
menu_opt = old_menu;
pull_opt = old_pull;
menu_bar(rtop = ntop, rbot, N_MAIN);
win_save('f');
win_save('s');
break;
case 6:
sys_clrwindow(rtop, rbot);
rtop = io0ps_stdirp->wintop;
sys_chanreq(currpid, "pos", pptr->chan,
rtop);
strcpy(request, "set vi -w");
sys_system(request);
request[0] = EOS;

ntop = io0ps_stdirp->wintop;
nbot = io0ps_stdirp->winbot;

if (!(BYTE)ntop) ntop =
make_int((BYTE)ntop + 1,
(BYTE)(ntop >> 8));
if ((BYTE)(nbot >> 8) == ROW_VMAX) nbot =
make_int((BYTE)nbot,

(BYTE)(nbot >> 8) - 1);
if ((BYTE)nbot > COL_VMAX - 1) nbot =
make_int(COL_VMAX - 1,
(BYTE)(nbot >> 8));
io0ps_stdirp->wintop = ntop - 0x0101;
io0ps_stdirp->winbot = nbot + 0x0101;

sav_attr = out_attr;
if (is_grmode(io0b_vmode))
out_attr = win_attr;
else out_attr = lo_attr;

make_window(ntop, nbot, 0);
out_attr = sav_attr;

sys_setwindow(io0ps_stdirp, rtop = ntop,
rbot = nbot);
*(int *)&win_inst[0].x = get_tcur();
menu_bar(rtop, rbot, N_MAIN);
break;
case 7:
if (is_grmode(io0b_vmode))
refresh = TRUE;
strcpy(request, "set font -t");
break;
case 8:
strcpy(request, "set term -t");
break;
case 9:
case 10:
set_menu(0, old_pull == 9 ? 3 : 7);
ext = pull_down(m_menu[1],
old_pull == 9 ? 7 : 8);
rtop = ntop;
if ((char)ext == BREAK ||
(char)ext == 'K' ||
(char)ext == 'M') break;
if (old_pull == 9)
strcpy(request, "set rem -l");
else strcpy(request, "set rem -c");
switch (pull_opt) {
case 3:
strcat(request, "1");
break;
case 4:
strcat(request, "2");
break;
case 5:
strcat(request, "3");
break;
case 6:
strcat(request, "4");
break;
case 7:
strcat(request, "0");
break;
default:
strcat(request, "1");
break;
}
sys_system(request);
request[0] = EOS;
break;
case 11:
strcpy(request, "set vi -s");
sys_system(request);
request[0] = EOS;
break;
}
break;
}

if (request[0]) {
if (!refresh) win_save('s');

ntop = rtop + 0x0201;
nbot = rbot - 0x0101;

if (io0b_vmode == 3) attribute = hi_attr;
else attribute = win_attr;

sys_setcolors(attribute);
make_window(ntop, nbot, 0);
sys_setcolors(attribute = lo_attr);

io0ps_stdirp->wintop = ntop;
io0ps_stdirp->winbot = nbot;

sys_chanreq(currpid, "pos", pptr->chan, ntop);
sys_chanreq(currpid, "cursor", pptr->chan, TRUE);

#ifdef IBMPC
if ((int)((long)sys_sysreq(currpid, "num")) < 4) {
#endif
if (wait) pid = (int)sys_spawn(request);
else sys_system(request);
#ifdef IBMPC
}
else {
pause = TRUE;
wait = FALSE;
sys_vprintf("VM$ERR_vw: Task Limit Exceeded\r\n");
}
#endif

sys_chanreq(currpid, "cursor", pptr->chan, EMPTY);

if (wait) {
nptr = sys_getpcb(pid); /* new process block */

while (nptr->pstate != PSTATE_FREE)
if ((BYTE)((*fpin)())) break;

if (nptr->pstate == PSTATE_FREE) {
sys_chanreq(pid, "vio", pptr->chan);
print(make_int((BYTE)io0ps_stdirp->wintop,
(BYTE)(io0ps_stdirp->winbot >> 8)),
"Press any key to exit");
while (!(BYTE)((*fpin)())) ;
}
}

if (pause) {
print(make_int((BYTE)io0ps_stdirp->wintop,
(BYTE)(io0ps_stdirp->winbot >> 8)),
"Press any key to exit");
while (!(BYTE)((*fpin)())) ;
}

if (refresh) {
get_screen(); /* current colors */
menu_bar(rtop, rbot, N_MAIN);
}
else {
io0ps_stdirp->wintop = rtop;
io0ps_stdirp->winbot = rbot;
sys_setcolors(attribute = lo_attr);
win_save('r');
}
}

menu_opt = old_menu;
pull_opt = old_pull;

return(SYS_OK);
}


void set_menu(submenu, option)

int submenu, option;

{
register int n = 0;
int startx;

startx = (BYTE)rtop + 2;
for ( ; n < menu_opt; n++)
startx += strlen(m_menu[0][n].head) + 3;
rtop = make_int((BYTE)startx, (BYTE)((rtop >> 8) + pull_opt + 2));
menu_opt = submenu;
pull_opt = option; /* new default option */
}


int service(request)

char *request;

{
int status;

status = sys_system(request);
sys_sysreq(currpid, "delay", 1); /* let service start */

request[0] = EOS;
io0ps_stdirp->wintop = rtop;
if ((BYTE)io0ps_stdirp->winbot > (BYTE)rbot)
io0ps_stdirp->winbot = make_int((BYTE)rbot,
(BYTE)(io0ps_stdirp->winbot >> 8));
rbot = io0ps_stdirp->winbot;

return(status);
}


int fork(request)

char *request;

{
register int n = 0;
char buf[SYS_SHLBUF];
int chan;
struct IRP *packet;

strcpy(buf, request);
if ((packet = (struct IRP *)sys_chanreq(currpid, "assign", cptr->uid,
currpid, cptr->csl)) == NULLPTR)
return(SYS_ERROR);

chan = packet->chan; /* new channel */
packet->wintop = rtop + 0x0201;
packet->winbot = rbot - 0x0101;

itoa(chan, request, 10);
while (request[n]) ++n;
request[n++] = BLANK;
strcpy(request + n, buf);

return(SYS_OK);
}


int win_save(action)

int action; /* 's' = save */
/* 'r' = restore */
/* 'f' = free save block */
{
union ADDRESS addr32, *ptr32;

ptr32 = &addr32;
ptr32->fp.offset = io0ps_stdirp->swappg * io0ui_regenlen;

if (io0b_vmode > 12) ptr32->fp.segment = EGA_SEG;
if (io0b_vmode == 7) ptr32->fp.segment = MDA_SEG;
if (io0b_vmode < 7) ptr32->fp.segment = CGA_SEG;

if (action == 's') { /* save */
if (idx > N_LEVEL - 1) {
idx = N_LEVEL;
return(SYS_ERROR);
} /* save screen and cursor */
sys_blkmov(ptr32->fptr, win_inst[idx].buffer, BYTES_80 >> 1);
*(int *)&win_inst[idx].x = get_tcur();
++idx;
}

if (action == 'r' || action == 'f') { /* restore or free */
if (idx < 1) {
idx = 0;
return(SYS_ERROR);
}
--idx;

if (action == 'f') return(SYS_OK);

if (!hascon || is_grmode(io0b_vmode)) {
sys_clrwindow(rtop + 0x0100, rbot);
return(SYS_OK);
}

sys_blkmov(win_inst[idx].buffer, ptr32->fptr, BYTES_80 >> 1);
sys_chanreq(currpid, "pos", pptr->chan, *(int *)&win_inst[idx].x);
}

return(SYS_OK);
}


void set_attributes(newbg, newwn)

BYTE newbg, newwn;

{
if (is_grmode(io0b_vmode)) {
out_attr = newwn;
hi_attr = newbg;
win_attr = 0;
lo_attr = newbg;
switch (currvfnt) {
case 0:
chratio = 4; /* io0b_chrysiz / 2 */
break;
case 1:
chratio = 3;
break;
case 2:
chratio = 7;
break;
default:
chratio = 4;
break;
}
}
else if (vflag || io0b_vmode == 7 || io0b_vmode == 15) {
out_attr = WHITE;
hi_attr = make_attrib(BLACK, WHITE);
win_attr = REVERSE | GREY;
lo_attr = IWHITE;
}
else {
if ((newwn & IWHITE) == (conbg & IWHITE)) {
out_attr = make_attrib(conbg & IWHITE, newwn >> 4);
hi_attr = make_attrib(YELLOW, newwn >> 4);
}
else {
out_attr = make_attrib(YELLOW, newwn >> 4);
hi_attr = make_attrib(conbg & IWHITE, newwn >> 4);
}
win_attr = make_attrib((newwn & IWHITE)
? (newwn & IWHITE)
: GREY, newwn >> 4);
lo_attr = newbg;
}
}


void box(top, bottom, type) /* type 0 = pull-down box */
/* type 1 = message box */
int top, bottom, type;

{
register int i;
char x0, x1, x2, x3, x4;
char str[2], string[COL_VMAX + 2];
int x, y, width, height;
void print(int, char *);

str[1] = EOS;

if (type || !hascon || is_grmode(io0b_vmode)) {
x0 = x2 = BLANK;
if (is_grmode(io0b_vmode)) x1 = x3 = x4 = str[0] = BLANK;
else {
x3 = x4 = str[0] = '|';
x1 = '_';
}
}
else {
x0 = '\x0DA';
x1 = '\x0C4';
x2 = '\x0BF';
x3 = '\x0C0';
x4 = '\x0D9';
str[0] = '\x0B3';
}

x = top & 0x00FF;
y = top >> 8;
++io0ps_stdirp->winbot;

width = (bottom & 0x00FF) - x + 2;
height = (bottom >> 8) - y + 2;

--x; /* offset to window border */
--y;

string[0] = x0; /* left corner */
for (i = 1; i < width; i++) string[i] = x1;
string[i++] = x2; /* right corner */
string[i] = EOS;
print(make_int(x, y++), string);

for (i = 1; i < height; i++) {
print(make_int(x, y), str);
print(make_int(x + width, y++), str);
}

string[0] = x3;
for (i = 1; i < width; i++) string[i] = x1;
string[i++] = x4;
string[i] = EOS;
print(make_int(x, y), string);
--io0ps_stdirp->winbot;
}


int make_window(top, bottom, type) /* draws and clears a box */
/* around window */
int top, bottom, type;

{
BYTE savattr;
void box(int, int, int);

bottom = make_int((BYTE)bottom, bottom >> 8 > (rbot >> 8)
? (BYTE)(rbot >> 8)
: (BYTE)(bottom >> 8));
savattr = attribute;

if (type) {
set_tcur(top - 0x0101);

if (type < 2) sys_setcolors(attribute = lo_attr);
else sys_setcolors(attribute = out_attr);

sys_chanreq(currpid, "window", pptr->chan,
(bottom >> 8) - (top >> 8) + 3,
(bottom & 0x00FF) - (top & 0x00FF) + 3);
sys_setcolors(attribute = hi_attr);
top += 0x0001;
bottom += 0x0001;
type = 0;
}
else {
sys_setcolors(attribute = out_attr);
sys_clrwindow(top - 0x0101, bottom + 0x0101); /* clear frame*/
sys_setcolors(attribute = lo_attr);
sys_clrwindow(top, bottom); /* clear panel*/
}

sys_setcolors(attribute = savattr);
box(top, bottom, type); /* box panel */

return(SYS_OK);
}


void print(x, str)

int x;
char *str;

{
x = make_int((BYTE)x, x >> 8 > io0ps_stdirp->winbot >> 8
? (BYTE)(io0ps_stdirp->winbot >> 8)
: (BYTE)(x >> 8));
sys_chanreq(currpid, "pos", pptr->chan, x);
(*fpwr)(str);
}


int get_key(ch, ext)

char *ch;
int *ext;

{
void menu_bar(int, int, int);

*ch = (BYTE)(*ext = (*fpin)());

if (!(*ext & 0x00FF))
switch (*ext = *ext >> 8) {
case 'H': break; /* up */
case 'P': break; /* down */
case 'K': break; /* left */
case 'M': break; /* right */
case 'G': /* home */
menu_bar(rtop, rbot, N_MAIN);
*ext = 0;
break;
default:
*ext = 0;
break;
}
*ch = toupper(*ch);

return(SYS_OK);
}


int get_screen(void)

{
int colors;
void set_attributes(BYTE, BYTE);

colors = sys_getcolors(); /* current colors */
conbg = is_grmode(io0b_vmode) ? 0x55 : (BYTE)colors;
conwn = (BYTE)(colors >> 8);
currvfnt = (BYTE)sys_getfont(); /* current graphics font */
set_attributes(conbg, conwn);

io0ps_stdirp->wintop = rtop; /* look into the stdirp */
rbot = io0ps_stdirp->winbot; /* for active window info */

return(colors);
}


/*----------------------------------------------------------------------------
| NAME: itoa -- converts integer to ASCII hex/dec
|
| SYNOPSIS:
| itoa(num, cp, base);
|
| int num; integer (+ - 32767)
| char *cp; pointer to numeric string
| 0x hexadecimal
| int base; conversion radix
|
| FUNCTION:
|
| RETURNS:
| = (char *)str
|
|---------------------------------------------------------------------------*/

char *itoa(num, cp, base)

int num; /* number to convert */
char *cp; /* the storage string */
int base; /* the conversion radix */

{
register int n; /* number of characters in result */
char temp[18], *tcp;
int sign = 0;
unsigned int unum; /* unsigned value */

*(tcp = temp + 17) = 0;

if (base == 10 && num < 0) { /* needs signed conversion */
sign = 1;
do {*--tcp = digits[-(num % base)]; } while((num /= -base));
}
else {
unum=num;
do {*--tcp = digits[unum % base]; } while(unum /= base);
}

if (base == 16) {
*--tcp = 'x';
*--tcp = '0';
}
else if (sign) *--tcp = '-';

n = (int)(temp + 17 - tcp);
strncpy(cp, tcp, n);
*(cp + n) = 0;

return(cp);
}


/*----------------------------------------------------------------------------
| NAME: strnloci -- locates string1 in string2 first n characters
|
| SYNOPSIS:
| strnloci(s, t, n));
|
| char *s; pointer to search string1
| char *t; pointer to target string2
| unsigned int n; number of characters to search
|
| FUNCTION:
| String2 can be multiple ASCIIZ strings.
| strnloci is case insensitive.
|
| RETURNS:
| = (char *)loc
| or = NULLPTR
|
|---------------------------------------------------------------------------*/

char *strnloci(s, t, n)

char *s, *t;
unsigned int n;

{
char *c = s;
char *p = NULLPTR;

while (n-- && *c) {
if (tolower(*c) == tolower(*t)) {
++c;
if (!p) p = t;
}
else {
p = NULLPTR;
c = s;
}
++t;
}

if (*c) p = NULLPTR;

return(p);
}



  3 Responses to “Category : Alternate Operating Systems - Quarterdeck DesqView, CP/M, etc
Archive   : VMIXUTL.ZIP
Filename : VW.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/