Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ls and cd commands #30

Closed
wants to merge 2 commits into from

2 participants

@rustyoz

starting working on a file browser and decided that a few extra commands and the bash could be used as one kind of

@chessmaster42

You were working on part of the same thing I was working on. My recent commit will have broken most of your code but I'm working on getting all of the directory changing code in. I had intended on doing it next then I saw your pull request after I had already committed my code >.>

@rustyoz

yeah from what you have added, it allows for a lot more. it's a problem though if two people are working on the same thing. the cd code shouldn't be that hard to work in you should be able to use most of your ls command code

@rustyoz

for the directory changing, i had the idea of having a buffer/tree of folder locations so that as you move down through a folder each, the directory is added to the buffer. When changing back, the prompt would simply move back up the tree. although displaying the directories before the prompt would make the shell need to find the name of each folder and print it out, this could be calculated once for each directory change and stored somewhere though.

@chessmaster42

Yeah, the idea I have in mind is to keep the present working directory then have a directory stack. And I have most of your cd code done. Just working on the cd .. part and the directory stack now.

@chessmaster42 chessmaster42 closed this pull request from a commit
@chessmaster42 chessmaster42 Moved directory stuff over to the shell
Fixed #30 using bungao's pull request code and the new filesystem code
Added a directory stack to keep track of the directory path
769769a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 19, 2012
  1. @rustyoz
  2. @rustyoz

    another addition to the bash shell this time th cd command

    rustyoz authored
    - features; help, folder existence, cd .. and cd /
This page is out of date. Refresh to see the latest.
Showing with 180 additions and 1 deletion.
  1. +180 −1 atlas.dasm16
View
181 atlas.dasm16
@@ -83,6 +83,9 @@ SET [keyboard_buffers_exclusive], 0
SET [keyboard_oldvalue], 0
JSR keyboard_unregister_all
+;Set a few things to start with
+SET [current_directory], files_table
+SET [old_directory], files_table
; The kernel constantly polls the keyboard.
:kernel_loop
@@ -2028,6 +2031,10 @@ dat 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
IFN A, 0
SET PC, AtlasShell_loop_wait
+ ;Place current directory in front of prompt
+ SET A, [current_directory]
+ JSR [AtlasShell_text_out]
+
; Display the prompt
SET A, text_prompt
JSR [AtlasShell_text_out]
@@ -2087,6 +2094,20 @@ dat 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
IFE c, 0
JSR command_listf
+ ;Check for the 'ls' command
+ SET a, command_ls
+ SET b, command_parameter_buffer
+ JSR [AtlasShell_strcmp]
+ IFE c, O
+ JSR command_lsf
+
+ ;Check for 'cd' command
+ SET a, command_cd
+ SET b, command_parameter_buffer
+ JSR [AtlasShell_strcmp]
+ IFE c, 0
+ JSR command_cdf
+
; If we don't have an acknowledged command, display the generic response
ifn [ack_command], 1
JSR command_unknownf
@@ -2393,6 +2414,147 @@ dat 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
SET PC, POP
+;Command to list files and folders
+:command_lsf
+ SET [ack_command], 1 ; acknowledge recognized command
+ SET PUSH, A
+ SET PUSH, B
+
+ JSR command_clear_parameter_buffer
+
+ JSR [AtlasShell_newline]
+
+ SET A, [current_directory]
+
+ ; Get the length of the folder name and move our pointer forward past that
+ JSR [AtlasShell_strlen]
+ ADD A, B
+ ADD A, 1 ; skip past null terminater
+:command_lsf_loop
+ IFE [A], 0xffff ; simple magic number saying we are at the end of the directory table
+ SET PC, command_lsf_end
+ ADD A, 3
+ JSR [AtlasShell_text_out]
+ JSR [AtlasShell_newline]
+ ; Get the length of the file/folder name and move our pointer forward past that
+ JSR [AtlasShell_strlen]
+ ADD A, B
+ ADD A, 3 ; skip past null terminater, file start, file end
+ SET PC, command_lsf_loop
+
+:command_lsf_end
+ SET B, POP
+ SET A, POP
+ JSR [AtlasShell_proc_suspend]
+ SET PC, POP
+
+:command_cdf
+ SET [ack_command], 1 ; acknowledge recognized command
+ SET PUSH, A
+ SET PUSH, B
+ SET PUSH, C
+
+ ; Capture the param
+ SET A, input_text_buffer
+ SET B, 1
+ JSR shell_getparameter
+
+ JSR [AtlasShell_newline]
+
+ ;check if 'cd'
+ SET A, command_parameter_buffer
+ SET B, command_cd
+ JSR [AtlasShell_strcmp]
+ IFE C, 0
+ SET PC, command_cdf_help
+
+ ; check if blank > load help
+ SET A, command_parameter_buffer
+ JSR [AtlasShell_strlen]
+ IFE B, 0
+ SET PC, command_cdf_help
+
+ ;check if '..'
+ SET A, command_parameter_buffer
+ SET B, command_cd_back
+ JSR [AtlasShell_strcmp]
+ IFE C, 0
+ SET PC, command_cdf_back
+
+ ;check if '/'
+ SET A, command_parameter_buffer
+ SET B, command_cd_root
+ JSR [AtlasShell_strcmp]
+ IFE C, 0
+ SET PC, command_cdf_root
+
+ SET A, [current_directory]
+ ; Get the length of the folder name and move our pointer forward past that
+ JSR [AtlasShell_strlen]
+ ADD A, B
+ ADD A, 1 ; skip past null terminater
+:command_cdf_loop
+ IFE [A], 0xffff ;magic number end of directory
+ SET PC, command_cdf_unknown
+ ADD A, 1
+ IFE [A], 1
+ SET PC, command_cdf_skip_file
+ ADD A, 2
+ SET B, command_parameter_buffer
+ JSR [AtlasShell_strcmp] ; compare table strings
+ IFE C, 0
+ SET PC, command_cdf_cd ; if equal change directory
+ JSR [AtlasShell_strlen] ; Get the length of the folder name and move our pointer forward past that
+ ADD A, B
+ ; Skip past the null terminator, the start address, and the end address
+ ADD A, 3
+ SET PC, command_cdf_loop
+
+:command_cdf_skip_file
+ ADD A, 1
+ JSR [AtlasShell_strlen] ; Get the length of the folder name and move our pointer forward past that
+ ADD A, B
+ ; Skip past the null terminator, the start address, and the end address
+ ADD A, 3
+ SET PC, command_cdf_loop
+
+:command_cdf_help
+ SET A, command_cd_help
+ JSR [AtlasShell_text_out]
+ SET PC, command_cdf_end
+
+:command_cdf_back
+ SET [current_directory], [old_directory]
+ SET PC, command_cdf_end
+
+:command_cdf_root
+ SET [old_directory], files_table
+ SET [current_directory], files_table
+ SET PC, command_cdf_end
+
+
+:command_cdf_unknown
+ SET A, command_parameter_buffer
+ JSR [AtlasShell_text_out]
+ SET A, command_cd_unknown
+ JSR [AtlasShell_text_out]
+ SET PC, command_cdf_end
+
+:command_cdf_cd
+ JSR [AtlasShell_strlen] ; Get the length of the folder name and move our pointer forward past that
+ ADD A, B
+ ADD A, 1
+ SET [old_directory], [current_directory]
+ SET [current_directory], [A]
+
+:command_cdf_end
+ JSR command_clear_parameter_buffer
+ SET C, POP
+ SET B, POP
+ SET A, POP
+ JSR [AtlasShell_proc_suspend]
+ SET PC, POP
+
:AtlasShell_die
SET A, input_buffer
JSR [AtlasShell_keyboard_unregister]
@@ -2518,8 +2680,16 @@ dat 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
:command_kill_last dat "last", 0
:command_list dat "list", 0
:command_list_info dat "Process list:", 0xA0, 0x00
+:command_ls dat "ls", 0
+:command_cd dat "cd", 0
+:command_cd_back dat "..", 0
+:command_cd_root dat "/", 0
+:command_cd_help dat "Syntax : cd [directory|..|/]", 0xA0, 0x00
+:command_cd_unknown dat " doesn't exist", 0xA0, 0
:command_parameter_buffer dat " ", 0x00
:command_number_buffer dat " ", 0x00
+:current_directory dat 0x0000
+:old_directory dat 0x0000
; API Jump table
:AtlasShell_os_version dat 0x1000 ; 0th index in API * 2 words long = 0x00, os_version
@@ -2766,12 +2936,16 @@ dat 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
:files
; Primary file table
+; starts with folder name
; Entry type is 0 for folder, 1 for file
; Access flags: 00 - no access, 01 - read, 10 - write, 11 - read+write
; index, type, access, name, null terminator, start, end
:files_table
+ dat "root", 0
dat 0x0001, 0x0001, 0x0003, "file01", 0, file01, file01_end
dat 0x0002, 0x0001, 0x0001, "hello_world", 0, file02, file02_end
+ dat 0x0003, 0x0000, 0x0001, "folder", 0, folder, folder_end
+ dat 0xffff
:files_table_end
; Basic flat text file
@@ -2795,7 +2969,12 @@ dat 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
dat 0x0048, 0x0065, 0x006c, 0x006c, 0x006f, 0x0020, 0x0057, 0x006f, 0x0072, 0x006c, 0x0064, 0x00a0, 0x0000, 0x1004, 0x100A, 0x101C
:file02_end
-
+:folder
+ dat "folder", 0
+ dat 0x0001, 0x0001, 0x0003, "file01", 0, file01, file01_end
+ dat 0x0002, 0x0001, 0x0001, "hello_world", 0, file02, file02_end
+ dat 0xffff
+:folder_end
Something went wrong with that request. Please try again.