src/cmd/cat.s: lots more comments added to the code.
This commit is contained in:
+62
-60
@@ -10,17 +10,17 @@
|
|||||||
dac name
|
dac name
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
sys open; name:0; 0; " Open file, get fd back
|
sys open; name:0; 0 " Open file, get fd back
|
||||||
spa
|
spa
|
||||||
jmp badfile " Negative fd, exit with an error message
|
jmp badfile " Negative fd, exit with an error message
|
||||||
dac fi " save file descriptor in fi
|
dac fi " Save file descriptor in fi
|
||||||
|
|
||||||
1:
|
1:
|
||||||
jms getc " get a character in AC
|
jms getc " Get a character in AC
|
||||||
sad o4
|
sad o4
|
||||||
jmp 1f
|
jmp 1f " Break the loop when we get a ctrl-D
|
||||||
jms putc " write the character on stdout
|
jms putc " Write the character on stdout
|
||||||
jmp 1b
|
jmp 1b " and loop back
|
||||||
|
|
||||||
1:
|
1:
|
||||||
lac fi " Close the file descriptor in fi
|
lac fi " Close the file descriptor in fi
|
||||||
@@ -57,14 +57,14 @@ nofiles:
|
|||||||
1: <no>; 040; <fi>;<le>;<s 012
|
1: <no>; 040; <fi>;<le>;<s 012
|
||||||
|
|
||||||
done:
|
done:
|
||||||
lac noc
|
lac noc " Is the number of characters left zero?
|
||||||
sna
|
sna
|
||||||
sys exit
|
sys exit " Yes, exit
|
||||||
and d1
|
and d1
|
||||||
sna cla
|
sna cla
|
||||||
jmp 1f
|
jmp 1f
|
||||||
jms putc
|
jms putc " Print out the character
|
||||||
jmp done
|
jmp done " and loop back
|
||||||
1:
|
1:
|
||||||
lac noc
|
lac noc
|
||||||
rcr
|
rcr
|
||||||
@@ -74,76 +74,78 @@ done:
|
|||||||
sys exit
|
sys exit
|
||||||
|
|
||||||
getc: 0
|
getc: 0
|
||||||
lac ipt
|
lac ipt " Load the pointer to the next word in the buffer
|
||||||
sad eipt
|
sad eipt
|
||||||
jmp 1f
|
jmp 1f " We've reached the end of the buffer, so read more
|
||||||
dac 2f
|
dac 2f " Save the pointer
|
||||||
add o400000
|
add o400000 " Flip the msb and save into ipt
|
||||||
dac ipt
|
dac ipt
|
||||||
ral
|
ral " Move the msb into the link register
|
||||||
lac 2f i
|
lac 2f i " Load the word from the buffer
|
||||||
szl
|
szl " Skip if this is the second character in the word
|
||||||
lrss 9
|
lrss 9 " It's the first char, shift down the top character
|
||||||
and o177 " keep the lowest 7 bits
|
and o177 " Keep the lowest 7 bits
|
||||||
sna
|
sna
|
||||||
jmp getc+1
|
jmp getc+1 " Skip a NUL characters and read another one
|
||||||
jmp getc i " return from subroutine
|
jmp getc i " Return the character from the subroutine
|
||||||
1:
|
1:
|
||||||
lac fi
|
lac fi " Buffer is empty, read another 64 characters
|
||||||
sys read; iipt+1; 64
|
sys read; iipt+1; 64
|
||||||
sna
|
sna
|
||||||
jmp 1f
|
jmp 1f " No characters were read in
|
||||||
tad iipt
|
tad iipt " Add the word count to the base of the buffer
|
||||||
dac eipt
|
dac eipt " and store in the end buffer pointer
|
||||||
lac iipt
|
lac iipt " Reset the ipt to the base of the buffer
|
||||||
dac ipt
|
dac ipt
|
||||||
jmp getc+1
|
jmp getc+1 " and loop back to get one character
|
||||||
1:
|
1:
|
||||||
lac o4
|
lac o4 " No character, return with ctrl-D
|
||||||
jmp getc i " return from subroutine
|
jmp getc i " return from subroutine
|
||||||
|
|
||||||
putc: 0
|
putc: 0
|
||||||
and o177 " keep the lowest 7 bits
|
and o177 " Keep the lowest 7 bits and save into 2f+1
|
||||||
dac 2f+1
|
dac 2f+1
|
||||||
lac opt
|
lac opt " Save the pointer to the empty buffer
|
||||||
dac 2f
|
dac 2f " position to 2f
|
||||||
add o400000
|
add o400000 " Flip the msb and save back into opt
|
||||||
dac opt
|
dac opt " This also has the effect of incrementing
|
||||||
spa
|
" the opt pointer every second addition!
|
||||||
jmp 1f
|
|
||||||
lac 2f i
|
spa " If the bit was set, we already have one
|
||||||
|
jmp 1f " character at 2f+1. If no previous character,
|
||||||
|
lac 2f i " merge the old and new character together
|
||||||
xor 2f+1
|
xor 2f+1
|
||||||
jmp 3f
|
jmp 3f " and go to the "save it in buffer" code
|
||||||
1:
|
1:
|
||||||
lac 2f+1
|
lac 2f+1 " Move the character up into the top half
|
||||||
alss 9
|
alss 9
|
||||||
3:
|
3:
|
||||||
dac 2f i
|
dac 2f i " Save the word into the buffer
|
||||||
isz noc
|
isz noc " Add 1 to the char count, never skipping
|
||||||
lac noc
|
lac noc " Have we reached 128 characters, 64 words?
|
||||||
sad d128
|
sad d128
|
||||||
skp
|
skp
|
||||||
jmp putc i
|
jmp putc i " No, so return (more room still in the buffer)
|
||||||
lac fo " load fd 1, stdout
|
lac fo " Load fd1 (i.e stdout)
|
||||||
sys write; iopt+1; 64
|
sys write; iopt+1; 64 " and write out the 64 words in the buffer
|
||||||
lac iopt
|
lac iopt
|
||||||
dac opt
|
dac opt " Set opt pointing back to base of buffer
|
||||||
dzm noc
|
dzm noc " Set the number of chars in the buffer to 0
|
||||||
jmp putc i
|
jmp putc i " and return
|
||||||
|
|
||||||
2: 0;0
|
2: 0;0 " Current input and output word pointers
|
||||||
ipt: 0
|
ipt: 0 " Current input buffer base
|
||||||
eipt: 0
|
eipt: 0 " Pointer to end of data read in input buffer
|
||||||
iipt: .+1; .=.+64 " 64 word input buffer
|
iipt: .+1; .=.+64 " 64 word input buffer and pointer to it
|
||||||
fi: 0
|
fi: 0 " Input file descriptor
|
||||||
opt: .+2
|
opt: .+2 " Current output buffer base
|
||||||
iopt: .+1; .=.+64 " 64 word output buffer
|
iopt: .+1; .=.+64 " 64 word output buffer and pointer to it
|
||||||
noc: 0
|
noc: 0 " Number of output characters
|
||||||
fo: 1 " output file descriptor, fd 1 is stdout
|
fo: 1 " Output file descriptor, fd 1 is stdout
|
||||||
|
|
||||||
d1: 1 " octal and decimal constants
|
d1: 1 " Octal and decimal constants
|
||||||
o4:d4: 4
|
o4:d4: 4
|
||||||
d8: 8
|
d8: 8
|
||||||
o400000: 0400000
|
o400000: 0400000 " Msb toggle bit
|
||||||
o177: 0177
|
o177: 0177 " ASCII mask
|
||||||
d128: 128
|
d128: 128 " 128 words in the output buffer
|
||||||
|
|||||||
Reference in New Issue
Block a user