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.

479 lines
14KB

  1. const expect = require('chai').expect;
  2. const mos6502 = require('../src/MOS6502.js');
  3. describe("Testing MOS6502 Systems...", function(){
  4. describe("Testing MOS6502 Assembler...", function(){
  5. var asm = new mos6502.Assembler();
  6. it(".reset()", function(){
  7. asm.compile("ADC $44");
  8. asm.reset();
  9. expect(asm.PC).to.equal(0);
  10. expect(Object.keys(asm.variables).length).to.equal(0);
  11. expect(Object.keys(asm.jumplabels).length).to.equal(0);
  12. expect(asm.result().length).to.equal(0);
  13. });
  14. it(".result()", function(){
  15. asm.reset();
  16. asm.compile("ADC $44");
  17. expect(asm.result().length).to.be.gt(0);
  18. });
  19. describe(".compile()", function(){
  20. it(".define directive", function(){
  21. asm.compile(".define TAG $44");
  22. let vars = asm.variables;
  23. expect(vars).to.have.key('TAG');
  24. expect(vars['TAG']).to.equal(0x44);
  25. });
  26. it("Jump labels", function(){
  27. let pc = asm.PC;
  28. asm.compile("loop:\nBNE loop");
  29. let jmp = asm.jumplabels;
  30. expect(jmp).to.have.key('loop');
  31. expect(jmp['loop']).to.equal(pc);
  32. });
  33. it(".bytes directive", function(){
  34. let res = asm.reset().compile(".BYTES $44, $55, $66, $77, b10110101, 128").result();
  35. expect(res.length).to.equal(6);
  36. expect(res[0]).to.equal(0x44);
  37. expect(res[1]).to.equal(0x55);
  38. expect(res[2]).to.equal(0x66);
  39. expect(res[3]).to.equal(0x77);
  40. expect(res[4]).to.equal(parseInt('10110101', 2));
  41. expect(res[5]).to.equal(128);
  42. });
  43. it("Jump label before and after .byte directive", function(){
  44. asm.reset();
  45. let pc1 = asm.PC;
  46. asm.compile("bytes: .bytes $44, $55, $66, $77");
  47. let pc2 = asm.PC;
  48. asm.compile("loop: BNE loop");
  49. let jmp = asm.jumplabels;
  50. //expect(jmp).to.have.key('bytes');
  51. expect(jmp['bytes']).to.equal(pc1);
  52. //expect(jmp).to.have.key('loop');
  53. expect(jmp['loop']).to.equal(pc2);
  54. let res = asm.result();
  55. expect(res.length).to.equal(6);
  56. expect(res[0]).to.equal(0x44);
  57. expect(res[1]).to.equal(0x55);
  58. expect(res[2]).to.equal(0x66);
  59. expect(res[3]).to.equal(0x77);
  60. expect(res[4]).to.equal(0xD0);
  61. expect(res[5]).to.equal(0xFE);
  62. });
  63. it("ADC Immediate", function(){
  64. asm.reset();
  65. asm.compile("ADC #$44");
  66. let res = asm.result();
  67. expect(res.length).to.equal(2);
  68. expect(res[0]).to.equal(0x69);
  69. expect(res[1]).to.equal(0x44);
  70. });
  71. it("ADC Zero Page", function(){
  72. asm.reset();
  73. asm.compile("ADC $44");
  74. let res = asm.result();
  75. expect(res.length).to.equal(2);
  76. expect(res[0]).to.equal(0x65);
  77. expect(res[1]).to.equal(0x44);
  78. });
  79. it("ADC Zero Page, X", function(){
  80. asm.reset();
  81. asm.compile("ADC $44, X");
  82. let res = asm.result();
  83. expect(res.length).to.equal(2);
  84. expect(res[0]).to.equal(0x75);
  85. expect(res[1]).to.equal(0x44);
  86. });
  87. it("ADC Absolute", function(){
  88. asm.reset();
  89. asm.compile("ADC $4400");
  90. let res = asm.result();
  91. expect(res.length).to.equal(3);
  92. expect(res[0]).to.equal(0x6D);
  93. expect(res[1]).to.equal(0x00);
  94. expect(res[2]).to.equal(0x44);
  95. });
  96. it("ADC Absolute, X", function(){
  97. asm.reset();
  98. asm.compile("ADC $4400,X");
  99. let res = asm.result();
  100. expect(res.length).to.equal(3);
  101. expect(res[0]).to.equal(0x7D);
  102. expect(res[1]).to.equal(0x00);
  103. expect(res[2]).to.equal(0x44);
  104. });
  105. it("ADC Absolute, Y", function(){
  106. asm.reset();
  107. asm.compile("ADC $4400, Y");
  108. let res = asm.result();
  109. expect(res.length).to.equal(3);
  110. expect(res[0]).to.equal(0x79);
  111. expect(res[1]).to.equal(0x00);
  112. expect(res[2]).to.equal(0x44);
  113. });
  114. it("ADC Indirect, X", function(){
  115. asm.reset();
  116. asm.compile("ADC ($44,X)");
  117. let res = asm.result();
  118. expect(res.length).to.equal(2);
  119. expect(res[0]).to.equal(0x61);
  120. expect(res[1]).to.equal(0x44);
  121. });
  122. it("ADC Indirect, Y", function(){
  123. asm.reset();
  124. asm.compile("ADC ($44), Y");
  125. let res = asm.result();
  126. expect(res.length).to.equal(2);
  127. expect(res[0]).to.equal(0x71);
  128. expect(res[1]).to.equal(0x44);
  129. });
  130. // -------------------------------------------------------------
  131. it("AND Immediate");
  132. it("AND Zero Page");
  133. it("AND Zero Page, X");
  134. it("AND Absolute");
  135. it("AND Absolute, X");
  136. it("AND Absolute, Y");
  137. it("AND Indirect, X");
  138. it("AND Indirect, Y");
  139. // -------------------------------------------------------------
  140. it("ASL Accumulator");
  141. it("ASL Zero Page");
  142. it("ASL Zero Page, X");
  143. it("ASL Absolute");
  144. it("ASL Absolute, X");
  145. // -------------------------------------------------------------
  146. it("BIT Zero Page");
  147. it("BIT Absolute");
  148. // -------------------------------------------------------------
  149. it("BPL");
  150. it("BMI");
  151. it("BVC");
  152. it("BVS");
  153. it("BCC");
  154. it("BCS");
  155. it("BNE");
  156. it("BEQ");
  157. // -------------------------------------------------------------
  158. it ("BRK", function(){
  159. asm.reset();
  160. let res = asm.compile("BRK").result();
  161. expect(res.length).to.equal(1);
  162. expect(res[0]).to.equal(0x00);
  163. });
  164. // -------------------------------------------------------------
  165. it("CMP Immediate");
  166. it("CMP Zero Page");
  167. it("CMP Zero Page, X");
  168. it("CMP Absolute");
  169. it("CMP Absolute, X");
  170. it("CMP Absolute, Y");
  171. it("CMP Indirect, X");
  172. it("CMP Indirect, Y");
  173. // -------------------------------------------------------------
  174. it("CPX Immediate");
  175. it("CPX Zero Page");
  176. it("CPX Absolute");
  177. // -------------------------------------------------------------
  178. it("CPY Immediate");
  179. it("CPY Zero Page");
  180. it("CPY Absolute");
  181. // -------------------------------------------------------------
  182. it("DEC Zero Page");
  183. it("DEC Zero Page, X");
  184. it("DEC Absolute");
  185. it("DEC Absolute, X");
  186. // -------------------------------------------------------------
  187. it("EOR Immediate");
  188. it("EOR Zero Page");
  189. it("EOR Zero Page, X");
  190. it("EOR Absolute");
  191. it("EOR Absolute, X");
  192. it("EOR Absolute, Y");
  193. it("EOR Indirect, X");
  194. it("EOR Indirect, Y");
  195. // -------------------------------------------------------------
  196. it("CLC", function(){
  197. asm.reset();
  198. let res = asm.compile("CLC").result();
  199. expect(res.length).to.equal(1);
  200. expect(res[0]).to.equal(0x18);
  201. });
  202. it("CLD", function(){
  203. asm.reset();
  204. let res = asm.compile("CLD").result();
  205. expect(res.length).to.equal(1);
  206. expect(res[0]).to.equal(0xD8);
  207. });
  208. it("CLI", function(){
  209. asm.reset();
  210. let res = asm.compile("CLI").result();
  211. expect(res.length).to.equal(1);
  212. expect(res[0]).to.equal(0x58);
  213. });
  214. it("CLV", function(){
  215. asm.reset();
  216. let res = asm.compile("CLV").result();
  217. expect(res.length).to.equal(1);
  218. expect(res[0]).to.equal(0xB8);
  219. });
  220. it("SEC", function(){
  221. asm.reset();
  222. let res = asm.compile("SEC").result();
  223. expect(res.length).to.equal(1);
  224. expect(res[0]).to.equal(0x38);
  225. });
  226. it("SED", function(){
  227. asm.reset();
  228. let res = asm.compile("SED").result();
  229. expect(res.length).to.equal(1);
  230. expect(res[0]).to.equal(0xF8);
  231. });
  232. it("SEI", function(){
  233. asm.reset();
  234. let res = asm.compile("SEI").result();
  235. expect(res.length).to.equal(1);
  236. expect(res[0]).to.equal(0x78);
  237. });
  238. // -------------------------------------------------------------
  239. it("INC Zero Page");
  240. it("INC Zero Page, X");
  241. it("INC Absolute");
  242. it("INC Absolute, X");
  243. // -------------------------------------------------------------
  244. it("JMP Absolute");
  245. it("JMP Indirect");
  246. // -------------------------------------------------------------
  247. it("JRS Absolute");
  248. // -------------------------------------------------------------
  249. it("LDA Immediate");
  250. it("LDA Zero Page");
  251. it("LDA Zero Page, X");
  252. it("LDA Absolute");
  253. it("LDA Absolute, X");
  254. it("LDA Absolute, Y");
  255. it("LDA Indirect, X");
  256. it("LDA Indirect, Y");
  257. // -------------------------------------------------------------
  258. it("LDX Immediate");
  259. it("LDX Zero Page");
  260. it("LDX Zero Page, Y");
  261. it("LDX Absolute");
  262. it("LDX Absolute, Y");
  263. // -------------------------------------------------------------
  264. it("LDY Immediate");
  265. it("LDY Zero Page");
  266. it("LDY Zero Page, X");
  267. it("LDY Absolute");
  268. it("LDY Absolute, X");
  269. // -------------------------------------------------------------
  270. it("LSR Accumulator");
  271. it("LSR Zero Page");
  272. it("LSR Zero Page, X");
  273. it("LSR Absolute");
  274. it("LSR Absolute, X");
  275. // -------------------------------------------------------------
  276. it("NOP", function(){
  277. asm.reset();
  278. let res = asm.compile("NOP").result();
  279. expect(res.length).to.equal(1);
  280. expect(res[0]).to.equal(0xEA);
  281. });
  282. // -------------------------------------------------------------
  283. it("ORA Immediate");
  284. it("ORA Zero Page");
  285. it("ORA Zero Page, X");
  286. it("ORA Absolute");
  287. it("ORA Absolute, X");
  288. it("ORA Absolute, Y");
  289. it("ORA Indirect, X");
  290. it("ORA Indirect, Y");
  291. // -------------------------------------------------------------
  292. it("DEX", function(){
  293. asm.reset();
  294. let res = asm.compile("DEX").result();
  295. expect(res.length).to.equal(1);
  296. expect(res[0]).to.equal(0xCA);
  297. });
  298. it("DEY", function(){
  299. asm.reset();
  300. let res = asm.compile("DEY").result();
  301. expect(res.length).to.equal(1);
  302. expect(res[0]).to.equal(0x88);
  303. });
  304. it("INX", function(){
  305. asm.reset();
  306. let res = asm.compile("INX").result();
  307. expect(res.length).to.equal(1);
  308. expect(res[0]).to.equal(0xE8);
  309. });
  310. it("INY", function(){
  311. asm.reset();
  312. let res = asm.compile("INY").result();
  313. expect(res.length).to.equal(1);
  314. expect(res[0]).to.equal(0xC8);
  315. });
  316. it("TAX", function(){
  317. asm.reset();
  318. let res = asm.compile("TAX").result();
  319. expect(res.length).to.equal(1);
  320. expect(res[0]).to.equal(0xAA);
  321. });
  322. it("TAY", function(){
  323. asm.reset();
  324. let res = asm.compile("TAY").result();
  325. expect(res.length).to.equal(1);
  326. expect(res[0]).to.equal(0xA8);
  327. });
  328. it("TXA", function(){
  329. asm.reset();
  330. let res = asm.compile("TXA").result();
  331. expect(res.length).to.equal(1);
  332. expect(res[0]).to.equal(0x8A);
  333. });
  334. it("TYA", function(){
  335. asm.reset();
  336. let res = asm.compile("TYA").result();
  337. expect(res.length).to.equal(1);
  338. expect(res[0]).to.equal(0x98);
  339. });
  340. // -------------------------------------------------------------
  341. it("ROL Accumulator");
  342. it("ROL Zero Page");
  343. it("ROL Zero Page, X");
  344. it("ROL Absolute");
  345. it("ROL Absolute, X");
  346. // -------------------------------------------------------------
  347. it("ROR Accumulator");
  348. it("ROR Zero Page");
  349. it("ROR Zero Page, X");
  350. it("ROR Absolute");
  351. it("ROR Absolute, X");
  352. // -------------------------------------------------------------
  353. it("RTI", function(){
  354. asm.reset();
  355. let res = asm.compile("RTI").result();
  356. expect(res.length).to.equal(1);
  357. expect(res[0]).to.equal(0x40);
  358. });
  359. it("RTS", function(){
  360. asm.reset();
  361. let res = asm.compile("RTS").result();
  362. expect(res.length).to.equal(1);
  363. expect(res[0]).to.equal(0x60);
  364. });
  365. // -------------------------------------------------------------
  366. it("SBC Immediate");
  367. it("SBC Zero Page");
  368. it("SBC Zero Page, X");
  369. it("SBC Absolute");
  370. it("SBC Absolute, X");
  371. it("SBC Absolute, Y");
  372. it("SBC Indirect, X");
  373. it("SBC Indirect, Y");
  374. // -------------------------------------------------------------
  375. it("STA Zero Page");
  376. it("STA Zero Page, X");
  377. it("STA Absolute");
  378. it("STA Absolute, X");
  379. it("STA Absolute, Y");
  380. it("STA Indirect, X");
  381. it("STA Indirect, Y");
  382. // -------------------------------------------------------------
  383. it("PHA", function(){
  384. asm.reset();
  385. let res = asm.compile("PHA").result();
  386. expect(res.length).to.equal(1);
  387. expect(res[0]).to.equal(0x48);
  388. });
  389. it("PHP", function(){
  390. asm.reset();
  391. let res = asm.compile("PHP").result();
  392. expect(res.length).to.equal(1);
  393. expect(res[0]).to.equal(0x08);
  394. });
  395. it("PLA", function(){
  396. asm.reset();
  397. let res = asm.compile("PLA").result();
  398. expect(res.length).to.equal(1);
  399. expect(res[0]).to.equal(0x68);
  400. });
  401. it("PLP", function(){
  402. asm.reset();
  403. let res = asm.compile("PLP").result();
  404. expect(res.length).to.equal(1);
  405. expect(res[0]).to.equal(0x28);
  406. });
  407. it("TSX", function(){
  408. asm.reset();
  409. let res = asm.compile("TSX").result();
  410. expect(res.length).to.equal(1);
  411. expect(res[0]).to.equal(0xBA);
  412. });
  413. it("TXS", function(){
  414. asm.reset();
  415. let res = asm.compile("TXS").result();
  416. expect(res.length).to.equal(1);
  417. expect(res[0]).to.equal(0x9A);
  418. });
  419. // -------------------------------------------------------------
  420. it("STX Zero Page");
  421. it("STX Zero Page, Y");
  422. it("STX Absolute");
  423. // -------------------------------------------------------------
  424. it("STY Zero Page");
  425. it("STY Zero Page, X");
  426. it("STY Absolute");
  427. // -------------------------------------------------------------
  428. });
  429. });
  430. describe("Testing MOS6502 CPU...", function(){
  431. it("Something here...");
  432. });
  433. });