Skip to content

Commit 36decc5

Browse files
committed
MIN,MAX: allow string as only argument; allow lines and direct commands in multi-line input; examples moved to CPCBasicApps
1 parent fa677f3 commit 36decc5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+85
-10504
lines changed

CodeGeneratorJs.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -1317,12 +1317,22 @@ CodeGeneratorJs.prototype = {
13171317

13181318
if (fnIsInString(" asc cint derr eof erl err fix fre inkey inp instr int joy len memory peek pos remain sgn sq test testr unt vpos xpos ypos ", sTypeWithSpaces)) {
13191319
node.pt = "I";
1320-
} else if (fnIsInString(" abs atn cos creal exp log log10 max min pi rnd round sin sqr tan time val ", sTypeWithSpaces)) {
1320+
} else if (fnIsInString(" abs atn cos creal exp log log10 pi rnd round sin sqr tan time val ", sTypeWithSpaces)) {
13211321
node.pt = "R";
13221322
} else if (fnIsInString(" bin$ chr$ copychr$ dec$ hex$ inkey$ left$ lower$ mid$ right$ space$ str$ string$ upper$ ", sTypeWithSpaces)) {
13231323
node.pt = "$";
13241324
}
13251325

1326+
// Note: min and max usually return a number, but for a single string argument also the string!
1327+
if (node.type === "min" || node.type === "max") {
1328+
if (node.args.length === 1) {
1329+
if (node.args[0].type === "$") {
1330+
node.pt = "$";
1331+
}
1332+
} else if (node.args.length > 1) {
1333+
node.pt = "R";
1334+
}
1335+
}
13261336
return node.pv;
13271337
},
13281338

@@ -1467,7 +1477,9 @@ CodeGeneratorJs.prototype = {
14671477
} catch (e) {
14681478
oOut.error = e;
14691479
if ("pos" in e) {
1470-
Utils.console.warn(e); // our errors have "pos" defined => show as warning
1480+
if (!this.bQuiet) {
1481+
Utils.console.warn(e); // our errors have "pos" defined => show as warning
1482+
}
14711483
} else { // other errors
14721484
Utils.console.error(e);
14731485
}

Controller.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ Controller.prototype = {
446446
switch (sKey) {
447447
case "": // no key?
448448
break;
449-
case "\r": // cr (\x0c)
449+
case "\r": // cr (\x0d)
450450
break;
451451
case "\x10": // DLE (clear character under cursor)
452452
sKey = "\x07"; // currently ignore (BEL)
@@ -1381,7 +1381,10 @@ Controller.prototype = {
13811381
fnRun: function (oParas) {
13821382
var sScript = this.view.getAreaValue("outputText"),
13831383
iLine = oParas && oParas.iLine || 0,
1384-
oVm = this.oVm;
1384+
oVm = this.oVm,
1385+
that = this,
1386+
iTimeout = 1,
1387+
input;
13851388

13861389
iLine = iLine || 0;
13871390
if (iLine === 0) {
@@ -1409,10 +1412,12 @@ Controller.prototype = {
14091412
oVm.clear(); // we do a clear as well here
14101413
}
14111414
oVm.vmReset4Run();
1415+
/*
14121416
if (!this.bInputSet) {
14131417
this.bInputSet = true;
14141418
this.oKeyboard.putKeysInBuffer(this.model.getProperty("input"));
14151419
}
1420+
*/
14161421

14171422
if (this.fnScript) {
14181423
oVm.sOut = this.view.getAreaValue("resultText");
@@ -1424,6 +1429,19 @@ Controller.prototype = {
14241429
this.view.setDisabled("stopButton", false);
14251430
this.view.setDisabled("continueButton", true);
14261431
}
1432+
1433+
if (!this.bInputSet) {
1434+
this.bInputSet = true;
1435+
input = this.model.getProperty("input");
1436+
1437+
if (input !== "") {
1438+
this.view.setAreaValue("inp2Text", input);
1439+
setTimeout(function () {
1440+
that.startEnter();
1441+
}, iTimeout);
1442+
}
1443+
}
1444+
14271445
if (Utils.debug > 1) {
14281446
Utils.console.debug("End of fnRun");
14291447
}
@@ -1762,7 +1780,7 @@ Controller.prototype = {
17621780
var sInput = this.view.getAreaValue("inp2Text"),
17631781
i;
17641782

1765-
sInput = sInput.replace("\n", "\r"); // LF => CR
1783+
sInput = sInput.replace(/\n/g, "\r"); // LF => CR
17661784
if (!sInput.endsWith("\r")) {
17671785
sInput += "\r";
17681786
}

CpcVm.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ CpcVm.prototype = {
626626
if (iTime >= this.iNextFrameTime) {
627627
this.vmCheckNextFrame(iTime);
628628
this.iStopCount += 1;
629-
if (this.iStopCount >= 5) { // do not stop too often because of just timer resason because setTimeout is expensive
629+
if (this.iStopCount >= 5) { // do not stop too often because of just timer reason because setTimeout is expensive
630630
this.iStopCount = 0;
631631
this.vmStop("timer", 20);
632632
}
@@ -2091,6 +2091,13 @@ CpcVm.prototype = {
20912091
max: function () { // varargs
20922092
var i;
20932093

2094+
if (arguments.length === 1) { // if just one argument, return it, even if it is a string
2095+
if (typeof arguments[0] !== "number" && !this.quiet) {
2096+
Utils.console.warn("MAX: Not a number:", arguments[0]);
2097+
}
2098+
return arguments[0];
2099+
}
2100+
20942101
for (i = 0; i < arguments.length; i += 1) {
20952102
this.vmAssertNumber(arguments[i], "MAX");
20962103
}
@@ -2145,6 +2152,13 @@ CpcVm.prototype = {
21452152
min: function () { // varargs
21462153
var i;
21472154

2155+
if (arguments.length === 1) { // if just one argument, return it, even if it is a string
2156+
if (typeof arguments[0] !== "number" && !this.quiet) {
2157+
Utils.console.warn("MIN: Not a number:", arguments[0]);
2158+
}
2159+
return arguments[0];
2160+
}
2161+
21482162
for (i = 0; i < arguments.length; i += 1) {
21492163
this.vmAssertNumber(arguments[i], "MIN");
21502164
}

DiskImage.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ DiskImage.prototype = {
2323
this.oConfig = oConfig || {};
2424

2525
this.sData = oConfig.sData;
26+
this.bQuiet = oConfig.bQuiet || false;
2627
this.reset();
2728
},
2829

@@ -95,7 +96,9 @@ DiskImage.prototype = {
9596

9697
if (oDiskInfo.sIdent.substr(34 - 11, 9) !== "Disk-Info") { // some tools use "Disk-Info " instead of "Disk-Info\r\n", so compare without "\r\n"
9798
// "Disk-Info" string is optional
98-
Utils.console.warn(this.composeError({}, "Disk ident not found", oDiskInfo.sIdent.substr(34 - 11, 9), iPos + 34 - 11).message);
99+
if (!this.bQuiet) {
100+
Utils.console.warn(this.composeError({}, "Disk ident not found", oDiskInfo.sIdent.substr(34 - 11, 9), iPos + 34 - 11).message);
101+
}
99102
}
100103

101104
oDiskInfo.sCreator = this.readUtf(iPos + 34, 14);
@@ -130,7 +133,9 @@ DiskImage.prototype = {
130133
oTrackInfo.sIdent = this.readUtf(iPos, 12);
131134
if (oTrackInfo.sIdent.substr(0, 10) !== "Track-Info") { // some tools use ""Track-Info " instead of ""Track-Info\r\n", so compare without "\r\n"
132135
// "Track-Info" string is optional
133-
Utils.console.warn(this.composeError({}, "Track ident not found", oTrackInfo.sIdent.substr(0, 10), iPos).message);
136+
if (!this.bQuiet) {
137+
Utils.console.warn(this.composeError({}, "Track ident not found", oTrackInfo.sIdent.substr(0, 10), iPos).message);
138+
}
134139
}
135140
// 4 unused bytes
136141
oTrackInfo.iTrack = this.readUInt8(iPos + 16);

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ BASIC programs are compiled to JavaScript which can be run in the browser. A lib
55

66
CPCBasic Links:
77
[CPCBasic Demo](https://benchmarko.github.io/CPCBasic/index.html?example=cpcbasic),
8-
[Colors CPC Demo](https://benchmarko.github.io/CPCBasic/index.html?example=demo/colors),
8+
[Colors CPC Demo](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/colors),
99
[Source code](https://github.com/benchmarko/CPCBasic/),
1010
[HTML Readme](https://github.com/benchmarko/CPCBasic/#readme),
1111

1212
Please note:
1313
CpcBasic gets only bug fixes. Active development goes on with CpcBasicTS, the TypeScript implementation of CPCBasic:
14-
[CPCBasicTS Demo](https://benchmarko.github.io/CPCBasicTS/?example=cpcbasic),
14+
[CPCBasicTS Demo](https://benchmarko.github.io/CPCBasicTS/),
1515
[CPCBasicTS Source](https://github.com/benchmarko/CPCBasicTS/)
1616

1717
## Features
@@ -26,12 +26,12 @@ CpcBasic gets only bug fixes. Active development goes on with CpcBasicTS, the Ty
2626

2727
[![A sample with cpcbasic](./img/cpcbasic.gif)](https://benchmarko.github.io/CPCBasic/index.html?example=cpcbasic)
2828

29-
[![Art](./img/art.png)](https://benchmarko.github.io/CPCBasic/index.html?example=art)
30-
[![Graphics](./img/graphics.png)](https://benchmarko.github.io/CPCBasic/index.html?example=demo/graphics)
31-
[![Labyrinth](./img/labyrinth.png)](https://benchmarko.github.io/CPCBasic/index.html?example=labyrinth)
32-
[![Landscape](./img/landscape.png)](https://benchmarko.github.io/CPCBasic/index.html?example=landscape)
29+
[![Art](./img/art.png)](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/art)
30+
[![Graphics](./img/graphics.png)](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/graphics)
31+
[![Labyrinth](./img/labyrinth.png)](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/labyrinth)
32+
[![Landscape](./img/landscape.png)](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/landscape)
3333

34-
More examples are in the sample library [CPCBasicApps](https://github.com/benchmarko/CPCBasicApps/#readme). They are included in CPCBasic as *apps*, example: [10print](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=demo/10print).
34+
More examples are in the sample library [CPCBasicApps](https://benchmarko.github.io/CPCBasicApps/), [CPCBasicApps source](https://github.com/benchmarko/CPCBasicApps/#readme). They are included in CPCBasic as *apps*, example: [10print](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=demo/10print).
3535

3636
## Why CPCBasic
3737

@@ -63,7 +63,7 @@ With CPC Basic we do not get that accuracy. But if we compile it to JavaScript,
6363
- The **Sound** button activates or deactivates sound.
6464
- If you use the *Reload* button with sound activated, the sound needs to be activated again. Just do a user action, e.g. click somewhere. This is a browser limitation.
6565
- The *Text View* window shows the text which is written in text mode.
66-
- The *Keyboard* window shows a virtual keyboard which can be also used with touch devices. You can test the functionality with the test program [keyboard](https://benchmarko.github.io/CPCBasic/index.html?example=test/keyboard&showKbd=true).
66+
- The *Keyboard* window shows a virtual keyboard which can be also used with touch devices. You can test the functionality with the test program [keyboard](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/keyboard&showKbd=true).
6767
- The *Input* window is an alternative way to send input to the CPC.
6868
- The *Console* window shows the textual output. This is useful for copying and pasting the output. It is cleared when the CPC screen is cleared (*MODE* or *CLS*).
6969
- The *Variables* window allows you to see the variables used by the program.
@@ -99,10 +99,10 @@ With CPC Basic we do not get that accuracy. But if we compile it to JavaScript,
9999
The next *INKEY$* will return it. This could be useful to select options presented on the screen.
100100
Another feature: After a MOVE 1000,1000, a mouse click does a *MOVE* at the click position.
101101
This can be detected by a BASIC program.
102-
Example: [Mouse Painting](https://benchmarko.github.io/CPCBasic/index.html?example=test/mousepa)
102+
Example: [Mouse Painting](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/mousepa)
103103
- *MODE 3*: High resolution mode with real 640x400 pixels, 16 colors and 8x8 pixels per character.
104104
This is different to the unofficial and not very useful Gate Array mode 3 on a real CPC: [CPC live: Graphics](http://cpctech.cpc-live.com/docs/graphics.html).
105-
Several examples use CPCBasic mode 3, e.g. [Art](https://benchmarko.github.io/CPCBasic/index.html?example=art), [Landscape](https://benchmarko.github.io/CPCBasic/index.html?example=landscape), [Rectangles](https://benchmarko.github.io/CPCBasic/index.html?example=test/rectangles).
105+
Several examples use CPCBasic mode 3, e.g. [Art](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/art), [Landscape](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/landscape), [Rectangles](https://benchmarko.github.io/CPCBasic/index.html?database=apps&example=test/rectangles).
106106
- *|MODE,n*: Change mode without *CLS*, including mode 3 (experimental)
107107
- *|RENUM,...*: similar to *RENUM* but with a 4th parameter to keep line numbers starting with this line
108108
- Computations with numbers are not limited to 16 bit

0 commit comments

Comments
 (0)