Skip to content

Commit

Permalink
Merge pull request #23 from robey/rfi
Browse files Browse the repository at this point in the history
update asm/disasm for spec 1.7 ("RFI"), and support single-quoted ascii constants.
  • Loading branch information
Denis Olshin committed May 2, 2012
2 parents e176157 + a0044c3 commit fc66bbf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
26 changes: 18 additions & 8 deletions js/assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var Assembler = {
"int": 0x08,
"iag": 0x09,
"ias": 0x0a,
"iap": 0x0b,
"rfi": 0x0b,
"iaq": 0x0c,
// ...
"hwn": 0x10,
Expand Down Expand Up @@ -111,6 +111,10 @@ var Assembler = {
return false;
}
atom.state.pos = pos + 1;
} else if (text.charAt(pos) == "'" && text.charAt(pos + 2) == "'") {
atom.literal = text.charCodeAt(pos + 1);
atom.state = state;
atom.state.pos = pos + 3;
} else {
var operand = text.substr(pos, end - pos).match(/^[A-Za-z_.0-9]+/);
if (!operand) {
Expand Down Expand Up @@ -315,14 +319,15 @@ var Assembler = {

// strip comments so we don't have to worry about them
var in_string = false;
var in_char = false
for (var i = 0; i < text.length; i++) {
if (in_string && text.charAt(i) == '\\' && i < text.length - 1) {
i++;
} else
if (text.charAt(i) == '"') {
} else if (text.charAt(i) == '"') {
in_string = !in_string;
} else
if (text.charAt(i) == ';' && !in_string) {
} else if (text.charAt(i) == '\'' && !in_string) {
in_char = !in_char;
} else if (text.charAt(i) == ';' && !in_string && !in_char) {
end = i;
break;
}
Expand Down Expand Up @@ -442,22 +447,27 @@ var Assembler = {
var arg_ends = [ -1 ];
var n = 0;
in_string = false;
in_char = false;
for (var i = pos; i < end; i++) {
if (text.charAt(i) == '\\' && i + 1 < end) {
if (arg_locs[n] == -1) arg_locs[n] = i;
args[n] += text.charAt(i);
} else if (text.charAt(i) == '"') {
in_string = !in_string;
args[n] += text.charAt(i);
} else if (text.charAt(i) == ',' && !in_string) {
} else if (text.charAt(i) == "\'" && !in_string) {
in_char = !in_char;
args[n] += text.charAt(i);
if (arg_locs[n] == -1) arg_locs[n] = i;
} else if (text.charAt(i) == ',' && !in_string && !in_char) {
arg_ends[n] = i;
args.push("");
arg_locs.push(-1);
arg_ends.push(-1);
n += 1;
} else if (text.charAt(i) == ';' && !in_string) {
} else if (text.charAt(i) == ';' && !in_string && !in_char) {
break;
} else if (in_string || text.charAt(i) != ' ') {
} else if (in_string || in_char || text.charAt(i) != ' ') {
if (arg_locs[n] == -1) arg_locs[n] = i;
args[n] += text.charAt(i);
}
Expand Down
2 changes: 1 addition & 1 deletion js/disassembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var Disassembler = {
0x08: "INT",
0x09: "IAG",
0x0a: "IAS",
0x0b: "IAP",
0x0b: "RFI",
0x0c: "IAQ",
// ...
0x10: "HWN",
Expand Down
15 changes: 12 additions & 3 deletions js/emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,28 @@ step: function(memory, registers, state, hardware) {
}
case 0x1e: { // STI
v = av;
DCPU.cycles += 2;
break;
}
case 0x1f: { // STD
v = av;
DCPU.cycles += 2;
break;
}
}
DCPU.setValue(bb, v & 0xffff, memory, registers);
switch (op) {
case 0x1e: { // STI
registers.I = (registers.I + 1) & 0xffff;
registers.J = (registers.J + 1) & 0xffff;
DCPU.cycles += 2;
break;
}
case 0x1f: { // STD
registers.I = (registers.I - 1) & 0xffff;
registers.J = (registers.J - 1) & 0xffff;
DCPU.cycles += 2;
break;
}
}
DCPU.setValue(bb, v & 0xffff, memory, registers);
return DCPU.cycles;
}
},
Expand Down

0 comments on commit fc66bbf

Please sign in to comment.