Code does not depend on endian.h anymore (own implementation)
authorAndreas Eversberg <jolly@eversberg.eu>
Wed, 7 Mar 2018 17:16:28 +0000 (18:16 +0100)
committerAndreas Eversberg <jolly@eversberg.eu>
Wed, 7 Mar 2018 17:22:55 +0000 (18:22 +0100)
src/libcpu/execute.c
src/mercenary/main.c

index d7421f3..cb97845 100644 (file)
@@ -20,7 +20,6 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <endian.h>
 #include "execute.h"
 #include "m68k.h"
 #include "m68kcpu.h"
@@ -71,7 +70,8 @@ unsigned int m68k_read_memory_16(unsigned int address)
        if (address > memory_size - 2) {
                return read_io(address);
        }
-       return be16toh(*((uint16_t *)(memory + address)));
+       return  (memory[address] << 8) |
+                memory[address + 1];
 }
 
 unsigned int m68k_read_memory_32(unsigned int address)
@@ -82,7 +82,10 @@ unsigned int m68k_read_memory_32(unsigned int address)
                value |= read_io(address + 2);
                return value;
        }
-       return be32toh(*((uint32_t *)(memory + address)));
+       return  (memory[address] << 24)|
+               (memory[address + 1] << 16) |
+               (memory[address + 2] << 8) |
+                memory[address + 3];
 }
 
 void m68k_write_memory_8(unsigned int address, unsigned int value)
@@ -106,7 +109,8 @@ void m68k_write_memory_16(unsigned int address, unsigned int value)
                write_io(address, value);
                return;
        }
-       *((uint16_t *)(memory + address)) = htobe16(value);
+       memory[address] = value >> 8;
+       memory[address + 1] = value;
 }
 
 void m68k_write_memory_32(unsigned int address, unsigned int value)
@@ -116,7 +120,10 @@ void m68k_write_memory_32(unsigned int address, unsigned int value)
                write_io(address + 2, value);
                return;
        }
-       *((uint32_t *)(memory + address)) = htobe32(value);
+       memory[address] = value >> 24;
+       memory[address + 1] = value >> 16;
+       memory[address + 2] = value >> 8;
+       memory[address + 3] = value;
 }
 
 void execute_init(int32_t _memory_size, uint8_t *_memory, uint16_t *_chipreg)
index 0d8d582..b4c7735 100644 (file)
@@ -20,7 +20,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <endian.h>
+#include <arpa/inet.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include "../libsdl/sdl.h"