X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FArea.c;h=49c2afcdf073cf5c2a868545ca05ed23b3edc70e;hb=ae2bf94418b6a88f7aaae2f655163b75ce831309;hp=41ee68ba424a2ddb190c7b2ad7cb0a9351260eb2;hpb=3aa1e148a28da9b4e10e824984f7b3a4908b1ace;p=picodrive.git diff --git a/Pico/Area.c b/Pico/Area.c index 41ee68b..49c2afc 100644 --- a/Pico/Area.c +++ b/Pico/Area.c @@ -28,6 +28,8 @@ areaeof *areaEof = (areaeof *) 0; areaseek *areaSeek = (areaseek *) 0; areaclose *areaClose = (areaclose *) 0; +void (*PicoLoadStateHook)(void) = NULL; + // Scan one variable and callback static int ScanVar(void *data,int len,char *name,void *PmovFile,int PmovAction) @@ -42,7 +44,7 @@ static int ScanVar(void *data,int len,char *name,void *PmovFile,int PmovAction) #define SCANP(x) ScanVar(&Pico.x,sizeof(Pico.x),#x,PmovFile,PmovAction); // Pack the cpu into a common format: -PICO_INTERNAL int PicoAreaPackCpu(unsigned char *cpu, int is_sub) +PICO_INTERNAL void PicoAreaPackCpu(unsigned char *cpu, int is_sub) { unsigned int pc=0; @@ -71,14 +73,13 @@ PICO_INTERNAL int PicoAreaPackCpu(unsigned char *cpu, int is_sub) *(unsigned int *)(cpu+0x44)=context->sr; *(unsigned int *)(cpu+0x48)=context->asp; cpu[0x4c] = context->interrupts[0]; - cpu[0x4d] = (context->execinfo & M68K_HALTED) ? 1 : 0; + cpu[0x4d] = (context->execinfo & FM68K_HALTED) ? 1 : 0; #endif *(unsigned int *)(cpu+0x40)=pc; - return 0; } -PICO_INTERNAL int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) +PICO_INTERNAL void PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) { #if defined(EMU_C68K) struct Cyclone *context = is_sub ? &PicoCpuCS68k : &PicoCpuCM68k; @@ -108,10 +109,9 @@ PICO_INTERNAL int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) context->sr =*(unsigned int *)(cpu+0x44); context->asp=*(unsigned int *)(cpu+0x48); context->interrupts[0] = cpu[0x4c]; - context->execinfo &= ~M68K_HALTED; - if (cpu[0x4d]&1) context->execinfo |= M68K_HALTED; + context->execinfo &= ~FM68K_HALTED; + if (cpu[0x4d]&1) context->execinfo |= FM68K_HALTED; #endif - return 0; } // Scan the contents of the virtual machine's memory for saving or loading @@ -136,7 +136,6 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile) // Pack, scan and unpack the cpu data: if((PmovAction&3)==1) PicoAreaPackCpu(cpu, 0); - //SekInit(); // notaz: do we really have to do this here? //PicoMemInit(); SCAN_VAR(cpu,"cpu") if((PmovAction&3)==2) PicoAreaUnpackCpu(cpu, 0); @@ -144,8 +143,7 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile) SCAN_VAR(Pico.m ,"misc") SCAN_VAR(Pico.video,"video") - // notaz: save/load z80, YM2612, sn76496 states instead of Pico.s (which is unused anyway) - if(PicoOpt&7) { + if (PicoOpt&7) { if((PmovAction&3)==1) z80_pack(cpu_z80); ret = SCAN_VAR(cpu_z80,"cpu_z80") // do not unpack if we fail to load z80 state @@ -154,11 +152,12 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile) else z80_unpack(cpu_z80); } } - if(PicoOpt&3) + if (PicoOpt&3) ScanVar(sn76496_regs,28*4,"SN76496state", PmovFile, PmovAction); // regs and other stuff - if(PicoOpt&1) { + if (PicoOpt&1) { + if((PmovAction&3)==1) ym2612_pack_state(); ScanVar(ym2612_regs, 0x200+4, "YM2612state", PmovFile, PmovAction); // regs + addr line - if((PmovAction&3)==2) YM2612PicoStateLoad(); // reload YM2612 state from it's regs + if((PmovAction&3)==2) ym2612_unpack_state(); // reload YM2612 state from it's regs } } @@ -174,10 +173,14 @@ int PmovState(int PmovAction, void *PmovFile) int minimum=0; unsigned char head[32]; - if (PicoMCD & 1) + if ((PicoAHW & PAHW_MCD) || carthw_chunks != NULL) { if (PmovAction&1) return PicoCdSaveState(PmovFile); - if (PmovAction&2) return PicoCdLoadState(PmovFile); + if (PmovAction&2) { + int ret = PicoCdLoadState(PmovFile); + if (PicoLoadStateHook) PicoLoadStateHook(); + return ret; + } } memset(head,0,sizeof(head)); @@ -197,6 +200,8 @@ int PmovState(int PmovAction, void *PmovFile) // Scan memory areas: PicoAreaScan(PmovAction, *(unsigned int *)(head+0x8), PmovFile); + if ((PmovAction&2) && PicoLoadStateHook) PicoLoadStateHook(); + return 0; }