1 | ; File name : BootMenu.asm |
---|
2 | ; Project name : IDE BIOS |
---|
3 | ; Created date : 25.3.2010 |
---|
4 | ; Last update : 14.1.2011 |
---|
5 | ; Author : Tomi Tilli, |
---|
6 | ; : Krister Nordvall (optimizations) |
---|
7 | ; Description : Displays Boot Menu. |
---|
8 | |
---|
9 | ; Section containing code |
---|
10 | SECTION .text |
---|
11 | |
---|
12 | ;-------------------------------------------------------------------- |
---|
13 | ; Displays Boot Menu and returns Drive or Function number. |
---|
14 | ; |
---|
15 | ; BootMenu_DisplayAndReturnSelection |
---|
16 | ; Parameters: |
---|
17 | ; DS: RAMVARS segment |
---|
18 | ; Returns: |
---|
19 | ; DX: Untranslated drive number to be used for booting (if CF cleared) |
---|
20 | ; Function number (if CF set) |
---|
21 | ; CF: Cleared if drive selected |
---|
22 | ; Set if function selected |
---|
23 | ; Corrupts registers: |
---|
24 | ; All General Purpose Registers |
---|
25 | ;-------------------------------------------------------------------- |
---|
26 | ALIGN JUMP_ALIGN |
---|
27 | BootMenu_DisplayAndReturnSelection: |
---|
28 | call DriveXlate_Reset |
---|
29 | call BootMenuPrint_TheBottomOfScreen |
---|
30 | call BootMenu_GetMenuitemCount |
---|
31 | mov di, BootMenuEvent_Handler |
---|
32 | call BootMenu_Enter ; Get selected menuitem index to CX |
---|
33 | call BootMenuPrint_ClearScreen |
---|
34 | test cx, cx ; -1 if nothing selected (ESC pressed) |
---|
35 | js SHORT BootMenu_DisplayAndReturnSelection |
---|
36 | call BootMenu_CheckAndConvertHotkeyToMenuitem |
---|
37 | jc SHORT .SetDriveTranslationForHotkey |
---|
38 | jmp BootMenu_ConvertMenuitemToDriveOrFunction |
---|
39 | ALIGN JUMP_ALIGN |
---|
40 | .SetDriveTranslationForHotkey: |
---|
41 | call BootMenu_ConvertMenuitemToDriveOrFunction |
---|
42 | call DriveXlate_SetDriveToSwap |
---|
43 | clc |
---|
44 | ret |
---|
45 | |
---|
46 | |
---|
47 | ;-------------------------------------------------------------------- |
---|
48 | ; Returns number of menuitems in Boot Menu. |
---|
49 | ; |
---|
50 | ; BootMenu_GetMenuitemCount |
---|
51 | ; Parameters: |
---|
52 | ; DS: RAMVARS segment |
---|
53 | ; Returns: |
---|
54 | ; CX: Number of boot menu items |
---|
55 | ; Corrupts registers: |
---|
56 | ; AX |
---|
57 | ;-------------------------------------------------------------------- |
---|
58 | ALIGN JUMP_ALIGN |
---|
59 | BootMenu_GetMenuitemCount: |
---|
60 | call RamVars_GetHardDiskCountFromBDAtoCX |
---|
61 | xchg ax, cx |
---|
62 | call FloppyDrive_GetCount |
---|
63 | add ax, cx |
---|
64 | call BootMenu_GetMenuFunctionCount |
---|
65 | add cx, ax |
---|
66 | ret |
---|
67 | |
---|
68 | ;-------------------------------------------------------------------- |
---|
69 | ; Returns number of functions displayed in Boot Menu. |
---|
70 | ; |
---|
71 | ; BootMenu_GetMenuFunctionCount |
---|
72 | ; Parameters: |
---|
73 | ; Nothing |
---|
74 | ; Returns: |
---|
75 | ; CX: Number of boot menu functions |
---|
76 | ; Corrupts registers: |
---|
77 | ; Nothing |
---|
78 | ;-------------------------------------------------------------------- |
---|
79 | ALIGN JUMP_ALIGN |
---|
80 | BootMenu_GetMenuFunctionCount: |
---|
81 | xor cx, cx |
---|
82 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_ROMBOOT |
---|
83 | jz SHORT .DontIncludeRomBoot |
---|
84 | inc cx |
---|
85 | ALIGN JUMP_ALIGN |
---|
86 | .DontIncludeRomBoot: |
---|
87 | ret |
---|
88 | |
---|
89 | |
---|
90 | ;-------------------------------------------------------------------- |
---|
91 | ; Enters Boot Menu or submenu. |
---|
92 | ; |
---|
93 | ; BootMenu_Enter |
---|
94 | ; Parameters: |
---|
95 | ; CX: Number of menuitems in menu |
---|
96 | ; DS:SI: User specific far pointer |
---|
97 | ; CS:DI: Pointer to menu event handler function |
---|
98 | ; Returns: |
---|
99 | ; CX: Index of last pointed Menuitem (not necessary selected with ENTER) |
---|
100 | ; FFFFh if cancelled with ESC |
---|
101 | ; Corrupts registers: |
---|
102 | ; AX, BX, DX |
---|
103 | ;-------------------------------------------------------------------- |
---|
104 | ALIGN JUMP_ALIGN |
---|
105 | BootMenu_Enter: |
---|
106 | call BootMenu_GetSelectionTimeout |
---|
107 | call BootMenu_GetSize |
---|
108 | MIN_U ah, [cs:ROMVARS.bBootMnuH] ; Limit to max height |
---|
109 | jmp Menu_Enter |
---|
110 | |
---|
111 | ;-------------------------------------------------------------------- |
---|
112 | ; Returns Boot Menu selection timeout in milliseconds. |
---|
113 | ; |
---|
114 | ; BootMenu_GetSelectionTimeout |
---|
115 | ; Parameters: |
---|
116 | ; Nothing |
---|
117 | ; Returns: |
---|
118 | ; DX: Selection timeout in millisecs |
---|
119 | ; Corrupts registers: |
---|
120 | ; AX |
---|
121 | ;-------------------------------------------------------------------- |
---|
122 | ALIGN JUMP_ALIGN |
---|
123 | BootMenu_GetSelectionTimeout: |
---|
124 | mov ax, 1000 ; Seconds to milliseconds |
---|
125 | eMOVZX dx, BYTE [cs:ROMVARS.bBootDelay] |
---|
126 | mul dx ; AX = seconds * milliseconds_per_second |
---|
127 | xchg ax, dx ; DX = Timeout in millisecs |
---|
128 | ret |
---|
129 | |
---|
130 | ;-------------------------------------------------------------------- |
---|
131 | ; Returns Boot Menu size. |
---|
132 | ; |
---|
133 | ; BootMenu_GetSize |
---|
134 | ; Parameters: |
---|
135 | ; Nothing |
---|
136 | ; Returns: |
---|
137 | ; AL: Menu width with borders included (characters) |
---|
138 | ; AH: Menu height with borders included (characters) |
---|
139 | ; BL: Title line count |
---|
140 | ; BH: Info line count |
---|
141 | ; Corrupts registers: |
---|
142 | ; Nothing |
---|
143 | ;-------------------------------------------------------------------- |
---|
144 | ALIGN JUMP_ALIGN |
---|
145 | BootMenu_GetSize: |
---|
146 | mov al, MENU_WIDTH_IN_CHARS |
---|
147 | mov ah, cl ; Copy menuitem count to AH |
---|
148 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_DRVNFO |
---|
149 | jz SHORT .GetHeightWithoutInfoArea |
---|
150 | ;.GetHeightWithInfoArea: |
---|
151 | add ah, MENU_HEIGHT_IN_CHARS_WITH_INFO |
---|
152 | mov bx, (MENU_INFO_LINE_CNT<<8) | MENU_TITLE_LINE_CNT |
---|
153 | ret |
---|
154 | ALIGN JUMP_ALIGN |
---|
155 | .GetHeightWithoutInfoArea: |
---|
156 | add ah, MENU_HEIGHT_IN_CHARS_WITHOUT_INFO |
---|
157 | mov bx, MENU_TITLE_LINE_CNT |
---|
158 | ret |
---|
159 | |
---|
160 | |
---|
161 | ;-------------------------------------------------------------------- |
---|
162 | ; Checks if hotkey has been pressed on Boot Menu. |
---|
163 | ; If it has been, it will be converted to menuitem index. |
---|
164 | ; |
---|
165 | ; BootMenu_CheckAndConvertHotkeyToMenuitem |
---|
166 | ; Parameters: |
---|
167 | ; CX: Menuitem index (if no hotkey) |
---|
168 | ; Returns: |
---|
169 | ; CX: Menuitem index |
---|
170 | ; CF: Set if hotkey has been pressed |
---|
171 | ; Cleared if no hotkey selection |
---|
172 | ; Corrupts registers: |
---|
173 | ; AX |
---|
174 | ;-------------------------------------------------------------------- |
---|
175 | ALIGN JUMP_ALIGN |
---|
176 | BootMenu_CheckAndConvertHotkeyToMenuitem: |
---|
177 | push es |
---|
178 | LOAD_BDA_SEGMENT_TO es, ax ; Zero AX |
---|
179 | xchg al, [es:BOOTVARS.bMenuHotkey] ; Load and clear hotkey |
---|
180 | test al, al ; No hotkey? (clears CF) |
---|
181 | jz SHORT .Return |
---|
182 | call BootMenu_ConvertHotkeyToMenuitem |
---|
183 | stc |
---|
184 | ALIGN JUMP_ALIGN |
---|
185 | .Return: |
---|
186 | pop es |
---|
187 | ret |
---|
188 | |
---|
189 | ;-------------------------------------------------------------------- |
---|
190 | ; Converts any hotkey to Boot Menu menuitem index. |
---|
191 | ; |
---|
192 | ; BootMenu_ConvertHotkeyToMenuitem |
---|
193 | ; Parameters: |
---|
194 | ; AX: ASCII hotkey starting from upper case 'A' |
---|
195 | ; Returns: |
---|
196 | ; CX: Menuitem index |
---|
197 | ; Corrupts registers: |
---|
198 | ; AX |
---|
199 | ;-------------------------------------------------------------------- |
---|
200 | ALIGN JUMP_ALIGN |
---|
201 | BootMenu_ConvertHotkeyToMenuitem: |
---|
202 | call BootMenu_GetLetterForFirstHardDisk |
---|
203 | cmp al, cl ; Letter is for Hard Disk? |
---|
204 | jae SHORT .StartFromHardDiskLetter |
---|
205 | sub al, 'A' ; Letter to Floppy Drive menuitem |
---|
206 | xchg ax, cx ; Menuitem index to CX |
---|
207 | ret |
---|
208 | ALIGN JUMP_ALIGN |
---|
209 | .StartFromHardDiskLetter: |
---|
210 | sub al, cl ; Hard Disk index |
---|
211 | call FloppyDrive_GetCount |
---|
212 | add cx, ax ; Menuitem index |
---|
213 | ret |
---|
214 | |
---|
215 | ;-------------------------------------------------------------------- |
---|
216 | ; Returns letter for first hard disk. Usually it will be 'c' but it |
---|
217 | ; can be higher if more than two floppy drives are found. |
---|
218 | ; |
---|
219 | ; BootMenu_GetLetterForFirstHardDisk |
---|
220 | ; Parameters: |
---|
221 | ; Nothing |
---|
222 | ; Returns: |
---|
223 | ; CL: Upper case letter for first hard disk |
---|
224 | ; Corrupts registers: |
---|
225 | ; CH |
---|
226 | ;-------------------------------------------------------------------- |
---|
227 | ALIGN JUMP_ALIGN |
---|
228 | BootMenu_GetLetterForFirstHardDisk: |
---|
229 | call FloppyDrive_GetCount |
---|
230 | add cl, 'A' |
---|
231 | MAX_U cl, 'C' |
---|
232 | ret |
---|
233 | |
---|
234 | |
---|
235 | ;-------------------------------------------------------------------- |
---|
236 | ; Converts selected menuitem index to drive number or function ID. |
---|
237 | ; |
---|
238 | ; BootMenu_ConvertMenuitemToDriveOrFunction |
---|
239 | ; Parameters: |
---|
240 | ; CX: Index of menuitem selected from Boot Menu |
---|
241 | ; DS: RAMVARS segment |
---|
242 | ; Returns: |
---|
243 | ; DX: Drive number to be used for booting (if CF cleared) |
---|
244 | ; Function ID (if CF set) |
---|
245 | ; CF: Cleared if drive selected |
---|
246 | ; Set if function selected |
---|
247 | ; Corrupts registers: |
---|
248 | ; AX, CX |
---|
249 | ;-------------------------------------------------------------------- |
---|
250 | ALIGN JUMP_ALIGN |
---|
251 | BootMenu_ConvertMenuitemToDriveOrFunction: |
---|
252 | mov dx, cx ; Copy menuitem index to DX |
---|
253 | call FloppyDrive_GetCount |
---|
254 | cmp dx, cx ; Floppy drive? |
---|
255 | jb SHORT .ReturnFloppyDriveInDX |
---|
256 | sub dx, cx ; Remove floppy drives from index |
---|
257 | call RamVars_GetHardDiskCountFromBDAtoCX |
---|
258 | cmp dx, cx ; Hard disk? |
---|
259 | jb SHORT .ReturnHardDiskInDX |
---|
260 | sub dx, cx ; Remove hard disks from index |
---|
261 | jmp SHORT BootMenu_ConvertFunctionIndexToID |
---|
262 | ALIGN JUMP_ALIGN |
---|
263 | .ReturnHardDiskInDX: |
---|
264 | or dl, 80h |
---|
265 | ALIGN JUMP_ALIGN |
---|
266 | .ReturnFloppyDriveInDX: |
---|
267 | clc |
---|
268 | ret |
---|
269 | |
---|
270 | |
---|
271 | ;-------------------------------------------------------------------- |
---|
272 | ; Converts selected menuitem index to drive number or function ID. |
---|
273 | ; |
---|
274 | ; BootMenu_ConvertFunctionIndexToID |
---|
275 | ; Parameters: |
---|
276 | ; CX: Menuitem index |
---|
277 | ; DX: Function index (Menuitem index - floppy count - HD count) |
---|
278 | ; Returns: |
---|
279 | ; DX: Function ID |
---|
280 | ; CF: Set to indicate function |
---|
281 | ; Corrupts registers: |
---|
282 | ; AX, CX |
---|
283 | ;-------------------------------------------------------------------- |
---|
284 | ALIGN JUMP_ALIGN |
---|
285 | BootMenu_ConvertFunctionIndexToID: |
---|
286 | mov dx, ID_BOOTFUNC_ROMBOOT |
---|
287 | stc |
---|
288 | ret |
---|
289 | |
---|
290 | |
---|
291 | ;-------------------------------------------------------------------- |
---|
292 | ; Converts Floppy or Hard Disk Drive number to menuitem index. |
---|
293 | ; This function does not check does the drive really exists. |
---|
294 | ; |
---|
295 | ; BootMenu_ConvertDriveToMenuitem |
---|
296 | ; Parameters: |
---|
297 | ; DL: Drive number |
---|
298 | ; Returns: |
---|
299 | ; CX: Menuitem index (assuming drive is available) |
---|
300 | ; Corrupts registers: |
---|
301 | ; AX |
---|
302 | ;-------------------------------------------------------------------- |
---|
303 | ALIGN JUMP_ALIGN |
---|
304 | BootMenu_ConvertDriveToMenuitem: |
---|
305 | test dl, 80h ; Floppy drive? |
---|
306 | jz SHORT .ReturnFloppyMenuitem |
---|
307 | call FloppyDrive_GetCount |
---|
308 | mov ax, 7Fh ; Load mask to clear floppy bit |
---|
309 | and ax, dx ; AX = Hard Disk index |
---|
310 | add cx, ax ; Add hard disk index to floppy drive count |
---|
311 | ret |
---|
312 | ALIGN JUMP_ALIGN |
---|
313 | .ReturnFloppyMenuitem: |
---|
314 | eMOVZX cx, dl ; Drive number and item index are equal |
---|
315 | ret |
---|
316 | |
---|
317 | |
---|
318 | ;-------------------------------------------------------------------- |
---|
319 | ; Checks is drive number valid for this system. |
---|
320 | ; |
---|
321 | ; BootMenu_IsDriveInSystem |
---|
322 | ; Parameters: |
---|
323 | ; DL: Drive number |
---|
324 | ; DS: RAMVARS segment |
---|
325 | ; Returns: |
---|
326 | ; CF: Set if drive number is valid |
---|
327 | ; Clear if drive is not present in system |
---|
328 | ; Corrupts registers: |
---|
329 | ; AX, CX |
---|
330 | ;-------------------------------------------------------------------- |
---|
331 | ALIGN JUMP_ALIGN |
---|
332 | BootMenu_IsDriveInSystem: |
---|
333 | test dl, 80h ; Floppy drive? |
---|
334 | jz SHORT .IsFloppyDriveIsInSystem |
---|
335 | call RamVars_GetHardDiskCountFromBDAtoCX ; Hard Disk count to CX |
---|
336 | or cl, 80h ; Set Hard Disk bit to CX |
---|
337 | jmp SHORT .CompareDriveNumberToDriveCount |
---|
338 | .IsFloppyDriveIsInSystem: |
---|
339 | call FloppyDrive_GetCount ; Floppy Drive count to CX |
---|
340 | .CompareDriveNumberToDriveCount: |
---|
341 | cmp dl, cl |
---|
342 | ret |
---|