8SA1Sim/js/instruction_doc.js
2021-04-10 01:08:33 -07:00

73 lines
3.4 KiB
JavaScript

let isalist = document.getElementById("isa_list");
let ISAPrepList = new Array();
function hasInstruction(ins) {
for (let a = 0; a < ISAPrepList.length; a++) {
if (ISAPrepList[a].Mnemonic.toLowerCase() === ins.Mnemonic.toLowerCase()) {
return a;
}
}
return false;
}
for (let a = 0; a < Instructions.length; a++) {
if (hasInstruction(Instructions[a]) === false) {
ISAPrepList.push({Mnemonic: Instructions[a].Mnemonic,LongName: Instructions[a].LongName,Varients: new Array(Instructions[a])});
} else {
console.log(`${Instructions[a].Mnemonic} IS ALREADY THERE LETS ADD TO IT`);
ISAPrepList[hasInstruction(Instructions[a])].Varients.push(Instructions[a]);
}
}
let outHTML = "";
ISAPrepList.sort((a, b) => (a.Bytecode > b.Bytecode) ? -1 : 1);
for (let a = 0; a < ISAPrepList.length; a++) {
outHTML += `<div style="width: 60%; background-color: #eee;">`;
outHTML += `<h4>${ISAPrepList[a].Mnemonic}&nbsp;&nbsp;&nbsp;&nbsp;${ISAPrepList[a].LongName} </h4>`;
outHTML += `<table style="width: 100%;">`;
outHTML += `<tr>`;
outHTML += `<td style="border-bottom: 1px solid black;">Address Mode</td><td style="border-bottom: 1px solid black;">Example</td><td style="border-bottom: 1px solid black;">Bytecode</td><td style="border-bottom: 1px solid black;">Words</td><td style="border-bottom: 1px solid black;">Cycles</td>`;
outHTML += `</tr>`;
for (let b=0; b < ISAPrepList[a].Varients.length; b++) {
let operandtext = "";
for (let c = 0; c < ISAPrepList[a].Varients[b].Operands.length; c++) {
let operandresult = ISAPrepList[a].Varients[b].Operands[c].Operand;
let ogor = operandresult;
if (operandresult === "#") operandresult = "";
if (operandresult === "$" || operandresult === "") {
switch (Math.floor(Math.random() * 9)) {
case 0:
case 1:
case 2:
case 3: {
operandresult = ((ogor === "#") ? "" : ogor) + formatHex(Math.floor(Math.random() * (2 ** ISAPrepList[a].Varients[b].Operands[c].Bitwidth)), ((ISAPrepList[a].Varients[b].Operands[c].Bitwidth === 16) ? 4 : 2)) + "h";
break;
}
case 4:
case 5:
case 6:
case 7: {
operandresult = ((ogor === "#") ? "" : ogor) + Math.floor(Math.random() * (2 ** ISAPrepList[a].Varients[b].Operands[c].Bitwidth));
break;
}
case 8: {
operandresult = ((ogor === "#") ? "" : ogor) + "MyVar";
break;
}
}
}
if (ogor === "#") operandresult = "[" + operandresult + "]";
operandtext += ` ${operandresult},`;
}
operandtext = operandtext.substring(0,operandtext.length-1);
outHTML += `<tr>`;
outHTML += `<td>${ISAPrepList[a].Varients[b].Type}</td><td>${ISAPrepList[a].Mnemonic}${operandtext}</td><td>0x${formatHex(ISAPrepList[a].Varients[b].Bytecode,4)}</td><td>${ISAPrepList[a].Varients[b].Words}</td><td>${ISAPrepList[a].Varients[b].Cycles}</td>`;
outHTML += `</tr>`;
}
outHTML += `</table>`;
outHTML += `</div>`;
}
isalist.innerHTML = outHTML;