//MACRO AddLiteral OpCode, Parms, {optional}, Comment //-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- // // // Label if required // if (Label === "") return DVASM.putError("Macro ADDLITERAL requires a label"); if (Comment === null) Comment= ""; // // Define necessary constants // var tstCode= OpCode.toUpperCase(); var index= -1; if (tstCode.startsWith("BYTE") || tstCode === "UTF_8") index= 0; else if (tstCode === "UTF_16" || tstCode === "HWRD") index= 1; else if (tstCode === "UTF_32" || tstCode === "FWRD") index= 2; else if (tstCode === "DWRD") index= 3; else if (tstCode === "QWRD") index= 4; else if (tstCode.startsWith("WRD_")) index= ["1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1K", "2K", "4K", "8K", "16K", "32K", "64K"].indexOf(tstCode.substring(4)); if (index < 0) return DVASM.putError("Invalid OpCode [" + OpCode +"] used for literal"); index= 16-index; // // Insert literal statement into global variable // var litPool= DVASM.getJSGlobal("__sys_literals"); if (litPool == null) litPool= [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]; var stmt= new Array(Label, OpCode, Parms, Comment); var stmtList= litPool[index]; if (stmtList == null) stmtList= [stmt]; else { var len= stmtList.length; stmtList[len]= stmt; } litPool[index]= stmtList; DVASM.putJSGlobal("__sys_literals", litPool);