Reputation:
Essentially what I am working on is building a simple console-based OS that is similar to MS-DOS in functionality. I understand that a project like this couldn't be easily maintained, and I don't really care ;). So here is what I have made so far:
;------------------------------------------------------
;| SMOS Shell Source |
;| Kept under GPLv3 Open Source license |
;| (https://www.gnu.org/licenses/gpl.txt) |
;------------------------------------------------------
BITS 16
start:
mov ax, 07C0h
add ax, 288
mov ss, ax
mov sp, 4096
mov ax, 07C0h
mov ds, ax
jmp kool
kool:
mov si, lineone
call print_string
mov si, linetwo
call print_string
mov si, linethree
call print_string
call newline
mov si, shellprompt
call print_string
jmp type
shell:
call newline
mov si, shellprompt
call print_string
jmp type
lineone db '----------------------',13,10,0
linetwo db '| WELCOME TO SMOS |',13,10,0
linethree db '----------------------',13,10,0
shellprompt db 'smos> ',0
break db 13,10,0
clearscreen:
mov ah, 0x06
mov al, 0
int 10h
type:
mov ah,0h
int 16h
jmp shell
print_string:
mov ah, 0Eh
.repeat:
lodsb
cmp al, 0
je done
int 10h
jmp .repeat
newline:
mov si, break
call print_string
done:
ret
times 510-($-$$) db 0
dw 0xAA55
What I would like is a way to get a keypress and print it onto the smos>
shell line. So if the user typed test
it would display smos> test
and if the user presses enter it will be able to be stored, and then acted upon. I have looked for anything similar to my question and you can see that in the type:
function it stops the process until a key is pressed, which is an attempt I found. However, I can't figure out how to continue the code to get the result I explained. Anyway, remember when you're answering I'm new to assembly so treat me like a 5-year-old when explaining things. Thanks in advance!
Upvotes: 0
Views: 153
Reputation: 76537
Your question is too broad to be answered, but I can address the issue you seem to be stuck with at the moment:
That is the problem, I don't know how to save it to register. I would like to be able to save it like myvar db, al,0. al being the keystroke stored from int 16h. – DecstarG 4 hours ago
The trick is to save your keystrokes in memory.
First you'll have to reserve a block of memory, you can use the stack for that (See: What is stack frame in assembly?), or use a memory manager (See here: https://github.com/jakubbogucki/memoryManager), Or just use a fixed buffer in memory (see: 3.2.2 RESB and Friends: Declaring Uninitialized Data) that is only used for that.
Keep a close watch on buffer overflows, You must do checking to ensure you do not read and write past the end of the buffer.
Storing stuff in memory is simple:
keybuffer: resb 1024
endofbuffer: resb 1
mov si,keybuffer ;get the keybuffer address
loop:
.... ;get the keystroke somehow.
mov [si],al ;Store the keystroke (assuming it's in AL
inc si ;Go to the next space in the buffer
mov di,endofbuffer ;Is the buffer full?
cmp di,si ;
je BufferIsFull ;yes, jump to the code to handle this.
jmp loop ;we're still good, keep reading keys.
If you want to have a look at someone else's attempt at writing an OS from scratch, check out: http://mikeos.sourceforge.net/write-your-own-os.html
Upvotes: 1