Thunderclock: Tweak DOS/BASIC handling of colons
This is ugly, but you should see what real BASIC/DOS do under the hood.
This commit is contained in:
parent
d727640ef4
commit
d7ebf753db
7
basic.js
7
basic.js
|
@ -335,9 +335,10 @@ this.basic = (function() {
|
||||||
var regexWhitespace = /^[ \t]+/,
|
var regexWhitespace = /^[ \t]+/,
|
||||||
regexQuotedString = /^"([^"]*?)(?:"|(?=\n|\r|$))/,
|
regexQuotedString = /^"([^"]*?)(?:"|(?=\n|\r|$))/,
|
||||||
regexUnquotedString = /^[^:,\r\n]*/,
|
regexUnquotedString = /^[^:,\r\n]*/,
|
||||||
|
regexUnquotedStringIgnoreColons = /^[^,\r\n]*/,
|
||||||
regexComma = /^,/;
|
regexComma = /^,/;
|
||||||
|
|
||||||
return function parseDataInput(stream, items) {
|
return function parseDataInput(stream, items, ignoreColons) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
stream.match(regexWhitespace);
|
stream.match(regexWhitespace);
|
||||||
|
@ -345,7 +346,7 @@ this.basic = (function() {
|
||||||
if (stream.match(regexQuotedString)) {
|
if (stream.match(regexQuotedString)) {
|
||||||
// quoted string
|
// quoted string
|
||||||
items.push(stream.lastMatch[1]);
|
items.push(stream.lastMatch[1]);
|
||||||
} else if (stream.match(regexUnquotedString)) {
|
} else if (stream.match(ignoreColons ? regexUnquotedStringIgnoreColons : regexUnquotedString)) {
|
||||||
// unquoted string
|
// unquoted string
|
||||||
items.push(stream.lastMatch[0]);
|
items.push(stream.lastMatch[0]);
|
||||||
}
|
}
|
||||||
|
@ -760,7 +761,7 @@ this.basic = (function() {
|
||||||
var parts = [],
|
var parts = [],
|
||||||
stream = new Stream(entry);
|
stream = new Stream(entry);
|
||||||
|
|
||||||
parseDataInput(stream, parts);
|
parseDataInput(stream, parts, entry.ignoreColons);
|
||||||
|
|
||||||
while (varlist.length && parts.length) {
|
while (varlist.length && parts.length) {
|
||||||
try {
|
try {
|
||||||
|
|
13
dos.js
13
dos.js
|
@ -442,6 +442,9 @@ function DOS(tty) {
|
||||||
tty.writeString(prompt + string + "\r");
|
tty.writeString(prompt + string + "\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Suppress BASIC parsing of colons
|
||||||
|
string = Object.assign(new String(string), {ignoreColons: true});
|
||||||
|
|
||||||
// Non-blocking return
|
// Non-blocking return
|
||||||
setTimeout(function() { callback(string); }, 0);
|
setTimeout(function() { callback(string); }, 0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -527,7 +530,7 @@ function DOS(tty) {
|
||||||
var MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
|
var MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
|
||||||
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
||||||
function spad2(s) {
|
function spad2(s) {
|
||||||
return ('00' + String(s)).slice(-2);
|
return (' ' + String(s)).slice(-2);
|
||||||
}
|
}
|
||||||
function zpad2(s) {
|
function zpad2(s) {
|
||||||
return ('00' + String(s)).slice(-2);
|
return ('00' + String(s)).slice(-2);
|
||||||
|
@ -544,7 +547,7 @@ function DOS(tty) {
|
||||||
clockbuf =
|
clockbuf =
|
||||||
DAYS[now.getDay()] + ' ' +
|
DAYS[now.getDay()] + ' ' +
|
||||||
MONTHS[now.getMonth()] + ' ' +
|
MONTHS[now.getMonth()] + ' ' +
|
||||||
now.getDate() + ' ' +
|
spad2(now.getDate()) + ' ' +
|
||||||
spad2((now.getHours() === 0 ? 12 : now.getHours() > 12 ? now.getHours() - 12 : now.getHours())) + ':' +
|
spad2((now.getHours() === 0 ? 12 : now.getHours() > 12 ? now.getHours() - 12 : now.getHours())) + ':' +
|
||||||
zpad2(now.getMinutes()) + ':' +
|
zpad2(now.getMinutes()) + ':' +
|
||||||
zpad2(now.getSeconds()) + ' ' +
|
zpad2(now.getSeconds()) + ' ' +
|
||||||
|
@ -555,7 +558,7 @@ function DOS(tty) {
|
||||||
clockbuf =
|
clockbuf =
|
||||||
DAYS[now.getDay()] + ' ' +
|
DAYS[now.getDay()] + ' ' +
|
||||||
MONTHS[now.getMonth()] + ' ' +
|
MONTHS[now.getMonth()] + ' ' +
|
||||||
now.getDate() + ' ' +
|
spad2(now.getDate()) + ' ' +
|
||||||
spad2(now.getHours()) + ':' +
|
spad2(now.getHours()) + ':' +
|
||||||
zpad2(now.getMinutes()) + ':' +
|
zpad2(now.getMinutes()) + ':' +
|
||||||
zpad2(now.getSeconds()) + ' ' +
|
zpad2(now.getSeconds()) + ' ' +
|
||||||
|
@ -587,6 +590,10 @@ function DOS(tty) {
|
||||||
tty.writeString(prompt); // TODO: Correct? Newline?
|
tty.writeString(prompt); // TODO: Correct? Newline?
|
||||||
var tmp = clockbuf;
|
var tmp = clockbuf;
|
||||||
clockbuf = '';
|
clockbuf = '';
|
||||||
|
|
||||||
|
// Suppress BASIC parsing of colons
|
||||||
|
tmp = Object.assign(new String(tmp), {ignoreColons: true});
|
||||||
|
|
||||||
setTimeout(function() { callback(tmp); }, 0);
|
setTimeout(function() { callback(tmp); }, 0);
|
||||||
}
|
}
|
||||||
function clock_readChar(callback) {
|
function clock_readChar(callback) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ sample.onelinetrain One Liner Train (Chris ten Den)
|
||||||
sample.piglatin Pig Latin Translator (Gregg Buntin)
|
sample.piglatin Pig Latin Translator (Gregg Buntin)
|
||||||
sample.nuclear Nuclear Power Plant (Stephen R. Berggren c/o Kevin Riggle)
|
sample.nuclear Nuclear Power Plant (Stephen R. Berggren c/o Kevin Riggle)
|
||||||
sample.factors Prime Factors (Cristiano Trabuio)
|
sample.factors Prime Factors (Cristiano Trabuio)
|
||||||
sample.thunderclock Thunderclock (incomplete)
|
sample.thunderclock Thunderclock
|
||||||
|
|
||||||
# ____________________________________________
|
# ____________________________________________
|
||||||
# Traveller RPG Utilities
|
# Traveller RPG Utilities
|
||||||
|
|
|
@ -19,3 +19,22 @@
|
||||||
163 PRINT "Hours: ";HR
|
163 PRINT "Hours: ";HR
|
||||||
164 PRINT "Minutes: ";MN
|
164 PRINT "Minutes: ";MN
|
||||||
165 PRINT "Seconds: ";SEC
|
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
|
||||||
|
|
Loading…
Reference in New Issue