mkoffsets.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include "../pico/pico_int.h"
  4. #define DUMP(f, prefix, type, field) \
  5. fprintf(f, "#define %-20s 0x%02x\n", \
  6. prefix #field, (int)offsetof(type, field))
  7. #define DUMP_P(f, field) \
  8. fprintf(f, "#define %-20s 0x%04x\n", \
  9. "OFS_Pico_" #field, (char *)&p.field - (char *)&p)
  10. #define DUMP_PS(f, s1, field) \
  11. fprintf(f, "#define %-20s 0x%04x\n", \
  12. "OFS_Pico_" #s1 "_" #field, (char *)&p.s1.field - (char *)&p)
  13. #define DUMP_EST(f, field) \
  14. DUMP(f, "OFS_EST_", struct PicoEState, field)
  15. extern struct Pico p;
  16. int main(int argc, char *argv[])
  17. {
  18. char buf[128];
  19. FILE *f;
  20. snprintf(buf, sizeof(buf), "pico/pico_int_o%d.h", sizeof(void *) * 8);
  21. f = fopen(buf, "w");
  22. if (!f) {
  23. perror("fopen");
  24. return 1;
  25. }
  26. fprintf(f, "/* autogenerated by %s, do not edit */\n", argv[0]);
  27. DUMP_PS(f, video, reg);
  28. DUMP_PS(f, m, rotate);
  29. DUMP_PS(f, m, z80Run);
  30. DUMP_PS(f, m, dirtyPal);
  31. DUMP_PS(f, m, hardware);
  32. DUMP_PS(f, m, z80_reset);
  33. DUMP_PS(f, m, sram_reg);
  34. DUMP_P (f, sv);
  35. DUMP_PS(f, sv, data);
  36. DUMP_PS(f, sv, start);
  37. DUMP_PS(f, sv, end);
  38. DUMP_PS(f, sv, flags);
  39. DUMP_P (f, rom);
  40. DUMP_P (f, romsize);
  41. DUMP_EST(f, DrawScanline);
  42. DUMP_EST(f, rendstatus);
  43. DUMP_EST(f, DrawLineDest);
  44. DUMP_EST(f, HighCol);
  45. DUMP_EST(f, HighPreSpr);
  46. DUMP_EST(f, Pico);
  47. DUMP_EST(f, PicoMem_vram);
  48. DUMP_EST(f, PicoMem_cram);
  49. DUMP_EST(f, PicoOpt);
  50. DUMP_EST(f, Draw2FB);
  51. DUMP_EST(f, HighPal);
  52. fclose(f);
  53. return 0;
  54. }