flat assembler
Message board for the users of flat assembler.

Index > OS Construction > getting keyboard input?

Author
Thread Post new topic Reply to topic
oscar



Joined: 01 Feb 2006
Posts: 5
oscar
Hi, I'm trying to make a macro for reading the keyboard input (ala command line) but after looking for a few days i can't find any tutorials and all the code i've found in other OSes seems to be intertwined with lots of other parts of the codebase.


How can I read the input from the keyboard and print it to the screen as well as keep it for posible execution when the enter key is pressed?

this is what i've come up with so far :/

Code:
Macro Input prompt{

.GetInput:
        int 21h
        mov ah, 01
        cmp al, 02
        je .Pstring
        jmp .GetInput
.Pstring:

       ;put print character to screen stuff here
        
}                     
    


I know it is awfully wrong and i thank you eternally for any small piece of help you can give me in advance Smile


THANKYOU
Post 23 Jan 2007, 04:30
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
in OS construction, you probably can't use int 21h. You have to use int 16h.
Post 23 Jan 2007, 07:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
oscar



Joined: 01 Feb 2006
Posts: 5
oscar
thanks heaps!

So far i have it to the point of recognising what key is hit (loops through until enter is hit) but i still can't get it to print it to the screen.

Code:
Macro Input prompt{

        local .GetInput
        local .Done
        local .Var

        Write prompt ; reference to macro that prints to screen without going to newline

        .GetInput:
                int 16h
                mov ah, 0

               ;### start print string
               .Var db [al],0

                mov si, .Var
                mov ah, 0Eh
                int 10h

        jmp .GetInput



               ;### end print

                cmp al, 13
                jz .Done
                jmp .GetInput

        .Done:
                NewLine ;reference toanother macro which prints newline to the screen
}
    
Post 23 Jan 2007, 10:10
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Here is some code from MiniDOS that may help:
http://board.flatassembler.net/topic.php?t=5275&start=0
Code:
;====================================================;
; GetCommand                                         ;
;====================================================;
GetCommand:
        pusha                               ; Save genral regs
        push  es                            ; Save ES
        push  cs                            ; Move CS to stack
        pop   es                            ; Move CS from stack in to ES
        mov   di,CommandBuffer              ; Move the address of CommandBuffer in DI
        mov   cx,64                         ; move 64 in to counter
        mov   dx,di                         ; Remember initial offset
getkey:
        xor   ax,ax                         ; Get a key
        int   16h                           ; Call interrupt service
        cmp   al,13                         ; Enter?
        je    AH_3hd                        ; Jump = to label AH_3hd
        cmp   al,8                          ; Backspace?
        je    backspace                     ; Jump = to label backspace
        mov   bx,di                         ; Are we at CX bytes already?
        sub   bx,dx
        cmp   bx,cx
        jae   getkey                        ; Jump above or = to label getkey
        mov   ah,0Eh                        ; Write Character
        mov   bx,0x0001
        int   10h                           ; Call interrupt service
        stosb                               ; Record and display keystroke
        jmp   getkey                        ; Jump to label getkey
backspace:
        cmp   di,CommandBuffer              ; Compear pointer to start of buffer
        jbe   getkey                        ; Jump bellow or = to label getkey
        dec   di                            ; Go back in buffer
        mov   al,8                          ; Move cursor back
        mov   ah,0Eh                        ; Request display
        mov   bx,0x0001
        int   10h                           ; Call interrupt service
        mov   al,32                         ; Print a space
        mov   ah,0Eh                        ; Request display
        mov   bx,0x0001
        int   10h                           ; Call interrupt service
        mov   al,8                          ; Move cursor back again
        mov   ah,0Eh                        ; Request display
        mov   bx,0x0001
        int   10h                           ; Call interrupt service
        jmp   getkey                        ; Get another key
AH_3hd:                                     ; Finish up
        mov   cx,di                         ; CX = byte count
        sub   cx,dx
        xor   al,al                         ; Zero-terminate
        stosb                               ; Store a byte
        xor   ax,ax                         ; Success
        mov   si,CommandBuffer              ; Move the address of CommandBuffer in SI
        mov   ax,si                         ; Move SI into AX
        mov   dx,si                         ; Move SI into DX
        pop   es                            ; Restore ES
        popa                                ; Restore genral regs
        ret                                 ; Return

CommandBuffer: times  128  db 0
    
Post 23 Jan 2007, 16:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.