Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

740 lines
19KB

  1. /*
  2. * Emulate a basic 6502 (MOS) chip.
  3. */
  4. const BITM = require('../../utils/bitman.js');
  5. var Memory = require('../../common/memory.js');
  6. // mode = 0 - Immediate
  7. // mode = 1 - Zero Page
  8. // mode = 2 - Zero Page, X
  9. // mode = 3 - Zero Page, Y
  10. // mode = 4 - Absolute
  11. // mode = 5 - Absolute, X
  12. // mode = 6 - Absolute, Y
  13. // mode = 7 - Indirect, X
  14. // mode = 8 - Indirect, Y
  15. function ProcessOp(cpu, mode){
  16. switch(cpu.__cycle){
  17. case 0:
  18. cpu.__mem.address = cpu.__PC;
  19. PCUp(cpu, 1);
  20. cpu.__opv = cpu.__mem.byte;
  21. return (mode === 0);
  22. case 1:
  23. switch(mode){
  24. case 1: // Zero Page
  25. cpu.__mem.address = cpu.__opv;
  26. cpu.__opv = cpu.__mem.byte;
  27. return true;
  28. case 2: // Zero Page, X
  29. case 3: // Zero Page, Y
  30. cpu.__opv = (cpu.__opv + ((mode === 2) ? cpu.__XR : cpu.__YR)) & 0xFF; break;
  31. case 4: // Absolute
  32. case 5: // Absolute, X
  33. case 6: // Absolute, Y
  34. cpu.__mem.address = cpu.__PC;
  35. PCUp(cpu, 1);
  36. cpu.__opv |= cpu.__mem.byte << 8;
  37. break;
  38. case 7: // Indirect, X
  39. cpu.__opv = (cpu.__opv + cpu.__XR) & 0xFF; break;
  40. case 8: // Indirect, Y
  41. cpu.__mem.address = cpu.__opv;
  42. cpu.__opv = cpu.__mem.byte;
  43. break;
  44. } break;
  45. case 2:
  46. switch(mode){
  47. case 2: // Zero Page, X
  48. case 3: // Zero Page, Y
  49. case 4: // Absolute
  50. cpu.__mem.address = cpu.__opv;
  51. cpu.__opv = cpu.__mem.byte;
  52. return true;
  53. case 5: // Absolute, X
  54. case 6: // Absolute, Y
  55. let s = (mode === 5) ? cpu.__XR : cpu.__YR;
  56. let l = (cpu.__opv & 0xFF) + s;
  57. cpu.__opv = (cpu.__opv & 0xFF00) | (l & 0xFF);
  58. if (l < 255){
  59. cpu.__mem.address = cpu.__opv;
  60. cpu.__opv = cpu.__mem.byte;
  61. return true;
  62. }
  63. break;
  64. case 7: // Indirect, X
  65. cpu.__mem.address = cpu.__opv;
  66. cpu.__opv = cpu.__mem.byte;
  67. break;
  68. case 8: // Indirect, Y
  69. cpu.__mem.address += 1;
  70. cpu.__opv |= cpu.__mem.byte << 8;
  71. break;
  72. } break;
  73. case 3:
  74. switch(mode){
  75. case 5: // Absolute, X
  76. case 6: // Absolute, Y
  77. let h = (cpu.__opv >> 8) + 1;
  78. cpu.__mem.address = (cpu.__opv & 0xFF) | (h << 8);
  79. cpu.__opv = cpu.__mem.byte;
  80. return true;
  81. case 7: // Indirect, X
  82. cpu.__mem.address += 1;
  83. cpu.__opv |= cpu.__mem.byte << 8;
  84. break;
  85. case 8: // Indirect, Y
  86. let l = (cpu.__opv & 0xFF) + cpu.__YR;
  87. cpu.__opv = (cpu.__opv & 0xFF00) | (l & 0xFF);
  88. if (l <= 255){
  89. cpu.__mem.address = cpu.__opv;
  90. cpu.__opv = cpu.__mem.byte;
  91. return true;
  92. }
  93. break;
  94. } break;
  95. case 4:
  96. if (mode === 8){
  97. let h = (cpu.__opv >> 8) + 1;
  98. cpu.__opv = (cpu.__opv & 0x00FF) | (h << 8);
  99. }
  100. cpu.__mem.address = cpu.__opv;
  101. cpu.__opv = cpu.__mem.byte;
  102. return true;
  103. }
  104. cpu.__cycle += 1;
  105. return false;
  106. }
  107. function ADC(cpu){ // To be used by both the ADC and SBC op codes.
  108. let pmode = [0x69, 0x65, 0x75, null, 0x6D, 0x7D, 0x79, 0x61, 0x71].indexOf(cpu.__op);
  109. if (ProcessOp(cpu, pmode) === true){
  110. cpu.__op = -1;
  111. ALU(cpu, 0, cpu.__opv);
  112. }
  113. }
  114. /*function MATHC(cpu, m){ // To be used by both the ADC and SBC op codes.
  115. // m == 0 - Add
  116. // m == 1 - Subtract
  117. switch(cpu.__step){
  118. case 0:
  119. cpu.__mem.address = cpu.__PC;
  120. PCUp(cpu, 1);
  121. cpu.__opv = cpu.__mem.byte;
  122. if (cpu.__op == 0x69){ // Immediate
  123. ALU(cpu, m, cpu.__opv);
  124. cpu.__op = -1; break;
  125. }
  126. case 1:
  127. switch (cpu.__op){
  128. case 0x65: // Zero Page
  129. cpu.__mem.address = cpu.__opv;
  130. ALU(cpu, m, cpu.__mem.byte);
  131. cpu.__op = -1; break;
  132. case 0x75: // Zero Page, X
  133. cpu.__opv = (cpu.__opv + cpu.__XR) & 0xFF; break;
  134. case 0x6D: // Absolute
  135. case 0x7D: // Absolute, X
  136. case 0x79: // Absolute, Y
  137. cpu.__mem.address = cpu.__PC;
  138. PCUp(cpu, 1);
  139. cpu.__opv |= cpu.__mem.byte << 8; break;
  140. case 0x61: // Indirect, X
  141. cpu.__opv = (cpu.__opv + cpu.__XR) & 0xFF; break;
  142. case 0x71: // Indirect, Y
  143. cpu.__mem.address = cpu.__opv;
  144. cpu.__opv = cpu.__mem.byte;
  145. break;
  146. }
  147. break;
  148. case 2:
  149. switch (cpu.__op){
  150. case 0x75: // Zero Page, X
  151. case 0x6D: // Absolute
  152. cpu.__mem.address = cpu.__opv;
  153. ALU(cpu, m, cpu.__mem.byte);
  154. cpu.__op = -1; break;
  155. case 0x7D: // Absolute, X
  156. case 0x79: // Absolute, Y
  157. let s = (cpu.__op === 0x7D) ? cpu.__XR : cpu.__YR;
  158. let l = (cpu.__opv & 0xFF) + s;
  159. cpu.__opv = (cpu.__opv & 0xFF00) | (l & 0xFF);
  160. if (l < 255){
  161. cpu.__mem.address = cpu.__opv;
  162. ALU(cpu, m, cpu.__mem.byte);
  163. cpu.__op = -1;
  164. }
  165. break;
  166. case 0x61: // Indirect, X
  167. cpu.__mem.address = cpu.__opv;
  168. cpu.__opv = cpu.__mem.byte;
  169. break;
  170. case 0x71: // Indirect, Y
  171. cpu.__mem.address += 1;
  172. cpu.__opv |= cpu.__mem.byte << 8;
  173. break;
  174. }
  175. break;
  176. case 3:
  177. switch (cpu.__op){
  178. case 0x7D: // Absolute, X
  179. case 0x79: // Absolute, Y
  180. let h = (cpu.__opv >> 8) + 1;
  181. cpu.__mem.address = (cpu.__opv & 0xFF) | (h << 8);
  182. ALU(cpu, m, cpu.__mem.byte);
  183. cpu.__op = -1; break;
  184. case 0x61: // Indirect, X
  185. cpu.__mem.address += 1;
  186. cpu.__opv |= cpu.__mem.byte << 8;
  187. break;
  188. case 0x71: // Indirect, Y
  189. let l = (cpu.__opv & 0xFF) + cpu.__YR;
  190. cpu.__opv = (cpu.__opv & 0xFF00) | (l & 0xFF);
  191. if (l <= 255){
  192. cpu.__mem.address = cpu.__opv;
  193. ALU(cpu, m, cpu.__mem.byte);
  194. cpu.__op = -1; break;
  195. }
  196. }
  197. break;
  198. case 4:
  199. if (cpu.__op === 0x71){
  200. let h = (cpu.__opv >> 8) + 1;
  201. cpu.__opv = (cpu.__opv & 0x00FF) | (h << 8);
  202. }
  203. cpu.__mem.address = cpu.__opv;
  204. ALU(cpu, m, cpu.__mem.byte);
  205. cpu.__op = -1; break;
  206. }
  207. cpu.__step += 1;
  208. }*/
  209. function AND(cpu){
  210. }
  211. function ASL(cpu){
  212. }
  213. function BIT(cpu){
  214. }
  215. function BRANCH(cpu){
  216. switch(cpu.__cycle){
  217. case 0:
  218. let branch = false;
  219. switch(cpu.__op){
  220. case 0x10: // BPL
  221. branch = (cpu.N === 0); break;
  222. case 0x30: // BMI
  223. branch = (cpu.N === 1); break;
  224. case 0x50: // BVC
  225. branch = (cpu.V === 0); break;
  226. case 0x70: // BVS
  227. branch = (cpu.V === 1); break;
  228. case 0x90: // BCC
  229. branch = (cpu.C === 0); break;
  230. case 0xB0: // BCS
  231. branch = (cpu.C === 1); break;
  232. case 0xD0: // BNE
  233. branch = (cpu.Z === 0); break;
  234. case 0xF0: // BEQ
  235. branch = (cpu.Z === 1); break;
  236. }
  237. if (branch === false)
  238. PCUp(cpu, 1);
  239. case 1:
  240. if (cpu.__cycle === 1){ // TODO: Huh???
  241. cpu.__mem.address = this.__PC;
  242. let v = cpu.__mem.byte;
  243. if (v > 128){
  244. PCDown(cpu, 255 - v);
  245. } else {
  246. PCUp(cpu, v);
  247. }
  248. }
  249. cpu.__op = -1;
  250. }
  251. cpu.__cycle += 1;
  252. }
  253. function BRK(cpu){
  254. }
  255. function CMP(cpu){
  256. }
  257. function CPX(cpu){
  258. }
  259. function CPY(cpu){
  260. }
  261. function DEC(cpu){
  262. }
  263. function EOR(cpu){
  264. }
  265. function FLAG(cpu){
  266. switch (cpu.__op){
  267. case 0x18: // CLC
  268. cpu.C = 0; break;
  269. case 0x38: // SEC
  270. cpu.C = 1; break;
  271. case 0x58: // CLI
  272. cpu.I = 0; break;
  273. case 0x78: // SEI
  274. cpu.I = 1; break;
  275. case 0xB8: // CLV
  276. cpu.V = 0; break;
  277. case 0xD8: // CLD
  278. cpu.D = 0; break;
  279. case 0xF8: // SED
  280. cpu.D = 1; break;
  281. }
  282. cpu.__op = -1;
  283. }
  284. function INC(cpu){
  285. }
  286. function JMP(cpu){
  287. }
  288. function JRS(cpu){
  289. }
  290. function LDA(cpu){
  291. }
  292. function LDX(cpu){
  293. }
  294. function LDY(cpu){
  295. }
  296. function LSR(cpu){
  297. }
  298. function ORA(cpu){
  299. }
  300. function REGISTER(cpu){
  301. let t = 0;
  302. switch(this.__op){
  303. case 0xAA: // TAX
  304. cpu.__XR = cpu.__AR;
  305. t = cpu.__XR;
  306. break;
  307. case 0x8A: // TXA
  308. cpu.__AR = cpu.__XR;
  309. t = cpu.__AR;
  310. break;
  311. case 0xCA: // DEX
  312. cpu.__XR = (cpu.__XR === 0) ? 255 : cpu.__XR - 1;
  313. t = cpu.__XR;
  314. break;
  315. case 0xE8: // INX
  316. cpu.__XR = (cpu.__XR === 255) ? 0 : cpu.__XR + 1;
  317. t = cpu.__XR;
  318. break;
  319. case 0xA8: // TAY
  320. cpu.__YR = cpu.__AR;
  321. t = cpu.__YR;
  322. break;
  323. case 0x98: // TYA
  324. cpu.__AR = cpu.__YR;
  325. t = cpu.__AR;
  326. break;
  327. case 0x88: // DEY
  328. cpu.__YR = (cpu.__YR === 0) ? 255 : cpu.__YR - 1;
  329. t = cpu.__YR;
  330. break;
  331. case 0xC8: // INY
  332. cpu.__YR = (cpu.__YR === 255) ? 0 : cpu.__YR + 1;
  333. t = cpu.__YR;
  334. break;
  335. }
  336. cpu.N = (t >= 0x80);
  337. cpu.Z = (t === 0);
  338. cpu.__op = -1;
  339. }
  340. function ROL(cpu){
  341. }
  342. function ROR(cpu){
  343. }
  344. function RTI(cpu){
  345. }
  346. function RTS(cpu){
  347. }
  348. function SBC(cpu){
  349. let pmode = [0xE9, 0xE5, 0xF5, null, 0xED, 0xFD, 0xF9, 0xE1, 0xF1].indexOf(cpu.__op);
  350. if (ProcessOp(cpu, pmode) === true){
  351. cpu.__op = -1;
  352. ALU(cpu, 1, cpu.__opv);
  353. }
  354. }
  355. function STA(cpu){
  356. }
  357. function STACK(cpu){
  358. switch(cpu.__op){
  359. case 0x9A: // TXS
  360. cpu.__SP = cpu.__XR;
  361. cpu.__op = -1;
  362. break;
  363. case 0xBA: // TSX
  364. cpu.__XR = cpu.__SP;
  365. cpu.__op = -1;
  366. break;
  367. case 0x48: // PHA
  368. if (cpu.__cycle === 0){
  369. cpu.__mem.address = 0x0100 | cpu.__SP;
  370. } else if (cpu.__cycle === 1){
  371. cpu.__mem.byte = cpu.__AR;
  372. cpu.__SP = (cpu.__SP === 0) ? 255 : cpu.__SP - 1;
  373. cpu.__op = -1;
  374. }
  375. break;
  376. case 0x68: // PLA
  377. if (cpu.__cycle === 0){
  378. cpu.__mem.address = 0x0100 | cpu.__SP;
  379. } else if (cpu.__cycle === 1){
  380. cpu.__AR = cpu.__mem.byte;
  381. cpu.Z = (cpu.__AR === 0);
  382. cpu.N = BITM.isOn(cpu.__AR, 7);
  383. } else if (cpu.__step === 2){
  384. cpu.__SP = (cpu.__SP === 255) ? 0 : cpu.__SP + 1;
  385. cpu.__op = -1;
  386. }
  387. break;
  388. case 0x08: // PHP
  389. if (cpu.__cycle === 0){
  390. cpu.__mem.address = 0x0100 | cpu.__SP;
  391. } else if (cpu.__cycle === 1){
  392. cpu.__mem.byte = cpu.__PR;
  393. cpu.__SP = (cpu.__SP === 0) ? 255 : cpu.__SP - 1;
  394. cpu.__op = -1;
  395. }
  396. break;
  397. case 0x28: // PLP
  398. if (cpu.__cycle === 0){
  399. cpu.__mem.address = 0x0100 | cpu.__SP;
  400. } else if (cpu.__cycle === 1){
  401. cpu.__SP = cpu.__mem.byte;
  402. } else if (cpu.__cycle === 2){
  403. cpu.__SP = (cpu.__SP === 255) ? 0 : cpu.__SP + 1;
  404. cpu.__op = -1;
  405. }
  406. break;
  407. }
  408. cpu.__cycle += 1;
  409. }
  410. function STX(cpu){
  411. }
  412. function STY(cpu){
  413. }
  414. // --------------------------------------------------------------------------------------------
  415. // Test to see if both a and b's high byte is the same... same page.
  416. function SamePage(a, b){
  417. return ((a >> 8) == (b >> 8));
  418. }
  419. function PCHI(cpu, b){
  420. cpu.__PC = (cpu.__PC & 0x00FF) | (b << 8);
  421. }
  422. function PCLOW(cpu, b){
  423. cpu.__PC = (cpu.__PC & 0xFF00) | b;
  424. }
  425. function PCUp(cpu, amount){
  426. if (cpu.__pcc === 1){
  427. PCHI(cpu, ((cpu.__PC & 0xFF00) >> 8) + 1);
  428. cpu.__pcc = 0;
  429. } else if ((cpu.__PC & 0x00FF) + amount > 255){
  430. cpu.__pcc = 1;
  431. PCLOW(cpu, ((cpu.__PC & 0x00FF) + amount) - 256);
  432. } else {
  433. PCLOW(cpu, (cpu.__PC & 0x00FF) + amount);
  434. }
  435. }
  436. function PCDown(cpu, amount){
  437. if (cpu.__pcc === -1){
  438. PCHI(cpu, ((cpu.__PC & 0xFF00) >> 8) - 1);
  439. cpu.__pcc = 0;
  440. } else if ((cpu.__PC & 0x00FF) - amount < 0){
  441. cpu.__pcc = -1;
  442. PCLOW(cpu, ((cpu.__PC & 0x00FF) - amount) + 256);
  443. } else {
  444. PCLOW(cpu, (cpu.__PC & 0x00FF) - amount);
  445. }
  446. }
  447. function MemAddrFrom(cpu, addr){
  448. cpu.__mem.address = addr;
  449. let v = cpu.__mem.byte;
  450. cpu.__mem.address = (addr + 1) & 0xFF;
  451. v |= cpu.__mem.byte << 8;
  452. return v;
  453. }
  454. function ALU(cpu, m, b){
  455. let v = 0;
  456. switch(m){
  457. case 0: // Addition
  458. cpu.__AR = (cpu.__AR + b) + ((cpu.C === 1) ? 1 : 0);
  459. cpu.C = (v >= 256);
  460. break;
  461. case 1: // Subtraction
  462. cpu.__AR = (cpu.__AR - b) - ((cpu.C === 0) ? 1 : 0);
  463. cpu.C = (v >= 0);
  464. break;
  465. }
  466. cpu.__AR &= 0xFF;
  467. cpu.V = (BITM.isOn(cpu.__AR, 7) === BITM.isOn(b, 7)) && (BITM.val(v, 7) !== BITM.val(cpu.__AR, 7));
  468. cpu.N = BITM.val(cpu.__AR, 7);
  469. cpu.Z = (cpu.__AR === 0);
  470. return cpu.__AR;
  471. }
  472. // --------------------------------------------------------------------------------------------
  473. // --------------------------------------------------------------------------------------------
  474. // --------------------------------------------------------------------------------------------
  475. class CPU{
  476. constructor(){
  477. // Registers
  478. this.__PC = 0; // Program Counter (16 bit)
  479. this.__SP = 255; // Stack Pointer (8 bit)
  480. this.__PR = 32; // Status Register (8 bit, bit 5 is always 1)
  481. this.__XR = 0; // X Register (8 bit)
  482. this.__YR = 0; // Y Register (8 bit)
  483. this.__AR = 0; // Accumulator Register (8 bit)
  484. // Variables to watch for Hardware Interrupts.
  485. this.__nmi = false;
  486. this.__irq = false;
  487. // Variable for tracking tick operations.
  488. this.__op = -1;
  489. this.__opmem = 0;
  490. this.__opv = 0;
  491. this.__cycle = 0;
  492. this.__pcc = 0; // Program Counter Carry.
  493. // Memory module or controller.
  494. this.__mem = null; // Must be explicitly attached.
  495. // Hold any created CLK instances.
  496. this.__clkfn = null;
  497. }
  498. // ----------------------------------------
  499. // CPU Registers. Here for debug purposes.
  500. get PC(){return this.__PC;}
  501. get SP(){return this.__SP;}
  502. get P(){return this.__PR;}
  503. get X(){return this.__XR;}
  504. get Y(){return this.__YR;}
  505. get A(){return this.__AR;}
  506. // ----------------------------------------
  507. // Quick Flag Access
  508. get N(){return (BITM.isOn(this.__PR, 7)) ? 1 : 0;}
  509. set N(n){this.__PR = (n === true || n === 1) ? BITM.set(this.__PR, 7) : BITM.clear(this.__PR, 7);}
  510. get V(){return (BITM.isOn(this.__PR, 6)) ? 1 : 0;}
  511. set V(v){this.__PR = (v === true || v === 1) ? BITM.set(this.__PR, 6) : BITM.clear(this.__PR, 6);}
  512. get B(){return (BITM.isOn(this.__PR, 4)) ? 1 : 0;}
  513. set B(b){this.__PR = (b === true || b === 1) ? BITM.set(this.__PR, 4) : BITM.clear(this.__PR, 4);}
  514. get D(){return (BITM.isOn(this.__PR, 3)) ? 1 : 0;}
  515. set D(d){this.__PR = (d === true || d === 1) ? BITM.set(this.__PR, 3) : BITM.clear(this.__PR, 3);}
  516. get I(){return (BITM.isOn(this.__PR, 2)) ? 1 : 0;}
  517. set I(i){this.__PR = (i === true || i === 1) ? BITM.set(this.__PR, 2) : BITM.clear(this.__PR, 2);}
  518. get Z(){return (BITM.isOn(this.__PR, 1)) ? 1 : 0;}
  519. set Z(z){this.__PR = (z === true || z === 1) ? BITM.set(this.__PR, 1) : BITM.clear(this.__PR, 1);}
  520. get C(){return (BITM.isOn(this.__PR, 0)) ? 1 : 0;}
  521. set C(c){this.__PR = (c === true || c === 1) ? BITM.set(this.__PR, 0) : BITM.clear(this.__PR, 0);}
  522. // ----------------------------------------
  523. // Hardware interrupt triggers. Settable only.
  524. set NMI(n){
  525. this.__nmi = (n === true);
  526. }
  527. set IRQ(q){
  528. // TODO: Verify this.
  529. // TODO: Do not set if the interrupt flag is off.
  530. this.__irq = (q === true);
  531. }
  532. reset(){
  533. this.__mem.address = 0xFFFC;
  534. this.__PC = this.__mem.byte;
  535. this.__mem.address = 0xFFFD;
  536. this.__PC |= this.__mem.byte << 8;
  537. // Disabling the IRQ interrupts is the ONLY flag that must be set
  538. // during reset. The others are random.
  539. this.I = 1;
  540. }
  541. // -----------------------------------------
  542. // Set and Get Memory property.
  543. get memory(){return this.__mem;}
  544. set memory(m){
  545. if (!(m instanceof Memory))
  546. throw new ValueError("Expected Memory instance object.");
  547. this.__mem = m;
  548. }
  549. // -----------------------------------------
  550. clk(){
  551. if (this.__clkfn === null){
  552. this.__clkfn = (function(){
  553. if (this.__pcc !== 0){
  554. if (this.__pcc > 0) {
  555. PCUp(this, 1);
  556. } else {
  557. PCDown(this, 1);
  558. }
  559. } else if (this.__op < 0){
  560. if (this.__nmi) {
  561. // TODO: Handle NMI Interrupt.
  562. } else if (this.__irq) {
  563. this.__irq = false;
  564. if (!BITM.isOn(this.__PR, 5)){
  565. // TODO: Handle IRQ Interrupt.
  566. }
  567. } else {
  568. this.__cycle = 0;
  569. this.__mem.address = this.__PC;
  570. this.__op = this.__mem.byte;
  571. PCUp(this, 1);
  572. }
  573. } else {
  574. switch(this.__op){
  575. case 0x69: case 0x65: case 0x75: case 0x6D: case 0x7D: case 0x79: case 0x61: case 0x71:
  576. ADC(this); break;
  577. case 0x29: case 0x25: case 0x35: case 0x2D: case 0x3D: case 0x39: case 0x21: case 0x31:
  578. AND(this); break;
  579. case 0x0A: case 0x06: case 0x16: case 0x0E: case 0x1E:
  580. ASL(this); break;
  581. case 0x24: case 0x2C:
  582. BIT(this); break;
  583. case 0x10: case 0x30: case 0x50: case 0x70: case 0x90: case 0xB0: case 0xD0: case 0xF0:
  584. BRANCH(this); break;
  585. case 0x00:
  586. BRK(this); break;
  587. case 0xC9: case 0xC5: case 0xD5: case 0xCD: case 0xDD: case 0xD9: case 0xC1: case 0xD1:
  588. CMP(this); break;
  589. case 0xE0: case 0xE4: case 0xEC:
  590. CPX(this); break;
  591. case 0xC0: case 0xC4: case 0xCC:
  592. CPY(this); break;
  593. case 0xC6: case 0xD6: case 0xCE: case 0xDE:
  594. DEC(this); break;
  595. case 0x49: case 0x45: case 0x55: case 0x4D: case 0x5D: case 0x59: case 0x41: case 0x51:
  596. EOR(this); break;
  597. case 0x18: case 0x38: case 0x58: case 0x78: case 0xB8: case 0xD8: case 0xF8:
  598. FLAG(this); break;
  599. case 0xE6: case 0xF6: case 0xEE: case 0xFE:
  600. INC(this); break;
  601. case 0x4C: case 0x6C:
  602. JMP(this); break;
  603. case 0x20:
  604. JSR(this); break;
  605. case 0xA9: case 0xA5: case 0xB5: case 0xAD: case 0xBD: case 0xB9: case 0xA1: case 0xB1:
  606. LDA(this); break;
  607. case 0xA2: case 0xA6: case 0xB6: case 0xAE: case 0xBE:
  608. LDX(this); break;
  609. case 0xA0: case 0xA4: case 0xB4: case 0xAC: case 0xBC:
  610. LDY(this); break;
  611. case 0x4A: case 0x46: case 0x56: case 0x4E: case 0x5E:
  612. LSR(this); break;
  613. case 0xEA:
  614. // NOP
  615. if (this.__step == 1){
  616. this.__op = -1;
  617. } else {this.__step += 1;}
  618. break;
  619. case 0x09: case 0x05: case 0x15: case 0x0D: case 0x1D: case 0x19: case 0x01: case 0x11:
  620. ORA(this); break;
  621. case 0xAA: case 0x8A: case 0xCA: case 0xE8: case 0xA8: case 0x98: case 0x88: case 0xC8:
  622. REGISTER(this); break;
  623. case 0x2A: case 0x26: case 0x36: case 0x2E: case 0x3E:
  624. ROL(this); break;
  625. case 0x6A: case 0x66: case 0x76: case 0x6E: case 0x7E:
  626. ROR(this); break;
  627. case 0x40:
  628. RTI(this); break;
  629. case 0x60:
  630. RTS(this); break;
  631. case 0xE9: case 0xE5: case 0xF5: case 0xED: case 0xFD: case 0xF9: case 0xE1: case 0xF1:
  632. SBC(this); break;
  633. case 0x85: case 0x95: case 0x8D: case 0x9D: case 0x99: case 0x81: case 0x91:
  634. STA(this); break;
  635. case 0x9A: case 0xBA: case 0x48: case 0x68: case 0x08: case 0x28:
  636. STACK(this); break;
  637. case 0x86: case 0x96: case 0x8E:
  638. STX(this); break;
  639. case 0x84: case 0x94: case 0x8C:
  640. STY(this); break;
  641. }
  642. }
  643. }).bind(this);
  644. }
  645. return this.__clkfn;
  646. }
  647. }
  648. module.exports = CPU;