diff --git a/basic.js b/basic.js index 9e000f2..9551e62 100644 --- a/basic.js +++ b/basic.js @@ -335,9 +335,10 @@ this.basic = (function() { var regexWhitespace = /^[ \t]+/, regexQuotedString = /^"([^"]*?)(?:"|(?=\n|\r|$))/, regexUnquotedString = /^[^:,\r\n]*/, + regexUnquotedStringIgnoreColons = /^[^,\r\n]*/, regexComma = /^,/; - return function parseDataInput(stream, items) { + return function parseDataInput(stream, items, ignoreColons) { do { stream.match(regexWhitespace); @@ -345,7 +346,7 @@ this.basic = (function() { if (stream.match(regexQuotedString)) { // quoted string items.push(stream.lastMatch[1]); - } else if (stream.match(regexUnquotedString)) { + } else if (stream.match(ignoreColons ? regexUnquotedStringIgnoreColons : regexUnquotedString)) { // unquoted string items.push(stream.lastMatch[0]); } @@ -760,7 +761,7 @@ this.basic = (function() { var parts = [], stream = new Stream(entry); - parseDataInput(stream, parts); + parseDataInput(stream, parts, entry.ignoreColons); while (varlist.length && parts.length) { try { diff --git a/dos.js b/dos.js index 9cacac6..39eeb90 100644 --- a/dos.js +++ b/dos.js @@ -442,6 +442,9 @@ function DOS(tty) { tty.writeString(prompt + string + "\r"); } + // Suppress BASIC parsing of colons + string = Object.assign(new String(string), {ignoreColons: true}); + // Non-blocking return setTimeout(function() { callback(string); }, 0); } else { @@ -527,7 +530,7 @@ function DOS(tty) { var MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']; function spad2(s) { - return ('00' + String(s)).slice(-2); + return (' ' + String(s)).slice(-2); } function zpad2(s) { return ('00' + String(s)).slice(-2); @@ -544,7 +547,7 @@ function DOS(tty) { clockbuf = DAYS[now.getDay()] + ' ' + MONTHS[now.getMonth()] + ' ' + - now.getDate() + ' ' + + spad2(now.getDate()) + ' ' + spad2((now.getHours() === 0 ? 12 : now.getHours() > 12 ? now.getHours() - 12 : now.getHours())) + ':' + zpad2(now.getMinutes()) + ':' + zpad2(now.getSeconds()) + ' ' + @@ -555,7 +558,7 @@ function DOS(tty) { clockbuf = DAYS[now.getDay()] + ' ' + MONTHS[now.getMonth()] + ' ' + - now.getDate() + ' ' + + spad2(now.getDate()) + ' ' + spad2(now.getHours()) + ':' + zpad2(now.getMinutes()) + ':' + zpad2(now.getSeconds()) + ' ' + @@ -587,6 +590,10 @@ function DOS(tty) { tty.writeString(prompt); // TODO: Correct? Newline? var tmp = clockbuf; clockbuf = ''; + + // Suppress BASIC parsing of colons + tmp = Object.assign(new String(tmp), {ignoreColons: true}); + setTimeout(function() { callback(tmp); }, 0); } function clock_readChar(callback) { diff --git a/samples/index.txt b/samples/index.txt index 1fa0fc7..16f487d 100644 --- a/samples/index.txt +++ b/samples/index.txt @@ -94,7 +94,7 @@ sample.onelinetrain One Liner Train (Chris ten Den) sample.piglatin Pig Latin Translator (Gregg Buntin) sample.nuclear Nuclear Power Plant (Stephen R. Berggren c/o Kevin Riggle) sample.factors Prime Factors (Cristiano Trabuio) -sample.thunderclock Thunderclock (incomplete) +sample.thunderclock Thunderclock # ____________________________________________ # Traveller RPG Utilities diff --git a/samples/sample.thunderclock.txt b/samples/sample.thunderclock.txt index 311dd0c..6194d23 100644 --- a/samples/sample.thunderclock.txt +++ b/samples/sample.thunderclock.txt @@ -19,3 +19,22 @@ 163 PRINT "Hours: ";HR 164 PRINT "Minutes: ";MN 165 PRINT "Seconds: ";SEC +166 PRINT + +210 PRINT "12-Hour Format" +220 PRINT CHR$(4);"PR#4" +230 PRINT CHR$(4);"IN#4" +240 INPUT ">";T$ +250 PRINT CHR$(4);"PR#0" +260 PRINT CHR$(4);"IN#0" +270 PRINT T$ +280 PRINT + +310 PRINT "24-Hour Format" +320 PRINT CHR$(4);"PR#4" +330 PRINT CHR$(4);"IN#4" +340 INPUT "<";T$ +350 PRINT CHR$(4);"PR#0" +360 PRINT CHR$(4);"IN#0" +370 PRINT T$ +380 PRINT