X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FArea.c;h=040154ed4547b170bbbdcae5a482d57c62318c22;hb=1832075ec7b43b166a9d5f83753832a05e7d4239;hp=1faea1fce852debbb3b7ba3d7d781a8ddd52a09c;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/Pico/Area.c b/Pico/Area.c index 1faea1f..040154e 100644 --- a/Pico/Area.c +++ b/Pico/Area.c @@ -22,8 +22,13 @@ struct PicoArea { void *data; int len; char *name; }; // taking an address of fread or fwrite causes "application could't be started" error // on startup randomly depending on binary layout of executable file. -arearw *areaRead = (arearw *) 0; // fread; // read and write function pointers for -arearw *areaWrite = (arearw *) 0; // fwrite; // gzip save state ability +arearw *areaRead = (arearw *) 0; // fread; // read and write function pointers for +arearw *areaWrite = (arearw *) 0; // fwrite; // gzip save state ability +areaeof *areaEof = (areaeof *) 0; +areaseek *areaSeek = (areaseek *) 0; +areaclose *areaClose = (areaclose *) 0; + +void (*PicoLoadStateHook)(void) = NULL; // Scan one variable and callback @@ -39,63 +44,74 @@ 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: -static int PackCpu(unsigned char *cpu) +PICO_INTERNAL int 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; -#endif - -#ifdef EMU_C68K - memcpy(cpu,PicoCpu.d,0x40); - pc=PicoCpu.pc-PicoCpu.membase; - *(unsigned int *)(cpu+0x44)=CycloneGetSr(&PicoCpu); - *(unsigned int *)(cpu+0x48)=PicoCpu.osp; -#endif - -#ifdef EMU_M68K - memcpy(cpu,m68ki_cpu.dar,0x40); - pc=m68ki_cpu.pc; +#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; +#elif defined(EMU_M68K) + void *oldcontext = m68ki_cpu_p; + 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); - *(unsigned int *)(cpu+0x48)=m68ki_cpu.sp[0]; + *(unsigned int *)(cpu+0x48)=m68ki_cpu_p->sp[0]; + 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; } -static int UnpackCpu(unsigned char *cpu) +PICO_INTERNAL int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) { - unsigned int pc=0; - - pc=*(unsigned int *)(cpu+0x40); - -#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); -#endif - -#ifdef EMU_C68K - CycloneSetSr(&PicoCpu, *(unsigned int *)(cpu+0x44)); - PicoCpu.osp=*(unsigned int *)(cpu+0x48); - memcpy(PicoCpu.d,cpu,0x40); - PicoCpu.membase=0; - PicoCpu.pc =PicoCpu.checkpc(pc); // Base pc -#endif - -#ifdef EMU_M68K - memcpy(m68ki_cpu.dar,cpu,0x40); - m68ki_cpu.pc=pc; +#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 + context->irq = cpu[0x4c]; + context->state_flags = 0; + if (cpu[0x4d]) + context->state_flags |= 1; +#elif defined(EMU_M68K) + void *oldcontext = m68ki_cpu_p; + 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)); - m68ki_cpu.sp[0]=*(unsigned int *)(cpu+0x48); + m68ki_cpu_p->sp[0]=*(unsigned int *)(cpu+0x48); + 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; } @@ -117,42 +133,34 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile) { Pico.m.scanline=0; - // Scan all the memory areas: + // Scan all the memory areas: SCANP(ram) SCANP(vram) SCANP(zram) SCANP(cram) SCANP(vsram) // Pack, scan and unpack the cpu data: - if((PmovAction&3)==1) PackCpu(cpu); - //SekInit(); // notaz: do we really have to do this here? + if((PmovAction&3)==1) PicoAreaPackCpu(cpu, 0); //PicoMemInit(); SCAN_VAR(cpu,"cpu") - if((PmovAction&3)==2) UnpackCpu(cpu); + if((PmovAction&3)==2) PicoAreaUnpackCpu(cpu, 0); SCAN_VAR(Pico.m ,"misc") SCAN_VAR(Pico.video,"video") - - if(ver == 0x0030) { // zram was being saved incorrectly in 0x0030 (byteswaped?) - Byteswap(Pico.zram, 0x2000); - return 0; // do not try to load sound stuff - } - - //SCAN_VAR(Pico.s ,"sound") - // notaz: save/load z80, YM2612, sn76496 states instead of Pico.s (which is unused anyway) - if(PicoOpt&7) { - if((PmovAction&3)==1) z80_pack(cpu_z80); + 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 - if((PmovAction&3)==2) { + // do not unpack if we fail to load z80 state + if((PmovAction&3)==2) { if(ret) z80_reset(); 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 + } } return 0; @@ -167,6 +175,16 @@ int PmovState(int PmovAction, void *PmovFile) int minimum=0; unsigned char head[32]; + if ((PicoAHW & PAHW_MCD) || carthw_chunks != NULL) + { + if (PmovAction&1) return PicoCdSaveState(PmovFile); + if (PmovAction&2) { + int ret = PicoCdLoadState(PmovFile); + if (PicoLoadStateHook) PicoLoadStateHook(); + return ret; + } + } + memset(head,0,sizeof(head)); // Find out minimal compatible version: @@ -184,6 +202,8 @@ int PmovState(int PmovAction, void *PmovFile) // Scan memory areas: PicoAreaScan(PmovAction, *(unsigned int *)(head+0x8), PmovFile); + if ((PmovAction&2) && PicoLoadStateHook) PicoLoadStateHook(); + return 0; }