2 // Megadrive C++ module saving and loading
9 gs0 genecyst save file INfo
13 80-9f = d0-d7 almost certain
14 a0-bf = a0-a7 almost certain
15 c8 = pc fairly certain
16 d0 = sr fairly certain
19 112 Start of cram len 0x80
20 192 Start of vsram len 0x50
21 1e2-474 UNKNOWN sound info?
22 Start of z80 ram at 474 (they store 2000)
23 Start of RAM at 2478 almost certain (BYTE SWAPPED)
24 Start of VRAM at 12478
28 // NB - for load and save you don't need to use star_mz80_on/off
29 // Because stars/mz80 isn't actually used
30 #define fput(x,y) { if (fwrite(x,1,y,hand)!=y) goto save_error; }
31 #define fget(x,y) if (fread(x,1,y,hand)!=y) goto load_error;
33 extern int byteswap_memory(unsigned char *start
,int len
);
35 int md::import_gst(FILE *hand
)
37 #ifdef COMPILE_WITH_STAR
40 fseek(hand
,0x80,SEEK_SET
);
43 fseek(hand
,0xc8,SEEK_SET
);
45 fseek(hand
,0xd0,SEEK_SET
);
50 #ifdef COMPILE_WITH_MUSA
54 fseek(hand
,0x80,SEEK_SET
);
56 { fget(&t
,4); m68k_poke_dr(i
,t
); }
58 { fget(&t
,4); m68k_poke_ar(i
,t
); }
60 fseek(hand
,0xc8,SEEK_SET
);
61 fget(&t
,4); m68k_poke_pc(t
);
63 fseek(hand
,0xd0,SEEK_SET
);
64 fget(&t
,4); m68k_poke_sr(t
);
68 fseek(hand
,0xfa,SEEK_SET
);
71 fseek(hand
,0x112,SEEK_SET
);
72 fget(vdp
.cram
,0x00080);
73 byteswap_memory(vdp
.cram
,0x80);
74 fget(vdp
.vsram
,0x00050);
75 byteswap_memory(vdp
.vsram
,0x50);
77 fseek(hand
,0x474,SEEK_SET
);
78 fget(z80ram
, 0x02000);
80 fseek(hand
,0x2478,SEEK_SET
);
82 byteswap_memory(ram
,0x10000);
84 fget(vdp
.vram
,0x10000);
86 memset(vdp
.dirt
,0xff,0x35); // mark everything as changed
94 int md::export_gst(FILE *hand
)
97 static unsigned char gst_head
[0x80]=
99 0x47,0x53,0x54,0,0,0,0xe0,0x40
101 // 00 00 00 00 00 00 00 00 00 00 00 00 00 21 80 fa <.............!..>
103 unsigned char *zeros
=gst_head
+0x40; // 0x40 zeros
105 fseek(hand
,0x00,SEEK_SET
);
106 // Make file size 0x22478 with zeros
107 for (i
=0;i
<0x22440;i
+=0x40) fput(zeros
,0x40);
110 fseek(hand
,0x00,SEEK_SET
);
113 #ifdef COMPILE_WITH_STAR
116 fseek(hand
,0x80,SEEK_SET
);
119 fseek(hand
,0xc8,SEEK_SET
);
121 fseek(hand
,0xd0,SEEK_SET
);
125 #ifdef COMPILE_WITH_MUSA
129 fseek(hand
,0x80,SEEK_SET
);
131 { t
=m68k_peek_dr(i
); fput(&t
,4);}
133 { t
=m68k_peek_ar(i
); fput(&t
,4);}
135 fseek(hand
,0xc8,SEEK_SET
);
136 t
=m68k_peek_pc(); fput(&t
,4);
138 fseek(hand
,0xd0,SEEK_SET
);
139 t
=m68k_peek_sr(); fput(&t
,4);
143 fseek(hand
,0xfa,SEEK_SET
);
146 fseek(hand
,0x112,SEEK_SET
);
147 byteswap_memory(vdp
.cram
,0x80);
148 fput(vdp
.cram
,0x00080);
149 byteswap_memory(vdp
.cram
,0x80);
150 byteswap_memory(vdp
.vsram
,0x50);
151 fput(vdp
.vsram
,0x00050);
152 byteswap_memory(vdp
.vsram
,0x50);
154 fseek(hand
,0x474,SEEK_SET
);
155 fput(z80ram
, 0x02000);
157 fseek(hand
,0x2478,SEEK_SET
);
158 byteswap_memory(ram
,0x10000);
160 byteswap_memory(ram
,0x10000);
162 fput(vdp
.vram
,0x10000);