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.

39 line
755B

  1. #include <string.h>
  2. #include "ines.h"
  3. #include "nes.h"
  4. int ines_check_mem(void* mem) {
  5. int status = 0;
  6. ines_Header *hdr = (ines_Header*)mem;
  7. if (0 != memcmp(hdr->magic, ines_magic, sizeof(hdr->magic))) {
  8. INES_ERR("Bad file magic: expected '%.4s', got '%.4s'",
  9. ines_magic, hdr->magic);
  10. status = -1;
  11. }
  12. return status;
  13. }
  14. int ines_check(ines_Header* ret, FILE* file) {
  15. int status = 0;
  16. ines_Header hdr = {0};
  17. if (1 != fread(&hdr, sizeof(ines_Header), 1, file)) {
  18. INES_ERR("Failed to read header");
  19. status = -1;
  20. }
  21. if (0 == status) {
  22. status = ines_check_mem(&hdr);
  23. }
  24. if (0 == status && NULL != ret) {
  25. *ret = hdr;
  26. }
  27. return status;
  28. }