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 |
|
---|
21 | BUFFER_SIZE_FOR_WORD_INPUT EQU 6 ; 5 chars + NULL
|
---|
22 |
|
---|
23 | ; Section containing code
|
---|
24 | SECTION .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_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
40 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
41 | Keyboard_ReadUserInputtedWordWhilePrinting:
|
---|
42 | push ds
|
---|
43 | push si
|
---|
44 | push cx
|
---|
45 |
|
---|
46 | mov cl, BUFFER_SIZE_FOR_WORD_INPUT
|
---|
47 | call Memory_ReserveCLbytesFromStackToDSSI
|
---|
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_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
90 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
91 | Keyboard_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 | %ifdef CLD_NEEDED
|
---|
101 | cld
|
---|
102 | %endif
|
---|
103 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
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:
|
---|
116 | cmp al, BS ; No bell for backspace
|
---|
117 | je SHORT .GetCharacterFromUser
|
---|
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 | ;--------------------------------------------------------------------
|
---|
142 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
143 | .PrepareDisplayContextForKeyboardInput:
|
---|
144 | pop bx ; Pop return address to BX
|
---|
145 | mov si, di
|
---|
146 |
|
---|
147 | CALL_DISPLAY_LIBRARY PushDisplayContext
|
---|
148 | call DisplayCursor_GetDefaultCursorShapeToAX
|
---|
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 | ;--------------------------------------------------------------------
|
---|
171 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
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
|
---|
180 | clc ; Clear CF (ZF is already cleared)
|
---|
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
|
---|
190 | mov al, BS ; Restore character
|
---|
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
|
---|
201 | %endif ; EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
202 |
|
---|
203 |
|
---|
204 | ;--------------------------------------------------------------------
|
---|
205 | ; Keyboard_PrintBackspace
|
---|
206 | ; Parameters:
|
---|
207 | ; Nothing
|
---|
208 | ; Returns:
|
---|
209 | ; Nothing
|
---|
210 | ; Corrupts registers:
|
---|
211 | ; AX
|
---|
212 | ;--------------------------------------------------------------------
|
---|
213 | %ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
214 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
215 | Keyboard_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
|
---|
222 | %endif
|
---|
223 |
|
---|
224 |
|
---|
225 | ;--------------------------------------------------------------------
|
---|
226 | ; Keyboard_PlayBellForUnwantedKeystroke
|
---|
227 | ; Parameters:
|
---|
228 | ; Nothing
|
---|
229 | ; Returns:
|
---|
230 | ; Nothing
|
---|
231 | ; Corrupts registers:
|
---|
232 | ; AX
|
---|
233 | ;--------------------------------------------------------------------
|
---|
234 | %ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
235 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
236 | Keyboard_PlayBellForUnwantedKeystroke:
|
---|
237 | mov al, BELL
|
---|
238 | ; Fall to Keyboard_PrintInputtedCharacter
|
---|
239 | %endif
|
---|
240 |
|
---|
241 | ;--------------------------------------------------------------------
|
---|
242 | ; Keyboard_PrintInputtedCharacter
|
---|
243 | ; Parameters:
|
---|
244 | ; AL: Character inputted by user
|
---|
245 | ; Returns:
|
---|
246 | ; Nothing
|
---|
247 | ; Corrupts registers:
|
---|
248 | ; AX
|
---|
249 | ;--------------------------------------------------------------------
|
---|
250 | %ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
251 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
252 | Keyboard_PrintInputtedCharacter:
|
---|
253 | push di
|
---|
254 | CALL_DISPLAY_LIBRARY PrintCharacterFromAL
|
---|
255 | CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware ; Hardware cursor
|
---|
256 | pop di
|
---|
257 | ret
|
---|
258 | %endif
|
---|
259 |
|
---|
260 |
|
---|
261 | ;--------------------------------------------------------------------
|
---|
262 | ; Keyboard_RemoveAllKeystrokesFromBuffer
|
---|
263 | ; Parameters:
|
---|
264 | ; Nothing
|
---|
265 | ; Returns:
|
---|
266 | ; Nothing
|
---|
267 | ; Corrupts registers:
|
---|
268 | ; AX
|
---|
269 | ;--------------------------------------------------------------------
|
---|
270 | %ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS ; Only used when debugging
|
---|
271 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
272 | Keyboard_RemoveAllKeystrokesFromBuffer:
|
---|
273 | call Keyboard_GetKeystrokeToAX
|
---|
274 | jnz SHORT Keyboard_RemoveAllKeystrokesFromBuffer
|
---|
275 | ret
|
---|
276 | %endif
|
---|
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 | ;--------------------------------------------------------------------
|
---|
293 | %ifdef EXCLUDE_FROM_XUB
|
---|
294 | %define EXCLUDE
|
---|
295 | %ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
|
---|
296 | %undef EXCLUDE
|
---|
297 | %endif
|
---|
298 | %endif
|
---|
299 |
|
---|
300 | %ifndef EXCLUDE
|
---|
301 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
302 | Keyboard_GetKeystrokeToAXandLeaveItToBuffer:
|
---|
303 | mov ah, CHECK_FOR_KEYSTROKE
|
---|
304 | int BIOS_KEYBOARD_INTERRUPT_16h
|
---|
305 | ret
|
---|
306 |
|
---|
307 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
308 | Keyboard_GetKeystrokeToAX:
|
---|
309 | call Keyboard_GetKeystrokeToAXandLeaveItToBuffer
|
---|
310 | jz SHORT Keyboard_GetKeystrokeToAXReturn
|
---|
311 | ; Fall to Keyboard_GetKeystrokeToAXandWaitIfNecessary
|
---|
312 | ALIGN KEYBOARD_JUMP_ALIGN
|
---|
313 | Keyboard_GetKeystrokeToAXandWaitIfNecessary:
|
---|
314 | xor ah, ah ; GET_KEYSTROKE
|
---|
315 | int BIOS_KEYBOARD_INTERRUPT_16h
|
---|
316 | test ax, ax ; Clear ZF
|
---|
317 | Keyboard_GetKeystrokeToAXReturn:
|
---|
318 | ret
|
---|
319 |
|
---|
320 | %endif
|
---|
321 | %undef EXCLUDE
|
---|