%define LSFS_magic_start_sector 2064 ; This is the sector right after the SingOS kernel stops and is a magic number that has to be changed when the kernel grows.
%define LSFS_magic_start_sector 24 ; This is the sector right after the SingOS kernel stops and is a magic number that has to be changed when the kernel grows.
%define FSCI_sector 88
lsfs_check_extended_support:
; We have to test if the System support exented read/write bios int 13,
; If not, the system cannot use the disk.
xor ax, ax
mov BYTE al, [global_disk_identifier]
call dumpax
mov ah, 0x41 ;Set AH = 0x41
mov bx, 0x55aa ;BX = 0x55AA
mov dl, [global_disk_identifier] ;DL = disk_id
@ -66,7 +71,7 @@ lsfs_get_fs_info:
pusha
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer
mov WORD [DAPACK.lba_addr_dw_low], LSFS_magic_start_sector
mov WORD [DAPACK.lba_addr_dw_low], FSCI_sector
mov WORD [DAPACK.blkcnt], 0x1 ; Read to sectors, that is what the space is for the buffer in svim
mov WORD [DAPACK.db_addr_segment], 0x50
mov si, DAPACK ; address of "disk address packet"
@ -84,15 +89,30 @@ lsfs_read_file:
; INPUT ax = file index
; INPUT bx = filebuffer
pusha ; save all register state
; Save the buffer addr
mov WORD [DAPACK.db_addr_offset], bx
; We need to find the data pointers for the file.
; The file index, has to be multiplied by the magic file_size
mov bx, LSFS_FIX_FILE_SIZE
mul bx
; OBS HARDCODED, The mul can give us a much higher number and DAPACK.lba_addr_dw_low takes a DWORD.
add ax, LSFS_magic_start_sector
push bx
mov dx, LSFS_magic_start_sector
add ax, dx ; senctor number, into the master Table.
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer
mov WORD [DAPACK.lba_addr_dw_low], ax
mov WORD [DAPACK.blkcnt], 0x1 ; Read to sectors, that is what the space is for the buffer in svim
mov WORD [DAPACK.db_addr_segment], 0x50
mov si, DAPACK ; address of "disk address packet"
mov ah, 0x42 ; READ
mov dl, [global_disk_identifier]
int 0x13
pop bx
; Save the buffer addr
mov WORD [DAPACK.db_addr_offset], bx
mov bx, [lsfs_loading_buffer + 288] ; this is the first data pointer
mov ax, bx
mov WORD [DAPACK.lba_addr_dw_low], bx
mov WORD [DAPACK.blkcnt], 0x4 ; Read to sectors, that is what the space is for the buffer in svim
mov WORD [DAPACK.db_addr_segment], 0x50
mov si, DAPACK ; address of "disk address packet"
@ -101,22 +121,49 @@ lsfs_read_file:
int 0x13
popa
mov ax, [lsfs_loading_buffer + 264]
ret
lsfs_write_file:
; INPUT ax = file index
; INPUT bx = filebuffer
; INOUT cx = file size
pusha ; save all register state
; Save the buffer addr
mov WORD [DAPACK.db_addr_offset], bx
; We need to find the data pointers for the file.
push bp
mov bp, sp
sub sp, 6
; The file index, has to be multiplied by the magic file_size
mov bx, LSFS_FIX_FILE_SIZE
mul bx
; OBS HARDCODED, The mul can give us a much higher number and DAPACK.lba_addr_dw_low takes a DWORD.
add ax, LSFS_magic_start_sector
%define var_file_id [bp - 0]
%define var_file_buffer [bp - 2]
%define var_file_size [bp - 4]
mov var_file_buffer, bx
mov var_file_size, cx
mov dx, LSFS_magic_start_sector
add ax, dx ; senctor number, into the master Table.
mov var_file_id, ax
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer
mov WORD [DAPACK.lba_addr_dw_low], ax
mov WORD [DAPACK.blkcnt], 0x1 ; Read to sectors, that is what the space is for the buffer in svim
mov WORD [DAPACK.db_addr_segment], 0x50
mov si, DAPACK ; address of "disk address packet"
mov ah, 0x42 ; READ
mov dl, [global_disk_identifier]
int 0x13
; Save the buffer addr
mov bx, var_file_buffer
mov WORD [DAPACK.db_addr_offset], bx
mov bx, [lsfs_loading_buffer + 288] ; this is the first data pointer
mov WORD [DAPACK.lba_addr_dw_low], bx
mov ax, bx
mov WORD [DAPACK.blkcnt], 0x4 ; Read to sectors, that is what the space is for the buffer in svim
mov WORD [DAPACK.db_addr_segment], 0x50
mov si, DAPACK ; address of "disk address packet"
@ -124,6 +171,21 @@ lsfs_write_file:
mov dl, [global_disk_identifier]
int 0x13
mov ax, var_file_id
mov bx, var_file_size
mov [lsfs_loading_buffer + 264], bx
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer
mov WORD [DAPACK.lba_addr_dw_low], ax
mov WORD [DAPACK.blkcnt], 0x1 ; Read to sectors, that is what the space is for the buffer in svim
mov WORD [DAPACK.db_addr_segment], 0x50
mov si, DAPACK ; address of "disk address packet"
mov ah, 0x43 ; WRITE
mov dl, [global_disk_identifier]
int 0x13
mov sp, bp
pop bp
popa
ret
@ -198,7 +260,7 @@ lsfs_create_file:
; We first need to know the index for the file.
; The next avaliable index are we going to get from the
mov WORD [DAPACK.db_addr_offset], lsfs_loading_buffer
@ -234,7 +297,7 @@ lsfs_create_file:
mov bx, ds
mov es, bx
mov ax, [lsfs_loading_buffer + 508] ; The number of files in the system
mov ax, [.to_write_fileindex_16_bit_part] ; The number of files in the system
add ax, LSFS_magic_start_sector ; The Master Record is at LSFS_magic_start_sector, plus the file index, then we have the sector where the file information has to be placed.
mov WORD [DAPACK.lba_addr_dw_low], ax
@ -250,9 +313,20 @@ lsfs_create_file:
ret
.lsfs_create_file_type_filename db 'Enter filename: ', 0
.new_filename_buffer times 122 db 0
.new_file_size dw 0, 0
.to_write_fileindex dw 0
.new_filename_buffer times 256 db 0
;.file_id:
.to_write_fileindex_16_bit_part dw 0
.to_write_fileindex dw 0, 0, 0
;.file_size
.new_file_size dw 0, 0, 0
.new_file_size_16_bit_part dw 0
.ext_file_data dw 0, 0, 0, 0
.control_bits dw 0, 0, 0, 0
;.file_data_pointers
.new_file_data_pointer dw 0
times 222 db 0
lsfs_list_files_command:
; This function takes the adress of the first sector of the disk
@ -278,7 +352,7 @@ lsfs_list_files_command:
mov si, .seperate_line
call print
mov WORD [.ls_counter], LSFS_magic_start_sector
mov WORD [.ls_counter], 23
.load_next_fileinfo:
add WORD [.ls_counter], 1
@ -292,12 +366,12 @@ lsfs_list_files_command:
mov dl, [global_disk_identifier]
int 0x13
mov ax, [lsfs_loading_buffer + 126]
mov ax, [lsfs_loading_buffer + 256]
mov bx, ax
mov cx, ' '
mov dx, 'X'
cmp ax, 0
cmp BYTE [lsfs_loading_buffer], 0
je .end_ls
cmp ax, 10
ja .index_over_10
@ -348,6 +422,13 @@ lsfs_disk_error_halt db 'press a key to continue with no disk operations', 13, 1
align 2
lsfs_loading_buffer times 512 db 0
MetaInformationFormat:
.filename: times 252 db 0
.file_id: dw 0
.file_size dw 0
.file_data_pointers times 256 db 0
DAPACK:
.dap_Size: db 0x10 ; This is always 16 bytes (0x10)
.rev_byte: db 0x0 ; reserved byte, should always be zero
@ -357,4 +438,4 @@ DAPACK:
.lba_addr_dw_low: dd 0x0 ; put the lba to read in this spot
.lba_addr_dw_high: dd 0x0 ; more storage bytes only for big lba's ( > 4 bytes )
lsfs_global_is_suported db 0x0 ; 0 means is not supported, when SingOS i booted it will check if it is supported (int 0x13 extended read/write)
lsfs_global_is_suported db 0x1 ; 0 means is not supported, when SingOS i booted it will check if it is supported (int 0x13 extended read/write)