basic: getkeysdown is now function

This commit is contained in:
minjaesong
2020-12-23 23:01:13 +09:00
parent db8ca2d8ed
commit 2612cb48a1
6 changed files with 15 additions and 24 deletions

View File

@@ -1209,18 +1209,12 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
return twoArg(lnum, stmtnum, args, (lh,rh) => (lh < rh) ? rh : lh);
}},
"GETKEYSDOWN" : {f:function(lnum, stmtnum, args) {
if (args.length != 1) throw lang.syntaxfehler(lnum, args.length+lang.aG);
let troValue = args[0].troValue;
let varname = troValue.toUpperCase();
let keys = [];
sys.poke(-40, 255);
for (let k = -41; k >= -48; k--) {
keys.push(sys.peek(k));
}
if (_basicConsts[varname]) throw lang.asgnOnConst(lnum, varname);
bStatus.vars[varname] = new BasicVar(keys, "array");
return {asgnVarName: varname, asgnValue: keys};
return keys;
}},
"<~" : {f:function(lnum, stmtnum, args) { // CURRY operator
return twoArg(lnum, stmtnum, args, (fn, value) => {
@@ -2617,8 +2611,8 @@ bF._troNOP = function(lnum, stmtnum) { return new SyntaxTreeReturnObj("null", un
bF._executeSyntaxTree = function(lnum, stmtnum, syntaxTree, recDepth) {
if (lnum === undefined || stmtnum === undefined) throw Error(`Line or statement number is undefined: (${lnum},${stmtnum})`);
let _debugExec = false;
let _debugPrintCurrentLine = false;
let _debugExec = true;
let _debugPrintCurrentLine = true;
let recWedge = ">".repeat(recDepth) + " ";
if (_debugExec || _debugPrintCurrentLine) serial.println(recWedge+"@@ EXECUTE @@");

View File

@@ -1,3 +1,2 @@
10 GETKEYSDOWN K
20 PRINT K
30 GOTO 10
10 PRINT GETKEYSDOWN()
20 GOTO 10

View File

@@ -4,8 +4,7 @@
100 LABEL SINCQ:REM gets Sinc(Q)
110 Q=IF I==0 THEN 1.0 ELSE SIN(I)/I
120 RETURN
200 LABEL PLOTLINE:REM Converts 0-1 value into screen line
201 REM input is Q, results are stored to SQ
200 LABEL PLOTLINE:REM Converts 0-1 value into screen line. input is Q, results are stored to SQ
210 SQ=CHR(0)
220 FOR X=1 TO ZEROLINE+AMP
230 SQ=SQ+(IF X==ROUND(ZEROLINE+Q*AMP) THEN "@" ELSE IF X==10 THEN "|" ELSE CHR(250))

View File

@@ -3,8 +3,8 @@
10 DEFUN SINC(P)=IF P==0 THEN 1.0 ELSE SIN(P)/P
20 DEFUN TOCHAR(P,X)=IF (X==ROUND(ZEROLINE+P*AMP)) THEN "@" ELSE IF (X==ZEROLINE) THEN "|" ELSE CHR(250)
30 DEFUN SCONCAT(ACC,S)=ACC+S
40 DEFUN PLOTLINE(X)=FOLD(SCONCAT,CHR(0),MAP(TOCHAR<~X,1 TO ZEROLINE+AMP))
40 REM DEFUN PLOTLINE(X)=FOLD(SCONCAT,CHR(0),MAP(TOCHAR<~X,1 TO ZEROLINE+AMP))
41 DEFUN PLOTLINE(F,X)=FOLD(SCONCAT,CHR(0),MAP(TOCHAR<~F(X),1 TO ZEROLINE+AMP))
100 FOR I=0 TO 20
110 PRINT PLOTLINE(SINC(I))
120 NEXT

View File

@@ -84,8 +84,8 @@ Functions are a form of expression that may taks input arguments surrounded by p
\codeline{Y \textbf{= DIM(}X\textbf{)}}\par
Returns array with size of \code{X}, all filled with zero.
\subsection{GETKEYSDOWN}
\codeline{\textbf{GETKEYSDOWN} VARIABLE}\par
Stores array that contains keycode of keys held down in \code{VARIABLE}.\par
\codeline{K \textbf{= GETKEYSDOWN()}}\par
Stores array that contains keycode of keys held down into the given variable.\par
Actual keycode and the array length depends on the machine: in \thismachine , array length will be fixed to 8. For the list of available keycodes, see \ref{implementation}.
\subsection{INPUT}
\codeline{\textbf{INPUT} VARIABLE}\par

View File

@@ -1,7 +1,6 @@
10 FOR I = 1 TO 20
20 PRINT SPC(20-I);
30 FOR J = 1 TO I*2
40 PRINT "*";
50 NEXT
60 PRINT ""
70 NEXT
20 PRINT SPC(20-I);
30 FOR J = 1 TO I*2-1
40 PRINT "*";
50 NEXT:PRINT
60 NEXT