mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-12-22 15:29:58 +00:00
Move endian swapping code to endianswap.h.
Remove superfluous endian swapping wrappers.
This commit is contained in:
parent
fbe82010f8
commit
720b35aa26
@ -9,6 +9,7 @@
|
||||
#define PPCEMU_H
|
||||
|
||||
#include <setjmp.h>
|
||||
#include "endianswap.h"
|
||||
#include "devices/memctrlbase.h"
|
||||
|
||||
//Uncomment this to help debug the emulator further
|
||||
@ -155,11 +156,6 @@ extern uint64_t ppc_result64_b;
|
||||
extern uint64_t ppc_result64_c;
|
||||
extern uint64_t ppc_result64_d;
|
||||
|
||||
extern uint16_t rev_endian16(uint16_t insert_int);
|
||||
extern uint32_t uimm_rev_endian16(uint32_t insert_int);
|
||||
extern int32_t simm_rev_endian16(int32_t insert_int);
|
||||
extern uint32_t rev_endian32(uint32_t insert_int);
|
||||
extern uint64_t rev_endian64(uint64_t insert_int);
|
||||
|
||||
/* The precise end of a basic block. */
|
||||
enum class BB_end_kind {
|
||||
@ -435,7 +431,7 @@ extern void ppc_fmr();
|
||||
extern void ppc_mffs();
|
||||
extern void ppc_mffsdot();
|
||||
extern void ppc_mtfsf();
|
||||
extern void ppc_mtfsfdot();
|
||||
extern void ppc_mtfsfdot();
|
||||
extern void ppc_mtfsfi();
|
||||
extern void ppc_mtfsfidot();
|
||||
|
||||
|
@ -1901,7 +1901,7 @@ void ppc_sthx(){
|
||||
void ppc_sthbrx(){
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = (reg_a == 0)?ppc_result_b:(ppc_result_a + ppc_result_b);
|
||||
ppc_result_d = (uint32_t)(rev_endian16((uint16_t)ppc_result_d));
|
||||
ppc_result_d = (uint32_t)(BYTESWAP_16((uint16_t)ppc_result_d));
|
||||
address_quickinsert_translate(ppc_result_d, ppc_effective_address, 2);
|
||||
}
|
||||
|
||||
@ -1952,7 +1952,7 @@ void ppc_stwux(){
|
||||
void ppc_stwbrx(){
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = (reg_a == 0)?ppc_result_b:(ppc_result_a + ppc_result_b);
|
||||
ppc_result_d = rev_endian32(ppc_result_d);
|
||||
ppc_result_d = BYTESWAP_32(ppc_result_d);
|
||||
address_quickinsert_translate(ppc_result_d, ppc_effective_address, 4);
|
||||
}
|
||||
|
||||
@ -2137,7 +2137,7 @@ void ppc_lhbrx(){
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = (reg_a == 0)?ppc_result_b:(ppc_result_a + ppc_result_b);
|
||||
address_quickgrab_translate(ppc_effective_address, 2);
|
||||
ppc_result_d = (uint32_t)(rev_endian16((uint16_t)ppc_result_d));
|
||||
ppc_result_d = (uint32_t)(BYTESWAP_16((uint16_t)ppc_result_d));
|
||||
return_value = 0;
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
@ -2156,7 +2156,7 @@ void ppc_lwbrx(){
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = (reg_a == 0)?ppc_result_b:(ppc_result_a + ppc_result_b);
|
||||
address_quickgrab_translate(ppc_effective_address, 4);
|
||||
ppc_result_d = rev_endian32(return_value);
|
||||
ppc_result_d = BYTESWAP_32(return_value);
|
||||
return_value = 0;
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
51
endianswap.h
Normal file
51
endianswap.h
Normal file
@ -0,0 +1,51 @@
|
||||
/** @file Macros for performing byte swapping for quick endian conversion.
|
||||
|
||||
It will try to use the fast built-in machine instructions first
|
||||
and fall back to the slow conversion if none were found.
|
||||
*/
|
||||
|
||||
#ifndef ENDIAN_SWAP_H
|
||||
#define ENDIAN_SWAP_H
|
||||
|
||||
#ifdef __GNUG__ /* GCC, ICC and Clang */
|
||||
|
||||
# ifdef __APPLE__
|
||||
# include <machine/endian.h>
|
||||
# else
|
||||
# include <endian.h>
|
||||
# endif
|
||||
|
||||
# define BYTESWAP_16(x) (__builtin_bswap16 (x))
|
||||
# define BYTESWAP_32(x) (__builtin_bswap32 (x))
|
||||
# define BYTESWAP_64(x) (__builtin_bswap64 (x))
|
||||
|
||||
#elif _MSC_VER /* MSVC */
|
||||
|
||||
# include <stdlib.h>
|
||||
|
||||
# define BYTESWAP_16(x) (_byteswap_ushort (x))
|
||||
# define BYTESWAP_32(x) (_byteswap_ulong (x))
|
||||
# define BYTESWAP_64(x) (_byteswap_uint64 (x))
|
||||
|
||||
#else
|
||||
|
||||
# warning "Unknown byte swapping built-ins (do it the slow way)!"
|
||||
|
||||
# define BYTESWAP_16(x) ((x) >> 8) | (((x) & 0xFFUL) << 8)
|
||||
|
||||
# define BYTESWAP_32(x) ((x) >> 24) | (((x) >> 8) & 0xFF00UL) | \
|
||||
(((x) & 0xFF00UL) << 8) | ((x) << 24)
|
||||
|
||||
# define BYTESWAP_64(x) \
|
||||
((x) >> 56) | \
|
||||
(((x) & 0x00FF000000000000ULL) >> 48) | \
|
||||
(((x) & 0x0000FF0000000000ULL) >> 40) | \
|
||||
(((x) & 0x000000FF00000000ULL) >> 32) | \
|
||||
(((x) & 0x00000000FF000000ULL) << 32) | \
|
||||
(((x) & 0x0000000000FF0000ULL) << 40) | \
|
||||
(((x) & 0x000000000000FF00ULL) << 48) | \
|
||||
(((x) & 0x00000000000000FFULL) << 56)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ENDIAN_SWAP_H */
|
29
main.cpp
29
main.cpp
@ -25,14 +25,6 @@
|
||||
#include "devices/macio.h"
|
||||
#include "devices/mpc106.h"
|
||||
|
||||
#define max_16b_int 65535
|
||||
#define max_32b_int 4294967295
|
||||
#define ENDIAN_REVERSE16(x) (x >> 8) | (((x) & 0x00FF) << 8)
|
||||
#define ENDIAN_REVERSE32(x) (x >> 24) | ((x & 0x00FF0000) >> 8) | ((x & 0x0000FF00) << 8) | (x << 24)
|
||||
#define ENDIAN_REVERSE64(x) (x >> 56) | ((x & 0x00FF000000000000) >> 48) | ((x & 0x0000FF0000000000) >> 40) | ((x & 0x000000FF00000000) >> 32) | \
|
||||
((x & 0x00000000FF000000) << 32) | ((x & 0x0000000000FF0000) << 40) | ((x & 0x000000000000FF00) << 48) | ((x & 0x00000000000000FF) << 56)
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
@ -105,27 +97,6 @@ uint32_t rom_filesize;
|
||||
uint32_t write_opcode;
|
||||
uint8_t write_char;
|
||||
|
||||
/*
|
||||
//DISK VARIABLES
|
||||
unsigned char * grab_disk_buf;
|
||||
bool disk_inserted;
|
||||
uint64_t disk_offset = 0;
|
||||
uint32_t disk_word = 0;
|
||||
*/
|
||||
|
||||
|
||||
uint16_t rev_endian16(uint16_t insert_int){
|
||||
return ENDIAN_REVERSE16(insert_int);
|
||||
}
|
||||
|
||||
uint32_t rev_endian32(uint32_t insert_int){
|
||||
return ENDIAN_REVERSE32(insert_int);
|
||||
}
|
||||
|
||||
uint64_t rev_endian64(uint64_t insert_int){
|
||||
return ENDIAN_REVERSE64(insert_int);
|
||||
}
|
||||
|
||||
//Initialize the PPC's registers.
|
||||
void reg_init(){
|
||||
for (uint32_t i = 0; i < 32; i++){
|
||||
|
Loading…
Reference in New Issue
Block a user