From f5fc0c9cd37a87bd440ea73f959cf0e11dc21821 Mon Sep 17 00:00:00 2001 From: William Barnes Date: Wed, 15 Jun 2022 14:59:47 -0400 Subject: [PATCH] Added keywords: _Readbit, _Setbit, _Resetbit, _Togglebit. --- codemirror/qb-lang.js | 6 +++--- qb.js | 28 ++++++++++++++++++++++++++-- qb2js.js | 4 ++++ tools/qb2js.bas | 6 +++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/codemirror/qb-lang.js b/codemirror/qb-lang.js index 1f92d85..8921cae 100644 --- a/codemirror/qb-lang.js +++ b/codemirror/qb-lang.js @@ -38,9 +38,9 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) { var builtinFuncsWords = ['_acos', '_acosh', '_alpha', '_alpha32', '_asin', '_asinh', '_atan2', '_atanh', '_autodisplay', '_blue', '_blue32', '_ceil', '_continue', '_copyimage', '_cosh', '_coth', '_csch', '_d2g', '_d2r', '_delay', '_dest', '_display', '_fontwidth', '_freeimage', '_fullscreen', '_g2d', '_g2r', '_green', '_green32', '_height', '_hypot', '_instrrev', '_limit', '_keyclear', '_keydown', '_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth', - '_putimage', '_r2d', '_r2g', '_red', '_red32', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round', - '_screenexists', '_sech', '_shl', '_shr', '_sinh', '_source', '_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol', '_strcmp', '_stricmp', '_tanh', - '_title', '_trim', '_width', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'data', 'draw', 'exp', + '_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', 'abs', 'asc', 'atn', 'beep', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'data', 'draw', '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', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr', 'str', 'swap', 'tan', 'time', 'timer', 'ubound', 'ucase', 'val', 'varptr', 'window', diff --git a/qb.js b/qb.js index 9dde32a..b75abc3 100644 --- a/qb.js +++ b/qb.js @@ -547,6 +547,15 @@ var QB = new function() { return (x*(9/10))*180/Math.PI; }; + this.func__Readbit= function(x, y) { + var mask = 1 << y; + if ((x & mask) != 0) { + return -1; + } else { + return 0; + } + }; + this.func__Red = function(rgb, imageHandle) { // TODO: implement corresponding logic when an image handle is supplied (maybe) return _color(rgb).r; @@ -557,6 +566,11 @@ var QB = new function() { return _color(rgb).r; }; + this.func__Resetbit = function(x, y) { + var mask = 1 << y; + return x & ~mask; + }; + this.func__Resize = function() { var tmp = _resize; _resize = false; @@ -613,6 +627,11 @@ var QB = new function() { return 1/Math.cosh(x); }; + this.func__Setbit = function(x, y) { + var mask = 1 << y; + return x | mask; + }; + this.func__Shl = function(x, y) { return x << y; }; @@ -661,13 +680,13 @@ var QB = new function() { }; this.func__Strcmp = function(x, y) { - return ( ( x == y ) ? 0 : ( ( x > y ) ? 1 : -1 ) ); + return (( x == y ) ? 0 : (( x > y ) ? 1 : -1 )); }; this.func__Stricmp = function(x, y) { var a = x.toLowerCase(); var b = y.toLowerCase(); - return ( ( a == b ) ? 0 : ( ( a > b ) ? 1 : -1 ) ); + return (( a == b ) ? 0 : (( a > b ) ? 1 : -1 )); }; this.func__Tanh = function(x) { @@ -682,6 +701,11 @@ var QB = new function() { return value.trim(); }; + this.func__Togglebit = function(x, y) { + var mask = 1 << y; + return x ^ mask; + }; + this.func__Width = function(imageId) { if (imageId == undefined) { imageId = _activeImage; } if (_images[imageId].charSizeMode) { diff --git a/qb2js.js b/qb2js.js index 841dc68..f2daed4 100644 --- a/qb2js.js +++ b/qb2js.js @@ -2808,8 +2808,10 @@ if (QB.halted()) { return; } await sub_AddQBMethod( "SUB", "_PutImage", False); await sub_AddQBMethod( "FUNCTION", "_R2D", False); await sub_AddQBMethod( "FUNCTION", "_R2G", False); + await sub_AddQBMethod( "FUNCTION", "_Readbit", False); await sub_AddQBMethod( "FUNCTION", "_Red", False); await sub_AddQBMethod( "FUNCTION", "_Red32", False); + await sub_AddQBMethod( "FUNCTION", "_Resetbit", False); await sub_AddQBMethod( "FUNCTION", "_Resize", False); await sub_AddQBMethod( "FUNCTION", "_ResizeHeight", False); await sub_AddQBMethod( "FUNCTION", "_ResizeWidth", False); @@ -2820,6 +2822,7 @@ if (QB.halted()) { return; } await sub_AddQBMethod( "FUNCTION", "_Round", False); await sub_AddQBMethod( "FUNCTION", "_ScreenExists", False); await sub_AddQBMethod( "FUNCTION", "_Sech", False); + await sub_AddQBMethod( "FUNCTION", "_Setbit", False); await sub_AddQBMethod( "FUNCTION", "_Shl", False); await sub_AddQBMethod( "FUNCTION", "_Shr", False); await sub_AddQBMethod( "FUNCTION", "_Sinh", False); @@ -2836,6 +2839,7 @@ if (QB.halted()) { return; } await sub_AddQBMethod( "FUNCTION", "_Stricmp", False); await sub_AddQBMethod( "FUNCTION", "_Tanh", False); await sub_AddQBMethod( "SUB", "_Title", False); + await sub_AddQBMethod( "FUNCTION", "_Togglebit", False); await sub_AddQBMethod( "FUNCTION", "_Trim", False); await sub_AddQBMethod( "FUNCTION", "_Width", False); await sub_AddQBMethod( "FUNCTION", "Abs", False); diff --git a/tools/qb2js.bas b/tools/qb2js.bas index b032ac2..8e02314 100644 --- a/tools/qb2js.bas +++ b/tools/qb2js.bas @@ -2996,8 +2996,10 @@ Sub InitQBMethods AddQBMethod "SUB", "_PutImage", False AddQBMethod "FUNCTION", "_R2D", False AddQBMethod "FUNCTION", "_R2G", False + AddQBMethod "FUNCTION", "_Readbit", False AddQBMethod "FUNCTION", "_Red", False AddQBMethod "FUNCTION", "_Red32", False + AddQBMethod "FUNCTION", "_Resetbit", False AddQBMethod "FUNCTION", "_Resize", False AddQBMethod "FUNCTION", "_ResizeHeight", False AddQBMethod "FUNCTION", "_ResizeWidth", False @@ -3008,6 +3010,7 @@ Sub InitQBMethods AddQBMethod "FUNCTION", "_Round", False AddQBMethod "FUNCTION", "_ScreenExists", False AddQBMethod "FUNCTION", "_Sech", False + AddQBMethod "FUNCTION", "_Setbit", False AddQBMethod "FUNCTION", "_Shl", False AddQBMethod "FUNCTION", "_Shr", False AddQBMethod "FUNCTION", "_Sinh", False @@ -3021,9 +3024,10 @@ Sub InitQBMethods AddQBMethod "SUB", "_SndStop", False AddQBMethod "SUB", "_SndVol", False AddQBMethod "FUNCTION", "_Strcmp", False - AddQBMethod "FUNCTION", "_Stricmp", False + AddQBMethod "FUNCTION", "_Stricmp", False AddQBMethod "FUNCTION", "_Tanh", False AddQBMethod "SUB", "_Title", False + AddQBMethod "FUNCTION", "_Togglebit", False AddQBMethod "FUNCTION", "_Trim", False AddQBMethod "FUNCTION", "_Width", False