Skip to content

Commit a2cdb8b

Browse files
committed
Use template strings
1 parent 038f5ad commit a2cdb8b

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/6502.opcodes.js

+26-23
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ function pull(reg) {
3232
if (reg === "p") {
3333
return ["cpu.p.setFromByte(cpu.pull());"];
3434
}
35-
return ["cpu." + reg + " = cpu.p.setzn(cpu.pull());"];
35+
return [`cpu.${reg} = cpu.p.setzn(cpu.pull());`];
3636
}
3737

3838
function push(reg) {
3939
if (reg === "p") return "cpu.push(cpu.p.asByte());";
40-
return "cpu.push(cpu." + reg + ");";
40+
return `cpu.push(cpu.${reg});`;
4141
}
4242

4343
class InstructionGen {
@@ -76,27 +76,27 @@ class InstructionGen {
7676
readOp(addr, reg, spurious) {
7777
this.cycle++;
7878
let op;
79-
if (reg) op = reg + " = cpu.readmem(" + addr + ");";
80-
else op = "cpu.readmem(" + addr + ");";
79+
if (reg) op = `${reg} = cpu.readmem(${addr});`;
80+
else op = `cpu.readmem(${addr});`;
8181
if (spurious) op += " // spurious";
8282
this.append(this.cycle, op, true, addr);
8383
}
8484

8585
writeOp(addr, reg, spurious) {
8686
this.cycle++;
87-
let op = "cpu.writemem(" + addr + ", " + reg + ");";
87+
let op = `cpu.writemem(${addr}, ${reg});`;
8888
if (spurious) op += " // spurious";
8989
this.append(this.cycle, op, true, addr);
9090
}
9191

9292
zpReadOp(addr, reg) {
9393
this.cycle++;
94-
this.append(this.cycle, reg + " = cpu.readmemZpStack(" + addr + ");", false);
94+
this.append(this.cycle, `${reg} = cpu.readmemZpStack(${addr});`, false);
9595
}
9696

9797
zpWriteOp(addr, reg) {
9898
this.cycle++;
99-
this.append(this.cycle, "cpu.writememZpStack(" + addr + ", " + reg + ");", true);
99+
this.append(this.cycle, `cpu.writememZpStack(${addr}, ${reg});`, true);
100100
}
101101

102102
render(startCycle) {
@@ -124,9 +124,9 @@ class InstructionGen {
124124
}
125125
if (toSkip && this.ops[i].exact) {
126126
if (this.ops[i].addr) {
127-
out.push("cpu.polltimeAddr(" + toSkip + ", " + this.ops[i].addr + ");");
127+
out.push(`cpu.polltimeAddr(${toSkip}, ${this.ops[i].addr});`);
128128
} else {
129-
out.push("cpu.polltime(" + toSkip + ");");
129+
out.push(`cpu.polltime(${toSkip});`);
130130
}
131131
toSkip = 0;
132132
}
@@ -135,9 +135,9 @@ class InstructionGen {
135135
}
136136
if (toSkip) {
137137
if (this.ops[this.cycle] && this.ops[this.cycle].addr) {
138-
out.push("cpu.polltimeAddr(" + toSkip + ", " + this.ops[this.cycle].addr + ");");
138+
out.push(`cpu.polltimeAddr(${toSkip}, ${this.ops[this.cycle].addr});`);
139139
} else {
140-
out.push("cpu.polltime(" + toSkip + ");");
140+
out.push(`cpu.polltime(${toSkip});`);
141141
}
142142
}
143143
if (this.ops[this.cycle]) out = out.concat(this.ops[this.cycle].op);
@@ -173,7 +173,7 @@ class SplitInstruction {
173173
render() {
174174
return this.preamble
175175
.renderInternal()
176-
.concat("if (" + this.condition + ") {")
176+
.concat(`if (${this.condition}) {`)
177177
.concat(this.indent(this.ifTrue.render(this.preamble.cycle)))
178178
.concat("} else {")
179179
.concat(this.indent(this.ifFalse.render(this.preamble.cycle)))
@@ -1009,8 +1009,8 @@ class Disassemble6502 {
10091009
const index = param.match(/(.*),([xy])$/);
10101010
if (index) {
10111011
param = index[1];
1012-
suffix = "," + index[2].toUpperCase();
1013-
suffix2 = " + " + index[2].toUpperCase();
1012+
suffix = `,${index[2].toUpperCase()}`;
1013+
suffix2 = ` + ${index[2].toUpperCase()}`;
10141014
}
10151015
switch (param) {
10161016
case "imm":
@@ -1097,7 +1097,7 @@ function makeCpuFunctions(cpu, opcodes, is65c12) {
10971097
ig.append("const addr = cpu.getb() | 0;");
10981098
} else {
10991099
ig.tick(3);
1100-
ig.append("const addr = (cpu.getb() + cpu." + arg[3] + ") & 0xff;");
1100+
ig.append(`const addr = (cpu.getb() + cpu.${arg[3]}) & 0xff;`);
11011101
}
11021102
if (op.read) {
11031103
ig.zpReadOp("addr", "REG");
@@ -1124,7 +1124,7 @@ function makeCpuFunctions(cpu, opcodes, is65c12) {
11241124
case "abs,x":
11251125
case "abs,y":
11261126
ig.append("const addr = cpu.getw() | 0;");
1127-
ig.append("let addrWithCarry = (addr + cpu." + arg[4] + ") & 0xffff;");
1127+
ig.append(`let addrWithCarry = (addr + cpu.${arg[4]}) & 0xffff;`);
11281128
ig.append("const addrNonCarry = (addr & 0xff00) | (addrWithCarry & 0xff);");
11291129
ig.tick(3);
11301130
ig = ig.split("addrWithCarry !== addrNonCarry");
@@ -1289,13 +1289,16 @@ function makeCpuFunctions(cpu, opcodes, is65c12) {
12891289
const opcode = opcodes[opcodeNum];
12901290
return (
12911291
indent +
1292-
['"use strict";', "// " + utils.hexbyte(opcodeNum) + " - " + opcode + "\n"]
1293-
.concat(
1294-
opcode
1295-
? getInstruction(opcode, !!needsReg)
1296-
: ["this.invalidOpcode(cpu, 0x" + utils.hexbyte(opcodeNum) + ");"],
1297-
)
1298-
.join("\n" + indent)
1292+
[
1293+
'"use strict";',
1294+
`// ${utils.hexbyte(opcodeNum)} - ${opcode}
1295+
`,
1296+
].concat(
1297+
opcode
1298+
? getInstruction(opcode, !!needsReg)
1299+
: [`this.invalidOpcode(cpu, 0x${utils.hexbyte(opcodeNum)});`],
1300+
).join(`
1301+
${indent}`)
12991302
);
13001303
}
13011304

0 commit comments

Comments
 (0)