NESe (pronounced "Nessie") is a NES emulator based on the e6502 emulator, also written in C with a focus on speed and portability for use on embedded platforms, especially ARM.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

48 rindas
1.1KB

  1. #include <stdio.h>
  2. #include "src/f6502.h"
  3. int load(uint8_t* mem, FILE* file) {
  4. return fread(mem, 65536, 1, file);
  5. }
  6. void print_registers(const f6502_Registers* regs,
  7. FILE* file) {
  8. fprintf(file, "PC: $%04x\n", regs->PC);
  9. fprintf(file, " S: $%02x\n", regs->S);
  10. fprintf(file, " A: $%02x\n", regs->A);
  11. fprintf(file, " X: $%02x\n", regs->X);
  12. fprintf(file, " Y: $%02x\n", regs->Y);
  13. fprintf(file, " P: $%02x\n", regs->P);
  14. }
  15. static f6502_Core core = {0};
  16. int main(int argc, char* argv[]) {
  17. f6502_init(&core);
  18. if (load(core.memory.ram, stdin) != 1) {
  19. fprintf(stderr, "Failed to load e6502 memory\n");
  20. return 1;
  21. }
  22. core.memory.ram[0xbffc] = 0;
  23. f6502_reset(&core);
  24. core.registers.PC = 0x400;
  25. int total_clocks = 0;
  26. int clocks_elapsed = 1;
  27. while (clocks_elapsed > 0) {
  28. clocks_elapsed = f6502_step(&core, 1000);
  29. if (clocks_elapsed < 0) total_clocks -= clocks_elapsed;
  30. else total_clocks += clocks_elapsed;
  31. }
  32. fprintf(stdout, "Ran %d\n", total_clocks);
  33. print_registers(&core.registers, stdout);
  34. return 0;
  35. }