EttinOS/src/FILEIFY.INC

121 lines
1.6 KiB
Plaintext

;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
mov di, buffer
mov al, 0xff
call readln
;Set SI and DI
mov si, buffer
mov di, .file
;Initialise the name with spaces
mov cx, 0xb
mov al, 0x20
rep stosb
sub di, 0xb
;Initialise the length counter for the main part of the name
mov bl, 0x8
.nameloop:
;Load a character
lodsb
;Check for a period
cmp al, 0x2e
je .initext
call .test
jmp .nameloop
.initext:
;Set DI and initialise the counter for the extension
mov bl, 0x3
mov di, .file+0x8
.extloop:
call .test
jmp .extloop
.error:
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
.done:
ret
.file times 0xc db 0x0
.errormsg db "Invalid file name", 0x0
.test:
;Check for the string end
cmp al, 0x0
je .print
;Check for the length limit
cmp bl, 0x0
je .error
;Check for invalid characters
cmp al, 0x22
je .error
cmp al, 0x2a
jl .contcheck1
cmp al, 0x2c
jg .contcheck1
jmp .error
.contcheck1:
cmp al, 0x2f
je .error
cmp al, 0x3a
jl .contcheck2
cmp al, 0x3f
jg .contcheck2
jmp .error
.contcheck2:
cmp al, 0x5b
jl .contcheck3
cmp al, 0x5d
jg .contcheck3
jmp .error
.contcheck3:
cmp al, 0x7c
je .error
;Find and convert lower case letters to upper case
;Check for lower case
cmp al, 0x61
jl .conttest
cmp al, 0x7a
jg .conttest
;Convert lower to upper case
sub al, 0x20
.conttest:
;Store the character
stosb
;Increase the counter
dec bl
ret