From b0832f6676c945c9b1262f97a34765b859299988 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 8 Jul 2018 22:35:48 -0700 Subject: 4328 Insert an indirection to avoid over-allocating memory for RAM. --- subx/010core.cc | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/subx/010core.cc b/subx/010core.cc index a364f2f6..dbab5fc5 100644 --- a/subx/010core.cc +++ b/subx/010core.cc @@ -65,51 +65,53 @@ SF = ZF = OF = false; :(before "End Globals") vector Mem; +uint32_t Mem_offset = 0; uint32_t End_of_program = 0; :(before "End Reset") Mem.clear(); Mem.resize(1024); +Mem_offset = 0; End_of_program = 0; :(code) // These helpers depend on Mem being laid out contiguously (so you can't use a // map, etc.) and on the host also being little-endian. inline uint8_t read_mem_u8(uint32_t addr) { - return Mem.at(addr); + return Mem.at(addr-Mem_offset); } inline int8_t read_mem_i8(uint32_t addr) { - return static_cast(Mem.at(addr)); + return static_cast(Mem.at(addr-Mem_offset)); } inline uint32_t read_mem_u32(uint32_t addr) { - return *reinterpret_cast(&Mem.at(addr)); + return *reinterpret_cast(&Mem.at(addr-Mem_offset)); } inline int32_t read_mem_i32(uint32_t addr) { - return *reinterpret_cast(&Mem.at(addr)); + return *reinterpret_cast(&Mem.at(addr-Mem_offset)); } inline uint8_t* mem_addr_u8(uint32_t addr) { - return &Mem.at(addr); + return &Mem.at(addr-Mem_offset); } inline int8_t* mem_addr_i8(uint32_t addr) { - return reinterpret_cast(&Mem.at(addr)); + return reinterpret_cast(&Mem.at(addr-Mem_offset)); } inline uint32_t* mem_addr_u32(uint32_t addr) { - return reinterpret_cast(&Mem.at(addr)); + return reinterpret_cast(&Mem.at(addr-Mem_offset)); } inline int32_t* mem_addr_i32(uint32_t addr) { - return reinterpret_cast(&Mem.at(addr)); + return reinterpret_cast(&Mem.at(addr-Mem_offset)); } inline void write_mem_u8(uint32_t addr, uint8_t val) { - Mem.at(addr) = val; + Mem.at(addr-Mem_offset) = val; } inline void write_mem_i8(uint32_t addr, int8_t val) { - Mem.at(addr) = static_cast(val); + Mem.at(addr-Mem_offset) = static_cast(val); } inline void write_mem_u32(uint32_t addr, uint32_t val) { - *reinterpret_cast(&Mem.at(addr)) = val; + *reinterpret_cast(&Mem.at(addr-Mem_offset)) = val; } inline void write_mem_i32(uint32_t addr, int32_t val) { - *reinterpret_cast(&Mem.at(addr)) = val; + *reinterpret_cast(&Mem.at(addr-Mem_offset)) = val; } //:: core interpreter loop -- cgit 1.4.1-2-gfad0