OSDN Git Service

[VM][EVENT] Fix wrong effect of before commit.Revert "High resolution accum_clocks...
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sat, 12 Oct 2019 20:14:25 +0000 (05:14 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sat, 12 Oct 2019 20:14:25 +0000 (05:14 +0900)
[VM][EVENT] Update comment of scheduler (EVENT::drive()).
[VM][EVENT] .
[VM][I386] .

source/src/vm/event.cpp
source/src/vm/i386.cpp
source/src/vm/mame/emu/cpu/i386/i386.c

index 4583ed1..33e6e81 100644 (file)
@@ -272,8 +272,8 @@ void EVENT::drive()
                        vline_clocks[index]++;
                }
                for(int i = 1; i < dcount_cpu; i++) {
-                       //d_cpu[i].update_clocks = (int)(1024.0 * (double)d_cpu[i].cpu_clocks / (double)d_cpu[0].cpu_clocks + 0.5);
-                       d_cpu[i].update_clocks = (int)(4096.0 * (double)d_cpu[i].cpu_clocks / (double)d_cpu[0].cpu_clocks + 0.5);
+                       d_cpu[i].update_clocks = (int)(1024.0 * (double)d_cpu[i].cpu_clocks / (double)d_cpu[0].cpu_clocks + 0.5);
+                       //d_cpu[i].update_clocks = (int)(4096.0 * (double)d_cpu[i].cpu_clocks / (double)d_cpu[0].cpu_clocks + 0.5);
                }
                for(DEVICE* device = vm->first_device; device; device = device->next_device) {
                        if(device->get_event_manager_id() == this_device_id) {
@@ -322,26 +322,51 @@ void EVENT::drive()
                                
                                // sub cpu runs continuously and no events will be fired while the given clocks,
                                // so I need to give small enough clocks...
-                               cpu_done_tmp = (event_extra > 0 || cpu_done < 256) ? cpu_done : 256;
-                               cpu_done -= cpu_done_tmp;
+#if 1
+//                             cpu_done_tmp = (event_extra > 0 || cpu_done < 256) ? cpu_done : 256;
+//                             cpu_done -= cpu_done_tmp;
+                               cpu_done_tmp = cpu_done;
+                               cpu_done = 0;           ;
                                for(int i = 1; i < dcount_cpu; i++) {
                                        // run sub cpus
                                        int clock_result = d_cpu[i].update_clocks * cpu_done_tmp;
-                                       int sub_clock;
+                                       int sub_clock = 0;
+                                       int sub_clock2 = 0;
                                        if(clock_result > 0) {
-                                               if(clock_result >= 0x10000) { // OVER 16 clocks with HOST
-                                                       sub_clock = (int)(clock_result >> 12);
-                                                       d_cpu[i].device->run(sub_clock); // Execute over 16 host clocks.
-                                                       clock_result -= (sub_clock << 12);
+                                               if(clock_result >= 0x400) { // OVER 1 clocks with HOST, to reduce risk of overflow@accum_clocks.
+                                                       // Upper clocks are not to need to add accum_clocks,
+                                                       // accum_clocks may be effected by lower value of clock_result,
+                                                       // *excepts multiply value (of adding value to accum_clocks) isn't 2^x*.
+                                                       // 20191013 K.O
+                                                       sub_clock = (int)(clock_result >> 10);
+                                                       // Update only execution clocks (executing later)
+                                                       //d_cpu[i].device->run(sub_clock); // Execute over 1 host clocks.
+                                                       clock_result -= (sub_clock << 10);
                                                }
-                                               d_cpu[i].accum_clocks += clock_result; // At most, 16 host clocks.Guranteed maximum at 16 host clocks.
-                                               sub_clock = (int)(d_cpu[i].accum_clocks >> 12);
+                                               d_cpu[i].accum_clocks += clock_result; // At most, 1 host clocks.Guranteed maximum at 1 host clocks.
+                                               sub_clock2 = (int)(d_cpu[i].accum_clocks >> 10);
+                                               sub_clock += sub_clock2;
                                                if(sub_clock > 0) {
-                                                       d_cpu[i].accum_clocks -= sub_clock << 12;
+                                                       d_cpu[i].accum_clocks -= sub_clock2 << 10;
                                                        d_cpu[i].device->run(sub_clock);
                                                }
                                        }
                                }
+#else
+                               cpu_done_tmp = (event_extra > 0 || cpu_done < 4) ? cpu_done : 4;
+                               cpu_done -= cpu_done_tmp;
+                               for(int i = 1; i < dcount_cpu; i++) {
+                                       // run sub cpus
+                                       int clock_result = d_cpu[i].update_clocks * cpu_done_tmp;
+                                       int sub_clock;
+                                       d_cpu[i].accum_clocks += clock_result; // At most, 16 host clocks.Guranteed maximum at 16 host clocks.
+                                       sub_clock = (int)(d_cpu[i].accum_clocks >> 10);
+                                       if(sub_clock > 0) {
+                                               d_cpu[i].accum_clocks -= sub_clock << 10;
+                                               d_cpu[i].device->run(sub_clock);
+                                       }
+                               }
+#endif
                        }
                        cpu_remain -= cpu_done_tmp;
                        cpu_accum += cpu_done_tmp;
@@ -1169,8 +1194,8 @@ void EVENT::update_config()
        }
 }
 
-// Clock ratio resolution was changed from 2^10 to 2^12.20191011 K.O
-#define STATE_VERSION  5
+// Revert clock ratio to 1024 (2^10).STATE_VERSION to 4; 20191013 K.O
+#define STATE_VERSION  4
 
 bool EVENT::process_state(FILEIO* state_fio, bool loading)
 {
index b545f90..8099641 100644 (file)
 #define CPU_RESET_CALL(name)                   CPU_RESET_NAME(name)(cpustate)
 
 #define CPU_EXECUTE_NAME(name)                 cpu_execute_##name
-#define CPU_EXECUTE(name)                      int CPU_EXECUTE_NAME(name)(i386_state *cpustate, int cycles)
+#define CPU_EXECUTE(name)                      int __FASTCALL CPU_EXECUTE_NAME(name)(i386_state *cpustate, int cycles)
 #define CPU_EXECUTE_CALL(name)                 CPU_EXECUTE_NAME(name)(cpustate, cycles)
 
 #define CPU_TRANSLATE_NAME(name)               cpu_translate_##name
index 40d88bc..4bacac9 100644 (file)
@@ -3283,6 +3283,8 @@ CPU_INIT( i386 )
 {
        i386_state *cpustate = i386_common_init(32);
        build_opcode_table(cpustate, OP_I386);
+//     build_opcode_table(cpustate, OP_I386 | OP_FPU);
+//     build_x87_opcode_table(cpustate);
        cpustate->cycle_table_rm = cycle_table_rm[CPU_CYCLES_I386];
        cpustate->cycle_table_pm = cycle_table_pm[CPU_CYCLES_I386];
        return cpustate;
@@ -3512,6 +3514,8 @@ static CPU_RESET( i386 )
        cpustate->nmi_masked = false;
        cpustate->nmi_latched = false;
 
+//     x87_reset(cpustate);
+       
        cpustate->a20_mask = ~0;
        // Move to zero_state().
        cpustate->cr[0] = 0x7fffffe0; // reserved bits set to 1