Divide shell.asm logically into sections

This commit is contained in:
Juhani Krekelä 2023-03-27 11:34:21 +03:00
parent 71444f5ce7
commit feffd0cb28
1 changed files with 236 additions and 212 deletions

448
shell.asm
View File

@ -132,6 +132,10 @@ process_event:
pop bx pop bx
retf retf
; ------------------------------------------------------------------
; Event handlers
; ------------------------------------------------------------------
; in: ; in:
; al = WM_PAINT ; al = WM_PAINT
; bx = window ID ; bx = window ID
@ -277,85 +281,6 @@ mouse:
call forward_event call forward_event
ret ret
; in:
; ax = window ID
; bx = Y coördinate
; cx = X coördinate
; si = pointer to window structure
resize:
push dx
push bp
xor bp, bp ; Change?
mov dx, [si + window.res_y]
sub dx, bx
jc .end_y
cmp dx, WINDOW_MIN_HEIGHT
jl .end_y
cmp dx, ROWS
jg .end_y
cmp [si + window.y], bx
je .end_y
inc bp
mov [si + window.y], bx
mov [si + window.height], dx
.end_y:
mov dx, [si + window.res_x]
sub dx, cx
jc .end_x
cmp dx, WINDOW_MIN_WIDTH
jl .end_x
cmp dx, COLUMNS
jg .end_x
cmp [si + window.x], cx
je .end_x
inc bp
mov [si + window.x], cx
mov [si + window.width], dx
.end_x:
test bp, bp
jz .end
call render_file_window
call request_redraw
.end:
pop bp
pop dx
ret
; in:
; ax = window ID
; bx = Y coördinate
; cx = X coördinate
; si = pointer to window structure
move:
push dx
mov dx, cx
sub dx, [si + window.res_x]
cmp [si + window.y], bx
jne .change
cmp [si + window.x], dx
jne .change
jmp .end
.change:
mov [si + window.y], bx
mov [si + window.x], dx
call request_redraw
.end:
pop dx
ret
; in: ; in:
; ax = window ID ; ax = window ID
; bx = Y coördinate ; bx = Y coördinate
@ -440,68 +365,132 @@ click:
pop dx pop dx
ret ret
; in ; in:
; si = pointer to window structure ; al = WM_KEYBOARD
render_file_window: ; bx = window ID
call copy_dirents ; cl = typed character
; cl = typed key
push ax ; out:
push cx ; clobbers everything
push dx keyboard:
push es
mov ax, cs
mov es, ax
mov di, [si + window.data]
mov cx, [si + window.width]
mov ax, 0x0f00
rep stosw
mov cx, (ROWS-1)*COLUMNS
mov ax, 0xf000
rep stosw
mov di, [si + window.data]
mov byte [di], 0x17
mov byte [di + 2], 'A'
mov byte [di + 4], ':'
add di, [si + window.width]
add di, [si + window.width]
mov byte [di - 2], 'x'
mov cx, [si + window.height]
dec cx
mov dx, [si + window.width]
call print_ls
pop es
pop dx
pop cx
pop ax
ret ret
copy_dirents: ; in:
push cx ; al = WM_UNHOOK
push si ; bx = window ID
push di ; cx = window to unhook
push ds ; out:
push es ; ax = own ID if not the window to unhook
; next ID if the window to unhook
; clobbers everything else
unhook:
call get_window
mov bp, PONYDOS_SEG cmp bx, cx
mov ds, bp je .match
mov bp, cs
mov es, bp
mov si, GLOBAL_DIRENTS push bx
mov di, dirents
mov cx, FS_DIRENT_SIZE*FS_DIRECTORY_DIRENTS
rep movsb
pop es ; Forward the event
pop ds mov bx, [si + window.next]
pop di call forward_event
pop si
pop cx ; Update next ID
; If window.next was zero, forward_event will also return zero so
; this is safe in all cases
mov [si + window.next], ax
; Return own ID to keep self in the chain
pop ax
ret
.match:
; Return next ID in the chain to unhook
mov ax, [si + window.next]
ret
; ------------------------------------------------------------------
; Event handler subroutines
; ------------------------------------------------------------------
; in:
; ax = window ID
; bx = Y coördinate
; cx = X coördinate
; si = pointer to window structure
resize:
push dx
push bp
xor bp, bp ; Change?
mov dx, [si + window.res_y]
sub dx, bx
jc .end_y
cmp dx, WINDOW_MIN_HEIGHT
jl .end_y
cmp dx, ROWS
jg .end_y
cmp [si + window.y], bx
je .end_y
inc bp
mov [si + window.y], bx
mov [si + window.height], dx
.end_y:
mov dx, [si + window.res_x]
sub dx, cx
jc .end_x
cmp dx, WINDOW_MIN_WIDTH
jl .end_x
cmp dx, COLUMNS
jg .end_x
cmp [si + window.x], cx
je .end_x
inc bp
mov [si + window.x], cx
mov [si + window.width], dx
.end_x:
test bp, bp
jz .end
call render_file_window
call request_redraw
.end:
pop bp
pop dx
ret
; in:
; ax = window ID
; bx = Y coördinate
; cx = X coördinate
; si = pointer to window structure
move:
push dx
mov dx, cx
sub dx, [si + window.res_x]
cmp [si + window.y], bx
jne .change
cmp [si + window.x], dx
jne .change
jmp .end
.change:
mov [si + window.y], bx
mov [si + window.x], dx
call request_redraw
.end:
pop dx
ret ret
show_file_window: show_file_window:
@ -645,51 +634,40 @@ set_wallpaper:
call PONYDOS_SEG:SYS_MODIFY_SECTORS call PONYDOS_SEG:SYS_MODIFY_SECTORS
ret ret
; in: ; ------------------------------------------------------------------
; al = WM_KEYBOARD ; Windows
; bx = window ID ; ------------------------------------------------------------------
; cl = typed character
; cl = typed key
; out:
; clobbers everything
keyboard:
ret
; in: ; in:
; al = WM_UNHOOK
; bx = window ID ; bx = window ID
; cx = window to unhook
; out: ; out:
; ax = own ID if not the window to unhook ; ax = return value of event handler; 0 if window ID is 0
; next ID if the window to unhook forward_event:
; clobbers everything else push bp
unhook:
call get_window
cmp bx, cx cmp bx, 0
je .match je .id_is_zero
push bx push cs ; Return segment
mov bp, .end
push bp ; Return offset
; Forward the event mov bp, 0xf000
mov bx, [si + window.next] and bp, bx
call forward_event push bp ; Call segment
xor bp, bp
push bp ; Call offset
retf
; Update next ID .id_is_zero:
; If window.next was zero, forward_event will also return zero so ; This gets skipped over in normal execution, because it
; this is safe in all cases ; explicitly returns to .end
mov [si + window.next], ax xor ax, ax
; Return own ID to keep self in the chain
pop ax
.end:
pop bp
ret ret
.match:
; Return next ID in the chain to unhook
mov ax, [si + window.next]
ret
; in: ; in:
; bx = valid window id for this process ; bx = valid window id for this process
; out: ; out:
@ -713,18 +691,6 @@ get_window:
pop bx pop bx
ret ret
request_redraw:
push es
push bp
mov bp, PONYDOS_SEG
mov es, bp
mov byte [es:GLOBAL_REDRAW], 1
pop bp
pop es
ret
; in: ; in:
; cx = window ID to unhook ; cx = window ID to unhook
unhook_window: unhook_window:
@ -778,6 +744,66 @@ raise_window:
pop bx pop bx
ret ret
; ------------------------------------------------------------------
; Painting
; ------------------------------------------------------------------
; in
; si = pointer to window structure
render_file_window:
call copy_dirents
push ax
push cx
push dx
push es
mov ax, cs
mov es, ax
mov di, [si + window.data]
mov cx, [si + window.width]
mov ax, 0x0f00
rep stosw
mov cx, (ROWS-1)*COLUMNS
mov ax, 0xf000
rep stosw
mov di, [si + window.data]
mov byte [di], 0x17
mov byte [di + 2], 'A'
mov byte [di + 4], ':'
add di, [si + window.width]
add di, [si + window.width]
mov byte [di - 2], 'x'
mov cx, [si + window.height]
dec cx
mov dx, [si + window.width]
call print_ls
pop es
pop dx
pop cx
pop ax
ret
request_redraw:
push es
push bp
mov bp, PONYDOS_SEG
mov es, bp
mov byte [es:GLOBAL_REDRAW], 1
pop bp
pop es
ret
; ------------------------------------------------------------------
; File access
; ------------------------------------------------------------------
; in ; in
; cx = height of window (>= 1) ; cx = height of window (>= 1)
; dx = width of window in characters ; dx = width of window in characters
@ -905,6 +931,34 @@ print_ls:
pop ax pop ax
ret 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
; ------------------------------------------------------------------
; String routines
; ------------------------------------------------------------------
; in: ; in:
; ds:si = string ; ds:si = string
; out: ; out:
@ -954,36 +1008,6 @@ strcmp:
pop si pop si
ret ret
; in:
; bx = window ID
; out:
; ax = return value of event handler; 0 if window ID is 0
forward_event:
push bp
cmp bx, 0
je .id_is_zero
push cs ; Return segment
mov bp, .end
push bp ; Return offset
mov bp, 0xf000
and bp, bx
push bp ; Call segment
xor bp, bp
push bp ; Call offset
retf
.id_is_zero:
; This gets skipped over in normal execution, because it
; explicitly returns to .end
xor ax, ax
.end:
pop bp
ret
wallpaper_name db 'ponydos.wall' wallpaper_name db 'ponydos.wall'
times FS_DIRENT_NAME_SIZE-12 db 0 times FS_DIRENT_NAME_SIZE-12 db 0