sh: Add rdnext command

This command redirects the IO stream for the next command to the
specified file or named stream
This commit is contained in:
Ry 2023-03-31 16:28:23 -07:00
parent 958e6348f7
commit d3c75a7c9c
5 changed files with 58 additions and 13 deletions

View File

@ -1,6 +1,9 @@
; command parser ; command parser
shell_parse_command: shell_parse_command:
cmp.8 [shell_redirect_next], 0
ifnz mov [shell_stream_struct_ptr], shell_redirect_stream_struct
mov r0, shell_text_buf_bottom mov r0, shell_text_buf_bottom
; clear ; clear
@ -33,6 +36,11 @@ shell_parse_command:
call compare_string call compare_string
ifz jmp shell_help_command ifz jmp shell_help_command
; rdnext
mov r1, shell_rdnext_command_string
call compare_string
ifz jmp shell_rdnext_command
; shutdown ; shutdown
mov r1, shell_shutdown_command_string mov r1, shell_shutdown_command_string
call compare_string call compare_string
@ -61,5 +69,6 @@ shell_invalid_command_string: data.str "invalid command or FXF binary" data.8 10
#include "commands/diskrm.asm" #include "commands/diskrm.asm"
#include "commands/exit.asm" #include "commands/exit.asm"
#include "commands/help.asm" #include "commands/help.asm"
#include "commands/rdnext.asm"
#include "commands/shutdown.asm" #include "commands/shutdown.asm"
#include "commands/type.asm" #include "commands/type.asm"

View File

@ -22,6 +22,7 @@ shell_help_text:
data.str "diskrm | remove disk $0" data.8 10 data.str "diskrm | remove disk $0" data.8 10
data.str "exit | exit the shell" data.8 10 data.str "exit | exit the shell" data.8 10
data.str "help | show this help text" data.8 10 data.str "help | show this help text" data.8 10
data.str "rdnext | redirect the next command's IO" data.8 10
data.str "shutdown| turn the computer off" data.8 10 data.str "shutdown| turn the computer off" data.8 10
data.str "type | print contents of file $0" data.8 10 data.str "type | print contents of file $0" data.8 10
data.8 10 data.8 10

View File

@ -0,0 +1,29 @@
; rdnext command
shell_rdnext_command_string: data.strz "rdnext"
shell_rdnext_command:
cmp.8 [shell_redirect_next], 0
ifnz ret
call shell_parse_arguments
push r0
call get_current_disk_id
mov r1, r0
pop r0
mov r2, shell_redirect_stream_struct
call open
cmp r0, 0
ifz jmp shell_rdnext_command_failed_to_open
mov.8 [shell_redirect_next], 2
mov [shell_old_stream_struct_ptr], [shell_stream_struct_ptr]
ret
shell_rdnext_command_failed_to_open:
mov r0, shell_rdnext_command_failed_to_open_string
call print_str_to_terminal
ret
shell_rdnext_command_failed_to_open_string: data.str "failed to open file for redirect" data.8 10 data.8 0

View File

@ -72,7 +72,7 @@ launch_fxf_name_loop_done:
push r2 push r2
push r1 push r1
push r0 push r0
push [shell_terminal_stream_struct_ptr] push [shell_stream_struct_ptr]
sub rsp, 65516 sub rsp, 65516
mov [launch_fxf_stack_ptr], rsp mov [launch_fxf_stack_ptr], rsp
mov rsp, r4 mov rsp, r4

View File

@ -6,19 +6,24 @@ const MOVE_CURSOR: 0xF1
const SET_COLOR: 0xF2 const SET_COLOR: 0xF2
const REDRAW_LINE: 0xFE const REDRAW_LINE: 0xFE
pop [shell_terminal_stream_struct_ptr] pop [shell_stream_struct_ptr]
shell_task_return: shell_task_return:
cmp.8 [shell_redirect_next], 0
ifnz mov [shell_stream_struct_ptr], [shell_old_stream_struct_ptr]
ifnz dec.8 [shell_redirect_next]
call shell_clear_buffer call shell_clear_buffer
call shell_print_prompt call shell_print_prompt
shell_task_loop: shell_task_loop:
mov r0, 1 mov r0, 1
mov r1, [shell_terminal_stream_struct_ptr] mov r1, [shell_stream_struct_ptr]
mov r2, shell_char_buffer mov r2, shell_char_buffer
call read call read
movz.8 r0, [shell_char_buffer] movz.8 r0, [shell_char_buffer]
cmp.8 r0, 0 cmp.8 r0, 0
ifnz call shell_task_parse_key ifnz jmp shell_task_parse_key
rjmp shell_task_loop rjmp shell_task_loop
@ -51,7 +56,7 @@ shell_task_parse_key:
call print_character_to_terminal call print_character_to_terminal
call print_character_to_terminal call print_character_to_terminal
call print_character_to_terminal call print_character_to_terminal
ret jmp shell_task_loop
shell_key_down_enter: shell_key_down_enter:
; clear the cursor from the screen ; clear the cursor from the screen
mov r0, 8 ; backspace character mov r0, 8 ; backspace character
@ -68,15 +73,13 @@ shell_key_down_enter:
call shell_push_character call shell_push_character
call shell_parse_line call shell_parse_line
call shell_clear_buffer
call shell_print_prompt jmp shell_task_return
ret
shell_key_down_backspace: shell_key_down_backspace:
; check if we are already at the start of the prompt ; check if we are already at the start of the prompt
mov r1, [shell_text_buf_ptr] mov r1, [shell_text_buf_ptr]
cmp r1, shell_text_buf_bottom cmp r1, shell_text_buf_bottom
iflteq ret iflteq jmp shell_task_loop
; delete the last character from the screen, draw the cursor, and pop the last character from the buffer ; delete the last character from the screen, draw the cursor, and pop the last character from the buffer
mov r0, 8 ; backspace character mov r0, 8 ; backspace character
call print_character_to_terminal call print_character_to_terminal
@ -92,7 +95,7 @@ shell_key_down_backspace:
call print_character_to_terminal call print_character_to_terminal
call print_character_to_terminal call print_character_to_terminal
call print_character_to_terminal call print_character_to_terminal
ret jmp shell_task_loop
shell_print_prompt: shell_print_prompt:
call get_current_disk_id call get_current_disk_id
@ -241,7 +244,7 @@ print_character_to_terminal:
mov.8 [shell_char_buffer], r0 mov.8 [shell_char_buffer], r0
mov r0, 1 mov r0, 1
mov r1, [shell_terminal_stream_struct_ptr] mov r1, [shell_stream_struct_ptr]
mov r2, shell_char_buffer mov r2, shell_char_buffer
call write call write
@ -259,7 +262,7 @@ print_str_to_terminal:
push r0 push r0
push r2 push r2
mov r1, [shell_terminal_stream_struct_ptr] mov r1, [shell_stream_struct_ptr]
mov r2, r0 mov r2, r0
print_str_to_terminal_loop: print_str_to_terminal_loop:
mov r0, 1 mov r0, 1
@ -311,7 +314,10 @@ shell_args_ptr: data.32 0 ; pointer to the beginning of the command argum
shell_prompt: data.str "> " data.8 CURSOR data.8 0 shell_prompt: data.str "> " data.8 CURSOR data.8 0
shell_terminal_stream_struct_ptr: data.32 0 shell_stream_struct_ptr: data.32 0
shell_old_stream_struct_ptr: data.32 0
shell_redirect_next: data.8 0
shell_redirect_stream_struct: data.fill 0, 32
shell_char_buffer: data.32 0 shell_char_buffer: data.32 0
#include "commands/commands.asm" #include "commands/commands.asm"