-
Notifications
You must be signed in to change notification settings - Fork 96
/
MENU.BAK
173 lines (155 loc) · 2.89 KB
/
MENU.BAK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <stdio.h>
#include <conio.h>
#include <mem.h>
#include <dos.h>
#include "main.h"
item_t *current;
menu_t *currentmenu;
int curitem; // current item #
char inv_attrib; // inversion attribute
char buffer[160]; // save the entire screen line!
short menukey; // globally set after GetMenuInput()
//
// Make a sound!
//
void Sound(int freq, int dly)
{
sound(freq);
delay(dly);
nosound();
}
//
// Draw a dot if "value" is > 0 at item->x - 3
//
void SetMark(item_t *item,int value)
{
char far *screen;
screen = MK_FP(0xb800,item->y*160 + (item->x-3)*2);
*screen = ' ';
if (value)
*screen = 7;
}
//
// Invert the menu item
//
void Invert(item_t *item)
{
char far *screen;
int i;
movedata(0xb800,item->y*160,FP_SEG(&buffer),FP_OFF(&buffer),160);
screen = MK_FP(0xb800,item->y*160 + item->x*2);
for (i = 0; i < item->w; i++)
{
*(screen+1) = inv_attrib;
screen += 2;
}
}
//
// Restore the screen line (uninvert)
//
void UnInvert(item_t *item)
{
movedata(FP_SEG(&buffer),FP_OFF(&buffer),0xb800,item->y*160,160);
}
//
// Set "current" to first menu item
//
void SetupMenu(menu_t *menu)
{
currentmenu = menu;
current = menu->items;
current += menu->startitem;
curitem = menu->startitem;
inv_attrib = menu->invert;
Invert(current);
}
//
// Get menu input for current menu
// Exit: -1 = ESC was pressed, xx = item id
//
int GetMenuInput(void)
{
char c;
while(1)
{
c = getch();
// gotoxy(1,2);
// printf("char:%x ",c);
switch(c)
{
case 0x48: // UP
if (!curitem)
break;
UnInvert(current);
if (curitem->up)
{
curitem = curitem->up;
current = currentmenu->items + curitem;
}
else
{
curitem--;
current--;
}
Invert(current);
Sound(50,10);
break;
case 0x50: // DOWN
if (curitem == currentmenu->maxitems - 1)
break;
UnInvert(current);
if (curitem->down)
{
curitem = curitem->down;
current = currentmenu->items + curitem;
}
else
{
curitem++;
current++;
}
Invert(current);
Sound(50,10);
break;
case 0x4b: // LEFT
if (current->left != -1)
{
UnInvert(current);
curitem = current->left;
current = currentmenu->items+curitem;
Invert(current);
Sound(50,10);
}
break;
case 0x4d: // RIGHT
if (current->right != -1)
{
UnInvert(current);
curitem = current->right;
current = currentmenu->items+curitem;
Invert(current);
Sound(50,10);
}
break;
case 0x44: // F10
case 0x3b: // F1
case 0x3c: // F2
UnInvert(current);
menukey = c;
currentmenu->startitem = curitem;
Sound(50,10);
return current->id;
case 0x0d: // ENTER
UnInvert(current);
menukey = c;
currentmenu->startitem = curitem;
Sound(2000,10);
return current->id;
case 0x1b: // ESC
UnInvert(current);
menukey = c;
Sound(3000,10);
return -1;
}
}
}