source: xtideuniversalbios/trunk/Assembly_Library/Src/Keyboard/Keyboard.asm @ 592

Last change on this file since 592 was 592, checked in by krille_n_, 6 years ago

Changes:

  • The problem with NASM in the previous revision (r591) has been fixed.
  • The colors used by the boot menu and hotkey bar can now be customized by selecting one of a number of pre-defined color themes. Suggestions for additional themes are more than welcome!
  • Large builds are now 10 KB. Small builds are still 8 KB with the exception of the Tiny build which is now 4 KB. In other words, builds are now as small as possible to make it easier to combine them with other BIOSes.
  • Added code to the library to improve drive error handling. XTIDECFG can now handle "Drive Not Ready" errors.
  • Fixed a couple of potential bugs in AtaID.asm (AtaID_GetMaxPioModeToAXandMinCycleTimeToCX); 1) ATA1.bPioMode was treated as a WORD variable. 2) ATA2.bPIOSupp was assumed to be non-zero which would result in PIO mode 3 being returned if the assumption was wrong.
  • Made the same changes in the equivalent function used by BIOSDRVS (DisplayPioModeInformationUsingAtaInfoFromDSBX in AtaInfo.asm).
  • Fixed a bug from r587 in PDC20x30.asm in PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX.
  • Fixed a bug from r523 in XTIDECFG where Auto Configure would only set the IRQ on one IDE interface on AT-builds.
  • XTIDECFG will now restore the default settings for the "Serial port virtual device" when reselecting it in the list of device types. This makes it behave consistently for all device types.
  • The eAAM macro is now used regardless if USE_UNDOC_INTEL is defined or not because it is apparently supported on all processors including the NEC V20/V30 CPUs.
  • Renamed the EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS define to EXCLUDE_FROM_XUB.
  • Added a define to exclude unused library code from BIOSDRVS (EXCLUDE_FROM_BIOSDRVS). This makes it a lot smaller than in previous revisions.
  • All unnecessary CLD-instructions are now under a new define 'CLD_NEEDED' which is only enabled for the BIOS. It is disabled for XTIDECFG and BIOSDRVS but can be enabled if needed by adding this define to the respective makefile. This change was made because these unnecessary instructions are wasteful and should never be needed. In fact, they only serve to hide bugs (in other peoples code) which I strongly believe should be avoided. I recommend people making their own BIOSes from source to not use this define as it's extremely unlikely to be needed.
  • Updated the copyright info in SerDrive and changed an URL to point to the new site.
  • Updated the copyright info and version number in BIOSDRVS.
  • Updated the copyright info in XTIDECFG.
  • Optimizations in general.
File size: 9.3 KB
RevLine 
[41]1; Project name  :   Assembly Library
2; Description   :   Functions for managing keyboard.
3
[376]4;
[526]5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]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;
[376]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.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
[526]20
[41]21BUFFER_SIZE_FOR_WORD_INPUT      EQU     6   ; 5 chars + NULL
22
23; Section containing code
24SECTION .text
25
26;--------------------------------------------------------------------
27; Reads user inputted word.
28; Function returns when ENTER or ESC will be pressed.
[133]29;
[41]30; Keyboard_ReadUserInputtedWordWhilePrinting
31;   Parameters
32;       BX:     Numeric base (10 or 16)
33;   Returns:
34;       AX:     User inputted word
35;       ZF:     Set if user cancellation
36;   Corrupts registers:
37;       DX
38;--------------------------------------------------------------------
[592]39%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
[369]40ALIGN KEYBOARD_JUMP_ALIGN
[41]41Keyboard_ReadUserInputtedWordWhilePrinting:
[52]42    push    ds
43    push    si
[41]44    push    cx
45
[52]46    mov     cx, BUFFER_SIZE_FOR_WORD_INPUT
47    call    Memory_ReserveCXbytesFromStackToDSSI
[41]48
49    call    Char_GetFilterFunctionToDXforNumericBaseInBX
[54]50    call    Registers_ExchangeDSSIwithESDI
[41]51    call    Keyboard_ReadUserInputtedStringToESDIWhilePrinting
[54]52    call    Registers_ExchangeDSSIwithESDI  ; Does not modify FLAGS
[52]53    jz      SHORT .CancelledByUser
[41]54
55    call    String_ConvertWordToAXfromStringInDSSIwithBaseInBX
[52]56.CancelledByUser:
57    add     sp, BYTE BUFFER_SIZE_FOR_WORD_INPUT
[54]58    test    cx, cx                          ; Set ZF if string length is zero
[41]59    pop     cx
[52]60    pop     si
61    pop     ds
[41]62    ret
[131]63%endif
[41]64
65
66;--------------------------------------------------------------------
67; Reads user inputted string to buffer. Character filter is
68; supported to ignore unwanted characters.
69; Function returns when ENTER or ESC will be pressed.
[133]70;
[41]71; Keyboard_ReadUserInputtedStringToESDIWhilePrinting
72;   Parameters:
73;       CX:     Buffer size (with NULL)
74;       ES:DI:  Ptr to destination buffer
75;       CS:DX:  Ptr to character filter function:
76;                   Parameters:
77;                       AL:     Character inputted by user
78;                   Returns:
79;                       CF:     Set if character is accepted
80;                               Cleared if character is rejected
81;                   Corrupts registers:
82;                       Nothing
83;   Returns:
84;       CX:     String length in characters (without NULL)
85;       ZF:     Set if user cancellation
86;   Corrupts registers:
87;       AX
88;--------------------------------------------------------------------
[592]89%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
[369]90ALIGN KEYBOARD_JUMP_ALIGN
[41]91Keyboard_ReadUserInputtedStringToESDIWhilePrinting:
92    push    di
93    push    si
94    push    bx
95    call    .PrepareDisplayContextForKeyboardInput
96    jcxz    .ReturnAfterUpdatingZF
97
98    xor     bx, bx                              ; Zero character counter
99    dec     cx                                  ; Decrement buffer size for NULL
[592]100%ifdef CLD_NEEDED
[41]101    cld
[592]102%endif
[369]103ALIGN KEYBOARD_JUMP_ALIGN
[41]104.GetCharacterFromUser:
105    call    Keyboard_GetKeystrokeToAXandWaitIfNecessary ; Get ASCII to AL
106    call    .ProcessControlCharacter
107    jz      SHORT .TerminateStringWithNULL
108    jc      SHORT .PlayBellForRejectedCharacter
109    call    dx                                  ; Filter character
110    jnc     SHORT .PlayBellForRejectedCharacter
111    inc     bx                                  ; Increment number of characters stored
112    stosb                                       ; Store from AL to ES:DI
113    call    Keyboard_PrintInputtedCharacter
114    loop    .GetCharacterFromUser
115.PlayBellForRejectedCharacter:
[48]116    cmp     al, BS                              ; No bell for backspace
117    je      SHORT .GetCharacterFromUser
[41]118    call    Keyboard_PlayBellForUnwantedKeystroke
119    jmp     SHORT .GetCharacterFromUser
120
121.TerminateStringWithNULL:
122    stosb                                       ; Terminate string with NULL
123    mov     cx, bx                              ; String length now in CX
124
125.ReturnAfterUpdatingZF:
126    CALL_DISPLAY_LIBRARY PopDisplayContext
127    test    cx, cx                              ; Clear or set ZF
128    pop     bx
129    pop     si
130    pop     di
131    ret
132
133;--------------------------------------------------------------------
134; .PrepareDisplayContextForKeyboardInput
135;   Parameters:
136;       Nothing
137;   Returns:
138;       Nothing (Display context pushed to stack)
139;   Corrupts registers:
140;       AX, BX, SI
141;--------------------------------------------------------------------
[369]142ALIGN KEYBOARD_JUMP_ALIGN
[41]143.PrepareDisplayContextForKeyboardInput:
144    pop     bx                  ; Pop return address to BX
145    mov     si, di
146
147    CALL_DISPLAY_LIBRARY PushDisplayContext
[407]148    call    DisplayCursor_GetDefaultCursorShapeToAX
[41]149    CALL_DISPLAY_LIBRARY SetCursorShapeFromAX
150    CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware
151
152    mov     di, si
153    jmp     bx
154
155
156;--------------------------------------------------------------------
157; .ProcessControlCharacter
158;   Parameters:
159;       AL:     Character inputted by user
160;       CX:     Number of bytes left in buffer
161;       BX:     Total number of characters inputted
162;       ES:DI:  Ptr where to store next character
163;   Returns:
164;       AL:     Character inputted by user or NULL if end of input
165;       BX:     Cleared if user cancellation
166;       ZF:     Set if user has ended or cancelled key input
167;       CF:     Set if character is rejected
168;   Corrupts registers:
169;       AH
170;--------------------------------------------------------------------
[369]171ALIGN KEYBOARD_JUMP_ALIGN
[41]172.ProcessControlCharacter:
173    cmp     al, CR                              ; ENTER to terminate string?
174    je      SHORT .EndCharacterInput
175    cmp     al, ESC                             ; Cancel input?
176    je      SHORT .CancelCharacterInput
177    cmp     al, BS                              ; Backspace?
178    je      SHORT .Backspace
179    jcxz    .RejectCharacter
[145]180    clc                                         ; Clear CF (ZF is already cleared)
[41]181    ret
182
183.Backspace:
184    test    bx, bx                              ; At the beginning?
185    jz      SHORT .RejectCharacter
186    inc     cx                                  ; Increment bytes left
187    dec     bx                                  ; Decrement characters inputted
188    dec     di
189    call    Keyboard_PrintBackspace
[48]190    mov     al, BS                              ; Restore character
[41]191.RejectCharacter:
192    test    al, al                              ; Clear ZF...
193    stc                                         ; ...and set CF
194    ret
195
196.CancelCharacterInput:
197    xor     bx, bx
198.EndCharacterInput:
199    xor     al, al                              ; Set ZF and clear CF
200    ret
[592]201%endif ; EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
[41]202
203
204;--------------------------------------------------------------------
205; Keyboard_PrintBackspace
206;   Parameters:
207;       Nothing
208;   Returns:
209;       Nothing
210;   Corrupts registers:
211;       AX
212;--------------------------------------------------------------------
[592]213%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
[369]214ALIGN KEYBOARD_JUMP_ALIGN
[41]215Keyboard_PrintBackspace:
216    mov     al, BS
217    call    Keyboard_PrintInputtedCharacter
218    mov     al, ' '
219    call    Keyboard_PrintInputtedCharacter
220    mov     al, BS
221    jmp     SHORT Keyboard_PrintInputtedCharacter
[131]222%endif
[41]223
224
225;--------------------------------------------------------------------
226; Keyboard_PlayBellForUnwantedKeystroke
227;   Parameters:
228;       Nothing
229;   Returns:
230;       Nothing
231;   Corrupts registers:
232;       AX
233;--------------------------------------------------------------------
[592]234%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
[369]235ALIGN KEYBOARD_JUMP_ALIGN
[41]236Keyboard_PlayBellForUnwantedKeystroke:
237    mov     al, BELL
238    ; Fall to Keyboard_PrintInputtedCharacter
[131]239%endif
[41]240
241;--------------------------------------------------------------------
242; Keyboard_PrintInputtedCharacter
243;   Parameters:
244;       AL:     Character inputted by user
245;   Returns:
246;       Nothing
247;   Corrupts registers:
248;       AX
249;--------------------------------------------------------------------
[592]250%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
[369]251ALIGN KEYBOARD_JUMP_ALIGN
[41]252Keyboard_PrintInputtedCharacter:
253    push    di
254    CALL_DISPLAY_LIBRARY PrintCharacterFromAL
[48]255    CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware    ; Hardware cursor
[41]256    pop     di
257    ret
[131]258%endif
[41]259
260
261;--------------------------------------------------------------------
262; Keyboard_RemoveAllKeystrokesFromBuffer
263;   Parameters:
264;       Nothing
265;   Returns:
266;       Nothing
267;   Corrupts registers:
268;       AX
269;--------------------------------------------------------------------
[592]270%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS               ; Only used when debugging
[369]271ALIGN KEYBOARD_JUMP_ALIGN
[41]272Keyboard_RemoveAllKeystrokesFromBuffer:
273    call    Keyboard_GetKeystrokeToAX
274    jnz     SHORT Keyboard_RemoveAllKeystrokesFromBuffer
275    ret
[133]276%endif
[41]277
278
279;--------------------------------------------------------------------
280; Keyboard_GetKeystrokeToAX
281; Keyboard_GetKeystrokeToAXandLeaveItToBuffer
282; Keyboard_GetKeystrokeToAXandWaitIfNecessary
283;   Parameters:
284;       Nothing
285;   Returns:
286;       AL:     ASCII character (if keystroke available)
287;       AH:     BIOS scan code (if keystroke available)
288;       ZF:     Set if no keystroke available
289;               Cleared if keystroke available
290;   Corrupts registers:
291;       Nothing
292;--------------------------------------------------------------------
[592]293%ifdef EXCLUDE_FROM_XUB
[492]294    %define EXCLUDE
[589]295    %ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
[492]296        %undef EXCLUDE
297    %endif
298%endif
[526]299
[492]300%ifndef EXCLUDE
[369]301ALIGN KEYBOARD_JUMP_ALIGN
[41]302Keyboard_GetKeystrokeToAXandLeaveItToBuffer:
303    mov     ah, CHECK_FOR_KEYSTROKE
304    int     BIOS_KEYBOARD_INTERRUPT_16h
305    ret
[526]306
[369]307ALIGN KEYBOARD_JUMP_ALIGN
[133]308Keyboard_GetKeystrokeToAX:
309    call    Keyboard_GetKeystrokeToAXandLeaveItToBuffer
310    jz      SHORT Keyboard_GetKeystrokeToAXReturn
311    ; Fall to Keyboard_GetKeystrokeToAXandWaitIfNecessary
[369]312ALIGN KEYBOARD_JUMP_ALIGN
[41]313Keyboard_GetKeystrokeToAXandWaitIfNecessary:
314    xor     ah, ah                      ; GET_KEYSTROKE
315    int     BIOS_KEYBOARD_INTERRUPT_16h
316    test    ax, ax                      ; Clear ZF
[133]317Keyboard_GetKeystrokeToAXReturn:
[41]318    ret
[526]319
[492]320%endif
321%undef EXCLUDE
Note: See TracBrowser for help on using the repository browser.