2024-04-04 10:13:02 +00:00
|
|
|
;; File: fat12.inc
|
|
|
|
|
2024-07-29 14:40:21 +00:00
|
|
|
struc fat_bpb
|
|
|
|
{
|
|
|
|
.jump db 3 dup(?)
|
|
|
|
.oem_name db 8 dup(?)
|
|
|
|
.bytes_per_sects dw ?
|
|
|
|
.sects_per_clust db ?
|
|
|
|
.reserved_sects dw ?
|
|
|
|
.FAT_count db ?
|
|
|
|
.root_dir_entries dw ?
|
|
|
|
.total_sects dw ?
|
|
|
|
.media_type db ?
|
|
|
|
.sects_per_FAT dw ?
|
|
|
|
.sects_per_track dw ?
|
|
|
|
.heads_per_cyl dw ?
|
|
|
|
}
|
2024-08-31 12:40:07 +00:00
|
|
|
DEFN fat_bpb
|
2024-07-29 14:40:21 +00:00
|
|
|
|
2024-07-05 06:16:40 +00:00
|
|
|
;; Struct: fat_entry
|
2024-04-04 10:13:02 +00:00
|
|
|
struc fat_entry
|
|
|
|
{
|
|
|
|
.name db 8 dup ?
|
|
|
|
.ext db 3 dup ?
|
|
|
|
.attrs db ?
|
|
|
|
.reserved dw ?
|
|
|
|
.creation_time dw ?
|
|
|
|
.creation_date dw ?
|
|
|
|
.access_date dw ?
|
|
|
|
.reserved2 dw ?
|
|
|
|
.mod_time dw ?
|
|
|
|
.mod_date dw ?
|
|
|
|
.start dw ?
|
|
|
|
.size dd ?
|
|
|
|
}
|
2024-08-31 12:40:07 +00:00
|
|
|
DEFN fat_entry
|
2024-04-04 10:13:02 +00:00
|
|
|
|
2024-07-05 06:16:40 +00:00
|
|
|
;; Constants: Attributes
|
|
|
|
;; ATTR_READ_ONLY - Read-only
|
|
|
|
;; ATTR_HIDDEN - Hidden
|
|
|
|
;; ATTR_SYSTEM - System
|
|
|
|
;; ATTR_VOLUME_ID - Volume label
|
|
|
|
;; ATTR_DIRECTORY - Subdirectory
|
|
|
|
;; ATTR_ARCHIVE - Archive
|
|
|
|
ATTR_READ_ONLY = 0x01
|
|
|
|
ATTR_HIDDEN = 0x02
|
|
|
|
ATTR_SYSTEM = 0x04
|
|
|
|
ATTR_VOLUME_ID = 0x08
|
|
|
|
ATTR_DIRECTORY = 0x10
|
|
|
|
ATTR_ARCHIVE = 0x20
|
|
|
|
|
|
|
|
;; Section: Globals
|
|
|
|
|
2024-04-04 10:13:02 +00:00
|
|
|
;; Function: fat_load_root
|
2024-03-31 10:27:15 +00:00
|
|
|
fat_load_root:
|
2024-04-04 10:13:02 +00:00
|
|
|
mov ax, DISK_BUFFER/0x10
|
|
|
|
mov es, ax
|
|
|
|
|
|
|
|
; load root directory
|
|
|
|
mov ax, [sectors_per_FAT]
|
|
|
|
xor cx, cx
|
|
|
|
mov cl, [FAT_count]
|
|
|
|
mul cx
|
|
|
|
add ax, [reserved_sectors]
|
|
|
|
push ax
|
|
|
|
|
|
|
|
mov bx, [bytes_per_sector]
|
|
|
|
mov cl, 0x5
|
|
|
|
shr bx, cl
|
|
|
|
mov ax, [root_dir_entries]
|
|
|
|
xor dx, dx
|
|
|
|
div bx
|
|
|
|
mov cx, ax
|
|
|
|
pop ax
|
|
|
|
|
|
|
|
mov [data_start], ax
|
|
|
|
add [data_start], cx
|
|
|
|
|
|
|
|
xor bx, bx
|
|
|
|
|
|
|
|
call disk_read_sectors
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
;; Function: fat_search_root
|
|
|
|
;;
|
|
|
|
;; Parameters:
|
|
|
|
;;
|
|
|
|
;; SI - file to search
|
|
|
|
;;
|
2024-03-31 10:27:15 +00:00
|
|
|
fat_search_root:
|
2024-04-04 10:13:02 +00:00
|
|
|
mov cx, [root_dir_entries]
|
|
|
|
mov di, 0x0
|
2024-03-31 10:27:15 +00:00
|
|
|
@@:
|
2024-04-04 10:13:02 +00:00
|
|
|
push si
|
|
|
|
push cx
|
|
|
|
mov cx, 0xB ; name(8) + ext(3)
|
|
|
|
push di
|
|
|
|
rep cmpsb
|
|
|
|
pop di
|
|
|
|
pop cx
|
|
|
|
pop si
|
|
|
|
je .file_found
|
|
|
|
add di, 0x20
|
|
|
|
loop @b
|
|
|
|
; set carry if not found
|
|
|
|
stc
|
|
|
|
ret
|
2024-03-31 10:27:15 +00:00
|
|
|
.file_found:
|
2024-04-04 10:13:02 +00:00
|
|
|
mov ax, [es:di + fat_entry.start]
|
2024-06-14 03:32:46 +00:00
|
|
|
mov ebx, [es:di + fat_entry.size]
|
2024-04-04 10:13:02 +00:00
|
|
|
clc
|
|
|
|
ret
|
|
|
|
|
|
|
|
;; Function: fat_load_binary
|
|
|
|
;;
|
|
|
|
;; Parameters:
|
|
|
|
;; AX - cluster
|
|
|
|
;; ES:BX - buffer
|
2024-03-31 10:27:15 +00:00
|
|
|
fat_load_binary:
|
2024-04-04 10:13:02 +00:00
|
|
|
push ax
|
|
|
|
sub ax, 0x2
|
|
|
|
xor cx, cx
|
|
|
|
mov cl, [sectors_per_cluster]
|
|
|
|
mul cx
|
|
|
|
|
|
|
|
add ax, [data_start]
|
|
|
|
xor cx, cx
|
|
|
|
mov cl, [sectors_per_cluster]
|
|
|
|
call disk_read_sectors
|
|
|
|
|
|
|
|
pop ax
|
|
|
|
mov cx, ax
|
|
|
|
mov dx, ax
|
|
|
|
shr dx, 0x1
|
|
|
|
add cx, dx
|
|
|
|
push bx
|
|
|
|
mov bx, DISK_BUFFER
|
|
|
|
add bx, cx
|
|
|
|
mov dx, [bx]
|
|
|
|
pop bx
|
|
|
|
|
|
|
|
test ax, 0x1
|
|
|
|
jnz .odd_cluster
|
2024-03-31 10:27:15 +00:00
|
|
|
.even_cluster:
|
2024-04-04 10:13:02 +00:00
|
|
|
and dx, 0xFFF
|
|
|
|
jmp .end
|
2024-03-31 10:27:15 +00:00
|
|
|
.odd_cluster:
|
2024-04-04 10:13:02 +00:00
|
|
|
shr dx, 0x4
|
2024-03-31 10:27:15 +00:00
|
|
|
.end:
|
2024-04-04 10:13:02 +00:00
|
|
|
mov ax, dx
|
|
|
|
cmp dx, 0xFF0
|
|
|
|
jb fat_load_binary
|
|
|
|
ret
|
2024-03-31 10:27:15 +00:00
|
|
|
|
|
|
|
data_start dw 0x0
|