#include "states.h" #include extern bool is_paused; struct state states[MAX_TICKS]; size_t current_tick = 0; size_t last_tick = 0; void init_state (void) { *cache_locking_busses = CPU_COUNT; *bus_cycles = 0; init_bus (data_bus, cons_cache_bus_data, con_memory_bus_data, 0*BUS_SPACING + BUS_THICKNESS, 1.00, COLOR_DATA, "DATA BUS"); init_bus (addr_bus, cons_cache_bus_addr, con_memory_bus_addr, 1*BUS_SPACING + BUS_THICKNESS, 1.00, COLOR_ADDR, "ADDRESS BUS"); init_bus (shared_bus, cons_cache_bus_shared, NULL, 2*BUS_SPACING + BUS_THICKNESS, 0.75, COLOR_SHARED, "SHARED BUS"); for (int i = 0; i < CPU_COUNT; ++i) { init_cache (caches[i], shared_bus); init_cpu (cpus[i], caches[i]); } init_memory (memory, cpus[0]); } void reset_state (void) { set_state (0); init_state (); is_paused = false; } void set_state (size_t tick) { cache_locking_busses = &states[tick].cache_locking_busses; bus_cycles = &states[tick].bus_cycles; data_bus = &states[tick].data_bus; addr_bus = &states[tick].addr_bus; shared_bus = &states[tick].shared_bus; memory = &states[tick].memory; for (int i = 0; i < CPU_COUNT; ++i) { caches [i] = &states[tick].caches [i]; cpus [i] = &states[tick].cpus [i]; cons_cpu_cache_addr [i] = &states[tick].cons_cpu_cache_addr [i]; cons_cpu_cache_data [i] = &states[tick].cons_cpu_cache_data [i]; cons_cache_bus_shared [i] = &states[tick].cons_cache_bus_shared [i]; cons_cache_bus_addr [i] = &states[tick].cons_cache_bus_addr [i]; cons_cache_bus_data [i] = &states[tick].cons_cache_bus_data [i]; } con_memory_bus_addr = &states[tick].con_memory_bus_addr; con_memory_bus_data = &states[tick].con_memory_bus_data; current_tick = tick; } void save_state (void) { memcpy (&states[current_tick + 1], &states[current_tick + 0], sizeof (struct state)); set_state (current_tick + 1); last_tick = current_tick; // re-link bus connections for (int i = 0; i < CPU_COUNT; ++i) { states[current_tick] . data_bus.cache_connections [i] = &states[current_tick].cons_cache_bus_data [i]; states[current_tick] . addr_bus.cache_connections [i] = &states[current_tick].cons_cache_bus_addr [i]; states[current_tick] . shared_bus.cache_connections [i] = &states[current_tick].cons_cache_bus_shared [i]; } states[current_tick] . data_bus.memory_connection = &states[current_tick].con_memory_bus_data; states[current_tick] . addr_bus.memory_connection = &states[current_tick].con_memory_bus_addr; states[current_tick] . shared_bus.memory_connection = NULL; }