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

443 lines
13KB

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