From 9cc938bfe6d62fa7f204a9d93269f4fe96cf68d5 Mon Sep 17 00:00:00 2001 From: Warren Toomey Date: Thu, 3 Mar 2016 13:36:35 +1000 Subject: [PATCH] I've written a simple ls program that actually works :-) --- src/other/wktls.s | 55 +++++++++++++++++++++++++++++++++++++++++++++++ tools/a7out | 3 ++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/other/wktls.s diff --git a/src/other/wktls.s b/src/other/wktls.s new file mode 100644 index 0000000..e911900 --- /dev/null +++ b/src/other/wktls.s @@ -0,0 +1,55 @@ +" Warren's version of ls. Simply print out the names in the current directory + +main: + sys open; curdir; 0 " Open up the currect directory + spa + sys exit " Unable, so die now + dac fd " Save the fd + +fileloop: + " Read 64 words into the buffer from the input file + lac fd + sys read; buf; 64 + spa " Skip if result was >= 0 + jmp fileend " Result was -ve, so error result + sna " Skip if result was >0 + jmp fileend " Result was zero, so nothing left to read + + " Save the count of words read in + dac count + lac ibufptr " Point bufptr at the base of the buffer + dac bufptr + +printloop: + lac d1 + sys write; bufptr:0; 4 " Write a filename out to stdout + lac d1 + sys write; newline; 1 " followed by a newline + + lac bufptr " Add 4 to the bufptr + tad d4 + dac bufptr + -4 + tad count " Decrement the count of words by 4 + dac count + sza " Anything left in the buffer to print? + jmp printloop " Yes, stuff left to print + jmp fileloop " Nothing in the buffer, try reading some more + +fileend: + " Close the open file descriptor and exit + lac fd + sys close + sys exit + +curdir: <. 040; 040040; 040040; 040040 " i.e. "." +newline: 012000 + +fd: 0 +d1: 1 " stdout fd +d4: 4 +count: 0 + +" Input buffer for read +ibufptr: buf " Constant pointer to the buffer +buf: .=.+64 diff --git a/tools/a7out b/tools/a7out index aaff83a..9c769e5 100755 --- a/tools/a7out +++ b/tools/a7out @@ -673,7 +673,8 @@ sub opensomething { open( $FH, ">", $tempfile) || return(undef); dprintf("Converting directory $filename\n"); - while ( my $name= readdir($dh)) { + my @list= sort(readdir($dh)); + foreach my $name (@list) { printf( $FH "%-8s", substr( $name, 0, 8 ) ); } closedir($dh);