Allow opening text files by clicking on them in the file window
This commit is contained in:
parent
ceb7745b42
commit
cb77e27fb2
|
@ -75,7 +75,6 @@ installation option, for your safety.
|
||||||
|
|
||||||
### Basic stuff
|
### Basic stuff
|
||||||
|
|
||||||
* be able to click on asm/text files in file listing to open
|
|
||||||
* delete the TODO from release README
|
* delete the TODO from release README
|
||||||
|
|
||||||
### Nice to have
|
### Nice to have
|
||||||
|
|
|
@ -16,6 +16,7 @@ WM_PAINT equ 0
|
||||||
WM_MOUSE equ 1
|
WM_MOUSE equ 1
|
||||||
WM_KEYBOARD equ 2
|
WM_KEYBOARD equ 2
|
||||||
WM_UNHOOK equ 3
|
WM_UNHOOK equ 3
|
||||||
|
WM_OPEN_FILE equ 4
|
||||||
|
|
||||||
MOUSE_PRIMARY equ 0x01
|
MOUSE_PRIMARY equ 0x01
|
||||||
MOUSE_SECONDARY equ 0x02
|
MOUSE_SECONDARY equ 0x02
|
||||||
|
|
189
shell.asm
189
shell.asm
|
@ -181,7 +181,7 @@ paint:
|
||||||
call get_window
|
call get_window
|
||||||
|
|
||||||
mov bx, [si + window.next]
|
mov bx, [si + window.next]
|
||||||
call forward_event
|
call send_event
|
||||||
|
|
||||||
cmp si, windows + WINDOW_ID_FILE_WINDOW*window.size
|
cmp si, windows + WINDOW_ID_FILE_WINDOW*window.size
|
||||||
jne .not_file_window
|
jne .not_file_window
|
||||||
|
@ -308,7 +308,7 @@ mouse:
|
||||||
mov cx, 0xffff
|
mov cx, 0xffff
|
||||||
mov bx, [si + window.next]
|
mov bx, [si + window.next]
|
||||||
mov al, WM_MOUSE
|
mov al, WM_MOUSE
|
||||||
call forward_event
|
call send_event
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.outside:
|
.outside:
|
||||||
|
@ -316,7 +316,7 @@ mouse:
|
||||||
pop cx
|
pop cx
|
||||||
mov bx, [si + window.next]
|
mov bx, [si + window.next]
|
||||||
mov al, WM_MOUSE
|
mov al, WM_MOUSE
|
||||||
call forward_event
|
call send_event
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; in:
|
; in:
|
||||||
|
@ -442,10 +442,10 @@ unhook:
|
||||||
|
|
||||||
; Forward the event
|
; Forward the event
|
||||||
mov bx, [si + window.next]
|
mov bx, [si + window.next]
|
||||||
call forward_event
|
call send_event
|
||||||
|
|
||||||
; Update next ID
|
; Update next ID
|
||||||
; If window.next was zero, forward_event will also return zero so
|
; If window.next was zero, send_event will also return zero so
|
||||||
; this is safe in all cases
|
; this is safe in all cases
|
||||||
mov [si + window.next], ax
|
mov [si + window.next], ax
|
||||||
|
|
||||||
|
@ -542,49 +542,129 @@ move:
|
||||||
pop dx
|
pop dx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; ------------------------------------------------------------------
|
||||||
|
; Launching
|
||||||
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
; out:
|
; out:
|
||||||
; clobbers everything
|
; clobbers everything
|
||||||
launch:
|
launch:
|
||||||
mov si, launch_filename
|
mov si, launch_filename
|
||||||
|
|
||||||
; Is it a .wall file?
|
; 4 letter file extension?
|
||||||
call strlen
|
call strlen
|
||||||
cmp cx, 5
|
cmp cx, 5
|
||||||
jb .not_wall
|
jb .less_than_5_chars
|
||||||
add si, cx
|
add si, cx
|
||||||
sub si, 5
|
sub si, 5
|
||||||
|
; .text
|
||||||
|
mov di, text_extension
|
||||||
|
call strcmp
|
||||||
|
je .text_file
|
||||||
|
; .wall
|
||||||
mov di, wall_extension
|
mov di, wall_extension
|
||||||
call strcmp
|
call strcmp
|
||||||
jne .not_wall
|
je .wallpaper
|
||||||
|
.less_than_5_chars:
|
||||||
|
|
||||||
mov ax, cs
|
; 3 letter file extension?
|
||||||
mov es, ax
|
|
||||||
mov si, launch_filename
|
|
||||||
mov di, wallpaper_name
|
|
||||||
mov cx, FS_DIRENT_NAME_SIZE
|
|
||||||
rep movsb
|
|
||||||
|
|
||||||
call set_wallpaper
|
|
||||||
call request_redraw
|
|
||||||
jmp .end
|
|
||||||
|
|
||||||
.not_wall:
|
|
||||||
|
|
||||||
; Is it a .bin file?
|
|
||||||
cmp cx, 4
|
cmp cx, 4
|
||||||
jb .not_launchable ; No, too short
|
jb .not_launchable ; No, too short
|
||||||
mov si, launch_filename
|
mov si, launch_filename
|
||||||
add si, cx
|
add si, cx
|
||||||
sub si, 4
|
sub si, 4
|
||||||
|
; .asm
|
||||||
|
mov di, asm_extension
|
||||||
|
call strcmp
|
||||||
|
je .text_file
|
||||||
|
; .txt
|
||||||
|
mov di, txt_extension
|
||||||
|
call strcmp
|
||||||
|
je .text_file
|
||||||
|
; .bin
|
||||||
mov di, bin_extension
|
mov di, bin_extension
|
||||||
call strcmp
|
call strcmp
|
||||||
jne .not_launchable ; No, wrong extension
|
jne .not_launchable ; No extension matched
|
||||||
|
|
||||||
mov si, launch_filename
|
mov si, launch_filename
|
||||||
|
call launch_binary
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
.wallpaper:
|
||||||
|
mov ax, cs
|
||||||
|
mov es, ax
|
||||||
|
mov si, launch_filename
|
||||||
|
mov di, wallpaper_name
|
||||||
|
mov cx, FS_DIRENT_NAME_SIZE
|
||||||
|
rep movsb
|
||||||
|
|
||||||
|
call set_wallpaper
|
||||||
|
call request_redraw
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
.not_launchable:
|
||||||
|
; Copy filename into the launch error dialog
|
||||||
|
mov si, launch_filename
|
||||||
|
call show_launch_error
|
||||||
|
ret
|
||||||
|
|
||||||
|
.text_file:
|
||||||
|
; Launch viewer.bin if it exists
|
||||||
|
mov si, viewer_file_name
|
||||||
|
call launch_binary
|
||||||
|
jc .viewer_not_found
|
||||||
|
|
||||||
|
; Send the WM_OPEN_FILE event to tell viewer the file we
|
||||||
|
; want it to open. launch_binary returned its segment in bx
|
||||||
|
; so we can just pass that to send_event, as window IDs are
|
||||||
|
; of the form segment | internal_id.
|
||||||
|
mov al, WM_OPEN_FILE
|
||||||
|
mov cx, launch_filename
|
||||||
|
call send_event
|
||||||
|
|
||||||
|
.viewer_not_found:
|
||||||
|
ret
|
||||||
|
|
||||||
|
; in:
|
||||||
|
; si = name of file not launchable
|
||||||
|
; out:
|
||||||
|
; clobbers everything
|
||||||
|
show_launch_error:
|
||||||
|
mov di, launch_error_dialog.filename
|
||||||
|
mov cx, FS_DIRENT_NAME_SIZE-1
|
||||||
|
mov ah, 0xf0
|
||||||
|
.copy:
|
||||||
|
lodsb
|
||||||
|
test al, al
|
||||||
|
je .copy_end
|
||||||
|
stosw
|
||||||
|
loop .copy
|
||||||
|
.copy_end:
|
||||||
|
; Zero out the rest
|
||||||
|
xor al, al
|
||||||
|
rep stosw
|
||||||
|
|
||||||
|
; Show dialog
|
||||||
|
mov ax, cs
|
||||||
|
add ax, WINDOW_ID_LAUNCH_ERROR
|
||||||
|
mov si, windows + WINDOW_ID_LAUNCH_ERROR*window.size
|
||||||
|
call show_window
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
; in:
|
||||||
|
; si = name of the binary to launch
|
||||||
|
; out:
|
||||||
|
; cf = error occured when launching binary
|
||||||
|
; bx = segment of the launched binary
|
||||||
|
; clobbers everything else
|
||||||
|
launch_binary:
|
||||||
mov dx, 1 ; Don't create a new file if not found
|
mov dx, 1 ; Don't create a new file if not found
|
||||||
call PONYDOS_SEG:SYS_OPEN_FILE
|
call PONYDOS_SEG:SYS_OPEN_FILE
|
||||||
test ax, ax
|
test ax, ax
|
||||||
jz .not_launchable
|
jz .file_not_found
|
||||||
|
|
||||||
push ax
|
push ax
|
||||||
push cx
|
push cx
|
||||||
|
@ -600,14 +680,7 @@ launch:
|
||||||
jz .found_free_segment
|
jz .found_free_segment
|
||||||
inc si
|
inc si
|
||||||
loop .find_free_segment
|
loop .find_free_segment
|
||||||
; Display an error dialog if we can't allocate a segment
|
jmp .out_of_memory
|
||||||
mov ax, cs
|
|
||||||
add ax, WINDOW_ID_OOM_ERROR
|
|
||||||
mov si, windows + WINDOW_ID_OOM_ERROR*window.size
|
|
||||||
call show_window
|
|
||||||
pop cx
|
|
||||||
pop ax
|
|
||||||
jmp .end
|
|
||||||
.found_free_segment:
|
.found_free_segment:
|
||||||
mov byte [es:si], 1 ; Mark as used
|
mov byte [es:si], 1 ; Mark as used
|
||||||
|
|
||||||
|
@ -623,34 +696,37 @@ launch:
|
||||||
xor di, di ; Read
|
xor di, di ; Read
|
||||||
call PONYDOS_SEG:SYS_MODIFY_SECTORS
|
call PONYDOS_SEG:SYS_MODIFY_SECTORS
|
||||||
|
|
||||||
|
push es ; Save the segment for return value
|
||||||
|
|
||||||
; Transfer control to the newly loaded binary
|
; Transfer control to the newly loaded binary
|
||||||
push cs ; Return segment
|
push cs ; Return segment
|
||||||
mov ax, .end
|
mov ax, .success
|
||||||
push ax ; Return offset
|
push ax ; Return offset
|
||||||
push es ; Call segment
|
push es ; Call segment
|
||||||
mov ax, PROC_INITIALIZE_ENTRYPOINT
|
mov ax, PROC_INITIALIZE_ENTRYPOINT
|
||||||
push ax ; Call offset
|
push ax ; Call offset
|
||||||
retf
|
retf
|
||||||
|
|
||||||
.end:
|
.success:
|
||||||
|
pop bx
|
||||||
|
clc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.not_launchable:
|
.file_not_found:
|
||||||
; Copy filename into the launch error dialog
|
call show_launch_error
|
||||||
mov si, launch_filename
|
jmp .error
|
||||||
mov di, launch_error_dialog.filename
|
|
||||||
mov cx, FS_DIRENT_NAME_SIZE-1
|
|
||||||
.loop:
|
|
||||||
lodsb
|
|
||||||
stosb
|
|
||||||
inc di
|
|
||||||
loop .loop
|
|
||||||
|
|
||||||
; Show dialog
|
.out_of_memory:
|
||||||
|
; Display an error dialog if we can't allocate a segment
|
||||||
mov ax, cs
|
mov ax, cs
|
||||||
add ax, WINDOW_ID_LAUNCH_ERROR
|
add ax, WINDOW_ID_OOM_ERROR
|
||||||
mov si, windows + WINDOW_ID_LAUNCH_ERROR*window.size
|
mov si, windows + WINDOW_ID_OOM_ERROR*window.size
|
||||||
call show_window
|
call show_window
|
||||||
|
pop cx
|
||||||
|
pop ax
|
||||||
|
|
||||||
|
.error:
|
||||||
|
stc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; out:
|
; out:
|
||||||
|
@ -675,7 +751,7 @@ set_wallpaper:
|
||||||
; bx = window ID
|
; bx = window ID
|
||||||
; out:
|
; out:
|
||||||
; ax = return value of event handler; 0 if window ID is 0
|
; ax = return value of event handler; 0 if window ID is 0
|
||||||
forward_event:
|
send_event:
|
||||||
push bp
|
push bp
|
||||||
|
|
||||||
cmp bx, 0
|
cmp bx, 0
|
||||||
|
@ -796,7 +872,7 @@ unhook_window:
|
||||||
mov bx, [es:GLOBAL_WINDOW_CHAIN_HEAD]
|
mov bx, [es:GLOBAL_WINDOW_CHAIN_HEAD]
|
||||||
|
|
||||||
mov al, WM_UNHOOK
|
mov al, WM_UNHOOK
|
||||||
call forward_event
|
call send_event
|
||||||
|
|
||||||
mov [es:GLOBAL_WINDOW_CHAIN_HEAD], ax
|
mov [es:GLOBAL_WINDOW_CHAIN_HEAD], ax
|
||||||
|
|
||||||
|
@ -1130,14 +1206,20 @@ strcmp:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; Variables
|
; Constants
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
|
asm_extension db '.asm', 0
|
||||||
bin_extension db '.bin', 0
|
bin_extension db '.bin', 0
|
||||||
|
txt_extension db '.txt', 0
|
||||||
|
text_extension db '.text', 0
|
||||||
wall_extension db '.wall', 0
|
wall_extension db '.wall', 0
|
||||||
|
|
||||||
wallpaper_name db 'ponydos.wall'
|
viewer_file_name db 'viewer.bin', 0
|
||||||
times FS_DIRENT_NAME_SIZE-12 db 0
|
|
||||||
|
; ------------------------------------------------------------------
|
||||||
|
; Variables
|
||||||
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
disk_icon:
|
disk_icon:
|
||||||
db 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f
|
db 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f
|
||||||
|
@ -1171,6 +1253,9 @@ windows:
|
||||||
|
|
||||||
open_windows db 0
|
open_windows db 0
|
||||||
|
|
||||||
|
wallpaper_name db 'ponydos.wall'
|
||||||
|
times FS_DIRENT_NAME_SIZE-12 db 0
|
||||||
|
|
||||||
launch_filename times FS_DIRENT_NAME_SIZE db 0
|
launch_filename times FS_DIRENT_NAME_SIZE db 0
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
|
|
76
viewer.asm
76
viewer.asm
|
@ -51,9 +51,14 @@ process_event:
|
||||||
push es
|
push es
|
||||||
|
|
||||||
; On entry, ds and es will not be set correctly for us
|
; On entry, ds and es will not be set correctly for us
|
||||||
mov bp, cs
|
; WM_OPEN_FILE needs ds to be left-as is
|
||||||
mov ds, bp
|
cmp al, WM_OPEN_FILE
|
||||||
mov es, bp
|
je .no_set_ds
|
||||||
|
push cs
|
||||||
|
pop ds
|
||||||
|
.no_set_ds:
|
||||||
|
push cs
|
||||||
|
pop es
|
||||||
|
|
||||||
cmp al, WM_PAINT
|
cmp al, WM_PAINT
|
||||||
jne .not_paint
|
jne .not_paint
|
||||||
|
@ -79,7 +84,21 @@ process_event:
|
||||||
jmp .end
|
jmp .end
|
||||||
.not_unhook:
|
.not_unhook:
|
||||||
|
|
||||||
|
cmp al, WM_OPEN_FILE
|
||||||
|
jne .not_open_file
|
||||||
|
call event_open_file
|
||||||
|
; Set ds in case event_open_file didn't
|
||||||
|
push cs
|
||||||
|
pop ds
|
||||||
|
jmp .end
|
||||||
|
.not_open_file:
|
||||||
|
|
||||||
.end:
|
.end:
|
||||||
|
cmp byte [exiting], 0
|
||||||
|
je .not_exiting
|
||||||
|
call deallocate_own_memory
|
||||||
|
.not_exiting:
|
||||||
|
|
||||||
pop es
|
pop es
|
||||||
pop ds
|
pop ds
|
||||||
pop bp
|
pop bp
|
||||||
|
@ -579,7 +598,7 @@ event_click:
|
||||||
jne .not_cancel
|
jne .not_cancel
|
||||||
.cancel:
|
.cancel:
|
||||||
call unhook_self_from_window_chain
|
call unhook_self_from_window_chain
|
||||||
call deallocate_own_memory
|
mov byte [exiting], 1
|
||||||
jmp .end
|
jmp .end
|
||||||
.not_cancel:
|
.not_cancel:
|
||||||
cmp byte [bx], OK_COLOR
|
cmp byte [bx], OK_COLOR
|
||||||
|
@ -735,6 +754,37 @@ event_unhook:
|
||||||
mov ax, [window_next]
|
mov ax, [window_next]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; in:
|
||||||
|
; al = WM_OPEN_FILE
|
||||||
|
; ds:cx = filename
|
||||||
|
; out:
|
||||||
|
; clobbers everything
|
||||||
|
event_open_file:
|
||||||
|
; Copy the file name over
|
||||||
|
mov si, cx
|
||||||
|
mov di, [es:cur_filename_address]
|
||||||
|
.copy_filename:
|
||||||
|
lodsb
|
||||||
|
test al, al
|
||||||
|
jz .copy_end
|
||||||
|
|
||||||
|
stosb
|
||||||
|
inc di
|
||||||
|
jmp .copy_filename
|
||||||
|
.copy_end:
|
||||||
|
mov [es:cur_filename_address], di
|
||||||
|
|
||||||
|
; Set ds to be as expected by most of the program
|
||||||
|
push cs
|
||||||
|
pop ds
|
||||||
|
|
||||||
|
; Mark that the filename came from WM_OPEN_FILE
|
||||||
|
mov byte [filename_from_wm_open_file], 1
|
||||||
|
|
||||||
|
call filename_ok
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; Event handler subroutines
|
; Event handler subroutines
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
@ -742,15 +792,20 @@ event_unhook:
|
||||||
; out:
|
; out:
|
||||||
; clobbers si, di, cx
|
; clobbers si, di, cx
|
||||||
close_window:
|
close_window:
|
||||||
|
; If filename was from WM_OPEN_FILE event instead of user input,
|
||||||
|
; exit the app instead of going to name input dialog
|
||||||
|
cmp byte [filename_from_wm_open_file], 0
|
||||||
|
jne .exit_app
|
||||||
cmp word [window.data_address], oom_window_data
|
cmp word [window.data_address], oom_window_data
|
||||||
je .error_window
|
je .error_window
|
||||||
cmp word [window.data_address], ood_window_data
|
cmp word [window.data_address], ood_window_data
|
||||||
je .error_window
|
je .error_window
|
||||||
.not_error_window:
|
|
||||||
; Shut off app
|
.exit_app:
|
||||||
call unhook_self_from_window_chain
|
call unhook_self_from_window_chain
|
||||||
call deallocate_own_memory
|
mov byte [exiting], 1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.error_window:
|
.error_window:
|
||||||
mov si, filename_window
|
mov si, filename_window
|
||||||
mov di, window
|
mov di, window
|
||||||
|
@ -1116,10 +1171,13 @@ request_redraw:
|
||||||
; Variables
|
; Variables
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
|
filename_from_wm_open_file db 0
|
||||||
|
exiting db 0
|
||||||
|
|
||||||
window_title times FS_DIRENT_NAME_SIZE db 0
|
window_title times FS_DIRENT_NAME_SIZE db 0
|
||||||
|
|
||||||
cur_file_address: dw 0 ; Segment
|
cur_file_address: dw 0
|
||||||
dw 0
|
dw 0 ; Segment
|
||||||
beg_file_address dw 0
|
beg_file_address dw 0
|
||||||
end_file_address dw 0
|
end_file_address dw 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue