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