mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 07:14:04 +09:00
basic: getkeysdown is now function
This commit is contained in:
@@ -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);
|
return twoArg(lnum, stmtnum, args, (lh,rh) => (lh < rh) ? rh : lh);
|
||||||
}},
|
}},
|
||||||
"GETKEYSDOWN" : {f:function(lnum, stmtnum, args) {
|
"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 = [];
|
let keys = [];
|
||||||
sys.poke(-40, 255);
|
sys.poke(-40, 255);
|
||||||
for (let k = -41; k >= -48; k--) {
|
for (let k = -41; k >= -48; k--) {
|
||||||
keys.push(sys.peek(k));
|
keys.push(sys.peek(k));
|
||||||
}
|
}
|
||||||
|
return keys;
|
||||||
if (_basicConsts[varname]) throw lang.asgnOnConst(lnum, varname);
|
|
||||||
bStatus.vars[varname] = new BasicVar(keys, "array");
|
|
||||||
return {asgnVarName: varname, asgnValue: keys};
|
|
||||||
}},
|
}},
|
||||||
"<~" : {f:function(lnum, stmtnum, args) { // CURRY operator
|
"<~" : {f:function(lnum, stmtnum, args) { // CURRY operator
|
||||||
return twoArg(lnum, stmtnum, args, (fn, value) => {
|
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) {
|
bF._executeSyntaxTree = function(lnum, stmtnum, syntaxTree, recDepth) {
|
||||||
if (lnum === undefined || stmtnum === undefined) throw Error(`Line or statement number is undefined: (${lnum},${stmtnum})`);
|
if (lnum === undefined || stmtnum === undefined) throw Error(`Line or statement number is undefined: (${lnum},${stmtnum})`);
|
||||||
|
|
||||||
let _debugExec = false;
|
let _debugExec = true;
|
||||||
let _debugPrintCurrentLine = false;
|
let _debugPrintCurrentLine = true;
|
||||||
let recWedge = ">".repeat(recDepth) + " ";
|
let recWedge = ">".repeat(recDepth) + " ";
|
||||||
|
|
||||||
if (_debugExec || _debugPrintCurrentLine) serial.println(recWedge+"@@ EXECUTE @@");
|
if (_debugExec || _debugPrintCurrentLine) serial.println(recWedge+"@@ EXECUTE @@");
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
10 GETKEYSDOWN K
|
10 PRINT GETKEYSDOWN()
|
||||||
20 PRINT K
|
20 GOTO 10
|
||||||
30 GOTO 10
|
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
100 LABEL SINCQ:REM gets Sinc(Q)
|
100 LABEL SINCQ:REM gets Sinc(Q)
|
||||||
110 Q=IF I==0 THEN 1.0 ELSE SIN(I)/I
|
110 Q=IF I==0 THEN 1.0 ELSE SIN(I)/I
|
||||||
120 RETURN
|
120 RETURN
|
||||||
200 LABEL PLOTLINE:REM Converts 0-1 value into screen line
|
200 LABEL PLOTLINE:REM Converts 0-1 value into screen line. input is Q, results are stored to SQ
|
||||||
201 REM input is Q, results are stored to SQ
|
|
||||||
210 SQ=CHR(0)
|
210 SQ=CHR(0)
|
||||||
220 FOR X=1 TO ZEROLINE+AMP
|
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))
|
230 SQ=SQ+(IF X==ROUND(ZEROLINE+Q*AMP) THEN "@" ELSE IF X==10 THEN "|" ELSE CHR(250))
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
10 DEFUN SINC(P)=IF P==0 THEN 1.0 ELSE SIN(P)/P
|
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)
|
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
|
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
|
100 FOR I=0 TO 20
|
||||||
110 PRINT PLOTLINE(SINC(I))
|
110 PRINT PLOTLINE(SINC(I))
|
||||||
120 NEXT
|
120 NEXT
|
||||||
|
|||||||
@@ -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
|
\codeline{Y \textbf{= DIM(}X\textbf{)}}\par
|
||||||
Returns array with size of \code{X}, all filled with zero.
|
Returns array with size of \code{X}, all filled with zero.
|
||||||
\subsection{GETKEYSDOWN}
|
\subsection{GETKEYSDOWN}
|
||||||
\codeline{\textbf{GETKEYSDOWN} VARIABLE}\par
|
\codeline{K \textbf{= GETKEYSDOWN()}}\par
|
||||||
Stores array that contains keycode of keys held down in \code{VARIABLE}.\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}.
|
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}
|
\subsection{INPUT}
|
||||||
\codeline{\textbf{INPUT} VARIABLE}\par
|
\codeline{\textbf{INPUT} VARIABLE}\par
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
10 FOR I = 1 TO 20
|
10 FOR I = 1 TO 20
|
||||||
20 PRINT SPC(20-I);
|
20 PRINT SPC(20-I);
|
||||||
30 FOR J = 1 TO I*2
|
30 FOR J = 1 TO I*2-1
|
||||||
40 PRINT "*";
|
40 PRINT "*";
|
||||||
50 NEXT
|
50 NEXT:PRINT
|
||||||
60 PRINT ""
|
60 NEXT
|
||||||
70 NEXT
|
|
||||||
|
|||||||
Reference in New Issue
Block a user