Real mode string input problems

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
killedbydeath

Real mode string input problems

Post by killedbydeath »

Hi all,
i managed make my computer print
Welcome to my Os!
root@default:
but when i hit a key nothing happens and my keystroke doesn't appear on the screen. Remember i just want to write something like
root@default:foo
and the hit enter and just print another promt like
root@default:foo <carriage>
root@default:

But as i said it does not display my keystrokes. I've simplified my code and made it a bootsector (avoiding the bootloader) for simplicity. Here's my code

Code: Select all

[BITS 16]
[ORG 0]
start:
mov ax,0x7C0
mov ds,ax
mov ax,0x0000
mov ss,ax
mov sp,0xFFFF


Main:
  
mov si,welcome
call print

mainloop:
mov ax,0E0Ah                 
int  10h
call callpromt
mov di,commandbuffer
mov dx,40
xor cx,cx
call scanf
 
print:
lodsb
cmp al,0
je printend
mov ah,0Eh
mov bh, 0Fh
mov bl, 0
int 10h
jmp print

printend:
ret

callpromt:
mov si,unixpromt
call print

;some data
commandbuffer: times 40 db 0
welcome db 'Welcome to my Os!',0,13,10

unixpromt db 13,'root@default#:',0


scanf:
xor bx,bx
.start
xor ax,ax
int 16h
cmp al,0x0D
je .return
mov [es:di+bx],al
inc bx
cmp bx,dx
je .return ; if reached the buffer limit just act like return
push bx
xor bx,bx
cmp bx,cx
je .put
.putreturn
pop bx
jmp .start
.put
pop bx
push ax
push bx
xor ah,ah
mov ah,0Eh
mov bh,0Fh
mov bl,0
int 10h
pop bx
pop ax
je .putreturn
.return 
xor al,al
mov [es:di+bx],al
jmp mainloop

times 510-($-$$) db 0
dw 0AA55h

Thank you for your time
JAAman

Re:Real mode string input problems

Post by JAAman »

as i replied on the other board:

well, the first thing i see is trying to execute string data usually doesnt work well...

the first thing you do after printing your opening message, is setup for your int10 call, then you immediatly call 'callpromt':

Code: Select all


callpromt:
   mov si,unixpromt
   call print

...

print:
  lodsb

...

printend:
  ret

...   returning to the call...

call print
                              < ret returns here

;some data
commandbuffer: times 40 db 0
welcome db 'Welcome to my Os!',0,13,10
killedbydeath

Re:Real mode string input problems

Post by killedbydeath »

problem solved, MANY THANKS JAAMAN, YOU SAVED ME !
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Real mode string input problems

Post by Candy »

killedbydeath wrote:

Code: Select all

[BITS 16]
[ORG 0]
start:
mov ax,0x7C0
mov ds,ax
mov ax,0x0000
mov ss,ax
mov sp,0xFFFF


Main:
  
mov si,welcome
call print
                                          <--- fallthrough, not sure it's intended but I think so
mainloop:
mov ax,0E0Ah                 
int  10h
call callpromt
mov di,commandbuffer
mov dx,40
xor cx,cx
call scanf
                                                      <--- fallthrough that is not intended
print:
lodsb
cmp al,0
je printend
mov ah,0Eh
mov bh, 0Fh
mov bl, 0
int 10h
jmp print

printend:
ret

callpromt:
mov si,unixpromt
call print
                                                   <-- fallthrough JAAman indicated that's certainly not intended.
;some data
commandbuffer: times 40 db 0
welcome db 'Welcome to my Os!',0,13,10                           <-- What does this 13,10 do? It's not part of the string.

unixpromt db 13,'root@default#:',0


scanf:
xor bx,bx
.start
xor ax,ax
int 16h
cmp al,0x0D
je .return
mov [es:di+bx],al
inc bx
cmp bx,dx
je .return ; if reached the buffer limit just act like return
push bx
xor bx,bx
cmp bx,cx
je .put
.putreturn
pop bx
jmp .start
.put
pop bx
push ax
push bx
xor ah,ah
mov ah,0Eh
mov bh,0Fh
mov bl,0
int 10h
pop bx
pop ax
je .putreturn
.return 
xor al,al
mov [es:di+bx],al
jmp mainloop

times 510-($-$$) db 0
dw 0AA55h

evincarofautumn

Re:Real mode string input problems

Post by evincarofautumn »

What does this 13,10 do? It's not part of the string.
It's a dos/win-style newline (cr+lf). I assume that that code should read "...[tt]13,10,0[/tt]..." instead.

Cheers!
Post Reply