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

Last change on this file since 589 was 589, checked in by krille_n_, 8 years ago

Changes:

  • BIOS: Fixed a purely cosmetic bug from r542 where, in builds containing MODULE_EBIOS, the boot menu would display an incorrect drive size (0.4 kB with MODULE_STRINGS_COMPRESSED or 0.5 kB without) for old drives with no support for LBA.
  • Fixed a bug from r392 where Vision_DetectAndReturnIDinAXandPortInDXifControllerPresent would return the ID in AL instead of AH (if DANGEROUS_DETECTION had been defined).
  • Fixed a bug from r587 in AdvAtaInit.asm that would prevent detection of QDI Vision controllers.
  • Also changed how the QDI Vision IDs are defined (removed the need for shifting) to avoid confusion. This fixed a potential bug from r587 in AdvAtaInit.asm where some IDs were not being shifted.
  • Fixed a bug in PDC20x30.asm from r587 where GetPdcIDtoAX would not return with the IDE base port in DX so DisablePdcProgrammingMode would fail.
  • Made some changes to ModuleDependency.inc and other files so that MODULE_ADVANCED_ATA now requires USE_386. Consequently it is no longer included in the regular AT-builds, only in the 386_8k-build.
  • Moved the UNROLL_SECTORS_IN_CX_TO_xWORDS macros from IDE_8bit.inc to IdeIO.inc which means it's now possible to build a BIOS without MODULE_8BIT_IDE.
  • XTIDECFG: Added a minimum DOS version check (since it needs DOS version 2+) to allow the program to quit gracefully in the unlikely scenario where someone tries to run it under DOS version 1.
  • Made some changes to Drive.asm to improve drive enumeration. The old method using GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE worked well in Windows XP but not in Windows 98 SE (in Windows or in DOS mode). The two problems were; 1) The function call would access the drives which on single floppy drive systems would cause Windows to swap between A: and B: (throwing a blue screen asking the user to insert a disk etc). 2) Only floppy drives and FAT16 drives would be available in the list of drives, no FAT32/optical/network drives.
  • Improved code in IdeControllerMenu.asm so that the default port addresses for all IDE interfaces are now restored when (re-)selecting the (same) type of IDE device.
  • Also made it impossible to select a device type unless the required module is included in the loaded BIOS.
  • The version check done when loading a BIOS now uses the FLASH_SIGNATURE definition from Version.inc. Any changes affecting RomVars now only requires updating that definition. This means that changes to RomVars must be implemented in both the BIOS and XTIDECFG before being committed to the repository.
  • Added a compatibility fix for 3Com 3C503 cards to the ROM checksumming code in Buffers.asm (Buffers_GenerateChecksum).
  • SerDrive: Made some minor changes to file names and paths to improve compatibility with case sensitive environments.
  • BIOSDRVS: Made a minor size optimization which as a side effect also makes it compatible with all DOS versions including DOS version 1.
  • Library: Renamed the WAIT_RETRACE_IF_NECESSARY_THEN macro to CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN and made a tail-call-optimized version of it (JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN).
  • A speed optimization to the eRCL_IM macro for 386 and higher. This change breaks emulation in the sense that the macro will fail when given a memory operand as the first parameter.
  • Other minor optimizations and fixes.
File size: 9.2 KB
Line 
1; Project name  :   Assembly Library
2; Description   :   Functions for managing keyboard.
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
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.
29;
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;--------------------------------------------------------------------
39%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
40ALIGN KEYBOARD_JUMP_ALIGN
41Keyboard_ReadUserInputtedWordWhilePrinting:
42    push    ds
43    push    si
44    push    cx
45
46    mov     cx, BUFFER_SIZE_FOR_WORD_INPUT
47    call    Memory_ReserveCXbytesFromStackToDSSI
48
49    call    Char_GetFilterFunctionToDXforNumericBaseInBX
50    call    Registers_ExchangeDSSIwithESDI
51    call    Keyboard_ReadUserInputtedStringToESDIWhilePrinting
52    call    Registers_ExchangeDSSIwithESDI  ; Does not modify FLAGS
53    jz      SHORT .CancelledByUser
54
55    call    String_ConvertWordToAXfromStringInDSSIwithBaseInBX
56.CancelledByUser:
57    add     sp, BYTE BUFFER_SIZE_FOR_WORD_INPUT
58    test    cx, cx                          ; Set ZF if string length is zero
59    pop     cx
60    pop     si
61    pop     ds
62    ret
63%endif
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.
70;
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;--------------------------------------------------------------------
89%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
90ALIGN KEYBOARD_JUMP_ALIGN
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
100    cld
101ALIGN KEYBOARD_JUMP_ALIGN
102.GetCharacterFromUser:
103    call    Keyboard_GetKeystrokeToAXandWaitIfNecessary ; Get ASCII to AL
104    call    .ProcessControlCharacter
105    jz      SHORT .TerminateStringWithNULL
106    jc      SHORT .PlayBellForRejectedCharacter
107    call    dx                                  ; Filter character
108    jnc     SHORT .PlayBellForRejectedCharacter
109    inc     bx                                  ; Increment number of characters stored
110    stosb                                       ; Store from AL to ES:DI
111    call    Keyboard_PrintInputtedCharacter
112    loop    .GetCharacterFromUser
113.PlayBellForRejectedCharacter:
114    cmp     al, BS                              ; No bell for backspace
115    je      SHORT .GetCharacterFromUser
116    call    Keyboard_PlayBellForUnwantedKeystroke
117    jmp     SHORT .GetCharacterFromUser
118
119.TerminateStringWithNULL:
120    stosb                                       ; Terminate string with NULL
121    mov     cx, bx                              ; String length now in CX
122
123.ReturnAfterUpdatingZF:
124    CALL_DISPLAY_LIBRARY PopDisplayContext
125    test    cx, cx                              ; Clear or set ZF
126    pop     bx
127    pop     si
128    pop     di
129    ret
130
131;--------------------------------------------------------------------
132; .PrepareDisplayContextForKeyboardInput
133;   Parameters:
134;       Nothing
135;   Returns:
136;       Nothing (Display context pushed to stack)
137;   Corrupts registers:
138;       AX, BX, SI
139;--------------------------------------------------------------------
140ALIGN KEYBOARD_JUMP_ALIGN
141.PrepareDisplayContextForKeyboardInput:
142    pop     bx                  ; Pop return address to BX
143    mov     si, di
144
145    CALL_DISPLAY_LIBRARY PushDisplayContext
146    call    DisplayCursor_GetDefaultCursorShapeToAX
147    CALL_DISPLAY_LIBRARY SetCursorShapeFromAX
148    CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware
149
150    mov     di, si
151    jmp     bx
152
153
154;--------------------------------------------------------------------
155; .ProcessControlCharacter
156;   Parameters:
157;       AL:     Character inputted by user
158;       CX:     Number of bytes left in buffer
159;       BX:     Total number of characters inputted
160;       ES:DI:  Ptr where to store next character
161;   Returns:
162;       AL:     Character inputted by user or NULL if end of input
163;       BX:     Cleared if user cancellation
164;       ZF:     Set if user has ended or cancelled key input
165;       CF:     Set if character is rejected
166;   Corrupts registers:
167;       AH
168;--------------------------------------------------------------------
169ALIGN KEYBOARD_JUMP_ALIGN
170.ProcessControlCharacter:
171    cmp     al, CR                              ; ENTER to terminate string?
172    je      SHORT .EndCharacterInput
173    cmp     al, ESC                             ; Cancel input?
174    je      SHORT .CancelCharacterInput
175    cmp     al, BS                              ; Backspace?
176    je      SHORT .Backspace
177    jcxz    .RejectCharacter
178    clc                                         ; Clear CF (ZF is already cleared)
179    ret
180
181.Backspace:
182    test    bx, bx                              ; At the beginning?
183    jz      SHORT .RejectCharacter
184    inc     cx                                  ; Increment bytes left
185    dec     bx                                  ; Decrement characters inputted
186    dec     di
187    call    Keyboard_PrintBackspace
188    mov     al, BS                              ; Restore character
189.RejectCharacter:
190    test    al, al                              ; Clear ZF...
191    stc                                         ; ...and set CF
192    ret
193
194.CancelCharacterInput:
195    xor     bx, bx
196.EndCharacterInput:
197    xor     al, al                              ; Set ZF and clear CF
198    ret
199%endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
200
201
202;--------------------------------------------------------------------
203; Keyboard_PrintBackspace
204;   Parameters:
205;       Nothing
206;   Returns:
207;       Nothing
208;   Corrupts registers:
209;       AX
210;--------------------------------------------------------------------
211%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
212ALIGN KEYBOARD_JUMP_ALIGN
213Keyboard_PrintBackspace:
214    mov     al, BS
215    call    Keyboard_PrintInputtedCharacter
216    mov     al, ' '
217    call    Keyboard_PrintInputtedCharacter
218    mov     al, BS
219    jmp     SHORT Keyboard_PrintInputtedCharacter
220%endif
221
222
223;--------------------------------------------------------------------
224; Keyboard_PlayBellForUnwantedKeystroke
225;   Parameters:
226;       Nothing
227;   Returns:
228;       Nothing
229;   Corrupts registers:
230;       AX
231;--------------------------------------------------------------------
232%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
233ALIGN KEYBOARD_JUMP_ALIGN
234Keyboard_PlayBellForUnwantedKeystroke:
235    mov     al, BELL
236    ; Fall to Keyboard_PrintInputtedCharacter
237%endif
238
239;--------------------------------------------------------------------
240; Keyboard_PrintInputtedCharacter
241;   Parameters:
242;       AL:     Character inputted by user
243;   Returns:
244;       Nothing
245;   Corrupts registers:
246;       AX
247;--------------------------------------------------------------------
248%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
249ALIGN KEYBOARD_JUMP_ALIGN
250Keyboard_PrintInputtedCharacter:
251    push    di
252    CALL_DISPLAY_LIBRARY PrintCharacterFromAL
253    CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware    ; Hardware cursor
254    pop     di
255    ret
256%endif
257
258
259;--------------------------------------------------------------------
260; Keyboard_RemoveAllKeystrokesFromBuffer
261;   Parameters:
262;       Nothing
263;   Returns:
264;       Nothing
265;   Corrupts registers:
266;       AX
267;--------------------------------------------------------------------
268%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS   ; Only used when debugging
269ALIGN KEYBOARD_JUMP_ALIGN
270Keyboard_RemoveAllKeystrokesFromBuffer:
271    call    Keyboard_GetKeystrokeToAX
272    jnz     SHORT Keyboard_RemoveAllKeystrokesFromBuffer
273    ret
274%endif
275
276
277;--------------------------------------------------------------------
278; Keyboard_GetKeystrokeToAX
279; Keyboard_GetKeystrokeToAXandLeaveItToBuffer
280; Keyboard_GetKeystrokeToAXandWaitIfNecessary
281;   Parameters:
282;       Nothing
283;   Returns:
284;       AL:     ASCII character (if keystroke available)
285;       AH:     BIOS scan code (if keystroke available)
286;       ZF:     Set if no keystroke available
287;               Cleared if keystroke available
288;   Corrupts registers:
289;       Nothing
290;--------------------------------------------------------------------
291%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
292    %define EXCLUDE
293    %ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
294        %undef EXCLUDE
295    %endif
296%endif
297
298%ifndef EXCLUDE
299ALIGN KEYBOARD_JUMP_ALIGN
300Keyboard_GetKeystrokeToAXandLeaveItToBuffer:
301    mov     ah, CHECK_FOR_KEYSTROKE
302    int     BIOS_KEYBOARD_INTERRUPT_16h
303    ret
304
305ALIGN KEYBOARD_JUMP_ALIGN
306Keyboard_GetKeystrokeToAX:
307    call    Keyboard_GetKeystrokeToAXandLeaveItToBuffer
308    jz      SHORT Keyboard_GetKeystrokeToAXReturn
309    ; Fall to Keyboard_GetKeystrokeToAXandWaitIfNecessary
310ALIGN KEYBOARD_JUMP_ALIGN
311Keyboard_GetKeystrokeToAXandWaitIfNecessary:
312    xor     ah, ah                      ; GET_KEYSTROKE
313    int     BIOS_KEYBOARD_INTERRUPT_16h
314    test    ax, ax                      ; Clear ZF
315Keyboard_GetKeystrokeToAXReturn:
316    ret
317
318%endif
319%undef EXCLUDE
Note: See TracBrowser for help on using the repository browser.