reduce differences from upstream
[pcsx_rearmed.git] / libpcsxcore / misc.c
index 854bbb8..7929dc7 100644 (file)
@@ -91,7 +91,7 @@ static void mmssdd( char *b, char *p )
        time[0] = itob(time[0]); time[1] = itob(time[1]); time[2] = itob(time[2]);
 
 #define READTRACK() \
-       if (CDR_readTrack(time) == -1) return -1; \
+       if (!CDR_readTrack(time)) return -1; \
        buf = (void *)CDR_getBuffer(); \
        if (buf == NULL) return -1; \
        else CheckPPFCache((u8 *)buf, time[0], time[1], time[2]);
@@ -418,7 +418,7 @@ static int PSXGetFileType(FILE *f) {
 
        current = ftell(f);
        fseek(f, 0L, SEEK_SET);
-       if (fread(&mybuf, sizeof(mybuf), 1, f) != sizeof(mybuf))
+       if (fread(&mybuf, 1, sizeof(mybuf), f) != sizeof(mybuf))
                goto io_fail;
        
        fseek(f, current, SEEK_SET);
@@ -479,7 +479,7 @@ int Load(const char *ExePath) {
                type = PSXGetFileType(tmpFile);
                switch (type) {
                        case PSX_EXE:
-                               if (fread(&tmpHead, sizeof(EXE_HEADER), 1, tmpFile) != sizeof(EXE_HEADER))
+                               if (fread(&tmpHead, 1, sizeof(EXE_HEADER), tmpFile) != sizeof(EXE_HEADER))
                                        goto fail_io;
                                section_address = SWAP32(tmpHead.t_addr);
                                section_size = SWAP32(tmpHead.t_size);
@@ -499,13 +499,13 @@ int Load(const char *ExePath) {
                        case CPE_EXE:
                                fseek(tmpFile, 6, SEEK_SET); /* Something tells me we should go to 4 and read the "08 00" here... */
                                do {
-                                       if (fread(&opcode, sizeof(opcode), 1, tmpFile) != sizeof(opcode))
+                                       if (fread(&opcode, 1, sizeof(opcode), tmpFile) != sizeof(opcode))
                                                goto fail_io;
                                        switch (opcode) {
                                                case 1: /* Section loading */
-                                                       if (fread(&section_address, sizeof(section_address), 1, tmpFile) != sizeof(section_address))
+                                                       if (fread(&section_address, 1, sizeof(section_address), tmpFile) != sizeof(section_address))
                                                                goto fail_io;
-                                                       if (fread(&section_size, sizeof(section_size), 1, tmpFile) != sizeof(section_size))
+                                                       if (fread(&section_size, 1, sizeof(section_size), tmpFile) != sizeof(section_size))
                                                                goto fail_io;
                                                        section_address = SWAPu32(section_address);
                                                        section_size = SWAPu32(section_size);
@@ -520,7 +520,7 @@ int Load(const char *ExePath) {
                                                        break;
                                                case 3: /* register loading (PC only?) */
                                                        fseek(tmpFile, 2, SEEK_CUR); /* unknown field */
-                                                       if (fread(&psxRegs.pc, sizeof(psxRegs.pc), 1, tmpFile) != sizeof(psxRegs.pc))
+                                                       if (fread(&psxRegs.pc, 1, sizeof(psxRegs.pc), tmpFile) != sizeof(psxRegs.pc))
                                                                goto fail_io;
                                                        psxRegs.pc = SWAPu32(psxRegs.pc);
                                                        break;
@@ -550,7 +550,8 @@ int Load(const char *ExePath) {
                CdromLabel[0] = '\0';
        }
 
-       fclose(tmpFile);
+       if (tmpFile)
+               fclose(tmpFile);
        return retval;
 
 fail_io:
@@ -611,7 +612,7 @@ int SaveState(const char *file) {
        new_dyna_before_save();
 
        if (drc_is_lightrec() && Config.Cpu != CPU_INTERPRETER)
-               lightrec_plugin_prepare_save_state();
+               lightrec_plugin_sync_regs_to_pcsx();
 
        SaveFuncs.write(f, (void *)PcsxHeader, 32);
        SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32));
@@ -699,7 +700,7 @@ int LoadState(const char *file) {
        psxRegs.gteBusyCycle = psxRegs.cycle;
 
        if (drc_is_lightrec() && Config.Cpu != CPU_INTERPRETER)
-               lightrec_plugin_prepare_load_state();
+               lightrec_plugin_sync_regs_from_pcsx();
 
        if (Config.HLE)
                psxBiosFreeze(0);
@@ -758,10 +759,13 @@ int SendPcsxInfo() {
        if (NET_recvData == NULL || NET_sendData == NULL)
                return 0;
 
+       boolean Sio_old = 0;
+       boolean SpuIrq_old = 0;
+       boolean RCntFix_old = 0;
        NET_sendData(&Config.Xa, sizeof(Config.Xa), PSE_NET_BLOCKING);
-       NET_sendData(&Config.Sio, sizeof(Config.Sio), PSE_NET_BLOCKING);
-       NET_sendData(&Config.SpuIrq, sizeof(Config.SpuIrq), PSE_NET_BLOCKING);
-       NET_sendData(&Config.RCntFix, sizeof(Config.RCntFix), PSE_NET_BLOCKING);
+       NET_sendData(&Sio_old, sizeof(Sio_old), PSE_NET_BLOCKING);
+       NET_sendData(&SpuIrq_old, sizeof(SpuIrq_old), PSE_NET_BLOCKING);
+       NET_sendData(&RCntFix_old, sizeof(RCntFix_old), PSE_NET_BLOCKING);
        NET_sendData(&Config.PsxType, sizeof(Config.PsxType), PSE_NET_BLOCKING);
        NET_sendData(&Config.Cpu, sizeof(Config.Cpu), PSE_NET_BLOCKING);
 
@@ -774,10 +778,13 @@ int RecvPcsxInfo() {
        if (NET_recvData == NULL || NET_sendData == NULL)
                return 0;
 
+       boolean Sio_old = 0;
+       boolean SpuIrq_old = 0;
+       boolean RCntFix_old = 0;
        NET_recvData(&Config.Xa, sizeof(Config.Xa), PSE_NET_BLOCKING);
-       NET_recvData(&Config.Sio, sizeof(Config.Sio), PSE_NET_BLOCKING);
-       NET_recvData(&Config.SpuIrq, sizeof(Config.SpuIrq), PSE_NET_BLOCKING);
-       NET_recvData(&Config.RCntFix, sizeof(Config.RCntFix), PSE_NET_BLOCKING);
+       NET_recvData(&Sio_old, sizeof(Sio_old), PSE_NET_BLOCKING);
+       NET_recvData(&SpuIrq_old, sizeof(SpuIrq_old), PSE_NET_BLOCKING);
+       NET_recvData(&RCntFix_old, sizeof(RCntFix_old), PSE_NET_BLOCKING);
        NET_recvData(&Config.PsxType, sizeof(Config.PsxType), PSE_NET_BLOCKING);
 
        SysUpdate();