158 lines
2.5 KiB
NASM
158 lines
2.5 KiB
NASM
|
CPU 8086
|
|||
|
ORG 0x2000
|
|||
|
|
|||
|
;List the files on a drive
|
|||
|
|
|||
|
;Store the drive number
|
|||
|
mov [drive], dl
|
|||
|
|
|||
|
;Load the disk description table
|
|||
|
;Set the source
|
|||
|
mov dl, [drive]
|
|||
|
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
|
|||
|
;Abort if the load failed
|
|||
|
jc done
|
|||
|
|
|||
|
;Store the disk values used for the rest of the call
|
|||
|
mov ax, word [buffer + 0xb]
|
|||
|
mov word [sectorsize], ax
|
|||
|
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
|
|||
|
|
|||
|
;Load the root
|
|||
|
;Set the source
|
|||
|
mov ah, 0x0
|
|||
|
mov al, [fats]
|
|||
|
mul word [sectorsperfat]
|
|||
|
add ax, [bootsectors]
|
|||
|
push ax
|
|||
|
call calcsource
|
|||
|
;Set the destination
|
|||
|
mov si, buffer
|
|||
|
mov bx, si
|
|||
|
;Set the size
|
|||
|
push dx
|
|||
|
mov ax, [rootentries]
|
|||
|
mov dx, 0x20
|
|||
|
mul dx
|
|||
|
mov dx, 0x0
|
|||
|
div word [sectorsize]
|
|||
|
pop dx
|
|||
|
push ax
|
|||
|
;Load
|
|||
|
mov ah, 0x2
|
|||
|
int 0x13
|
|||
|
|
|||
|
;List
|
|||
|
;Set SI to the root
|
|||
|
mov si, buffer
|
|||
|
;Initialise the loop
|
|||
|
mov cx, word [rootentries]
|
|||
|
mov ax, 0x0
|
|||
|
loop:
|
|||
|
;Store CX in the stack
|
|||
|
push cx
|
|||
|
;Check for an empty entry
|
|||
|
cmp byte [si], 0xe5
|
|||
|
je skip
|
|||
|
;Check for the end of entries
|
|||
|
cmp byte [si], 0x0
|
|||
|
je done
|
|||
|
;store AX in the stack
|
|||
|
push ax
|
|||
|
;Print the main part of the name
|
|||
|
mov cx, 0x8
|
|||
|
push ax
|
|||
|
printname:
|
|||
|
mov al, [si]
|
|||
|
mov ah, 0xe
|
|||
|
int 0x10
|
|||
|
inc si
|
|||
|
loop printname
|
|||
|
;Print a space
|
|||
|
mov al, 0x20
|
|||
|
mov ah, 0xe
|
|||
|
int 0x10
|
|||
|
;Print the extension
|
|||
|
mov cx, 0x3
|
|||
|
printext:
|
|||
|
mov al, [si]
|
|||
|
mov ah, 0xe
|
|||
|
int 0x10
|
|||
|
inc si
|
|||
|
loop printext
|
|||
|
;Print a newline
|
|||
|
mov al, 0xd
|
|||
|
mov ah, 0xe
|
|||
|
int 0x10
|
|||
|
mov al, 0xa
|
|||
|
mov ah, 0xe
|
|||
|
int 0x10
|
|||
|
;Load AX from the stack
|
|||
|
pop ax
|
|||
|
skip:
|
|||
|
;Set SI to the next entry
|
|||
|
add ax, 0x20
|
|||
|
mov si, buffer
|
|||
|
add si, ax
|
|||
|
;Load CX from the stack
|
|||
|
pop cx
|
|||
|
loop loop
|
|||
|
|
|||
|
done:
|
|||
|
int 0x20
|
|||
|
|
|||
|
;Data
|
|||
|
drive db 0x0
|
|||
|
sectorsize dw 0x0 ;bytes
|
|||
|
bootsectors dw 0x0
|
|||
|
fats db 0x0
|
|||
|
rootentries dw 0x0
|
|||
|
sectorsperfat dw 0x0
|
|||
|
sectorspertrack dw 0x0
|
|||
|
sides dw 0x0
|
|||
|
|
|||
|
;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
|
|||
|
mov dl, byte [drive]
|
|||
|
ret
|
|||
|
|
|||
|
;Buffer
|
|||
|
buffer:
|
|||
|
|