flat assembler
Message board for the users of flat assembler.
Index
> DOS > User input? |
Author |
|
adroit 23 Feb 2010, 16:06
I spent the last few hours trying to figure out how to get user's input. But I was unsuccessful. So I took a look at some code from "console fun" by Bitshifter. The coding was brilliant (from my perspective). I tried to duplicate the code in my way, but it didn't work. Please tell the errors in the code:
Let's say the user enters: "MeshNix" The program would output: "Hi MeshNix!!!" the go on a new line, then prompt again. The virtual keys such as backspace don't work. And also when the enter key is pressed, the prompt comes back on the same line instead of a newline Code: org 100h jmp Start buffer rb 16 length db 0 maxlen db 15 startmsg db 'Enter something here: ',0 nextmsg1 db 'Hi ',0 nextmsg2 db '!!!',0 newline db 13,10,0 Start: ;set to graphic mode 3 mov al,03h mov ah,0 int 10h .reset: ;reset prompt buffer mov [buffer],0 ;set buffer to 0 mov [length],0 ;set length to 0 mov di,buffer ;print prompt mov si, startmsg call PrintString .input: ;wait for keystroke xor ax,ax int 16h ;handle special keys cmp al,1Bh ;VK_ESCAPE je .vk_escape cmp al,08H ;VK_BACK je .vk_back cmp al,1DH ;VK_RETURN je .vk_return ;is buffer full mov ah,[length] cmp ah,[maxlen] je .input ;append character to buffer mov byte[di],al inc di mov byte[di],0 inc [length] ;print character call PrintChar jmp .input .vk_escape: ;exit program ret .vk_back: ;remove character from buffer dec di ;decrease buffer pointer mov byte[di],0 ;insert NULL terminator dec [length] ;decrement rompt length jmp .input .vk_return: ;check form empty command buffer cmp [length],0 je .input call ProcessInput jmp .reset ;Call procedures PrintString: jmp GetChar ;skip echo - no character in al as yet EchoChar: mov ah,0Eh int 10h ;Get character from string GetChar: mov al,[si] ;extract character from string inc si ;step up on stack (skip last byte) or al,al ;is string complete printer (is al =0) jz .finish ;if so end procedure jmp EchoChar ;else repeat process ;return to call address .finish: ret ;print character PrintChar: mov ah,0Eh int 10h ret ;return to call address ;process input from user ProcessInput: inc si ;print nextmsg1 mov si,nextmsg1 call PrintString inc si ;print data in buffer mov si,buffer call PrintString inc si ;print nextmsg2 mov si,nextmsg2 call PrintString inc si ret Help me please!!! _________________ meshnix |
|||
23 Feb 2010, 16:06 |
|
Picnic 23 Feb 2010, 18:31
Hi MeshNix,
The INT 21h / AH=0Ah interrupt provides a simple way to read user input. See the last post by daluca here |
|||
23 Feb 2010, 18:31 |
|
bitshifter 23 Feb 2010, 19:41
This may be the problem:
Code: cmp al,1DH ;VK_RETURN It should be Code: cmp al,0DH ;VK_RETURN |
|||
23 Feb 2010, 19:41 |
|
bitshifter 23 Feb 2010, 20:09
You need to specify newlines...
Change your code to this and its fixed! Code: nextmsg1 db 13,10,'Hi ',0 nextmsg2 db '!!!',13,10,0 |
|||
23 Feb 2010, 20:09 |
|
Picnic 23 Feb 2010, 20:43
MeshNix wrote: I like Bitshifter's code because it was (what I would call) raw. |
|||
23 Feb 2010, 20:43 |
|
adroit 24 Feb 2010, 23:05
Thanks a lot
... |
|||
24 Feb 2010, 23:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.