There’s something I don’t understand with the ZVM interpreter and @sread instruction for version 3.
In this example, I should be able to type a maximum of 7 characters and not 9. I should be able to type a maximum of 4 words and it shows me 102. The text buffer should end with 0 and not 32. The ‘f’ is missing in the text buffer, but is in the parse buffer.
With Frotz all works fine, but not with ZVM under Lectrote.
Lectrote ZVM:
>ab cd e f
text: [8] 97 98 32 99 100 32 101 32
parse: [102][4] ab[2,1] cd[2,4] e[1,7] f[1,9]
Frotz:
>ab cd e
text: [8] 97 98 32 99 100 32 101 0
parse: [4][3] ab[2,1] cd[2,4] e[1,7]
Code
!% -v3
!% -~S
Constant MAX_INPUT_CHARS = 7;
Constant MAX_INPUT_WORDS = 4;
Array text->(1+MAX_INPUT_CHARS+1);
Array parse->(2+(MAX_INPUT_WORDS * 4));
Global location = Library;
Global status_field_1 = 0;
Global status_field_2 = 0;
Object Library "The Library"
with description "You are in a library.";
[ BeforeParsing i w at len;
print "text: [", text->0, "] ";
for (i=1 : i<=text->0 : i++)
print text->i, " ";
print "^parse: [", parse->0,"]", "[", parse->1,"] ";
for (w=1 : w <= parse->1 : w++){
at = parse->(4*w+1);
len = parse->(4*w);
for (i=0 : i< len : i++)
print (char) text-> (at+i);
print "[", parse->(4*w), ",", parse->(4*w+1), "] ";
}
];
[ main;
text->0 = MAX_INPUT_CHARS+1;
parse->0 = MAX_INPUT_WORDS;
print "Type Q to quit.^";
while(1) {
print "^>";
@sread text parse;
if (text->1 == 'q') break;
BeforeParsing();
new_line;
}
];