Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

204 行
5.4KB

  1. const expect = require('chai').expect;
  2. const MOS6502 = require('../src/MOS6502');
  3. const Mem = require('../src/memory');
  4. describe("Testing MOS6502 CPU...", function(){
  5. var asm = new MOS6502.Assembler();
  6. var cpu = new MOS6502.CPU();
  7. var tick = cpu.clk();
  8. cpu.memory = new Mem.Memory.RAM(256);
  9. cpu.memory.load(0xFFFC, [0x00, 0x00]);
  10. it("Resetting (IRQ Disabled flag must be on", function(){
  11. cpu.reset = true;
  12. tick(); // One tick to handle resets.
  13. expect(cpu.I).to.equal(1);
  14. expect(cpu.PC).to.equal(0); // Test program counter set to the vector stored at 0xFFFC - 0xFFFD
  15. });
  16. describe("Testing flag set/clear calls...", function(){
  17. it("CLC / SEC", function(){
  18. cpu.memory.clearPage(0);
  19. cpu.memory.load(0, [0x18, 0x38]);
  20. cpu.reset = true;
  21. tick(); // reset.
  22. tick(); tick(); // Two ticks to process opcode.
  23. expect(cpu.C).to.equal(0);
  24. tick(); tick();
  25. expect(cpu.C).to.equal(1);
  26. });
  27. it("CLI / SEI", function(){
  28. cpu.memory.clearPage(0);
  29. cpu.memory.load(0, [0x58, 0x78]);
  30. cpu.reset = true;
  31. tick();
  32. tick(); tick();
  33. expect(cpu.I).to.equal(0);
  34. tick(); tick();
  35. expect(cpu.I).to.equal(1);
  36. });
  37. it("CLD / SED", function(){
  38. cpu.memory.clearPage(0);
  39. cpu.memory.load(0, [0xD8, 0xF8]);
  40. cpu.reset = true;
  41. tick();
  42. tick(); tick();
  43. expect(cpu.D).to.equal(0);
  44. tick(); tick();
  45. expect(cpu.D).to.equal(1);
  46. });
  47. it("CLV", function(){
  48. cpu.memory.clearPage(0);
  49. cpu.memory.load(0, [0xB8]);
  50. cpu.reset = true;
  51. tick();
  52. tick(); tick();
  53. expect(cpu.V).to.equal(0);
  54. });
  55. });
  56. describe("Testing LDA...", function(){
  57. it("LDA Immediate", function(){
  58. let prg = "LDA #$01\n";
  59. prg += "LDA #$BB";
  60. asm.reset().compile(prg);
  61. cpu.memory.clearPage(0);
  62. cpu.memory.load(0, asm.result());
  63. cpu.reset = true;
  64. tick();
  65. tick();
  66. tick();
  67. expect(cpu.A).to.equal(0x01);
  68. tick();
  69. expect(cpu.A).to.equal(0x01);
  70. tick();
  71. expect(cpu.A).to.equal(0xBB);
  72. });
  73. it("LDA Zero Page");
  74. it("LDA Zero Page, X");
  75. it("LDA Absolute");
  76. it("LDA Absolute, X");
  77. it("LDA Absolute, Y");
  78. it("LDA Indirect, X");
  79. it("LDA Indirect, Y");
  80. });
  81. describe("Testing ADC...", function(){
  82. describe("ADC Binary Mode...", function(){
  83. it("ADC Immediate", function(){
  84. let prg = "CLC\n";
  85. prg += "CLV\n";
  86. prg += "CLD\n";
  87. prg += "CLI\n";
  88. prg += "LDA #$00\n";
  89. prg += "ADC #$01\n";
  90. prg += "ADC #$01\n";
  91. asm.reset().compile(prg);
  92. cpu.memory.clearPage(0);
  93. cpu.memory.load(0, asm.result());
  94. cpu.reset = true;
  95. tick(); // To reset;
  96. while (cpu.PC !== 10){
  97. switch(cpu.PC){
  98. case 6:
  99. expect(cpu.A).to.equal(0); break;
  100. case 8:
  101. expect(cpu.A).to.equal(1); break;
  102. case 10:
  103. expect(cpu.A).to.equal(2); break;
  104. }
  105. tick();
  106. }
  107. });
  108. it("ADC Zero Page");
  109. it("ADC Zero Page, X");
  110. it("ADC Absolute");
  111. it("ADC Absolute, X");
  112. it("ADC Absolute, Y");
  113. it("ADC Indirect, X");
  114. it("ADC Indirect, Y");
  115. });
  116. describe("ADC Decimal (BCD) Mode...", function(){
  117. it("ADC Immediate");
  118. it("ADC Zero Page");
  119. it("ADC Zero Page, X");
  120. it("ADC Absolute");
  121. it("ADC Absolute, X");
  122. it("ADC Absolute, Y");
  123. it("ADC Indirect, X");
  124. it("ADC Indirect, Y");
  125. });
  126. });
  127. describe("Testing SBC...", function(){
  128. describe("SBC Binary Mode...", function(){
  129. it("SBC Immediate", function(){
  130. let prg = "SEC\n";
  131. prg += "CLV\n";
  132. prg += "CLD\n";
  133. prg += "CLI\n";
  134. prg += "LDA #$01\n";
  135. prg += "SBC #$01\n";
  136. prg += "SBC #$01";
  137. asm.reset().compile(prg);
  138. cpu.memory.clearPage(0);
  139. cpu.memory.load(0, asm.result());
  140. cpu.reset = true;
  141. tick(); // To reset;
  142. while(cpu.PC !== 11){
  143. // NOTE TO SELF: Depending on the OP code, these tests could be
  144. // checked multiple times, as the cpu may sit at a program cntr
  145. // for a couple cycles depending on the OP.
  146. switch(cpu.PC){
  147. case 1:
  148. expect(cpu.C).to.be.equal(1); break;
  149. case 6:
  150. expect(cpu.A).to.be.equal(0x01); break;
  151. case 8:
  152. expect(cpu.A).to.be.equal(0x00);
  153. expect(cpu.C).to.be.equal(1);
  154. expect(cpu.Z).to.be.equal(1);
  155. expect(cpu.N).to.be.equal(0);
  156. break;
  157. case 9:
  158. expect(cpu.A).to.be.equal(0xFF);
  159. expect(cpu.C).to.be.equal(0);
  160. expect(cpu.Z).to.be.equal(0);
  161. expect(cpu.N).to.be.equal(1);
  162. break;
  163. }
  164. tick();
  165. }
  166. });
  167. it("SBC Zero Page");
  168. it("SBC Zero Page, X");
  169. it("SBC Absolute");
  170. it("SBC Absolute, X");
  171. it("SBC Absolute, Y");
  172. it("SBC Indirect, X");
  173. it("SBC Indirect, Y");
  174. });
  175. describe("SBC Decimal (BCD) Mode...", function(){
  176. it("SBC Immediate");
  177. it("SBC Zero Page");
  178. it("SBC Zero Page, X");
  179. it("SBC Absolute");
  180. it("SBC Absolute, X");
  181. it("SBC Absolute, Y");
  182. it("SBC Indirect, X");
  183. it("SBC Indirect, Y");
  184. });
  185. });
  186. });