X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FArea.c;h=49c2afcdf073cf5c2a868545ca05ed23b3edc70e;hb=2aa27095f2dbf5b38950fcb1f856d5ffc6a70361;hp=3749ac3232c43b200ad07729665726ad793091e1;hpb=0af33fe0ef24a3e3b65217ad0d7aa2db03d16fc1;p=picodrive.git diff --git a/Pico/Area.c b/Pico/Area.c index 3749ac3..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,33 +44,21 @@ 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: -int PicoAreaPackCpu(unsigned char *cpu, int is_sub) +PICO_INTERNAL void PicoAreaPackCpu(unsigned char *cpu, int is_sub) { unsigned int pc=0; -#ifdef EMU_A68K - memcpy(cpu,M68000_regs.d,0x40); - pc=M68000_regs.pc; - *(unsigned char *)(cpu+0x44)=(unsigned char)M68000_regs.ccr; - *(unsigned char *)(cpu+0x45)=(unsigned char)M68000_regs.srh; - *(unsigned int *)(cpu+0x48)=M68000_regs.isp; - cpu[0x4c] = M68000_regs.irq; - // stop flag? -#endif - -#ifdef EMU_C68K - struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu; +#if defined(EMU_C68K) + struct Cyclone *context = is_sub ? &PicoCpuCS68k : &PicoCpuCM68k; memcpy(cpu,context->d,0x40); pc=context->pc-context->membase; *(unsigned int *)(cpu+0x44)=CycloneGetSr(context); *(unsigned int *)(cpu+0x48)=context->osp; cpu[0x4c] = context->irq; cpu[0x4d] = context->state_flags & 1; -#endif - -#ifdef EMU_M68K +#elif defined(EMU_M68K) void *oldcontext = m68ki_cpu_p; - m68k_set_context(is_sub ? &PicoS68kCPU : &PicoM68kCPU); + m68k_set_context(is_sub ? &PicoCpuMS68k : &PicoCpuMM68k); memcpy(cpu,m68ki_cpu_p->dar,0x40); pc=m68ki_cpu_p->pc; *(unsigned int *)(cpu+0x44)=m68k_get_reg(NULL, M68K_REG_SR); @@ -76,28 +66,25 @@ int PicoAreaPackCpu(unsigned char *cpu, int is_sub) cpu[0x4c] = CPU_INT_LEVEL>>8; cpu[0x4d] = CPU_STOPPED; m68k_set_context(oldcontext); +#elif defined(EMU_F68K) + M68K_CONTEXT *context = is_sub ? &PicoCpuFS68k : &PicoCpuFM68k; + memcpy(cpu,context->dreg,0x40); + pc=context->pc; + *(unsigned int *)(cpu+0x44)=context->sr; + *(unsigned int *)(cpu+0x48)=context->asp; + cpu[0x4c] = context->interrupts[0]; + cpu[0x4d] = (context->execinfo & FM68K_HALTED) ? 1 : 0; #endif *(unsigned int *)(cpu+0x40)=pc; - return 0; } -int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) +PICO_INTERNAL void PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) { -#ifdef EMU_A68K - memcpy(M68000_regs.d,cpu,0x40); - M68000_regs.pc=pc; - M68000_regs.ccr=*(unsigned char *)(cpu+0x44); - M68000_regs.srh=*(unsigned char *)(cpu+0x45); - M68000_regs.isp=*(unsigned int *)(cpu+0x48); - M68000_regs.irq = cpu[0x4c]; - // stop flag? -#endif - -#ifdef EMU_C68K - struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu; - CycloneSetSr(context, *(unsigned int *)(cpu+0x44)); - context->osp=*(unsigned int *)(cpu+0x48); +#if defined(EMU_C68K) + struct Cyclone *context = is_sub ? &PicoCpuCS68k : &PicoCpuCM68k; + CycloneSetSr(context, *(unsigned int *)(cpu+0x44)); + context->osp=*(unsigned int *)(cpu+0x48); memcpy(context->d,cpu,0x40); context->membase=0; context->pc = context->checkpc(*(unsigned int *)(cpu+0x40)); // Base pc @@ -105,11 +92,9 @@ int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) context->state_flags = 0; if (cpu[0x4d]) context->state_flags |= 1; -#endif - -#ifdef EMU_M68K +#elif defined(EMU_M68K) void *oldcontext = m68ki_cpu_p; - m68k_set_context(is_sub ? &PicoS68kCPU : &PicoM68kCPU); + m68k_set_context(is_sub ? &PicoCpuMS68k : &PicoCpuMM68k); memcpy(m68ki_cpu_p->dar,cpu,0x40); m68ki_cpu_p->pc=*(unsigned int *)(cpu+0x40); m68k_set_reg(M68K_REG_SR, *(unsigned int *)(cpu+0x44)); @@ -117,8 +102,16 @@ int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) CPU_INT_LEVEL = cpu[0x4c] << 8; CPU_STOPPED = cpu[0x4d]; m68k_set_context(oldcontext); +#elif defined(EMU_F68K) + M68K_CONTEXT *context = is_sub ? &PicoCpuFS68k : &PicoCpuFM68k; + memcpy(context->dreg,cpu,0x40); + context->pc =*(unsigned int *)(cpu+0x40); + context->sr =*(unsigned int *)(cpu+0x44); + context->asp=*(unsigned int *)(cpu+0x48); + context->interrupts[0] = cpu[0x4c]; + 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 @@ -143,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); @@ -151,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 @@ -161,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 } } @@ -181,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)); @@ -204,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; }