You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
342 lines
9.6 KiB
342 lines
9.6 KiB
BITS 16
|
|
vsfs_format_disk:
|
|
; When SingOS it booted for the first time,
|
|
; we have to format the disk to create the global structure
|
|
; of the VSFS.
|
|
pusha
|
|
;AH 03h
|
|
;AL Sectors To Write Count
|
|
;CH Track
|
|
;CL Sector
|
|
;DH Head
|
|
;DL Drive
|
|
|
|
; Set the es to point to the data segment,
|
|
; this is the global segment, where we calculate all
|
|
; our adresses from
|
|
; ES:BX Buffer Address Pointer
|
|
mov bx, ds
|
|
mov es, bx
|
|
|
|
; Set the bx to point to the pointer of the sector we have to write
|
|
; to the disk.
|
|
mov bx, .vsfs_format_disk_buffer
|
|
mov ah, 0x03 ;Write sectors to drive
|
|
mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes)
|
|
mov cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
|
|
mov ch, 0x08
|
|
mov dh, 0x00 ;Head number
|
|
mov dl, [global_disk_identifier] ;Drive number
|
|
int 0x13 ;Low level disk services
|
|
|
|
popa
|
|
ret
|
|
|
|
.vsfs_format_disk_buffer db 'VSFS v0.1', 13, 10, '(VerySimpelFileSystem)', 13, 10, 'Developed to SingOS', 13, 10, 'by Jorn Guldberg', 13, 10, 0 ; 66 chars + 8 bytes
|
|
times 431 db 0
|
|
dw 8, 0, 9 ; Start index, number of files, next free index
|
|
|
|
vsfs_get_fs_info:
|
|
pusha
|
|
mov bx, ds
|
|
mov es, bx
|
|
mov bx, vsfs_loading_buffer
|
|
|
|
mov ah, 0x02 ; Read sectors from drive
|
|
mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes)
|
|
mov ch, 0x08 ; cylinder
|
|
mov cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
|
|
mov dh, 0x00 ; Head number
|
|
mov dl, [global_disk_identifier] ; Drive number
|
|
int 0x13
|
|
|
|
mov si, vsfs_loading_buffer
|
|
call print
|
|
popa
|
|
ret
|
|
|
|
vsfs_read_file_index_in_ax:
|
|
; INPUT ax = file index
|
|
; INPUT bx = filebuffer
|
|
pusha ; save all register state
|
|
;call vsfs_convert_index_into_regs
|
|
;mov bx, .buffer_for_svim
|
|
push bx
|
|
mov bx, ds
|
|
mov es, bx
|
|
pop bx
|
|
|
|
mov ch, al ; Low 8 bits of cylinder
|
|
; the file index into ch, we need to calculatet this, if the number is larger than 16-bits
|
|
mov ah, 0x02 ; Read sectors from drive
|
|
mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes)
|
|
mov cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
|
|
mov dh, 0x00 ; Head number
|
|
mov dl, [global_disk_identifier] ; Drive number
|
|
int 0x13
|
|
popa
|
|
ret
|
|
|
|
|
|
vsfs_write_file_to_index_in_ax:
|
|
pusha ; save all register state
|
|
;AH 03h
|
|
;AL Sectors To Write Count
|
|
;CH Track
|
|
;CL Sector
|
|
;DH Head
|
|
;DL Drive
|
|
;ES:BX Buffer Address Pointer
|
|
mov bx, ds
|
|
mov es, bx
|
|
xor bx, bx
|
|
;mov bx, .buffer_for_svim
|
|
xor cx, cx
|
|
xor ax, ax
|
|
mov ah, 0x03 ;Write sectors to drive
|
|
mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes)
|
|
mov cl, 0x03 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
|
|
mov ch, 0x02
|
|
mov dh, 0x01 ;Head number
|
|
mov dl, [global_disk_identifier] ;Drive number
|
|
int 0x13 ;Low level disk services
|
|
popa
|
|
ret
|
|
|
|
vsfs_convert_index_into_regs:
|
|
; This function takes a file index in ax, do the calculations
|
|
; to set the registers to the right place at the disk
|
|
; CH Track
|
|
; CL Sector
|
|
; DH Head
|
|
; The rest of the parameters is set in the read and write function.
|
|
|
|
ret
|
|
|
|
vsfs_create_file:
|
|
; ax pointer to filename
|
|
; bx size
|
|
; cx fileIndex
|
|
|
|
pusha ; save all register state
|
|
|
|
mov si, .vsfs_create_file_type_filename
|
|
call print
|
|
|
|
; Ask the user for the filename
|
|
xor bx, bx
|
|
xor cx, cx ; are going to be the counter
|
|
xor dx, dx
|
|
.enter_filename_loop:
|
|
push cx
|
|
mov ax, 0x10 ; BIOS call to wait for key
|
|
int 0x16
|
|
cmp ax, 0x1c0d ; enter key
|
|
je .filename_done
|
|
|
|
cmp ax, 0x0e08 ; backspace
|
|
jne .no_enter
|
|
pop cx
|
|
cmp cx, 0
|
|
je .enter_filename_loop
|
|
|
|
sub cx, 1
|
|
mov bx, .new_filename_buffer
|
|
add bx, cx
|
|
mov BYTE [bx], 0
|
|
; Go back one space
|
|
mov ax, 0x0e08 ; ah=0x0e means teletype output. al=0x08 means backspace character.
|
|
int 0x10
|
|
|
|
; Place a NULL
|
|
mov al, 0x0 ; NULL
|
|
int 0x10
|
|
|
|
; Go back one space again as the above print of NULL pushes the cursor forward again.
|
|
mov ax, 0x0e08
|
|
int 0x10
|
|
jmp .enter_filename_loop
|
|
|
|
.no_enter:
|
|
mov bh, 0x00
|
|
mov bl, 0x02
|
|
mov ah, 0x0E
|
|
int 0x10 ; print char
|
|
pop cx
|
|
mov bx, .new_filename_buffer
|
|
add bx, cx
|
|
mov [bx], al
|
|
add cx, 1
|
|
; filename must only be 120 chars
|
|
cmp cx, 120
|
|
jae .filename_done
|
|
|
|
jmp .enter_filename_loop
|
|
|
|
.filename_done:
|
|
pop cx ; Cleanup, and now contain filename size
|
|
mov bx, .new_filename_buffer
|
|
add bx, cx
|
|
mov BYTE [bx], 0
|
|
call printCRLF
|
|
|
|
|
|
; We first need to know the index for the file.
|
|
; The next avaliable index are we going to get from the
|
|
; FSinfo sctor of the disk:
|
|
mov bx, ds
|
|
mov es, bx
|
|
|
|
mov bx, vsfs_loading_buffer
|
|
mov ch, 0x08 ; Low 8 bits of cylinder
|
|
; the file index into ch, we need to calculatet this, if the number is larger than 16-bits
|
|
mov ah, 0x02 ; Read sectors from drive
|
|
mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes)
|
|
mov cl, 0x01 ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
|
|
mov dh, 0x00 ; Head number
|
|
mov dl, [global_disk_identifier] ; Drive number
|
|
int 0x13
|
|
|
|
mov ax, [vsfs_loading_buffer + 510]
|
|
mov [.to_write_fileindex], ax
|
|
|
|
; We have to do modulo 4, to know where in the sector the
|
|
; file entry has to be written
|
|
add DWORD [vsfs_loading_buffer + 510], 1
|
|
add DWORD [vsfs_loading_buffer + 508], 1
|
|
|
|
mov bx, vsfs_loading_buffer
|
|
mov ah, 0x03 ;Write sectors to drive
|
|
mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes)
|
|
mov cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
|
|
mov ch, 0x08
|
|
mov dh, 0x00 ;Head number
|
|
mov dl, [global_disk_identifier] ;Drive number
|
|
int 0x13 ;Low level disk services
|
|
|
|
; Now we have the index in ax.
|
|
|
|
;AH 03h
|
|
;AL Sectors To Write Count
|
|
;CH Track
|
|
;CL Sector
|
|
;DH Head
|
|
;DL Drive
|
|
|
|
; Set the es to point to the data segment,
|
|
; this is the global segment, where we calculate all
|
|
; our adresses from
|
|
; ES:BX Buffer Address Pointer
|
|
mov bx, ds
|
|
mov es, bx
|
|
|
|
mov bx, [.to_write_fileindex]
|
|
sub bx, 0x07 ; Det skal den bare
|
|
mov cl, bl ; First sector to write (bits 0-5), upper bits of cylinder (bits 6-7)
|
|
; Set the bx to point to the pointer of the sector we have to write
|
|
; to the disk.
|
|
mov bx, .new_filename_buffer
|
|
mov ah, 0x03 ;Write sectors to drive
|
|
mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes)
|
|
mov ch, 0x08
|
|
mov dh, 0x00 ;Head number
|
|
mov dl, [global_disk_identifier] ;Drive number
|
|
int 0x13 ;Low level disk services
|
|
popa
|
|
ret
|
|
|
|
.vsfs_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
|
|
|
|
vsfs_list_files_command:
|
|
; This function takes the adress of the first sector of the disk
|
|
; which the OS has to know
|
|
; the adress is given by ax
|
|
|
|
; Check which registers to save
|
|
pusha
|
|
|
|
; Load the master table into memory
|
|
;mov ax, 8 ; file index for master record
|
|
;mov bx, vsfs_loading_buffer ; pointer to the input buffer
|
|
;call vsfs_read_file_index_in_ax ; call the fucntion which read the master record
|
|
; TODO we might want this to be in memory at all times
|
|
; loaded already from boot
|
|
|
|
mov bx, ds
|
|
mov es, bx
|
|
|
|
mov si, .ls_header
|
|
call print
|
|
|
|
mov si, .seperate_line
|
|
call print
|
|
|
|
mov BYTE [.ls_counter], 1
|
|
.load_next_fileinfo:
|
|
add BYTE [.ls_counter], 1
|
|
mov bl, [.ls_counter]
|
|
mov cl, bl ; First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
|
|
mov bx, vsfs_loading_buffer
|
|
;mov ch, al ; Low 8 bits of cylinder
|
|
; the file index into ch, we need to calculatet this, if the number is larger than 16-bits
|
|
mov ah, 0x02 ; Read sectors from drive
|
|
mov al, 0x01 ; Number of sectors to read (8 * 512 = 4096 bytes)
|
|
mov ch, 0x08 ; cylinder
|
|
mov dh, 0x00 ; Head number
|
|
mov dl, [global_disk_identifier] ; Drive number
|
|
int 0x13
|
|
|
|
mov ax, [vsfs_loading_buffer + 126]
|
|
mov bx, ax
|
|
mov cx, ' '
|
|
mov dx, 'X'
|
|
|
|
cmp ax, 0
|
|
je .end_ls
|
|
cmp ax, 10
|
|
ja .index_over_10
|
|
mov [.fileentry_line + 3 ], cx
|
|
mov [.fileentry_line + 4 ], cx
|
|
add bx, 48 ; get ascii value
|
|
mov [.fileentry_line + 5 ], bl
|
|
jmp .stop_index
|
|
.index_over_10:
|
|
cmp ax, 10
|
|
ja .index_over_100
|
|
mov [.fileentry_line + 3 ], cx
|
|
mov [.fileentry_line + 4 ], dx
|
|
mov [.fileentry_line + 5 ], dx
|
|
jmp .stop_index
|
|
|
|
.index_over_100:
|
|
mov [.fileentry_line + 3 ], dx
|
|
mov [.fileentry_line + 4 ], dx
|
|
mov [.fileentry_line + 5 ], dx
|
|
|
|
|
|
.stop_index:
|
|
|
|
mov si, .fileentry_line ; printing the buffer
|
|
call print
|
|
mov si, vsfs_loading_buffer ; printing the buffer
|
|
call print
|
|
|
|
call printCRLF
|
|
mov si, .seperate_line
|
|
|
|
call print
|
|
jmp .load_next_fileinfo
|
|
|
|
.end_ls:
|
|
popa
|
|
ret
|
|
|
|
.ls_counter db 0
|
|
.ls_header db 'List of files:', 13, 10, 'Index | Filename ', 13, 10, 0
|
|
.seperate_line db '- - - - - - - - - - - - - - - - ', 13, 10, 0
|
|
.fileentry_line db ' 456 | ', 0
|
|
|
|
vsfs_loading_buffer times 512 db 0
|