Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1267 lines
38KB

  1. const expect = require('chai').expect;
  2. const Assembler = require('../src/MOS/6502/assembler.js');
  3. describe("Testing MOS6502 Assembler...", function(){
  4. var asm = new Assembler();
  5. it(".reset()", function(){
  6. asm.compile("ADC $44");
  7. asm.reset();
  8. expect(asm.PC).to.equal(0);
  9. expect(Object.keys(asm.variables).length).to.equal(0);
  10. expect(Object.keys(asm.jumplabels).length).to.equal(0);
  11. expect(asm.result().length).to.equal(0);
  12. });
  13. it(".result()", function(){
  14. asm.reset();
  15. asm.compile("ADC $44");
  16. expect(asm.result().length).to.be.gt(0);
  17. });
  18. describe(".compile()", function(){
  19. it(".define directive", function(){
  20. asm.compile(".define TAG $44");
  21. let vars = asm.variables;
  22. expect(vars).to.have.key('TAG');
  23. expect(vars['TAG']).to.equal(0x44);
  24. });
  25. it(".def directive (.define shorthand)", function(){
  26. asm.compile(".define TAG2 $55");
  27. let vars = asm.variables;
  28. expect(vars['TAG2']).to.exist;
  29. expect(vars['TAG2']).to.equal(0x55);
  30. });
  31. it("Jump labels", function(){
  32. let pc = asm.PC;
  33. asm.compile("loop:\nBNE loop");
  34. let jmp = asm.jumplabels;
  35. expect(jmp).to.have.key('loop');
  36. expect(jmp['loop']).to.equal(pc);
  37. });
  38. it(".bytes directive", function(){
  39. let res = asm.reset().compile(".BYTES $44, $55, $66, $77, b10110101, 128").result();
  40. expect(res.length).to.equal(6);
  41. expect(res[0]).to.equal(0x44);
  42. expect(res[1]).to.equal(0x55);
  43. expect(res[2]).to.equal(0x66);
  44. expect(res[3]).to.equal(0x77);
  45. expect(res[4]).to.equal(parseInt('10110101', 2));
  46. expect(res[5]).to.equal(128);
  47. });
  48. it(".byt directive (.bytes shorthand)", function(){
  49. let res = asm.reset().compile(".BYT $44, $55, $66").result();
  50. expect(res.length).to.equal(3);
  51. expect(res[0]).to.equal(0x44);
  52. expect(res[1]).to.equal(0x55);
  53. expect(res[2]).to.equal(0x66);
  54. });
  55. it("Jump label before and after .byte directive", function(){
  56. asm.reset();
  57. let pc1 = asm.PC;
  58. asm.compile("bytes: .bytes $44, $55, $66, $77");
  59. let pc2 = asm.PC;
  60. asm.compile("loop: BNE loop");
  61. let jmp = asm.jumplabels;
  62. //expect(jmp).to.have.key('bytes');
  63. expect(jmp['bytes']).to.equal(pc1);
  64. //expect(jmp).to.have.key('loop');
  65. expect(jmp['loop']).to.equal(pc2);
  66. let res = asm.result();
  67. expect(res.length).to.equal(6);
  68. expect(res[0]).to.equal(0x44);
  69. expect(res[1]).to.equal(0x55);
  70. expect(res[2]).to.equal(0x66);
  71. expect(res[3]).to.equal(0x77);
  72. expect(res[4]).to.equal(0xD0);
  73. expect(res[5]).to.equal(0xFE);
  74. });
  75. it("ADC Immediate", function(){
  76. asm.reset();
  77. asm.compile("ADC #$44");
  78. let res = asm.result();
  79. expect(res.length).to.equal(2);
  80. expect(res[0]).to.equal(0x69);
  81. expect(res[1]).to.equal(0x44);
  82. });
  83. it("ADC Zero Page", function(){
  84. asm.reset();
  85. asm.compile("ADC $44");
  86. let res = asm.result();
  87. expect(res.length).to.equal(2);
  88. expect(res[0]).to.equal(0x65);
  89. expect(res[1]).to.equal(0x44);
  90. });
  91. it("ADC Zero Page, X", function(){
  92. asm.reset();
  93. asm.compile("ADC $44, X");
  94. let res = asm.result();
  95. expect(res.length).to.equal(2);
  96. expect(res[0]).to.equal(0x75);
  97. expect(res[1]).to.equal(0x44);
  98. });
  99. it("ADC Absolute", function(){
  100. asm.reset();
  101. asm.compile("ADC $4400");
  102. let res = asm.result();
  103. expect(res.length).to.equal(3);
  104. expect(res[0]).to.equal(0x6D);
  105. expect(res[1]).to.equal(0x00);
  106. expect(res[2]).to.equal(0x44);
  107. });
  108. it("ADC Absolute, X", function(){
  109. asm.reset();
  110. asm.compile("ADC $4400,X");
  111. let res = asm.result();
  112. expect(res.length).to.equal(3);
  113. expect(res[0]).to.equal(0x7D);
  114. expect(res[1]).to.equal(0x00);
  115. expect(res[2]).to.equal(0x44);
  116. });
  117. it("ADC Absolute, Y", function(){
  118. asm.reset();
  119. asm.compile("ADC $4400, Y");
  120. let res = asm.result();
  121. expect(res.length).to.equal(3);
  122. expect(res[0]).to.equal(0x79);
  123. expect(res[1]).to.equal(0x00);
  124. expect(res[2]).to.equal(0x44);
  125. });
  126. it("ADC Indirect, X", function(){
  127. asm.reset();
  128. asm.compile("ADC ($44,X)");
  129. let res = asm.result();
  130. expect(res.length).to.equal(2);
  131. expect(res[0]).to.equal(0x61);
  132. expect(res[1]).to.equal(0x44);
  133. });
  134. it("ADC Indirect, Y", function(){
  135. asm.reset();
  136. asm.compile("ADC ($44), Y");
  137. let res = asm.result();
  138. expect(res.length).to.equal(2);
  139. expect(res[0]).to.equal(0x71);
  140. expect(res[1]).to.equal(0x44);
  141. });
  142. // -------------------------------------------------------------
  143. it("AND Immediate", function(){
  144. let res = asm.reset().compile("AND #$44").result();
  145. expect(res.length).to.equal(2);
  146. expect(res[0]).to.equal(0x29);
  147. expect(res[1]).to.equal(0x44);
  148. });
  149. it("AND Zero Page", function(){
  150. let res = asm.reset().compile("AND $44").result();
  151. expect(res.length).to.equal(2);
  152. expect(res[0]).to.equal(0x25);
  153. expect(res[1]).to.equal(0x44);
  154. });
  155. it("AND Zero Page, X", function(){
  156. let res = asm.reset().compile("AND $44,X").result();
  157. expect(res.length).to.equal(2);
  158. expect(res[0]).to.equal(0x35);
  159. expect(res[1]).to.equal(0x44);
  160. });
  161. it("AND Absolute", function(){
  162. let res = asm.reset().compile("AND $4400").result();
  163. expect(res.length).to.equal(3);
  164. expect(res[0]).to.equal(0x2D);
  165. expect(res[1]).to.equal(0x00);
  166. expect(res[2]).to.equal(0x44);
  167. });
  168. it("AND Absolute, X", function(){
  169. let res = asm.reset().compile("AND $4400, X").result();
  170. expect(res.length).to.equal(3);
  171. expect(res[0]).to.equal(0x3D);
  172. expect(res[1]).to.equal(0x00);
  173. expect(res[2]).to.equal(0x44);
  174. });
  175. it("AND Absolute, Y", function(){
  176. let res = asm.reset().compile("AND $4400, Y").result();
  177. expect(res.length).to.equal(3);
  178. expect(res[0]).to.equal(0x39);
  179. expect(res[1]).to.equal(0x00);
  180. expect(res[2]).to.equal(0x44);
  181. });
  182. it("AND Indirect, X", function(){
  183. let res = asm.reset().compile("AND ($44, X)").result();
  184. expect(res.length).to.equal(2);
  185. expect(res[0]).to.equal(0x21);
  186. expect(res[1]).to.equal(0x44);
  187. });
  188. it("AND Indirect, Y", function(){
  189. let res = asm.reset().compile("AND ($44), Y").result();
  190. expect(res.length).to.equal(2);
  191. expect(res[0]).to.equal(0x31);
  192. expect(res[1]).to.equal(0x44);
  193. });
  194. // -------------------------------------------------------------
  195. it("ASL Accumulator", function(){
  196. let res = asm.reset().compile("ASL A").result();
  197. expect(res.length).to.equal(1);
  198. expect(res[0]).to.equal(0x0A);
  199. });
  200. it("ASL Zero Page", function(){
  201. let res = asm.reset().compile("ASL $44").result();
  202. expect(res.length).to.equal(2);
  203. expect(res[0]).to.equal(0x06);
  204. expect(res[1]).to.equal(0x44);
  205. });
  206. it("ASL Zero Page, X", function(){
  207. let res = asm.reset().compile("ASL $44, X").result();
  208. expect(res.length).to.equal(2);
  209. expect(res[0]).to.equal(0x16);
  210. expect(res[1]).to.equal(0x44);
  211. });
  212. it("ASL Absolute", function(){
  213. let res = asm.reset().compile("ASL $4400").result();
  214. expect(res.length).to.equal(3);
  215. expect(res[0]).to.equal(0x0E);
  216. expect(res[1]).to.equal(0x00);
  217. expect(res[2]).to.equal(0x44);
  218. });
  219. it("ASL Absolute, X", function(){
  220. let res = asm.reset().compile("ASL $4400, X").result();
  221. expect(res.length).to.equal(3);
  222. expect(res[0]).to.equal(0x1E);
  223. expect(res[1]).to.equal(0x00);
  224. expect(res[2]).to.equal(0x44);
  225. });
  226. // -------------------------------------------------------------
  227. it("BIT Zero Page", function(){
  228. let res = asm.reset().compile("BIT $44").result();
  229. expect(res.length).to.equal(2);
  230. expect(res[0]).to.equal(0x24);
  231. expect(res[1]).to.equal(0x44);
  232. });
  233. it("BIT Absolute", function(){
  234. let res = asm.reset().compile("BIT $4400").result();
  235. expect(res.length).to.equal(3);
  236. expect(res[0]).to.equal(0x2C);
  237. expect(res[1]).to.equal(0x00);
  238. expect(res[2]).to.equal(0x44);
  239. });
  240. // -------------------------------------------------------------
  241. it("BPL", function(){
  242. let res = asm.reset().compile("NOP\nNOP\nBPL $0000").result();
  243. expect(res.length).to.equal(4);
  244. expect(res[0]).to.equal(0xEA);
  245. expect(res[1]).to.equal(0xEA);
  246. expect(res[2]).to.equal(0x10);
  247. expect(res[3]).to.equal(0xFC);
  248. });
  249. it("BMI", function(){
  250. let res = asm.reset().compile("BMI $0003\nNOP\nNOP").result();
  251. expect(res.length).to.equal(4);
  252. expect(res[0]).to.equal(0x30);
  253. expect(res[1]).to.equal(0x02);
  254. expect(res[2]).to.equal(0xEA);
  255. expect(res[3]).to.equal(0xEA);
  256. });
  257. it("BVC", function(){
  258. let res = asm.reset().compile("BVC $0003\nNOP\nNOP").result();
  259. expect(res.length).to.equal(4);
  260. expect(res[0]).to.equal(0x50);
  261. expect(res[1]).to.equal(0x02);
  262. expect(res[2]).to.equal(0xEA);
  263. expect(res[3]).to.equal(0xEA);
  264. });
  265. it("BVS", function(){
  266. let res = asm.reset().compile("NOP\nNOP\nBVS $0000").result();
  267. expect(res.length).to.equal(4);
  268. expect(res[0]).to.equal(0xEA);
  269. expect(res[1]).to.equal(0xEA);
  270. expect(res[2]).to.equal(0x70);
  271. expect(res[3]).to.equal(0xFC);
  272. });
  273. it("BCC", function(){
  274. let res = asm.reset().compile("BCC $0003\nNOP\nNOP").result();
  275. expect(res.length).to.equal(4);
  276. expect(res[0]).to.equal(0x90);
  277. expect(res[1]).to.equal(0x02);
  278. expect(res[2]).to.equal(0xEA);
  279. expect(res[3]).to.equal(0xEA);
  280. });
  281. it("BCS", function(){
  282. let res = asm.reset().compile("NOP\nNOP\nBCS $0000").result();
  283. expect(res.length).to.equal(4);
  284. expect(res[0]).to.equal(0xEA);
  285. expect(res[1]).to.equal(0xEA);
  286. expect(res[2]).to.equal(0xB0);
  287. expect(res[3]).to.equal(0xFC);
  288. });
  289. it("BNE", function(){
  290. let res = asm.reset().compile("BNE $0003\nNOP\nNOP").result();
  291. expect(res.length).to.equal(4);
  292. expect(res[0]).to.equal(0xD0);
  293. expect(res[1]).to.equal(0x02);
  294. expect(res[2]).to.equal(0xEA);
  295. expect(res[3]).to.equal(0xEA);
  296. });
  297. it("BEQ", function(){
  298. let res = asm.reset().compile("NOP\nNOP\nBEQ $0000").result();
  299. expect(res.length).to.equal(4);
  300. expect(res[0]).to.equal(0xEA);
  301. expect(res[1]).to.equal(0xEA);
  302. expect(res[2]).to.equal(0xF0);
  303. expect(res[3]).to.equal(0xFC);
  304. });
  305. it("Branch Too Far Back", function(){
  306. expect(()=>{
  307. let asm2 = new Assembler(0x1000);
  308. let res = asm2.compile("BNE $0000").result();
  309. }).to.throw("Branch exceeds maximum number of bytes on program address 1001");
  310. });
  311. it("Branch Too Far Forward", function(){
  312. expect(()=>{
  313. let res = asm.reset().compile("BNE $00F0").result();
  314. }).to.throw("Branch exceeds maximum number of bytes on program address 01");
  315. });
  316. // -------------------------------------------------------------
  317. it ("BRK", function(){
  318. asm.reset();
  319. let res = asm.compile("BRK").result();
  320. expect(res.length).to.equal(1);
  321. expect(res[0]).to.equal(0x00);
  322. });
  323. // -------------------------------------------------------------
  324. it("CMP Immediate", function(){
  325. let res = asm.reset().compile("CMP #$44").result();
  326. expect(res.length).to.equal(2);
  327. expect(res[0]).to.equal(0xC9);
  328. expect(res[1]).to.equal(0x44);
  329. });
  330. it("CMP Zero Page", function(){
  331. let res = asm.reset().compile("CMP $44").result();
  332. expect(res.length).to.equal(2);
  333. expect(res[0]).to.equal(0xC5);
  334. expect(res[1]).to.equal(0x44);
  335. });
  336. it("CMP Zero Page, X", function(){
  337. let res = asm.reset().compile("CMP $44,X").result();
  338. expect(res.length).to.equal(2);
  339. expect(res[0]).to.equal(0xD5);
  340. expect(res[1]).to.equal(0x44);
  341. });
  342. it("CMP Absolute", function(){
  343. let res = asm.reset().compile("CMP $4400").result();
  344. expect(res.length).to.equal(3);
  345. expect(res[0]).to.equal(0xCD);
  346. expect(res[1]).to.equal(0x00);
  347. expect(res[2]).to.equal(0x44);
  348. });
  349. it("CMP Absolute, X", function(){
  350. let res = asm.reset().compile("CMP $4400,X").result();
  351. expect(res.length).to.equal(3);
  352. expect(res[0]).to.equal(0xDD);
  353. expect(res[1]).to.equal(0x00);
  354. expect(res[2]).to.equal(0x44);
  355. });
  356. it("CMP Absolute, Y", function(){
  357. let res = asm.reset().compile("CMP $4400, Y").result();
  358. expect(res.length).to.equal(3);
  359. expect(res[0]).to.equal(0xD9);
  360. expect(res[1]).to.equal(0x00);
  361. expect(res[2]).to.equal(0x44);
  362. });
  363. it("CMP Indirect, X", function(){
  364. let res = asm.reset().compile("CMP ($44,X)").result();
  365. expect(res.length).to.equal(2);
  366. expect(res[0]).to.equal(0xC1);
  367. expect(res[1]).to.equal(0x44);
  368. });
  369. it("CMP Indirect, Y", function(){
  370. let res = asm.reset().compile("CMP ($44),Y").result();
  371. expect(res.length).to.equal(2);
  372. expect(res[0]).to.equal(0xD1);
  373. expect(res[1]).to.equal(0x44);
  374. });
  375. // -------------------------------------------------------------
  376. it("CPX Immediate", function(){
  377. let res = asm.reset().compile("CPX #$44").result();
  378. expect(res.length).to.equal(2);
  379. expect(res[0]).to.equal(0xE0);
  380. expect(res[1]).to.equal(0x44);
  381. });
  382. it("CPX Zero Page", function(){
  383. let res = asm.reset().compile("CPX $44").result();
  384. expect(res.length).to.equal(2);
  385. expect(res[0]).to.equal(0xE4);
  386. expect(res[1]).to.equal(0x44);
  387. });
  388. it("CPX Absolute", function(){
  389. let res = asm.reset().compile("CPX $4400").result();
  390. expect(res.length).to.equal(3);
  391. expect(res[0]).to.equal(0xEC);
  392. expect(res[1]).to.equal(0x00);
  393. expect(res[2]).to.equal(0x44);
  394. });
  395. // -------------------------------------------------------------
  396. it("CPY Immediate", function(){
  397. let res = asm.reset().compile("CPY #$44").result();
  398. expect(res.length).to.equal(2);
  399. expect(res[0]).to.equal(0xC0);
  400. expect(res[1]).to.equal(0x44);
  401. });
  402. it("CPY Zero Page", function(){
  403. let res = asm.reset().compile("CPY $44").result();
  404. expect(res.length).to.equal(2);
  405. expect(res[0]).to.equal(0xC4);
  406. expect(res[1]).to.equal(0x44);
  407. });
  408. it("CPY Absolute", function(){
  409. let res = asm.reset().compile("CPY $4400").result();
  410. expect(res.length).to.equal(3);
  411. expect(res[0]).to.equal(0xCC);
  412. expect(res[1]).to.equal(0x00);
  413. expect(res[2]).to.equal(0x44);
  414. });
  415. // -------------------------------------------------------------
  416. it("DEC Zero Page", function(){
  417. let res = asm.reset().compile("DEC $44").result();
  418. expect(res.length).to.equal(2);
  419. expect(res[0]).to.equal(0xC6);
  420. expect(res[1]).to.equal(0x44);
  421. });
  422. it("DEC Zero Page, X", function(){
  423. let res = asm.reset().compile("DEC $44,X").result();
  424. expect(res.length).to.equal(2);
  425. expect(res[0]).to.equal(0xD6);
  426. expect(res[1]).to.equal(0x44);
  427. });
  428. it("DEC Absolute", function(){
  429. let res = asm.reset().compile("DEC $4400").result();
  430. expect(res.length).to.equal(3);
  431. expect(res[0]).to.equal(0xCE);
  432. expect(res[1]).to.equal(0x00);
  433. expect(res[2]).to.equal(0x44);
  434. });
  435. it("DEC Absolute, X", function(){
  436. let res = asm.reset().compile("DEC $4400,X").result();
  437. expect(res.length).to.equal(3);
  438. expect(res[0]).to.equal(0xDE);
  439. expect(res[1]).to.equal(0x00);
  440. expect(res[2]).to.equal(0x44);
  441. });
  442. // -------------------------------------------------------------
  443. it("EOR Immediate", function(){
  444. let res = asm.reset().compile("EOR #$44").result();
  445. expect(res.length).to.equal(2);
  446. expect(res[0]).to.equal(0x49);
  447. expect(res[1]).to.equal(0x44);
  448. });
  449. it("EOR Zero Page", function(){
  450. let res = asm.reset().compile("EOR $44").result();
  451. expect(res.length).to.equal(2);
  452. expect(res[0]).to.equal(0x45);
  453. expect(res[1]).to.equal(0x44);
  454. });
  455. it("EOR Zero Page, X", function(){
  456. let res = asm.reset().compile("EOR $44,X").result();
  457. expect(res.length).to.equal(2);
  458. expect(res[0]).to.equal(0x55);
  459. expect(res[1]).to.equal(0x44);
  460. });
  461. it("EOR Absolute", function(){
  462. let res = asm.reset().compile("EOR $4400").result();
  463. expect(res.length).to.equal(3);
  464. expect(res[0]).to.equal(0x4D);
  465. expect(res[1]).to.equal(0x00);
  466. expect(res[2]).to.equal(0x44);
  467. });
  468. it("EOR Absolute, X", function(){
  469. let res = asm.reset().compile("EOR $4400, X").result();
  470. expect(res.length).to.equal(3);
  471. expect(res[0]).to.equal(0x5D);
  472. expect(res[1]).to.equal(0x00);
  473. expect(res[2]).to.equal(0x44);
  474. });
  475. it("EOR Absolute, Y", function(){
  476. let res = asm.reset().compile("EOR $4400,Y").result();
  477. expect(res.length).to.equal(3);
  478. expect(res[0]).to.equal(0x59);
  479. expect(res[1]).to.equal(0x00);
  480. expect(res[2]).to.equal(0x44);
  481. });
  482. it("EOR Indirect, X", function(){
  483. let res = asm.reset().compile("EOR ($44,X)").result();
  484. expect(res.length).to.equal(2);
  485. expect(res[0]).to.equal(0x41);
  486. expect(res[1]).to.equal(0x44);
  487. });
  488. it("EOR Indirect, Y", function(){
  489. let res = asm.reset().compile("EOR ($44),Y").result();
  490. expect(res.length).to.equal(2);
  491. expect(res[0]).to.equal(0x51);
  492. expect(res[1]).to.equal(0x44);
  493. });
  494. // -------------------------------------------------------------
  495. it("CLC", function(){
  496. asm.reset();
  497. let res = asm.compile("CLC").result();
  498. expect(res.length).to.equal(1);
  499. expect(res[0]).to.equal(0x18);
  500. });
  501. it("CLD", function(){
  502. asm.reset();
  503. let res = asm.compile("CLD").result();
  504. expect(res.length).to.equal(1);
  505. expect(res[0]).to.equal(0xD8);
  506. });
  507. it("CLI", function(){
  508. asm.reset();
  509. let res = asm.compile("CLI").result();
  510. expect(res.length).to.equal(1);
  511. expect(res[0]).to.equal(0x58);
  512. });
  513. it("CLV", function(){
  514. asm.reset();
  515. let res = asm.compile("CLV").result();
  516. expect(res.length).to.equal(1);
  517. expect(res[0]).to.equal(0xB8);
  518. });
  519. it("SEC", function(){
  520. asm.reset();
  521. let res = asm.compile("SEC").result();
  522. expect(res.length).to.equal(1);
  523. expect(res[0]).to.equal(0x38);
  524. });
  525. it("SED", function(){
  526. asm.reset();
  527. let res = asm.compile("SED").result();
  528. expect(res.length).to.equal(1);
  529. expect(res[0]).to.equal(0xF8);
  530. });
  531. it("SEI", function(){
  532. asm.reset();
  533. let res = asm.compile("SEI").result();
  534. expect(res.length).to.equal(1);
  535. expect(res[0]).to.equal(0x78);
  536. });
  537. // -------------------------------------------------------------
  538. it("INC Zero Page", function(){
  539. let res = asm.reset().compile("INC $44").result();
  540. expect(res.length).to.equal(2);
  541. expect(res[0]).to.equal(0xE6);
  542. expect(res[1]).to.equal(0x44);
  543. });
  544. it("INC Zero Page, X", function(){
  545. let res = asm.reset().compile("INC $44,X").result();
  546. expect(res.length).to.equal(2);
  547. expect(res[0]).to.equal(0xF6);
  548. expect(res[1]).to.equal(0x44);
  549. });
  550. it("INC Absolute", function(){
  551. let res = asm.reset().compile("INC $4400").result();
  552. expect(res.length).to.equal(3);
  553. expect(res[0]).to.equal(0xEE);
  554. expect(res[1]).to.equal(0x00);
  555. expect(res[2]).to.equal(0x44);
  556. });
  557. it("INC Absolute, X", function(){
  558. let res = asm.reset().compile("INC $4400,X").result();
  559. expect(res.length).to.equal(3);
  560. expect(res[0]).to.equal(0xFE);
  561. expect(res[1]).to.equal(0x00);
  562. expect(res[2]).to.equal(0x44);
  563. });
  564. // -------------------------------------------------------------
  565. it("JMP Absolute", function(){
  566. let res = asm.reset().compile("JMP $2134").result();
  567. expect(res.length).to.equal(3);
  568. expect(res[0]).to.equal(0x4C);
  569. expect(res[1]).to.equal(0x34);
  570. expect(res[2]).to.equal(0x21);
  571. });
  572. it("JMP Indirect", function(){
  573. let res = asm.reset().compile("JMP ($2134)").result();
  574. expect(res.length).to.equal(3);
  575. expect(res[0]).to.equal(0x6C);
  576. expect(res[1]).to.equal(0x34);
  577. expect(res[2]).to.equal(0x21);
  578. });
  579. // -------------------------------------------------------------
  580. it("JSR Absolute", function(){
  581. let res = asm.reset().compile("JSR $5122").result();
  582. expect(res.length).to.equal(3);
  583. expect(res[0]).to.equal(0x20);
  584. expect(res[1]).to.equal(0x22);
  585. expect(res[2]).to.equal(0x51);
  586. });
  587. // -------------------------------------------------------------
  588. it("LDA Immediate", function(){
  589. let res = asm.reset().compile("LDA #$44").result();
  590. expect(res.length).to.equal(2);
  591. expect(res[0]).to.equal(0xA9);
  592. expect(res[1]).to.equal(0x44);
  593. });
  594. it("LDA Zero Page", function(){
  595. let res = asm.reset().compile("LDA $44").result();
  596. expect(res.length).to.equal(2);
  597. expect(res[0]).to.equal(0xA5);
  598. expect(res[1]).to.equal(0x44);
  599. });
  600. it("LDA Zero Page, X", function(){
  601. let res = asm.reset().compile("LDA $44,X").result();
  602. expect(res.length).to.equal(2);
  603. expect(res[0]).to.equal(0xB5);
  604. expect(res[1]).to.equal(0x44);
  605. });
  606. it("LDA Absolute", function(){
  607. let res = asm.reset().compile("LDA $4400").result();
  608. expect(res.length).to.equal(3);
  609. expect(res[0]).to.equal(0xAD);
  610. expect(res[1]).to.equal(0x00);
  611. expect(res[2]).to.equal(0x44);
  612. });
  613. it("LDA Absolute, X", function(){
  614. let res = asm.reset().compile("LDA $4400,X").result();
  615. expect(res.length).to.equal(3);
  616. expect(res[0]).to.equal(0xBD);
  617. expect(res[1]).to.equal(0x00);
  618. expect(res[2]).to.equal(0x44);
  619. });
  620. it("LDA Absolute, Y", function(){
  621. let res = asm.reset().compile("LDA $4400, Y").result();
  622. expect(res.length).to.equal(3);
  623. expect(res[0]).to.equal(0xB9);
  624. expect(res[1]).to.equal(0x00);
  625. expect(res[2]).to.equal(0x44);
  626. });
  627. it("LDA Indirect, X", function(){
  628. let res = asm.reset().compile("LDA ($44,X)").result();
  629. expect(res.length).to.equal(2);
  630. expect(res[0]).to.equal(0xA1);
  631. expect(res[1]).to.equal(0x44);
  632. });
  633. it("LDA Indirect, Y", function(){
  634. let res = asm.reset().compile("LDA ($44),Y").result();
  635. expect(res.length).to.equal(2);
  636. expect(res[0]).to.equal(0xB1);
  637. expect(res[1]).to.equal(0x44);
  638. });
  639. // -------------------------------------------------------------
  640. it("LDX Immediate", function(){
  641. let res = asm.reset().compile("LDX #$44").result();
  642. expect(res.length).to.equal(2);
  643. expect(res[0]).to.equal(0xA2);
  644. expect(res[1]).to.equal(0x44);
  645. });
  646. it("LDX Zero Page", function(){
  647. let res = asm.reset().compile("LDX $44").result();
  648. expect(res.length).to.equal(2);
  649. expect(res[0]).to.equal(0xA6);
  650. expect(res[1]).to.equal(0x44);
  651. });
  652. it("LDX Zero Page, Y", function(){
  653. let res = asm.reset().compile("LDX $44,Y").result();
  654. expect(res.length).to.equal(2);
  655. expect(res[0]).to.equal(0xB6);
  656. expect(res[1]).to.equal(0x44);
  657. });
  658. it("LDX Absolute", function(){
  659. let res = asm.reset().compile("LDX $4400").result();
  660. expect(res.length).to.equal(3);
  661. expect(res[0]).to.equal(0xAE);
  662. expect(res[1]).to.equal(0x00);
  663. expect(res[2]).to.equal(0x44);
  664. });
  665. it("LDX Absolute, Y", function(){
  666. let res = asm.reset().compile("LDX $4400,Y").result();
  667. expect(res.length).to.equal(3);
  668. expect(res[0]).to.equal(0xBE);
  669. expect(res[1]).to.equal(0x00);
  670. expect(res[2]).to.equal(0x44);
  671. });
  672. // -------------------------------------------------------------
  673. it("LDY Immediate", function(){
  674. let res = asm.reset().compile("LDY #$44").result();
  675. expect(res.length).to.equal(2);
  676. expect(res[0]).to.equal(0xA0);
  677. expect(res[1]).to.equal(0x44);
  678. });
  679. it("LDY Zero Page", function(){
  680. let res = asm.reset().compile("LDY $44").result();
  681. expect(res.length).to.equal(2);
  682. expect(res[0]).to.equal(0xA4);
  683. expect(res[1]).to.equal(0x44);
  684. });
  685. it("LDY Zero Page, X", function(){
  686. let res = asm.reset().compile("LDY $44,X").result();
  687. expect(res.length).to.equal(2);
  688. expect(res[0]).to.equal(0xB4);
  689. expect(res[1]).to.equal(0x44);
  690. });
  691. it("LDY Absolute", function(){
  692. let res = asm.reset().compile("LDY $4400").result();
  693. expect(res.length).to.equal(3);
  694. expect(res[0]).to.equal(0xAC);
  695. expect(res[1]).to.equal(0x00);
  696. expect(res[2]).to.equal(0x44);
  697. });
  698. it("LDY Absolute, X", function(){
  699. let res = asm.reset().compile("LDY $4400,X").result();
  700. expect(res.length).to.equal(3);
  701. expect(res[0]).to.equal(0xBC);
  702. expect(res[1]).to.equal(0x00);
  703. expect(res[2]).to.equal(0x44);
  704. });
  705. // -------------------------------------------------------------
  706. it("LSR Accumulator", function(){
  707. let res = asm.reset().compile("LSR A").result();
  708. expect(res.length).to.equal(1);
  709. expect(res[0]).to.equal(0x4A);
  710. });
  711. it("LSR Zero Page", function(){
  712. let res = asm.reset().compile("LSR $44").result();
  713. expect(res.length).to.equal(2);
  714. expect(res[0]).to.equal(0x46);
  715. expect(res[1]).to.equal(0x44);
  716. });
  717. it("LSR Zero Page, X", function(){
  718. let res = asm.reset().compile("LSR $44,X").result();
  719. expect(res.length).to.equal(2);
  720. expect(res[0]).to.equal(0x56);
  721. expect(res[1]).to.equal(0x44);
  722. });
  723. it("LSR Absolute", function(){
  724. let res = asm.reset().compile("LSR $4400").result();
  725. expect(res.length).to.equal(3);
  726. expect(res[0]).to.equal(0x4E);
  727. expect(res[1]).to.equal(0x00);
  728. expect(res[2]).to.equal(0x44);
  729. });
  730. it("LSR Absolute, X", function(){
  731. let res = asm.reset().compile("LSR $4400, X").result();
  732. expect(res.length).to.equal(3);
  733. expect(res[0]).to.equal(0x5E);
  734. expect(res[1]).to.equal(0x00);
  735. expect(res[2]).to.equal(0x44);
  736. });
  737. // -------------------------------------------------------------
  738. it("NOP", function(){
  739. asm.reset();
  740. let res = asm.compile("NOP").result();
  741. expect(res.length).to.equal(1);
  742. expect(res[0]).to.equal(0xEA);
  743. });
  744. // -------------------------------------------------------------
  745. it("ORA Immediate", function(){
  746. let res = asm.reset().compile("ORA #$44").result();
  747. expect(res.length).to.equal(2);
  748. expect(res[0]).to.equal(0x09);
  749. expect(res[1]).to.equal(0x44);
  750. });
  751. it("ORA Zero Page", function(){
  752. let res = asm.reset().compile("ORA $44").result();
  753. expect(res.length).to.equal(2);
  754. expect(res[0]).to.equal(0x05);
  755. expect(res[1]).to.equal(0x44);
  756. });
  757. it("ORA Zero Page, X", function(){
  758. let res = asm.reset().compile("ORA $44,X").result();
  759. expect(res.length).to.equal(2);
  760. expect(res[0]).to.equal(0x15);
  761. expect(res[1]).to.equal(0x44);
  762. });
  763. it("ORA Absolute", function(){
  764. let res = asm.reset().compile("ORA $4400").result();
  765. expect(res.length).to.equal(3);
  766. expect(res[0]).to.equal(0x0D);
  767. expect(res[1]).to.equal(0x00);
  768. expect(res[2]).to.equal(0x44);
  769. });
  770. it("ORA Absolute, X", function(){
  771. let res = asm.reset().compile("ORA $4400,X").result();
  772. expect(res.length).to.equal(3);
  773. expect(res[0]).to.equal(0x1D);
  774. expect(res[1]).to.equal(0x00);
  775. expect(res[2]).to.equal(0x44);
  776. });
  777. it("ORA Absolute, Y", function(){
  778. let res = asm.reset().compile("ORA $4400,Y").result();
  779. expect(res.length).to.equal(3);
  780. expect(res[0]).to.equal(0x19);
  781. expect(res[1]).to.equal(0x00);
  782. expect(res[2]).to.equal(0x44);
  783. });
  784. it("ORA Indirect, X", function(){
  785. let res = asm.reset().compile("ORA ($44,X)").result();
  786. expect(res.length).to.equal(2);
  787. expect(res[0]).to.equal(0x01);
  788. expect(res[1]).to.equal(0x44);
  789. });
  790. it("ORA Indirect, Y", function(){
  791. let res = asm.reset().compile("ORA ($44), Y").result();
  792. expect(res.length).to.equal(2);
  793. expect(res[0]).to.equal(0x11);
  794. expect(res[1]).to.equal(0x44);
  795. });
  796. // -------------------------------------------------------------
  797. it("DEX", function(){
  798. asm.reset();
  799. let res = asm.compile("DEX").result();
  800. expect(res.length).to.equal(1);
  801. expect(res[0]).to.equal(0xCA);
  802. });
  803. it("DEY", function(){
  804. asm.reset();
  805. let res = asm.compile("DEY").result();
  806. expect(res.length).to.equal(1);
  807. expect(res[0]).to.equal(0x88);
  808. });
  809. it("INX", function(){
  810. asm.reset();
  811. let res = asm.compile("INX").result();
  812. expect(res.length).to.equal(1);
  813. expect(res[0]).to.equal(0xE8);
  814. });
  815. it("INY", function(){
  816. asm.reset();
  817. let res = asm.compile("INY").result();
  818. expect(res.length).to.equal(1);
  819. expect(res[0]).to.equal(0xC8);
  820. });
  821. it("TAX", function(){
  822. asm.reset();
  823. let res = asm.compile("TAX").result();
  824. expect(res.length).to.equal(1);
  825. expect(res[0]).to.equal(0xAA);
  826. });
  827. it("TAY", function(){
  828. asm.reset();
  829. let res = asm.compile("TAY").result();
  830. expect(res.length).to.equal(1);
  831. expect(res[0]).to.equal(0xA8);
  832. });
  833. it("TXA", function(){
  834. asm.reset();
  835. let res = asm.compile("TXA").result();
  836. expect(res.length).to.equal(1);
  837. expect(res[0]).to.equal(0x8A);
  838. });
  839. it("TYA", function(){
  840. asm.reset();
  841. let res = asm.compile("TYA").result();
  842. expect(res.length).to.equal(1);
  843. expect(res[0]).to.equal(0x98);
  844. });
  845. // -------------------------------------------------------------
  846. it("ROL Accumulator", function(){
  847. let res = asm.reset().compile("ROL A").result();
  848. expect(res.length).to.equal(1);
  849. expect(res[0]).to.equal(0x2A);
  850. });
  851. it("ROL Zero Page", function(){
  852. let res = asm.reset().compile("ROL $44").result();
  853. expect(res.length).to.equal(2);
  854. expect(res[0]).to.equal(0x26);
  855. expect(res[1]).to.equal(0x44);
  856. });
  857. it("ROL Zero Page, X", function(){
  858. let res = asm.reset().compile("ROL $44,X").result();
  859. expect(res.length).to.equal(2);
  860. expect(res[0]).to.equal(0x36);
  861. expect(res[1]).to.equal(0x44);
  862. });
  863. it("ROL Absolute", function(){
  864. let res = asm.reset().compile("ROL $4400").result();
  865. expect(res.length).to.equal(3);
  866. expect(res[0]).to.equal(0x2E);
  867. expect(res[1]).to.equal(0x00);
  868. expect(res[2]).to.equal(0x44);
  869. });
  870. it("ROL Absolute, X", function(){
  871. let res = asm.reset().compile("ROL $4400,X").result();
  872. expect(res.length).to.equal(3);
  873. expect(res[0]).to.equal(0x3E);
  874. expect(res[1]).to.equal(0x00);
  875. expect(res[2]).to.equal(0x44);
  876. });
  877. // -------------------------------------------------------------
  878. it("ROR Accumulator", function(){
  879. let res = asm.reset().compile("ROR A").result();
  880. expect(res.length).to.equal(1);
  881. expect(res[0]).to.equal(0x6A);
  882. });
  883. it("ROR Zero Page", function(){
  884. let res = asm.reset().compile("ROR $44").result();
  885. expect(res.length).to.equal(2);
  886. expect(res[0]).to.equal(0x66);
  887. expect(res[1]).to.equal(0x44);
  888. });
  889. it("ROR Zero Page, X", function(){
  890. let res = asm.reset().compile("ROR $44,X").result();
  891. expect(res.length).to.equal(2);
  892. expect(res[0]).to.equal(0x76);
  893. expect(res[1]).to.equal(0x44);
  894. });
  895. it("ROR Absolute", function(){
  896. let res = asm.reset().compile("ROR $4400").result();
  897. expect(res.length).to.equal(3);
  898. expect(res[0]).to.equal(0x6E);
  899. expect(res[1]).to.equal(0x00);
  900. expect(res[2]).to.equal(0x44);
  901. });
  902. it("ROR Absolute, X", function(){
  903. let res = asm.reset().compile("ROR $4400,X").result();
  904. expect(res.length).to.equal(3);
  905. expect(res[0]).to.equal(0x7E);
  906. expect(res[1]).to.equal(0x00);
  907. expect(res[2]).to.equal(0x44);
  908. });
  909. // -------------------------------------------------------------
  910. it("RTI", function(){
  911. asm.reset();
  912. let res = asm.compile("RTI").result();
  913. expect(res.length).to.equal(1);
  914. expect(res[0]).to.equal(0x40);
  915. });
  916. it("RTS", function(){
  917. asm.reset();
  918. let res = asm.compile("RTS").result();
  919. expect(res.length).to.equal(1);
  920. expect(res[0]).to.equal(0x60);
  921. });
  922. // -------------------------------------------------------------
  923. it("SBC Immediate", function(){
  924. let res = asm.reset().compile("SBC #$44").result();
  925. expect(res.length).to.equal(2);
  926. expect(res[0]).to.equal(0xE9);
  927. expect(res[1]).to.equal(0x44);
  928. });
  929. it("SBC Zero Page", function(){
  930. let res = asm.reset().compile("SBC $44").result();
  931. expect(res.length).to.equal(2);
  932. expect(res[0]).to.equal(0xE5);
  933. expect(res[1]).to.equal(0x44);
  934. });
  935. it("SBC Zero Page, X", function(){
  936. let res = asm.reset().compile("SBC $44,X").result();
  937. expect(res.length).to.equal(2);
  938. expect(res[0]).to.equal(0xF5);
  939. expect(res[1]).to.equal(0x44);
  940. });
  941. it("SBC Absolute", function(){
  942. let res = asm.reset().compile("SBC $4400").result();
  943. expect(res.length).to.equal(3);
  944. expect(res[0]).to.equal(0xED);
  945. expect(res[1]).to.equal(0x00);
  946. expect(res[2]).to.equal(0x44);
  947. });
  948. it("SBC Absolute, X", function(){
  949. let res = asm.reset().compile("SBC $4400,X").result();
  950. expect(res.length).to.equal(3);
  951. expect(res[0]).to.equal(0xFD);
  952. expect(res[1]).to.equal(0x00);
  953. expect(res[2]).to.equal(0x44);
  954. });
  955. it("SBC Absolute, Y", function(){
  956. let res = asm.reset().compile("SBC $4400,Y").result();
  957. expect(res.length).to.equal(3);
  958. expect(res[0]).to.equal(0xF9);
  959. expect(res[1]).to.equal(0x00);
  960. expect(res[2]).to.equal(0x44);
  961. });
  962. it("SBC Indirect, X", function(){
  963. let res = asm.reset().compile("SBC ($44,X)").result();
  964. expect(res.length).to.equal(2);
  965. expect(res[0]).to.equal(0xE1);
  966. expect(res[1]).to.equal(0x44);
  967. });
  968. it("SBC Indirect, Y", function(){
  969. let res = asm.reset().compile("SBC ($44),Y").result();
  970. expect(res.length).to.equal(2);
  971. expect(res[0]).to.equal(0xF1);
  972. expect(res[1]).to.equal(0x44);
  973. });
  974. // -------------------------------------------------------------
  975. it("STA Zero Page", function(){
  976. let res = asm.reset().compile("STA $44").result();
  977. expect(res.length).to.equal(2);
  978. expect(res[0]).to.equal(0x85);
  979. expect(res[1]).to.equal(0x44);
  980. });
  981. it("STA Zero Page, X", function(){
  982. let res = asm.reset().compile("STA $44,X").result();
  983. expect(res.length).to.equal(2);
  984. expect(res[0]).to.equal(0x95);
  985. expect(res[1]).to.equal(0x44);
  986. });
  987. it("STA Absolute", function(){
  988. let res = asm.reset().compile("STA $4400").result();
  989. expect(res.length).to.equal(3);
  990. expect(res[0]).to.equal(0x8D);
  991. expect(res[1]).to.equal(0x00);
  992. expect(res[2]).to.equal(0x44);
  993. });
  994. it("STA Absolute, X", function(){
  995. let res = asm.reset().compile("STA $4400,X").result();
  996. expect(res.length).to.equal(3);
  997. expect(res[0]).to.equal(0x9D);
  998. expect(res[1]).to.equal(0x00);
  999. expect(res[2]).to.equal(0x44);
  1000. });
  1001. it("STA Absolute, Y", function(){
  1002. let res = asm.reset().compile("STA $4400,Y").result();
  1003. expect(res.length).to.equal(3);
  1004. expect(res[0]).to.equal(0x99);
  1005. expect(res[1]).to.equal(0x00);
  1006. expect(res[2]).to.equal(0x44);
  1007. });
  1008. it("STA Indirect, X", function(){
  1009. let res = asm.reset().compile("STA ($44,X)").result();
  1010. expect(res.length).to.equal(2);
  1011. expect(res[0]).to.equal(0x81);
  1012. expect(res[1]).to.equal(0x44);
  1013. });
  1014. it("STA Indirect, Y", function(){
  1015. let res = asm.reset().compile("STA ($44),Y").result();
  1016. expect(res.length).to.equal(2);
  1017. expect(res[0]).to.equal(0x91);
  1018. expect(res[1]).to.equal(0x44);
  1019. });
  1020. // -------------------------------------------------------------
  1021. it("PHA", function(){
  1022. asm.reset();
  1023. let res = asm.compile("PHA").result();
  1024. expect(res.length).to.equal(1);
  1025. expect(res[0]).to.equal(0x48);
  1026. });
  1027. it("PHP", function(){
  1028. asm.reset();
  1029. let res = asm.compile("PHP").result();
  1030. expect(res.length).to.equal(1);
  1031. expect(res[0]).to.equal(0x08);
  1032. });
  1033. it("PLA", function(){
  1034. asm.reset();
  1035. let res = asm.compile("PLA").result();
  1036. expect(res.length).to.equal(1);
  1037. expect(res[0]).to.equal(0x68);
  1038. });
  1039. it("PLP", function(){
  1040. asm.reset();
  1041. let res = asm.compile("PLP").result();
  1042. expect(res.length).to.equal(1);
  1043. expect(res[0]).to.equal(0x28);
  1044. });
  1045. it("TSX", function(){
  1046. asm.reset();
  1047. let res = asm.compile("TSX").result();
  1048. expect(res.length).to.equal(1);
  1049. expect(res[0]).to.equal(0xBA);
  1050. });
  1051. it("TXS", function(){
  1052. asm.reset();
  1053. let res = asm.compile("TXS").result();
  1054. expect(res.length).to.equal(1);
  1055. expect(res[0]).to.equal(0x9A);
  1056. });
  1057. // -------------------------------------------------------------
  1058. it("STX Zero Page", function(){
  1059. let res = asm.reset().compile("STX $44").result();
  1060. expect(res.length).to.equal(2);
  1061. expect(res[0]).to.equal(0x86);
  1062. expect(res[1]).to.equal(0x44);
  1063. });
  1064. it("STX Zero Page, Y", function(){
  1065. let res = asm.reset().compile("STX $44, Y").result();
  1066. expect(res.length).to.equal(2);
  1067. expect(res[0]).to.equal(0x96);
  1068. expect(res[1]).to.equal(0x44);
  1069. });
  1070. it("STX Absolute", function(){
  1071. let res = asm.reset().compile("STX $4400").result();
  1072. expect(res.length).to.equal(3);
  1073. expect(res[0]).to.equal(0x8E);
  1074. expect(res[1]).to.equal(0x00);
  1075. expect(res[2]).to.equal(0x44);
  1076. });
  1077. // -------------------------------------------------------------
  1078. it("STY Zero Page", function(){
  1079. let res = asm.reset().compile("STY $44").result();
  1080. expect(res.length).to.equal(2);
  1081. expect(res[0]).to.equal(0x84);
  1082. expect(res[1]).to.equal(0x44);
  1083. });
  1084. it("STY Zero Page, X", function(){
  1085. let res = asm.reset().compile("sty $44,x").result();
  1086. expect(res.length).to.equal(2);
  1087. expect(res[0]).to.equal(0x94);
  1088. expect(res[1]).to.equal(0x44);
  1089. });
  1090. it("STY Absolute", function(){
  1091. let res = asm.reset().compile("STY $4400").result();
  1092. expect(res.length).to.equal(3);
  1093. expect(res[0]).to.equal(0x8C);
  1094. expect(res[1]).to.equal(0x00);
  1095. expect(res[2]).to.equal(0x44);
  1096. });
  1097. // -------------------------------------------------------------
  1098. });
  1099. });