mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
122 lines
1.8 KiB
Plaintext
122 lines
1.8 KiB
Plaintext
NAME_MAX := 256
|
|
|
|
CMD.builtins.dir:
|
|
push nx0
|
|
|
|
sub nx0, nx0 # no. of files found
|
|
|
|
mov ax0, .dirmsg
|
|
call print
|
|
|
|
.dirmsg = " Directory of C:\\\n\n"
|
|
|
|
.first:
|
|
mov ax0, .buf
|
|
mov ax1, NAME_MAX
|
|
call DISK.FindFirst
|
|
jmp .list
|
|
|
|
.next:
|
|
mov ax0, .buf
|
|
mov ax1, NAME_MAX
|
|
call DISK.FindNext
|
|
|
|
.list:
|
|
test rax, rax
|
|
j.z .end
|
|
|
|
; found something
|
|
inc nx0
|
|
|
|
; separate extension from file name
|
|
mov rcx, NAME_MAX
|
|
mov r10, .buf
|
|
mov r11, r10
|
|
scasb.rep.nz r10, '.'
|
|
|
|
.print_file_name:
|
|
prn b[r11]
|
|
inc r11
|
|
|
|
cmp r11, r10
|
|
j.b .print_file_name
|
|
|
|
; calculate where to put extension
|
|
lea r11, b[r10 - 1]
|
|
sub r11, .buf
|
|
|
|
.ext_pad:
|
|
; print at least 11 non-space characters before extension
|
|
cmp r11, 11
|
|
j.ae .print_ext
|
|
prn ' '
|
|
inc r11
|
|
jmp .ext_pad
|
|
|
|
.print_ext:
|
|
; here we print at least 4 characters excluding '.'
|
|
mov rcx, 4
|
|
prn ' '
|
|
|
|
cmp b[r10], '.'
|
|
inc.z r10
|
|
|
|
.print_ext.1:
|
|
cmp b[r10], 0
|
|
j.z .print_ext.2
|
|
|
|
; print and decrease rcx, unless it's already 0
|
|
prn b[r10]
|
|
inc r10
|
|
test rcx, rcx
|
|
dec.nz rcx
|
|
|
|
jmp .print_ext.1
|
|
|
|
.print_ext.2:
|
|
; did we print at least 4 bytes?
|
|
test rcx, rcx
|
|
j.z .print_bytes ; yes, carry on
|
|
|
|
prn.rep ' '
|
|
jmp .print_ext.2
|
|
|
|
.print_bytes:
|
|
; print file size in bytes
|
|
prn ' '
|
|
prn ' '
|
|
prn ' '
|
|
|
|
mov rax, rdx
|
|
shr rax, 10
|
|
and rdx, 1023
|
|
|
|
mov ax0, .bytesstr
|
|
push rdx
|
|
push rax
|
|
call printf
|
|
add rsp, 16
|
|
|
|
.bytesstr = "%d kilobytes + %d bytes"
|
|
|
|
.prepare_next:
|
|
; go find next entry
|
|
prn 10
|
|
jmp .next
|
|
|
|
.end:
|
|
mov ax0, .endstr1
|
|
push nx0
|
|
call printf
|
|
add rsp, 8
|
|
|
|
mov ax0, .endstr2
|
|
call print
|
|
|
|
pop nx0
|
|
ret
|
|
|
|
.buf = [256]
|
|
.endstr1 = " %d file(s)\n"
|
|
.endstr2 = " 0 dir(s)\n"
|