source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenu.asm@ 82

Last change on this file since 82 was 32, checked in by Tomi Tilli, 14 years ago

Correct number of drives is now returned from AH=08h even when it is redirected to foreign BIOS.

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