X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=Pico%2FArea.c;h=e62274af6b0dfbe9592792fac2b97267bf8f6672;hb=e5f426aa2e86d56357b8af2795e73cc0c9b17e8f;hp=1faea1fce852debbb3b7ba3d7d781a8ddd52a09c;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/Pico/Area.c b/Pico/Area.c index 1faea1f..e62274a 100644 --- a/Pico/Area.c +++ b/Pico/Area.c @@ -22,8 +22,11 @@ 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; // Scan one variable and callback @@ -39,7 +42,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: -static int PackCpu(unsigned char *cpu) +PICO_INTERNAL int PicoAreaPackCpu(unsigned char *cpu, int is_sub) { unsigned int pc=0; @@ -49,53 +52,71 @@ static int PackCpu(unsigned char *cpu) *(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 - memcpy(cpu,PicoCpu.d,0x40); - pc=PicoCpu.pc-PicoCpu.membase; - *(unsigned int *)(cpu+0x44)=CycloneGetSr(&PicoCpu); - *(unsigned int *)(cpu+0x48)=PicoCpu.osp; + struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu; + 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 - memcpy(cpu,m68ki_cpu.dar,0x40); - pc=m68ki_cpu.pc; + void *oldcontext = m68ki_cpu_p; + m68k_set_context(is_sub ? &PicoS68kCPU : &PicoM68kCPU); + 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); #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); + M68000_regs.irq = cpu[0x4c]; + // stop flag? #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 + struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu; + 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; #endif #ifdef EMU_M68K - memcpy(m68ki_cpu.dar,cpu,0x40); - m68ki_cpu.pc=pc; + void *oldcontext = m68ki_cpu_p; + m68k_set_context(is_sub ? &PicoS68kCPU : &PicoM68kCPU); + 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); #endif return 0; } @@ -117,42 +138,35 @@ 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); + 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) 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); + // 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); 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) { 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) YM2612PicoStateLoad(); // reload YM2612 state from it's regs + } } return 0; @@ -167,6 +181,12 @@ int PmovState(int PmovAction, void *PmovFile) int minimum=0; unsigned char head[32]; + if (PicoMCD & 1) + { + if (PmovAction&1) return PicoCdSaveState(PmovFile); + if (PmovAction&2) return PicoCdLoadState(PmovFile); + } + memset(head,0,sizeof(head)); // Find out minimal compatible version: