The bootloadercode is the same like in my first post
You can just Emualte this os in qemu, becauso virtualbox, ... lokking on the size of the file, but qemu ignore it
kernel:
mov ax, 0x1000 ;1
mov ds, ax ; 2
mov es, ax ; 3
; 1-3 : This need the Kernel, that the bootloader can find him
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; Kernel ;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main; ; main function
mov si, welcome
call print_yellow
loop: ; Terminal function
mov si, prompt
call print_white
; Now, i wanna make a small shell
mov di, buffer ; Thats a variable for the string, what you have type
call get ; keyboard function
mov si, buffer ; thats so a type variable. when you type
something, thats comming into the variable
cmp byte [si], 0 ; if you dont type sonthing
je loop ; go back to the prompt main
mov si, buffer ;you type somthing
mov di, cmd_hi ;when you type the command hi.....
call strcmp ;compare si and di!
jc .hello ; when si and di are the same, please go to the function .hello
;now its come the same, but just for the help funtion and the reboot function
mov si, buffer
mov di, cmd_help
call strcmp
jc .help
mov si, buffer
mov di, cmd_reboot
call strcmp
jc .reboot
;when you type an unknow commant, then comming out a error message
mov si, errormsg
call print_red
jmp loop ; and please got back to the prompt main
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; Functions ;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.hello:
mov si, msg
call print_green
jmp loop ; go back to prompt main
.help:
mov si, commands
call print_yellow
mov si, command1
call print_white
mov si, command2
call print_white
jmp loop
.reboot:
mov si, please_press_any_key
call print_blue
xor ah, ah ; pres a key
int 16h ;interrupt number
jmp 0xFFFF:0x0000 ;reboot the computer
welcome db 'Welcome to ', 230, 'OS Version 0.1.0', 0x0D, 0x0A, 0
cmd_hi db 'hi', 0 ;hi command
cmd_help db 'help', 0 ;help command
cmd_reboot db 'reboot', 0 ;reboot command
errormsg db 'Unknow Command', 0x0D, 0x0A, 0
msg db 'Hello, World!', 0x0D, 0x0A, 0
please_press_any_key db 'Please press any key, to reboot the computer...', 0
commands db 'Commands:', 0x0D, 0x0A, 0
command1 db ' hi', 0x0D, 0x0A, 0
command2 db ' reboot', 0x0D, 0x0A, 0
prompt db '[/', 230, 'Terminal]', 0
buffer times 64 db 0 ; thats important for the prompt
;keyboard function
get:
xor cl, cl
ged:
xor ah, ah
int 16h
cmp al, 0x0D ; if you pressed enter
je .return
mov ah, 0Eh ;print out the character you pressed
int 10h
stosb ;si get you pressed worth
inc cl
jmp ged
.return:
mov al, 0 ; 0 <- si ignore it
stosb
mov ah, 0Eh
mov al, 0x0D
int 10h
mov al, 0x0A
int 10h
ret; go back to prompt main
strcmp:
.loop:
mov al, [si]
mov bl, [di]
cmp al, bl ; if si = di
jne .not ;if not, than please go to the notewual function
cmp al, 0 ;are si = 0(so like by enter function)
je .done ;go to ignore function
inc di
inc si
jmp .loop
.not:
clc
ret
.done
stc
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; Graphics ;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print_yellow: ; so like print_white, just the textcolor number changes
mov ah, 0Bh
mov bh, 0
mov bl, 14
lodsb
or al, al
jz .done_yellow
mov ah, 0Eh
int 10h
jmp print_yellow
.done_yellow:
ret
print_white: ; so like print_white, just the textcolor number changes
mov ah, 0Bh
mov bh, 0
mov bl, 15
lodsb
or al, al
jz .done_white
mov ah, 0Eh
int 10h
jmp print_white
.done_white:
ret
print_blue: ; so like print_white, just the textc
olor number changes
mov ah, 0Bh
mov bh, 0
mov bl, 9
lodsb
or al, al
jz .done_blue
mov ah, 0Eh
int 10h
jmp print_blue
.done_blue:
ret
print_red: ; so like print_white, just the textcolor number changes
mov ah, 0Bh
mov bh, 0
mov bl, 12
lodsb
or al, al
jz .done_red
mov ah, 0Eh
int 10h
jmp print_red
.done_red:
ret
print_green: ; so like print_white, just the textcolor number changes
mov ah, 0Bh
mov bh, 0
mov bl, 10
lodsb
or al, al
jz .done_green
mov ah, 0Eh
int 10h
jmp print_green
.done_green:
ret
times 512 - ($ - $$) hlt ; he kernel is a sector worth
Heres a picture, what cames out:

No comments:
Post a Comment