DRF
User
 Platinum Osdever
| Posts: 123 |   | Karma: 1
|
Re: string input - 2005/05/29 10:46
Don't worry about the driver, in real mode which you say you are using you can use the BIOS interrupt (as the previous poster said). The interrupt to call is 16h. The function is 0. It should return the scan code in AH and the ASCII code in AL.
So you need to make a simple loop which: Run 'int 16h' al=0 Compare al with the return key value (0x0D) If the compared values are the same jmp to end. Store AL in memory some where. Loop back round to the start.
In the spirt of sharing I'll cut and paste my code below (which I wrote for an early OS of mine so the values/useage might be a bit different as it does a few extra things but you might get some ideas from it).
| Code: |
; Scanf - Get a string from the keyboard, until the key is pressed
; DI must be set before running command to the command variable. (CmdStr)
; Output the keyboard value to the variable in DI.
; Limited to dx chars, and will start at the start of the string.
; If CX contains a 1 then the string is not to be displayed
Scanf:
xor bx,bx ; Zero BX (string location counter/pointer)
.start
; Make the BIOS call
xor ax,ax ; Function 0, read keyboard char
int 16h ; Keyboard interrupt (outputs char to al)
; Check to see if the return key was pressed
cmp al, 0x0D ; Compare to ASCII char code
je .return ; If equal make the jump
; Save the character to a location
mov [es:di+bx],al ; String Location + Num chars from start
inc bx ; Increase BX for next char
; Max string size
cmp bx, dx ; Compare the length with the max size entered
je .return ; No error message, just act as though return pressed
; Display or not?
push bx ; Save bx
xor bx,bx
cmp bx,cx ; Compare cx to see what value was passed
je .putchar
.putcharReturn
;pop bx ; Restore bx (Done before reaching this point!)
jmp .start ; Loop for next char input
.putchar
pop bx ; Restore bx
push ax ; Save the registers
push bx
xor ah,ah
mov si,ax ; Move the ASCII char to the register
call putchar ; Call the procedure
pop bx ; Restore the registers
pop ax
jmp .putcharReturn ; Return
.return
xor al,al ; 0 to indicate the end of the string
mov [es:di+bx],al
ret ; Return
|
Which I called using:
| Code: |
mov di, CmdStr ; Location to store keyboard input
mov dx, 40 ; Max size
xor cx, cx ; 0 = Display char
call Scanf ; Make the call
|
CmdStr was just a variable of in this case 40bytes I zeroed and reserved for use to store the inputted 'string' containing a command at the prompt.
Hope that helps a little (sorry about the size of my code/bodge job style of my code).
If you want any help later on the backspace/cursor buttons just ask (thought I should paste a simpler earlier version of my scanf code).
Daniel
|