[392] | 1 | ; Project name : XTIDE Universal BIOS |
---|
| 2 | ; Description : Boot Menu event handler for menu library callbacks. |
---|
| 3 | |
---|
| 4 | ; |
---|
[526] | 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team. |
---|
[392] | 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. |
---|
[526] | 12 | ; |
---|
[392] | 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 |
---|
[526] | 16 | ; GNU General Public License for more details. |
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 18 | ; |
---|
[392] | 19 | |
---|
| 20 | ; Section containing code |
---|
| 21 | SECTION .text |
---|
| 22 | |
---|
| 23 | ;-------------------------------------------------------------------- |
---|
| 24 | ; GetMenuitemToDXforDriveInDL |
---|
| 25 | ; Parameters: |
---|
| 26 | ; DL: Drive number |
---|
| 27 | ; Returns: |
---|
| 28 | ; DX: Menuitem index (assuming drive is available) |
---|
| 29 | ; Corrupts registers: |
---|
| 30 | ; AX |
---|
| 31 | ;-------------------------------------------------------------------- |
---|
| 32 | GetMenuitemToDXforDriveInDL: |
---|
| 33 | xor dh, dh ; Drive number now in DX |
---|
| 34 | test dl, dl |
---|
| 35 | jns SHORT .ReturnItemIndexInDX ; Return if floppy drive (HD bit not set) |
---|
| 36 | call FloppyDrive_GetCountToAX |
---|
| 37 | and dl, ~80h ; Clear HD bit |
---|
| 38 | add dx, ax |
---|
| 39 | .ReturnItemIndexInDX: |
---|
| 40 | ret |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | ;-------------------------------------------------------------------- |
---|
| 44 | ; BootMenuEvent_Handler |
---|
| 45 | ; Common parameters for all events: |
---|
| 46 | ; BX: Menu event (anything from MENUEVENT struct) |
---|
| 47 | ; SS:BP: Menu library handle |
---|
| 48 | ; Common return values for all events: |
---|
| 49 | ; CF: Set if event processed |
---|
| 50 | ; Cleared if event not processed |
---|
| 51 | ; Corrupts registers: |
---|
| 52 | ; All |
---|
| 53 | ;-------------------------------------------------------------------- |
---|
| 54 | BootMenuEvent_Handler: |
---|
| 55 | LOAD_BDA_SEGMENT_TO es, di |
---|
| 56 | call RamVars_GetSegmentToDS |
---|
| 57 | |
---|
| 58 | %ifdef MENUEVENT_INLINE_OFFSETS |
---|
| 59 | |
---|
| 60 | add bx, FirstEvent |
---|
| 61 | jmp bx |
---|
| 62 | |
---|
[489] | 63 | .EventNotHandled: |
---|
| 64 | .DoNotSetDefaultMenuitem: |
---|
[392] | 65 | xor dx, dx ; Clear CF (and menuitem index for DoNotSetDefaultMenuitem) |
---|
| 66 | ret |
---|
| 67 | |
---|
[567] | 68 | MENUEVENT_InitializeMenuinitFromDSSI equ (EventInitializeMenuinitFromSSBP - FirstEvent) |
---|
| 69 | MENUEVENT_ExitMenu equ (BootMenuEvent_Completed - FirstEvent) |
---|
| 70 | MENUEVENT_ItemHighlightedFromCX equ (EventItemHighlightedFromCX - FirstEvent) |
---|
| 71 | MENUEVENT_KeyStrokeInAX equ (EventKeyStrokeInAX - FirstEvent) |
---|
| 72 | MENUEVENT_ItemSelectedFromCX equ (EventItemSelectedFromCX - FirstEvent) |
---|
| 73 | MENUEVENT_RefreshTitle equ (BootMenuPrint_TitleStrings - FirstEvent) |
---|
| 74 | MENUEVENT_RefreshInformation equ (BootMenuPrint_RefreshInformation - FirstEvent) |
---|
| 75 | MENUEVENT_RefreshItemFromCX equ (BootMenuPrint_RefreshItem - FirstEvent) |
---|
[392] | 76 | ; |
---|
| 77 | ; Note that there is no entry for MENUEVENT_IdleProcessing. If MENUEVENT_IDLEPROCESSING_ENABLE is not %defined, |
---|
| 78 | ; then the entry point will not be called (saving memory on this end and at the CALL point). |
---|
| 79 | ; |
---|
| 80 | |
---|
| 81 | %else |
---|
| 82 | |
---|
| 83 | cmp bx, BYTE MENUEVENT.RefreshItemFromCX ; Above last supported item? |
---|
[489] | 84 | ja SHORT .EventNotHandled |
---|
[392] | 85 | jmp [cs:bx+rgfnEventSpecificHandlers] |
---|
| 86 | |
---|
[489] | 87 | .EventNotHandled: |
---|
| 88 | .DoNotSetDefaultMenuitem: |
---|
[392] | 89 | xor dx, dx ; Clear CF (and menuitem index for DoNotSetDefaultMenuitem) |
---|
| 90 | ret |
---|
| 91 | |
---|
| 92 | rgfnEventSpecificHandlers: |
---|
| 93 | dw EventInitializeMenuinitFromSSBP ; MENUEVENT.InitializeMenuinitFromDSSI |
---|
| 94 | dw EventCompleted ; MENUEVENT.ExitMenu |
---|
| 95 | dw EventNotHandled ; MENUEVENT.IdleProcessing |
---|
| 96 | dw EventItemHighlightedFromCX ; MENUEVENT.ItemHighlightedFromCX |
---|
[567] | 97 | |
---|
[392] | 98 | dw EventItemSelectedFromCX ; MENUEVENT.ItemSelectedFromCX |
---|
| 99 | dw EventKeyStrokeInAX ; MENUEVENT.KeyStrokeInAX |
---|
| 100 | dw BootMenuPrint_TitleStrings ; MENUEVENT.RefreshTitle |
---|
| 101 | dw BootMenuPrint_RefreshInformation ; MENUEVENT.RefreshInformation |
---|
| 102 | dw BootMenuPrint_RefreshItem ; MENUEVENT.RefreshItemFromCX |
---|
| 103 | |
---|
| 104 | %endif |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | ;-------------------------------------------------------------------- |
---|
| 108 | ; EventInitializeMenuinitFromSSBP |
---|
| 109 | ; Parameters |
---|
| 110 | ; DS: Ptr to RAMVARS |
---|
| 111 | ; ES: Ptr to BDA (zero) |
---|
| 112 | ; SS:BP: Ptr to MENUINIT struct to initialize |
---|
| 113 | ; Returns: |
---|
| 114 | ; CF: Set if event processed |
---|
| 115 | ; Cleared if event not processed |
---|
| 116 | ; Corrupts registers: |
---|
| 117 | ; Does not matter |
---|
| 118 | ;-------------------------------------------------------------------- |
---|
[526] | 119 | FirstEvent: |
---|
[392] | 120 | EventInitializeMenuinitFromSSBP: |
---|
| 121 | ; Store number of Menuitems |
---|
| 122 | call RamVars_GetHardDiskCountFromBDAtoAX |
---|
| 123 | xchg ax, cx |
---|
| 124 | call FloppyDrive_GetCountToAX |
---|
| 125 | add ax, cx |
---|
[492] | 126 | inc ax ; extra entry for ROM Boot item |
---|
[392] | 127 | mov [bp+MENUINIT.wItems], ax |
---|
[526] | 128 | |
---|
[392] | 129 | ; Store menu size |
---|
| 130 | mov WORD [bp+MENUINIT.wTitleAndInfoLines], BOOT_MENU_TITLE_AND_INFO_LINES |
---|
| 131 | mov BYTE [bp+MENUINIT.bWidth], BOOT_MENU_WIDTH |
---|
| 132 | add al, BOOT_MENU_HEIGHT_WITHOUT_ITEMS |
---|
| 133 | xchg cx, ax |
---|
| 134 | CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH |
---|
| 135 | MIN_U ah, cl |
---|
| 136 | mov [bp+MENUINIT.bHeight], ah |
---|
| 137 | |
---|
| 138 | ; Store selection timeout |
---|
| 139 | mov ax, [cs:ROMVARS.wBootTimeout] |
---|
| 140 | CALL_MENU_LIBRARY StartSelectionTimeoutWithTicksInAX |
---|
[562] | 141 | |
---|
| 142 | ; Store default Menuitem (=default drive to boot from) |
---|
[592] | 143 | eMOVZX dx, [cs:ROMVARS.bBootDrv] |
---|
[562] | 144 | call GetMenuitemToDXforDriveInDL |
---|
| 145 | mov [bp+MENUINIT.wHighlightedItem], dx |
---|
| 146 | |
---|
[392] | 147 | stc |
---|
| 148 | ret |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | ;-------------------------------------------------------------------- |
---|
| 152 | ; EventItemHighlightedFromCX |
---|
| 153 | ; Parameters |
---|
| 154 | ; CX: Index of new highlighted item |
---|
| 155 | ; DX: Index of previously highlighted item or NO_ITEM_HIGHLIGHTED |
---|
| 156 | ; DS: Ptr to RAMVARS |
---|
| 157 | ; ES: Ptr to BDA (zero) |
---|
| 158 | ; SS:BP: Menu library handle |
---|
| 159 | ; Returns: |
---|
| 160 | ; CF: Set if event processed |
---|
| 161 | ; Cleared if event not processed |
---|
| 162 | ; Corrupts registers: |
---|
| 163 | ; Does not matter |
---|
| 164 | ;-------------------------------------------------------------------- |
---|
| 165 | EventItemHighlightedFromCX: |
---|
| 166 | push cx |
---|
[528] | 167 | |
---|
| 168 | ; Drive number translations and hotkeys must be reset to defaults so highlighted |
---|
| 169 | ; selections are correctly displayed on Hotkey Bar and on Boot Menu |
---|
| 170 | %ifdef MODULE_HOTKEYS |
---|
[599] | 171 | call HotkeyBar_StoreDefaultDriveLettersToHotkeyVars |
---|
[528] | 172 | %endif |
---|
| 173 | call DriveXlate_Reset |
---|
| 174 | |
---|
| 175 | ; Set highlighted item to be drive to boot from for visual purposes only |
---|
[526] | 176 | call BootMenu_GetDriveToDXforMenuitemInCX |
---|
[528] | 177 | jnc SHORT .noDriveSwapSinceRomBootSelected |
---|
[392] | 178 | call DriveXlate_SetDriveToSwap |
---|
[526] | 179 | |
---|
[528] | 180 | %ifdef MODULE_HOTKEYS |
---|
| 181 | ; Store highlighted drive as hotkey |
---|
| 182 | call HotkeyBar_StoreHotkeyToBootvarsForDriveNumberInDL |
---|
| 183 | jmp SHORT .UpdateHotkeyBar |
---|
| 184 | .noDriveSwapSinceRomBootSelected: |
---|
| 185 | mov ah, ROM_BOOT_HOTKEY_SCANCODE |
---|
| 186 | call HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX |
---|
| 187 | |
---|
| 188 | .UpdateHotkeyBar: |
---|
| 189 | ; Redraw Hotkey Bar for updated boot drive letters |
---|
| 190 | mov al, MONO_NORMAL |
---|
| 191 | CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL |
---|
| 192 | |
---|
| 193 | mov bl, ATTRIBUTES_ARE_USED |
---|
| 194 | mov ax, TELETYPE_OUTPUT_WITH_ATTRIBUTE |
---|
| 195 | CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL |
---|
| 196 | call HotkeyBar_DrawToTopOfScreen |
---|
| 197 | %else |
---|
| 198 | .noDriveSwapSinceRomBootSelected: |
---|
| 199 | %endif ; MODULE_HOTKEYS |
---|
| 200 | |
---|
[392] | 201 | ; Redraw changes in drive numbers |
---|
| 202 | xor ax, ax ; Update first floppy drive (for translated drive number) |
---|
| 203 | CALL_MENU_LIBRARY RefreshItemFromAX |
---|
| 204 | mov dl, 80h |
---|
| 205 | call GetMenuitemToDXforDriveInDL |
---|
| 206 | xchg ax, dx ; Update first hard disk (for translated drive number) |
---|
| 207 | CALL_MENU_LIBRARY RefreshItemFromAX |
---|
| 208 | pop ax ; Update new item (for translated drive number) |
---|
| 209 | CALL_MENU_LIBRARY RefreshItemFromAX |
---|
| 210 | CALL_MENU_LIBRARY RefreshInformation |
---|
| 211 | stc |
---|
| 212 | ret |
---|
| 213 | |
---|
[526] | 214 | |
---|
[392] | 215 | ;-------------------------------------------------------------------- |
---|
[528] | 216 | ; EventKeyStrokeInAX |
---|
| 217 | ; Parameters |
---|
| 218 | ; AL: ASCII character for the key |
---|
| 219 | ; AH: Keyboard library scan code for the key |
---|
| 220 | ; DS: Ptr to RAMVARS |
---|
| 221 | ; ES: Ptr to BDA (zero) |
---|
| 222 | ; SS:BP: Menu library handle |
---|
| 223 | ; Returns: |
---|
| 224 | ; CF: Set if event processed |
---|
| 225 | ; Cleared if event not processed |
---|
| 226 | ; Corrupts registers: |
---|
| 227 | ; Does not matter |
---|
| 228 | ;-------------------------------------------------------------------- |
---|
| 229 | %ifdef MODULE_HOTKEYS |
---|
| 230 | EventKeyStrokeInAX: |
---|
| 231 | ; Keypress will be the primary boot drive |
---|
| 232 | cmp ah, BOOT_MENU_HOTKEY_SCANCODE |
---|
| 233 | je SHORT BootMenuEvent_Completed ; Ignore Boot Menu hotkey |
---|
| 234 | call HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX |
---|
| 235 | jnc SHORT BootMenuEvent_Completed |
---|
| 236 | ; Fall to CloseBootMenu through EventItemSelectedFromCX |
---|
| 237 | %endif |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | ;-------------------------------------------------------------------- |
---|
[395] | 241 | ; EventItemSelectedFromCX |
---|
[392] | 242 | ; Parameters |
---|
[395] | 243 | ; CX: Index of selected item |
---|
[392] | 244 | ; DS: Ptr to RAMVARS |
---|
| 245 | ; ES: Ptr to BDA (zero) |
---|
| 246 | ; SS:BP: Menu library handle |
---|
| 247 | ; Returns: |
---|
| 248 | ; CF: Set if event processed |
---|
| 249 | ; Cleared if event not processed |
---|
| 250 | ; Corrupts registers: |
---|
| 251 | ; Does not matter |
---|
| 252 | ;-------------------------------------------------------------------- |
---|
[395] | 253 | EventItemSelectedFromCX: |
---|
[392] | 254 | ; Fall to CloseBootMenu |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | ;-------------------------------------------------------------------- |
---|
| 258 | ; CloseBootMenu |
---|
| 259 | ; Parameters |
---|
| 260 | ; DS: RAMVARS segment |
---|
| 261 | ; ES: BDA segment (zero) |
---|
| 262 | ; Returns: |
---|
| 263 | ; Nothing |
---|
| 264 | ; Corrupts registers: |
---|
| 265 | ; Does not matter |
---|
| 266 | ;-------------------------------------------------------------------- |
---|
| 267 | CloseBootMenu: |
---|
| 268 | CALL_MENU_LIBRARY Close |
---|
| 269 | ; Fall to BootMenuEvent_Completed |
---|
| 270 | |
---|
[526] | 271 | |
---|
[392] | 272 | ;-------------------------------------------------------------------- |
---|
| 273 | ; BootMenuEvent_Completed |
---|
| 274 | ; Parameters |
---|
| 275 | ; Nothing |
---|
| 276 | ; Returns: |
---|
| 277 | ; CF: Set to exit from menu |
---|
| 278 | ; Corrupts registers: |
---|
| 279 | ; Nothing |
---|
| 280 | ;-------------------------------------------------------------------- |
---|
| 281 | BootMenuEvent_Completed: |
---|
| 282 | stc |
---|
[528] | 283 | %ifndef MODULE_HOTKEYS |
---|
| 284 | EventKeyStrokeInAX: |
---|
| 285 | %endif |
---|
[392] | 286 | ret |
---|