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

48 lines
1.3 KiB

  1. #include "boot.h"
  2. #include <assert.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. static const uint8_t MAGIC[0x10] = "PS-X EXE";
  7. static const uint8_t RESERVED[0x10] = {0};
  8. typedef struct __attribute__((packed))
  9. {
  10. uint32_t pc;
  11. uint32_t gp;
  12. uint32_t addr_dest;
  13. uint32_t size_file;
  14. uint32_t addr_data;
  15. uint32_t size_data;
  16. uint32_t addr_bss;
  17. uint32_t size_bss;
  18. } psx_header_t;
  19. psx_header_t parse_psx_header(byte_arr_t *prgm)
  20. {
  21. psx_header_t header;
  22. // TODO: Convert asserts into recoverable error
  23. assert(prgm->size >= 0x800);
  24. assert(memcmp(MAGIC, prgm->data, sizeof MAGIC) == 0);
  25. memcpy(&header, &prgm->data[sizeof MAGIC], sizeof header);
  26. assert(header.size_file == prgm->size - 0x800);
  27. assert(memcmp(RESERVED, &prgm->data[0x38], sizeof RESERVED) == 0);
  28. return header;
  29. }
  30. void boot_psx_prgm(byte_arr_t *prgm)
  31. {
  32. psx_header_t header = parse_psx_header(prgm);
  33. printf("pc = %08x\n", header.pc);
  34. printf("gp = %08x\n", header.gp);
  35. printf("data = %08x (%u bytes)\n", header.addr_data, header.size_data);
  36. printf("bss = %08x (%u bytes)\n", header.addr_bss, header.size_bss);
  37. printf("dest = %08x\n", header.addr_dest);
  38. printf("size = %08x (%u bytes)\n", header.size_file, header.size_file);
  39. }