2021-06-16 15:03:31 +00:00
|
|
|
;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
|
|
|
|
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
|
2021-06-16 19:00:45 +00:00
|
|
|
;Check for everything else and convert to upper case
|
|
|
|
call .checkconv
|
2021-06-16 15:03:31 +00:00
|
|
|
jmp .nameloop
|
|
|
|
|
|
|
|
.initext:
|
2021-06-16 19:00:45 +00:00
|
|
|
;Set DI and initialise the length counter for the extension
|
2021-06-16 15:03:31 +00:00
|
|
|
mov bl, 0x3
|
|
|
|
mov di, .file+0x8
|
|
|
|
|
|
|
|
.extloop:
|
2021-06-16 19:00:45 +00:00
|
|
|
;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
|
2021-06-16 15:03:31 +00:00
|
|
|
jmp .extloop
|
|
|
|
|
|
|
|
.error:
|
2021-06-16 19:00:45 +00:00
|
|
|
pop ax
|
2021-06-16 15:03:31 +00:00
|
|
|
mov si, .errormsg
|
|
|
|
call println
|
|
|
|
jmp .done
|
|
|
|
|
|
|
|
.print:
|
2021-06-16 19:00:45 +00:00
|
|
|
pop ax
|
|
|
|
mov si, .file
|
|
|
|
call println
|
2021-06-16 15:03:31 +00:00
|
|
|
|
|
|
|
.done:
|
|
|
|
ret
|
|
|
|
|
|
|
|
.file times 0xc db 0x0
|
|
|
|
|
|
|
|
.errormsg db "Invalid file name", 0x0
|
|
|
|
|
2021-06-16 19:00:45 +00:00
|
|
|
.checkconv:
|
2021-06-16 15:03:31 +00:00
|
|
|
|
|
|
|
;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
|
2021-06-16 19:00:45 +00:00
|
|
|
jl .storech
|
2021-06-16 15:03:31 +00:00
|
|
|
cmp al, 0x7a
|
2021-06-16 19:00:45 +00:00
|
|
|
jg .storech
|
2021-06-16 15:03:31 +00:00
|
|
|
;Convert lower to upper case
|
|
|
|
sub al, 0x20
|
|
|
|
|
2021-06-16 19:00:45 +00:00
|
|
|
.storech:
|
2021-06-16 15:03:31 +00:00
|
|
|
|
|
|
|
;Store the character
|
|
|
|
stosb
|
|
|
|
|
|
|
|
;Increase the counter
|
|
|
|
dec bl
|
|
|
|
|
|
|
|
ret
|