mirror of
https://github.com/MutableLoss/6502SimDesktop.git
synced 2024-12-28 03:29:25 +00:00
code cleanup
This commit is contained in:
parent
824cd8c56b
commit
e4f1f9f03f
264
app/assembler.js
264
app/assembler.js
@ -33,7 +33,7 @@ function SimulatorWidget(node) {
|
||||
$node.find('.runButton').click(simulator.runBinary);
|
||||
$node.find('.runButton').click(simulator.stopDebugger);
|
||||
$node.find('.resetButton').click(simulator.reset);
|
||||
$node.find('.hexdumpButton').click(assembler.hexdump);
|
||||
$node.find('.hexdumpButton').click(assembler.hexdump).trigger('keydown', {which: 65});
|
||||
$node.find('.disassembleButton').click(assembler.disassemble);
|
||||
$node.find('.debug').on('click', function () {
|
||||
$(this).toggleClass('active');
|
||||
@ -180,7 +180,7 @@ function SimulatorWidget(node) {
|
||||
caretEnd = this.selectionEnd,
|
||||
currentValue = this.value;
|
||||
|
||||
this.value = currentValue.substring(0, caretStart) + "\t" + currentValue.substring(caretEnd);
|
||||
this.value = currentValue.substring(0, caretStart) + '\t' + currentValue.substring(caretEnd);
|
||||
|
||||
// Move cursor forwards one (after tab)
|
||||
this.selectionStart = this.selectionEnd = caretStart + 1;
|
||||
@ -204,10 +204,10 @@ function SimulatorWidget(node) {
|
||||
function Display() {
|
||||
var displayArray = [];
|
||||
var palette = [
|
||||
"#000000", "#ffffff", "#880000", "#aaffee",
|
||||
"#cc44cc", "#00cc55", "#0000aa", "#eeee77",
|
||||
"#dd8855", "#664400", "#ff7777", "#333333",
|
||||
"#777777", "#aaff66", "#0088ff", "#bbbbbb"
|
||||
'#000000', '#ffffff', '#880000', '#aaffee',
|
||||
'#cc44cc', '#00cc55', '#0000aa', '#eeee77',
|
||||
'#dd8855', '#664400', '#ff7777', '#333333',
|
||||
'#777777', '#aaff66', '#0088ff', '#bbbbbb'
|
||||
];
|
||||
var ctx;
|
||||
var width;
|
||||
@ -226,7 +226,7 @@ function SimulatorWidget(node) {
|
||||
}
|
||||
|
||||
function reset() {
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
@ -279,14 +279,14 @@ function SimulatorWidget(node) {
|
||||
|
||||
for (var x = 0; x < length; x++) {
|
||||
if ((x & 15) === 0) {
|
||||
if (x > 0) { html += "\n"; }
|
||||
if (x > 0) { html += '\n'; }
|
||||
n = (start + x);
|
||||
html += num2hex(((n >> 8) & 0xff));
|
||||
html += num2hex((n & 0xff));
|
||||
html += ": ";
|
||||
html += ': ';
|
||||
}
|
||||
html += num2hex(memory.get(start + x));
|
||||
html += " ";
|
||||
html += ' ';
|
||||
}
|
||||
return html;
|
||||
}
|
||||
@ -871,7 +871,7 @@ function SimulatorWidget(node) {
|
||||
|
||||
i58: function () {
|
||||
regP &= ~0x04;
|
||||
throw new Error("Interrupts not implemented");
|
||||
throw new Error('Interrupts not implemented');
|
||||
//CLI
|
||||
},
|
||||
|
||||
@ -1006,7 +1006,7 @@ function SimulatorWidget(node) {
|
||||
|
||||
i78: function () {
|
||||
regP |= 0x04;
|
||||
throw new Error("Interrupts not implemented");
|
||||
throw new Error('Interrupts not implemented');
|
||||
//SEI
|
||||
},
|
||||
|
||||
@ -1499,7 +1499,7 @@ function SimulatorWidget(node) {
|
||||
},
|
||||
|
||||
ierr: function () {
|
||||
message("Address $" + addr2hex(regPC) + " - unknown opcode");
|
||||
message('Address $' + addr2hex(regPC) + ' - unknown opcode');
|
||||
codeRunning = false;
|
||||
}
|
||||
};
|
||||
@ -1509,7 +1509,7 @@ function SimulatorWidget(node) {
|
||||
regSP--;
|
||||
if (regSP < 0) {
|
||||
regSP &= 0xff;
|
||||
message("6502 Stack filled! Wrapping...");
|
||||
message('6502 Stack filled! Wrapping...');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1518,7 +1518,7 @@ function SimulatorWidget(node) {
|
||||
regSP++;
|
||||
if (regSP >= 0x100) {
|
||||
regSP &= 0xff;
|
||||
message("6502 Stack emptied! Wrapping...");
|
||||
message('6502 Stack emptied! Wrapping...');
|
||||
}
|
||||
value = memory.get(regSP + 0x100);
|
||||
return value;
|
||||
@ -1582,7 +1582,7 @@ function SimulatorWidget(node) {
|
||||
|
||||
if ((regPC === 0) || (!codeRunning && !debugging)) {
|
||||
stop();
|
||||
message("Program end at PC=$" + addr2hex(regPC - 1));
|
||||
message('Program end at PC=$' + addr2hex(regPC - 1));
|
||||
ui.stop();
|
||||
}
|
||||
}
|
||||
@ -1638,8 +1638,8 @@ function SimulatorWidget(node) {
|
||||
}
|
||||
|
||||
function updateDebugInfo() {
|
||||
var html = "A=$" + num2hex(regA) + " X=$" + num2hex(regX) + " Y=$" + num2hex(regY) +
|
||||
" SP=$" + num2hex(regSP) + " PC=$" + addr2hex(regPC) + " NV-BDIZC: ";
|
||||
var html = 'A=$' + num2hex(regA) + ' X=$' + num2hex(regX) + ' Y=$' + num2hex(regY) +
|
||||
' SP=$' + num2hex(regSP) + ' PC=$' + addr2hex(regPC) + ' NV-BDIZC: ';
|
||||
for (var i = 7; i >= 0; i--) {
|
||||
html += regP >> i & 1;
|
||||
}
|
||||
@ -1649,21 +1649,21 @@ function SimulatorWidget(node) {
|
||||
|
||||
// gotoAddr() - Set PC to address (or address of label)
|
||||
function gotoAddr() {
|
||||
var inp = prompt("Enter address or label", "");
|
||||
var inp = prompt('Enter address or label', '');
|
||||
var addr = 0;
|
||||
if (labels.find(inp)) {
|
||||
addr = labels.getPC(inp);
|
||||
} else {
|
||||
if (inp.match(/^0x[0-9a-f]{1,4}$/i)) {
|
||||
inp = inp.replace(/^0x/, "");
|
||||
inp = inp.replace(/^0x/, '');
|
||||
addr = parseInt(inp, 16);
|
||||
} else if (inp.match(/^\$[0-9a-f]{1,4}$/i)) {
|
||||
inp = inp.replace(/^\$/, "");
|
||||
inp = inp.replace(/^\$/, '');
|
||||
addr = parseInt(inp, 16);
|
||||
}
|
||||
}
|
||||
if (addr === 0) {
|
||||
message("Unable to find/parse given address/label");
|
||||
message('Unable to find/parse given address/label');
|
||||
} else {
|
||||
regPC = addr;
|
||||
}
|
||||
@ -1698,7 +1698,7 @@ function SimulatorWidget(node) {
|
||||
function stop() {
|
||||
codeRunning = false;
|
||||
clearInterval(executeId);
|
||||
message("\nStopped\n");
|
||||
message('\nStopped\n');
|
||||
}
|
||||
|
||||
function toggleMonitor() {
|
||||
@ -1725,7 +1725,7 @@ function SimulatorWidget(node) {
|
||||
function indexLines(lines, symbols) {
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
if (!indexLine(lines[i], symbols)) {
|
||||
message("**Label already defined at line " + (i + 1) + ":** " + lines[i]);
|
||||
message('**Label already defined at line ' + (i + 1) + ':** ' + lines[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1742,14 +1742,14 @@ function SimulatorWidget(node) {
|
||||
|
||||
// Find command or label
|
||||
if (input.match(/^\w+:/)) {
|
||||
var label = input.replace(/(^\w+):.*$/, "$1");
|
||||
var label = input.replace(/(^\w+):.*$/, '$1');
|
||||
|
||||
if (symbols.lookup(label)) {
|
||||
message("**Label " + label + "is already used as a symbol; please rename one of them**");
|
||||
message('**Label ' + label + 'is already used as a symbol; please rename one of them**');
|
||||
return false;
|
||||
}
|
||||
|
||||
return push(label + "|" + currentPC);
|
||||
return push(label + '|' + currentPC);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1759,7 +1759,7 @@ function SimulatorWidget(node) {
|
||||
if (find(name)) {
|
||||
return false;
|
||||
}
|
||||
labelIndex.push(name + "|");
|
||||
labelIndex.push(name + '|');
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1767,7 +1767,7 @@ function SimulatorWidget(node) {
|
||||
function find(name) {
|
||||
var nameAndAddr;
|
||||
for (var i = 0; i < labelIndex.length; i++) {
|
||||
nameAndAddr = labelIndex[i].split("|");
|
||||
nameAndAddr = labelIndex[i].split('|');
|
||||
if (name === nameAndAddr[0]) {
|
||||
return true;
|
||||
}
|
||||
@ -1779,9 +1779,9 @@ function SimulatorWidget(node) {
|
||||
function setPC(name, addr) {
|
||||
var nameAndAddr;
|
||||
for (var i = 0; i < labelIndex.length; i++) {
|
||||
nameAndAddr = labelIndex[i].split("|");
|
||||
nameAndAddr = labelIndex[i].split('|');
|
||||
if (name === nameAndAddr[0]) {
|
||||
labelIndex[i] = name + "|" + addr;
|
||||
labelIndex[i] = name + '|' + addr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1792,7 +1792,7 @@ function SimulatorWidget(node) {
|
||||
function getPC(name) {
|
||||
var nameAndAddr;
|
||||
for (var i = 0; i < labelIndex.length; i++) {
|
||||
nameAndAddr = labelIndex[i].split("|");
|
||||
nameAndAddr = labelIndex[i].split('|');
|
||||
if (name === nameAndAddr[0]) {
|
||||
return (nameAndAddr[1]);
|
||||
}
|
||||
@ -1801,11 +1801,11 @@ function SimulatorWidget(node) {
|
||||
}
|
||||
|
||||
function displayMessage() {
|
||||
var str = "Found " + labelIndex.length + " label";
|
||||
var str = 'Found ' + labelIndex.length + ' label';
|
||||
if (labelIndex.length !== 1) {
|
||||
str += "s";
|
||||
str += 's';
|
||||
}
|
||||
message(str + ".");
|
||||
message(str + '.');
|
||||
}
|
||||
|
||||
function reset() {
|
||||
@ -1830,64 +1830,64 @@ function SimulatorWidget(node) {
|
||||
|
||||
var Opcodes = [
|
||||
/* Name, Imm, ZP, ZPX, ZPY, ABS, ABSX, ABSY, IND, INDX, INDY, SNGL, BRA */
|
||||
["ADC", 0x69, 0x65, 0x75, null, 0x6d, 0x7d, 0x79, null, 0x61, 0x71, null, null],
|
||||
["AND", 0x29, 0x25, 0x35, null, 0x2d, 0x3d, 0x39, null, 0x21, 0x31, null, null],
|
||||
["ASL", null, 0x06, 0x16, null, 0x0e, 0x1e, null, null, null, null, 0x0a, null],
|
||||
["BIT", null, 0x24, null, null, 0x2c, null, null, null, null, null, null, null],
|
||||
["BPL", null, null, null, null, null, null, null, null, null, null, null, 0x10],
|
||||
["BMI", null, null, null, null, null, null, null, null, null, null, null, 0x30],
|
||||
["BVC", null, null, null, null, null, null, null, null, null, null, null, 0x50],
|
||||
["BVS", null, null, null, null, null, null, null, null, null, null, null, 0x70],
|
||||
["BCC", null, null, null, null, null, null, null, null, null, null, null, 0x90],
|
||||
["BCS", null, null, null, null, null, null, null, null, null, null, null, 0xb0],
|
||||
["BNE", null, null, null, null, null, null, null, null, null, null, null, 0xd0],
|
||||
["BEQ", null, null, null, null, null, null, null, null, null, null, null, 0xf0],
|
||||
["BRK", null, null, null, null, null, null, null, null, null, null, 0x00, null],
|
||||
["CMP", 0xc9, 0xc5, 0xd5, null, 0xcd, 0xdd, 0xd9, null, 0xc1, 0xd1, null, null],
|
||||
["CPX", 0xe0, 0xe4, null, null, 0xec, null, null, null, null, null, null, null],
|
||||
["CPY", 0xc0, 0xc4, null, null, 0xcc, null, null, null, null, null, null, null],
|
||||
["DEC", null, 0xc6, 0xd6, null, 0xce, 0xde, null, null, null, null, null, null],
|
||||
["EOR", 0x49, 0x45, 0x55, null, 0x4d, 0x5d, 0x59, null, 0x41, 0x51, null, null],
|
||||
["CLC", null, null, null, null, null, null, null, null, null, null, 0x18, null],
|
||||
["SEC", null, null, null, null, null, null, null, null, null, null, 0x38, null],
|
||||
["CLI", null, null, null, null, null, null, null, null, null, null, 0x58, null],
|
||||
["SEI", null, null, null, null, null, null, null, null, null, null, 0x78, null],
|
||||
["CLV", null, null, null, null, null, null, null, null, null, null, 0xb8, null],
|
||||
["CLD", null, null, null, null, null, null, null, null, null, null, 0xd8, null],
|
||||
["SED", null, null, null, null, null, null, null, null, null, null, 0xf8, null],
|
||||
["INC", null, 0xe6, 0xf6, null, 0xee, 0xfe, null, null, null, null, null, null],
|
||||
["JMP", null, null, null, null, 0x4c, null, null, 0x6c, null, null, null, null],
|
||||
["JSR", null, null, null, null, 0x20, null, null, null, null, null, null, null],
|
||||
["LDA", 0xa9, 0xa5, 0xb5, null, 0xad, 0xbd, 0xb9, null, 0xa1, 0xb1, null, null],
|
||||
["LDX", 0xa2, 0xa6, null, 0xb6, 0xae, null, 0xbe, null, null, null, null, null],
|
||||
["LDY", 0xa0, 0xa4, 0xb4, null, 0xac, 0xbc, null, null, null, null, null, null],
|
||||
["LSR", null, 0x46, 0x56, null, 0x4e, 0x5e, null, null, null, null, 0x4a, null],
|
||||
["NOP", null, null, null, null, null, null, null, null, null, null, 0xea, null],
|
||||
["ORA", 0x09, 0x05, 0x15, null, 0x0d, 0x1d, 0x19, null, 0x01, 0x11, null, null],
|
||||
["TAX", null, null, null, null, null, null, null, null, null, null, 0xaa, null],
|
||||
["TXA", null, null, null, null, null, null, null, null, null, null, 0x8a, null],
|
||||
["DEX", null, null, null, null, null, null, null, null, null, null, 0xca, null],
|
||||
["INX", null, null, null, null, null, null, null, null, null, null, 0xe8, null],
|
||||
["TAY", null, null, null, null, null, null, null, null, null, null, 0xa8, null],
|
||||
["TYA", null, null, null, null, null, null, null, null, null, null, 0x98, null],
|
||||
["DEY", null, null, null, null, null, null, null, null, null, null, 0x88, null],
|
||||
["INY", null, null, null, null, null, null, null, null, null, null, 0xc8, null],
|
||||
["ROR", null, 0x66, 0x76, null, 0x6e, 0x7e, null, null, null, null, 0x6a, null],
|
||||
["ROL", null, 0x26, 0x36, null, 0x2e, 0x3e, null, null, null, null, 0x2a, null],
|
||||
["RTI", null, null, null, null, null, null, null, null, null, null, 0x40, null],
|
||||
["RTS", null, null, null, null, null, null, null, null, null, null, 0x60, null],
|
||||
["SBC", 0xe9, 0xe5, 0xf5, null, 0xed, 0xfd, 0xf9, null, 0xe1, 0xf1, null, null],
|
||||
["STA", null, 0x85, 0x95, null, 0x8d, 0x9d, 0x99, null, 0x81, 0x91, null, null],
|
||||
["TXS", null, null, null, null, null, null, null, null, null, null, 0x9a, null],
|
||||
["TSX", null, null, null, null, null, null, null, null, null, null, 0xba, null],
|
||||
["PHA", null, null, null, null, null, null, null, null, null, null, 0x48, null],
|
||||
["PLA", null, null, null, null, null, null, null, null, null, null, 0x68, null],
|
||||
["PHP", null, null, null, null, null, null, null, null, null, null, 0x08, null],
|
||||
["PLP", null, null, null, null, null, null, null, null, null, null, 0x28, null],
|
||||
["STX", null, 0x86, null, 0x96, 0x8e, null, null, null, null, null, null, null],
|
||||
["STY", null, 0x84, 0x94, null, 0x8c, null, null, null, null, null, null, null],
|
||||
["WDM", 0x42, 0x42, null, null, null, null, null, null, null, null, null, null],
|
||||
["---", null, null, null, null, null, null, null, null, null, null, null, null]
|
||||
['ADC', 0x69, 0x65, 0x75, null, 0x6d, 0x7d, 0x79, null, 0x61, 0x71, null, null],
|
||||
['AND', 0x29, 0x25, 0x35, null, 0x2d, 0x3d, 0x39, null, 0x21, 0x31, null, null],
|
||||
['ASL', null, 0x06, 0x16, null, 0x0e, 0x1e, null, null, null, null, 0x0a, null],
|
||||
['BIT', null, 0x24, null, null, 0x2c, null, null, null, null, null, null, null],
|
||||
['BPL', null, null, null, null, null, null, null, null, null, null, null, 0x10],
|
||||
['BMI', null, null, null, null, null, null, null, null, null, null, null, 0x30],
|
||||
['BVC', null, null, null, null, null, null, null, null, null, null, null, 0x50],
|
||||
['BVS', null, null, null, null, null, null, null, null, null, null, null, 0x70],
|
||||
['BCC', null, null, null, null, null, null, null, null, null, null, null, 0x90],
|
||||
['BCS', null, null, null, null, null, null, null, null, null, null, null, 0xb0],
|
||||
['BNE', null, null, null, null, null, null, null, null, null, null, null, 0xd0],
|
||||
['BEQ', null, null, null, null, null, null, null, null, null, null, null, 0xf0],
|
||||
['BRK', null, null, null, null, null, null, null, null, null, null, 0x00, null],
|
||||
['CMP', 0xc9, 0xc5, 0xd5, null, 0xcd, 0xdd, 0xd9, null, 0xc1, 0xd1, null, null],
|
||||
['CPX', 0xe0, 0xe4, null, null, 0xec, null, null, null, null, null, null, null],
|
||||
['CPY', 0xc0, 0xc4, null, null, 0xcc, null, null, null, null, null, null, null],
|
||||
['DEC', null, 0xc6, 0xd6, null, 0xce, 0xde, null, null, null, null, null, null],
|
||||
['EOR', 0x49, 0x45, 0x55, null, 0x4d, 0x5d, 0x59, null, 0x41, 0x51, null, null],
|
||||
['CLC', null, null, null, null, null, null, null, null, null, null, 0x18, null],
|
||||
['SEC', null, null, null, null, null, null, null, null, null, null, 0x38, null],
|
||||
['CLI', null, null, null, null, null, null, null, null, null, null, 0x58, null],
|
||||
['SEI', null, null, null, null, null, null, null, null, null, null, 0x78, null],
|
||||
['CLV', null, null, null, null, null, null, null, null, null, null, 0xb8, null],
|
||||
['CLD', null, null, null, null, null, null, null, null, null, null, 0xd8, null],
|
||||
['SED', null, null, null, null, null, null, null, null, null, null, 0xf8, null],
|
||||
['INC', null, 0xe6, 0xf6, null, 0xee, 0xfe, null, null, null, null, null, null],
|
||||
['JMP', null, null, null, null, 0x4c, null, null, 0x6c, null, null, null, null],
|
||||
['JSR', null, null, null, null, 0x20, null, null, null, null, null, null, null],
|
||||
['LDA', 0xa9, 0xa5, 0xb5, null, 0xad, 0xbd, 0xb9, null, 0xa1, 0xb1, null, null],
|
||||
['LDX', 0xa2, 0xa6, null, 0xb6, 0xae, null, 0xbe, null, null, null, null, null],
|
||||
['LDY', 0xa0, 0xa4, 0xb4, null, 0xac, 0xbc, null, null, null, null, null, null],
|
||||
['LSR', null, 0x46, 0x56, null, 0x4e, 0x5e, null, null, null, null, 0x4a, null],
|
||||
['NOP', null, null, null, null, null, null, null, null, null, null, 0xea, null],
|
||||
['ORA', 0x09, 0x05, 0x15, null, 0x0d, 0x1d, 0x19, null, 0x01, 0x11, null, null],
|
||||
['TAX', null, null, null, null, null, null, null, null, null, null, 0xaa, null],
|
||||
['TXA', null, null, null, null, null, null, null, null, null, null, 0x8a, null],
|
||||
['DEX', null, null, null, null, null, null, null, null, null, null, 0xca, null],
|
||||
['INX', null, null, null, null, null, null, null, null, null, null, 0xe8, null],
|
||||
['TAY', null, null, null, null, null, null, null, null, null, null, 0xa8, null],
|
||||
['TYA', null, null, null, null, null, null, null, null, null, null, 0x98, null],
|
||||
['DEY', null, null, null, null, null, null, null, null, null, null, 0x88, null],
|
||||
['INY', null, null, null, null, null, null, null, null, null, null, 0xc8, null],
|
||||
['ROR', null, 0x66, 0x76, null, 0x6e, 0x7e, null, null, null, null, 0x6a, null],
|
||||
['ROL', null, 0x26, 0x36, null, 0x2e, 0x3e, null, null, null, null, 0x2a, null],
|
||||
['RTI', null, null, null, null, null, null, null, null, null, null, 0x40, null],
|
||||
['RTS', null, null, null, null, null, null, null, null, null, null, 0x60, null],
|
||||
['SBC', 0xe9, 0xe5, 0xf5, null, 0xed, 0xfd, 0xf9, null, 0xe1, 0xf1, null, null],
|
||||
['STA', null, 0x85, 0x95, null, 0x8d, 0x9d, 0x99, null, 0x81, 0x91, null, null],
|
||||
['TXS', null, null, null, null, null, null, null, null, null, null, 0x9a, null],
|
||||
['TSX', null, null, null, null, null, null, null, null, null, null, 0xba, null],
|
||||
['PHA', null, null, null, null, null, null, null, null, null, null, 0x48, null],
|
||||
['PLA', null, null, null, null, null, null, null, null, null, null, 0x68, null],
|
||||
['PHP', null, null, null, null, null, null, null, null, null, null, 0x08, null],
|
||||
['PLP', null, null, null, null, null, null, null, null, null, null, 0x28, null],
|
||||
['STX', null, 0x86, null, 0x96, 0x8e, null, null, null, null, null, null, null],
|
||||
['STY', null, 0x84, 0x94, null, 0x8c, null, null, null, null, null, null, null],
|
||||
['WDM', 0x42, 0x42, null, null, null, null, null, null, null, null, null, null],
|
||||
['---', null, null, null, null, null, null, null, null, null, null, null, null]
|
||||
];
|
||||
|
||||
// Assembles the code into memory
|
||||
@ -1902,14 +1902,14 @@ function SimulatorWidget(node) {
|
||||
$node.find('.messages code').empty();
|
||||
|
||||
var code = $node.find('.code').val();
|
||||
code += "\n\n";
|
||||
var lines = code.split("\n");
|
||||
code += '\n\n';
|
||||
var lines = code.split('\n');
|
||||
codeAssembledOK = true;
|
||||
|
||||
message("Preprocessing ...");
|
||||
message('Preprocessing ...');
|
||||
var symbols = preprocess(lines);
|
||||
|
||||
message("Indexing labels ...");
|
||||
message('Indexing labels ...');
|
||||
defaultCodePC = BOOTSTRAP_ADDRESS;
|
||||
if (!labels.indexLines(lines, symbols)) {
|
||||
return false;
|
||||
@ -1917,7 +1917,7 @@ function SimulatorWidget(node) {
|
||||
labels.displayMessage();
|
||||
|
||||
defaultCodePC = BOOTSTRAP_ADDRESS;
|
||||
message("Assembling code ...");
|
||||
message('Assembling code ...');
|
||||
|
||||
codeLen = 0;
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
@ -1929,7 +1929,7 @@ function SimulatorWidget(node) {
|
||||
|
||||
if (codeLen === 0) {
|
||||
codeAssembledOK = false;
|
||||
message("No code to run.");
|
||||
message('No code to run.');
|
||||
}
|
||||
|
||||
if (codeAssembledOK) {
|
||||
@ -1937,10 +1937,10 @@ function SimulatorWidget(node) {
|
||||
memory.set(defaultCodePC, 0x00); //set a null byte at the end of the code
|
||||
} else {
|
||||
|
||||
var str = lines[i].replace("<", "<").replace(">", ">");
|
||||
var str = lines[i].replace('<', '<').replace('>', '>');
|
||||
|
||||
if(!wasOutOfRangeBranch) {
|
||||
message("**Syntax error line " + (i + 1) + ": " + str + "**");
|
||||
message('**Syntax error line ' + (i + 1) + ': ' + str + '**');
|
||||
} else {
|
||||
message('**Out of range branch on line ' + (i + 1) + ' (branches are limited to -128 to +127): ' + str + '**');
|
||||
}
|
||||
@ -1949,22 +1949,22 @@ function SimulatorWidget(node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
message("Code assembled successfully, " + codeLen + " bytes.");
|
||||
message('Code assembled successfully, ' + codeLen + ' bytes.');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sanitize input: remove comments and trim leading/trailing whitespace
|
||||
function sanitize(line) {
|
||||
// remove comments
|
||||
var no_comments = line.replace(/^(.*?);.*/, "$1");
|
||||
var no_comments = line.replace(/^(.*?);.*/, '$1');
|
||||
|
||||
// trim line
|
||||
return no_comments.replace(/^\s+/, "").replace(/\s+$/, "");
|
||||
return no_comments.replace(/^\s+/, '').replace(/\s+$/, '');
|
||||
}
|
||||
|
||||
function preprocess(lines) {
|
||||
var table = [];
|
||||
var PREFIX = "__"; // Using a prefix avoids clobbering any predefined properties
|
||||
var PREFIX = '__'; // Using a prefix avoids clobbering any predefined properties
|
||||
|
||||
function lookup(key) {
|
||||
if (table.hasOwnProperty(PREFIX + key)) return table[PREFIX + key];
|
||||
@ -1984,7 +1984,7 @@ function SimulatorWidget(node) {
|
||||
var match_data = lines[i].match(/^define\s+(\w+)\s+(\S+)/);
|
||||
if (match_data) {
|
||||
add(match_data[1], sanitize(match_data[2]));
|
||||
lines[i] = ""; // We're done with this preprocessor directive, so delete it
|
||||
lines[i] = ''; // We're done with this preprocessor directive, so delete it
|
||||
}
|
||||
}
|
||||
|
||||
@ -2001,19 +2001,19 @@ function SimulatorWidget(node) {
|
||||
|
||||
// Find command or label
|
||||
if (input.match(/^\w+:/)) {
|
||||
label = input.replace(/(^\w+):.*$/, "$1");
|
||||
label = input.replace(/(^\w+):.*$/, '$1');
|
||||
if (input.match(/^\w+:[\s]*\w+.*$/)) {
|
||||
input = input.replace(/^\w+:[\s]*(.*)$/, "$1");
|
||||
command = input.replace(/^(\w+).*$/, "$1");
|
||||
input = input.replace(/^\w+:[\s]*(.*)$/, '$1');
|
||||
command = input.replace(/^(\w+).*$/, '$1');
|
||||
} else {
|
||||
command = "";
|
||||
command = '';
|
||||
}
|
||||
} else {
|
||||
command = input.replace(/^(\w+).*$/, "$1");
|
||||
command = input.replace(/^(\w+).*$/, '$1');
|
||||
}
|
||||
|
||||
// Nothing to do for blank lines
|
||||
if (command === "") {
|
||||
if (command === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2021,15 +2021,15 @@ function SimulatorWidget(node) {
|
||||
|
||||
if (input.match(/^\*\s*=\s*\$?[0-9a-f]*$/)) {
|
||||
// equ spotted
|
||||
param = input.replace(/^\s*\*\s*=\s*/, "");
|
||||
if (param[0] === "$") {
|
||||
param = param.replace(/^\$/, "");
|
||||
param = input.replace(/^\s*\*\s*=\s*/, '');
|
||||
if (param[0] === '$') {
|
||||
param = param.replace(/^\$/, '');
|
||||
addr = parseInt(param, 16);
|
||||
} else {
|
||||
addr = parseInt(param, 10);
|
||||
}
|
||||
if ((addr < 0) || (addr > 0xffff)) {
|
||||
message("Unable to relocate code outside 64k memory");
|
||||
message('Unable to relocate code outside 64k memory');
|
||||
return false;
|
||||
}
|
||||
defaultCodePC = addr;
|
||||
@ -2037,16 +2037,16 @@ function SimulatorWidget(node) {
|
||||
}
|
||||
|
||||
if (input.match(/^\w+\s+.*?$/)) {
|
||||
param = input.replace(/^\w+\s+(.*?)/, "$1");
|
||||
param = input.replace(/^\w+\s+(.*?)/, '$1');
|
||||
} else if (input.match(/^\w+$/)) {
|
||||
param = "";
|
||||
param = '';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
param = param.replace(/[ ]/g, "");
|
||||
param = param.replace(/[ ]/g, '');
|
||||
|
||||
if (command === "DCB") {
|
||||
if (command === 'DCB') {
|
||||
return DCB(param);
|
||||
}
|
||||
for (var o = 0; o < Opcodes.length; o++) {
|
||||
@ -2071,16 +2071,16 @@ function SimulatorWidget(node) {
|
||||
|
||||
function DCB(param) {
|
||||
var values, number, str, ch;
|
||||
values = param.split(",");
|
||||
values = param.split(',');
|
||||
if (values.length === 0) { return false; }
|
||||
for (var v = 0; v < values.length; v++) {
|
||||
str = values[v];
|
||||
if (str) {
|
||||
ch = str.substring(0, 1);
|
||||
if (ch === "$") {
|
||||
number = parseInt(str.replace(/^\$/, ""), 16);
|
||||
if (ch === '$') {
|
||||
number = parseInt(str.replace(/^\$/, ''), 16);
|
||||
pushByte(number);
|
||||
} else if (ch >= "0" && ch <= "9") {
|
||||
} else if (ch >= '0' && ch <= '9') {
|
||||
number = parseInt(str, 10);
|
||||
pushByte(number);
|
||||
} else {
|
||||
@ -2195,16 +2195,16 @@ function SimulatorWidget(node) {
|
||||
|
||||
// Label lo/hi
|
||||
if (param.match(/^#[<>]\w+$/)) {
|
||||
label = param.replace(/^#[<>](\w+)$/, "$1");
|
||||
hilo = param.replace(/^#([<>]).*$/, "$1");
|
||||
label = param.replace(/^#[<>](\w+)$/, '$1');
|
||||
hilo = param.replace(/^#([<>]).*$/, '$1');
|
||||
pushByte(opcode);
|
||||
if (labels.find(label)) {
|
||||
addr = labels.getPC(label);
|
||||
switch(hilo) {
|
||||
case ">":
|
||||
case '>':
|
||||
pushByte((addr >> 8) & 0xff);
|
||||
return true;
|
||||
case "<":
|
||||
case '<':
|
||||
pushByte(addr & 0xff);
|
||||
return true;
|
||||
default:
|
||||
@ -2274,7 +2274,7 @@ function SimulatorWidget(node) {
|
||||
function checkSingle(param, opcode) {
|
||||
if (opcode === null) { return false; }
|
||||
// Accumulator instructions are counted as single-byte opcodes
|
||||
if (param !== "" && param !== "A") { return false; }
|
||||
if (param !== '' && param !== 'A') { return false; }
|
||||
pushByte(opcode);
|
||||
return true;
|
||||
}
|
||||
@ -2311,7 +2311,7 @@ function SimulatorWidget(node) {
|
||||
|
||||
// it could be a label too..
|
||||
if (param.match(/^\w+,X$/i)) {
|
||||
param = param.replace(/,X$/i, "");
|
||||
param = param.replace(/,X$/i, '');
|
||||
pushByte(opcode);
|
||||
if (labels.find(param)) {
|
||||
addr = labels.getPC(param);
|
||||
@ -2344,7 +2344,7 @@ function SimulatorWidget(node) {
|
||||
|
||||
// it could be a label too..
|
||||
if (param.match(/^\w+,Y$/i)) {
|
||||
param = param.replace(/,Y$/i, "");
|
||||
param = param.replace(/,Y$/i, '');
|
||||
pushByte(opcode);
|
||||
if (labels.find(param)) {
|
||||
addr = labels.getPC(param);
|
||||
@ -2637,7 +2637,7 @@ function SimulatorWidget(node) {
|
||||
}
|
||||
|
||||
function num2hex(nr) {
|
||||
var str = "0123456789abcdef";
|
||||
var str = '0123456789abcdef';
|
||||
var hi = ((nr & 0xf0) >> 4);
|
||||
var lo = (nr & 15);
|
||||
return str.substring(hi, hi + 1) + str.substring(lo, lo + 1);
|
||||
|
Loading…
Reference in New Issue
Block a user