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.
 
 

310 lines
9.5 KiB

BITS 16
start_sing:
; loading essentials for SingOS to run
; VSFS is loaded:
mov [global_disk_identifier], dl ; saving disk_identifier, this is the number the disk that we are booting from.
; This number is set by the bios
; Setup stack
mov ax, 0x8fc0
mov ss, ax ; Set 'ss' to this location (the beginning of our stack region)
mov sp, 0xffff ; Set 'ss:sp' to the top of our 8K stack
mov bp, sp
jmp sing_ready
%include "mem_lib/mem_lib.nasm"
%include "lib/os_lib.nasm"
%include "lib/string.nasm"
%include "lib/debug_tools.nasm"
%include "lib/std_power.nasm"
%include "lib/svim.nasm"
%include "vsfs/vsfs.nasm"
%include "CLI/CLI.nasm"
sing_ready: ; SingOS is ready for the user:
call os_clear_screen
mov si, welcome ; Put address of the null-terminated string to output into 'si'
call print ; Call our string-printing routine
print_format example_format_string, 0xdead, 0xbeef, 0xbabe, 420
call printCRLF
call dump_general_registers
call printCRLF
call dump_segment_registers
call printCRLF
call dump_stack_registers
call printCRLF
call dump_status_flags
call printCRLF
call print_help_message
; call dump_status_flags
; call printCRLF
mov si, command_line
call print
jmp terminal
terminal:
call wait_for_key
jmp terminal
wait_for_key:
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
jne .dont_backspace
call CLI_DELETE
popa
ret
.dont_backspace:
call CLI_ASCII_INPUT
;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
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, 0
int 0x10
mov al, 0x08
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:
call CLI_CONFIRM_INPUT
jmp .command_interpreter
.no_str:
mov si, command_line
call print
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, vsfs_list_files_command, 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
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
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 ; 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
;mov ax, cx
;call dumpax
;mov bx, [.compare_with_LIST_searchindex]
mov bx, cx
add bx, bx ; The pointers are 2 bytes long. Compensate here
;call printCRLF
;mov ax, cx
;call dumpax
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
;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
;mov ax, cx
;call dumpax
mov dx, [.compare_with_LIST_POINTERS+bx] ; This is where the program is.
;mov ax, dx
;call printCRLF
;call dumpax
call dx
jmp .no_str
;
global_vars:
global_vsfs_master_record dw 8 ; this is the index of the start of the master table for the filesystem
; This should maby contain more information.
; and somehow be setted in a fix sector, which holds all the variabels for SingOS
; 8 is currently the magic number where the file system starts on our disk.
global_vsfs_next_index dw 0 ; This is the next index to the next file created.
; this var is set durling load of SingOS
; Changed my mind, the index is currently loaded and written back to disk under
; creation of a new file.
global_disk_identifier db 0 ; set by the bios passed by the bootloader,
; this is the bios ID
data:
welcome db "###############################################################################", 13, 10, "# Welcome to SingOS Legacy BIOS edition. #", 13, 10, "# This edition aims to be compliant with the original IBM PC Technical #", 13, 10, "# Reference from 1981. Systems from 1997 started to use extended BIOS #", 13, 10, "# functionality, why this edition aims to work on all systems before 1997. #", 13, 10, "###############################################################################", 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
number_one_zstring db '71', 0
example_format_string db "(%x-%x-%x){%d%%}",0
;times 131072-($-$$) db 0 ; 256 sectos
;GLOBAL_VSFS_START db 'VSFS v0.1' ; sector 257 reserved for file system information
times 737280-($-$$)-1024 db 0 ; sector 258 to sector 2048 should be avaliable to the filesystem.