4 int (*PicoAcb)(struct PicoArea *)=NULL; // Area callback for each block of memory
\r
8 // Scan one variable and callback
\r
9 static void ScanVar(void *data,int len,char *name)
\r
11 struct PicoArea pa={NULL,0,NULL};
\r
12 pa.data=data; pa.len=len; pa.name=name;
\r
13 if (PicoAcb) PicoAcb(&pa);
\r
16 #define SCAN_VAR(x,y) ScanVar(&x,sizeof(x),y);
\r
17 #define SCANP(x) ScanVar(&Pico.x,sizeof(Pico.x),#x);
\r
19 // Pack the cpu into a common format:
\r
20 static int PackCpu(unsigned char *cpu)
\r
25 memcpy(cpu,M68000_regs.d,0x40);
\r
27 *(unsigned char *)(cpu+0x44)=(unsigned char)M68000_regs.ccr;
\r
28 *(unsigned char *)(cpu+0x45)=(unsigned char)M68000_regs.srh;
\r
29 *(unsigned int *)(cpu+0x48)=M68000_regs.isp;
\r
33 memcpy(cpu,PicoCpu.d,0x40);
\r
34 pc=PicoCpu.pc-PicoCpu.membase;
\r
35 *(unsigned char *)(cpu+0x44)=PicoCpu.ccr;
\r
36 *(unsigned char *)(cpu+0x45)=PicoCpu.srh;
\r
37 *(unsigned int *)(cpu+0x48)=PicoCpu.osp;
\r
40 *(unsigned int *)(cpu+0x40)=pc;
\r
44 static int UnpackCpu(unsigned char *cpu)
\r
48 pc=*(unsigned int *)(cpu+0x40);
\r
51 memcpy(M68000_regs.d,cpu,0x40);
\r
53 M68000_regs.ccr=*(unsigned char *)(cpu+0x44);
\r
54 M68000_regs.srh=*(unsigned char *)(cpu+0x45);
\r
55 M68000_regs.isp=*(unsigned int *)(cpu+0x48);
\r
59 memcpy(PicoCpu.d,cpu,0x40);
\r
61 PicoCpu.pc =PicoCpu.checkpc(pc); // Base pc
\r
62 PicoCpu.ccr=*(unsigned char *)(cpu+0x44);
\r
63 PicoCpu.srh=*(unsigned char *)(cpu+0x45);
\r
64 PicoCpu.osp=*(unsigned int *)(cpu+0x48);
\r
69 // Scan the contents of the virtual machine's memory for saving or loading
\r
70 int PicoAreaScan(int action,int *pmin)
\r
72 unsigned char cpu[0x60];
\r
74 memset(&cpu,0,sizeof(cpu));
\r
78 // Scan all the memory areas:
\r
79 SCANP(ram) SCANP(vram) SCANP(zram) SCANP(cram) SCANP(vsram)
\r
81 // Pack, scan and unpack the cpu data:
\r
88 SCAN_VAR(Pico.m ,"misc")
\r
89 SCAN_VAR(Pico.video,"video")
\r
90 SCAN_VAR(Pico.s ,"sound")
\r
95 memset(Pico.highpal,0,sizeof(Pico.highpal));
\r
96 Pico.m.dirtyPal=1; // Recalculate palette
\r
100 if (pmin) *pmin=0x0021;
\r
105 // ---------------------------------------------------------------------------
\r
106 // Helper code to save/load to a file handle
\r
108 // Area callback for each piece of Megadrive memory, read or write to the file:
\r
109 static int StateAcb(struct PicoArea *pa)
\r
111 if (PmovFile==NULL) return 1;
\r
113 if ((PmovAction&3)==1) fwrite(pa->data,1,pa->len,PmovFile);
\r
114 if ((PmovAction&3)==2) fread (pa->data,1,pa->len,PmovFile);
\r
118 // Save or load the state from PmovFile:
\r
122 unsigned char head[32];
\r
124 memset(head,0,sizeof(head));
\r
126 // Find out minial compatible version:
\r
127 PicoAreaScan(PmovAction&0xc,&minimum);
\r
129 memcpy(head,"Pico",4);
\r
130 *(unsigned int *)(head+0x8)=PicoVer;
\r
131 *(unsigned int *)(head+0xc)=minimum;
\r
134 if (PmovAction&1) fwrite(head,1,sizeof(head),PmovFile);
\r
135 if (PmovAction&2) fread (head,1,sizeof(head),PmovFile);
\r
137 // Scan memory areas:
\r
139 PicoAreaScan(PmovAction,NULL);
\r
147 if (PmovFile==NULL) return 1;
\r
149 if ((PmovAction&3)==0) return 0;
\r
151 PicoPad[1]=0; // Make sure pad #2 is blank
\r
152 if (PmovAction&1) ret=fwrite(PicoPad,1,2,PmovFile);
\r
153 if (PmovAction&2) ret=fread (PicoPad,1,2,PmovFile);
\r
158 fclose(PmovFile); PmovFile=NULL;
\r