diff --git a/codemirror/qb-lang.js b/codemirror/qb-lang.js index 8921cae..b1e15d7 100644 --- a/codemirror/qb-lang.js +++ b/codemirror/qb-lang.js @@ -40,7 +40,7 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) { '_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth', '_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', + '_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', '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 b75abc3..5c3a25f 100644 --- a/qb.js +++ b/qb.js @@ -616,7 +616,11 @@ var QB = new function() { } this.func__Round = function(value) { - return Math.round(value); + if (value < 0) { + return -Math.round(-value); + } else { + return Math.round(value); + } }; this.func__ScreenExists = function() { @@ -832,6 +836,14 @@ var QB = new function() { return result; } + this.func_Date = function() { + var today = new Date(); + var dd = String(today.getDate()).padStart(2, '0'); + var mm = String(today.getMonth() + 1).padStart(2, '0'); + var yyyy = today.getFullYear(); + return mm + '-' + dd + '-' + yyyy; + } + this.sub_Draw = function(t) { // Turn input string into array of characters. @@ -1261,6 +1273,33 @@ var QB = new function() { return Math.log(value); }; + this.func_Cdbl = function(value) { + const buffer = new ArrayBuffer(16); + const view = new DataView(buffer); + view.setFloat32(1, value); + return view.getFloat32(1); + }; + + this.func_Cint = function(value) { + if (value > 0) { + return Math.round(value); + } else { + return -Math.round(-value); + } + }; + + this.func_Clng = function(value) { + if (value > 0) { + return Math.round(value); + } else { + return -Math.round(-value); + } + }; + + this.func_Csng = function(value) { + return value; // TODO: Implement this. + }; + this.sub_Circle = function(step, x, y, radius, color, startAngle, endAngle, aspect) { var screen = _images[_activeImage]; @@ -1783,7 +1822,7 @@ var QB = new function() { } this.sub_Restore = function(t) { - if (t == undefined || t.trim() == "") { + if ((t == undefined) || (t.trim() == "")) { _readCursorPosition = 0; } else { _readCursorPosition = _dataLabelMap[t]; @@ -1988,6 +2027,7 @@ var QB = new function() { this.func_Val = function(value) { var ret; + value = value.toString(); if (value.substring(0, 2) == "&H") { ret = parseInt(value.slice(2), 16); } else if (value.substring(0, 2) == "&O") { diff --git a/qb2js.js b/qb2js.js index 2907bad..cc06aef 100644 --- a/qb2js.js +++ b/qb2js.js @@ -30,8 +30,6 @@ async function _QBCompiler() { var currentMethod = ''; // STRING var currentModule = ''; // STRING var programMethods = 0; // INTEGER - var dataTicker = 0; // INTEGER - dataTicker = 1; if (QB.func_Command() != "" ) { await sub_QBToJS( QB.func_Command(), FILE, ""); await sub_PrintJS(); @@ -2847,6 +2845,10 @@ if (QB.halted()) { return; } await sub_AddQBMethod( "FUNCTION", "Atn", False); await sub_AddQBMethod( "SUB", "Beep", False); await sub_AddQBMethod( "FUNCTION", "Chr$", False); + await sub_AddQBMethod( "FUNCTION", "Cdbl", False); + await sub_AddQBMethod( "FUNCTION", "Cint", False); + await sub_AddQBMethod( "FUNCTION", "Clng", False); + await sub_AddQBMethod( "FUNCTION", "Csng", False); await sub_AddQBMethod( "SUB", "Circle", False); await sub_AddQBMethod( "SUB", "Cls", False); await sub_AddQBMethod( "SUB", "Color", False); @@ -2855,6 +2857,7 @@ if (QB.halted()) { return; } await sub_AddQBMethod( "FUNCTION", "Csrlin", False); await sub_AddQBMethod( "FUNCTION", "Cvi", False); await sub_AddQBMethod( "FUNCTION", "Cvl", False); + await sub_AddQBMethod( "FUNCTION", "Date$", False); await sub_AddQBMethod( "SUB", "Draw", False); await sub_AddQBMethod( "FUNCTION", "Exp", False); await sub_AddQBMethod( "FUNCTION", "Fix", False); diff --git a/tools/qb2js.bas b/tools/qb2js.bas index 0e877ac..42b0d2b 100644 --- a/tools/qb2js.bas +++ b/tools/qb2js.bas @@ -2,7 +2,7 @@ Option _Explicit $Console:Only '$ExeIcon:'./../gx/resource/gx.ico' -' In console after, creating exe, run: qb2js qb2js.bas > ../qb2js.js +' In console, after creating qb2js.exe, run: qb2js qb2js.bas > ../qb2js.js Const FILE = 1 Const TEXT = 2 @@ -70,8 +70,6 @@ Dim Shared modLevel As Integer Dim Shared As String currentMethod Dim Shared As String currentModule Dim Shared As Integer programMethods -Dim Shared As Integer dataTicker -dataTicker = 1 ' Only execute the conversion from the native version if we have been passed the ' source file to convert on the command line @@ -1720,19 +1718,6 @@ Function ReadLine (lineIndex As Integer, fline As String, rawJS As Integer) ReadLine = rawJS - 'If (_Trim$(LCase$(Left$(fline, 4))) = "data") Then - ' 'AddLineTop dataTicker, fline - ' 'AddSubLinesTop dataTicker, fline - ' AddLine dataTicker, fline - ' AddSubLines dataTicker, fline - ' Exit Function - 'End If - 'If (_Trim$(LCase$(Left$(fline, 6))) = "_label") Then - ' 'AddLineTop dataTicker, fline - ' AddLine dataTicker, fline - ' Exit Function - 'End If - If _Trim$(fline) = "" Then Exit Function Dim word As String @@ -2308,19 +2293,6 @@ Sub AddQBMethod (mtype As String, mname As String, sync As Integer) AddMethod m, "QB.", sync End Sub -'Sub AddLineTop (lineIndex As Integer, fline As String) -' Dim lcount As Integer: lcount = UBound(lines) + 1 -' ReDim _Preserve As CodeLine lines(lcount) -' Dim j As Integer -' For j = UBound(lines) To dataTicker Step -1 -' lines(j).line = lines(j - 1).line -' lines(j).text = lines(j - 1).text -' Next -' lines(dataTicker).line = dataTicker -' lines(dataTicker).text = fline -' dataTicker = dataTicker + 1 -'End Sub - Sub AddLine (lineIndex As Integer, fline As String) __AddLine lineIndex, fline End Sub @@ -3040,6 +3012,10 @@ Sub InitQBMethods AddQBMethod "FUNCTION", "Atn", False AddQBMethod "SUB", "Beep", False AddQBMethod "FUNCTION", "Chr$", False + AddQBMethod "FUNCTION", "Cdbl", False + AddQBMethod "FUNCTION", "Cint", False + AddQBMethod "FUNCTION", "Clng", False + AddQBMethod "FUNCTION", "Csng", False AddQBMethod "SUB", "Circle", False AddQBMethod "SUB", "Cls", False AddQBMethod "SUB", "Color", False @@ -3048,6 +3024,7 @@ Sub InitQBMethods AddQBMethod "FUNCTION", "Csrlin", False AddQBMethod "FUNCTION", "Cvi", False AddQBMethod "FUNCTION", "Cvl", False + AddQBMethod "FUNCTION", "Date$", False AddQBMethod "SUB", "Draw", False AddQBMethod "FUNCTION", "Exp", False AddQBMethod "FUNCTION", "Fix", False