From 4f8e18215b0a29a7ac23b90b15b678c1d685ea60 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Fri, 12 Jul 2019 17:20:43 +0200 Subject: [PATCH] Fixed savestates: restore compatibility with lr and master Add new maple devices from lr Clean up shil.cpp --- core/hw/aica/sgc_if.cpp | 4 +- core/hw/flashrom/flashrom.h | 4 +- core/hw/maple/maple_cfg.cpp | 38 +- core/hw/maple/maple_cfg.h | 2 +- core/hw/maple/maple_devs.cpp | 4 +- core/hw/maple/maple_devs.h | 22 + core/hw/sh4/dyna/shil.cpp | 1000 +------------------------------ core/hw/sh4/sh4_interrupts.cpp | 2 +- core/nullDC.cpp | 15 +- core/serialize.cpp | 1011 +++++++------------------------- 10 files changed, 284 insertions(+), 1818 deletions(-) diff --git a/core/hw/aica/sgc_if.cpp b/core/hw/aica/sgc_if.cpp index 5dd37a729..5de996378 100755 --- a/core/hw/aica/sgc_if.cpp +++ b/core/hw/aica/sgc_if.cpp @@ -1179,9 +1179,6 @@ void WriteCommonReg8(u32 reg,u32 data) s16 cdda_sector[CDDA_SIZE]={0}; u32 cdda_index=CDDA_SIZE<<1; - -SampleType mxlr[64]; - u32 samples_gen; //no DSP for now in this version @@ -1192,6 +1189,7 @@ void AICA_Sample32() return; } + SampleType mxlr[64]; memset(mxlr,0,sizeof(mxlr)); //Generate 32 samples for each channel, before moving to next channel diff --git a/core/hw/flashrom/flashrom.h b/core/hw/flashrom/flashrom.h index c47e596d4..078a44069 100644 --- a/core/hw/flashrom/flashrom.h +++ b/core/hw/flashrom/flashrom.h @@ -644,15 +644,15 @@ private: virtual bool Serialize(void **data, unsigned int *total_size) override { - REICAST_SA(&this->data[write_protect_size], size - write_protect_size); REICAST_S(state); + REICAST_SA(&this->data[write_protect_size], size - write_protect_size); return true; } virtual bool Unserialize(void **data, unsigned int *total_size) override { - REICAST_USA(&this->data[write_protect_size], size - write_protect_size); REICAST_US(state); + REICAST_USA(&this->data[write_protect_size], size - write_protect_size); return true; } }; diff --git a/core/hw/maple/maple_cfg.cpp b/core/hw/maple/maple_cfg.cpp index b71fd2f5e..bddf40e0b 100644 --- a/core/hw/maple/maple_cfg.cpp +++ b/core/hw/maple/maple_cfg.cpp @@ -245,7 +245,7 @@ void mcfg_SerializeDevices(void **data, unsigned int *total_size) } } -void mcfg_UnserializeDevices(void **data, unsigned int *total_size) +void mcfg_UnserializeDevices(void **data, unsigned int *total_size, bool old) { mcfg_DestroyDevices(); @@ -256,6 +256,42 @@ void mcfg_UnserializeDevices(void **data, unsigned int *total_size) MapleDeviceType device_type = (MapleDeviceType)**p; *p = *p + 1; *total_size = *total_size + 1; + if (old) + { + switch (device_type) + { + case OldMapleDeviceType::MDT_None: + device_type = MDT_None; + break; + case OldMapleDeviceType::MDT_SegaController: + device_type = MDT_SegaController; + break; + case OldMapleDeviceType::MDT_SegaVMU: + device_type = MDT_SegaVMU; + break; + case OldMapleDeviceType::MDT_PurupuruPack: + device_type = MDT_PurupuruPack; + break; + case OldMapleDeviceType::MDT_Microphone: + device_type = MDT_Microphone; + break; + case OldMapleDeviceType::MDT_Keyboard: + device_type = MDT_Keyboard; + break; + case OldMapleDeviceType::MDT_Mouse: + device_type = MDT_Mouse; + break; + case OldMapleDeviceType::MDT_LightGun: + device_type = MDT_LightGun; + break; + case OldMapleDeviceType::MDT_NaomiJamma: + device_type = MDT_NaomiJamma; + break; + default: + die("Invalid maple device type"); + break; + } + } if (device_type != MDT_None) { mcfg_Create(device_type, i, j); diff --git a/core/hw/maple/maple_cfg.h b/core/hw/maple/maple_cfg.h index 299117bb6..3dce39645 100644 --- a/core/hw/maple/maple_cfg.h +++ b/core/hw/maple/maple_cfg.h @@ -64,6 +64,6 @@ void mcfg_CreateAtomisWaveControllers(); void mcfg_DestroyDevices(); void mcfg_SerializeDevices(void **data, unsigned int *total_size); -void mcfg_UnserializeDevices(void **data, unsigned int *total_size); +void mcfg_UnserializeDevices(void **data, unsigned int *total_size, bool old_type_numbering); bool maple_atomiswave_coin_chute(int slot); diff --git a/core/hw/maple/maple_devs.cpp b/core/hw/maple/maple_devs.cpp index b7ecc68f1..a745a748c 100755 --- a/core/hw/maple/maple_devs.cpp +++ b/core/hw/maple/maple_devs.cpp @@ -2657,7 +2657,9 @@ maple_device* maple_Create(MapleDeviceType type) break; default: - return 0; + ERROR_LOG(MAPLE, "Invalid device type %d", type); + die("Invalid maple device type"); + break; } return rv; diff --git a/core/hw/maple/maple_devs.h b/core/hw/maple/maple_devs.h index ec45b4986..ce924ce9e 100755 --- a/core/hw/maple/maple_devs.h +++ b/core/hw/maple/maple_devs.h @@ -1,6 +1,27 @@ #pragma once #include "types.h" +enum MapleDeviceType +{ + MDT_SegaController, + + MDT_SegaVMU, + MDT_Microphone, + MDT_PurupuruPack, + MDT_AsciiStick, + MDT_Keyboard, + MDT_Mouse, + MDT_LightGun, + MDT_TwinStick, + + MDT_NaomiJamma, + + MDT_None, + MDT_Count +}; + +namespace OldMapleDeviceType +{ enum MapleDeviceType { MDT_SegaController, @@ -17,6 +38,7 @@ enum MapleDeviceType MDT_None, MDT_Count }; +} enum NAOMI_KEYS { diff --git a/core/hw/sh4/dyna/shil.cpp b/core/hw/sh4/dyna/shil.cpp index 628a453fc..eb371b1d7 100644 --- a/core/hw/sh4/dyna/shil.cpp +++ b/core/hw/sh4/dyna/shil.cpp @@ -1,876 +1,10 @@ -/* - Some WIP optimisation stuff and maby helper functions for shil -*/ - #include -#include -#include #include "types.h" -#include "shil.h" -#include "decoder.h" #include "hw/sh4/sh4_mem.h" -#include "blockmanager.h" -u32 RegisterWrite[sh4_reg_count]; -u32 RegisterRead[sh4_reg_count]; - -void RegReadInfo(shil_param p,size_t ord) -{ - if (p.is_reg()) - { - for (u32 i=0; i=RegisterRead[p._reg+i] && RegisterWrite[p._reg+i]!=0xFFFFFFFF) //if last read was before last write, and there was a last write - { - DEBUG_LOG(DYNAREC, "DEAD OPCODE %d %zd!\n",RegisterWrite[p._reg+i],ord); - ops[RegisterWrite[p._reg+i]].Flow=1; //the last write was unused - } - RegisterWrite[p._reg+i]=ord; - } - } -} -u32 fallback_blocks; -u32 total_blocks; -u32 REMOVED_OPS; - -bool isdst(shil_opcode* op,Sh4RegType rd) -{ - return (op->rd.is_r32() && op->rd._reg==rd) || (op->rd2.is_r32() && op->rd2._reg==rd); -} - -//really hacky ~ -//Isn't this now obsolete anyway ? (constprop pass should include it ..) -// -> constprop has some small stability issues still, not ready to be used on ip/bios fully yet -void PromoteConstAddress(RuntimeBlockInfo* blk) -{ - bool is_const=false; - u32 value; - - total_blocks++; - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - if (is_const && op->op==shop_readm && op->rs1.is_reg() && op->rs1._reg==reg_r0) - { - u32 val=value; - if (op->rs3.is_imm()) - { - val+=op->rs3._imm; - op->rs3=shil_param(); - } - op->rs1=shil_param(FMT_IMM,val); - } - - if (op->op==shop_mov32 && op->rs1.is_imm() && isdst(op,reg_r0) ) - { - is_const=true; - value=op->rs1._imm; - } - else if (is_const && (isdst(op,reg_r0) || op->op==shop_ifb || op->op==shop_sync_sr) ) - is_const=false; - } -} - -void sq_pref(RuntimeBlockInfo* blk, int i, Sh4RegType rt, bool mark) -{ - u32 data=0; - for (int c=i-1;c>0;c--) - { - if (blk->oplist[c].op==shop_writem && blk->oplist[c].rs1._reg==rt) - { - if (blk->oplist[c].rs2.is_r32i() || blk->oplist[c].rs2.is_r32f() || blk->oplist[c].rs2.is_r64f() || blk->oplist[c].rs2.is_r32fv()) - { - data+=blk->oplist[c].flags; - if (mark) - blk->oplist[c].flags2=0x1337; - } - else - break; - } - - if (blk->oplist[c].op==shop_pref || (blk->oplist[c].rd.is_reg() && blk->oplist[c].rd._reg==rt && blk->oplist[c].op!= shop_sub)) - { - break; - } - - if (data==32) - break; - } - - if (mark) return; - - if (data>=8) - { - blk->oplist[i].flags =0x1337; - sq_pref(blk,i,rt,true); - DEBUG_LOG(DYNAREC, "SQW-WM match %d !",data); - } - else if (data) - { - DEBUG_LOG(DYNAREC, "SQW-WM FAIL %d !",data); - } -} - -void sq_pref(RuntimeBlockInfo* blk) -{ - for (int i=0;ioplist.size();i++) - { - blk->oplist[i].flags2=0; - if (blk->oplist[i].op==shop_pref) - sq_pref(blk,i,blk->oplist[i].rs1._reg,false); - } -} - -//Read Groups -void rdgrp(RuntimeBlockInfo* blk) -{ - int started=-1; - Sh4RegType reg; - Sh4RegType regd; - u32 stride; - bool pend_add; - u32 rdc; - u32 addv; - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - op->Flow=0; - - if (started<0) - { - if (op->op==shop_readm && op->rd.type>=FMT_F32 && op->rs1.is_reg() && op->rs3.is_null()) - { - started=i; - stride=op->rd.count(); - reg=op->rs1._reg; - regd=op->rd._reg; - pend_add=true; - rdc=1; - addv=0; - } - } - else - { - if (!pend_add && op->op==shop_readm && op->rd._reg==(regd+stride) && op->rs1.is_reg() && op->rs1._reg==reg && op->rs3.is_null()) - { - regd=(Sh4RegType)(regd+stride); - pend_add=true; - rdc++; - } - else if (pend_add && op->op==shop_add && op->rd._reg==op->rs1._reg && op->rs1.is_reg() && op->rs2.is_imm() && op->rs2._imm==(stride*4)) - { - pend_add=false; - addv+=op->rs2._imm; - } - else - { - u32 byts=rdc*stride*4; - if (rdc!=1 && (byts==8 || byts==12 || byts==16 || byts==32 || byts==64)) - { - verify(addv==byts || (pend_add && (addv+stride*4==byts))); - - blk->oplist[started].rd.type=byts==8?FMT_V2:byts==12?FMT_V3: - byts==16?FMT_V4:byts==32?FMT_V8:FMT_V16; - blk->oplist[started].flags=byts|0x80; - if (stride==8) - blk->oplist[started].flags|=0x100; - blk->oplist[started].Flow=(rdc-1)*2 - (pend_add?1:0); - blk->oplist[started+1].rs2._imm=addv; - - DEBUG_LOG(DYNAREC, "Read Combination %d %d!",rdc,addv); - } - else if (rdc!=1) - { - DEBUG_LOG(DYNAREC, "Read Combination failed %d %d %d",rdc,rdc*stride*4,addv); - } - started=-1; - } - } - } - - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - if (op->Flow) - { - blk->oplist.erase(blk->oplist.begin()+i+2,blk->oplist.begin()+i+2+op->Flow); - } - } -} -//Write Groups -void wtgrp(RuntimeBlockInfo* blk) -{ - int started=-1; - Sh4RegType reg; - Sh4RegType regd; - u32 stride; - bool pend_add; - u32 rdc; - u32 addv; - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - op->Flow=0; - - if (started<0) - { - if (op->op==shop_writem && op->rs2.type>=FMT_F32 && op->rs1.is_reg() && op->rs3.is_null()) - { - started=i; - stride=op->rd.count(); - reg=op->rs1._reg; - regd=op->rs2._reg; - pend_add=true; - rdc=1; - addv=0; - } - } - else - { - if (!pend_add && op->op==shop_writem && op->rs2._reg==(regd-stride) && op->rs1.is_reg() && op->rs1._reg==reg && op->rs3.is_null()) - { - regd=(Sh4RegType)(regd-stride); - pend_add=true; - rdc++; - } - else if (pend_add && op->op==shop_sub && op->rd._reg==op->rs1._reg && op->rs1.is_reg() && op->rs1._reg==reg && op->rs2.is_imm() && op->rs2._imm==(stride*4)) - { - pend_add=false; - addv+=op->rs2._imm; - } - else - { - u32 byts=rdc*stride*4; - u32 mask=byts/4; - if (mask==3) mask=4; - mask--; - - if (rdc!=1 /*&& (!(regd&mask))*/ && (byts==8 || byts==12 || byts==16 || byts==32 || byts==64)) - { - verify(addv==byts || (pend_add && (addv+stride*4==byts))); - - blk->oplist[started].rs2.type=byts==8?FMT_V2:byts==12?FMT_V3: - byts==16?FMT_V4:byts==32?FMT_V8:FMT_V16; - blk->oplist[started].rs2._reg=regd; - blk->oplist[started].rs3._imm=-(rdc-1)*stride*4; - blk->oplist[started].rs3.type=FMT_IMM; - blk->oplist[started].flags=byts|0x80; - if (stride==8) - blk->oplist[started].flags|=0x100; - blk->oplist[started].Flow=(rdc-1)*2 - (pend_add?1:0); - blk->oplist[started+1].rs2._imm=addv; - - DEBUG_LOG(DYNAREC, "Write Combination %d %d!",rdc,addv); - } - else if (rdc!=1) - { - DEBUG_LOG(DYNAREC, "Write Combination failed fr%d,%d, %d %d %d",regd,mask,rdc,rdc*stride*4,addv); - } - i=started; - started=-1; - } - } - } - - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - if (op->Flow) - { - blk->oplist.erase(blk->oplist.begin()+i+2,blk->oplist.begin()+i+2+op->Flow); - } - } -} - -bool ReadsPhy(shil_opcode* op, u32 phy) -{ - return true; -} - -bool WritesPhy(shil_opcode* op, u32 phy) -{ - return true; -} - -void rw_related(RuntimeBlockInfo* blk) -{ - u32 reg[sh4_reg_count]={0}; - - u32 total=0; - u32 memtotal=0; - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - op->Flow=0; - - - if (op->op==shop_ifb || op->op==shop_sync_sr) - { - memset(reg,0,sizeof(reg)); - } - if ( (op->op==shop_add || op->op==shop_sub) ) - { - if (reg[op->rd._reg]) - { - if (op->rs1.is_r32i() && op->rs1._reg==op->rd._reg && op->rs2.is_imm_s16()) - { - //nothing ! - } - else - reg[op->rd._reg]=0; - } - } - else - { - - if (op->op==shop_readm || op->op==shop_writem) - if (op->rs1.is_r32i()) - memtotal++; - - if (op->op==shop_readm || op->op==shop_writem) - { - if (op->rs1.is_r32i()) - { - if (op->rs3.is_imm_s16() || op->rs3.is_null()) - { - reg[op->rs1._reg]++; - if (reg[op->rs1._reg]>1) - total++; - } - //else - //reg[op->rs1._reg]=0; - } - } - - if (op->rd.is_reg() && reg[op->rd._reg]) - reg[op->rd._reg]=0; - if (op->rd2.is_reg() && reg[op->rd2._reg]) - reg[op->rd2._reg]=0; - } - - } - - if (memtotal) - { - u32 lookups=memtotal-total; - - //printf("rw_related total: %d/%d -- %.2f:1\n",total,memtotal,memtotal/(float)lookups); - } - else - { - //printf("rw_related total: none\n"); - } - - blk->memops=memtotal; - blk->linkedmemops=total; -} - - -//constprop -void constprop(RuntimeBlockInfo* blk) -{ - u32 rv[16]; - bool isi[16]={0}; - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - - if (op->rs2.is_r32i() && op->rs2._reg<16 && isi[op->rs2._reg]) - { - /* - not all opcodes can take rs2 as constant - */ - if (op->op!=shop_readm && op->op!=shop_writem - && op->op!=shop_mul_u16 && op->op!=shop_mul_s16 && op->op!=shop_mul_i32 - && op->op!=shop_mul_u64 && op->op!=shop_mul_s64 - && op->op!=shop_adc && op->op!=shop_sbc) - { - op->rs2.type=FMT_IMM; - op->rs2._imm=rv[op->rs2._reg]; - - if (op->op==shop_shld || op->op==shop_shad) - { - //convert em to mov/shl/shr - - DEBUG_LOG(DYNAREC, "sh*d -> s*l !"); - s32 v=op->rs2._imm; - - if (v>=0) - { - //x86e->Emit(sl32,reg.mapg(op->rd),v); - op->op=shop_shl; - op->rs2._imm=0x1f & v; - } - else if (0==(v&0x1f)) - { - if (op->op!=shop_shad) - { - //r[n]=0; - //x86e->Emit(op_mov32,reg.mapg(op->rd),0); - op->op=shop_mov32; - op->rs1.type=FMT_IMM; - op->rs1._imm=0; - op->rs2.type=FMT_NULL; - } - else - { - //r[n]>>=31; - //x86e->Emit(op_sar32,reg.mapg(op->rd),31); - op->op=shop_sar; - op->rs2._imm=31; - } - } - else - { - //x86e->Emit(sr32,reg.mapg(op->rd),-v); - if (op->op!=shop_shad) - op->op=shop_shr; - else - op->op=shop_sar; - - op->rs2._imm=0x1f & (-v); - } - } - } - } - - if (op->rs1.is_r32i() && op->rs1._reg<16 && isi[op->rs1._reg]) - { - if ((op->op==shop_readm /*|| op->op==shop_writem*/) && (op->flags&0x7F)==4) - { - op->rs1.type=FMT_IMM; - op->rs1._imm=rv[op->rs1._reg]; - - if (op->rs3.is_imm()) - { - op->rs1._imm+=op->rs3._imm; - op->rs3.type=FMT_NULL; - } - DEBUG_LOG(DYNAREC, "%s promotion: %08X",shop_readm==op->op?"shop_readm":"shop_writem",op->rs1._imm); - } - else if (op->op==shop_jdyn) - { - if (blk->BlockType==BET_DynamicJump || blk->BlockType==BET_DynamicCall) - { - blk->BranchBlock=rv[op->rs1._reg]; - if (op->rs2.is_imm()) - blk->BranchBlock+=op->rs2._imm;; - - blk->BlockType=blk->BlockType==BET_DynamicJump?BET_StaticJump:BET_StaticCall; - blk->oplist.erase(blk->oplist.begin()+i); - i--; - DEBUG_LOG(DYNAREC, "SBP: %08X -> %08X!",blk->addr,blk->BranchBlock); - continue; - } - else - { - DEBUG_LOG(DYNAREC, "SBP: failed :("); - } - } - else if (op->op==shop_mov32) - { - //handled later on ! - } - else if (op->op==shop_add || op->op==shop_sub) - { - - if (op->rs2.is_imm()) - { - op->rs1.type = FMT_IMM; - op->rs1._imm= op->op==shop_add ? - (rv[op->rs1._reg]+op->rs2._imm): - (rv[op->rs1._reg]-op->rs2._imm); - op->rs2.type = FMT_NULL; - DEBUG_LOG(DYNAREC, "%s -> mov32!",op->op==shop_add?"shop_add":"shop_sub"); - op->op=shop_mov32; - } - - else if (op->op==shop_add && !op->rs2.is_imm()) - { - u32 immy=rv[op->rs1._reg]; - op->rs1=op->rs2; - op->rs2.type = FMT_IMM; - op->rs2._imm=immy; - DEBUG_LOG(DYNAREC, "%s -> imm prm (%08X)!",op->op==shop_add?"shop_add":"shop_sub",immy); - } - } - else - { - op->op=op->op; - } - } - - if (op->rd.is_r32i() && op->rd._reg<16) isi[op->rd._reg]=false; - if (op->rd2.is_r32i() && op->rd2._reg<16) isi[op->rd._reg]=false; - - if (op->op==shop_mov32 && op->rs1.is_imm() && op->rd.is_r32i() && op->rd._reg<16) - { - isi[op->rd._reg]=true; - rv[op->rd._reg]=op->rs1._imm; - } - - //NOT WORKING - //WE NEED PROPER PAGELOCKS - if (false && op->op==shop_readm && op->rs1.is_imm() && op->rd.is_r32i() && op->rd._reg<16 && op->flags==0x4 && op->rs3.is_null()) - { - u32 baddr=blk->addr&0x0FFFFFFF; - - if (/*baddr==0xC158400 &&*/ blk->addr/PAGE_SIZE == op->rs1._imm/PAGE_SIZE) - { - isi[op->rd._reg]=true; - rv[op->rd._reg]= ReadMem32(op->rs1._imm); - DEBUG_LOG(DYNAREC, "IMM MOVE: %08X -> %08X",op->rs1._imm,rv[op->rd._reg]); - - op->op=shop_mov32; - op->rs1._imm=rv[op->rd._reg]; - } - } - } - - rw_related(blk); -} - -//read_v4m3z1 -void read_v4m3z1(RuntimeBlockInfo* blk) -{ - - int state=0; - int st_sta=0; - Sh4RegType reg_a; - Sh4RegType reg_fb; - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - - bool a=false,b=false; - if ((i+6)>blk->oplist.size()) - break; - - if (state==0 && op->op==shop_readm && op->rd.is_r32f() && op->rs1.is_r32i() && op->rs3.is_null()) - { - if (op->rd._reg==reg_fr_0 || op->rd._reg==reg_fr_4 || op->rd._reg==reg_fr_8 || op->rd._reg==reg_fr_12) - { - reg_a=op->rs1._reg; - reg_fb=op->rd._reg; - st_sta=i; - goto _next_st; - } - goto _fail; - } - else if (state < 8 && state & 1 && op->op==shop_add && op->rd._reg==reg_a && op->rs1.is_reg() && op->rs1._reg==reg_a && op->rs2.is_imm() && op->rs2._imm==4) - { - if (state==7) - { - u32 start=st_sta; - - for (int j=0;j<6;j++) - { - blk->oplist.erase(blk->oplist.begin()+start); - } - - i=start+1; - op=&blk->oplist[start+0]; - op->op=shop_readm; - op->flags=0x440; - op->rd=shil_param(reg_fb==reg_fr_0?regv_fv_0: - reg_fb==reg_fr_4?regv_fv_4: - reg_fb==reg_fr_8?regv_fv_8: - reg_fb==reg_fr_12?regv_fv_12:reg_sr_T); - op->rd2=shil_param(); - - op->rs1=shil_param(reg_a); - op->rs2=shil_param(); - op->rs3=shil_param(); - - op=&blk->oplist[start+1]; - op->op=shop_add; - op->flags=0; - op->rd=shil_param(reg_a); - op->rd2=shil_param(); - - op->rs1=shil_param(reg_a); - op->rs2=shil_param(FMT_IMM,16); - op->rs3=shil_param(); - - goto _end; - } - else - goto _next_st; - } - else if (state >1 && - op->op==shop_readm && op->rd.is_r32f() && op->rd._reg==(reg_fb+state/2) && op->rs1.is_r32i() && op->rs1._reg==reg_a && op->rs3.is_null()) - { - goto _next_st; - } - else if ((a=(op->op==shop_mov32 && op->rd._reg==(reg_fb+3) && op->rs1.is_imm() && (op->rs1._imm==0x3f800000 /*|| op->rs1._imm==0*/))) || - (b=(i>7 && op[-7].op==shop_mov32 && op[-7].rd._reg==(reg_fb+3) && op[-7].rs1.is_imm() && (op[-7].rs1._imm==0x3f800000 /*|| op[-7].rs1._imm==0*/))) ) - { - if (state==6) - { - if (b) - st_sta--; - if (a) - DEBUG_LOG(DYNAREC, "NOT B"); - u32 start=st_sta; - - for (int j=0;j<5;j++) - { - blk->oplist.erase(blk->oplist.begin()+start); - } - - i=start+1; - op=&blk->oplist[start+0]; - op->op=shop_readm; - op->flags=0x431; - op->rd=shil_param(reg_fb==reg_fr_0?regv_fv_0: - reg_fb==reg_fr_4?regv_fv_4: - reg_fb==reg_fr_8?regv_fv_8: - reg_fb==reg_fr_12?regv_fv_12:reg_sr_T); - op->rd2=shil_param(); - - op->rs1=shil_param(reg_a); - op->rs2=shil_param(); - op->rs3=shil_param(); - - op=&blk->oplist[start+1]; - op->op=shop_add; - op->flags=0; - op->rd=shil_param(reg_a); - op->rd2=shil_param(); - - op->rs1=shil_param(reg_a); - op->rs2=shil_param(FMT_IMM,12); - op->rs3=shil_param(); - - goto _end; - } - else - goto _fail; - } - else - goto _fail; - - - die("wth"); - -_next_st: - state ++; - continue; - -_fail: - if (state) - i=st_sta; -_end: - state=0; - - } - -} - -//dejcond -void dejcond(RuntimeBlockInfo* blk) -{ - u32 rv[16]; - bool isi[16]={0}; - - if (!blk->has_jcond) return; - - bool found=false; - u32 jcondp=0; - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - - if (found) - { - if ((op->rd.is_reg() && op->rd._reg==reg_sr_T) || op->op==shop_ifb) - { - found=false; - } - } - - if (op->op==shop_jcond) - { - found=true; - jcondp=i; - } - } - - if (found) - { - blk->has_jcond=false; - blk->oplist.erase(blk->oplist.begin()+jcondp); - } -} - -//detect bswaps and talk about them -void enswap(RuntimeBlockInfo* blk) -{ - Sh4RegType r; - int state=0; - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - - op->Flow=0; - - if (state==0 && op->op==shop_swaplb) - { - if (op->rd._reg==op->rs1._reg) - { - state=1; - r=op->rd._reg; - op->Flow=1; - continue; - } - else - { - DEBUG_LOG(DYNAREC, "bswap -- wrong regs"); - } - } - - if (state==1 && op->op==shop_ror && op->rs2.is_imm() && op->rs2._imm==16 && - op->rs1._reg==r) - { - if (op->rd._reg==r) - { - state=2; - op->Flow=1; - continue; - } - else - { - DEBUG_LOG(DYNAREC, "bswap -- wrong regs"); - } - } - - if (state==2 && op->op==shop_swaplb && op->rs1._reg==r) - { - if (op->rd._reg!=r) - { - DEBUG_LOG(DYNAREC, "oops?"); - } - else - { - DEBUG_LOG(DYNAREC, "SWAPM!"); - } - op->Flow=1; - state=0; - } - - } -} - -//enjcond -//this is a normally slower -//however, cause of reg alloc stuff in arm, this -//speeds up access to SR_T (pc_dyn is stored in reg, not mem) -//This is temporary til that limitation is fixed on the reg alloc logic -void enjcond(RuntimeBlockInfo* blk) -{ - u32 rv[16]; - bool isi[16]={0}; - - if (!blk->has_jcond && (blk->BlockType==BET_Cond_0||blk->BlockType==BET_Cond_1)) - { - shil_opcode jcnd; - - jcnd.op=shop_jcond; - jcnd.rs1=shil_param(reg_sr_T); - jcnd.rd=shil_param(reg_pc_dyn); - jcnd.flags=0; - blk->oplist.push_back(jcnd); - blk->has_jcond=true; - } -} - - -//"links" consts to each other -void constlink(RuntimeBlockInfo* blk) -{ - Sh4RegType def=NoReg; - s32 val; - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - - if (op->op!=shop_mov32) - def=NoReg; - else - { - - if (def!=NoReg && op->rs1.is_imm() && op->rs1._imm==val) - { - op->rs1=shil_param(def); - } - else if (def==NoReg && op->rs1.is_imm() && op->rs1._imm==0) - { - //def=op->rd._reg; - val = op->rs1._imm; - } - } - } -} - - -void srt_waw(RuntimeBlockInfo* blk) -{ - bool found=false; - u32 srtw=0; - - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - - if (found) - { - if ((op->rs1.is_reg() && op->rs1._reg==reg_sr_T) - || (op->rs2.is_reg() && op->rs2._reg==reg_sr_T) - || (op->rs3.is_reg() && op->rs3._reg==reg_sr_T) - || op->op==shop_ifb) - { - found=false; - } - } - - if (op->rd.is_reg() && op->rd._reg==reg_sr_T && op->rd2.is_null()) - { - if (found) - { - blk->oplist.erase(blk->oplist.begin()+srtw); - i--; - } - - found=true; - srtw=i; - } - } - -} - -#include "hw/sh4/modules/ccn.h" #include "ngen.h" #include "hw/sh4/sh4_core.h" -#include "hw/sh4/sh4_mmr.h" - #define SHIL_MODE 1 #include "shil_canonical.h" @@ -888,143 +22,11 @@ void srt_waw(RuntimeBlockInfo* blk) #include "ssa.h" -//Simplistic Write after Write without read pass to remove (a few) dead opcodes -//Seems to be working void AnalyseBlock(RuntimeBlockInfo* blk) { SSAOptimizer optim(blk); optim.Optimize(); return; - - u32 st[sh4_reg_count]={0}; - /* - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - - if (op->rs1.is_reg() && st[op->rs1._reg]==0) - st[op->rs1._reg]=1; - - if (op->rs2.is_reg() && st[op->rs2._reg]==0) - st[op->rs2._reg]=1; - - if (op->rs3.is_reg() && st[op->rs3._reg]==0) - st[op->rs3._reg]=1; - - if (op->rd.is_reg()) - st[op->rd._reg]|=2; - - if (op->rd2.is_reg()) - st[op->rd2._reg]|=2; - } - - if (st[reg_sr_T]&1) - { - printf("BLOCK: %08X\n",blk->addr); - - puts("rin: "); - - for (int i=0;ihas_jcond && blk->oplist.size() > 0 && - blk->oplist[blk->oplist.size()-1].rd._reg==reg_sr_T; - - srt_waw(blk); - constlink(blk); - //dejcond(blk); - if (last_op_sets_flags) - { - shilop op= blk->oplist[blk->oplist.size()-1].op; - if (op == shop_test || op==shop_seteq || op==shop_setab || op==shop_setae - || op == shop_setge || op==shop_setgt) - ; - else - last_op_sets_flags=false; - } - if (!last_op_sets_flags) - enjcond(blk); - //read_v4m3z1(blk); - //rw_related(blk); - - return; //disbled to be on the safe side .. - memset(RegisterWrite,-1,sizeof(RegisterWrite)); - memset(RegisterRead,-1,sizeof(RegisterRead)); - - total_blocks++; - for (size_t i=0;ioplist.size();i++) - { - shil_opcode* op=&blk->oplist[i]; - op->Flow=0; - if (op->op==shop_ifb) - { - fallback_blocks++; - return; - } - - RegReadInfo(op->rs1,i); - RegReadInfo(op->rs2,i); - RegReadInfo(op->rs3,i); - - RegWriteInfo(&blk->oplist[0],op->rd,i); - RegWriteInfo(&blk->oplist[0],op->rd2,i); - } - - for (size_t i=0;ioplist.size();i++) - { - if (blk->oplist[i].Flow) - { - blk->oplist.erase(blk->oplist.begin()+i); - REMOVED_OPS++; - i--; - } - } - - int affregs=0; - for (int i=0;i<16;i++) - { - if (RegisterWrite[i]!=0) - { - affregs++; - //printf("r%02d:%02d ",i,RegisterWrite[i]); - } - } - //printf("<> %d\n",affregs); - - //printf("%d FB, %d native, %.2f%% || %d removed ops!\n",fallback_blocks,total_blocks-fallback_blocks,fallback_blocks*100.f/total_blocks,REMOVED_OPS); - //printf("\nBlock: %d affecter regs %d c\n",affregs,blk->guest_cycles); } string name_reg(Sh4RegType reg) @@ -1089,7 +91,7 @@ string name_reg(Sh4RegType reg) return ss.str(); } -string dissasm_param(const shil_param& prm, bool comma) +static string dissasm_param(const shil_param& prm, bool comma) { stringstream ss; diff --git a/core/hw/sh4/sh4_interrupts.cpp b/core/hw/sh4/sh4_interrupts.cpp index a05536fb7..fe9ef6afc 100644 --- a/core/hw/sh4/sh4_interrupts.cpp +++ b/core/hw/sh4/sh4_interrupts.cpp @@ -20,7 +20,7 @@ */ //these are fixed -/* TODO const */ u16 IRLPriority=0x0246; +const u16 IRLPriority = 0x0246; #define IRLP9 &IRLPriority,0 #define IRLP11 &IRLPriority,4 #define IRLP13 &IRLPriority,8 diff --git a/core/nullDC.cpp b/core/nullDC.cpp index cb7134a1b..b2e03e160 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -1026,9 +1026,15 @@ void dc_loadstate() return; } - fread(data, 1, total_size, f) ; + size_t read_size = fread(data, 1, total_size, f) ; fclose(f); - + if (read_size != total_size) + { + WARN_LOG(SAVESTATE, "Failed to load state - I/O error"); + gui_display_notification("Failed to load state - I/O error", 2000); + cleanup_serialize(data) ; + return; + } data_ptr = data ; @@ -1040,13 +1046,16 @@ void dc_loadstate() #endif bm_Reset(); - if ( ! dc_unserialize(&data_ptr, &total_size) ) + u32 unserialized_size = 0; + if ( ! dc_unserialize(&data_ptr, &unserialized_size) ) { WARN_LOG(SAVESTATE, "Failed to load state - could not unserialize data") ; gui_display_notification("Invalid save state", 2000); cleanup_serialize(data) ; return; } + if (unserialized_size != total_size) + WARN_LOG(SAVESTATE, "Save state error: read %d bytes but used %d", total_size, unserialized_size); mmu_set_state(); sh4_cpu.ResetCache(); diff --git a/core/serialize.cpp b/core/serialize.cpp index 2a98a00cf..66e843917 100644 --- a/core/serialize.cpp +++ b/core/serialize.cpp @@ -24,9 +24,7 @@ #include "hw/sh4/dyna/ngen.h" #include "hw/naomi/naomi_cart.h" -/* - * search for "maybe" to find items that were left out that may be needed - */ +#define REICAST_SKIP(size) do { *(u8**)data += size; *total_size += size; } while (false) extern "C" void DYNACALL TAWriteSQ(u32 address,u8* sqb); @@ -35,7 +33,10 @@ enum serialize_version_enum { V2, V3, V4, - V5_LIBRETRO + V5_LIBRETRO_UNSUPPORTED, + V6_LIBRETRO, + + V5 = 800, } ; //./core/hw/arm7/arm_mem.cpp @@ -45,103 +46,37 @@ extern bool e68k_out; extern u32 e68k_reg_L; extern u32 e68k_reg_M; - - //./core/hw/arm7/arm7.cpp extern DECL_ALIGN(8) reg_pair arm_Reg[RN_ARM_REG_COUNT]; extern bool armIrqEnable; extern bool armFiqEnable; extern int armMode; extern bool Arm7Enabled; -extern u8 cpuBitsSet[256]; -/* - if AREC dynarec enabled: - vector ops; - u8* icPtr; - u8* ICache; - u8 ARM7_TCB[ICacheSize+4096]; - void* EntryPoints[8*1024*1024/4]; - map renamed_regs; - u32 rename_reg_base; - u32 nfb,ffb,bfb,mfb; - static x86_block* x86e; - x86_Label* end_lbl; - u8* ARM::emit_opt=0; - eReg ARM::reg_addr; - eReg ARM::reg_dst; - s32 ARM::imma; -*/ - - - //./core/hw/aica/dsp.o extern DECL_ALIGN(4096) dsp_t dsp; -//recheck dsp.cpp if FEAT_DSPREC == DYNAREC_JIT - - - - -//./core/hw/aica/aica.o -//these are all just pointers into aica_reg -//extern CommonData_struct* CommonData; -//extern DSPData_struct* DSPData; -//extern InterruptInfo* MCIEB; -//extern InterruptInfo* MCIPD; -//extern InterruptInfo* MCIRE; -//extern InterruptInfo* SCIEB; -//extern InterruptInfo* SCIPD; -//extern InterruptInfo* SCIRE; extern AicaTimer timers[3]; - - //./core/hw/aica/aica_if.o extern VLockedMemory aica_ram; extern u32 VREG;//video reg =P extern u32 ARMRST;//arm reset reg extern u32 rtc_EN; -//extern s32 aica_pending_dma ; extern int dma_sched_id; - //./core/hw/aica/aica_mem.o extern u8 aica_reg[0x8000]; - - //./core/hw/aica/sgc_if.o struct ChannelEx; #define AicaChannel ChannelEx -extern s32 volume_lut[16]; -extern s32 tl_lut[256 + 768]; //xx.15 format. >=255 is muted -extern u32 AEG_ATT_SPS[64]; -extern u32 AEG_DSR_SPS[64]; -extern s16 pl; -extern s16 pr; -//this is just a pointer to aica_reg -//extern DSP_OUT_VOL_REG* dsp_out_vol; -//not needed - one-time init -//void(* STREAM_STEP_LUT [5][2][2])(ChannelEx *ch) -//void(* STREAM_INITAL_STEP_LUT [5])(ChannelEx *ch) -//void(* AEG_STEP_LUT [4])(ChannelEx *ch) -//void(* FEG_STEP_LUT [4])(ChannelEx *ch) -//void(* ALFOWS_CALC [4])(ChannelEx *ch) -//void(* PLFOWS_CALC [4])(ChannelEx *ch) //special handling -//extern AicaChannel AicaChannel::Chans[64]; #define Chans AicaChannel::Chans #define CDDA_SIZE (2352/2) extern s16 cdda_sector[CDDA_SIZE]; extern u32 cdda_index; -extern SampleType mxlr[64]; -extern u32 samples_gen; - - - - //./core/hw/holly/sb.o extern Array sb_regs; @@ -149,24 +84,13 @@ extern u32 SB_ISTNRM; extern u32 SB_FFST_rc; extern u32 SB_FFST; - - //./core/hw/holly/sb_mem.o -//unused -//static HollyInterruptID dmatmp1; -//static HollyInterruptID dmatmp2; -//static HollyInterruptID OldDmaId; - extern MemChip *sys_rom; extern MemChip *sys_nvmem; - //./core/hw/gdrom/gdrom_response.o extern u16 reply_11[] ; - - - //./core/hw/gdrom/gdromv3.o extern int gdrom_schid; extern signed int sns_asc; @@ -196,57 +120,20 @@ extern GD_SecNumbT SecNumber; extern GD_StatusT GDStatus; extern ByteCount_t ByteCount ; - - - - //./core/hw/maple/maple_devs.o extern char EEPROM[0x100]; extern bool EEPROM_loaded; //./core/hw/maple/maple_if.o -//one time set extern int maple_schid; -//incremented but never read -//extern u32 dmacount; extern bool maple_ddt_pending_reset; - //./core/hw/modem/modem.cpp extern int modem_sched; - - //./core/hw/pvr/Renderer_if.o -//only written - not read -//extern u32 VertexCount; -extern u32 FrameCount; -//one-time init -//extern Renderer* renderer; -//these are just mutexes used during rendering -//extern cResetEvent rs; -//extern cResetEvent re; -//these max_?? through ovrn are written and not read -//extern int max_idx; -//extern int max_mvo; -//extern int max_op; -//extern int max_pt; -//extern int max_tr; -//extern int max_vtx; -//extern int max_modt; -//extern int ovrn; -//seems safe to omit this - gets refreshed every frame from a pool -//extern TA_context* _pvrrc; -//just a flag indiating the rendering thread is running -//extern int rend_en ; -//the renderer thread - one time set -//extern cThread rthd; extern bool pend_rend; -//maybe -//extern u32 memops_t,memops_l; - - //./core/hw/pvr/pvr_mem.o extern u32 YUV_tempdata[512/4];//512 bytes extern u32 YUV_dest; @@ -256,113 +143,27 @@ extern u32 YUV_y_curr; extern u32 YUV_x_size; extern u32 YUV_y_size; - - - //./core/hw/pvr/pvr_regs.o extern bool fog_needs_update; extern u8 pvr_regs[pvr_RegSize]; - - - //./core/hw/pvr/spg.o extern u32 in_vblank; extern u32 clc_pvr_scanline; -extern u32 pvr_numscanlines; -extern u32 prv_cur_scanline; -extern u32 vblk_cnt; -extern u32 Line_Cycles; -extern u32 Frame_Cycles; extern int render_end_schid; extern int vblank_schid; extern int time_sync; -extern double speed_load_mspdf; -extern int mips_counter; -extern double full_rps; -extern u32 fskip; - - - //./core/hw/pvr/ta.o -extern u32 ta_type_lut[256]; extern u8 ta_fsm[2049]; //[2048] stores the current state extern u32 ta_fsm_cl; - - - -//./core/hw/pvr/ta_ctx.o -//these frameskipping don't need to be saved -//extern int frameskip; -//extern bool FrameSkipping; // global switch to enable/disable frameskip -//maybe need these - but hopefully not -//extern TA_context* ta_ctx; -//extern tad_context ta_tad; -//extern TA_context* vd_ctx; -//extern rend_context vd_rc; -//extern cMutex mtx_rqueue; -//extern TA_context* rqueue; -//extern cResetEvent frame_finished; -//extern cMutex mtx_pool; -//extern vector ctx_pool; -//extern vector ctx_list; -//end maybe - - - //./core/hw/pvr/ta_vtx.o extern bool pal_needs_update; -//extern u32 decoded_colors[3][65536]; -extern u32 tileclip_val; -extern u8 f32_su8_tbl[65536]; -//written but never read -//extern ModTriangle* lmr; -//never changed -//extern PolyParam nullPP; -//maybe -//extern PolyParam* CurrentPP; -//maybe -//extern List* CurrentPPlist; -//TA state vars -extern DECL_ALIGN(4) u8 FaceBaseColor[4]; -extern DECL_ALIGN(4) u8 FaceOffsColor[4]; -extern DECL_ALIGN(4) u8 FaceBaseColor1[4]; -extern DECL_ALIGN(4) u8 FaceOffsColor1[4]; -extern DECL_ALIGN(4) u32 SFaceBaseColor; -extern DECL_ALIGN(4) u32 SFaceOffsColor; -//maybe -//extern TaListFP* TaCmd; -//maybe -//extern u32 CurrentList; -//maybe -//extern TaListFP* VertexDataFP; -//written but never read -//extern bool ListIsFinished[5]; -//maybe ; need special handler -//FifoSplitter<0> TAFifo0; -//counter for frameskipping - doesn't need to be saved -//extern int ta_parse_cnt; - - - //./core/rend/TexCache.o -//maybe -//extern u8* vq_codebook; -//extern u32 palette_index; -//extern bool KillTex; -//extern u32 detwiddle[2][8][1024]; -//maybe -//extern vector VramLocks[/*VRAM_SIZE*/(16*1024*1024)/PAGE_SIZE]; -//maybe - probably not - just a locking mechanism -//extern cMutex vramlist_lock; extern VLockedMemory vram; - - - //./core/hw/sh4/sh4_mmr.o extern Array OnChipRAM; extern Array CCN; //CCN : 14 registers @@ -376,23 +177,10 @@ extern Array TMU; //TMU : 12 registers extern Array SCI; //SCI : 8 registers extern Array SCIF; //SCIF : 10 registers - - - //./core/hw/sh4/sh4_mem.o extern VLockedMemory mem_b; -//one-time init -//extern _vmem_handler area1_32b; -//one-time init -//extern _vmem_handler area5_handler; - - - //./core/hw/sh4/sh4_interrupts.o -extern u16 IRLPriority; -//one-time init -//extern InterptSourceList_Entry InterruptSourceList[28]; extern DECL_ALIGN(64) u16 InterruptEnvId[32]; extern DECL_ALIGN(64) u32 InterruptBit[32]; extern DECL_ALIGN(64) u32 InterruptLevelBit[16]; @@ -400,51 +188,26 @@ extern u32 interrupt_vpend; // Vector of pending interrupts extern u32 interrupt_vmask; // Vector of masked interrupts (-1 inhibits all interrupts) extern u32 decoded_srimask; // Vector of interrupts allowed by SR.IMSK (-1 inhibits all interrupts) - - - //./core/hw/sh4/sh4_core_regs.o extern Sh4RCB* p_sh4rcb; -//just method pointers -//extern sh4_if sh4_cpu; -//one-time set -//extern u8* sh4_dyna_rcb; -extern u32 old_rm; -extern u32 old_dn; - - - //./core/hw/sh4/sh4_sched.o extern u64 sh4_sched_ffb; extern u32 sh4_sched_intr; extern vector sch_list; -//extern int sh4_sched_next_id; - - - //./core/hw/sh4/interpr/sh4_interpreter.o extern int aica_schid; extern int rtc_schid; - - - //./core/hw/sh4/modules/serial.o extern SCIF_SCFSR2_type SCIF_SCFSR2; extern u8 SCIF_SCFRDR2; extern SCIF_SCFDR2_type SCIF_SCFDR2; - - - //./core/hw/sh4/modules/bsc.o extern BSC_PDTRA_type BSC_PDTRA; - - - //./core/hw/sh4/modules/tmu.o extern u32 tmu_shift[3]; extern u32 tmu_mask[3]; @@ -454,15 +217,9 @@ extern int tmu_sched[3]; extern u32 tmu_ch_base[3]; extern u64 tmu_ch_base64[3]; - - - //./core/hw/sh4/modules/ccn.o extern u32 CCN_QACR_TR[2]; - - - //./core/hw/sh4/modules/mmu.o extern TLB_Entry UTLB[64]; extern TLB_Entry ITLB[4]; @@ -472,127 +229,11 @@ extern u32 sq_remap[64]; static u32 ITLB_LRU_USE[64]; #endif - - //./core/imgread/common.o extern u32 NullDriveDiscType; -//maybe - seems to all be one-time inits ; needs special handler -//extern Disc* disc; extern u8 q_subchannel[96]; - - - -//./core/nullDC.o -//extern unsigned FLASH_SIZE; -//extern unsigned BBSRAM_SIZE; -//extern unsigned BIOS_SIZE; -//extern unsigned RAM_SIZE; -//extern unsigned ARAM_SIZE; -//extern unsigned VRAM_SIZE; -//extern unsigned RAM_MASK; -//extern unsigned ARAM_MASK; -//extern unsigned VRAM_MASK; -//settings can be dynamic -//extern settings_t settings; - - - - -//./core/reios/reios.o -//never used -//extern u8* biosrom; -//one time init -//extern u8* flashrom; -//one time init -//extern u32 base_fad ; -//one time init -//extern bool descrambl; -//one time init -//extern bool bootfile_inited; -//all these reios_?? are one-time inits -//extern char reios_bootfile[32]; -//extern char reios_hardware_id[17]; -//extern char reios_maker_id[17]; -//extern char reios_device_info[17]; -//extern char reios_area_symbols[9]; -//extern char reios_peripherals[9]; -//extern char reios_product_number[11]; -//extern char reios_product_version[7]; -//extern char reios_releasedate[17]; -//extern char reios_boot_filename[17]; -//extern char reios_software_company[17]; -//extern char reios_software_name[129]; -//one time init -//extern map hooks; -//one time init -//extern map hooks_rev; - - - - -//./core/reios/gdrom_hle.o -//never used in any meaningful way -//extern u32 SecMode[4]; - - - - -//./core/reios/descrambl.o -//random seeds can be...random -//extern unsigned int seed; - - - -//./core/rend/gles/gles.o -//maybe -//extern GLCache glcache; -//maybe -//extern gl_ctx gl; -//maybe -//extern struct ShaderUniforms_t ShaderUniforms; -//maybe -//extern u32 gcflip; -//maybe -//extern float fb_scale_x; -//extern float fb_scale_y; -//extern float scale_x; -//extern float scale_y; -//extern int screen_width; -//extern int screen_height; -//extern GLuint fogTextureId; -//end maybe - - - -//./core/rend/gles/gldraw.o -//maybe -//extern PipelineShader* CurrentShader; -//written, but never used -//extern Vertex* vtx_sort_base; -//maybe -//extern vector pidx_sort; - - - - -//./core/rend/gles/gltex.o -//maybe ; special handler -//extern map TexCache; -//maybe -//extern FBT fb_rtt; -//not used -//static int TexCacheLookups; -//static int TexCacheHits; -//static float LastTexCacheStats; -//maybe should get reset naturally if needed -//GLuint fbTextureId; - - - - //./core/hw/naomi/naomi.o -extern u32 naomi_updates; extern u32 GSerialBuffer; extern u32 BSerialBuffer; extern int GBufPos; @@ -618,86 +259,6 @@ extern u32 reg_dimm_48; //parameters extern u32 reg_dimm_4c; //status/control reg ? extern bool NaomiDataRead; - - - -//./core/hw/naomi/naomi_cart.o -//all one-time loads -//u8* RomPtr; -//u32 RomSize; -//fd_t* RomCacheMap; -//u32 RomCacheMapCount; - - - - -//./core/rec-x64/rec_x64.o -//maybe need special handler -//extern BlockCompilerx64 *compilerx64_data; - - - - -//./core/rec.o -#if FEAT_SHREC == DYNAREC_CPP -extern int idxnxx; -#endif - - - -//./core/hw/sh4/dyna/decoder.o -//temp storage only -//extern RuntimeBlockInfo* blk; -extern state_t state; -extern Sh4RegType div_som_reg1; -extern Sh4RegType div_som_reg2; -extern Sh4RegType div_som_reg3; - - - - -//./core/hw/sh4/dyna/driver.o -//extern u8 SH4_TCB[CODE_SIZE+4096]; -//one time ptr set -//extern u8* CodeCache; -//extern u32 LastAddr; -//extern u32 LastAddr_min; -//temp storage only -//extern u32* emit_ptr; -extern char block_hash[1024]; - - - - -//./core/hw/sh4/dyna/blockmanager.o -//cleared but never read -//extern bm_List blocks_page[/*BLOCKS_IN_PAGE_LIST_COUNT*/(32*1024*1024)/4096]; -//maybe - the next three seem to be list of precompiled blocks of code - but if not found will populate -//extern bm_List all_blocks; -//extern bm_List del_blocks; -//extern blkmap_t blkmap; -//these two are never referenced -//extern u32 bm_gc_luc; -//extern u32 bm_gcf_luc; -//data is never written to this -//extern u32 PAGE_STATE[(32*1024*1024)/*RAM_SIZE*//32]; -//never read -//extern u32 total_saved; -//counter with no real controlling logic behind it -//extern u32 rebuild_counter; -//just printf output -//extern bool print_stats; - - - - -//./core/hw/sh4/dyna/shil.o -extern u32 RegisterWrite[sh4_reg_count]; -extern u32 RegisterRead[sh4_reg_count]; -extern u32 fallback_blocks; -extern u32 total_blocks; -extern u32 REMOVED_OPS; - bool rc_serialize(void *src, unsigned int src_size, void **dest, unsigned int *total_size) { if ( *dest != NULL ) @@ -728,21 +289,21 @@ bool register_serialize(Array& regs,void **data, unsigned int *t for ( i = 0 ; i < regs.Size ; i++ ) { - REICAST_S(regs.data[i].flags) ; REICAST_S(regs.data[i].data32) ; } return true ; } -bool register_unserialize(Array& regs,void **data, unsigned int *total_size ) +bool register_unserialize(Array& regs,void **data, unsigned int *total_size, serialize_version_enum version) { int i = 0 ; u32 dummy = 0 ; for ( i = 0 ; i < regs.Size ; i++ ) { - REICAST_US(regs.data[i].flags) ; + if (version < V5) + REICAST_US(dummy); // regs.data[i].flags if ( ! (regs.data[i].flags & REG_RF) ) REICAST_US(regs.data[i].data32) ; else @@ -755,7 +316,7 @@ bool dc_serialize(void **data, unsigned int *total_size) { int i = 0; int j = 0; - serialize_version_enum version = V4 ; + serialize_version_enum version = V5; *total_size = 0 ; @@ -775,11 +336,6 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_S(armFiqEnable); REICAST_S(armMode); REICAST_S(Arm7Enabled); - REICAST_SA(cpuBitsSet,256); - bool dummy; - REICAST_S(dummy); - REICAST_S(dummy); - REICAST_S(dummy); REICAST_S(dsp); @@ -797,22 +353,10 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_SA(aica_reg,0x8000); - - - REICAST_SA(volume_lut,16); - REICAST_SA(tl_lut,256 + 768); - REICAST_SA(AEG_ATT_SPS,64); - REICAST_SA(AEG_DSR_SPS,64); - REICAST_S(pl); - REICAST_S(pr); - channel_serialize(data, total_size) ; REICAST_SA(cdda_sector,CDDA_SIZE); REICAST_S(cdda_index); - REICAST_SA(mxlr,64); - REICAST_S(samples_gen); - register_serialize(sb_regs, data, total_size) ; REICAST_S(SB_ISTNRM); @@ -822,15 +366,6 @@ bool dc_serialize(void **data, unsigned int *total_size) sys_rom->Serialize(data, total_size); sys_nvmem->Serialize(data, total_size); - /* - REICAST_S(sys_nvmem->size); - REICAST_S(sys_nvmem->mask); -#ifdef FLASH_SIZE - REICAST_S(sys_nvmem->state); -#endif - REICAST_SA(sys_nvmem->data, sys_nvmem->size); - */ - REICAST_SA(reply_11,16) ; @@ -853,6 +388,7 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_S(data_write_mode); REICAST_S(DriveSel); REICAST_S(Error); + REICAST_S(IntReason); REICAST_S(Features); REICAST_S(SecCount); @@ -869,10 +405,6 @@ bool dc_serialize(void **data, unsigned int *total_size) mcfg_SerializeDevices(data, total_size); - REICAST_S(FrameCount); - REICAST_S(pend_rend); - - REICAST_SA(YUV_tempdata,512/4); REICAST_S(YUV_dest); REICAST_S(YUV_blockcount); @@ -885,29 +417,10 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_S(in_vblank); REICAST_S(clc_pvr_scanline); - REICAST_S(pvr_numscanlines); - REICAST_S(prv_cur_scanline); - REICAST_S(vblk_cnt); - REICAST_S(Line_Cycles); - REICAST_S(Frame_Cycles); - REICAST_S(speed_load_mspdf); - REICAST_S(mips_counter); - REICAST_S(full_rps); - REICAST_S(fskip); - - - REICAST_SA(ta_type_lut,256); - REICAST_SA(ta_fsm,2049); + REICAST_S(ta_fsm[2048]); REICAST_S(ta_fsm_cl); - REICAST_S(tileclip_val); - REICAST_SA(f32_su8_tbl,65536); - REICAST_SA(FaceBaseColor,4); - REICAST_SA(FaceOffsColor,4); - REICAST_S(SFaceBaseColor); - REICAST_S(SFaceOffsColor); - REICAST_SA(vram.data, vram.size); REICAST_SA(OnChipRAM.data,OnChipRAM_SIZE); @@ -925,9 +438,6 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_SA(mem_b.data, mem_b.size); - - - REICAST_S(IRLPriority); REICAST_SA(InterruptEnvId,32); REICAST_SA(InterruptBit,32); REICAST_SA(InterruptLevelBit,16); @@ -951,23 +461,11 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_SA((*p_sh4rcb).sq_buffer,64/8); - //store these before unserializing and then restore after - //void *getptr = &((*p_sh4rcb).cntx.sr.GetFull) ; - //void *setptr = &((*p_sh4rcb).cntx.sr.SetFull) ; REICAST_S((*p_sh4rcb).cntx); - REICAST_S(old_rm); - REICAST_S(old_dn); - - - - REICAST_S(sh4_sched_ffb); REICAST_S(sh4_sched_intr); - //extern vector list; - - REICAST_S(sch_list[aica_schid].tag) ; REICAST_S(sch_list[aica_schid].start) ; REICAST_S(sch_list[aica_schid].end) ; @@ -1007,16 +505,16 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_S(sch_list[time_sync].start) ; REICAST_S(sch_list[time_sync].end) ; - #ifdef ENABLE_MODEM +#ifdef ENABLE_MODEM REICAST_S(sch_list[modem_sched].tag) ; REICAST_S(sch_list[modem_sched].start) ; REICAST_S(sch_list[modem_sched].end) ; - #else +#else int modem_dummy = 0; REICAST_S(modem_dummy); REICAST_S(modem_dummy); REICAST_S(modem_dummy); - #endif +#endif REICAST_S(SCIF_SCFSR2); REICAST_S(SCIF_SCFRDR2); @@ -1044,8 +542,6 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_S(NullDriveDiscType); REICAST_SA(q_subchannel,96); - REICAST_S(naomi_updates); - REICAST_S(i); //BoardID REICAST_S(GSerialBuffer); REICAST_S(BSerialBuffer); REICAST_S(GBufPos); @@ -1071,38 +567,6 @@ bool dc_serialize(void **data, unsigned int *total_size) REICAST_S(reg_dimm_4c); REICAST_S(NaomiDataRead); -#if FEAT_SHREC == DYNAREC_CPP - REICAST_S(idxnxx); -#else - REICAST_S(i); -#endif - - REICAST_S(state); - REICAST_S(div_som_reg1); - REICAST_S(div_som_reg2); - REICAST_S(div_som_reg3); - - REICAST_S(i); //LastAddr - REICAST_S(i); //LastAddr_min - REICAST_SA(block_hash,1024); - - REICAST_SA(RegisterWrite,sh4_reg_count); - REICAST_SA(RegisterRead,sh4_reg_count); - REICAST_S(fallback_blocks); - REICAST_S(total_blocks); - REICAST_S(REMOVED_OPS); - - REICAST_S(i); //REICAST_SA(kcode,4); - REICAST_S(i); - REICAST_S(i); //REICAST_SA(rt,4); - REICAST_S(i); //REICAST_SA(lt,4); - REICAST_S(i); //REICAST_SA(vks,4); - REICAST_S(i); - REICAST_S(i); - REICAST_S(i); - REICAST_S(i); //REICAST_SA(joyx,4); - REICAST_S(i); //REICAST_SA(joyy,4); - REICAST_S(settings.dreamcast.broadcast); REICAST_S(settings.dreamcast.cable); REICAST_S(settings.dreamcast.region); @@ -1110,6 +574,8 @@ bool dc_serialize(void **data, unsigned int *total_size) if (CurrentCartridge != NULL) CurrentCartridge->Serialize(data, total_size); + DEBUG_LOG(SAVESTATE, "Saved %d bytes", *total_size); + return true ; } @@ -1129,11 +595,11 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) REICAST_US(armFiqEnable); REICAST_US(armMode); REICAST_US(Arm7Enabled); - REICAST_USA(cpuBitsSet,256); + REICAST_SKIP(256); // cpuBitsSet bool dummy; - REICAST_US(dummy); - REICAST_US(dummy); - REICAST_US(dummy); + REICAST_US(dummy); // intState + REICAST_US(dummy); // stopState + REICAST_US(dummy); // holdState REICAST_US(dsp); @@ -1143,7 +609,6 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) REICAST_US(timers[i].m_step); } - REICAST_USA(aica_ram.data,aica_ram.size) ; REICAST_US(VREG); REICAST_US(ARMRST); @@ -1151,33 +616,27 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) REICAST_USA(aica_reg,0x8000); + u16 dummyshort; - - REICAST_USA(volume_lut,16); - REICAST_USA(tl_lut,256 + 768); - REICAST_USA(AEG_ATT_SPS,64); - REICAST_USA(AEG_DSR_SPS,64); - REICAST_US(pl); - REICAST_US(pr); + REICAST_SKIP(4 * 16); // volume_lut + REICAST_SKIP(4 * 256 + 768); // tl_lut. Due to a previous bug this is not 4 * (256 + 768) + REICAST_SKIP(4 * 64); // AEG_ATT_SPS + REICAST_SKIP(4 * 64); // AEG_DSR_SPS + REICAST_US(dummyshort); // pl + REICAST_US(dummyshort); // pr channel_unserialize(data, total_size) ; REICAST_USA(cdda_sector,CDDA_SIZE); REICAST_US(cdda_index); - REICAST_USA(mxlr,64); - REICAST_US(samples_gen); + REICAST_SKIP(4 * 64); // mxlr + REICAST_US(i); // samples_gen - - register_unserialize(sb_regs, data, total_size) ; + register_unserialize(sb_regs, data, total_size, V6_LIBRETRO) ; REICAST_US(SB_ISTNRM); REICAST_US(SB_FFST_rc); REICAST_US(SB_FFST); - - - //this is one-time init, no updates - don't need to serialize - //extern RomChip sys_rom; - REICAST_US(i); //LIBRETRO_S(sys_nvmem_sram.size); verify(i == 0); REICAST_US(i); //LIBRETRO_S(sys_nvmem_sram.mask); @@ -1192,10 +651,6 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) die("Naomi/Atomiswave libretro savestates are not supported"); REICAST_USA(sys_nvmem->data, sys_nvmem->size); - - //this is one-time init, no updates - don't need to serialize - //extern _vmem_handler area0_handler; - REICAST_USA(reply_11,16); REICAST_US(sns_asc); @@ -1222,19 +677,17 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) REICAST_US(SecNumber); REICAST_US(GDStatus); REICAST_US(ByteCount); - REICAST_US(i); //LIBRETRO_S(GDROM_TICK); - + REICAST_US(i); // GDROM_TICK REICAST_USA(EEPROM,0x100); REICAST_US(EEPROM_loaded); + bool dumbool; REICAST_US(maple_ddt_pending_reset); - - mcfg_UnserializeDevices(data, total_size); - - REICAST_US(FrameCount); - REICAST_US(pend_rend); - + mcfg_UnserializeDevices(data, total_size, false); + REICAST_US(i); // FrameCount + REICAST_US(dumbool); // pend_rend + pend_rend = false; REICAST_USA(YUV_tempdata,512/4); REICAST_US(YUV_dest); @@ -1244,73 +697,65 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) REICAST_US(YUV_x_size); REICAST_US(YUV_y_size); - bool dumbool; - REICAST_US(dumbool); //LIBRETRO_S(fog_needs_update); + REICAST_US(dumbool); // fog_needs_update REICAST_USA(pvr_regs,pvr_RegSize); fog_needs_update = true ; REICAST_US(in_vblank); REICAST_US(clc_pvr_scanline); - REICAST_US(pvr_numscanlines); - REICAST_US(prv_cur_scanline); - REICAST_US(vblk_cnt); - REICAST_US(Line_Cycles); - REICAST_US(Frame_Cycles); - REICAST_US(speed_load_mspdf); - REICAST_US(mips_counter); - REICAST_US(full_rps); + REICAST_US(i); // pvr_numscanlines + REICAST_US(i); // prv_cur_scanline + REICAST_US(i); // vblk_cnt + REICAST_US(i); // Line_Cycles + REICAST_US(i); // Frame_Cycles + REICAST_SKIP(8); // speed_load_mspdf + REICAST_US(i); // mips_counter + REICAST_SKIP(8); // full_rps - REICAST_USA(ta_type_lut,256); + REICAST_SKIP(4 * 256); // ta_type_lut REICAST_USA(ta_fsm,2049); REICAST_US(ta_fsm_cl); - - REICAST_US(dumbool); //LIBRETRO_S(pal_needs_update); - for (int i = 0; i < 4; i++) REICAST_US(j); //LIBRETRO_SA(_pal_rev_256,4); - for (int i = 0; i < 64; i++) REICAST_US(j); //LIBRETRO_SA(_pal_rev_16,64); - for (int i = 0; i < 4; i++) REICAST_US(j); //LIBRETRO_SA(pal_rev_256,4); - for (int i = 0; i < 64; i++) REICAST_US(j); //LIBRETRO_SA(pal_rev_16,64); + REICAST_US(dumbool); // pal_needs_update + for (int i = 0; i < 4; i++) REICAST_US(j); // _pal_rev_256 + for (int i = 0; i < 64; i++) REICAST_US(j); // _pal_rev_16 + for (int i = 0; i < 4; i++) REICAST_US(j); // pal_rev_256 + for (int i = 0; i < 64; i++) REICAST_US(j); // pal_rev_16 for ( i = 0 ; i < 3 ; i++ ) { u32 buf[65536]; //u32 *ptr = decoded_colors[i] ; REICAST_US(buf); //LIBRETRO_SA(ptr,65536); } - REICAST_US(tileclip_val); - REICAST_USA(f32_su8_tbl,65536); - REICAST_USA(FaceBaseColor,4); - REICAST_USA(FaceOffsColor,4); - REICAST_US(SFaceBaseColor); - REICAST_US(SFaceOffsColor); + REICAST_US(i); // tileclip_val + REICAST_SKIP(65536); // f32_su8_tbl + REICAST_SKIP(4); // FaceBaseColor + REICAST_SKIP(4); // FaceOffsColor + REICAST_US(i); // SFaceBaseColor + REICAST_US(i); // SFaceOffsColor pal_needs_update = true; - REICAST_US(i); //LIBRETRO_S(palette_index); - REICAST_US(dumbool); //LIBRETRO_S(KillTex); - for (int i = 0; i < 1024; i++) REICAST_US(j); //LIBRETRO_SA(palette16_ram,1024); - for (int i = 0; i < 1024; i++) REICAST_US(j); //LIBRETRO_SA(palette32_ram,1024); - for (i = 0 ; i < 2 ; i++) - for (j = 0 ; j < 8 ; j++) - { - u32 buf[1024]; //u32 *ptr = detwiddle[i][j] ; - REICAST_US(buf); //LIBRETRO_SA(ptr,1024); - } - REICAST_USA(vram.data, vram.size); + REICAST_US(i); // palette_index + REICAST_US(dumbool); // KillTex + REICAST_SKIP(4 * 1024); // palette16_ram + REICAST_SKIP(4 * 1024); // palette32_ram + REICAST_SKIP(2 * 8 * 4 * 1024); // detwiddle[][] + REICAST_USA(vram.data, vram.size); REICAST_USA(OnChipRAM.data,OnChipRAM_SIZE); - register_unserialize(CCN, data, total_size) ; - register_unserialize(UBC, data, total_size) ; - register_unserialize(BSC, data, total_size) ; - register_unserialize(DMAC, data, total_size) ; - register_unserialize(CPG, data, total_size) ; - register_unserialize(RTC, data, total_size) ; - register_unserialize(INTC, data, total_size) ; - register_unserialize(TMU, data, total_size) ; - register_unserialize(SCI, data, total_size) ; - register_unserialize(SCIF, data, total_size) ; + register_unserialize(CCN, data, total_size, V6_LIBRETRO) ; + register_unserialize(UBC, data, total_size, V6_LIBRETRO) ; + register_unserialize(BSC, data, total_size, V6_LIBRETRO) ; + register_unserialize(DMAC, data, total_size, V6_LIBRETRO) ; + register_unserialize(CPG, data, total_size, V6_LIBRETRO) ; + register_unserialize(RTC, data, total_size, V6_LIBRETRO) ; + register_unserialize(INTC, data, total_size, V6_LIBRETRO) ; + register_unserialize(TMU, data, total_size, V6_LIBRETRO) ; + register_unserialize(SCI, data, total_size, V6_LIBRETRO) ; + register_unserialize(SCIF, data, total_size, V6_LIBRETRO) ; REICAST_USA(mem_b.data, mem_b.size); - - REICAST_US(IRLPriority); + REICAST_US(dummyshort); // IRLPriority REICAST_USA(InterruptEnvId,32); REICAST_USA(InterruptBit,32); REICAST_USA(InterruptLevelBit,16); @@ -1328,25 +773,16 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) else if ( i == 3 ) do_sqw_nommu = &do_sqw_nommu_full ; - - REICAST_USA((*p_sh4rcb).sq_buffer,64/8); - //store these before unserializing and then restore after - //void *getptr = &((*p_sh4rcb).cntx.sr.GetFull) ; - //void *setptr = &((*p_sh4rcb).cntx.sr.SetFull) ; REICAST_US((*p_sh4rcb).cntx); - //(*p_sh4rcb).cntx.sr.GetFull = getptr ; - //(*p_sh4rcb).cntx.sr.SetFull = setptr ; - REICAST_US(old_rm); - REICAST_US(old_dn); + REICAST_US(i); // old_rm + REICAST_US(i); // old_dn REICAST_US(sh4_sched_ffb); REICAST_US(sh4_sched_intr); - //extern vector sch_list; - REICAST_US(sch_list[aica_schid].tag) ; REICAST_US(sch_list[aica_schid].start) ; REICAST_US(sch_list[aica_schid].end) ; @@ -1385,17 +821,16 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) REICAST_US(sch_list[time_sync].tag) ; REICAST_US(sch_list[time_sync].start) ; REICAST_US(sch_list[time_sync].end) ; - - #ifdef ENABLE_MODEM +#ifdef ENABLE_MODEM REICAST_US(sch_list[modem_sched].tag) ; REICAST_US(sch_list[modem_sched].start) ; REICAST_US(sch_list[modem_sched].end) ; - #else +#else int modem_dummy; REICAST_US(modem_dummy); REICAST_US(modem_dummy); REICAST_US(modem_dummy); - #endif +#endif REICAST_US(SCIF_SCFSR2); REICAST_US(SCIF_SCFRDR2); @@ -1412,14 +847,15 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) REICAST_USA(CCN_QACR_TR,2); - REICAST_USA(UTLB,64); - REICAST_USA(ITLB,4); + REICAST_USA(UTLB, 64); + REICAST_USA(ITLB, 4); + #if defined(NO_MMU) REICAST_USA(sq_remap,64); #else REICAST_USA(ITLB_LRU_USE,64); + REICAST_US(i); // mmu_error_TT #endif - REICAST_US(NullDriveDiscType); REICAST_USA(q_subchannel,96); @@ -1435,7 +871,7 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) - REICAST_US(naomi_updates); + REICAST_US(i); // naomi_updates REICAST_US(i); // BoardID REICAST_US(GSerialBuffer); REICAST_US(BSerialBuffer); @@ -1469,23 +905,23 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) REICAST_US(i); #endif - REICAST_US(state); - REICAST_US(div_som_reg1); - REICAST_US(div_som_reg2); - REICAST_US(div_som_reg3); + REICAST_SKIP(sizeof(state_t)); // state + REICAST_US(i); // div_som_reg1 + REICAST_US(i); // div_som_reg2 + REICAST_US(i); // div_som_reg3 - //REICAST_USA(CodeCache,CODE_SIZE) ; - //REICAST_USA(SH4_TCB,CODE_SIZE+4096); - REICAST_US(i); //LastAddr - REICAST_US(i); //LastAddr_min - REICAST_USA(block_hash,1024); + REICAST_US(i); // LastAddr + REICAST_US(i); // LastAddr_min + REICAST_SKIP(1024); // block_hash - - REICAST_USA(RegisterWrite,sh4_reg_count); - REICAST_USA(RegisterRead,sh4_reg_count); - REICAST_US(fallback_blocks); - REICAST_US(total_blocks); - REICAST_US(REMOVED_OPS); + for (int i = 0; i < sh4_reg_count; i++) // RegisterRead, RegisterWrite + { + REICAST_US(j); + REICAST_US(j); + } + REICAST_US(i); // fallback_blocks); + REICAST_US(i); // total_blocks); + REICAST_US(i); // REMOVED_OPS REICAST_US(settings.dreamcast.broadcast); REICAST_US(settings.dreamcast.cable); @@ -1494,6 +930,8 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size) if (CurrentCartridge != NULL) CurrentCartridge->Unserialize(data, total_size); + DEBUG_LOG(SAVESTATE, "Loaded %d bytes (libretro compat)", *total_size); + return true ; } @@ -1506,9 +944,9 @@ bool dc_unserialize(void **data, unsigned int *total_size) *total_size = 0 ; REICAST_US(version) ; - if (version == V5_LIBRETRO) + if (version == V6_LIBRETRO) return dc_unserialize_libretro(data, total_size); - if (version != V4) + if (version != V4 && version != V5) { WARN_LOG(SAVESTATE, "Save State version not supported: %d", version); return false; @@ -1524,11 +962,8 @@ bool dc_unserialize(void **data, unsigned int *total_size) REICAST_US(armFiqEnable); REICAST_US(armMode); REICAST_US(Arm7Enabled); - REICAST_USA(cpuBitsSet,256); - bool dummy; - REICAST_US(dummy); - REICAST_US(dummy); - REICAST_US(dummy); + if (version < 5) + REICAST_SKIP(256 + 3); REICAST_US(dsp); @@ -1545,46 +980,40 @@ bool dc_unserialize(void **data, unsigned int *total_size) REICAST_USA(aica_reg,0x8000); - REICAST_USA(volume_lut,16); - REICAST_USA(tl_lut,256 + 768); - REICAST_USA(AEG_ATT_SPS,64); - REICAST_USA(AEG_DSR_SPS,64); - REICAST_US(pl); - REICAST_US(pr); - + if (version < V5) + { + REICAST_SKIP(4 * 16); + REICAST_SKIP(4 * 256 + 768); + REICAST_SKIP(4 * 64); + REICAST_SKIP(4 * 64); + REICAST_SKIP(2); + REICAST_SKIP(2); + } channel_unserialize(data, total_size) ; REICAST_USA(cdda_sector,CDDA_SIZE); REICAST_US(cdda_index); - REICAST_USA(mxlr,64); - REICAST_US(samples_gen); + if (version < V5) + { + REICAST_SKIP(4 * 64); + REICAST_SKIP(4); + } - register_unserialize(sb_regs, data, total_size) ; + register_unserialize(sb_regs, data, total_size, version) ; REICAST_US(SB_ISTNRM); REICAST_US(SB_FFST_rc); REICAST_US(SB_FFST); + if (version < V5) + { + REICAST_SKIP(4); // size + REICAST_SKIP(4); // mask + } sys_rom->Unserialize(data, total_size); sys_nvmem->Unserialize(data, total_size); - /* - REICAST_US(sys_nvmem.size); - REICAST_US(sys_nvmem.mask); -#ifdef FLASH_SIZE - REICAST_US(sys_nvmem.state); -#endif - REICAST_USA(sys_nvmem.data,sys_nvmem.size); - */ - - //this is one-time init, no updates - don't need to serialize - //extern _vmem_handler area0_handler; - - - REICAST_USA(reply_11,16) ; - - REICAST_US(sns_asc); REICAST_US(sns_ascq); REICAST_US(sns_key); @@ -1610,18 +1039,19 @@ bool dc_unserialize(void **data, unsigned int *total_size) REICAST_US(GDStatus); REICAST_US(ByteCount); - REICAST_USA(EEPROM,0x100); REICAST_US(EEPROM_loaded); - REICAST_US(maple_ddt_pending_reset); - mcfg_UnserializeDevices(data, total_size); - - REICAST_US(FrameCount); - REICAST_US(pend_rend); + mcfg_UnserializeDevices(data, total_size, version < 5); + if (version < V5) + { + REICAST_SKIP(4); + REICAST_SKIP(1); // pend_rend + } + pend_rend = false; REICAST_USA(YUV_tempdata,512/4); REICAST_US(YUV_dest); @@ -1636,47 +1066,54 @@ bool dc_unserialize(void **data, unsigned int *total_size) REICAST_US(in_vblank); REICAST_US(clc_pvr_scanline); - REICAST_US(pvr_numscanlines); - REICAST_US(prv_cur_scanline); - REICAST_US(vblk_cnt); - REICAST_US(Line_Cycles); - REICAST_US(Frame_Cycles); - REICAST_US(speed_load_mspdf); - REICAST_US(mips_counter); - REICAST_US(full_rps); - REICAST_US(fskip); + if (version < V5) + { + REICAST_US(i); // pvr_numscanlines + REICAST_US(i); // prv_cur_scanline + REICAST_US(i); // vblk_cnt + REICAST_US(i); // Line_Cycles + REICAST_US(i); // Frame_Cycles + REICAST_SKIP(8); // speed_load_mspdf + REICAST_US(i); // mips_counter + REICAST_SKIP(8); // full_rps + REICAST_US(i); // fskip - REICAST_USA(ta_type_lut,256); - REICAST_USA(ta_fsm,2049); + REICAST_SKIP(4 * 256); + REICAST_SKIP(2048); // ta_fsm + } + REICAST_US(ta_fsm[2048]); REICAST_US(ta_fsm_cl); - REICAST_US(tileclip_val); - REICAST_USA(f32_su8_tbl,65536); - REICAST_USA(FaceBaseColor,4); - REICAST_USA(FaceOffsColor,4); - REICAST_US(SFaceBaseColor); - REICAST_US(SFaceOffsColor); - + if (version < V5) + { + REICAST_SKIP(4); + REICAST_SKIP(65536); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(4); + } pal_needs_update = true; REICAST_USA(vram.data, vram.size); REICAST_USA(OnChipRAM.data,OnChipRAM_SIZE); - register_unserialize(CCN, data, total_size) ; - register_unserialize(UBC, data, total_size) ; - register_unserialize(BSC, data, total_size) ; - register_unserialize(DMAC, data, total_size) ; - register_unserialize(CPG, data, total_size) ; - register_unserialize(RTC, data, total_size) ; - register_unserialize(INTC, data, total_size) ; - register_unserialize(TMU, data, total_size) ; - register_unserialize(SCI, data, total_size) ; - register_unserialize(SCIF, data, total_size) ; + register_unserialize(CCN, data, total_size, version) ; + register_unserialize(UBC, data, total_size, version) ; + register_unserialize(BSC, data, total_size, version) ; + register_unserialize(DMAC, data, total_size, version) ; + register_unserialize(CPG, data, total_size, version) ; + register_unserialize(RTC, data, total_size, version) ; + register_unserialize(INTC, data, total_size, version) ; + register_unserialize(TMU, data, total_size, version) ; + register_unserialize(SCI, data, total_size, version) ; + register_unserialize(SCIF, data, total_size, version) ; REICAST_USA(mem_b.data, mem_b.size); - REICAST_US(IRLPriority); + if (version < V5) + REICAST_SKIP(2); REICAST_USA(InterruptEnvId,32); REICAST_USA(InterruptBit,32); REICAST_USA(InterruptLevelBit,16); @@ -1694,28 +1131,18 @@ bool dc_unserialize(void **data, unsigned int *total_size) else if ( i == 3 ) do_sqw_nommu = &do_sqw_nommu_full ; - - REICAST_USA((*p_sh4rcb).sq_buffer,64/8); - //store these before unserializing and then restore after - //void *getptr = &((*p_sh4rcb).cntx.sr.GetFull) ; - //void *setptr = &((*p_sh4rcb).cntx.sr.SetFull) ; REICAST_US((*p_sh4rcb).cntx); - //(*p_sh4rcb).cntx.sr.GetFull = getptr ; - //(*p_sh4rcb).cntx.sr.SetFull = setptr ; - - REICAST_US(old_rm); - REICAST_US(old_dn); - - - + if (version < V5) + { + REICAST_SKIP(4); + REICAST_SKIP(4); + } REICAST_US(sh4_sched_ffb); REICAST_US(sh4_sched_intr); - //extern vector list; - REICAST_US(sch_list[aica_schid].tag) ; REICAST_US(sch_list[aica_schid].start) ; REICAST_US(sch_list[aica_schid].end) ; @@ -1755,27 +1182,23 @@ bool dc_unserialize(void **data, unsigned int *total_size) REICAST_US(sch_list[time_sync].start) ; REICAST_US(sch_list[time_sync].end) ; - #ifdef ENABLE_MODEM +#ifdef ENABLE_MODEM REICAST_US(sch_list[modem_sched].tag) ; REICAST_US(sch_list[modem_sched].start) ; REICAST_US(sch_list[modem_sched].end) ; - #else +#else int modem_dummy; REICAST_US(modem_dummy); REICAST_US(modem_dummy); REICAST_US(modem_dummy); - #endif +#endif REICAST_US(SCIF_SCFSR2); REICAST_US(SCIF_SCFRDR2); REICAST_US(SCIF_SCFDR2); - REICAST_US(BSC_PDTRA); - - - REICAST_USA(tmu_shift,3); REICAST_USA(tmu_mask,3); REICAST_USA(tmu_mask64,3); @@ -1783,14 +1206,8 @@ bool dc_unserialize(void **data, unsigned int *total_size) REICAST_USA(tmu_ch_base,3); REICAST_USA(tmu_ch_base64,3); - - - REICAST_USA(CCN_QACR_TR,2); - - - REICAST_USA(UTLB,64); REICAST_USA(ITLB,4); #if defined(NO_MMU) @@ -1799,24 +1216,14 @@ bool dc_unserialize(void **data, unsigned int *total_size) REICAST_USA(ITLB_LRU_USE,64); #endif - REICAST_US(NullDriveDiscType); REICAST_USA(q_subchannel,96); -// FIXME -// REICAST_US(i); // FLASH_SIZE -// REICAST_US(i); // BBSRAM_SIZE -// REICAST_US(i); // BIOS_SIZE -// REICAST_US(i); // RAM_SIZE -// REICAST_US(i); // ARAM_SIZE -// REICAST_US(i); // VRAM_SIZE -// REICAST_US(i); // RAM_MASK -// REICAST_US(i); // ARAM_MASK -// REICAST_US(i); // VRAM_MASK - - - REICAST_US(naomi_updates); - REICAST_US(i); // BoardID + if (version < V5) + { + REICAST_SKIP(4); + REICAST_SKIP(4); + } REICAST_US(GSerialBuffer); REICAST_US(BSerialBuffer); REICAST_US(GBufPos); @@ -1842,41 +1249,29 @@ bool dc_unserialize(void **data, unsigned int *total_size) REICAST_US(reg_dimm_4c); REICAST_US(NaomiDataRead); -#if FEAT_SHREC == DYNAREC_CPP - REICAST_US(idxnxx); -#else - REICAST_US(i); -#endif - - REICAST_US(state); - REICAST_US(div_som_reg1); - REICAST_US(div_som_reg2); - REICAST_US(div_som_reg3); - - //REICAST_USA(CodeCache,CODE_SIZE) ; - //REICAST_USA(SH4_TCB,CODE_SIZE+4096); - REICAST_US(i); //LastAddr - REICAST_US(i); //LastAddr_min); - REICAST_USA(block_hash,1024); - - REICAST_USA(RegisterWrite,sh4_reg_count); - REICAST_USA(RegisterRead,sh4_reg_count); - REICAST_US(fallback_blocks); - REICAST_US(total_blocks); - REICAST_US(REMOVED_OPS); - - REICAST_US(i); //REICAST_USA(kcode,4); - REICAST_US(i); - REICAST_US(i); //REICAST_USA(rt,4); - REICAST_US(i); //REICAST_USA(lt,4); - REICAST_US(i); //REICAST_USA(vks,4); - REICAST_US(i); - REICAST_US(i); - REICAST_US(i); - REICAST_US(i); //REICAST_USA(joyx,4); - REICAST_US(i); //REICAST_USA(joyy,4); + if (version < V5) + { + REICAST_US(i); // idxnxx + REICAST_SKIP(sizeof(state_t)); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(1024); + REICAST_SKIP(8 * sh4_reg_count); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(2 * 4); + REICAST_SKIP(4); + REICAST_SKIP(4); + REICAST_SKIP(4 * 4); + REICAST_SKIP(4); + REICAST_SKIP(4); + } REICAST_US(settings.dreamcast.broadcast); REICAST_US(settings.dreamcast.cable); REICAST_US(settings.dreamcast.region); @@ -1884,6 +1279,8 @@ bool dc_unserialize(void **data, unsigned int *total_size) if (CurrentCartridge != NULL) CurrentCartridge->Unserialize(data, total_size); + DEBUG_LOG(SAVESTATE, "Loaded %d bytes", *total_size); + return true ; } #endif