2019-07-10 17:17:45 +02:00
|
|
|
; The OS/K Team licenses this file to you under the MIT license.
|
|
|
|
; See the LICENSE file in the project root for more information.
|
|
|
|
|
2019-07-01 13:16:17 +02:00
|
|
|
NAME_MAX := 256
|
|
|
|
|
2019-07-10 17:17:45 +02:00
|
|
|
builtins.dir:
|
2019-07-01 13:16:17 +02:00
|
|
|
push nx0
|
|
|
|
|
2019-07-17 22:25:50 +02:00
|
|
|
mov nx0, zero # no. of files found
|
2019-07-01 13:16:17 +02:00
|
|
|
|
2019-07-02 20:13:05 +02:00
|
|
|
mov rcx, STRLEN_MAX
|
|
|
|
mov rdx, .dirmsg
|
|
|
|
prns.rep.nz rdx
|
2019-07-01 13:16:17 +02:00
|
|
|
|
2019-07-01 14:04:32 +02:00
|
|
|
.dirmsg = "Directory of C:\\\n\n"
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
.first:
|
2019-07-10 12:26:15 +02:00
|
|
|
mov rax, Sys.FindFirst
|
2019-07-01 13:16:17 +02:00
|
|
|
mov ax0, .buf
|
|
|
|
mov ax1, NAME_MAX
|
2019-07-10 12:26:15 +02:00
|
|
|
trap 0
|
|
|
|
|
2019-07-01 13:16:17 +02:00
|
|
|
jmp .list
|
|
|
|
|
|
|
|
.next:
|
2019-07-10 12:26:15 +02:00
|
|
|
mov rax, Sys.FindNext
|
2019-07-01 13:16:17 +02:00
|
|
|
mov ax0, .buf
|
|
|
|
mov ax1, NAME_MAX
|
2019-07-10 12:26:15 +02:00
|
|
|
trap 0
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
.list:
|
2019-07-02 20:13:05 +02:00
|
|
|
b.z rax, 0, .end
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
; found something
|
|
|
|
inc nx0
|
|
|
|
|
|
|
|
; separate extension from file name
|
|
|
|
mov rcx, NAME_MAX
|
|
|
|
mov r10, .buf
|
|
|
|
mov r11, r10
|
|
|
|
scasb.rep.nz r10, '.'
|
|
|
|
|
2019-07-02 20:13:05 +02:00
|
|
|
; print file name
|
2019-07-04 20:33:49 +02:00
|
|
|
sub rcx, r10, r11
|
2019-07-02 20:13:05 +02:00
|
|
|
prns.rep r11
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
; calculate where to put extension
|
2019-07-04 20:33:49 +02:00
|
|
|
sub r11, r10, .buf
|
2019-07-01 21:46:36 +02:00
|
|
|
dec r11
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
.ext_pad:
|
|
|
|
; print at least 11 non-space characters before extension
|
2019-07-02 20:13:05 +02:00
|
|
|
b.ae r11, 11, .print_ext
|
2019-07-01 13:16:17 +02:00
|
|
|
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:
|
2019-07-02 20:13:05 +02:00
|
|
|
b.z b[r10], 0, .print_ext.2
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
; print and decrease rcx, unless it's already 0
|
|
|
|
prn b[r10]
|
|
|
|
inc r10
|
2019-07-02 20:13:05 +02:00
|
|
|
dec.cxnz rcx
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
jmp .print_ext.1
|
|
|
|
|
|
|
|
.print_ext.2:
|
|
|
|
; did we print at least 4 bytes?
|
2019-07-17 22:25:50 +02:00
|
|
|
jmp.cxz .print_bytes ; yes, carry on
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
prn.rep ' '
|
|
|
|
|
|
|
|
.print_bytes:
|
|
|
|
; print file size in bytes
|
|
|
|
prn ' '
|
|
|
|
prn ' '
|
|
|
|
prn ' '
|
|
|
|
|
2019-07-05 14:06:14 +02:00
|
|
|
shr rax, rdx, 10
|
2019-07-17 22:25:50 +02:00
|
|
|
and rdx, rdx, 1023
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
mov ax0, .bytesstr
|
|
|
|
push rdx
|
|
|
|
push rax
|
|
|
|
call printf
|
2019-07-17 22:25:50 +02:00
|
|
|
add rsp, rsp, 16
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
.bytesstr = "%d kilobytes + %d bytes"
|
|
|
|
|
|
|
|
.prepare_next:
|
|
|
|
; go find next entry
|
|
|
|
prn 10
|
|
|
|
jmp .next
|
|
|
|
|
|
|
|
.end:
|
|
|
|
mov ax0, .endstr1
|
|
|
|
push nx0
|
|
|
|
call printf
|
2019-07-17 22:25:50 +02:00
|
|
|
add rsp, rsp, 8
|
2019-07-01 13:16:17 +02:00
|
|
|
|
2019-07-02 20:13:05 +02:00
|
|
|
mov rcx, STRLEN_MAX
|
|
|
|
mov rdx, .endstr2
|
|
|
|
prns.rep.nz rdx
|
2019-07-01 13:16:17 +02:00
|
|
|
|
|
|
|
pop nx0
|
|
|
|
ret
|
|
|
|
|
|
|
|
.buf = [256]
|
|
|
|
.endstr1 = " %d file(s)\n"
|
|
|
|
.endstr2 = " 0 dir(s)\n"
|
2019-07-01 14:04:32 +02:00
|
|
|
|