Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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