aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Serpell <daniel.serpell@gmail.com>2019-12-21 21:07:30 -0300
committerDaniel Serpell <daniel.serpell@gmail.com>2019-12-21 21:07:30 -0300
commit989b852bfd18b844737f80320a705b8d0c1c9052 (patch)
treedf136c80a4b4039e65fe77a9e9613293722f58b4
parent4c54517a959579b64c08f44dac61527b1469c599 (diff)
downloademu2-989b852bfd18b844737f80320a705b8d0c1c9052.tar.gz
Move get*/put* functions to common header.
-rw-r--r--src/dos.c39
-rw-r--r--src/emu.h45
-rw-r--r--src/loader.c11
3 files changed, 46 insertions, 49 deletions
diff --git a/src/dos.c b/src/dos.c
index 1647322..13b46aa 100644
--- a/src/dos.c
+++ b/src/dos.c
@@ -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)
{
diff --git a/src/emu.h b/src/emu.h
index 2708543..c367573 100644
--- a/src/emu.h
+++ b/src/emu.h
@@ -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);
Un proyecto texto-plano.xyz