From 28423d0de37eabbdbe2a85dbfeec4db4c777706a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 27 Mar 2023 11:10:15 +0300 Subject: [PATCH] Re-render file window in shell if directory has changed --- shell.asm | 98 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/shell.asm b/shell.asm index 63f0fe1..36ed9ad 100644 --- a/shell.asm +++ b/shell.asm @@ -141,6 +141,24 @@ paint: mov bx, [si + window.next] call forward_event + cmp si, windows + 1*window.size + jne .not_file_window + .file_window: + ; See if the dirents have changed since we rendered the + ; window contents. If yes, rerender. + push si + mov bp, PONYDOS_SEG + mov es, bp + mov si, dirents + mov di, GLOBAL_DIRENTS + mov cx, FS_DIRENT_SIZE*FS_DIRECTORY_DIRENTS + repe cmpsb + pop si + je .no_rerender + call render_file_window + .no_rerender: + .not_file_window: + ; Draw a rectangle on-screen mov bx, [si + window.width] mov dx, [si + window.height] @@ -399,21 +417,13 @@ click: cmp ax, FS_DIRECTORY_DIRENTS jae .end - push ds - - mov bp, PONYDOS_SEG - mov ds, bp - mov bp, FS_DIRENT_SIZE mul bp - mov si, GLOBAL_DIRENTS + mov si, dirents add si, ax cmp word [si], 0 - jne .dirent_present - pop ds - jmp .end - .dirent_present: + je .end ; Copy file name to launch_filename add si, FS_DIRENT_NAME_OFFSET @@ -421,8 +431,6 @@ click: mov cx, FS_DIRENT_NAME_SIZE rep movsb - pop ds - call launch .end: @@ -433,6 +441,8 @@ click: ; in ; si = pointer to window structure render_file_window: + call copy_dirents + push ax push cx push dx @@ -468,6 +478,30 @@ render_file_window: pop ax ret +copy_dirents: + push cx + push si + push di + push ds + push es + + mov bp, PONYDOS_SEG + mov ds, bp + mov bp, cs + mov es, bp + + mov si, GLOBAL_DIRENTS + mov di, dirents + mov cx, FS_DIRENT_SIZE*FS_DIRECTORY_DIRENTS + rep movsb + + pop es + pop ds + pop di + pop si + pop cx + ret + show_file_window: cmp byte [file_window_visible], 0 jne .already_visible @@ -753,18 +787,14 @@ print_ls: push si push di push bp - push ds - - mov bp, PONYDOS_SEG - mov ds, bp push cx push di - mov si, GLOBAL_DIRENTS + FS_DIRENT_NAME_OFFSET + mov si, dirents + FS_DIRENT_NAME_OFFSET xor ax, ax ; Maximum filename size .name_loop: - cmp word [ds:si - FS_DIRENT_NAME_OFFSET], 0 + cmp word [si - FS_DIRENT_NAME_OFFSET], 0 je .done_names push cx @@ -797,7 +827,7 @@ print_ls: add di, dx add si, FS_DIRENT_SIZE - cmp si, GLOBAL_DIRENTS + FS_DIRECTORY_DIRENTS*FS_DIRENT_SIZE + cmp si, dirents + FS_DIRECTORY_DIRENTS*FS_DIRENT_SIZE jge .done_names dec cx @@ -820,13 +850,13 @@ print_ls: add di, ax add di, ax - mov si, GLOBAL_DIRENTS + mov si, dirents .size_loop: - mov ax, word [ds:si] + mov ax, word [si] test ax, ax jz .done - mov byte [es:di + 8], 'K' + mov byte [di + 8], 'K' shr ax, 1 aam ; mango @@ -834,23 +864,23 @@ print_ls: cmp ah, 0x30 je .one_digit - mov byte [es:di + 2], ' ' - mov [es:di + 4], ah + mov byte [di + 2], ' ' + mov [di + 4], ah jmp .one_digit_print .one_digit: - test word [ds:si], 1 + test word [si], 1 jnz .one_and_half_digit - mov byte [es:di + 4], ' ' + mov byte [di + 4], ' ' .one_digit_print: - mov [es:di + 6], al + mov [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' + mov byte [di], ' ' + mov byte [di + 2], al + mov byte [di + 4], '.' + mov byte [di + 6], '5' .next_iter_size_loop: ; Move to next line @@ -858,14 +888,13 @@ print_ls: add di, dx add si, FS_DIRENT_SIZE - cmp si, GLOBAL_DIRENTS + 0x200 + cmp si, dirents + FS_DIRECTORY_DIRENTS*FS_DIRENT_SIZE jge .done dec cx jnz .size_loop .done: - pop ds pop bp pop di pop si @@ -975,5 +1004,8 @@ windows: launch_filename times FS_DIRENT_NAME_SIZE db 0 section .bss +dirents: + resb FS_DIRENT_SIZE*FS_DIRECTORY_DIRENTS + file_window: resw ROWS*COLUMNS