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.

184 lines
4.7KB

  1. const expect = require('chai').expect;
  2. const CPU = require('../src/chip/MOS6502/cpu.js');
  3. const Mem = require('../src/memory');
  4. describe("Testing MOS6502 CPU...", function(){
  5. var cpu = new CPU();
  6. var tick = cpu.clk();
  7. cpu.memory = new Mem.Memory.RAM(64);
  8. cpu.memory.load(0xFFFC, [0x00, 0x00]);
  9. it("Resetting (IRQ Disabled flag must be on", function(){
  10. cpu.reset = true;
  11. tick(); // One tick to handle resets.
  12. expect(cpu.I).to.equal(1);
  13. expect(cpu.PC).to.equal(0); // Test program counter set to the vector stored at 0xFFFC - 0xFFFD
  14. });
  15. describe("Testing flag set/clear calls...", function(){
  16. it("CLC / SEC", function(){
  17. cpu.memory.clearPage(0);
  18. cpu.memory.load(0, [0x18, 0x38]);
  19. cpu.reset = true;
  20. tick(); // reset.
  21. tick(); tick(); // Two ticks to process opcode.
  22. console.log(cpu);
  23. expect(cpu.C).to.equal(0);
  24. tick(); tick();
  25. //console.log(cpu)
  26. expect(cpu.C).to.equal(1);
  27. });
  28. it("CLI / SEI", function(){
  29. cpu.memory.clearPage(0);
  30. cpu.memory.load(0, [0x58, 0x78]);
  31. cpu.reset = true;
  32. tick();
  33. tick(); tick();
  34. expect(cpu.I).to.equal(0);
  35. tick(); tick();
  36. expect(cpu.I).to.equal(1);
  37. });
  38. it("CLD / SED", function(){
  39. cpu.memory.clearPage(0);
  40. cpu.memory.load(0, [0xD8, 0xF8]);
  41. cpu.reset = true;
  42. tick();
  43. tick(); tick();
  44. expect(cpu.D).to.equal(0);
  45. tick(); tick();
  46. expect(cpu.D).to.equal(1);
  47. });
  48. it("CLV", function(){
  49. cpu.memory.clearPage(0);
  50. cpu.memory.load(0, [0xB8]);
  51. cpu.reset = true;
  52. tick();
  53. tick(); tick();
  54. expect(cpu.V).to.equal(0);
  55. });
  56. });
  57. describe("Testing LDA...", function(){
  58. it("LDA Immediate", function(){
  59. cpu.memory.clearPage(0);
  60. cpu.memory.load(0, [0xA9, 0x01, 0xA9, 0xBB]);
  61. cpu.reset = true;
  62. tick();
  63. tick();
  64. tick();
  65. expect(cpu.A).to.equal(0x01);
  66. tick();
  67. expect(cpu.A).to.equal(0x01);
  68. tick();
  69. expect(cpu.A).to.equal(0xBB);
  70. });
  71. it("LDA Zero Page");
  72. it("LDA Zero Page, X");
  73. it("LDA Absolute");
  74. it("LDA Absolute, X");
  75. it("LDA Absolute, Y");
  76. it("LDA Indirect, X");
  77. it("LDA Indirect, Y");
  78. });
  79. describe("Testing ADC...", function(){
  80. it("ADC Immediate", function(){
  81. cpu.memory.clearPage(0);
  82. // CLC
  83. // CLV
  84. // CLD
  85. // CLI
  86. // LDA $00
  87. // ADC $01
  88. // ADC $01
  89. cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0xA9, 0x00, 0x69, 0x01, 0x69, 0x01]);
  90. cpu.reset = true;
  91. tick();
  92. // Getting through the 4 clear flag calls. Each should take 2 ticks.
  93. tick(); tick(); tick(); tick(); tick(); tick(); tick(); tick();
  94. // Next two ticks for the LDA call
  95. tick(); tick();
  96. // Now processing the adds.
  97. expect(cpu.A).to.equal(0);
  98. tick();
  99. expect(cpu.A).to.equal(0);
  100. tick();
  101. expect(cpu.A).to.equal(1);
  102. tick();
  103. expect(cpu.A).to.equal(1);
  104. tick();
  105. expect(cpu.A).to.equal(2);
  106. });
  107. it("ADC Zero Page");
  108. it("ADC Zero Page, X");
  109. it("ADC Absolute");
  110. it("ADC Absolute, X");
  111. it("ADC Absolute, Y");
  112. it("ADC Indirect, X");
  113. it("ADC Indirect, Y");
  114. it ("ADC Test Zero flag"/*, function(){
  115. cpu.memory.clearPage(0);
  116. cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0x69, 0xFF, 0x69, 0x01]);
  117. // Getting through the 4 clear flag calls. Each should take 2 ticks.
  118. tick(); tick(); tick(); tick(); tick(); tick(); tick(); tick();
  119. // Now processing the adds.
  120. expect(cpu.A).to.equal(0);
  121. tick();
  122. expect(cpu.A).to.equal(0);
  123. tick();
  124. expect(cpu.A).to.equal(1);
  125. tick();
  126. expect(cpu.A).to.equal(1);
  127. tick();
  128. expect(cpu.A).to.equal(2);
  129. }*/);
  130. });
  131. describe("Testing SBC...", function(){
  132. it("SBC Immediate", function(){
  133. cpu.memory.clearPage(0);
  134. // SEC
  135. // CLV
  136. // CLD
  137. // CLI
  138. // LDA $00
  139. // SBC $01
  140. // SBC $01
  141. cpu.memory.load(0, [0x38, 0xB8, 0xD8, 0x58, 0xA9, 0x00, 0xE9, 0x01, 0xE9, 0x01]);
  142. cpu.reset = true;
  143. tick();
  144. // Getting through the 1 set and 3 clear flag calls. Each should take 2 ticks.
  145. tick(); tick(); tick(); tick(); tick(); tick(); tick(); tick();
  146. // Next two ticks for the LDA call
  147. tick(); tick();
  148. // Now processing the subtractions.
  149. expect(cpu.A).to.equal(0);
  150. tick();
  151. expect(cpu.A).to.equal(0);
  152. tick();
  153. expect(cpu.A).to.equal(0xFF);
  154. tick();
  155. expect(cpu.A).to.equal(0xFF);
  156. tick();
  157. expect(cpu.A).to.equal(0xFE);
  158. });
  159. it("SBC Zero Page");
  160. it("SBC Zero Page, X");
  161. it("SBC Absolute");
  162. it("SBC Absolute, X");
  163. it("SBC Absolute, Y");
  164. it("SBC Indirect, X");
  165. it("SBC Indirect, Y");
  166. });
  167. });