Added lowercase function, string length function formating to fat12
function
This commit is contained in:
@@ -25,24 +25,95 @@ os_compare_strings:
|
|||||||
mov cl, 1
|
mov cl, 1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; Get the length of a string
|
||||||
|
; 'hello world', 0 is 11 characters long (excluding the terminator)
|
||||||
|
; input: si points to the string to be counted
|
||||||
|
; output: cl holds the length
|
||||||
|
os_string_length:
|
||||||
|
push si
|
||||||
|
xor cl,cl ; Clear the al register
|
||||||
|
.loop
|
||||||
|
lodsb
|
||||||
|
cmp al, 0
|
||||||
|
je .finish
|
||||||
|
inc cl
|
||||||
|
jmp .loop
|
||||||
|
.finish
|
||||||
|
pop si
|
||||||
|
ret
|
||||||
|
|
||||||
; Convert a string to all upper case
|
; convert a string to fat's filename format
|
||||||
|
; It will be capitalised and 11 characters long,
|
||||||
|
; 8 for the filename, 3 for the extension
|
||||||
|
; eg: 'file.txt' -> 'FILE TXT'
|
||||||
|
; input: si points to filename, di points to a free 11 bytes in memory
|
||||||
|
; output: di points to the fat formatted filename
|
||||||
|
os_format_fat_filename:
|
||||||
|
pusha
|
||||||
|
call os_upper_case
|
||||||
|
call os_string_length ; Stores the length of the string in cl
|
||||||
|
mov bl, 11
|
||||||
|
sub bl, cl ; 11 - string_length
|
||||||
|
.character_loop:
|
||||||
|
lodsb
|
||||||
|
cmp al, 0
|
||||||
|
je .finish
|
||||||
|
cmp al, 2Eh ; 2Eh
|
||||||
|
je .add_spaces ; This will end up back at .character_loop
|
||||||
|
stosb
|
||||||
|
jmp .character_loop
|
||||||
|
|
||||||
|
.add_spaces: ; Add the number of spaces as bl holds
|
||||||
|
mov al, ' ' ; 20h = space
|
||||||
|
.spaces_loop:
|
||||||
|
stosb
|
||||||
|
cmp bl, 0
|
||||||
|
je .character_loop
|
||||||
|
dec bl
|
||||||
|
jmp .spaces_loop
|
||||||
|
.finish:
|
||||||
|
popa
|
||||||
|
ret
|
||||||
|
|
||||||
|
; 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:
|
||||||
pusha
|
pusha
|
||||||
mov di, si
|
mov di, si
|
||||||
.loop:
|
.loop:
|
||||||
lodsb
|
lodsb ; Load the character into al
|
||||||
inc di
|
inc di
|
||||||
cmp al, 0
|
cmp al, 0
|
||||||
je .finish
|
je .finish ; If it's null then the string is finished
|
||||||
cmp al, 7Ah
|
cmp al, 7Ah ; 7Ah = 'z'
|
||||||
jns .loop
|
jns .loop ; Ignore if it's more than 'z'
|
||||||
cmp al, 61h
|
cmp al, 61h ; 61h = 'a'
|
||||||
js .loop
|
js .loop ; Ignore if it's less than 'a'
|
||||||
sub al, 20h
|
sub al, 20h ; Otherwise subtract 20h to capitalise it
|
||||||
dec di
|
dec di
|
||||||
stosb
|
stosb ; Store the new value
|
||||||
jmp .loop
|
jmp .loop ; Next character
|
||||||
|
.finish:
|
||||||
|
popa
|
||||||
|
ret
|
||||||
|
|
||||||
|
os_lower_case:
|
||||||
|
pusha
|
||||||
|
mov di, si
|
||||||
|
.loop:
|
||||||
|
lodsb ; Load the character into al
|
||||||
|
inc di
|
||||||
|
cmp al, 0
|
||||||
|
je .finish ; If it's null then the string is finished
|
||||||
|
cmp al, 5Ah ; 5Ah = 'Z'
|
||||||
|
jns .loop ; Ignore if it's more than 'Z'
|
||||||
|
cmp al, 41h ; 41h = 'A'
|
||||||
|
js .loop ; Ignore if it's less than 'A'
|
||||||
|
add al, 20h ; Otherwise subtract 20h to capitalise it
|
||||||
|
dec di
|
||||||
|
stosb ; Store the new value
|
||||||
|
jmp .loop ; Next character
|
||||||
.finish:
|
.finish:
|
||||||
popa
|
popa
|
||||||
ret
|
ret
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
game_snake:
|
|
||||||
call .draw_screen
|
|
||||||
call .detect_input
|
|
||||||
|
|
||||||
.draw_screen:
|
|
||||||
call os_set_graphics_mode ; Clear screen
|
|
||||||
.draw_snake_loop:
|
|
||||||
mov ax, [snake_x]
|
|
||||||
mov [x_start], ax
|
|
||||||
mov [x_end], ax
|
|
||||||
|
|
||||||
mov bx, [snake_y]
|
|
||||||
mov [y_start], bx
|
|
||||||
mov [y_end], bx
|
|
||||||
|
|
||||||
call os_draw_graphical_rectangle
|
|
||||||
ret
|
|
||||||
|
|
||||||
; Player 1 movements
|
|
||||||
.up:
|
|
||||||
mov dword [snake_direction], 0
|
|
||||||
jmp .end_detect_input
|
|
||||||
.down:
|
|
||||||
mov dword [snake_direction], 2
|
|
||||||
jmp .end_detect_input
|
|
||||||
.left:
|
|
||||||
mov dword [snake_direction], 3
|
|
||||||
jmp .end_detect_input
|
|
||||||
.right:
|
|
||||||
mov dword [snake_direction], 1
|
|
||||||
jmp .end_detect_input
|
|
||||||
|
|
||||||
.move_up:
|
|
||||||
mov dx, [snake_y]
|
|
||||||
sub dx, 1
|
|
||||||
mov [snake_y], dx
|
|
||||||
ret
|
|
||||||
.move_down:
|
|
||||||
mov dx, [snake_y]
|
|
||||||
add dx, 1
|
|
||||||
mov [snake_y], dx
|
|
||||||
ret
|
|
||||||
.move_left:
|
|
||||||
mov dx, [snake_x]
|
|
||||||
sub dx, 1
|
|
||||||
mov [snake_x], dx
|
|
||||||
ret
|
|
||||||
.move_right:
|
|
||||||
mov dx, [snake_x]
|
|
||||||
add dx, 1
|
|
||||||
mov [snake_x], dx
|
|
||||||
ret
|
|
||||||
|
|
||||||
.move_snake:
|
|
||||||
cmp dword [snake_direction], 0
|
|
||||||
je .move_up
|
|
||||||
cmp dword [snake_direction], 1
|
|
||||||
je .move_right
|
|
||||||
cmp dword [snake_direction], 2
|
|
||||||
je .move_down
|
|
||||||
; Else it must be left
|
|
||||||
jmp .move_left
|
|
||||||
|
|
||||||
|
|
||||||
.detect_input:
|
|
||||||
call os_read_input
|
|
||||||
cmp al, 08h
|
|
||||||
je .finish
|
|
||||||
|
|
||||||
; Player 1
|
|
||||||
cmp al, 77h ; Pressed 'w' up
|
|
||||||
je .up
|
|
||||||
cmp al, 61h ; Pressed 'a' left
|
|
||||||
je .left
|
|
||||||
cmp al, 73h ; Pressed 's' down
|
|
||||||
je .down
|
|
||||||
cmp al, 64h ; Pressed 'd' right
|
|
||||||
je .right
|
|
||||||
.end_detect_input:
|
|
||||||
call .move_snake
|
|
||||||
call .draw_screen
|
|
||||||
|
|
||||||
jmp .detect_input
|
|
||||||
|
|
||||||
.finish:
|
|
||||||
call os_set_text_mode
|
|
||||||
call os_start_cli
|
|
||||||
|
|
||||||
|
|
||||||
section .data:
|
|
||||||
snake_x: dw 5
|
|
||||||
snake_y: dw 5
|
|
||||||
snake_direction: dw 1 ; 0=up, 1=right, 2=down, 3=left
|
|
||||||
snake_length: dw 1
|
|
||||||
@@ -2,21 +2,28 @@ ORG 0h
|
|||||||
BITS 16
|
BITS 16
|
||||||
|
|
||||||
start:
|
start:
|
||||||
mov si, boot_message
|
|
||||||
call os_upper_case
|
|
||||||
mov si, boot_message
|
mov si, boot_message
|
||||||
call os_print_string_nl
|
call os_print_string_nl
|
||||||
|
|
||||||
mov si, help_text
|
mov si, help_text
|
||||||
call os_print_string_nl
|
call os_print_string_nl
|
||||||
|
|
||||||
|
mov si, file_name
|
||||||
|
call os_print_string_nl
|
||||||
|
mov di, fat_file_name
|
||||||
|
call os_format_fat_filename
|
||||||
|
mov si, fat_file_name
|
||||||
|
call os_print_string_nl
|
||||||
|
|
||||||
call os_start_cli
|
call os_start_cli
|
||||||
hlt
|
hlt
|
||||||
|
|
||||||
halt:
|
halt:
|
||||||
jmp halt
|
jmp halt
|
||||||
|
|
||||||
boot_message: db 'kernel successfully loaded!', 0
|
boot_message: db 'OK] Kernel successfully loaded!', 0
|
||||||
|
file_name: db 'hello.cws', 0
|
||||||
|
fat_file_name: db ' ',0 ; 11 characters
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; FEATURES -- Code to pull into the kernel
|
; FEATURES -- Code to pull into the kernel
|
||||||
@@ -29,4 +36,3 @@ boot_message: db 'kernel successfully loaded!', 0
|
|||||||
%INCLUDE "source/kernel/features/utils.asm"
|
%INCLUDE "source/kernel/features/utils.asm"
|
||||||
; GAMES -- Games that I wrote for it
|
; GAMES -- Games that I wrote for it
|
||||||
%INCLUDE "source/kernel/games/pong.asm"
|
%INCLUDE "source/kernel/games/pong.asm"
|
||||||
%INCLUDE "source/kernel/games/snake.asm"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user