source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuEvent.asm@ 461

Last change on this file since 461 was 395, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Hotkey Bar and drive translations are now in MODULE_HOTKEYS.
File size: 10.6 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Boot Menu event handler for menu library callbacks.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23
24;--------------------------------------------------------------------
25; GetDefaultMenuitemToDL
26; Parameters:
27; DL: Drive number
28; ES: Ptr to BDA (zero)
29; Returns:
30; DL: Menuitem index (assuming drive is available)
31; Corrupts registers:
32; AX, DH
33;--------------------------------------------------------------------
34GetDefaultMenuitemToDX:
35 mov dx, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wHddAndFddLetters]
36 test BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bFlags], FLG_HOTKEY_HD_FIRST
37 eCMOVZ dl, dh
38 call IsDriveDLinSystem
39 jnc SHORT DoNotSetDefaultMenuitem
40 call DriveXlate_SetDriveToSwap
41 ; Fall to GetMenuitemToDXforDriveInDL
42
43
44;--------------------------------------------------------------------
45; GetMenuitemToDXforDriveInDL
46; Parameters:
47; DL: Drive number
48; Returns:
49; DX: Menuitem index (assuming drive is available)
50; Corrupts registers:
51; AX
52;--------------------------------------------------------------------
53GetMenuitemToDXforDriveInDL:
54 xor dh, dh ; Drive number now in DX
55 test dl, dl
56 jns SHORT .ReturnItemIndexInDX ; Return if floppy drive (HD bit not set)
57 call FloppyDrive_GetCountToAX
58 and dl, ~80h ; Clear HD bit
59 add dx, ax
60.ReturnItemIndexInDX:
61 ret
62
63
64;--------------------------------------------------------------------
65; IsDriveDLinSystem
66; Parameters:
67; DL: Drive number
68; DS: RAMVARS segment
69; Returns:
70; CF: Set if drive number is valid
71; Clear if drive is not present in system
72; Corrupts registers:
73; AX, CX
74;--------------------------------------------------------------------
75IsDriveDLinSystem:
76 test dl, dl ; Floppy drive?
77 jns SHORT .IsFloppyDriveInSystem
78 call RamVars_GetHardDiskCountFromBDAtoAX ; Hard Disk count to AX
79 or al, 80h ; Set Hard Disk bit to AX
80 jmp SHORT .CompareDriveNumberToDriveCount
81.IsFloppyDriveInSystem:
82 call FloppyDrive_GetCountToAX
83.CompareDriveNumberToDriveCount:
84 cmp dl, al ; Set CF when DL is smaller
85 ret
86
87
88;--------------------------------------------------------------------
89; BootMenuEvent_Handler
90; Common parameters for all events:
91; BX: Menu event (anything from MENUEVENT struct)
92; SS:BP: Menu library handle
93; Common return values for all events:
94; CF: Set if event processed
95; Cleared if event not processed
96; Corrupts registers:
97; All
98;--------------------------------------------------------------------
99BootMenuEvent_Handler:
100 LOAD_BDA_SEGMENT_TO es, di
101 call RamVars_GetSegmentToDS
102
103%ifdef MENUEVENT_INLINE_OFFSETS
104
105 add bx, FirstEvent
106 jmp bx
107
108EventNotHandled:
109DoNotSetDefaultMenuitem:
110 xor dx, dx ; Clear CF (and menuitem index for DoNotSetDefaultMenuitem)
111 ret
112
113MENUEVENT_InitializeMenuinitFromDSSI equ (EventInitializeMenuinitFromSSBP - FirstEvent)
114MENUEVENT_ExitMenu equ (BootMenuEvent_Completed - FirstEvent)
115MENUEVENT_ItemHighlightedFromCX equ (EventItemHighlightedFromCX - FirstEvent)
116MENUEVENT_ItemSelectedFromCX equ (EventItemSelectedFromCX - FirstEvent)
117MENUEVENT_KeyStrokeInAX equ (EventKeyStrokeInAX - FirstEvent)
118MENUEVENT_RefreshTitle equ (BootMenuPrint_TitleStrings - FirstEvent)
119MENUEVENT_RefreshInformation equ (BootMenuPrint_RefreshInformation - FirstEvent)
120MENUEVENT_RefreshItemFromCX equ (BootMenuPrint_RefreshItem - FirstEvent)
121;
122; Note that there is no entry for MENUEVENT_IdleProcessing. If MENUEVENT_IDLEPROCESSING_ENABLE is not %defined,
123; then the entry point will not be called (saving memory on this end and at the CALL point).
124;
125
126%else
127
128 cmp bx, BYTE MENUEVENT.RefreshItemFromCX ; Above last supported item?
129 ja SHORT EventNotHandled
130 jmp [cs:bx+rgfnEventSpecificHandlers]
131
132EventNotHandled:
133DoNotSetDefaultMenuitem:
134 xor dx, dx ; Clear CF (and menuitem index for DoNotSetDefaultMenuitem)
135 ret
136
137rgfnEventSpecificHandlers:
138 dw EventInitializeMenuinitFromSSBP ; MENUEVENT.InitializeMenuinitFromDSSI
139 dw EventCompleted ; MENUEVENT.ExitMenu
140 dw EventNotHandled ; MENUEVENT.IdleProcessing
141 dw EventItemHighlightedFromCX ; MENUEVENT.ItemHighlightedFromCX
142 dw EventItemSelectedFromCX ; MENUEVENT.ItemSelectedFromCX
143 dw EventKeyStrokeInAX ; MENUEVENT.KeyStrokeInAX
144 dw BootMenuPrint_TitleStrings ; MENUEVENT.RefreshTitle
145 dw BootMenuPrint_RefreshInformation ; MENUEVENT.RefreshInformation
146 dw BootMenuPrint_RefreshItem ; MENUEVENT.RefreshItemFromCX
147
148%endif
149
150
151;--------------------------------------------------------------------
152; EventInitializeMenuinitFromSSBP
153; Parameters
154; DS: Ptr to RAMVARS
155; ES: Ptr to BDA (zero)
156; SS:BP: Ptr to MENUINIT struct to initialize
157; Returns:
158; CF: Set if event processed
159; Cleared if event not processed
160; Corrupts registers:
161; Does not matter
162;--------------------------------------------------------------------
163FirstEvent:
164EventInitializeMenuinitFromSSBP:
165 ; Store default Menuitem (=default drive to boot from)
166 call GetDefaultMenuitemToDX
167 mov [bp+MENUINIT.wHighlightedItem], dx
168
169 ; Store number of Menuitems
170 call RamVars_GetHardDiskCountFromBDAtoAX
171 xchg ax, cx
172 call FloppyDrive_GetCountToAX
173 add ax, cx
174 mov [bp+MENUINIT.wItems], ax
175
176 ; Store menu size
177 mov WORD [bp+MENUINIT.wTitleAndInfoLines], BOOT_MENU_TITLE_AND_INFO_LINES
178 mov BYTE [bp+MENUINIT.bWidth], BOOT_MENU_WIDTH
179 add al, BOOT_MENU_HEIGHT_WITHOUT_ITEMS
180 xchg cx, ax
181 CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
182 sub ah, MENU_SCREEN_BOTTOM_LINES*2 ; Leave space for Hotkey Bar
183 MIN_U ah, cl
184 mov [bp+MENUINIT.bHeight], ah
185
186 ; Store selection timeout
187 mov ax, [cs:ROMVARS.wBootTimeout]
188 CALL_MENU_LIBRARY StartSelectionTimeoutWithTicksInAX
189 stc
190 ret
191
192
193;--------------------------------------------------------------------
194; EventItemHighlightedFromCX
195; Parameters
196; CX: Index of new highlighted item
197; DX: Index of previously highlighted item or NO_ITEM_HIGHLIGHTED
198; DS: Ptr to RAMVARS
199; ES: Ptr to BDA (zero)
200; SS:BP: Menu library handle
201; Returns:
202; CF: Set if event processed
203; Cleared if event not processed
204; Corrupts registers:
205; Does not matter
206;--------------------------------------------------------------------
207EventItemHighlightedFromCX:
208 push cx
209 call BootMenu_GetDriveToDXforMenuitemInCX
210 call DriveXlate_Reset
211 call DriveXlate_SetDriveToSwap
212
213 ; We need to generate keystroke so selection two drives is possible.
214 ; The secondary boot drive is selected by highlighting it using menu keys
215 ; and the primary boot drive is selected by pressing drive letter hotkey.
216 call BootVars_StoreHotkeyForDriveNumberInDL
217 call RedrawHotkeyBarFromInsideMenuEventHandler
218
219 ; Redraw changes in drive numbers
220 xor ax, ax ; Update first floppy drive (for translated drive number)
221 CALL_MENU_LIBRARY RefreshItemFromAX
222 mov dl, 80h
223 call GetMenuitemToDXforDriveInDL
224 xchg ax, dx ; Update first hard disk (for translated drive number)
225 CALL_MENU_LIBRARY RefreshItemFromAX
226 pop ax ; Update new item (for translated drive number)
227 CALL_MENU_LIBRARY RefreshItemFromAX
228 CALL_MENU_LIBRARY RefreshInformation
229 stc
230 ret
231
232
233;--------------------------------------------------------------------
234; EventKeyStrokeInAX
235; Parameters
236; AL: ASCII character for the key
237; AH: Keyboard library scan code for the key
238; DS: Ptr to RAMVARS
239; ES: Ptr to BDA (zero)
240; SS:BP: Menu library handle
241; Returns:
242; CF: Set if event processed
243; Cleared if event not processed
244; Corrupts registers:
245; Does not matter
246;--------------------------------------------------------------------
247EventKeyStrokeInAX:
248 cmp ah, BOOT_MENU_HOTKEY_SCANCODE
249 je SHORT BootMenuEvent_Completed ; Ignore Boot Menu hotkey
250 call HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX
251 jnc SHORT BootMenuEvent_Completed
252
253 ; Hotkey is now stored to BOOTVARS and menu can be closed
254 jmp SHORT CloseBootMenu
255
256
257;--------------------------------------------------------------------
258; EventItemSelectedFromCX
259; Parameters
260; CX: Index of selected item
261; DS: Ptr to RAMVARS
262; ES: Ptr to BDA (zero)
263; SS:BP: Menu library handle
264; Returns:
265; CF: Set if event processed
266; Cleared if event not processed
267; Corrupts registers:
268; Does not matter
269;--------------------------------------------------------------------
270EventItemSelectedFromCX:
271 call BootMenu_GetDriveToDXforMenuitemInCX
272 jnc SHORT BootMenuEvent_Completed ; No menuitem selected
273
274 ; Convert selected drive to hotkey keystroke
275 call HotkeyBar_StoreHotkeyToBootvarsForDriveLetterInDL
276 ; Fall to CloseBootMenu
277
278
279;--------------------------------------------------------------------
280; CloseBootMenu
281; Parameters
282; DS: RAMVARS segment
283; ES: BDA segment (zero)
284; Returns:
285; Nothing
286; Corrupts registers:
287; Does not matter
288;--------------------------------------------------------------------
289CloseBootMenu:
290 call DriveXlate_Reset
291 CALL_MENU_LIBRARY Close
292 ; Fall to RedrawHotkeyBarFromInsideMenuEventHandler
293
294
295;--------------------------------------------------------------------
296; RedrawHotkeyBarFromInsideMenuEventHandler
297; Parameters
298; DS: RAMVARS segment
299; ES: BDA segment (zero)
300; Returns:
301; Nothing
302; Corrupts registers:
303; AX, BX, CX, DX, SI, DI
304;--------------------------------------------------------------------
305RedrawHotkeyBarFromInsideMenuEventHandler:
306 mov al, MONO_NORMAL
307 CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
308
309 mov bl, ATTRIBUTES_ARE_USED
310 mov ax, TELETYPE_OUTPUT_WITH_ATTRIBUTE
311 CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
312 call HotkeyBar_DrawToTopOfScreen
313 ; Fall to BootMenuEvent_Completed
314
315
316;--------------------------------------------------------------------
317; BootMenuEvent_Completed
318; Parameters
319; Nothing
320; Returns:
321; CF: Set to exit from menu
322; Corrupts registers:
323; Nothing
324;--------------------------------------------------------------------
325BootMenuEvent_Completed:
326 stc
327 ret
Note: See TracBrowser for help on using the repository browser.