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

63 行
1.1KB

  1. const mos6502 = require("./src/chip/MOS6502");
  2. const Bank = require("./src/common/bank.js");
  3. function toHex(v){
  4. let r = v.toString(16);
  5. return (r.length < 2) ? "0" + r : r;
  6. }
  7. function printBytes(b, acc){
  8. var out = "";
  9. for (let i=0; i < b.length; i++){
  10. if (i % acc === 0 && out !== ""){
  11. console.log(out);
  12. out = ""
  13. } else {
  14. out += toHex(b[i]) + " ";
  15. }
  16. }
  17. console.log(out);
  18. }
  19. var asm = new mos6502.Assembler();
  20. var cpu = new mos6502.CPU();
  21. cpu.memory = new Bank(65536);
  22. cpu.memory.clear();
  23. var tick = cpu.clk();
  24. var src = "SEC\n";
  25. src += "CLV\n";
  26. src += "CLD\n";
  27. src += "CLI\n";
  28. src += "LDA #$00\n";
  29. src += "SBC #$01\n";
  30. src += "CLC\n";
  31. src += "ADC #$01";
  32. var res = asm.compile(src).result();
  33. printBytes(res, 16);
  34. cpu.memory.load(0, res);
  35. var page = [];
  36. for (let i = 0; i < 256; i++){
  37. cpu.memory.address = i;
  38. page.push(cpu.memory.byte);
  39. }
  40. printBytes(page, 16);
  41. cpu.reset();
  42. //console.log(cpu.PC);
  43. //return;
  44. tick(); tick();
  45. tick(); tick();
  46. tick(); tick();
  47. tick(); tick();
  48. tick(); tick();
  49. console.log("A: " + cpu.A);
  50. tick(); tick();
  51. console.log("A: " + cpu.A);
  52. tick(); tick();
  53. tick(); tick();
  54. console.log("A: " + cpu.A);