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

Last change on this file since 416 was 407, checked in by aitotat@…, 13 years ago

Changes to Assembly Library:

  • One more attempt to properly restore MDA cursor after exiting menu.
File size: 9.1 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-2012 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;--------------------------------------------------------------------
291ALIGN KEYBOARD_JUMP_ALIGN
292Keyboard_GetKeystrokeToAXandLeaveItToBuffer:
293 mov ah, CHECK_FOR_KEYSTROKE
294 int BIOS_KEYBOARD_INTERRUPT_16h
295 ret
296ALIGN KEYBOARD_JUMP_ALIGN
297Keyboard_GetKeystrokeToAX:
298 call Keyboard_GetKeystrokeToAXandLeaveItToBuffer
299 jz SHORT Keyboard_GetKeystrokeToAXReturn
300 ; Fall to Keyboard_GetKeystrokeToAXandWaitIfNecessary
301ALIGN KEYBOARD_JUMP_ALIGN
302Keyboard_GetKeystrokeToAXandWaitIfNecessary:
303 xor ah, ah ; GET_KEYSTROKE
304 int BIOS_KEYBOARD_INTERRUPT_16h
305 test ax, ax ; Clear ZF
306Keyboard_GetKeystrokeToAXReturn:
307 ret
Note: See TracBrowser for help on using the repository browser.