You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

242 lines
6.7 KiB

BITS 16
start_sing_os:
mov si, welcome ; Put address of the null-terminated string to output into 'si'
call print_os ; Call our string-printing routine
mov si, command_line
call print_os
jmp terminal
terminal:
call wait_for_key_os
jmp terminal
wait_for_key_os:
pusha
mov ax, 0
mov ah, 0x10 ; BIOS call to wait for key
int 0x16
cmp ax, 0x11b; ESC key
je near .end
cmp ax, 0x3b00 ; f1 key
je .change_one
cmp ax, 0x3c00 ; f2 key
je .change_two
cmp ax, 0x1c0d ; enter key
je .enter_hit
mov [.tmp_buf], ax ; save the key pressed befor printing it
mov cx, [.tmp_buf]
cmp cx, 0x0e08 ; backspace key
je .backspace_handler
mov ah, 0xE ; This destroy the high part of the key pressed
mov bl, 0x02
int 0x10
mov bx, [.os_command_buffer_counter]
cmp bx, 254
je .os_buffer_full
mov ax, bx
add ax, .os_command_buffer
add bx, 0x01
mov [.os_command_buffer_counter], bx
mov bx, ax
mov ax, [.tmp_buf]
mov [bx], ax
.return_enter:
mov ax, [.tmp_buf]
popa ; But restore all other regs
ret
.os_buffer_full:
mov si, .os_str_full
call print_os
popa
ret
.backspace_handler:
; bx already set to the current buffer count
mov bx, [.os_command_buffer_counter]
cmp bx, 0x00
je .backspace_stop
sub bx, 0x01
mov [.os_command_buffer_counter], bx
add bx, .os_command_buffer
mov ax, 0x00
mov [bx], ax
mov ax, [.tmp_buf] ; load the backpace
mov ah, 0xE ; print the backspace
int 0x10
;mov al, 0x20 ; now the curser is one back
;int 0x10 ; print null charecter
.backspace_stop:
popa ; But restore all other regs
ret
.change_one:
mov al, 0x00 ; arg: index 0
call os_change_screen
jmp terminal
.change_two:
mov al, 0x01 ; arg: index 0
call os_change_screen
jmp terminal
.enter_hit:
jmp .command_interpreter
.no_str:
mov si, command_line
call print_os
jmp .return_enter
.compare_with_LIST_searchindex dw 0
.compare_with_LIST_NAMES dw .compare_with_dumpmem, .compare_with_keyprint, .compare_with_display, .compare_with_svim, .compare_with_clear, .compare_with_ls, 0
.compare_with_LIST_POINTERS dw dumpmem, keyprint, .change_display, svim, .clearcommand, ls, 0
.compare_with_dumpmem db 'dumpmem', 0
.compare_with_keyprint db 'keyprint', 0
.compare_with_display db 'display', 0 ; original this is the display command for better grapichs
.compare_with_svim db 'svim', 0 ; SingOS vim edition 'svim'
.compare_with_clear db 'clear', 0 ; Clear the screen
.compare_with_ls db 'ls', 0 ; List file table
.end:
mov si, exit_message
call print_os
call power_off
cli
hlt
.change_display:
mov ax, 0x4F02 ; set VBE mode
mov bx, 0x4118 ; VBE mode number; notice that bits 0-13 contain the mode number and bit 14 (LFB) is set and bit 15 (DM) is clear.
;xor bx, bx
;xor cx, cx
;xor dx, dx
;mov ah, 0x06
;mov al, 0xff
int 0x10
ret
.clearcommand:
xor bx, bx
xor cx, cx ; Upper and left coordinate
mov bh, 0x0f ; color for new screen 0 = black f = white
mov dh, 0xff ; Select all screen
mov dl, 0xff ; Select all screen
mov ah, 0x07 ; scrool down
mov al, 0x00 ; scrool 0 lines (means blank screen )
int 0x10
; move curser back to the top of the screen
mov ah, 0x02
mov bh, 0x00 ; page number 0
mov dh, 0x00 ; row zero
mov dl, 0x00 ; coloumn zero
int 0x10
ret
.tmp_buf dw 0
.os_command_buffer times 255 dw 0
.os_command_buffer_counter dw 0
.os_str_full db 13, 10, 'Buffer is full', 13, 10, 0
.command_interpreter:
mov bx, [.os_command_buffer_counter]
cmp bx, 0x00
je near .no_str ; First byte is 0 => No command
call printCRLF_os
add bx, .os_command_buffer ; Note addition. Sets bx to the end of the string, which should be guaranteed to be 0
mov ax, 0x00
mov [bx], ax ; Ensure that the command is null-terminated
xor bx, bx
mov [.os_command_buffer_counter], bx
mov si, .os_command_buffer
call print_os ; Echo the command
lea si, [.os_command_buffer]
;mov dword [.compare_with_LIST_searchindex], 0 ; Next time, start at 0
mov cx, 0 ; Index
.command_interpreter_searchloop:
;call printCRLF_os
;mov ax, cx
;call dumpax_os
;mov bx, [.compare_with_LIST_searchindex]
mov bx, cx
add bx, bx ; The pointers are 2 bytes long. Compensate here
;call printCRLF_os
;mov ax, cx
;call dumpax_os
mov dx, [.compare_with_LIST_NAMES+bx] ; Here it HAS to be bx. Otherwise it is invalid for some reason
mov bx, dx
lea di, [bx]
call stringcompare
je .command_interpreter_foundcommand
; I don't assume here that the registers contain the same values they used to after the calls
;mov bx, [.compare_with_LIST_searchindex]
;inc bx
;mov [.compare_with_LIST_searchindex], bx
inc cx
mov bx, cx
add bx, bx
mov dx, [.compare_with_LIST_NAMES+bx]
cmp dx, 0 ;Is it at the null terminator?
jne .command_interpreter_searchloop ; There is another command to check
jmp .no_str
.command_interpreter_foundcommand:
call printCRLF_os
;mov bx, [.compare_with_LIST_searchindex] ; Remember this thing
mov bx, cx
add bx, bx ;The pointers are 2 bytes long. Compensate here
;call printCRLF_os
;mov ax, cx
;call dumpax_os
mov dx, [.compare_with_LIST_POINTERS+bx] ; This is where the program is.
;mov ax, dx
;call printCRLF_os
;call dumpax_os
call dx
jmp .no_str
;
data_os:
welcome db 'This is SingOS! v0.0.3', 13, 10, 'Press ESC to halt.', 13, 10, 0
exit_message db 13, 10, 'Goodbye from SingOS',13,10,'The system has halted.', 0
command_line db 13, 10, 'groot@SingOS $ ', 0
%include "lib/os_lib.nasm"
%include "lib/string.nasm"
%include "lib/dumpmem.nasm"
%include "lib/printkey.nasm"
%include "lib/std_power.nasm"
%include "lib/svim.nasm"
%include "lib/ls.nasm"
times 131072-($-$$) db 0