source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Menus/HotkeyBar.asm@ 614

Last change on this file since 614 was 604, checked in by Krister Nordvall, 4 years ago

Changes:

  • HotkeyBar_TimerTickHandler now uses interrupt 08h instead of interrupt 1Ch and that seems to have finally fixed the problem with hangs in MODULE_HOTKEYS from r599.
File size: 17.3 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Hotkey Bar related functions.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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; Handler for INT 08h System Timer Tick.
26; Reads key presses and draws hotkey bar.
27;
28; HotkeyBar_TimerTickHandler
29; Parameters:
30; Nothing
31; Returns:
32; Nothing
33; Corrupts registers:
34; Nothing
35;--------------------------------------------------------------------
36ALIGN JUMP_ALIGN
37HotkeyBar_TimerTickHandler:
38 push es
39%ifndef USE_186 ; LOAD_BDA_SEGMENT_TO will corrupt AX on 8088/8086
40 push ax
41%endif
42 LOAD_BDA_SEGMENT_TO es, ax
43
44 ; Call previous handler
45 pushf
46 call FAR [es:BOOTVARS.hotkeyVars+HOTKEYVARS.fpPrevTimerHandler]
47
48 ; Update Hotkeybar (process key input and draw) every fourth tick
49 test BYTE [es:BDA.dwTimerTicks], 11b
50 jnz SHORT .ReturnFromHandler
51
52 push ds
53%ifdef USE_186
54 pusha
55%else
56 push di
57 push si
58 push dx
59 push cx
60%endif
61 call RamVars_GetSegmentToDS
62 call HotkeyBar_UpdateDuringDriveDetection
63%ifdef USE_186
64 popa
65%else
66 pop cx
67 pop dx
68 pop si
69 pop di
70%endif
71 pop ds
72
73.ReturnFromHandler:
74%ifndef USE_186
75 pop ax
76%endif
77 pop es
78 iret
79
80
81;--------------------------------------------------------------------
82; Scans key presses and draws any hotkey changes.
83;
84; HotkeyBar_UpdateDuringDriveDetection
85; Parameters:
86; DS: RAMVARS segment
87; ES: BDA segment (zero)
88; Returns:
89; Nothing
90; Corrupts registers:
91; AX, CX, DX, SI, DI
92;--------------------------------------------------------------------
93HotkeyBar_UpdateDuringDriveDetection:
94 call ScanHotkeysFromKeyBufferAndStoreToBootvars
95
96 ; If ESC pressed, abort detection by forcing timeout
97 cmp al, ESC_SCANCODE
98 jne SHORT .ContinueDrawing
99 mov BYTE [RAMVARS.bTimeoutTicksLeft], 0
100.ContinueDrawing:
101 ; Fall to HotkeyBar_DrawToTopOfScreen
102
103
104;--------------------------------------------------------------------
105; HotkeyBar_DrawToTopOfScreen
106; Parameters:
107; DS: RAMVARS segment
108; ES: BDA segment (zero)
109; Returns:
110; Nothing
111; Corrupts registers:
112; AX, CX, DX, SI, DI
113;--------------------------------------------------------------------
114HotkeyBar_DrawToTopOfScreen:
115 ; Store current screen coordinates to stack
116 ; (to be restored when Hotkey Bar is rendered)
117 CALL_DISPLAY_LIBRARY GetSoftwareCoordinatesToAX
118 push ax
119
120 ; Move cursor to top left corner (0, 0)
121 mov ax, es
122 call HotkeyBar_SetCursorCoordinatesFromAX
123 ; Fall to .PrintFloppyDriveHotkeys
124
125;--------------------------------------------------------------------
126; .PrintFloppyDriveHotkeys
127; Parameters:
128; DS: RAMVARS segment
129; ES: BDA segment (zero)
130; Returns:
131; Nothing
132; Corrupts registers:
133; AX, CX, DX, SI, DI
134;--------------------------------------------------------------------
135.PrintFloppyDriveHotkeys:
136 call FloppyDrive_GetCountToAX
137 xchg cx, ax ; Any Floppy Drives?
138 jcxz .SkipFloppyDriveHotkeys
139
140 mov ax, (ANGLE_QUOTE_RIGHT << 8) | DEFAULT_FLOPPY_DRIVE_LETTER
141 mov cl, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bFddLetter]
142 mov di, g_szFDD
143
144 ; Clear CH if floppy drive is selected for boot
145%if 0 ; Not needed until more flags added
146 mov ch, FLG_HOTKEY_HD_FIRST
147 and ch, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bFlags]
148%else
149 mov ch, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bFlags]
150%endif
151 call FormatDriveHotkeyString
152
153.SkipFloppyDriveHotkeys:
154 ; Fall to .PrintHardDriveHotkeys
155
156;--------------------------------------------------------------------
157; .PrintHardDriveHotkeys
158; Parameters:
159; DS: RAMVARS segment
160; ES: BDA segment (zero)
161; Returns:
162; Nothing
163; Corrupts registers:
164; AX, CX, DX, SI, DI
165;--------------------------------------------------------------------
166 call BootVars_GetLetterForFirstHardDriveToAX
167 mov ah, ANGLE_QUOTE_RIGHT
168 mov cx, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wHddLetterAndFlags] ; Letter to CL, flags to CH
169 ;and ch, FLG_HOTKEY_HD_FIRST ; Not needed until more flags added
170 xor ch, FLG_HOTKEY_HD_FIRST ; Clear CH if HD is selected for boot, set otherwise
171 mov di, g_szHDD
172 call FormatDriveHotkeyString
173 ; Fall to .PrintBootMenuHotkey
174
175;--------------------------------------------------------------------
176; .PrintBootMenuHotkey
177; Parameters:
178; ES: BDA segment (zero)
179; Returns:
180; Nothing
181; Corrupts registers:
182; AX, CX, DX, SI, DI
183;--------------------------------------------------------------------
184.PrintBootMenuHotkey:
185%ifdef MODULE_BOOT_MENU
186 mov ax, BOOT_MENU_HOTKEY_SCANCODE | ('2' << 8)
187 mov di, g_szBootMenu
188 call FormatFunctionHotkeyString
189%endif
190 ; Fall to .PrintComDetectHotkey
191
192;--------------------------------------------------------------------
193; .PrintComDetectHotkey
194; Parameters:
195; ES: BDA segment (zero)
196; Returns:
197; Nothing
198; Corrupts registers:
199; AX, CX, DX, SI, DI
200;--------------------------------------------------------------------
201.PrintComDetectHotkey:
202%ifdef MODULE_SERIAL
203 mov ax, COM_DETECT_HOTKEY_SCANCODE | ('6' << 8)
204 mov di, g_szHotComDetect
205 call FormatFunctionHotkeyString
206%endif
207 ; Fall to .PrintRomBootHotkey
208
209;--------------------------------------------------------------------
210; .PrintRomBootHotkey
211; Parameters:
212; ES: BDA segment (zero)
213; Returns:
214; Nothing
215; Corrupts registers:
216; AX, CX, DX, SI, DI
217;--------------------------------------------------------------------
218.PrintRomBootHotkey:
219 mov ax, ROM_BOOT_HOTKEY_SCANCODE | ('8' << 8)
220 mov di, g_szRomBoot
221 call FormatFunctionHotkeyString
222 ; Fall to .EndHotkeyBarRendering
223
224;--------------------------------------------------------------------
225; .EndHotkeyBarRendering
226; Parameters:
227; Stack: Screen coordinates before drawing Hotkey Bar
228; Returns:
229; Nothing
230; Corrupts registers:
231; AX, CX, DI
232;--------------------------------------------------------------------
233.EndHotkeyBarRendering:
234 ; Clear the rest of the top row
235 CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
236 eMOVZX cx, al
237 CALL_DISPLAY_LIBRARY GetSoftwareCoordinatesToAX
238 sub cl, al
239 mov al, ' '
240 CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
241
242 ; Restore the saved coordinates from stack
243 pop ax
244 ; Fall to HotkeyBar_SetCursorCoordinatesFromAX
245
246
247;--------------------------------------------------------------------
248; HotkeyBar_SetCursorCoordinatesFromAX
249; Parameters:
250; Nothing
251; Returns:
252; Nothing
253; Corrupts registers:
254; AX, DI
255;--------------------------------------------------------------------
256HotkeyBar_SetCursorCoordinatesFromAX:
257 JMP_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
258
259
260;--------------------------------------------------------------------
261; FormatDriveHotkeyString
262; Parameters:
263; CH: Zero if letter in CL is selected for boot
264; CL: Drive letter hotkey from BOOTVARS
265; AL: First character for drive key string
266; AH: Second character for drive key string (ANGLE_QUOTE_RIGHT)
267; SI: Offset to hotkey description string
268; ES: BDA segment (zero)
269; Returns:
270; Nothing
271; Corrupts registers:
272; AX, CX, DX, SI, DI
273;--------------------------------------------------------------------
274FormatDriveHotkeyString:
275 ; Invalid scancodes are filtered on HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX
276 ; so here we have either drive letter or function key pressed. If latter, draw
277 ; drive letters as unselected
278 cmp BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], FIRST_FUNCTION_KEY_SCANCODE
279 jae SHORT GetNonSelectedHotkeyDescriptionAttributeToDX
280
281 ; Drive selected to boot from?
282 test ch, ch
283 jnz SHORT GetNonSelectedHotkeyDescriptionAttributeToDX
284 jmp SHORT GetSelectedHotkeyDescriptionAttributeToDX
285
286
287;--------------------------------------------------------------------
288; FormatFunctionHotkeyString
289; Parameters:
290; AL: Scancode of function key, to know which if any to show as selected
291; Later replaced with an 'F' for the call to the output routine
292; AH: Second character for drive key string
293; SI: Offset to hotkey description string
294; ES: BDA segment (zero)
295; Returns:
296; Nothing
297; Corrupts registers:
298; AX, CX, DX, SI, DI
299;--------------------------------------------------------------------
300FormatFunctionHotkeyString:
301 xor cx, cx ; Null character, eaten in output routines
302
303 cmp [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode], al
304 mov al, 'F' ; Replace scancode with character for output
305
306%ifdef MODULE_BOOT_MENU
307
308GetSelectedHotkeyDescriptionAttributeToDX:
309 mov si, ATTRIBUTE_CHARS.cHighlightedItem ; Selected hotkey
310 je SHORT GetDescriptionAttributeToDX ; From compare with bScancode above and from FormatDriveHotkeyString
311
312GetNonSelectedHotkeyDescriptionAttributeToDX:
313 mov si, ATTRIBUTE_CHARS.cItem ; Unselected hotkey
314
315 ; Display Library should not be called like this
316GetDescriptionAttributeToDX:
317 xchg dx, ax
318 call MenuAttribute_GetToAXfromTypeInSI
319 xchg dx, ax ; DX = Description attribute
320 ;; fall through to PushHotkeyParamsAndFormat
321
322
323%else ; if no MODULE_BOOT_MENU - No boot menu so use simpler attributes
324
325GetSelectedHotkeyDescriptionAttributeToDX:
326 mov dx, (COLOR_ATTRIBUTE(COLOR_YELLOW, COLOR_CYAN) << 8) | MONO_REVERSE_BLINK
327 je SHORT SelectAttributeFromDHorDLbasedOnVideoMode ; From compare with bScancode above and from FormatDriveHotkeyString
328
329GetNonSelectedHotkeyDescriptionAttributeToDX:
330 mov dx, (COLOR_ATTRIBUTE(COLOR_BLACK, COLOR_CYAN) << 8) | MONO_REVERSE
331
332SelectAttributeFromDHorDLbasedOnVideoMode:
333 mov ch, [es:BDA.bVidMode] ; We only need to preserve CL
334 shr ch, 1
335 jnc SHORT .AttributeLoadedToDL ; Black & White modes
336 shr ch, 1
337 jnz SHORT .AttributeLoadedToDL ; MDA
338 mov dl, dh
339.AttributeLoadedToDL:
340 ;; fall through to PushHotkeyParamsAndFormat
341
342%endif ; MODULE_BOOT_MENU
343
344
345;--------------------------------------------------------------------
346; PushHotkeyParamsAndFormat
347; Parameters:
348; AL: First character
349; AH: Second character
350; DX: Description Attribute
351; CX: Description string parameter
352; CS:DI: Description string
353; Returns:
354; Nothing
355; Corrupts registers:
356; AX, SI, DI
357;--------------------------------------------------------------------
358PushHotkeyParamsAndFormat:
359 push bp
360 mov bp, sp
361
362 mov si, MONO_BRIGHT
363
364 push si ; Key attribute
365 push ax ; First Character
366 mov al, ah
367 push ax ; Second Character
368
369 push dx ; Description attribute
370 push di ; Description string
371 push cx ; Description string parameter
372
373 push si ; Key attribute for last space
374
375 mov si, g_szHotkey
376 jmp DetectPrint_FormatCSSIfromParamsInSSBP
377
378
379;--------------------------------------------------------------------
380; HotkeyBar_StoreDefaultDriveLettersToHotkeyVars
381; Parameters:
382; ES: BDA Segment
383; Returns:
384; Nothing
385; Corrupts registers:
386; AX
387;--------------------------------------------------------------------
388HotkeyBar_StoreDefaultDriveLettersToHotkeyVars:
389 call BootVars_GetLetterForFirstHardDriveToAX
390 mov ah, DEFAULT_FLOPPY_DRIVE_LETTER
391 xchg al, ah
392 mov [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wFddAndHddLetters], ax
393 ret
394
395
396;--------------------------------------------------------------------
397; HotkeyBar_InitializeVariables
398; Parameters:
399; DS: RAMVARS Segment
400; ES: BDA Segment
401; Returns:
402; Nothing
403; Corrupts registers:
404; AX, CX, DX, DI
405;--------------------------------------------------------------------
406HotkeyBar_InitializeVariables:
407 push ds
408 push es
409 pop ds
410
411 ; Store System Timer Tick handler and install our hotkeybar handler
412 mov ax, [BIOS_SYSTEM_TIMER_TICK_INTERRUPT_08h*4]
413 mov [BOOTVARS.hotkeyVars+HOTKEYVARS.fpPrevTimerHandler], ax
414 mov ax, [BIOS_SYSTEM_TIMER_TICK_INTERRUPT_08h*4+2]
415 mov [BOOTVARS.hotkeyVars+HOTKEYVARS.fpPrevTimerHandler+2], ax
416 mov al, BIOS_SYSTEM_TIMER_TICK_INTERRUPT_08h
417 mov si, HotkeyBar_TimerTickHandler
418 call Interrupts_InstallHandlerToVectorInALFromCSSI
419
420 ; Store time when hotkeybar is displayed
421 ; (it will be displayed after initialization is complete)
422 mov ax, [BDA.dwTimerTicks]
423 mov [BOOTVARS.hotkeyVars+HOTKEYVARS.wTimeWhenDisplayed], ax
424
425 pop ds
426
427 ; Initialize HOTKEYVARS by storing default drives to boot from
428 call HotkeyBar_StoreDefaultDriveLettersToHotkeyVars
429 mov dl, [cs:ROMVARS.bBootDrv]
430 ; Fall to HotkeyBar_StoreHotkeyToBootvarsForDriveNumberInDL
431
432
433;--------------------------------------------------------------------
434; HotkeyBar_StoreHotkeyToBootvarsForDriveNumberInDL
435; Parameters:
436; DS: RAMVARS segment
437; ES: BDA segment (zero)
438; DL: Drive Number
439; Returns:
440; Nothing
441; Corrupts registers:
442; AX, CX, DL, DI
443;--------------------------------------------------------------------
444HotkeyBar_StoreHotkeyToBootvarsForDriveNumberInDL:
445 call DriveXlate_ConvertDriveNumberFromDLtoDriveLetter
446 ; Fall to StoreHotkeyToBootvarsForDriveLetterInDL
447
448
449;--------------------------------------------------------------------
450; StoreHotkeyToBootvarsForDriveLetterInDL
451; Parameters:
452; DS: RAMVARS segment
453; ES: BDA segment (zero)
454; DL: Drive Letter ('A'...)
455; Returns:
456; Nothing
457; Corrupts registers:
458; AX, CX, DI
459;--------------------------------------------------------------------
460StoreHotkeyToBootvarsForDriveLetterInDL:
461 eMOVZX ax, dl
462 or al, 32 ; Upper case drive letter to lower case keystroke
463 jmp SHORT HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX
464
465
466;--------------------------------------------------------------------
467; ScanHotkeysFromKeyBufferAndStoreToBootvars
468; Parameters:
469; DS: RAMVARS segment
470; ES: BDA segment (zero)
471; Returns:
472; AL: Last scancode value
473; Corrupts registers:
474; AH, CX
475;--------------------------------------------------------------------
476ScanHotkeysFromKeyBufferAndStoreToBootvars:
477 call Keyboard_GetKeystrokeToAX
478 jz SHORT NoHotkeyToProcess
479
480 ; Prepare to read another key from buffer
481 ePUSH_T cx, ScanHotkeysFromKeyBufferAndStoreToBootvars
482 ; Fall to HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX
483
484
485;--------------------------------------------------------------------
486; HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX
487; Parameters:
488; AL: Hotkey ASCII code
489; AH: Hotkey Scancode
490; DS: RAMVARS segment
491; ES: BDA segment (zero)
492; Returns:
493; AL: Last scancode seen
494; CF: Set if valid hotkey in AL
495; Clear if scancode in AL is not for any hotkey
496; Corrupts registers:
497; AH, CX, DI
498;--------------------------------------------------------------------
499HotkeyBar_StoreHotkeyToBootvarsIfValidKeystrokeInAX:
500 mov di, BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode
501
502 ; All scancodes are saved, even if it wasn't a drive letter,
503 ; which also covers our function key case. Invalid function keys
504 ; will not do anything (won't be printed, won't be accepted as input)
505 mov [es:di], ah
506
507 ; Drive letter hotkeys remaining, allow 'a' to 'z'
508 call Char_IsLowerCaseLetterInAL
509 jnc SHORT .KeystrokeIsNotValidDriveLetter
510 and al, ~32 ; We want to print upper case letters
511
512 ; Clear HD First flag to assume Floppy Drive hotkey
513 dec di
514 and BYTE [es:di], ~FLG_HOTKEY_HD_FIRST
515
516 ; Determine if Floppy or Hard Drive hotkey
517 xchg cx, ax
518 call BootVars_GetLetterForFirstHardDriveToAX
519 cmp cl, al
520 jb SHORT .StoreDriveLetter ; Store Floppy Drive letter
521
522 ; Store Hard Drive letter
523 or BYTE [es:di], FLG_HOTKEY_HD_FIRST
524
525.StoreDriveLetter:
526 sbb di, BYTE 1 ; Sub CF if Floppy Drive
527 xchg ax, cx
528 stosb
529 stc ; Valid hotkey scancode returned in AL
530
531.KeystrokeIsNotValidDriveLetter:
532NoHotkeyToProcess:
533 mov al, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bScancode]
534 ret
535
536
537;--------------------------------------------------------------------
538; HotkeyBar_GetBootDriveNumbersToDX
539; Parameters:
540; DS: RAMVARS segment
541; ES: BDA segment (zero)
542; Returns:
543; DX: Drives selected as boot device, DL is primary
544; Corrupts registers:
545; AX
546;--------------------------------------------------------------------
547HotkeyBar_GetBootDriveNumbersToDX:
548 mov dx, [es:BOOTVARS.hotkeyVars+HOTKEYVARS.wFddAndHddLetters]
549
550 ; HotkeyBar_GetBootDriveNumbersToDX is called when all drives are detected and
551 ; drive letters are known.
552 ; Replace unavailable hard drive letter with first hard drive.
553 ; If we have boot menu, it will be displayed instead.
554%ifndef MODULE_BOOT_MENU
555 call BootVars_GetLetterForFirstHardDriveToAX
556 mov ah, al
557 add al, [es:BDA.bHDCount] ; AL now contains first unavailable HD letter
558 cmp dh, al ; Unavailable drive?
559 jb SHORT .ValidHardDriveLetterInDH
560 mov dh, ah ; Replace unavailable drive with first drive
561.ValidHardDriveLetterInDH:
562%endif
563
564 test BYTE [es:BOOTVARS.hotkeyVars+HOTKEYVARS.bFlags], FLG_HOTKEY_HD_FIRST
565 jnz SHORT .noflip
566 xchg dl, dh
567.noflip:
568 call DriveXlate_ConvertDriveLetterInDLtoDriveNumber
569 xchg dl, dh
570 ; Fall to HotkeyBar_FallThroughTo_DriveXlate_ConvertDriveLetterInDLtoDriveNumber
571
572HotkeyBar_FallThroughTo_DriveXlate_ConvertDriveLetterInDLtoDriveNumber:
573
Note: See TracBrowser for help on using the repository browser.