2021-07-04 16:16:27 +00:00
|
|
|
;Load a file named at SI as a string ending in a null to the offset BX
|
2021-07-06 18:12:15 +00:00
|
|
|
;and store the file size in CX and the error codes in AL:
|
2021-07-01 13:50:43 +00:00
|
|
|
; * AL = 0x0: Succesful load
|
|
|
|
; * AL = 0x1: Drive not found
|
|
|
|
; * AL = 0x2: Unable to read disk
|
|
|
|
; * AL = 0x4: File or command not found
|
|
|
|
; * AL = 0x8: Not enough memory
|
2021-06-22 13:05:09 +00:00
|
|
|
|
|
|
|
loadf:
|
|
|
|
|
|
|
|
;Store the initial registers in the stack
|
|
|
|
push bx
|
|
|
|
push dx
|
|
|
|
push si
|
|
|
|
push di
|
|
|
|
|
2021-06-28 17:00:22 +00:00
|
|
|
;Store the current drive and offset
|
2021-06-22 13:05:09 +00:00
|
|
|
mov word [.pointer], bx
|
2021-06-28 17:00:22 +00:00
|
|
|
mov dl, byte [drive]
|
|
|
|
mov byte [.drive], dl
|
|
|
|
|
|
|
|
;Change the drive if needed
|
|
|
|
;Check for a drive specification
|
|
|
|
cmp byte [si + 0x1], ":"
|
|
|
|
jne .start
|
|
|
|
;Check which drive to change to
|
|
|
|
cmp byte [si], "a"
|
|
|
|
je .cha
|
|
|
|
cmp byte [si], "A"
|
|
|
|
je .cha
|
|
|
|
cmp byte [si], "b"
|
|
|
|
je .chb
|
|
|
|
cmp byte [si], "B"
|
|
|
|
je .chb
|
|
|
|
cmp byte [si], "c"
|
|
|
|
je .chc
|
|
|
|
cmp byte [si], "C"
|
|
|
|
je .chc
|
|
|
|
cmp byte [si], "d"
|
|
|
|
je .chd
|
|
|
|
cmp byte [si], "D"
|
|
|
|
je .chd
|
2021-07-06 18:12:15 +00:00
|
|
|
;Set AL to 0x1, CX to 0x0, and print an error message
|
2021-06-28 17:00:22 +00:00
|
|
|
mov si, .driverrormsg
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x21
|
2021-07-01 13:50:43 +00:00
|
|
|
mov al, 0x1
|
2021-07-06 18:12:15 +00:00
|
|
|
mov cx, 0x0
|
2021-06-28 17:00:22 +00:00
|
|
|
jmp .done
|
|
|
|
;Change
|
|
|
|
.cha:
|
|
|
|
mov dl, 0x0
|
|
|
|
mov byte [.drive], dl
|
|
|
|
jmp .drivechanged
|
|
|
|
.chb:
|
|
|
|
mov dl, 0x1
|
|
|
|
mov byte [.drive], dl
|
|
|
|
jmp .drivechanged
|
|
|
|
.chc:
|
|
|
|
mov dl, 0x2
|
|
|
|
mov byte [.drive], dl
|
|
|
|
jmp .drivechanged
|
|
|
|
.chd:
|
|
|
|
mov dl, 0x3
|
|
|
|
mov byte [.drive], dl
|
|
|
|
.drivechanged:
|
|
|
|
add si, 0x2
|
|
|
|
|
|
|
|
.start:
|
2021-06-22 13:05:09 +00:00
|
|
|
|
|
|
|
;Set DI at .file and initialise it with spaces
|
|
|
|
mov di, .file
|
|
|
|
mov cx, 0xb
|
|
|
|
mov al, 0x20
|
|
|
|
rep stosb
|
|
|
|
sub di, 0xb
|
|
|
|
|
|
|
|
;Convert .file into FAT formatting
|
|
|
|
|
2021-06-27 16:22:58 +00:00
|
|
|
;Initialise the length counter for the main part of the file name
|
2021-06-22 13:05:09 +00:00
|
|
|
mov bl, 0x8
|
|
|
|
|
2021-06-27 16:22:58 +00:00
|
|
|
;Convert the main part of the file name
|
2021-06-22 13:05:09 +00:00
|
|
|
.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
|
|
|
|
|
|
|
|
;Convert the extension
|
|
|
|
.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
|
2021-07-06 18:12:15 +00:00
|
|
|
;Set AL to 0x4, CX to 0x0, and print an error message
|
2021-06-22 13:05:09 +00:00
|
|
|
.error:
|
|
|
|
pop ax
|
2021-06-28 17:00:22 +00:00
|
|
|
mov si, .filerrormsg
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x21
|
2021-07-01 13:50:43 +00:00
|
|
|
mov al, 0x4
|
2021-07-06 18:12:15 +00:00
|
|
|
mov cx, 0x0
|
2021-06-22 13:05:09 +00:00
|
|
|
jmp .done
|
|
|
|
|
|
|
|
;Find and load the file
|
|
|
|
|
|
|
|
.load:
|
|
|
|
pop ax
|
|
|
|
|
2021-06-24 15:34:41 +00:00
|
|
|
;Load the disk description table
|
|
|
|
;Set the source
|
2021-06-28 17:00:22 +00:00
|
|
|
mov dl, [.drive]
|
2021-06-24 15:34:41 +00:00
|
|
|
mov ch, 0x0
|
|
|
|
mov dh, 0x0
|
|
|
|
mov cl, 0x1
|
|
|
|
;Set the destination
|
|
|
|
mov si, buffer
|
|
|
|
mov bx, si
|
|
|
|
;Set the size
|
|
|
|
mov al, 0x1
|
|
|
|
;Load
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x13
|
2021-06-29 17:05:14 +00:00
|
|
|
jnc .storevalues
|
2021-07-06 18:12:15 +00:00
|
|
|
;Set AL to 0x2, CX to 0x0, and print an error message
|
2021-06-29 17:05:14 +00:00
|
|
|
mov si, .diskerrormsg
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x21
|
2021-07-01 13:50:43 +00:00
|
|
|
mov al, 0x2
|
2021-07-06 18:12:15 +00:00
|
|
|
mov cx, 0x0
|
2021-06-29 17:05:14 +00:00
|
|
|
jmp .done
|
2021-06-24 15:34:41 +00:00
|
|
|
|
|
|
|
;Store the disk values used for the rest of the call
|
2021-06-29 17:05:14 +00:00
|
|
|
.storevalues:
|
2021-06-24 15:34:41 +00:00
|
|
|
mov ax, word [buffer + 0xb]
|
|
|
|
mov word [.sectorsize], ax
|
|
|
|
mov al, byte [buffer + 0xd]
|
|
|
|
mov byte [.clustersize], al
|
|
|
|
mov ax, word [buffer + 0xe]
|
|
|
|
mov word [.bootsectors], ax
|
|
|
|
mov al, byte [buffer + 0x10]
|
|
|
|
mov byte [.fats], al
|
|
|
|
mov ax, word [buffer + 0x11]
|
|
|
|
mov word [.rootentries], ax
|
|
|
|
mov ax, word [buffer + 0x16]
|
|
|
|
mov word [.sectorsperfat], ax
|
|
|
|
mov ax, word [buffer + 0x18]
|
|
|
|
mov word [.sectorspertrack], ax
|
|
|
|
mov ax, word [buffer + 0x1a]
|
|
|
|
mov word [.sides], ax
|
|
|
|
|
2021-06-22 13:05:09 +00:00
|
|
|
;Load the root
|
|
|
|
;Set the source
|
|
|
|
mov ah, 0x0
|
|
|
|
mov al, [.fats]
|
|
|
|
mul word [.sectorsperfat]
|
|
|
|
add ax, [.bootsectors]
|
|
|
|
push ax
|
|
|
|
;Set the destination
|
|
|
|
mov si, buffer
|
|
|
|
mov bx, si
|
|
|
|
;Set the size
|
|
|
|
mov ax, [.rootentries]
|
|
|
|
mov dx, 0x20
|
|
|
|
mul dx
|
|
|
|
mov dx, 0x0
|
|
|
|
div word [.sectorsize]
|
2021-07-01 17:40:28 +00:00
|
|
|
mov cx, ax
|
|
|
|
pop ax
|
|
|
|
push ax
|
|
|
|
push cx
|
|
|
|
.loadroot:
|
|
|
|
push cx
|
|
|
|
call .calcsource
|
|
|
|
;Set the size
|
2021-06-22 13:05:09 +00:00
|
|
|
push ax
|
2021-07-01 17:40:28 +00:00
|
|
|
mov al, 0x1
|
2021-06-22 13:05:09 +00:00
|
|
|
;Load
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x13
|
2021-07-01 17:40:28 +00:00
|
|
|
pop ax
|
|
|
|
;Set the next sector
|
|
|
|
add ax, 0x1
|
|
|
|
add bx, word [.sectorsize]
|
|
|
|
pop cx
|
|
|
|
loop .loadroot
|
2021-06-22 13:05:09 +00:00
|
|
|
|
|
|
|
;Search the root for the file entry
|
|
|
|
;Set DI to the root
|
|
|
|
mov di, buffer
|
|
|
|
;Initialise the search loop
|
|
|
|
mov cx, word [.rootentries]
|
|
|
|
mov ax, 0x0
|
|
|
|
.search:
|
|
|
|
;Store CX in the stack
|
|
|
|
push cx
|
|
|
|
;Check for the file entry
|
|
|
|
mov si, .file
|
|
|
|
mov cx, 0xb
|
|
|
|
rep cmpsb
|
2021-07-01 13:50:43 +00:00
|
|
|
je .checksize
|
2021-06-22 13:05:09 +00:00
|
|
|
;Set DI to the next entry
|
|
|
|
add ax, 0x20
|
|
|
|
mov di, buffer
|
|
|
|
add di, ax
|
|
|
|
;Load CX from the stack
|
|
|
|
pop cx
|
|
|
|
loop .search
|
2021-07-06 18:12:15 +00:00
|
|
|
;Set AL to 0x4, CX to 0x0, and print an error message
|
2021-06-28 17:00:22 +00:00
|
|
|
mov si, .filerrormsg
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x21
|
2021-07-01 13:50:43 +00:00
|
|
|
mov al, 0x4
|
2021-07-06 18:12:15 +00:00
|
|
|
mov cx, 0x0
|
2021-06-22 13:05:09 +00:00
|
|
|
jmp .clearstack
|
|
|
|
|
2021-07-06 18:12:15 +00:00
|
|
|
;Check and store the file size
|
2021-07-01 13:50:43 +00:00
|
|
|
.checksize:
|
2021-06-22 13:05:09 +00:00
|
|
|
;Load CX from the stack
|
|
|
|
pop cx
|
2021-07-01 13:50:43 +00:00
|
|
|
;Check for files larger than 64 KiB
|
|
|
|
cmp word [di + 0x13], 0x0
|
|
|
|
jne .sizerror
|
|
|
|
;Get the cluster size in bytes
|
|
|
|
mov ah, 0x0
|
|
|
|
mov al, [.clustersize]
|
|
|
|
mul word [.sectorsize]
|
|
|
|
mov bx, ax
|
2021-07-06 18:12:15 +00:00
|
|
|
;Store the file size
|
|
|
|
mov ax, [di + 0x11]
|
|
|
|
mov word [.size], ax
|
2021-07-01 13:50:43 +00:00
|
|
|
;Check for files smaller than 64 KiB but too large to fit into memory
|
|
|
|
jc .sizerror
|
|
|
|
dec ax
|
|
|
|
mov dx, 0x0
|
|
|
|
div bx
|
|
|
|
mul bx
|
|
|
|
add ax, [.pointer]
|
2021-07-04 16:16:27 +00:00
|
|
|
jnc .loadfat
|
2021-07-06 18:12:15 +00:00
|
|
|
;Set AL to 0x8, CX to 0x0, and print an error message
|
2021-07-01 13:50:43 +00:00
|
|
|
.sizerror:
|
|
|
|
mov si, .sizerrormsg
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x21
|
|
|
|
mov al, 0x8
|
2021-07-06 18:12:15 +00:00
|
|
|
mov cx, 0x0
|
2021-07-01 13:50:43 +00:00
|
|
|
jmp .clearstack
|
|
|
|
|
2021-07-04 16:16:27 +00:00
|
|
|
;Load the FAT
|
|
|
|
.loadfat:
|
|
|
|
;Store the first cluster of the file
|
|
|
|
mov ax, word [di + 0xf]
|
2021-06-22 13:05:09 +00:00
|
|
|
mov word [.cluster], ax
|
|
|
|
;Set the source
|
|
|
|
mov ax, 0x1
|
|
|
|
call .calcsource
|
|
|
|
;Set the destination
|
|
|
|
mov di, buffer
|
|
|
|
mov bx, di
|
|
|
|
;Set the size
|
|
|
|
mov ax, [.sectorsperfat]
|
|
|
|
;Load
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x13
|
|
|
|
|
|
|
|
;Load the file
|
|
|
|
|
|
|
|
;Load a cluster
|
|
|
|
.loadcluster:
|
|
|
|
;Set the source
|
|
|
|
pop cx
|
|
|
|
pop bx
|
|
|
|
mov ax, word [.cluster]
|
|
|
|
sub ax, 0x2
|
|
|
|
mul byte [.clustersize]
|
|
|
|
add ax, bx
|
|
|
|
add ax, cx
|
|
|
|
push bx
|
|
|
|
push cx
|
|
|
|
;Set the destination
|
|
|
|
mov bx, word [.pointer]
|
2021-06-26 15:55:47 +00:00
|
|
|
;Load a sector
|
|
|
|
mov ch, 0x0
|
|
|
|
mov cl, byte [.clustersize]
|
|
|
|
.loadsector:
|
|
|
|
push cx
|
|
|
|
call .calcsource
|
2021-06-22 13:05:09 +00:00
|
|
|
;Set the size
|
2021-06-26 15:55:47 +00:00
|
|
|
push ax
|
|
|
|
mov al, 0x1
|
2021-06-22 13:05:09 +00:00
|
|
|
;Load
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x13
|
2021-06-26 15:55:47 +00:00
|
|
|
pop ax
|
|
|
|
;Set the next sector
|
|
|
|
add ax, 0x1
|
|
|
|
add bx, word [.sectorsize]
|
|
|
|
pop cx
|
|
|
|
loop .loadsector
|
2021-06-22 13:05:09 +00:00
|
|
|
|
|
|
|
;Calculate the next cluster
|
|
|
|
mov ax, [.cluster]
|
|
|
|
mov dx, 0x0
|
|
|
|
mov bx, 0x3
|
|
|
|
mul bx
|
|
|
|
mov bx, 0x2
|
|
|
|
div bx
|
|
|
|
mov si, buffer
|
|
|
|
add si, ax
|
|
|
|
mov ax, word [ds:si]
|
|
|
|
or dx, dx
|
|
|
|
jz .even
|
|
|
|
shr ax, 1
|
|
|
|
shr ax, 1
|
|
|
|
shr ax, 1
|
|
|
|
shr ax, 1
|
|
|
|
jmp .contcalc
|
|
|
|
.even:
|
|
|
|
and ax, 0xfff
|
|
|
|
.contcalc:
|
|
|
|
mov word [.cluster], ax
|
|
|
|
cmp ax, 0xff8
|
2021-07-01 13:50:43 +00:00
|
|
|
jge .success
|
2021-06-22 13:05:09 +00:00
|
|
|
mov ax, [.sectorsize]
|
|
|
|
mul word [.clustersize]
|
|
|
|
add word [.pointer], ax
|
|
|
|
jmp .loadcluster
|
|
|
|
|
2021-07-06 18:12:15 +00:00
|
|
|
;Set AL to 0x0 and load the file size to CX if the load was succesful
|
2021-07-01 13:50:43 +00:00
|
|
|
.success:
|
|
|
|
mov al, 0x0
|
2021-07-06 18:12:15 +00:00
|
|
|
mov cx, [.size]
|
2021-06-22 13:05:09 +00:00
|
|
|
|
|
|
|
;Clear the stack
|
|
|
|
.clearstack:
|
2021-07-06 18:12:15 +00:00
|
|
|
pop bx
|
2021-06-22 13:05:09 +00:00
|
|
|
pop bx
|
|
|
|
|
|
|
|
.done:
|
|
|
|
|
|
|
|
;Load the initial registers from the stack
|
|
|
|
pop di
|
|
|
|
pop si
|
|
|
|
pop dx
|
|
|
|
pop bx
|
|
|
|
|
2021-07-01 13:50:43 +00:00
|
|
|
;Set AH to its initial value
|
|
|
|
mov ah, 0x0
|
|
|
|
|
2021-06-22 13:05:09 +00:00
|
|
|
iret
|
|
|
|
|
|
|
|
;Data
|
2021-06-28 17:00:22 +00:00
|
|
|
.drive db 0x0
|
2021-06-24 15:34:41 +00:00
|
|
|
.sectorsize dw 0x0 ;bytes
|
|
|
|
.clustersize db 0x0 ;sectors
|
|
|
|
.bootsectors dw 0x0
|
|
|
|
.fats db 0x0
|
|
|
|
.rootentries dw 0x0
|
|
|
|
.sectorsperfat dw 0x0
|
|
|
|
.sectorspertrack dw 0x0
|
|
|
|
.sides dw 0x0
|
|
|
|
.file times 0xb db 0x20
|
2021-07-06 18:12:15 +00:00
|
|
|
.size dw 0x0
|
2021-06-24 15:34:41 +00:00
|
|
|
.cluster dw 0x0
|
|
|
|
.pointer dw 0x0
|
2021-06-28 17:00:22 +00:00
|
|
|
.driverrormsg db "Drive not found", 0x0
|
2021-07-01 13:50:43 +00:00
|
|
|
.diskerrormsg db "Unable to read disk", 0x0
|
|
|
|
.filerrormsg db "File or command not found", 0x0
|
|
|
|
.sizerrormsg db "Not enough memory", 0x0
|
2021-06-22 13:05:09 +00:00
|
|
|
|
2021-06-27 16:22:58 +00:00
|
|
|
;Check the file name and convert to upper case
|
2021-06-22 13:05:09 +00:00
|
|
|
.checkconv:
|
|
|
|
;Check for the string end
|
|
|
|
cmp al, 0x0
|
|
|
|
je .load
|
|
|
|
;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
|
|
|
|
;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
|
2021-06-24 15:34:41 +00:00
|
|
|
;Decrease the counter
|
2021-06-22 13:05:09 +00:00
|
|
|
dec bl
|
|
|
|
ret
|
|
|
|
|
|
|
|
;Calculate the source arguments for loading data from the disk
|
|
|
|
.calcsource:
|
|
|
|
push ax
|
|
|
|
push bx
|
|
|
|
mov bx, ax
|
|
|
|
mov dx, 0x0
|
|
|
|
div word [.sectorspertrack]
|
|
|
|
add dl, 0x1
|
|
|
|
mov cl, dl
|
|
|
|
mov ax, bx
|
|
|
|
mov dx, 0x0
|
|
|
|
div word [.sectorspertrack]
|
|
|
|
mov dx, 0x0
|
|
|
|
div word [.sides]
|
|
|
|
mov dh, dl
|
|
|
|
mov ch, al
|
|
|
|
pop bx
|
|
|
|
pop ax
|
2021-06-28 17:00:22 +00:00
|
|
|
mov dl, byte [.drive]
|
2021-06-22 13:05:09 +00:00
|
|
|
ret
|