Added support for \n, \t and \\ in the string printing function
This commit is contained in:
@@ -23,36 +23,29 @@ os_read_cli:
|
||||
|
||||
.check_matches: ; Check if the user input matches any internal commands
|
||||
; Help
|
||||
mov di, user_input
|
||||
mov si, help_string
|
||||
mov si, user_input
|
||||
mov di, help_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je help
|
||||
|
||||
; Clear screen
|
||||
mov di, user_input
|
||||
mov si, clear_string
|
||||
mov si, user_input
|
||||
mov di, clear_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je clear
|
||||
|
||||
; Reboot
|
||||
mov di, user_input
|
||||
mov si, reboot_string
|
||||
mov si, user_input
|
||||
mov di, reboot_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je os_reboot
|
||||
|
||||
; Reboot
|
||||
mov di, user_input
|
||||
mov si, cat_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je cat
|
||||
je power_reboot
|
||||
|
||||
; Pong
|
||||
mov di, user_input
|
||||
mov si, pong_string
|
||||
mov si, user_input
|
||||
mov di, pong_string
|
||||
call os_compare_strings
|
||||
cmp cl, 1
|
||||
je pong
|
||||
@@ -63,7 +56,7 @@ os_read_cli:
|
||||
mov si, unknown_command
|
||||
call os_print_string
|
||||
mov si, user_input
|
||||
call os_print_string_nl
|
||||
call os_print_string
|
||||
jmp .finish
|
||||
|
||||
.finish:
|
||||
@@ -76,19 +69,15 @@ clear:
|
||||
|
||||
help:
|
||||
mov si, help_text
|
||||
call os_print_string_nl
|
||||
call os_print_string
|
||||
call os_read_cli.finish
|
||||
|
||||
cat:
|
||||
call util_cat
|
||||
call os_read_cli.finish
|
||||
|
||||
pong:
|
||||
call game_pong
|
||||
call os_read_cli.finish
|
||||
|
||||
section .data
|
||||
welcome_text db 'Welcome to CrawOS, the Cool, Real and AWsome Operating System', 0
|
||||
welcome_text db 'Welcome to CrawOS, the Cwick, Real and AWsome Operating System\n', 0
|
||||
user_input times 20 db 0
|
||||
prompt_length db 20
|
||||
prompt db 'CrawOS sh> ', 0
|
||||
@@ -97,6 +86,6 @@ section .data
|
||||
reboot_string db 'REBOOT', 0
|
||||
cat_string db 'CAT', 0
|
||||
pong_string db 'PONG', 0
|
||||
help_text db 'This is for Cowards: "HELP" for this help text, "CLEAR" to clear the screen, esc or "REBOOT" to reboot', 0
|
||||
help_text db 'This is for Cowards:\n"HELP" for this helpful text,\n"CLEAR" to clear the screen,\n"REBOOT" or esc to reboot\n', 0
|
||||
command_result_text db 'You typed: ', 0
|
||||
unknown_command db 'Error: Unkown Command.. ', 0
|
||||
unknown_command db 'Error: Unkown Command.. \n', 0
|
||||
|
||||
@@ -43,7 +43,7 @@ os_display_input:
|
||||
jmp .check_key_pressed
|
||||
|
||||
.esc_key:
|
||||
call os_reboot
|
||||
call power_reboot
|
||||
|
||||
.enter_key:
|
||||
mov al, 0
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
; LBA = index of data segment on disk
|
||||
; CHS = cylinder, header, sector
|
||||
; T = LBA/sectors per track
|
||||
; S = (LBA%sectors per track) + 1
|
||||
; H = T % heads
|
||||
; C = T / headers
|
||||
; input, LBA index: ax
|
||||
; sector number: cl
|
||||
; cylinder: ch
|
||||
; head: dh
|
||||
; Example where LBA = 50h (CHS = 2,0,9)
|
||||
; ax = 0050h, push this to the stack
|
||||
; dx = 0000h
|
||||
; dx = 50h % 12h = 0008h
|
||||
; ax = 50h / 12h = 0004h
|
||||
; dx = 0009h
|
||||
; cx = 0009h
|
||||
; dx = 0000h
|
||||
; dx = 04h % 02h = 0000h
|
||||
; ax = 04h / 02h = 0002h
|
||||
; dh = 00h (dx = 0000h)
|
||||
; ch = 02h (cx = 0209h)
|
||||
; ah = 00h (ax = 0002h)
|
||||
; cl = 09h OR 00h = 09h (cx = 0209h)
|
||||
; ax = 0050h
|
||||
; dl = 50h (dx = 0050h)
|
||||
; ax = 0050h
|
||||
; thus:
|
||||
; cylinder (ch) = 02h
|
||||
; head (cl) = 00h
|
||||
; sector (dh) = 09h
|
||||
os_lba_to_chs:
|
||||
push ax
|
||||
push dx
|
||||
|
||||
xor dx,dx ; clear dx
|
||||
div word [bdb_sectors_per_track] ; (LBA % sectors per track) + 1 = sector
|
||||
inc dx ; sector, dx stores the remainder so we increment that.
|
||||
mov cx,dx
|
||||
|
||||
xor dx,dx ; clear dx
|
||||
div word [bdb_number_of_heads]
|
||||
mov dh,dl ; head, dx stores remainder so we move that up 8 bits to dh
|
||||
|
||||
mov ch,al
|
||||
shl ah, 6 ; * 32
|
||||
or cl, ah ; cylinder
|
||||
|
||||
pop ax
|
||||
mov dl,al
|
||||
pop ax
|
||||
|
||||
ret
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
os_reboot:
|
||||
power_reboot:
|
||||
mov ax, 0x5307
|
||||
mov bx, 0x0001
|
||||
mov cx, 0x0003
|
||||
int 0x19
|
||||
|
||||
; Not done
|
||||
power_shutdown:
|
||||
ret
|
||||
|
||||
@@ -6,21 +6,31 @@
|
||||
; memory address 2: |s|n|a|k|e|0|
|
||||
; ^
|
||||
; SI => lodsb loads value stored at SI to AX and then increments SI if DF is 0
|
||||
; Additionaly, if the di string ends and the relevant character in si contains a space, it will still return
|
||||
; the strings as being equal, this is to allow for command line arquments
|
||||
os_compare_strings:
|
||||
cld
|
||||
|
||||
.compare:
|
||||
mov al, 0
|
||||
scasb
|
||||
je .di_ended
|
||||
dec di
|
||||
lodsb
|
||||
scasb ; Compare di to si
|
||||
jne .unequal ; If they are not equal, jump to .unequal
|
||||
cmp al, 0 ; Check if string is finished
|
||||
je .equal ; If it has, return true
|
||||
jmp .compare ; Finally, repeat
|
||||
|
||||
.unequal:
|
||||
mov cl, 0 ; Change to 0 if unquality is proven
|
||||
ret
|
||||
|
||||
.di_ended:
|
||||
lodsb
|
||||
cmp al, 20h ; 20h = space
|
||||
je .equal
|
||||
cmp al, 0
|
||||
je .equal
|
||||
jmp .unequal
|
||||
.equal:
|
||||
mov cl, 1
|
||||
ret
|
||||
@@ -32,13 +42,13 @@ os_compare_strings:
|
||||
os_string_length:
|
||||
push si
|
||||
xor cl,cl ; Clear the al register
|
||||
.loop
|
||||
.loop:
|
||||
lodsb
|
||||
cmp al, 0
|
||||
je .finish
|
||||
inc cl
|
||||
jmp .loop
|
||||
.finish
|
||||
.finish:
|
||||
pop si
|
||||
ret
|
||||
|
||||
@@ -78,7 +88,7 @@ os_format_fat_filename:
|
||||
; Convert a string to all upper/lower case
|
||||
; INPUT: si pointing to a string
|
||||
; OUPUT: the same string in memory will now be capitalised/decapitalised
|
||||
os_upper_case:
|
||||
os_upper_case: ; to upper case
|
||||
pusha
|
||||
mov di, si
|
||||
.loop:
|
||||
@@ -98,7 +108,7 @@ os_upper_case:
|
||||
popa
|
||||
ret
|
||||
|
||||
os_lower_case:
|
||||
os_lower_case: ; to lower case
|
||||
pusha
|
||||
mov di, si
|
||||
.loop:
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
; SI = pointer to start of string to be printed
|
||||
; \n for newline
|
||||
; \t for tab
|
||||
; \\ for a single backslash
|
||||
os_print_string:
|
||||
pusha
|
||||
|
||||
@@ -8,34 +11,43 @@ os_print_string:
|
||||
lodsb ; Get char from si into al
|
||||
cmp al, 0 ; Compare al to 0
|
||||
je .done ; If char is zero, end of string
|
||||
cmp al, 5Ch ; backslash
|
||||
je .backslash
|
||||
|
||||
int 10h ; Otherwise, print it
|
||||
jmp .repeat ; And move on to next char
|
||||
|
||||
.backslash: ; If there is a '\', do what it says, \n for newline, \t for tab etc
|
||||
lodsb
|
||||
dec si
|
||||
cmp al, 6Eh ; 'n'
|
||||
je .newline
|
||||
cmp al, 74h ; \t
|
||||
je .tab
|
||||
cmp al, 5Ch ; '\'
|
||||
je .another_backslash
|
||||
jmp .repeat
|
||||
.newline:
|
||||
mov al, 0Ah ; new line
|
||||
int 10h
|
||||
mov al, 0Dh ; carriage return
|
||||
int 10h
|
||||
jmp .finish_backslash
|
||||
.tab:
|
||||
mov al, 09h ; tab
|
||||
int 10h
|
||||
jmp .finish_backslash
|
||||
.another_backslash: ; This just prints 1 backslash
|
||||
mov al, 5Ch
|
||||
int 10h
|
||||
jmp .finish_backslash
|
||||
.finish_backslash:
|
||||
inc si
|
||||
jmp .repeat
|
||||
.done:
|
||||
popa
|
||||
ret
|
||||
|
||||
; Exact same as the above procedure, but this adds a newline
|
||||
; after priting, similar to the difference between Rust's print! and println!
|
||||
os_print_string_nl:
|
||||
pusha
|
||||
|
||||
mov ah, 0Eh ; int 10h teletype function, we're telling the BIOS we will print something
|
||||
|
||||
.repeat:
|
||||
lodsb ; Get char from si into al
|
||||
cmp al, 0 ; Compare al to 0
|
||||
je .done ; If char is zero, end of string
|
||||
|
||||
int 10h ; Otherwise, print it
|
||||
jmp .repeat ; And move on to next char
|
||||
|
||||
.done:
|
||||
call os_print_newline
|
||||
popa
|
||||
ret
|
||||
|
||||
; --------------------------------------------
|
||||
|
||||
os_print_newline:
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
; Outputs the contents of a file
|
||||
util_cat:
|
||||
pusha
|
||||
|
||||
call os_print_newline
|
||||
|
||||
mov si, cat_prompt
|
||||
call os_print_string
|
||||
|
||||
mov ax, 11 ; length of input
|
||||
mov di, user_input
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
|
||||
section .data:
|
||||
cat_prompt db 'Enter file name: ', 0
|
||||
Reference in New Issue
Block a user