1
1
Fork 0
mirror of https://github.com/boxgaming/qbjs.git synced 2024-05-12 08:00:12 +00:00

Compare commits

...

5 commits

5 changed files with 58 additions and 13 deletions

View file

@ -135,7 +135,7 @@
<div>
<img id="logo" src="logo.png" onclick="window.open('https://github.com/boxgaming/qbjs/wiki', '_blank')">
<p>QBJS - QBasic for the Web!</p>
<p>Version: <a href="https://github.com/boxgaming/qbjs/releases" target="_blank">0.8.1</a></p>
<p>Version: <a href="https://github.com/boxgaming/qbjs/releases" target="_blank">0.8.2</a></p>
<p></p>
<p>
QBJS brings the fun and accessibility of QBasic to the browser.<br/>
@ -158,5 +158,5 @@
<script language="javascript" src="qb.js?v=0.8.0"></script>
<script language="javascript" src="qb2js.js?v=0.8.0"></script>
<script language="javascript" src="githelp.js?v=0.8.0"></script>
<script language="javascript" src="qbjs-ide.js?v=0.8.1"></script>
<script language="javascript" src="qbjs-ide.js?v=0.8.2"></script>
</html>

57
qb.js
View file

@ -58,7 +58,7 @@ var QB = new function() {
var _strokeLineThickness = 2;
var _windowAspect = [];
var _windowDef = [];
var _fileHandles = null;
var _fileHandles = {};
var _typeMap = {};
@ -2162,7 +2162,7 @@ var QB = new function() {
return n.toString(8).toUpperCase();
};
this.sub_Open = function(path, mode, handle) {
this.sub_Open = async function(path, mode, handle) {
var vfs = GX.vfs();
var vfsCwd = GX.vfsCwd();
if (mode == QB.OUTPUT || mode == QB.APPEND || mode == QB.BINARY) {
@ -2173,23 +2173,67 @@ var QB = new function() {
var file = null;
if (mode == QB.APPEND || mode == QB.BINARY) {
file = vfs.getNode(path, vfsCwd);
// TODO: make sure this is not a directory
}
if (!file) {
file = vfs.createFile(filename, parentNode);
if (mode == QB.APPEND || mode == QB.BINARY) {
file = await downloadFile(path);
}
if (!file) {
file = vfs.createFile(filename, parentNode);
}
}
else if (file.type != vfs.FILE) {
// make sure this is not a directory
throw new Error("Path is not a file.");
}
_fileHandles[handle] = { file: file, mode: mode, offset: 0 };
}
else if (mode == QB.INPUT) {
var file = vfs.getNode(path, vfsCwd);
if (!file || file.type != vfs.FILE) {
throw new Error("File not found");
if (!file) {
// attempt to copy the path to the local filesystem
var file = await downloadFile(path);
if (!file) {
throw new Error("File not found");
}
}
else if (file.type != vfs.FILE) {
throw new Error("Path is not a file.");
}
_fileHandles[handle] = { file: file, mode: mode, offset: 0 };
}
else {
throw new Error("Unsupported Open Method");
}
async function downloadFile(path) {
try {
var res = await fetch(path);
if (res.ok) {
var filename = vfs.getFileName(path);
var parentPath = vfs.getParentPath(path);
var parentNode = vfs.rootDirectory();
var dirs = parentPath.split("/");
for (var i=0; i < dirs.length; i++) {
if (dirs[i] == "") { continue; }
var node = vfs.getNode(dirs[i], parentNode);
if (!node) { node = vfs.createDirectory(dirs[i], parentNode); }
parentNode = node;
}
var file = vfs.createFile(filename, parentNode);
vfs.writeData(file, await res.arrayBuffer());
return file;
}
else {
return null;
}
}
catch (err) {
return null;
}
}
};
this.sub_Paint = function(sstep, startX, startY, fillColor, borderColor) {
@ -3026,6 +3070,7 @@ var QB = new function() {
while (!_lastKey && elapsed < totalWait) {
await GX.sleep(100);
elapsed += 100;
if (_haltedFlag) { return; }
}
};

View file

@ -2035,7 +2035,7 @@ if (QB.halted()) { return; };
var fline = ''; /* STRING */
var lineIndex = 0; /* INTEGER */
var rawJS = 0; /* SINGLE */
QB.sub_Open(filename, QB.INPUT, 1);
await QB.sub_Open(filename, QB.INPUT, 1);
var ___v1000522 = 0; while (!((QB.func_EOF( 1)))) { if (QB.halted()) { return; }___v1000522++; if (___v1000522 % 100 == 0) { await QB.autoLimit(); }
var ___v1030226 = new Array(1); await QB.sub_LineInputFromFile(1, ___v1030226); fline = ___v1030226[0];
lineIndex = lineIndex + 1;
@ -3556,7 +3556,7 @@ if (QB.halted()) { return; };
await sub_AddQBMethod( "FUNCTION" , "Mkl$" , False);
await sub_AddQBMethod( "SUB" , "Name" , False);
await sub_AddQBMethod( "FUNCTION" , "Oct$" , False);
await sub_AddQBMethod( "SUB" , "Open" , False);
await sub_AddQBMethod( "SUB" , "Open" , True);
await sub_AddQBMethod( "SUB" , "Paint" , False);
await sub_AddQBMethod( "FUNCTION" , "Point" , False);
await sub_AddQBMethod( "FUNCTION" , "Pos" , False);

View file

@ -161,7 +161,7 @@ var IDE = new function() {
}
});
}
if (appMode == "ide") {
if (appMode == "ide" && !inIframe()) {
editor.focus();
}
@ -371,7 +371,7 @@ var IDE = new function() {
zip.file("qb.js", await getFile("qb.js", "text"));
zip.file("vfs.js", await getFile("vfs.js", "text"));
zip.file("pako.2.1.0.min.js", await getFile("util/pako.2.1.0.min.js"));
zip.file("pako.2.1.0.min.js", await getFile("util/pako.2.1.0.min.js", "text"));
zip.file("gx/gx.js", await getFile("gx/gx.js", "text"));
zip.file("gx/__gx_font_default.png", await getFile("gx/__gx_font_default.png", "blob"));

View file

@ -3785,7 +3785,7 @@ Sub InitQBMethods
AddQBMethod "FUNCTION", "Mkl$", False
AddQBMethod "SUB", "Name", False
AddQBMethod "FUNCTION", "Oct$", False
AddQBMethod "SUB", "Open", False
AddQBMethod "SUB", "Open", True
AddQBMethod "SUB", "Paint", False
AddQBMethod "FUNCTION", "Point", False
AddQBMethod "FUNCTION", "Pos", False