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.

182 lines
4.7KB

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