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.
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.

50 lines
930B

  1. #include <stdio.h>
  2. #include "cart.h"
  3. #include "nese.h"
  4. #include "port.h"
  5. static int nese_file_size(FILE* file) {
  6. int size = -1;
  7. if (0 == fseek(file, 0, SEEK_END)) {
  8. size = ftell(file);
  9. }
  10. return size;
  11. }
  12. int nese_start(nes* sys, const char* filename) {
  13. int status = 0;
  14. void* cart_data = NULL;
  15. int filesize = -1;
  16. FILE* file = NULL;
  17. file = fopen(filename, "rb");
  18. if (NULL == file) {
  19. status = -1;
  20. }
  21. if (0 == status) {
  22. filesize = nese_file_size(file);
  23. cart_data = nese_map_file(file, filesize);
  24. if (NULL == cart_data) {
  25. fprintf(stderr, "Failed to map %s\n", filename);
  26. status = -1;
  27. } else {
  28. status = nes_cart_load_mem(cart_data, filesize, sys);
  29. }
  30. }
  31. nes_init(sys);
  32. nes_loop(sys);
  33. if (cart_data) nese_unmap_file(cart_data, filesize);
  34. nes_done(sys);
  35. return 0;
  36. }