Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

875 lines
26KB

  1. const expect = require('chai').expect;
  2. const Assembler = require('../src/chip/MOS6502/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");
  589. it("LDA Zero Page");
  590. it("LDA Zero Page, X");
  591. it("LDA Absolute");
  592. it("LDA Absolute, X");
  593. it("LDA Absolute, Y");
  594. it("LDA Indirect, X");
  595. it("LDA Indirect, Y");
  596. // -------------------------------------------------------------
  597. it("LDX Immediate");
  598. it("LDX Zero Page");
  599. it("LDX Zero Page, Y");
  600. it("LDX Absolute");
  601. it("LDX Absolute, Y");
  602. // -------------------------------------------------------------
  603. it("LDY Immediate");
  604. it("LDY Zero Page");
  605. it("LDY Zero Page, X");
  606. it("LDY Absolute");
  607. it("LDY Absolute, X");
  608. // -------------------------------------------------------------
  609. it("LSR Accumulator");
  610. it("LSR Zero Page");
  611. it("LSR Zero Page, X");
  612. it("LSR Absolute");
  613. it("LSR Absolute, X");
  614. // -------------------------------------------------------------
  615. it("NOP", function(){
  616. asm.reset();
  617. let res = asm.compile("NOP").result();
  618. expect(res.length).to.equal(1);
  619. expect(res[0]).to.equal(0xEA);
  620. });
  621. // -------------------------------------------------------------
  622. it("ORA Immediate");
  623. it("ORA Zero Page");
  624. it("ORA Zero Page, X");
  625. it("ORA Absolute");
  626. it("ORA Absolute, X");
  627. it("ORA Absolute, Y");
  628. it("ORA Indirect, X");
  629. it("ORA Indirect, Y");
  630. // -------------------------------------------------------------
  631. it("DEX", function(){
  632. asm.reset();
  633. let res = asm.compile("DEX").result();
  634. expect(res.length).to.equal(1);
  635. expect(res[0]).to.equal(0xCA);
  636. });
  637. it("DEY", function(){
  638. asm.reset();
  639. let res = asm.compile("DEY").result();
  640. expect(res.length).to.equal(1);
  641. expect(res[0]).to.equal(0x88);
  642. });
  643. it("INX", function(){
  644. asm.reset();
  645. let res = asm.compile("INX").result();
  646. expect(res.length).to.equal(1);
  647. expect(res[0]).to.equal(0xE8);
  648. });
  649. it("INY", function(){
  650. asm.reset();
  651. let res = asm.compile("INY").result();
  652. expect(res.length).to.equal(1);
  653. expect(res[0]).to.equal(0xC8);
  654. });
  655. it("TAX", function(){
  656. asm.reset();
  657. let res = asm.compile("TAX").result();
  658. expect(res.length).to.equal(1);
  659. expect(res[0]).to.equal(0xAA);
  660. });
  661. it("TAY", function(){
  662. asm.reset();
  663. let res = asm.compile("TAY").result();
  664. expect(res.length).to.equal(1);
  665. expect(res[0]).to.equal(0xA8);
  666. });
  667. it("TXA", function(){
  668. asm.reset();
  669. let res = asm.compile("TXA").result();
  670. expect(res.length).to.equal(1);
  671. expect(res[0]).to.equal(0x8A);
  672. });
  673. it("TYA", function(){
  674. asm.reset();
  675. let res = asm.compile("TYA").result();
  676. expect(res.length).to.equal(1);
  677. expect(res[0]).to.equal(0x98);
  678. });
  679. // -------------------------------------------------------------
  680. it("ROL Accumulator");
  681. it("ROL Zero Page");
  682. it("ROL Zero Page, X");
  683. it("ROL Absolute");
  684. it("ROL Absolute, X");
  685. // -------------------------------------------------------------
  686. it("ROR Accumulator");
  687. it("ROR Zero Page");
  688. it("ROR Zero Page, X");
  689. it("ROR Absolute");
  690. it("ROR Absolute, X");
  691. // -------------------------------------------------------------
  692. it("RTI", function(){
  693. asm.reset();
  694. let res = asm.compile("RTI").result();
  695. expect(res.length).to.equal(1);
  696. expect(res[0]).to.equal(0x40);
  697. });
  698. it("RTS", function(){
  699. asm.reset();
  700. let res = asm.compile("RTS").result();
  701. expect(res.length).to.equal(1);
  702. expect(res[0]).to.equal(0x60);
  703. });
  704. // -------------------------------------------------------------
  705. it("SBC Immediate");
  706. it("SBC Zero Page");
  707. it("SBC Zero Page, X");
  708. it("SBC Absolute");
  709. it("SBC Absolute, X");
  710. it("SBC Absolute, Y");
  711. it("SBC Indirect, X");
  712. it("SBC Indirect, Y");
  713. // -------------------------------------------------------------
  714. it("STA Zero Page");
  715. it("STA Zero Page, X");
  716. it("STA Absolute");
  717. it("STA Absolute, X");
  718. it("STA Absolute, Y");
  719. it("STA Indirect, X");
  720. it("STA Indirect, Y");
  721. // -------------------------------------------------------------
  722. it("PHA", function(){
  723. asm.reset();
  724. let res = asm.compile("PHA").result();
  725. expect(res.length).to.equal(1);
  726. expect(res[0]).to.equal(0x48);
  727. });
  728. it("PHP", function(){
  729. asm.reset();
  730. let res = asm.compile("PHP").result();
  731. expect(res.length).to.equal(1);
  732. expect(res[0]).to.equal(0x08);
  733. });
  734. it("PLA", function(){
  735. asm.reset();
  736. let res = asm.compile("PLA").result();
  737. expect(res.length).to.equal(1);
  738. expect(res[0]).to.equal(0x68);
  739. });
  740. it("PLP", function(){
  741. asm.reset();
  742. let res = asm.compile("PLP").result();
  743. expect(res.length).to.equal(1);
  744. expect(res[0]).to.equal(0x28);
  745. });
  746. it("TSX", function(){
  747. asm.reset();
  748. let res = asm.compile("TSX").result();
  749. expect(res.length).to.equal(1);
  750. expect(res[0]).to.equal(0xBA);
  751. });
  752. it("TXS", function(){
  753. asm.reset();
  754. let res = asm.compile("TXS").result();
  755. expect(res.length).to.equal(1);
  756. expect(res[0]).to.equal(0x9A);
  757. });
  758. // -------------------------------------------------------------
  759. it("STX Zero Page");
  760. it("STX Zero Page, Y");
  761. it("STX Absolute");
  762. // -------------------------------------------------------------
  763. it("STY Zero Page");
  764. it("STY Zero Page, X");
  765. it("STY Absolute");
  766. // -------------------------------------------------------------
  767. });
  768. });