mirror of
https://github.com/simon987/Much-Assembly-Required-Frontend.git
synced 2025-04-10 14:26:44 +00:00
22 lines
8.7 KiB
JavaScript
22 lines
8.7 KiB
JavaScript
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.checkStringArgs=function(a,c,b){if(null==a)throw new TypeError("The 'this' value for String.prototype."+b+" must not be null or undefined");if(c instanceof RegExp)throw new TypeError("First argument to String.prototype."+b+" must not be a regular expression");return a+""};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;
|
|
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,b){a!=Array.prototype&&a!=Object.prototype&&(a[c]=b.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
|
|
$jscomp.polyfill=function(a,c,b,d){if(c){b=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in b||(b[e]={});b=b[e]}a=a[a.length-1];d=b[a];c=c(d);c!=d&&null!=c&&$jscomp.defineProperty(b,a,{configurable:!0,writable:!0,value:c})}};
|
|
$jscomp.polyfill("String.prototype.startsWith",function(a){return a?a:function(a,b){var c=$jscomp.checkStringArgs(this,a,"startsWith");a+="";var e=c.length,f=a.length;b=Math.max(0,Math.min(b|0,c.length));for(var g=0;g<f&&b<e;)if(c[b++]!=a[g++])return!1;return g>=f}},"es6","es3");
|
|
$jscomp.polyfill("String.prototype.endsWith",function(a){return a?a:function(a,b){var c=$jscomp.checkStringArgs(this,a,"endsWith");a+="";void 0===b&&(b=c.length);b=Math.max(0,Math.min(b|0,c.length));for(var e=a.length;0<e&&0<b;)if(c[--b]!=a[--e])return!1;return 0>=e}},"es6","es3");OPERAND_INVALID=-1;OPERAND_REG=0;OPERAND_MEM_IMM=1;OPERAND_MEM_REG=2;OPERAND_IMM=3;editor=ace.edit("editor");editor.session.setOption("useWorker",!1);editor.$blockScrolling=Infinity;
|
|
function removeComment(a){return-1!==a.indexOf(";")?a.substring(0,a.indexOf(";")):a}function checkForLabel(a,c){a=removeComment(a);var b;null!==(b=/\b\w*\b:/.exec(a))&&c.labels.push(b[0].substring(0,b[0].length-1))}function checkForSegmentDeclaration(a){a=getTokens(a);return void 0!==a[0]&&(".data"===a[0].toLowerCase()||".text"===a[0].toLowerCase())}
|
|
function checkForEQUInstruction(a,c,b){var d=getTokens(a);return-1!==a.toLowerCase().indexOf(" equ ")||void 0!==d[1]&&"equ"===d[1].toLowerCase()?(a=Number(d[2]),isNaN(a)||a!==Math.floor(a)?c.annotations.push({row:b,column:0,text:"Usage: constant_name EQU immediate_value",type:"error"}):c.labels.push(d[0]),!0):!1}function getTokens(a){a=a.split(/\s+/);for(var c=0;c<a.length;c++)""===a[c]&&a.splice(c,1);return a}function removeLabel(a){return a.replace(/\b\w*\b:/,"")}
|
|
function checkForORGInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);a=getTokens(a);var d=a[0];if(void 0!==d&&"org"===d.toLowerCase()){if(console.log(a),1<a.length)return d=Number(a[1]),(isNaN(d)||d!==Math.floor(d))&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+a[1],type:"error"}),!0}else return!1}
|
|
function parseDWInstruction(a,c,b){a=a.trim();if("dw"===a.substr(0,2).toLowerCase()){a=a.substr(2,a.length).split(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/,-1);for(var d=0;d<a.length;d++){a[d]=a[d].trim();var e=getTokens(a[d]);if(!(2===e.length&&getOperandType(e[0],c)===OPERAND_IMM&&e[1].toLowerCase().startsWith("dup(")&&e[1].endsWith(")")&&getOperandType(e[1].substring(4,e[1].indexOf(")")),c)===OPERAND_IMM||a[d].startsWith('"')&&a[d].endsWith('"')||getOperandType(a[d],c)===OPERAND_IMM)){c.annotations.push({row:b,
|
|
column:0,text:"Usage: DW IMM, IMM ...",type:"error"});break}}return!0}return!1}
|
|
function getOperandType(a,c){a=a.trim();if(""===a)return OPERAND_INVALID;if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a))&&-1===a.indexOf("o")&&0!==a.indexOf("0e"))return OPERAND_IMM;if(/^(a|b|c|d|x|y|bp|sp)$/.test(a.toLowerCase()))return OPERAND_REG;for(b=0;b<c.labels.length;b++)if(a===c.labels[b])return OPERAND_IMM;if(a.startsWith("[")&&a.endsWith("]")){a=a.replace("[","").replace("]","");if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a)))return OPERAND_MEM_IMM;for(var b=0;b<c.labels.length;b++)if(a===
|
|
c.labels[b])return OPERAND_MEM_IMM;if(/^(bp|sp)$/.test(a.toLowerCase().substring(0,2).toLowerCase()))a=a.substring(2);else if(/^(a|b|c|d|x|y)$/.test(a.toLowerCase().substring(0,1).toLowerCase()))a=a.substring(1);else return OPERAND_INVALID;if(""===a.replace(/\s+/g,""))return OPERAND_MEM_REG;a=a.replace(/\s+/g,"");for(b=0;b<c.labels.length;b++)if(a.substring(1)===c.labels[b])return OPERAND_MEM_REG;if(!isNaN(Number(a))&&Number(a)===Math.floor(Number(a)))return OPERAND_MEM_REG}return OPERAND_INVALID}
|
|
function parseInstruction(a,c,b){a=removeComment(a);a=removeLabel(a);var d=getTokens(a),e=d[0];if(void 0!==e&&""!==e&&!parseDWInstruction(a,c,b))if(/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|hwi|hwq|nop|neg|call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno|inc|dec)\b/.test(e.toLowerCase()))if(-1!==a.indexOf(","))if(d=a.substring(a.indexOf(e)+e.length,a.indexOf(",")),a=a.substring(a.indexOf(",")+1).trim(),/\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar)\b/.test(e.toLowerCase())){e=
|
|
getOperandType(d,c);var f=getOperandType(a,c);e===OPERAND_INVALID?c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):f===OPERAND_INVALID?c.annotations.push({row:b,column:0,text:"Invalid operand: "+a,type:"error"}):e===OPERAND_IMM&&c.annotations.push({row:b,column:0,text:"Destination operand can't be an immediate value",type:"error"})}else c.annotations.push({row:b,column:0,text:e+" instruction with 2 operands is illegal",type:"error"});else 1<d.length?(d=a.substring(a.indexOf(e)+
|
|
e.length).trim(),/\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno|inc|dec)\b/.test(e.toLowerCase())?getOperandType(d,c)===OPERAND_INVALID&&c.annotations.push({row:b,column:0,text:"Invalid operand: "+d,type:"error"}):c.annotations.push({row:b,column:0,text:e+" instruction with 1 operand is illegal",type:"error"})):/\b(?:ret|brk|nop)\b/.test(e.toLowerCase())||c.annotations.push({row:b,column:0,text:e+" instruction with no operand is illegal",type:"error"});
|
|
else c.annotations.push({row:b,column:0,text:"Unknown mnemonic: "+e,type:"error"})}function parse(){for(var a=ace.edit("editor").getValue().split("\n"),c={labels:[],annotations:[]},b=0;b<a.length;b++)checkForLabel(a[b],c);for(b=0;b<a.length;b++)checkForSegmentDeclaration(a[b])||checkForEQUInstruction(a[b],c,b)||checkForORGInstruction(a[b],c,b)||parseInstruction(a[b],c,b);editor.getSession().setAnnotations(c.annotations)}
|
|
function gameClick(){document.getElementById("editorBtns").setAttribute("style","display: none");document.getElementById("gameBtns").setAttribute("style","")}function editorClick(){document.getElementById("editorBtns").setAttribute("style","");document.getElementById("gameBtns").setAttribute("style","display: none")}var editorStorage;editorStorage="undefined"!==typeof window.localStorage?window.localStorage:!1;
|
|
var editorThemeOptions={available:"theme/ambiance theme/chaos theme/chrome theme/clouds theme/clouds_midnight theme/cobalt theme/crimson_editor theme/dawn theme/dracula theme/dreamweaver theme/eclipse theme/github theme/gob theme/gruvbox theme/idle_fingers theme/iplastic theme/katzenmilch theme/kr_theme theme/kuroir theme/merbivore theme/merbivore_soft theme/mono_industrial theme/monokai theme/pastel_on_dark theme/solarized_dark theme/solarized_light theme/sqlserver theme/terminal theme/textmate theme/tomorrow theme/tomorrow_night_blue theme/tomorrow_night_bright theme/tomorrow_night_eighties theme/tomorrow_night theme/twilight theme/vibrant_ink theme/xcode".split(" "),defaultTheme:"theme/tomorrow"};
|
|
if(editorStorage){var storedTheme=editorStorage.getItem("editorTheme");null!==storedTheme&&-1!==editorThemeOptions.available.indexOf(storedTheme)&&(editorThemeOptions.defaultTheme=storedTheme)}var editorThemeSelectElement=document.getElementById("editorTheme");
|
|
function editorOnThemeChange(){if(null===editorThemeSelectElement)console.error("editorOnThemeChange() :: editorThemeSelectElement seems to be 'null'");else{var a=editorThemeSelectElement;a=a.options[a.selectedIndex];-1===editorThemeOptions.available.indexOf(a.value)?console.error("editorOnThemeChange() :: user somehow selected an invalid theme : '"+a.value+"' for '"+a.text+"'"):(editorStorage&&editorStorage.setItem("editorTheme",a.value),editor.setTheme("ace/"+a.value))}}
|
|
editorThemeSelectElement.addEventListener("change",editorOnThemeChange);editorThemeOptions.available.forEach(function(a){var c=document.createElement("option");c.value=a;c.text=a.substring(6);a===editorThemeOptions.defaultTheme&&(c.selected=!0);editorThemeSelectElement.appendChild(c)});editorOnThemeChange();editor.getSession().setMode("ace/mode/mar");editor.setFontSize(16);editor.setDisplayIndentGuides(!1);document.getElementById("editor").style.fontFamily="fixedsys";editor.on("change",parse);
|