diff options
author | Daniel Serpell <daniel.serpell@gmail.com> | 2019-12-21 21:07:30 -0300 |
---|---|---|
committer | Daniel Serpell <daniel.serpell@gmail.com> | 2019-12-21 21:07:30 -0300 |
commit | 989b852bfd18b844737f80320a705b8d0c1c9052 (patch) | |
tree | df136c80a4b4039e65fe77a9e9613293722f58b4 | |
parent | 4c54517a959579b64c08f44dac61527b1469c599 (diff) | |
download | emu2-989b852bfd18b844737f80320a705b8d0c1c9052.tar.gz |
Move get*/put* functions to common header.
-rw-r--r-- | src/dos.c | 39 | ||||
-rw-r--r-- | src/emu.h | 45 | ||||
-rw-r--r-- | src/loader.c | 11 |
3 files changed, 46 insertions, 49 deletions
@@ -26,46 +26,9 @@ static uint32_t nls_dbc_set_table; static uint8_t *nls_country_info; static uint32_t dos_sysvars; - // Disk Transfer Area, buffer for find-first-file output. +// Disk Transfer Area, buffer for find-first-file output. static int dosDTA; -static void put16(int addr, int v) -{ - memory[0xFFFFF & (addr)] = v; - memory[0xFFFFF & (addr + 1)] = v >> 8; -} - -static void put32(int addr, unsigned v) -{ - put16(addr, v & 0xFFFF); - put16(addr+2, v >> 16); -} - -static int get16(int addr) -{ - return memory[0xFFFFF & addr] + (memory[0xFFFFF & (addr + 1)] << 8); -} - -static unsigned get32(int addr) -{ - return get16(addr) + (get16(addr+2) << 16); -} - -static int putmem(uint32_t dest, const uint8_t *src, unsigned size) -{ - if(size >= 0x100000 || dest >= 0x100000 || size + dest >= 0x100000) - return 1; - memcpy(memory + dest, src, size); - return 0; -} - -static uint8_t *getptr(uint32_t addr, unsigned size) -{ - if(size >= 0x100000 || addr >= 0x100000 || size + addr >= 0x100000) - return 0; - return memory + addr; -} - // Allocates memory for static DOS tables, from "rom" memory static uint32_t get_static_memory(uint16_t bytes, uint16_t align) { @@ -3,6 +3,7 @@ #include <stdint.h> #include <stdio.h> +#include <string.h> extern volatile int exit_cpu; extern uint8_t memory[]; @@ -80,4 +81,48 @@ void cpuClrFlag(enum cpuFlags flag); void cpuSetStartupFlag(enum cpuFlags flag); void cpuClrStartupFlag(enum cpuFlags flag); +// Helper functions to access memory +// Read 16 bit number +static inline void put16(int addr, int v) +{ + memory[0xFFFFF & (addr)] = v; + memory[0xFFFFF & (addr + 1)] = v >> 8; +} + +// Read 32 bit number +static inline void put32(int addr, unsigned v) +{ + put16(addr, v & 0xFFFF); + put16(addr+2, v >> 16); +} + +// Write 16 bit number +static inline int get16(int addr) +{ + return memory[0xFFFFF & addr] + (memory[0xFFFFF & (addr + 1)] << 8); +} + +// Write 32 bit number +static inline unsigned get32(int addr) +{ + return get16(addr) + (get16(addr+2) << 16); +} + +// Copy data to CPU memory +static inline int putmem(uint32_t dest, const uint8_t *src, unsigned size) +{ + if(size >= 0x100000 || dest >= 0x100000 || size + dest >= 0x100000) + return 1; + memcpy(memory + dest, src, size); + return 0; +} + +// Get pointer to CPU memory or null if overflow +static inline uint8_t *getptr(uint32_t addr, unsigned size) +{ + if(size >= 0x100000 || addr >= 0x100000 || size + addr >= 0x100000) + return 0; + return memory + addr; +} + #endif // EMU_H diff --git a/src/loader.c b/src/loader.c index cd7259d..9f79baf 100644 --- a/src/loader.c +++ b/src/loader.c @@ -315,17 +315,6 @@ unsigned get_current_PSP(void) return current_PSP; } -static int get16(int addr) -{ - return memory[addr] + (memory[addr + 1] << 8); -} - -static void put16(int addr, int v) -{ - memory[addr] = v; - memory[addr + 1] = v >> 8; -} - static int g16(uint8_t *buf) { return buf[0] + (buf[1] << 8); |