#pragma once #include #include #include "state.h" #include "memory_map.h" static inline bool is_delay_slot(struct architectural_state * state) { return state->is_delay_slot; } static inline void sleep(struct architectural_state * state) { } static inline void ocbp(struct architectural_state * state, uint32_t address) { } static inline uint8_t read_memory8(struct memory_map * map, uint32_t address) { struct memory_map_entry * entry = find_entry(map, address); if (entry == NULL) return 0; uint32_t relative_address = physical_address(address) - entry->start; return entry->access.read_memory8(entry->mem, relative_address); } static inline uint16_t read_memory16(struct memory_map * map, uint32_t address) { assert((address & 0b1) == 0); struct memory_map_entry * entry = find_entry(map, address); if (entry == NULL) return 0; uint32_t relative_address = physical_address(address) - entry->start; return entry->access.read_memory16(entry->mem, relative_address); } static inline uint32_t read_memory32(struct memory_map * map, uint32_t address) { assert((address & 0b11) == 0); struct memory_map_entry * entry = find_entry(map, address); if (entry == NULL) return 0; uint32_t relative_address = physical_address(address) - entry->start; return entry->access.read_memory32(entry->mem, relative_address); } static inline void write_memory8(struct memory_map * map, uint32_t address, uint8_t value) { struct memory_map_entry * entry = find_entry(map, address); if (entry == NULL) return; uint32_t relative_address = physical_address(address) - entry->start; entry->access.write_memory8(entry->mem, relative_address, value); } static inline void write_memory16(struct memory_map * map, uint32_t address, uint16_t value) { assert((address & 0b1) == 0); struct memory_map_entry * entry = find_entry(map, address); if (entry == NULL) return; uint32_t relative_address = physical_address(address) - entry->start; entry->access.write_memory16(entry->mem, relative_address, value); } static inline void write_memory32(struct memory_map * map, uint32_t address, uint32_t value) { assert((address & 0b11) == 0); struct memory_map_entry * entry = find_entry(map, address); if (entry == NULL) return; uint32_t relative_address = physical_address(address) - entry->start; entry->access.write_memory32(entry->mem, relative_address, value); }