Finish writing fileify, remove printch and readch since those have not proven useful, merge the code in byte2hex to keycode, and rename printnl back to newline because it was easy to confuse with println.

This commit is contained in:
CrazyEttin 2021-06-16 22:00:45 +03:00
parent a62a87970a
commit 45a11e601f
9 changed files with 89 additions and 128 deletions

View File

@ -1,49 +0,0 @@
;Converts a byte in AL to a hex string at DI.
byte2hex:
;Store the initial registers in the stack
push si
push ax
push bx
push cx
;Move the byte to AH
mov ah, al
;Set a key for the hex digits
mov si, .key
;Set a counter for the two hex digits
mov cx, 0x2
.loop:
;Read a nibble
rol ax, 0x1
rol ax, 0x1
rol ax, 0x1
rol ax, 0x1
mov bx, ax
;Convert the nibble to a hex digit
and bx, 0xf
mov bl, [si + bx]
;Store the hex digit
mov [di], bl
;Repeat
inc di
dec cx
jnz .loop
;Load the initial registers from the stack
pop cx
pop bx
pop ax
pop si
ret
.key db "0123456789abcdef"

View File

@ -1,7 +1,5 @@
;Reads a string, checks if it is a valid 8.3 file name, converts it into FAT formatting, and prints it. ;Reads a string, checks if it is a valid 8.3 file name, converts it into FAT formatting, and prints it.
;To do: change the .test call to work with flags instead of direct jumps.
fileify: fileify:
;Read a string ;Read a string
@ -23,39 +21,42 @@ sub di, 0xb
mov bl, 0x8 mov bl, 0x8
.nameloop: .nameloop:
;Load a character ;Load a character
lodsb lodsb
;Check for a period ;Check for a period
cmp al, 0x2e cmp al, 0x2e
je .initext je .initext
;Check for everything else and convert to upper case
call .test call .checkconv
jmp .nameloop jmp .nameloop
.initext: .initext:
;Set DI and initialise the counter for the extension ;Set DI and initialise the length counter for the extension
mov bl, 0x3 mov bl, 0x3
mov di, .file+0x8 mov di, .file+0x8
.extloop: .extloop:
call .test ;Load a character
lodsb
;Check for a period
push ax
cmp al, 0x2e
je .error
pop ax
;Check for everything else and convert to upper case
call .checkconv
jmp .extloop jmp .extloop
.error: .error:
pop ax
mov si, .errormsg mov si, .errormsg
call println call println
jmp .done jmp .done
.print: .print:
mov si, .name pop ax
call printstr mov si, .file
mov si, .extension call println
call printstr
mov al, 0x7c
call printch
call printnl
.done: .done:
ret ret
@ -64,7 +65,7 @@ ret
.errormsg db "Invalid file name", 0x0 .errormsg db "Invalid file name", 0x0
.test: .checkconv:
;Check for the string end ;Check for the string end
cmp al, 0x0 cmp al, 0x0
@ -103,13 +104,13 @@ je .error
;Find and convert lower case letters to upper case ;Find and convert lower case letters to upper case
;Check for lower case ;Check for lower case
cmp al, 0x61 cmp al, 0x61
jl .conttest jl .storech
cmp al, 0x7a cmp al, 0x7a
jg .conttest jg .storech
;Convert lower to upper case ;Convert lower to upper case
sub al, 0x20 sub al, 0x20
.conttest: .storech:
;Store the character ;Store the character
stosb stosb

View File

@ -17,13 +17,13 @@ call printstr
;Convert the scancode to a hex string ;Convert the scancode to a hex string
mov al, [.scan] mov al, [.scan]
mov di, .keycode mov di, .keycode
call byte2hex call .byte2hex
;Convert the ascii value to a hex string ;Convert the ascii value to a hex string
mov al, [.ascii] mov al, [.ascii]
mov di, .keycode mov di, .keycode
add di, 0x2 add di, 0x2
call byte2hex call .byte2hex
;Print the keycode ;Print the keycode
mov si, .keycode mov si, .keycode
@ -37,3 +37,51 @@ ret
.ascii db 0x0 .ascii db 0x0
.keycode times 0x5 db 0x0 .keycode times 0x5 db 0x0
.byte2hex:
;Store the initial registers in the stack
push si
push ax
push bx
push cx
;Move the byte to AH
mov ah, al
;Set a key for the hex digits
mov si, .key
;Set a counter for the two hex digits
mov cx, 0x2
.loop:
;Read a nibble
rol ax, 0x1
rol ax, 0x1
rol ax, 0x1
rol ax, 0x1
mov bx, ax
;Convert the nibble to a hex digit
and bx, 0xf
mov bl, [si + bx]
;Store the hex digit
mov [di], bl
;Repeat
inc di
dec cx
jnz .loop
;Load the initial registers from the stack
pop cx
pop bx
pop ax
pop si
ret
.key db "0123456789abcdef"

View File

@ -1,12 +1,12 @@
;Prints a newline ;Prints a newline
printnl: newline:
;Store the initial registers in the stack ;Store the initial registers in the stack
push si push si
;Print the newline ;Print the newline
mov si, .nl mov si, .newline
call printstr call printstr
;Load the initial registers from the stack ;Load the initial registers from the stack
@ -14,4 +14,4 @@ pop si
ret ret
.nl db 0xd, 0xa, 0x0 .newline db 0xd, 0xa, 0x0

View File

@ -1,8 +0,0 @@
;Prints a character from AL
printch:
mov ah, 0xe
int 0x10
ret

View File

@ -6,6 +6,6 @@ println:
call printstr call printstr
;Print a newline ;Print a newline
call printnl call newline
ret ret

View File

@ -1,28 +0,0 @@
;Reads a character to AL
readch:
;Store the initial registers
push bx
push ax
;Read a keypress
mov ah, 0x0
int 0x16
;Check for non-printing characters
cmp al, 0x1f
jle readch
cmp al, 0x7f
je readch
;Print the character
mov ah, 0xe
int 0x10
;Load the initial registers
pop bx
mov ah, bh
pop bx
ret

View File

@ -6,6 +6,6 @@ readln:
call readstr call readstr
;Print a newline ;Print a newline
call printnl call newline
ret ret

View File

@ -4,19 +4,16 @@ ORG 0x500
jmp start jmp start
;Calls ;Calls
%include "BYTE2HEX.INC"
%include "CMPSTR.INC" %include "CMPSTR.INC"
%include "PRINTNL.INC"
%include "PRINTCH.INC"
%include "PRINTSTR.INC" %include "PRINTSTR.INC"
%include "PRINTLN.INC"
%include "READCH.INC"
%include "READSTR.INC" %include "READSTR.INC"
%include "NEWLINE.INC"
%include "PRINTLN.INC"
%include "READLN.INC" %include "READLN.INC"
;Commands ;Commands
%include "ECHO.INC" %include "ECHO.INC"
;%include "FILEIFY.INC" %include "FILEIFY.INC"
%include "HELLO.INC" %include "HELLO.INC"
%include "HELP.INC" %include "HELP.INC"
%include "KEYCODE.INC" %include "KEYCODE.INC"
@ -59,20 +56,20 @@ je loop
mov si, buffer mov si, buffer
mov di, cmd.echo mov di, cmd.echo
call cmpstr call cmpstr
;jnc .fileify jnc .fileify
jnc .hello ;jnc .hello
;Execute ;Execute
call echo call echo
jmp loop jmp loop
;.fileify: .fileify:
;;Check ;Check
;mov si, buffer mov si, buffer
;mov di, cmd.fileify mov di, cmd.fileify
;call cmpstr call cmpstr
;jnc .hello jnc .hello
;;Execute ;Execute
;call fileify call fileify
;jmp loop jmp loop
.hello: .hello:
;Check ;Check
mov si, buffer mov si, buffer