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

Last change on this file since 369 was 369, checked in by gregli@…, 12 years ago

Removed align directives for initalization code and added define for align in boot-time calls to the assembly library (defaulting to 1), resulting in a significant savings for the AT and 386 builds. Fixed a bug with switch command line handling in the serial server. Put in CR characters in licesnse.txt, so that it properly displays on Windows. In the configurator, added default values for user supplied CHS and LBA values, defaulting to values within range when those features are enabled. Updated the copyright message in the configurator as the literal word Copyright is important.

File size: 8.4 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for managing keyboard.
3
4BUFFER_SIZE_FOR_WORD_INPUT EQU 6 ; 5 chars + NULL
5
6; Section containing code
7SECTION .text
8
9;--------------------------------------------------------------------
10; Reads user inputted word.
11; Function returns when ENTER or ESC will be pressed.
12;
13; Keyboard_ReadUserInputtedWordWhilePrinting
14; Parameters
15; BX: Numeric base (10 or 16)
16; Returns:
17; AX: User inputted word
18; ZF: Set if user cancellation
19; Corrupts registers:
20; DX
21;--------------------------------------------------------------------
22%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
23ALIGN KEYBOARD_JUMP_ALIGN
24Keyboard_ReadUserInputtedWordWhilePrinting:
25 push ds
26 push si
27 push cx
28
29 mov cx, BUFFER_SIZE_FOR_WORD_INPUT
30 call Memory_ReserveCXbytesFromStackToDSSI
31
32 call Char_GetFilterFunctionToDXforNumericBaseInBX
33 call Registers_ExchangeDSSIwithESDI
34 call Keyboard_ReadUserInputtedStringToESDIWhilePrinting
35 call Registers_ExchangeDSSIwithESDI ; Does not modify FLAGS
36 jz SHORT .CancelledByUser
37
38 call String_ConvertWordToAXfromStringInDSSIwithBaseInBX
39.CancelledByUser:
40 add sp, BYTE BUFFER_SIZE_FOR_WORD_INPUT
41 test cx, cx ; Set ZF if string length is zero
42 pop cx
43 pop si
44 pop ds
45 ret
46%endif
47
48
49;--------------------------------------------------------------------
50; Reads user inputted string to buffer. Character filter is
51; supported to ignore unwanted characters.
52; Function returns when ENTER or ESC will be pressed.
53;
54; Keyboard_ReadUserInputtedStringToESDIWhilePrinting
55; Parameters:
56; CX: Buffer size (with NULL)
57; ES:DI: Ptr to destination buffer
58; CS:DX: Ptr to character filter function:
59; Parameters:
60; AL: Character inputted by user
61; Returns:
62; CF: Set if character is accepted
63; Cleared if character is rejected
64; Corrupts registers:
65; Nothing
66; Returns:
67; CX: String length in characters (without NULL)
68; ZF: Set if user cancellation
69; Corrupts registers:
70; AX
71;--------------------------------------------------------------------
72%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
73ALIGN KEYBOARD_JUMP_ALIGN
74Keyboard_ReadUserInputtedStringToESDIWhilePrinting:
75 push di
76 push si
77 push bx
78 call .PrepareDisplayContextForKeyboardInput
79 jcxz .ReturnAfterUpdatingZF
80
81 xor bx, bx ; Zero character counter
82 dec cx ; Decrement buffer size for NULL
83 cld
84ALIGN KEYBOARD_JUMP_ALIGN
85.GetCharacterFromUser:
86 call Keyboard_GetKeystrokeToAXandWaitIfNecessary ; Get ASCII to AL
87 call .ProcessControlCharacter
88 jz SHORT .TerminateStringWithNULL
89 jc SHORT .PlayBellForRejectedCharacter
90 call dx ; Filter character
91 jnc SHORT .PlayBellForRejectedCharacter
92 inc bx ; Increment number of characters stored
93 stosb ; Store from AL to ES:DI
94 call Keyboard_PrintInputtedCharacter
95 loop .GetCharacterFromUser
96.PlayBellForRejectedCharacter:
97 cmp al, BS ; No bell for backspace
98 je SHORT .GetCharacterFromUser
99 call Keyboard_PlayBellForUnwantedKeystroke
100 jmp SHORT .GetCharacterFromUser
101
102.TerminateStringWithNULL:
103 stosb ; Terminate string with NULL
104 mov cx, bx ; String length now in CX
105
106.ReturnAfterUpdatingZF:
107 CALL_DISPLAY_LIBRARY PopDisplayContext
108 test cx, cx ; Clear or set ZF
109 pop bx
110 pop si
111 pop di
112 ret
113
114;--------------------------------------------------------------------
115; .PrepareDisplayContextForKeyboardInput
116; Parameters:
117; Nothing
118; Returns:
119; Nothing (Display context pushed to stack)
120; Corrupts registers:
121; AX, BX, SI
122;--------------------------------------------------------------------
123ALIGN KEYBOARD_JUMP_ALIGN
124.PrepareDisplayContextForKeyboardInput:
125 pop bx ; Pop return address to BX
126 mov si, di
127
128 CALL_DISPLAY_LIBRARY PushDisplayContext
129 mov ax, CURSOR_NORMAL
130 CALL_DISPLAY_LIBRARY SetCursorShapeFromAX
131 CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware
132
133 mov di, si
134 jmp bx
135
136
137;--------------------------------------------------------------------
138; .ProcessControlCharacter
139; Parameters:
140; AL: Character inputted by user
141; CX: Number of bytes left in buffer
142; BX: Total number of characters inputted
143; ES:DI: Ptr where to store next character
144; Returns:
145; AL: Character inputted by user or NULL if end of input
146; BX: Cleared if user cancellation
147; ZF: Set if user has ended or cancelled key input
148; CF: Set if character is rejected
149; Corrupts registers:
150; AH
151;--------------------------------------------------------------------
152ALIGN KEYBOARD_JUMP_ALIGN
153.ProcessControlCharacter:
154 cmp al, CR ; ENTER to terminate string?
155 je SHORT .EndCharacterInput
156 cmp al, ESC ; Cancel input?
157 je SHORT .CancelCharacterInput
158 cmp al, BS ; Backspace?
159 je SHORT .Backspace
160 jcxz .RejectCharacter
161 clc ; Clear CF (ZF is already cleared)
162 ret
163
164.Backspace:
165 test bx, bx ; At the beginning?
166 jz SHORT .RejectCharacter
167 inc cx ; Increment bytes left
168 dec bx ; Decrement characters inputted
169 dec di
170 call Keyboard_PrintBackspace
171 mov al, BS ; Restore character
172.RejectCharacter:
173 test al, al ; Clear ZF...
174 stc ; ...and set CF
175 ret
176
177.CancelCharacterInput:
178 xor bx, bx
179.EndCharacterInput:
180 xor al, al ; Set ZF and clear CF
181 ret
182%endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
183
184
185;--------------------------------------------------------------------
186; Keyboard_PrintBackspace
187; Parameters:
188; Nothing
189; Returns:
190; Nothing
191; Corrupts registers:
192; AX
193;--------------------------------------------------------------------
194%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
195ALIGN KEYBOARD_JUMP_ALIGN
196Keyboard_PrintBackspace:
197 mov al, BS
198 call Keyboard_PrintInputtedCharacter
199 mov al, ' '
200 call Keyboard_PrintInputtedCharacter
201 mov al, BS
202 jmp SHORT Keyboard_PrintInputtedCharacter
203%endif
204
205
206;--------------------------------------------------------------------
207; Keyboard_PlayBellForUnwantedKeystroke
208; Parameters:
209; Nothing
210; Returns:
211; Nothing
212; Corrupts registers:
213; AX
214;--------------------------------------------------------------------
215%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
216ALIGN KEYBOARD_JUMP_ALIGN
217Keyboard_PlayBellForUnwantedKeystroke:
218 mov al, BELL
219 ; Fall to Keyboard_PrintInputtedCharacter
220%endif
221
222;--------------------------------------------------------------------
223; Keyboard_PrintInputtedCharacter
224; Parameters:
225; AL: Character inputted by user
226; Returns:
227; Nothing
228; Corrupts registers:
229; AX
230;--------------------------------------------------------------------
231%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
232ALIGN KEYBOARD_JUMP_ALIGN
233Keyboard_PrintInputtedCharacter:
234 push di
235 CALL_DISPLAY_LIBRARY PrintCharacterFromAL
236 CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware ; Hardware cursor
237 pop di
238 ret
239%endif
240
241
242;--------------------------------------------------------------------
243; Keyboard_RemoveAllKeystrokesFromBuffer
244; Parameters:
245; Nothing
246; Returns:
247; Nothing
248; Corrupts registers:
249; AX
250;--------------------------------------------------------------------
251%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS ; Only used when debugging
252ALIGN KEYBOARD_JUMP_ALIGN
253Keyboard_RemoveAllKeystrokesFromBuffer:
254 call Keyboard_GetKeystrokeToAX
255 jnz SHORT Keyboard_RemoveAllKeystrokesFromBuffer
256 ret
257%endif
258
259
260;--------------------------------------------------------------------
261; Keyboard_GetKeystrokeToAX
262; Keyboard_GetKeystrokeToAXandLeaveItToBuffer
263; Keyboard_GetKeystrokeToAXandWaitIfNecessary
264; Parameters:
265; Nothing
266; Returns:
267; AL: ASCII character (if keystroke available)
268; AH: BIOS scan code (if keystroke available)
269; ZF: Set if no keystroke available
270; Cleared if keystroke available
271; Corrupts registers:
272; Nothing
273;--------------------------------------------------------------------
274ALIGN KEYBOARD_JUMP_ALIGN
275Keyboard_GetKeystrokeToAXandLeaveItToBuffer:
276 mov ah, CHECK_FOR_KEYSTROKE
277 int BIOS_KEYBOARD_INTERRUPT_16h
278 ret
279ALIGN KEYBOARD_JUMP_ALIGN
280Keyboard_GetKeystrokeToAX:
281 call Keyboard_GetKeystrokeToAXandLeaveItToBuffer
282 jz SHORT Keyboard_GetKeystrokeToAXReturn
283 ; Fall to Keyboard_GetKeystrokeToAXandWaitIfNecessary
284ALIGN KEYBOARD_JUMP_ALIGN
285Keyboard_GetKeystrokeToAXandWaitIfNecessary:
286 xor ah, ah ; GET_KEYSTROKE
287 int BIOS_KEYBOARD_INTERRUPT_16h
288 test ax, ax ; Clear ZF
289Keyboard_GetKeystrokeToAXReturn:
290 ret
Note: See TracBrowser for help on using the repository browser.