Add file sizes to ls.

This commit is contained in:
shikhin 2023-03-20 16:11:46 +05:30
parent 1bb62d1887
commit 140b191c0a
1 changed files with 97 additions and 25 deletions

122
shell.asm
View File

@ -68,16 +68,16 @@ initialize:
; Temporary testing
mov ax, cs
mov es, ax
mov di, window_1 + 16
mov cx, 3
mov dx, 8
call print_ls
mov di, window_2 + 32
mov di, window_1 + 32
mov cx, 3
mov dx, 16
call print_ls
mov di, window_2 + 80
mov cx, 3
mov dx, 40
call print_ls
ret
paint:
@ -100,8 +100,8 @@ paint:
mov byte [window_1.number], '1'
; Draw a rectangle on-screen
mov bx, 8
mov cx, 8
mov bx, 16
mov cx, 16
mov dx, 4
mov si, window_1
mov di, 10
@ -116,12 +116,12 @@ paint:
mov byte [window_2.number], '2'
mov bx, 16
mov cx, 16
mov bx, 40
mov cx, 40
mov dx, 4
mov si, window_2
mov di, 14
mov bp, 5
mov bp, 6
call PONYDOS_SEG:SYS_DRAW_RECT
ret
@ -131,6 +131,7 @@ paint:
; dx = width of window in characters
; es:di = start of output
print_ls:
push ax
push bx
push cx
push si
@ -140,13 +141,16 @@ print_ls:
mov bp, PONYDOS_SEG
mov ds, bp
push cx
push di
mov si, GLOBAL_DIRENTS + 2
.file_loop:
xor ax, ax ; Maximum filename size
.name_loop:
cmp word [ds:si - 2], 0
je .done
je .done_names
push cx
call strlen
mov bx, cx
@ -156,7 +160,12 @@ print_ls:
jle .not_long_filename
mov bx, dx
.not_long_filename:
cmp ax, bx
jge .not_new_max
mov ax, bx
.not_new_max:
push si
push di
.copy:
@ -171,13 +180,74 @@ print_ls:
add di, dx
add di, dx
add si, FS_DIRENT_SIZE
cmp si, GLOBAL_DIRENTS + 0x200
jge .done_names
dec cx
jnz .name_loop
.done_names:
pop di
pop cx
; Don't print sizes for too short a window
cmp dx, 10
jle .done
add ax, 5 ; 1 whitespace, 4 length
cmp ax, dx
jle .not_truncate
mov ax, dx
.not_truncate:
sub ax, 5 ; Go to start of where to put the file length
add di, ax
add di, ax
mov si, GLOBAL_DIRENTS
.size_loop:
mov ax, word [ds:si]
test ax, ax
jz .done
mov byte [es:di + 8], 'K'
shr ax, 1
aam ; mango
add ax, 0x3030
cmp ah, 0x30
je .one_digit
mov byte [es:di + 2], ' '
mov [es:di + 4], ah
jmp .one_digit_print
.one_digit:
test word [ds:si], 1
jnz .one_and_half_digit
mov byte [es:di + 4], ' '
.one_digit_print:
mov [es:di + 6], al
jmp .next_iter_size_loop
.one_and_half_digit:
mov byte [es:di], ' '
mov byte [es:di + 2], al
mov byte [es:di + 4], '.'
mov byte [es:di + 6], '5'
.next_iter_size_loop:
; Move to next line
add di, dx
add di, dx
add si, FS_DIRENT_SIZE
cmp si, GLOBAL_DIRENTS + 0x200
jge .done
dec cx
jnz .file_loop
jnz .size_loop
.done:
pop ds
pop bp
@ -185,6 +255,7 @@ print_ls:
pop si
pop cx
pop bx
pop ax
ret
; in:
@ -243,14 +314,15 @@ wallpaper_name db 'wallpaper.bin', 0
window_1:
db 'W', 0x0f, 'i', 0x0f, 'n', 0x0f, 'd', 0x0f, 'o', 0x0f, 'w', 0x0f, ' ', 0x0f,
.number db '*', 0x0f
times 8 db ' ', 0xf0
times 8 db ' ', 0xf0
times 8 db ' ', 0xf0
times 8 db ' ', 0x0f
times 16 db ' ', 0xf0
times 16 db ' ', 0xf0
times 16 db ' ', 0xf0
window_2:
db 'W', 0x0f, 'i', 0x0f, 'n', 0x0f, 'd', 0x0f, 'o', 0x0f, 'w', 0x0f, ' ', 0x0f,
.number db '*', 0x0f
times 8 db ' ', 0x0f
times 16 db ' ', 0xf0
times 16 db ' ', 0xf0
times 16 db ' ', 0xf0
times 32 db ' ', 0x0f
times 40 db ' ', 0xf0
times 40 db ' ', 0xf0
times 40 db ' ', 0xf0