From 45a11e601f35066e6e457942f413ae09f914709d Mon Sep 17 00:00:00 2001 From: CrazyEttin <> Date: Wed, 16 Jun 2021 22:00:45 +0300 Subject: [PATCH] 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. --- src/BYTE2HEX.INC | 49 ------------------------------ src/FILEIFY.INC | 39 ++++++++++++------------ src/KEYCODE.INC | 52 ++++++++++++++++++++++++++++++-- src/{PRINTNL.INC => NEWLINE.INC} | 6 ++-- src/PRINTCH.INC | 8 ----- src/PRINTLN.INC | 2 +- src/READCH.INC | 28 ----------------- src/READLN.INC | 2 +- src/SYSTEM.ASM | 31 +++++++++---------- 9 files changed, 89 insertions(+), 128 deletions(-) delete mode 100644 src/BYTE2HEX.INC rename src/{PRINTNL.INC => NEWLINE.INC} (75%) delete mode 100644 src/PRINTCH.INC delete mode 100644 src/READCH.INC diff --git a/src/BYTE2HEX.INC b/src/BYTE2HEX.INC deleted file mode 100644 index 78a6ac1..0000000 --- a/src/BYTE2HEX.INC +++ /dev/null @@ -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" diff --git a/src/FILEIFY.INC b/src/FILEIFY.INC index b9c0bd5..5a945f6 100644 --- a/src/FILEIFY.INC +++ b/src/FILEIFY.INC @@ -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. -;To do: change the .test call to work with flags instead of direct jumps. - fileify: ;Read a string @@ -23,39 +21,42 @@ sub di, 0xb mov bl, 0x8 .nameloop: - ;Load a character lodsb - ;Check for a period cmp al, 0x2e je .initext - -call .test +;Check for everything else and convert to upper case +call .checkconv jmp .nameloop .initext: -;Set DI and initialise the counter for the extension +;Set DI and initialise the length counter for the extension mov bl, 0x3 mov di, .file+0x8 .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 .error: +pop ax mov si, .errormsg call println jmp .done .print: -mov si, .name -call printstr -mov si, .extension -call printstr -mov al, 0x7c -call printch -call printnl +pop ax +mov si, .file +call println .done: ret @@ -64,7 +65,7 @@ ret .errormsg db "Invalid file name", 0x0 -.test: +.checkconv: ;Check for the string end cmp al, 0x0 @@ -103,13 +104,13 @@ je .error ;Find and convert lower case letters to upper case ;Check for lower case cmp al, 0x61 -jl .conttest +jl .storech cmp al, 0x7a -jg .conttest +jg .storech ;Convert lower to upper case sub al, 0x20 -.conttest: +.storech: ;Store the character stosb diff --git a/src/KEYCODE.INC b/src/KEYCODE.INC index e056e7e..8306bfa 100644 --- a/src/KEYCODE.INC +++ b/src/KEYCODE.INC @@ -17,13 +17,13 @@ call printstr ;Convert the scancode to a hex string mov al, [.scan] mov di, .keycode -call byte2hex +call .byte2hex ;Convert the ascii value to a hex string mov al, [.ascii] mov di, .keycode add di, 0x2 -call byte2hex +call .byte2hex ;Print the keycode mov si, .keycode @@ -37,3 +37,51 @@ ret .ascii 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" diff --git a/src/PRINTNL.INC b/src/NEWLINE.INC similarity index 75% rename from src/PRINTNL.INC rename to src/NEWLINE.INC index 481073f..e56c024 100644 --- a/src/PRINTNL.INC +++ b/src/NEWLINE.INC @@ -1,12 +1,12 @@ ;Prints a newline -printnl: +newline: ;Store the initial registers in the stack push si ;Print the newline -mov si, .nl +mov si, .newline call printstr ;Load the initial registers from the stack @@ -14,4 +14,4 @@ pop si ret -.nl db 0xd, 0xa, 0x0 +.newline db 0xd, 0xa, 0x0 diff --git a/src/PRINTCH.INC b/src/PRINTCH.INC deleted file mode 100644 index d508b3d..0000000 --- a/src/PRINTCH.INC +++ /dev/null @@ -1,8 +0,0 @@ -;Prints a character from AL - -printch: - -mov ah, 0xe -int 0x10 - -ret diff --git a/src/PRINTLN.INC b/src/PRINTLN.INC index 6045769..96b555a 100644 --- a/src/PRINTLN.INC +++ b/src/PRINTLN.INC @@ -6,6 +6,6 @@ println: call printstr ;Print a newline -call printnl +call newline ret diff --git a/src/READCH.INC b/src/READCH.INC deleted file mode 100644 index 9b0680e..0000000 --- a/src/READCH.INC +++ /dev/null @@ -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 diff --git a/src/READLN.INC b/src/READLN.INC index 9da3cb8..f97dd46 100644 --- a/src/READLN.INC +++ b/src/READLN.INC @@ -6,6 +6,6 @@ readln: call readstr ;Print a newline -call printnl +call newline ret diff --git a/src/SYSTEM.ASM b/src/SYSTEM.ASM index b804cfd..be0ca14 100644 --- a/src/SYSTEM.ASM +++ b/src/SYSTEM.ASM @@ -4,19 +4,16 @@ ORG 0x500 jmp start ;Calls -%include "BYTE2HEX.INC" %include "CMPSTR.INC" -%include "PRINTNL.INC" -%include "PRINTCH.INC" %include "PRINTSTR.INC" -%include "PRINTLN.INC" -%include "READCH.INC" %include "READSTR.INC" +%include "NEWLINE.INC" +%include "PRINTLN.INC" %include "READLN.INC" ;Commands %include "ECHO.INC" -;%include "FILEIFY.INC" +%include "FILEIFY.INC" %include "HELLO.INC" %include "HELP.INC" %include "KEYCODE.INC" @@ -59,20 +56,20 @@ je loop mov si, buffer mov di, cmd.echo call cmpstr -;jnc .fileify -jnc .hello +jnc .fileify +;jnc .hello ;Execute call echo jmp loop -;.fileify: -;;Check -;mov si, buffer -;mov di, cmd.fileify -;call cmpstr -;jnc .hello -;;Execute -;call fileify -;jmp loop +.fileify: +;Check +mov si, buffer +mov di, cmd.fileify +call cmpstr +jnc .hello +;Execute +call fileify +jmp loop .hello: ;Check mov si, buffer