mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-19 20:14:58 +00:00
added support for misc low-hanging fruit keywords (#78)
This commit is contained in:
parent
2a0b72396d
commit
1aa1ee17a6
4 changed files with 125 additions and 16 deletions
|
@ -36,21 +36,21 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
|||
var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];
|
||||
|
||||
var builtinFuncsWords = ['_acos', '_acosh', '_alpha', '_alpha32', '_asin', '_asinh', '_atan2', '_atanh', '_autodisplay',
|
||||
'_blue', '_blue32', '_ceil', '_continue', '_copyimage', '_cosh', '_coth', '_csch', '_backgroundcolor', '_defaultcolor',
|
||||
'_d2g', '_d2r', '_delay', '_dest', '_display', '_font', '_loadfont', '_fontwidth', '_fontheight', '_freeimage', '_fullscreen',
|
||||
'_g2d', '_g2r', '_green', '_green32', '_height', '_hypot',
|
||||
'_instrrev', '_limit', '_keyclear', '_keydown', '_keyhit', '_loadimage',
|
||||
'_mousebutton', '_mouseinput', '_mousewheel', '_mousex', '_mousey', '_newimage',
|
||||
'_palettecolor', '_pi', '_printstring', '_printwidth', '_printmode', '_putimage',
|
||||
'_backgroundcolor', '_blue', '_blue32', '_ceil', '_commandcount', '_continue', '_copyimage',
|
||||
'_cosh', '_coth', '_csch', '_cwd', '_defaultcolor', '_d2g', '_d2r', '_desktopwidth', '_desktopheight',
|
||||
'_delay', '_dest', '_dir', '_direxists', '_display', '_echo', '_fileexists', '_font', '_fontwidth', '_fontheight',
|
||||
'_freeimage', '_fullscreen', '_g2d', '_g2r', '_green', '_green32', '_height', '_hypot',
|
||||
'_instrrev', '_limit', '_keyclear', '_keydown', '_keyhit', '_loadfont', '_loadimage',
|
||||
'_mousebutton', '_mousehide', '_mouseinput', '_mouseshow', '_mousewheel', '_mousex', '_mousey',
|
||||
'_newimage', '_os', '_palettecolor', '_pi', '_printstring', '_printwidth', '_printmode', '_putimage',
|
||||
'_r2d', '_r2g', '_readbit', '_red', '_red32', '_resetbit', '_resize', '_resizewidth',
|
||||
'_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
|
||||
'_screenexists', '_sech', '_setbit', '_shl', '_shr', '_sinh', '_source', '_sndclose', '_sndopen',
|
||||
'_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol', '_strcmp', '_stricmp',
|
||||
'_tanh', '_title', '_trim', '_togglebit', '_width',
|
||||
'_cwd', '_startdir', '_os', '_direxists', '_fileexists',
|
||||
'_screenexists', '_screenmove', '_screenx', '_screeny', '_sech', '_setbit', '_shl', '_shr', '_sinh', '_source',
|
||||
'_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol', '_startdir',
|
||||
'_strcmp', '_stricmp', '_tanh', '_title', '_trim', '_togglebit', '_width',
|
||||
'abs', 'asc', 'atn', 'beep',
|
||||
'chr', 'cdbl', 'cint', 'clng', 'csng', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl',
|
||||
'data', 'date', 'draw', 'exp', 'fix', 'hex', 'input', 'inkey', 'instr', 'int',
|
||||
'data', 'date', 'draw', 'environ', 'error', 'exp', 'fix', 'hex', 'input', 'inkey', 'instr', 'int',
|
||||
'lbound', 'left', 'lcase', 'len', 'line', 'locate', 'log', 'ltrim', 'mid', 'mki', 'mkl',
|
||||
'oct', 'paint', 'point', 'preset', 'print', 'pset',
|
||||
'right', 'rtrim', 'randomize', 'read', 'restore', 'rnd',
|
||||
|
|
91
qb.js
91
qb.js
|
@ -291,6 +291,10 @@ var QB = new function() {
|
|||
return Math.ceil(x);
|
||||
};
|
||||
|
||||
this.func__CommandCount = function() {
|
||||
return 0;
|
||||
};
|
||||
|
||||
this.func__CopyImage = function(srcImageId) {
|
||||
var srcCanvas = _images[srcImageId].canvas;
|
||||
var destImageId = QB.func__NewImage(srcCanvas.width, srcCanvas.height);
|
||||
|
@ -334,6 +338,14 @@ var QB = new function() {
|
|||
await GX.sleep(seconds*1000);
|
||||
};
|
||||
|
||||
this.func__DesktopHeight = function() {
|
||||
return window.screen.height * window.devicePixelRatio;
|
||||
};
|
||||
|
||||
this.func__DesktopWidth = function() {
|
||||
return window.screen.width * window.devicePixelRatio;
|
||||
};
|
||||
|
||||
this.func__Dest = function() {
|
||||
return _activeImage;
|
||||
};
|
||||
|
@ -342,6 +354,10 @@ var QB = new function() {
|
|||
_activeImage = imageId;
|
||||
};
|
||||
|
||||
this.func__Dir = function(folder) {
|
||||
return "./";
|
||||
};
|
||||
|
||||
this.func__DirExists = function(path) {
|
||||
var vfs = GX.vfs();
|
||||
var dir = vfs.getNode(path, GX.vfsCwd());
|
||||
|
@ -359,6 +375,10 @@ var QB = new function() {
|
|||
// The canvas handles this for us, this method is included for compatibility
|
||||
};
|
||||
|
||||
this.sub__Echo = function(msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
this.func__FileExists = function(path) {
|
||||
var vfs = GX.vfs();
|
||||
var file = vfs.getNode(path, GX.vfsCwd());
|
||||
|
@ -607,6 +627,37 @@ var QB = new function() {
|
|||
return GX._mouseInput();
|
||||
};
|
||||
|
||||
this.sub__MouseHide = function() {
|
||||
var canvas = _images[0].canvas;
|
||||
canvas.style.cursor = "none";
|
||||
};
|
||||
|
||||
this.sub__MouseShow = function(style) {
|
||||
if (style == undefined) {
|
||||
style = "DEFAULT";
|
||||
}
|
||||
else {
|
||||
style = style.trim().toUpperCase();
|
||||
}
|
||||
var canvas = _images[0].canvas;
|
||||
if (style == "LINK") { canvas.style.cursor = "pointer"; }
|
||||
else if (style == "TEXT") { canvas.style.cursor = "text"; }
|
||||
else if (style == "CROSSHAIR") { canvas.style.cursor = "crosshair"; }
|
||||
else if (style == "VERTICAL") { canvas.style.cursor = "ns-resize"; }
|
||||
else if (style == "HORIZONTAL") { canvas.style.cursor = "ew-resize"; }
|
||||
else if (style == "TOPLEFT_BOTTOMRIGHT") { canvas.style.cursor = "nwse-resize"; }
|
||||
else if (style == "TOPRIGHT_BOTTOMLEFT") { canvas.style.cursor = "nesw-resize"; }
|
||||
else if (style == "PROGRESS") { canvas.style.cursor = "progress"; }
|
||||
else if (style == "WAIT") { canvas.style.cursor = "wait"; }
|
||||
else if (style == "MOVE") { canvas.style.cursor = "move"; }
|
||||
else if (style == "NOT_ALLOWED") { canvas.style.cursor = "not-allowed"; }
|
||||
else if (style == "GRAB") { canvas.style.cursor = "grab"; }
|
||||
else if (style == "GRABBING") { canvas.style.cursor = "grabbing"; }
|
||||
else if (style == "ZOOM_IN") { canvas.style.cursor = "zoom-in"; }
|
||||
else if (style == "ZOOM_OUT") { canvas.style.cursor = "zoom-out"; }
|
||||
else { canvas.style.cursor = "default"; }
|
||||
};
|
||||
|
||||
this.func__MouseX = function() {
|
||||
return GX.mouseX();
|
||||
};
|
||||
|
@ -917,6 +968,18 @@ var QB = new function() {
|
|||
return true;
|
||||
};
|
||||
|
||||
this.sub__ScreenMove = function() {
|
||||
/* no-op: included for compatibility */
|
||||
};
|
||||
|
||||
this.func__ScreenX = function() {
|
||||
return window.screenX;
|
||||
};
|
||||
|
||||
this.func__ScreenY = function() {
|
||||
return window.screenY;
|
||||
};
|
||||
|
||||
this.func__Sech = function(x) {
|
||||
return 1/Math.cosh(x);
|
||||
};
|
||||
|
@ -991,6 +1054,10 @@ var QB = new function() {
|
|||
return Math.tanh(x);
|
||||
};
|
||||
|
||||
this.func__Title = function() {
|
||||
return document.title;
|
||||
};
|
||||
|
||||
this.sub__Title = function(title) {
|
||||
document.title = title;
|
||||
};
|
||||
|
@ -1139,7 +1206,7 @@ var QB = new function() {
|
|||
|
||||
this.func_Csrlin = function() {
|
||||
return _locY + 1;
|
||||
}
|
||||
};
|
||||
|
||||
this.func_Cvi = function(numString) {
|
||||
var result = 0;
|
||||
|
@ -1148,7 +1215,7 @@ var QB = new function() {
|
|||
result+=numString.charCodeAt(1-i)<<(8*i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
this.func_Cvl = function(numString) {
|
||||
var result = 0;
|
||||
|
@ -1157,7 +1224,7 @@ var QB = new function() {
|
|||
result+=numString.charCodeAt(3-i)<<(8*i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
this.func_Date = function() {
|
||||
var today = new Date();
|
||||
|
@ -1165,7 +1232,7 @@ var QB = new function() {
|
|||
var mm = String(today.getMonth() + 1).padStart(2, '0');
|
||||
var yyyy = today.getFullYear();
|
||||
return mm + '-' + dd + '-' + yyyy;
|
||||
}
|
||||
};
|
||||
|
||||
this.sub_Draw = function(t) {
|
||||
|
||||
|
@ -1472,6 +1539,19 @@ var QB = new function() {
|
|||
screen.lastY = cursY;
|
||||
};
|
||||
|
||||
this.func_Environ = function(param) {
|
||||
/* no-op: included for compatibility */
|
||||
return "";
|
||||
};
|
||||
|
||||
this.sub_Environ = function(value) {
|
||||
/* no-op: included for compatibility */
|
||||
};
|
||||
|
||||
this.sub_Error = function(errorNumber) {
|
||||
throw new Error("Unhandled Error #" + errorNumber);
|
||||
};
|
||||
|
||||
this.func_Exp = function(value) {
|
||||
return Math.exp(value);
|
||||
};
|
||||
|
@ -2747,6 +2827,7 @@ var QB = new function() {
|
|||
_images[0] = { canvas: GX.canvas(), ctx: GX.ctx(), lastX: 0, lastY: 0 };
|
||||
_images[0].lastX = _images[0].canvas.width/2;
|
||||
_images[0].lastY = _images[0].canvas.height/2;
|
||||
_images[0].canvas.style.cursor = "default";
|
||||
|
||||
_screenDiagInv = 1/Math.sqrt(_images[0].canvas.width*_images[0].canvas.width + _images[0].canvas.height*_images[0].canvas.height);
|
||||
|
||||
|
@ -2775,7 +2856,7 @@ var QB = new function() {
|
|||
_keyDownMap = {};
|
||||
|
||||
// TODO: set the appropriate default font for the selected screen mode above instead of here
|
||||
GX.canvas().style.letterSpacing = "-1px";
|
||||
//GX.canvas().style.letterSpacing = "-1px";
|
||||
};
|
||||
|
||||
this.func_Seek = function(fh) {
|
||||
|
|
14
qb2js.js
14
qb2js.js
|
@ -3235,6 +3235,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION" , "_Blue" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Blue32" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Ceil" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_CommandCount" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_CopyImage" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Cosh" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Coth" , False);
|
||||
|
@ -3244,11 +3245,15 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION" , "_D2R" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_DefaultColor" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_Delay" , True);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_DesktopHeight" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_DesktopWidth" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Dest" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_Dest" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Dir" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_DirExists" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Display" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_Display" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_Echo" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_FileExists" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Font" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_Font" , False);
|
||||
|
@ -3272,6 +3277,8 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION" , "_LoadImage" , True);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_MouseButton" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_MouseInput" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_MouseShow" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_MouseHide" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_MouseWheel" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_MouseX" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_MouseY" , False);
|
||||
|
@ -3299,6 +3306,9 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION" , "_RGBA32" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Round" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_ScreenExists" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_ScreenMove" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_ScreenX" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_ScreenY" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Sech" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Setbit" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Shl" , False);
|
||||
|
@ -3317,6 +3327,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION" , "_Strcmp" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Stricmp" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Tanh" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Title" , False);
|
||||
await sub_AddQBMethod( "SUB" , "_Title" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Togglebit" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "_Trim" , False);
|
||||
|
@ -3342,6 +3353,9 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION" , "Cvl" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "Date$" , False);
|
||||
await sub_AddQBMethod( "SUB" , "Draw" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "Environ" , False);
|
||||
await sub_AddQBMethod( "SUB" , "Environ" , False);
|
||||
await sub_AddQBMethod( "SUB" , "Error" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "EOF" , False);
|
||||
await sub_AddQBMethod( "FUNCTION" , "Exp" , False);
|
||||
await sub_AddQBMethod( "SUB" , "Files" , True);
|
||||
|
|
|
@ -3454,6 +3454,7 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "_Blue", False
|
||||
AddQBMethod "FUNCTION", "_Blue32", False
|
||||
AddQBMethod "FUNCTION", "_Ceil", False
|
||||
AddQBMethod "FUNCTION", "_CommandCount", False
|
||||
AddQBMethod "FUNCTION", "_CopyImage", False
|
||||
AddQBMethod "FUNCTION", "_Cosh", False
|
||||
AddQBMethod "FUNCTION", "_Coth", False
|
||||
|
@ -3463,11 +3464,15 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "_D2R", False
|
||||
AddQBMethod "FUNCTION", "_DefaultColor", False
|
||||
AddQBMethod "SUB", "_Delay", True
|
||||
AddQBMethod "FUNCTION", "_DesktopHeight", False
|
||||
AddQBMethod "FUNCTION", "_DesktopWidth", False
|
||||
AddQBMethod "FUNCTION", "_Dest", False
|
||||
AddQBMethod "SUB", "_Dest", False
|
||||
AddQBMethod "FUNCTION", "_Dir", False
|
||||
AddQBMethod "FUNCTION", "_DirExists", False
|
||||
AddQBMethod "FUNCTION", "_Display", False
|
||||
AddQBMethod "SUB", "_Display", False
|
||||
AddQBMethod "SUB", "_Echo", False
|
||||
AddQBMethod "FUNCTION", "_FileExists", False
|
||||
AddQBMethod "FUNCTION", "_Font", False
|
||||
AddQBMethod "SUB", "_Font", False
|
||||
|
@ -3491,6 +3496,8 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "_LoadImage", True
|
||||
AddQBMethod "FUNCTION", "_MouseButton", False
|
||||
AddQBMethod "FUNCTION", "_MouseInput", False
|
||||
AddQBMethod "SUB", "_MouseShow", False
|
||||
AddQBMethod "SUB", "_MouseHide", False
|
||||
AddQBMethod "FUNCTION", "_MouseWheel", False
|
||||
AddQBMethod "FUNCTION", "_MouseX", False
|
||||
AddQBMethod "FUNCTION", "_MouseY", False
|
||||
|
@ -3518,6 +3525,9 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "_RGBA32", False
|
||||
AddQBMethod "FUNCTION", "_Round", False
|
||||
AddQBMethod "FUNCTION", "_ScreenExists", False
|
||||
AddQBMethod "SUB", "_ScreenMove", False
|
||||
AddQBMethod "FUNCTION", "_ScreenX", False
|
||||
AddQBMethod "FUNCTION", "_ScreenY", False
|
||||
AddQBMethod "FUNCTION", "_Sech", False
|
||||
AddQBMethod "FUNCTION", "_Setbit", False
|
||||
AddQBMethod "FUNCTION", "_Shl", False
|
||||
|
@ -3536,6 +3546,7 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "_Strcmp", False
|
||||
AddQBMethod "FUNCTION", "_Stricmp", False
|
||||
AddQBMethod "FUNCTION", "_Tanh", False
|
||||
AddQBMethod "FUNCTION", "_Title", False
|
||||
AddQBMethod "SUB", "_Title", False
|
||||
AddQBMethod "FUNCTION", "_Togglebit", False
|
||||
AddQBMethod "FUNCTION", "_Trim", False
|
||||
|
@ -3564,6 +3575,9 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "Cvl", False
|
||||
AddQBMethod "FUNCTION", "Date$", False
|
||||
AddQBMethod "SUB", "Draw", False
|
||||
AddQBMethod "FUNCTION", "Environ", False
|
||||
AddQBMethod "SUB", "Environ", False
|
||||
AddQBMethod "SUB", "Error", False
|
||||
AddQBMethod "FUNCTION", "EOF", False
|
||||
AddQBMethod "FUNCTION", "Exp", False
|
||||
AddQBMethod "SUB", "Files", True
|
||||
|
|
Loading…
Reference in a new issue