Add rudimentary ls

This commit is contained in:
shikhin 2023-03-20 14:30:57 +05:30
parent c4dc87c8fd
commit 1bb62d1887
3 changed files with 119 additions and 13 deletions

View File

@ -11,9 +11,6 @@ org 0x7c00
COLUMNS equ 80
ROWS equ 25
DIRENT_SIZE equ 32
FILE_MAX_SIZE equ 128
jmp 0:start
start:
@ -336,8 +333,8 @@ open_file:
popa
je .success
add ax, FILE_MAX_SIZE
add di, DIRENT_SIZE
add ax, FS_FILE_MAX_SIZE
add di, FS_DIRENT_SIZE
cmp di, GLOBAL_DIRENTS + 0x200
jl .loop

View File

@ -3,5 +3,8 @@ PONYDOS_SEG equ 0
GLOBAL_WALLPAPER equ 0x500
GLOBAL_DIRENTS equ 0x2000
FS_DIRENT_SIZE equ 32
FS_FILE_MAX_SIZE equ 128
WM_INITIALIZE equ 0
WM_PAINT equ 1

122
shell.asm
View File

@ -65,6 +65,19 @@ initialize:
xchg [es:GLOBAL_WINDOW_CHAIN_HEAD], ax
mov [next_window2], ax
; 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 cx, 3
mov dx, 16
call print_ls
ret
paint:
@ -84,13 +97,13 @@ paint:
mov bx, [next_window1]
call forward_event
mov byte [window.number], '1'
mov byte [window_1.number], '1'
; Draw a rectangle on-screen
mov bx, 8
mov cx, 8
mov dx, 4
mov si, window
mov si, window_1
mov di, 10
mov bp, 3
call PONYDOS_SEG:SYS_DRAW_RECT
@ -101,18 +114,103 @@ paint:
mov bx, [next_window2]
call forward_event
mov byte [window.number], '2'
mov byte [window_2.number], '2'
mov bx, 8
mov cx, 8
mov bx, 16
mov cx, 16
mov dx, 4
mov si, window
mov si, window_2
mov di, 14
mov bp, 4
mov bp, 5
call PONYDOS_SEG:SYS_DRAW_RECT
ret
; in
; cx = height of window (>= 1)
; dx = width of window in characters
; es:di = start of output
print_ls:
push bx
push cx
push si
push di
push bp
push ds
mov bp, PONYDOS_SEG
mov ds, bp
mov si, GLOBAL_DIRENTS + 2
.file_loop:
cmp word [ds:si - 2], 0
je .done
push cx
call strlen
mov bx, cx
pop cx
cmp bx, dx
jle .not_long_filename
mov bx, dx
.not_long_filename:
push si
push di
.copy:
movsb
inc di ; Formatting
dec bx
jnz .copy
pop di
pop si
; 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
.done:
pop ds
pop bp
pop di
pop si
pop cx
pop bx
ret
; in:
; ds:si = string
; out:
; cx = stlen
strlen:
push ax
push di
push es
mov cx, ds
mov es, cx
mov di, si
mov cx, -1
xor ax, ax
repne scasb
not cx
dec cx
pop es
pop di
pop ax
ret
; in:
; bx = window ID
; out:
@ -142,9 +240,17 @@ wallpaper_name db 'wallpaper.bin', 0
%include "debug.inc"
window:
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
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