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

Last change on this file since 538 was 526, checked in by krille_n_@…, 11 years ago

Changes:

  • Update of the copyright notices to include the year 2013.
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;--------------------------------------------------------------------
[131]39%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[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;--------------------------------------------------------------------
[131]89%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[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
100 cld
[369]101ALIGN KEYBOARD_JUMP_ALIGN
[41]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:
[48]114 cmp al, BS ; No bell for backspace
115 je SHORT .GetCharacterFromUser
[41]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;--------------------------------------------------------------------
[369]140ALIGN KEYBOARD_JUMP_ALIGN
[41]141.PrepareDisplayContextForKeyboardInput:
142 pop bx ; Pop return address to BX
143 mov si, di
144
145 CALL_DISPLAY_LIBRARY PushDisplayContext
[407]146 call DisplayCursor_GetDefaultCursorShapeToAX
[41]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;--------------------------------------------------------------------
[369]169ALIGN KEYBOARD_JUMP_ALIGN
[41]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
[145]178 clc ; Clear CF (ZF is already cleared)
[41]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
[48]188 mov al, BS ; Restore character
[41]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
[131]199%endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]200
201
202;--------------------------------------------------------------------
203; Keyboard_PrintBackspace
204; Parameters:
205; Nothing
206; Returns:
207; Nothing
208; Corrupts registers:
209; AX
210;--------------------------------------------------------------------
[131]211%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]212ALIGN KEYBOARD_JUMP_ALIGN
[41]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
[131]220%endif
[41]221
222
223;--------------------------------------------------------------------
224; Keyboard_PlayBellForUnwantedKeystroke
225; Parameters:
226; Nothing
227; Returns:
228; Nothing
229; Corrupts registers:
230; AX
231;--------------------------------------------------------------------
[131]232%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]233ALIGN KEYBOARD_JUMP_ALIGN
[41]234Keyboard_PlayBellForUnwantedKeystroke:
235 mov al, BELL
236 ; Fall to Keyboard_PrintInputtedCharacter
[131]237%endif
[41]238
239;--------------------------------------------------------------------
240; Keyboard_PrintInputtedCharacter
241; Parameters:
242; AL: Character inputted by user
243; Returns:
244; Nothing
245; Corrupts registers:
246; AX
247;--------------------------------------------------------------------
[131]248%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]249ALIGN KEYBOARD_JUMP_ALIGN
[41]250Keyboard_PrintInputtedCharacter:
251 push di
252 CALL_DISPLAY_LIBRARY PrintCharacterFromAL
[48]253 CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware ; Hardware cursor
[41]254 pop di
255 ret
[131]256%endif
[41]257
258
259;--------------------------------------------------------------------
260; Keyboard_RemoveAllKeystrokesFromBuffer
261; Parameters:
262; Nothing
263; Returns:
264; Nothing
265; Corrupts registers:
266; AX
267;--------------------------------------------------------------------
[133]268%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS ; Only used when debugging
[369]269ALIGN KEYBOARD_JUMP_ALIGN
[41]270Keyboard_RemoveAllKeystrokesFromBuffer:
271 call Keyboard_GetKeystrokeToAX
272 jnz SHORT Keyboard_RemoveAllKeystrokesFromBuffer
273 ret
[133]274%endif
[41]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;--------------------------------------------------------------------
[492]291
292%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
293 %define EXCLUDE
294 %ifdef MODULE_HOTKEYS
295 %undef EXCLUDE
296 %endif
297 %ifdef MODULE_BOOT_MENU
298 %undef EXCLUDE
299 %endif
300%endif
[526]301
[492]302%ifndef EXCLUDE
303
[369]304ALIGN KEYBOARD_JUMP_ALIGN
[41]305Keyboard_GetKeystrokeToAXandLeaveItToBuffer:
306 mov ah, CHECK_FOR_KEYSTROKE
307 int BIOS_KEYBOARD_INTERRUPT_16h
308 ret
[526]309
[369]310ALIGN KEYBOARD_JUMP_ALIGN
[133]311Keyboard_GetKeystrokeToAX:
312 call Keyboard_GetKeystrokeToAXandLeaveItToBuffer
313 jz SHORT Keyboard_GetKeystrokeToAXReturn
314 ; Fall to Keyboard_GetKeystrokeToAXandWaitIfNecessary
[369]315ALIGN KEYBOARD_JUMP_ALIGN
[41]316Keyboard_GetKeystrokeToAXandWaitIfNecessary:
317 xor ah, ah ; GET_KEYSTROKE
318 int BIOS_KEYBOARD_INTERRUPT_16h
319 test ax, ax ; Clear ZF
[133]320Keyboard_GetKeystrokeToAXReturn:
[41]321 ret
[526]322
[492]323%endif
324%undef EXCLUDE
Note: See TracBrowser for help on using the repository browser.