diff options
Diffstat (limited to 'src/states.c')
| -rw-r--r-- | src/states.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/states.c b/src/states.c new file mode 100644 index 0000000..3bf80ca --- /dev/null +++ b/src/states.c | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | #include "states.h" | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | extern bool is_paused; | ||
| 5 | |||
| 6 | struct state states[MAX_TICKS]; | ||
| 7 | size_t current_tick = 0; | ||
| 8 | size_t last_tick = 0; | ||
| 9 | |||
| 10 | void | ||
| 11 | init_state (void) | ||
| 12 | { | ||
| 13 | *cache_locking_busses = CPU_COUNT; | ||
| 14 | *bus_cycles = 0; | ||
| 15 | init_bus (data_bus, cons_cache_bus_data, con_memory_bus_data, 0*BUS_SPACING + BUS_THICKNESS, 1.00, COLOR_DATA, "DATA BUS"); | ||
| 16 | init_bus (addr_bus, cons_cache_bus_addr, con_memory_bus_addr, 1*BUS_SPACING + BUS_THICKNESS, 1.00, COLOR_ADDR, "ADDRESS BUS"); | ||
| 17 | init_bus (shared_bus, cons_cache_bus_shared, NULL, 2*BUS_SPACING + BUS_THICKNESS, 0.75, COLOR_SHARED, "SHARED BUS"); | ||
| 18 | for (int i = 0; i < CPU_COUNT; ++i) { | ||
| 19 | init_cache (caches[i], shared_bus); | ||
| 20 | init_cpu (cpus[i], caches[i]); | ||
| 21 | } | ||
| 22 | init_memory (memory, cpus[0]); | ||
| 23 | } | ||
| 24 | |||
| 25 | void | ||
| 26 | reset_state (void) | ||
| 27 | { | ||
| 28 | set_state (0); | ||
| 29 | init_state (); | ||
| 30 | is_paused = false; | ||
| 31 | } | ||
| 32 | |||
| 33 | void | ||
| 34 | set_state (size_t tick) | ||
| 35 | { | ||
| 36 | cache_locking_busses = &states[tick].cache_locking_busses; | ||
| 37 | bus_cycles = &states[tick].bus_cycles; | ||
| 38 | data_bus = &states[tick].data_bus; | ||
| 39 | addr_bus = &states[tick].addr_bus; | ||
| 40 | shared_bus = &states[tick].shared_bus; | ||
| 41 | memory = &states[tick].memory; | ||
| 42 | for (int i = 0; i < CPU_COUNT; ++i) { | ||
| 43 | caches [i] = &states[tick].caches [i]; | ||
| 44 | cpus [i] = &states[tick].cpus [i]; | ||
| 45 | cons_cpu_cache_addr [i] = &states[tick].cons_cpu_cache_addr [i]; | ||
| 46 | cons_cpu_cache_data [i] = &states[tick].cons_cpu_cache_data [i]; | ||
| 47 | cons_cache_bus_shared [i] = &states[tick].cons_cache_bus_shared [i]; | ||
| 48 | cons_cache_bus_addr [i] = &states[tick].cons_cache_bus_addr [i]; | ||
| 49 | cons_cache_bus_data [i] = &states[tick].cons_cache_bus_data [i]; | ||
| 50 | } | ||
| 51 | con_memory_bus_addr = &states[tick].con_memory_bus_addr; | ||
| 52 | con_memory_bus_data = &states[tick].con_memory_bus_data; | ||
| 53 | |||
| 54 | current_tick = tick; | ||
| 55 | } | ||
| 56 | |||
| 57 | void | ||
| 58 | save_state (void) | ||
| 59 | { | ||
| 60 | memcpy (&states[current_tick + 1], | ||
| 61 | &states[current_tick + 0], | ||
| 62 | sizeof (struct state)); | ||
| 63 | set_state (current_tick + 1); | ||
| 64 | last_tick = current_tick; | ||
| 65 | |||
| 66 | // re-link bus connections | ||
| 67 | for (int i = 0; i < CPU_COUNT; ++i) { | ||
| 68 | states[current_tick] . data_bus.cache_connections [i] = &states[current_tick].cons_cache_bus_data [i]; | ||
| 69 | states[current_tick] . addr_bus.cache_connections [i] = &states[current_tick].cons_cache_bus_addr [i]; | ||
| 70 | states[current_tick] . shared_bus.cache_connections [i] = &states[current_tick].cons_cache_bus_shared [i]; | ||
| 71 | } | ||
| 72 | states[current_tick] . data_bus.memory_connection = &states[current_tick].con_memory_bus_data; | ||
| 73 | states[current_tick] . addr_bus.memory_connection = &states[current_tick].con_memory_bus_addr; | ||
| 74 | states[current_tick] . shared_bus.memory_connection = NULL; | ||
| 75 | } | ||
