Category : Files from Magazines
Archive   : CUJ9204.ZIP
Filename : 1004046A

 
Output of file : 1004046A contained in archive : CUJ9204.ZIP
/*
menu = controls cursor movement and menu display and selection -
returns the number of the selected menu item.

values: a string consisting of two digits showing
the number of menu choices, followed by
four digits for each choice, the first
two showing the starting column of the
menu item and the second two its length.

menu_first_line: the first line of instructions in the
menu mode.

menu_second_line: the second line in the menu mode. It con-
tains the menu choices.

screen_first_line: the first line of instructions in the
screen mode.

screen_second_line: the second line of instructions in the
screen mode.

menu_type: 0: Start with Menu Mode.
Alphanumeric characters are ignored
when entered in screen mode.
1: Start with Menu Mode.
Alphanumeric characters are displayed
when entered in screen mode
2: Start with Screen Mode.
Alphanumeric characters are ignored
when entered in screen mode.
3: Start with Screen Mode.
Alphanumeric characters are displayed
when entered in screen mode.

screen_color: color for screen mode.
menu_color: color for menu display.

highlight_color: color of selected menu item

select_no: number of menu items using selection

escape_char: number of the key selected for escape
from the screen display.

map: bit map of permitted cursor locations.
The cursor will go to permitted locations
only and no others.
*/

int menu(char values[],char menu_first_line[],char menu_second_line[],
char screen_first_line[],char screen_second_line[],int menu_type,
int screen_color,int menu_color,int highlight_color, int select_no,
int escape_char, int first_line_loc, char map[25][10])
{
union REGS reg;
int i,choices,indx,start,length,menu_second_line_length;
int interim,remainder,temp;
char spaces[80],prev_char;

for (i=0; i<76; i++)
spaces[i] = ' ';
spaces[76] = '\0';
menu_second_line_length = strlen(menu_second_line);
gotoxy(2,first_line_loc);
choice = 1;
if (menu_type <= 1)
{
color_printf("%s",menu_color,menu_first_line);
gotoxy(2,first_line_loc+1);
length = values[4] - '0';
length = 10 * length + values[5] - '0';
for (indx = 0; indx < menu_second_line_length; indx++)
if (indx < length)
putcolorchar(menu_second_line[indx],
highlight_color);
else
putcolorchar(menu_second_line[indx],
menu_color);
}
else
{
color_printf(screen_first_line,menu_color);
gotoxy(2,first_line_loc+1);
color_printf(screen_second_line,menu_color);
}
choices = 10 * (values[0] - '0') + values[1] -'0';
gotoxy(column,row);
for(;;)
{
key_id = getch();
if (key_id == 0)
key_id = getch()+256;
if (menu_type <= 1)
{
switch(key_id)
{
case 13:
if(choice > select_no)
goto ExitPoint;
change_line_color(47);
gotoxy(2,23);
color_printf("%s",screen_color,spaces);
gotoxy(2,23);
color_printf("%s",menu_color,
screen_first_line);
gotoxy(2,24);
color_printf("%s",screen_color,spaces);
gotoxy(2,24);
color_printf("%s",menu_color,
screen_second_line);
gotoxy(column,row);
menu_type +=2;
break;
case 333: /*Right Arrow*/
choice = choice + 2;
case 331: /*Left Arrowb*/
--choice;
if (choice < 1)
choice = choices;
if (choice > choices)
choice = 1;
start = 10 * (values[(choice-1)*4+2] - '0')
+values[(choice-1)*4+3] - '0';
length = 10 * (values[(choice-1)*4+4] - '0')
+values[(choice-1)*4+5] - '0';
gotoxy(2,24);
for (indx = 0;indx < menu_second_line_length;
indx++)
{
if ((indx >= start) && (indx < start
+ length))
putcolorchar
(menu_second_line
[indx],
highlight_color);
else
putcolorchar
(menu_second_line
[indx],
menu_color);
}
gotoxy(column,row);
break;
default:
if ((key_id >= 0x41) && (key_id <= 0x7A))
{
temp = toupper(key_id);
for (indx=0; indx<=choices; indx++)
{
start = 10 * (values[
(indx-1)*4+2] -
'0')+values[(indx
-1)*4+3] - '0';
if (temp == menu_second_line
[start])
{
choice = indx;
if(choice >
select_no)
goto ExitPoint;
change_line_color
(47);
gotoxy(2,23);
color_printf("%s",
screen_color,spaces);
gotoxy(2,23);
color_printf("%s",
menu_color,
screen_first_line);
gotoxy(2,24);
color_printf("%s",
screen_color,spaces);
gotoxy(2,24);
color_printf("%s",
menu_color,
screen_second_line);
gotoxy(column,row);
menu_type += 2;
}
}
}
}
}
else
{
if (key_id == escape_char)
goto ExitPoint;
switch(key_id)
{
case 8: /*Backspace*/
case 331: /*Left Arrow*/
if ((menu_type == 0) ||
(menu_type == 2))
change_line_color
(screen_color);
do
{
column--;
if (column < 0)
{
column = 79;
row --;
if (row < 0)
row = 24;
}
indx = column/8;
remainder = column - indx*8;
interim = map[row][indx] &
(0x01 << remainder);
}
while (interim == 0x00);
gotoxy(column,row);
if ((menu_type == 0) ||
(menu_type == 2))
change_line_color
(highlight_color);
break;

case 333: /*Right Arrow*/
if ((menu_type == 0) ||
(menu_type == 2))
change_line_color
(screen_color);
do
{
column++;
if (column > 79)
{
column = 0;
row ++;
if (row > 24)
row = 0;
}
indx = column/8;
remainder = column - indx*8;
interim = map[row][indx] &
(0x01 << remainder);
}
while (interim == 0x00);
gotoxy(column,row);
if ((menu_type == 0) ||
(menu_type == 2))
change_line_color
(highlight_color);
break;
case 13:
column = 0;
case 336: /*Down Arrow*/
if ((menu_type == 0) ||
(menu_type == 2))
change_line_color
(screen_color);
row++;
if (row > 24)
row = 0;
indx = column/8;
remainder = column - indx * 8;
interim = map[row][indx] & (0x01 <<
remainder);
if (interim != 0x00)
{
gotoxy(column,row);
if ((menu_type == 0) ||
(menu_type == 2))
change_line_color
(highlight_color);
break;
}
column = 0;
do
{
indx = column/8;
remainder = column - indx*8;
interim = map[row][indx] &
(0x01 << remainder);
if (interim != 0x00)
{
gotoxy(column,row);
if ((menu_type == 0)
|| (menu_type == 2))
change_line_color
(highlight_color);
break;
}
column++;
if (column > 79)
{
column = 0;
row ++;
if (row > 24)
row = 0;
}
}
while (interim == 0x00);
break;
case 328: /*Up Arrow*/
if ((menu_type == 0) ||
(menu_type == 2))
change_line_color
(screen_color);
row--;
if (row < 0)
row = 24;
indx = column/8;
remainder = column - indx * 8;
interim = map[row][indx] & (0x01
<< remainder);
if (interim != 0x00)
{
gotoxy(column,row);
if ((menu_type == 0) ||
(menu_type == 2))
change_line_color
(highlight_color);
break;
}
column = 79;
do
{
indx = column/8;
remainder = column - indx*8;
interim = map[row][indx] &
(0x01 << remainder);
if (interim != 0x00)
{
gotoxy(column,row);
if ((menu_type == 0)
|| (menu_type == 2))
change_line_color
(highlight_color);
break;
}
column--;
if (column < 0)
{
column = 79;
row --;
if (row < 0)
row = 24;
}
}
while (interim == 0x00);
break;
default:
if ((menu_type == 1) ||
(menu_type == 3))
{
putcolorchar(key_id,
screen_color);
do
{
column++;
if (column > 79)
{
column = 0;
row ++;
if (row > 24)
row =
0;
}
indx = column/8;
remainder = column -
indx * 8;
interim = map[row]
[indx] & (0x01
<< remainder);
}
while (interim == 0x00);
gotoxy(column,row);
}
}
}
}
ExitPoint:
return choice;
}

/*
change_line_color = changes the color of a line up to a double space
*/

void change_line_color(int color)
{
union REGS rin;
char prev_char;

prev_char = 's';
for( ; ; )
{
rin.h.ah = 3;
rin.h.bh = 0;
int86(0x10,&rin,&rin);
ch = read_char_from_screen();
if((ch == ' ') && (prev_char == ' '))
break;
prev_char = ch;
gotoxy(rin.h.dl,rin.h.dh);
putcolorchar(ch,color);
}
gotoxy(column,row);
}

/*
clearscreen = clears the screen and displays selected color background
*/

void clearscreen(int color)
{
int indx;
union REGS reg;

gotoxy(0,0);
reg.h.ah = 9;
reg.h.al = 0x20;
reg.h.bh = 0;
reg.h.bl = color;
reg.x.cx = 2000;
int86(0x10,®,®);
}

/*
color_printf = printf with selected foreground and background colors
*/

void color_printf (char *msg,int color,...)
{
union REGS reg;
char ch, string[2000];
int i = 0;
va_list (ap);

va_start (ap,msg);
vsprintf(string,msg,ap); /*do printf to string*/
va_end(ap);
while ((ch=string[i++]) != '\0') /*get chars from string till end*/
{
if (ch == 0x0A) /*is character a line feed*/
{
reg.h.ah = 3;
int86(0x10,®,®);
/*get cursor position*/
reg.h.dl = 0;
reg.h.dh++;
/*cursor value to beginning of next line*/
reg.h.ah = 2;
int86(0x10,®,®);
/*set new cursor position*/
}
else
{
reg.h.ah = 9;
reg.h.al = ch;
reg.x.bx = color;
reg.x.cx = 1;
int86(0x10,®,®);
/*send a color character to display*/
reg.h.ah = 3;
int86(0x10,®,®);
/*get cursor position in D reg*/
reg.x.dx++;
reg.h.ah = 2;
/*increment cursor position value*/
int86(0x10,®,®);
/*set cursor to new position*/
}
}
}


/*
gotoxy = moves cursor to selected column and row
*/

void gotoxy(int col, int row)
{
union REGS reg;
reg.h.ah = 2;
reg.h.bh = 0;
reg.x.dx = (row << 8) +col;
int86(0X10,®, ®);
}

/*
putcolorchar = displays a character with selected color foreground
and background
*/

void putcolorchar(char character, int color)
{
union REGS reg;
reg.h.ah = 3;
reg.h.bh = 0;
int86(0x10,®,®);
reg.h.ah = 9;
reg.h.al = character;
reg.h.bl = color;
reg.x.cx = 1;
int86(0x10,®,®);
reg.h.ah =2;
reg.h.dl = reg.h.dl+1;
int86(0x10,®,®);
}

/*
read_char_from_screen = reads a character from the screen into 'ch'
*/

char read_char_from_screen()
{
char ch;
union REGS reg;

reg.h.ah = 3;
reg.h.bh = 0;
int86(0x10,®,®);
reg.h.ah = 8;
int86(0x10,®,®);
ch = reg.h.al;
attr = reg.h.ah;
reg.h.ah =2;
reg.h.dl = reg.h.dl+1;
int86(0x10,®,®);
return ch;
}

/*
set_cursor = sets up array of permissible cursor positions
*/

void set_cursor()
{
int i,j,indx,remainder,key_value;
char interim,map[25][10];

FILE *f1;
f1 = fopen("matrix.c","w");

for(i=0;i<=24;i++)
{
for(j=0;j<=9;j++)
{
map[i][j]=0x00;
}
}
row=0;
column = 0;
gotoxy(column,row);
while ((key_value = getch()) != 13)
{
if (key_value == 0)
key_value = getch()+128;
switch(key_value)
{
case 8: /*Backspace*/
case 203: /*Left Arrow*/
--column;
break;
case 205: /*Right Arrow*/
++column;
break;
case 208: /*Down Arrow*/
++row;
break;
case 200: /*Up Arrow*/
--row;
break;
default:
putch(key_value);
column++;
}
if (column > 79)
{
column = 0;
row++;
}
if (column < 0)
{
column = 0;
row--;
}
if (row < 0)
row = 0;
gotoxy(column,row);
}
row=0;
column = 0;
while (row*column < 1896)
{
gotoxy(column,row);
ch = read_char_from_screen();
if ((ch == 'x') || (ch == 'X'))
{
indx = column/8;
remainder = column - indx * 8;
interim = 0x01;
interim = interim << remainder;
map[row][indx] = map[row][indx] | interim;
}
column++;
if (column > 79)
{
column = 0;
row++;
}
gotoxy(column,row);
}

clearscreen(30);
fputc('{',f1);
gotoxy(0,0);
for (i=0;i<=24;i++)
{
for (j=0;j<=9;j++)
{
fprintf(f1,"0x%x",map[i][j]);
if ((i != 24) || (j != 9))
fputc(',',f1);
}
fprintf(f1,"\n");
}
fputc('}',f1);
fclose(f1);
}


  3 Responses to “Category : Files from Magazines
Archive   : CUJ9204.ZIP
Filename : 1004046A

  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/