Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

174 lines
4.5KB

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