[392] | 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
|
---|
| 21 | SECTION .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 | ;--------------------------------------------------------------------
|
---|
| 34 | GetDefaultMenuitemToDX:
|
---|
| 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 | ;--------------------------------------------------------------------
|
---|
| 53 | GetMenuitemToDXforDriveInDL:
|
---|
| 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 | ;--------------------------------------------------------------------
|
---|
| 75 | IsDriveDLinSystem:
|
---|
| 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 | ; ConvertKeystrokeToAXfromDriveLetterInDL
|
---|
| 90 | ; Parameters:
|
---|
| 91 | ; DL: Drive Letter ('A'...)
|
---|
| 92 | ; Returns:
|
---|
| 93 | ; AX: Hotkey keystroke
|
---|
| 94 | ; Corrupts registers:
|
---|
| 95 | ; Nothing
|
---|
| 96 | ;--------------------------------------------------------------------
|
---|
| 97 | ConvertKeystrokeToAXfromDriveLetterInDL:
|
---|
| 98 | eMOVZX ax, dl
|
---|
| 99 | jmp Char_ChangeCaseInAL ; Upper case drive letter to lower case keystroke
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 | ;--------------------------------------------------------------------
|
---|
| 103 | ; BootMenuEvent_Handler
|
---|
| 104 | ; Common parameters for all events:
|
---|
| 105 | ; BX: Menu event (anything from MENUEVENT struct)
|
---|
| 106 | ; SS:BP: Menu library handle
|
---|
| 107 | ; Common return values for all events:
|
---|
| 108 | ; CF: Set if event processed
|
---|
| 109 | ; Cleared if event not processed
|
---|
| 110 | ; Corrupts registers:
|
---|
| 111 | ; All
|
---|
| 112 | ;--------------------------------------------------------------------
|
---|
| 113 | BootMenuEvent_Handler:
|
---|
| 114 | LOAD_BDA_SEGMENT_TO es, di
|
---|
| 115 | call RamVars_GetSegmentToDS
|
---|
| 116 |
|
---|
| 117 | %ifdef MENUEVENT_INLINE_OFFSETS
|
---|
| 118 |
|
---|
| 119 | add bx, FirstEvent
|
---|
| 120 | jmp bx
|
---|
| 121 |
|
---|
| 122 | EventNotHandled:
|
---|
| 123 | DoNotSetDefaultMenuitem:
|
---|
| 124 | xor dx, dx ; Clear CF (and menuitem index for DoNotSetDefaultMenuitem)
|
---|
| 125 | ret
|
---|
| 126 |
|
---|
| 127 | MENUEVENT_InitializeMenuinitFromDSSI equ (EventInitializeMenuinitFromSSBP - FirstEvent)
|
---|
| 128 | MENUEVENT_ExitMenu equ (BootMenuEvent_Completed - FirstEvent)
|
---|
| 129 | MENUEVENT_ItemHighlightedFromCX equ (EventItemHighlightedFromCX - FirstEvent)
|
---|
| 130 | MENUEVENT_ItemSelectedFromCX equ (EventItemSelectedFromCX - FirstEvent)
|
---|
| 131 | MENUEVENT_KeyStrokeInAX equ (EventKeyStrokeInAX - FirstEvent)
|
---|
| 132 | MENUEVENT_RefreshTitle equ (BootMenuPrint_TitleStrings - FirstEvent)
|
---|
| 133 | MENUEVENT_RefreshInformation equ (BootMenuPrint_RefreshInformation - FirstEvent)
|
---|
| 134 | MENUEVENT_RefreshItemFromCX equ (BootMenuPrint_RefreshItem - FirstEvent)
|
---|
| 135 | ;
|
---|
| 136 | ; Note that there is no entry for MENUEVENT_IdleProcessing. If MENUEVENT_IDLEPROCESSING_ENABLE is not %defined,
|
---|
| 137 | ; then the entry point will not be called (saving memory on this end and at the CALL point).
|
---|
| 138 | ;
|
---|
| 139 |
|
---|
| 140 | %else
|
---|
| 141 |
|
---|
| 142 | cmp bx, BYTE MENUEVENT.RefreshItemFromCX ; Above last supported item?
|
---|
| 143 | ja SHORT EventNotHandled
|
---|
| 144 | jmp [cs:bx+rgfnEventSpecificHandlers]
|
---|
| 145 |
|
---|
| 146 | EventNotHandled:
|
---|
| 147 | DoNotSetDefaultMenuitem:
|
---|
| 148 | xor dx, dx ; Clear CF (and menuitem index for DoNotSetDefaultMenuitem)
|
---|
| 149 | ret
|
---|
| 150 |
|
---|
| 151 | rgfnEventSpecificHandlers:
|
---|
| 152 | dw EventInitializeMenuinitFromSSBP ; MENUEVENT.InitializeMenuinitFromDSSI
|
---|
| 153 | dw EventCompleted ; MENUEVENT.ExitMenu
|
---|
| 154 | dw EventNotHandled ; MENUEVENT.IdleProcessing
|
---|
| 155 | dw EventItemHighlightedFromCX ; MENUEVENT.ItemHighlightedFromCX
|
---|
| 156 | dw EventItemSelectedFromCX ; MENUEVENT.ItemSelectedFromCX
|
---|
| 157 | dw EventKeyStrokeInAX ; MENUEVENT.KeyStrokeInAX
|
---|
| 158 | dw BootMenuPrint_TitleStrings ; MENUEVENT.RefreshTitle
|
---|
| 159 | dw BootMenuPrint_RefreshInformation ; MENUEVENT.RefreshInformation
|
---|
| 160 | dw BootMenuPrint_RefreshItem ; MENUEVENT.RefreshItemFromCX
|
---|
| 161 |
|
---|
| 162 | %endif
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | ;--------------------------------------------------------------------
|
---|
| 166 | ; EventInitializeMenuinitFromSSBP
|
---|
| 167 | ; Parameters
|
---|
| 168 | ; DS: Ptr to RAMVARS
|
---|
| 169 | ; ES: Ptr to BDA (zero)
|
---|
| 170 | ; SS:BP: Ptr to MENUINIT struct to initialize
|
---|
| 171 | ; Returns:
|
---|
| 172 | ; CF: Set if event processed
|
---|
| 173 | ; Cleared if event not processed
|
---|
| 174 | ; Corrupts registers:
|
---|
| 175 | ; Does not matter
|
---|
| 176 | ;--------------------------------------------------------------------
|
---|
| 177 | FirstEvent:
|
---|
| 178 | EventInitializeMenuinitFromSSBP:
|
---|
| 179 | ; Store default Menuitem (=default drive to boot from)
|
---|
| 180 | call GetDefaultMenuitemToDX
|
---|
| 181 | mov [bp+MENUINIT.wHighlightedItem], dx
|
---|
| 182 |
|
---|
| 183 | ; Store number of Menuitems
|
---|
| 184 | call RamVars_GetHardDiskCountFromBDAtoAX
|
---|
| 185 | xchg ax, cx
|
---|
| 186 | call FloppyDrive_GetCountToAX
|
---|
| 187 | add ax, cx
|
---|
| 188 | mov [bp+MENUINIT.wItems], ax
|
---|
| 189 |
|
---|
| 190 | ; Store menu size
|
---|
| 191 | mov WORD [bp+MENUINIT.wTitleAndInfoLines], BOOT_MENU_TITLE_AND_INFO_LINES
|
---|
| 192 | mov BYTE [bp+MENUINIT.bWidth], BOOT_MENU_WIDTH
|
---|
| 193 | add al, BOOT_MENU_HEIGHT_WITHOUT_ITEMS
|
---|
| 194 | xchg cx, ax
|
---|
| 195 | CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
|
---|
| 196 | sub ah, MENU_SCREEN_BOTTOM_LINES*2 ; Leave space for Hotkey Bar
|
---|
| 197 | MIN_U ah, cl
|
---|
| 198 | mov [bp+MENUINIT.bHeight], ah
|
---|
| 199 |
|
---|
| 200 | ; Store selection timeout
|
---|
| 201 | mov ax, [cs:ROMVARS.wBootTimeout]
|
---|
| 202 | CALL_MENU_LIBRARY StartSelectionTimeoutWithTicksInAX
|
---|
| 203 | stc
|
---|
| 204 | ret
|
---|
| 205 |
|
---|
| 206 |
|
---|
| 207 | ;--------------------------------------------------------------------
|
---|
| 208 | ; EventItemHighlightedFromCX
|
---|
| 209 | ; Parameters
|
---|
| 210 | ; CX: Index of new highlighted item
|
---|
| 211 | ; DX: Index of previously highlighted item or NO_ITEM_HIGHLIGHTED
|
---|
| 212 | ; DS: Ptr to RAMVARS
|
---|
| 213 | ; ES: Ptr to BDA (zero)
|
---|
| 214 | ; SS:BP: Menu library handle
|
---|
| 215 | ; Returns:
|
---|
| 216 | ; CF: Set if event processed
|
---|
| 217 | ; Cleared if event not processed
|
---|
| 218 | ; Corrupts registers:
|
---|
| 219 | ; Does not matter
|
---|
| 220 | ;--------------------------------------------------------------------
|
---|
| 221 | EventItemHighlightedFromCX:
|
---|
| 222 | push cx
|
---|
| 223 | call BootMenu_GetDriveToDXforMenuitemInCX
|
---|
| 224 | call DriveXlate_Reset
|
---|
| 225 | call DriveXlate_SetDriveToSwap
|
---|
| 226 |
|
---|
| 227 | ; We need to generate keystroke so selection two drives is possible.
|
---|
| 228 | ; The secondary boot drive is selected by highlighting it using menu keys
|
---|
| 229 | ; and the primary boot drive is selected by pressing drive letter hotkey.
|
---|
| 230 | call HotkeyBar_ConvertDriveNumberFromDLtoDriveLetter
|
---|
| 231 | call ConvertKeystrokeToAXfromDriveLetterInDL
|
---|
| 232 | call HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX
|
---|
| 233 | call RedrawHotkeyBarFromInsideMenuEventHandler
|
---|
| 234 |
|
---|
| 235 | ; Redraw changes in drive numbers
|
---|
| 236 | xor ax, ax ; Update first floppy drive (for translated drive number)
|
---|
| 237 | CALL_MENU_LIBRARY RefreshItemFromAX
|
---|
| 238 | mov dl, 80h
|
---|
| 239 | call GetMenuitemToDXforDriveInDL
|
---|
| 240 | xchg ax, dx ; Update first hard disk (for translated drive number)
|
---|
| 241 | CALL_MENU_LIBRARY RefreshItemFromAX
|
---|
| 242 | pop ax ; Update new item (for translated drive number)
|
---|
| 243 | CALL_MENU_LIBRARY RefreshItemFromAX
|
---|
| 244 | CALL_MENU_LIBRARY RefreshInformation
|
---|
| 245 | stc
|
---|
| 246 | ret
|
---|
| 247 |
|
---|
| 248 |
|
---|
| 249 | ;--------------------------------------------------------------------
|
---|
| 250 | ; EventItemSelectedFromCX
|
---|
| 251 | ; Parameters
|
---|
| 252 | ; CX: Index of selected item
|
---|
| 253 | ; DS: Ptr to RAMVARS
|
---|
| 254 | ; ES: Ptr to BDA (zero)
|
---|
| 255 | ; SS:BP: Menu library handle
|
---|
| 256 | ; Returns:
|
---|
| 257 | ; CF: Set if event processed
|
---|
| 258 | ; Cleared if event not processed
|
---|
| 259 | ; Corrupts registers:
|
---|
| 260 | ; Does not matter
|
---|
| 261 | ;--------------------------------------------------------------------
|
---|
| 262 | EventItemSelectedFromCX:
|
---|
| 263 | call BootMenu_GetDriveToDXforMenuitemInCX
|
---|
| 264 | jnc SHORT BootMenuEvent_Completed ; No menuitem selected
|
---|
| 265 |
|
---|
| 266 | ; Convert selected drive to hotkey keystroke
|
---|
| 267 | call HotkeyBar_ConvertDriveNumberFromDLtoDriveLetter
|
---|
| 268 | call ConvertKeystrokeToAXfromDriveLetterInDL
|
---|
| 269 | ; Fall to EventKeyStrokeInAX
|
---|
| 270 |
|
---|
| 271 |
|
---|
| 272 | ;--------------------------------------------------------------------
|
---|
| 273 | ; EventKeyStrokeInAX
|
---|
| 274 | ; Parameters
|
---|
| 275 | ; AL: ASCII character for the key
|
---|
| 276 | ; AH: Keyboard library scan code for the key
|
---|
| 277 | ; DS: Ptr to RAMVARS
|
---|
| 278 | ; ES: Ptr to BDA (zero)
|
---|
| 279 | ; SS:BP: Menu library handle
|
---|
| 280 | ; Returns:
|
---|
| 281 | ; CF: Set if event processed
|
---|
| 282 | ; Cleared if event not processed
|
---|
| 283 | ; Corrupts registers:
|
---|
| 284 | ; Does not matter
|
---|
| 285 | ;--------------------------------------------------------------------
|
---|
| 286 | EventKeyStrokeInAX:
|
---|
| 287 | cmp ah, BOOT_MENU_HOTKEY_SCANCODE
|
---|
| 288 | je SHORT BootMenuEvent_Completed ; Ignore Boot Menu hotkey
|
---|
| 289 | call HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX
|
---|
| 290 | jnc SHORT BootMenuEvent_Completed
|
---|
| 291 |
|
---|
| 292 | ; Hotkey is now stored to BOOTVARS and menu can be closed
|
---|
| 293 | ; Fall to CloseBootMenu
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 | ;--------------------------------------------------------------------
|
---|
| 297 | ; CloseBootMenu
|
---|
| 298 | ; Parameters
|
---|
| 299 | ; DS: RAMVARS segment
|
---|
| 300 | ; ES: BDA segment (zero)
|
---|
| 301 | ; Returns:
|
---|
| 302 | ; Nothing
|
---|
| 303 | ; Corrupts registers:
|
---|
| 304 | ; Does not matter
|
---|
| 305 | ;--------------------------------------------------------------------
|
---|
| 306 | CloseBootMenu:
|
---|
| 307 | call DriveXlate_Reset
|
---|
| 308 | CALL_MENU_LIBRARY Close
|
---|
| 309 | ; Fall to RedrawHotkeyBarFromInsideMenuEventHandler
|
---|
| 310 |
|
---|
| 311 |
|
---|
| 312 | ;--------------------------------------------------------------------
|
---|
| 313 | ; RedrawHotkeyBarFromInsideMenuEventHandler
|
---|
| 314 | ; Parameters
|
---|
| 315 | ; DS: RAMVARS segment
|
---|
| 316 | ; ES: BDA segment (zero)
|
---|
| 317 | ; Returns:
|
---|
| 318 | ; Nothing
|
---|
| 319 | ; Corrupts registers:
|
---|
| 320 | ; AX, BX, CX, DX, SI, DI
|
---|
| 321 | ;--------------------------------------------------------------------
|
---|
| 322 | RedrawHotkeyBarFromInsideMenuEventHandler:
|
---|
| 323 | mov al, MONO_NORMAL
|
---|
| 324 | CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
|
---|
| 325 |
|
---|
| 326 | mov bl, ATTRIBUTES_ARE_USED
|
---|
| 327 | mov ax, TELETYPE_OUTPUT_WITH_ATTRIBUTE
|
---|
| 328 | CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
|
---|
| 329 | call HotkeyBar_DrawToTopOfScreen
|
---|
| 330 | ; Fall to BootMenuEvent_Completed
|
---|
| 331 |
|
---|
| 332 |
|
---|
| 333 | ;--------------------------------------------------------------------
|
---|
| 334 | ; BootMenuEvent_Completed
|
---|
| 335 | ; Parameters
|
---|
| 336 | ; Nothing
|
---|
| 337 | ; Returns:
|
---|
| 338 | ; CF: Set to exit from menu
|
---|
| 339 | ; Corrupts registers:
|
---|
| 340 | ; Nothing
|
---|
| 341 | ;--------------------------------------------------------------------
|
---|
| 342 | BootMenuEvent_Completed:
|
---|
| 343 | stc
|
---|
| 344 | ret
|
---|