Skip to content
This repository
Browse code

Merge pull request #23 from robey/rfi

update asm/disasm for spec 1.7 ("RFI"), and support single-quoted ascii constants.
  • Loading branch information...
commit fc66bbfcabbf3012be1c400e9dc652644aba5128 2 parents e176157 + a0044c3
Denis Olshin authored May 02, 2012
26  js/assembler.js
@@ -56,7 +56,7 @@ var Assembler = {
56 56
     "int": 0x08,
57 57
     "iag": 0x09,
58 58
     "ias": 0x0a,
59  
-    "iap": 0x0b,
  59
+    "rfi": 0x0b,
60 60
     "iaq": 0x0c,
61 61
     // ...
62 62
     "hwn": 0x10,
@@ -111,6 +111,10 @@ var Assembler = {
111 111
         return false;
112 112
       }
113 113
       atom.state.pos = pos + 1;
  114
+    } else if (text.charAt(pos) == "'" && text.charAt(pos + 2) == "'") {
  115
+      atom.literal = text.charCodeAt(pos + 1);
  116
+      atom.state = state;
  117
+      atom.state.pos = pos + 3;
114 118
     } else {
115 119
       var operand = text.substr(pos, end - pos).match(/^[A-Za-z_.0-9]+/);
116 120
       if (!operand) {
@@ -315,14 +319,15 @@ var Assembler = {
315 319
 
316 320
     // strip comments so we don't have to worry about them
317 321
     var in_string = false;
  322
+    var in_char = false
318 323
     for (var i = 0; i < text.length; i++) {
319 324
       if (in_string && text.charAt(i) == '\\' && i < text.length - 1) {
320 325
         i++;
321  
-      } else
322  
-      if (text.charAt(i) == '"') {
  326
+      } else if (text.charAt(i) == '"') {
323 327
         in_string = !in_string;
324  
-      } else
325  
-      if (text.charAt(i) == ';' && !in_string) {
  328
+      } else if (text.charAt(i) == '\'' && !in_string) {
  329
+        in_char = !in_char;
  330
+      } else if (text.charAt(i) == ';' && !in_string && !in_char) {
326 331
         end = i;
327 332
         break;
328 333
       }
@@ -442,6 +447,7 @@ var Assembler = {
442 447
     var arg_ends = [ -1 ];
443 448
     var n = 0;
444 449
     in_string = false;
  450
+    in_char = false;
445 451
     for (var i = pos; i < end; i++) {
446 452
       if (text.charAt(i) == '\\' && i + 1 < end) {
447 453
         if (arg_locs[n] == -1) arg_locs[n] = i;
@@ -449,15 +455,19 @@ var Assembler = {
449 455
       } else if (text.charAt(i) == '"') {
450 456
         in_string = !in_string;
451 457
         args[n] += text.charAt(i);
452  
-      } else if (text.charAt(i) == ',' && !in_string) {
  458
+      } else if (text.charAt(i) == "\'" && !in_string) {
  459
+        in_char = !in_char;
  460
+        args[n] += text.charAt(i);
  461
+        if (arg_locs[n] == -1) arg_locs[n] = i;
  462
+      } else if (text.charAt(i) == ',' && !in_string && !in_char) {
453 463
         arg_ends[n] = i;
454 464
         args.push("");
455 465
         arg_locs.push(-1);
456 466
         arg_ends.push(-1);
457 467
         n += 1;
458  
-      } else if (text.charAt(i) == ';' && !in_string) {
  468
+      } else if (text.charAt(i) == ';' && !in_string && !in_char) {
459 469
         break;
460  
-      } else if (in_string || text.charAt(i) != ' ') {
  470
+      } else if (in_string || in_char || text.charAt(i) != ' ') {
461 471
         if (arg_locs[n] == -1) arg_locs[n] = i;
462 472
         args[n] += text.charAt(i);
463 473
       }
2  js/disassembler.js
@@ -50,7 +50,7 @@ var Disassembler = {
50 50
     0x08: "INT",
51 51
     0x09: "IAG",
52 52
     0x0a: "IAS",
53  
-    0x0b: "IAP",
  53
+    0x0b: "RFI",
54 54
     0x0c: "IAQ",
55 55
     // ...
56 56
     0x10: "HWN",
15  js/emulator.js
@@ -432,19 +432,28 @@ step: function(memory, registers, state, hardware) {
432 432
       }
433 433
       case 0x1e: { // STI
434 434
         v = av;
  435
+        DCPU.cycles += 2;
  436
+        break;
  437
+      }
  438
+      case 0x1f: { // STD
  439
+        v = av;
  440
+        DCPU.cycles += 2;
  441
+        break;
  442
+      }
  443
+    }
  444
+    DCPU.setValue(bb, v & 0xffff, memory, registers);
  445
+    switch (op) {        
  446
+      case 0x1e: { // STI
435 447
         registers.I = (registers.I + 1) & 0xffff;
436 448
         registers.J = (registers.J + 1) & 0xffff;
437  
-        DCPU.cycles += 2;
438 449
         break;
439 450
       }
440 451
       case 0x1f: { // STD
441 452
         registers.I = (registers.I - 1) & 0xffff;
442 453
         registers.J = (registers.J - 1) & 0xffff;
443  
-        DCPU.cycles += 2;
444 454
         break;
445 455
       }
446 456
     }
447  
-    DCPU.setValue(bb, v & 0xffff, memory, registers);
448 457
     return DCPU.cycles;
449 458
   }
450 459
 },

0 notes on commit fc66bbf

Please sign in to comment.
Something went wrong with that request. Please try again.