Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

474 行
13KB

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