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.

114 lines
2.9KB

  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 ADC...", function(){
  51. it("ADC Immediate", function(){
  52. cpu.memory.clearPage(0);
  53. // CLC
  54. // CLV
  55. // CLD
  56. // CLI
  57. // ADC $01
  58. // ADC $01
  59. cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0x69, 0x01, 0x69, 0x01]);
  60. cpu.reset();
  61. // Getting through the 4 clear flag calls. Each should take 2 ticks.
  62. tick(); tick(); tick(); tick(); tick(); tick(); tick(); tick();
  63. // Now processing the adds.
  64. expect(cpu.A).to.equal(0);
  65. tick();
  66. expect(cpu.A).to.equal(0);
  67. tick();
  68. expect(cpu.A).to.equal(1);
  69. tick();
  70. expect(cpu.A).to.equal(1);
  71. tick();
  72. expect(cpu.A).to.equal(2);
  73. });
  74. it("ADC Zero Page");
  75. it("ADC Zero Page, X");
  76. it("ADC Absolute");
  77. it("ADC Absolute, X");
  78. it("ADC Absolute, Y");
  79. it("ADC Indirect, X");
  80. it("ADC Indirect, Y");
  81. it ("ADC Test Zero flag", /*function(){
  82. cpu.memory.clearPage(0);
  83. cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0x69, 0xFF, 0x69, 0x01]);
  84. // Getting through the 4 clear flag calls. Each should take 2 ticks.
  85. tick(); tick(); tick(); tick(); tick(); tick(); tick(); tick();
  86. // Now processing the adds.
  87. expect(cpu.A).to.equal(0);
  88. tick();
  89. expect(cpu.A).to.equal(0);
  90. tick();
  91. expect(cpu.A).to.equal(1);
  92. tick();
  93. expect(cpu.A).to.equal(1);
  94. tick();
  95. expect(cpu.A).to.equal(2);
  96. }*/);
  97. });
  98. });