Page 1 of 1

String input problems

Posted: Fri Aug 11, 2006 10:34 am
by joke
Well, i am trying to implement a very simple console. For now, i just want it to let the user type in a command (no longer than 10 chars) and when he hits return just write a new line and the command prompt. The problem
is that when i make a simple kernel that only prints a message everything's going fine. However, when i implement reading from the keyboard, nothing happens (only a blinking cursor appears). Here's my code
boot.asm

Code: Select all

; I used Daniel's tutor at os resources as a template 
[BITS 16]
[ORG 0]
start:
mov ax,0x7C0
mov ds,ax
mov ax,0x0000
mov ss,ax
mov sp,0xFFFF
reset_drive:                    
mov ax, 0          
mov dl, 0          
int 13h             
jc reset_drive            

read:
mov ax,1000h ; ES:BX = 1000:0000
mov es,ax          
mov bx,0           ;
mov ah,2           ; Load disk data to ES:BX
mov al,5           ; Load 5 sectors
mov ch,0           ; Cylinder=0
mov cl,2           ; Sector=2
mov dh,0           ; Head=0
mov dl,0           ; Drive=0
int 13h             ; Read!
jc read             ; ERROR => Try again

mov ax,0x1000
mov ds,ax
jmp 1000h:0000  ; Jump to the program


times 510-($-$$) db 0
dw 0AA55h
kernel.asm

Code: Select all

[BITS 16]
setcursor: ; note i also tried it out without the setcursor function but with ;no success 
mov ah,02 
mov bh,00
mov dx,0x0100
int 10h 


Main:

mov si,welcome 
call print ; print welcome message
mov ax,0E0Ah; line feed          
int  10h
mainloop:
call callpromt
call getcommand
 
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

welcome db 'Welcome to my Os!',0,13,10

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


commandbuffer: times 10 db 0

getcommand:
mov di,commandbuffer
mov cx,10
mov dx,di
jmp get
get:
xor ax,ax
int 16h
cmp al,13
je carriage 
cmp al,8
je backspace
mov bx,di
sub bx,dx
cmp bx,cx 
mov ah,0Eh
mov bx,0x0001
int 10h
stosb
jmp get
backspace:
cmp di,commandbuffer
jbe get
dec di
mov al,8
mov ah,0Eh
mov bx,0x0001; go back cursor
int 10h
mov al,32 ; print a space
mov ah,0Eh
mov bx,0x0001
int 10h
mov al,8 ; go back again
mov ah,0Eh
mov bx,0x0001
int 10h
jmp get
carriage:
xor al,al
mov ax,0E0Ah
int 10h
call callpromt
jmp getcommand
; just print another promt and try again. No command processing for now


Thank you in advance

Posted: Sun Aug 13, 2006 8:14 am
by SpooK
Are you processing interrupts, specifically, IRQ 1 for Keyboard Input?

Posted: Sun Aug 13, 2006 8:54 am
by JAAman
hes using int 16, letting the BIOS continue processing hard-ints

i dont know what your problem is, but:

Code: Select all

cmp bx,cx
you never do anything on the results (based on context, i assume you want to abort the loop, but you never do...)

also:
your using dark blue (iirc) for your forground color (this is much less visible than the light gray (0x07) that is normally used (light gray provides better contrast with a black background)

Posted: Sun Aug 13, 2006 8:56 am
by joke
please have a look on my other post, "again keyboard problems :((("