EttinOS/src/FILEIFY.INC

125 lines
1.7 KiB
Plaintext

;Reads a string, checks if it is a valid 8.3 file name, converts it into FAT formatting, and prints it.
fileify:
;Read a string
mov di, buffer
mov al, 0xff
mov ah, 0x3
int 0x21
;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
;Check for everything else and convert to upper case
call .checkconv
jmp .nameloop
.initext:
;Set DI and initialise the length counter for the extension
mov bl, 0x3
mov di, .file+0x8
.extloop:
;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
mov ah, 0x2
int 0x21
jmp .done
.print:
pop ax
mov si, .file
mov ah, 0x2
int 0x21
.done:
ret
.file times 0xc db 0x0
.errormsg db "Invalid file name", 0x0
.checkconv:
;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 .storech
cmp al, 0x7a
jg .storech
;Convert lower to upper case
sub al, 0x20
.storech:
;Store the character
stosb
;Increase the counter
dec bl
ret