#ifndef _USF_INTERNAL_H_
#define _USF_INTERNAL_H_
#include "osal/preproc.h"
#include "main/main.h"
#include "main/rom.h"
#include "ai/ai_controller.h"
#include "memory/memory.h"
#include "pi/pi_controller.h"
#include "r4300/r4300_core.h"
#include "r4300/ops.h"
#include "r4300/cp0.h"
#include "rdp/rdp_core.h"
#include "ri/ri_controller.h"
#include "rsp/rsp_core.h"
#include "si/si_controller.h"
#include "vi/vi_controller.h"
#include "rsp_hle/hle.h"
#include <stdio.h>
struct usf_state_helper
{
size_t offset_to_structure;
};
#ifdef DEBUG_INFO
#include <stdio.h>
#endif
#ifndef RCPREG_DEFINED
#define RCPREG_DEFINED
typedef uint32_t RCPREG;
#endif
#if defined(__x86_64__)
typedef struct _jump_table
{
unsigned int mi_addr;
unsigned int pc_addr;
unsigned int absolute64;
} jump_table;
typedef struct _riprelative_table
{
unsigned int pc_addr;
unsigned int extra_bytes;
unsigned char *global_dst;
} riprelative_table;
#else
typedef struct _jump_table
{
unsigned int mi_addr;
unsigned int pc_addr;
} jump_table;
#endif
#ifndef INTERUPT_STRUCTS
#define INTERUPT_STRUCTS
#define POOL_CAPACITY 16
struct interrupt_event
{
int type;
unsigned int count;
};
struct node
{
struct interrupt_event data;
struct node *next;
};
struct pool
{
struct node nodes[POOL_CAPACITY];
struct node* stack[POOL_CAPACITY];
size_t index;
};
struct interrupt_queue
{
struct pool pool;
struct node* first;
};
#endif
#ifndef TLB_STRUCTS
#define TLB_STRUCTS
typedef struct _tlb
{
short mask;
int vpn2;
char g;
unsigned char asid;
int pfn_even;
char c_even;
char d_even;
char v_even;
int pfn_odd;
char c_odd;
char d_odd;
char v_odd;
char r;
unsigned int start_even;
unsigned int end_even;
unsigned int phys_even;
unsigned int start_odd;
unsigned int end_odd;
unsigned int phys_odd;
} tlb;
#endif
#ifndef PRECOMP_STRUCTS
#define PRECOMP_STRUCTS
#if defined(__x86_64__)
#include "r4300/x86_64/assemble_struct.h"
#else
#include "r4300/x86/assemble_struct.h"
#endif
typedef struct _precomp_instr
{
void (osal_fastcall *ops)(usf_state_t * state);
union
{
struct
{
long long int *rs;
long long int *rt;
short immediate;
} i;
struct
{
unsigned int inst_index;
} j;
struct
{
long long int *rs;
long long int *rt;
long long int *rd;
unsigned char sa;
unsigned char nrd;
} r;
struct
{
unsigned char base;
unsigned char ft;
short offset;
} lf;
struct
{
unsigned char ft;
unsigned char fs;
unsigned char fd;
} cf;
} f;
unsigned int addr;
unsigned int local_addr;
reg_cache_struct reg_cache_infos;
} precomp_instr;
typedef struct _precomp_block
{
precomp_instr *block;
unsigned int start;
unsigned int end;
unsigned char *code;
unsigned int code_length;
unsigned int max_code_length;
void *jumps_table;
int jumps_number;
void *riprel_table;
int riprel_number;
unsigned int adler32;
} precomp_block;
#endif
struct usf_state
{
uint32_t g_rdram[RDRAM_MAX_SIZE/4];
int16_t VR[32][8];
int16_t VACC[3][8];
int32_t SR[32];
RCPREG* CR[16];
int16_t ne[8];
int16_t co[8];
int16_t clip[8];
int16_t comp[8];
int16_t vce[8];
int32_t DivIn;
int32_t DivOut;
#if (0)
int32_t MovIn;
#endif
int32_t DPH;
int32_t stage; int32_t temp_PC;
int16_t MFC0_count[32];
unsigned char * DMEM;
unsigned char * IMEM;
struct hle_t hle;
uint32_t enablecompare, enableFIFOfull;
uint32_t enable_hle_audio;
uint32_t enable_trimming_mode;
void * barray_rom;
void * barray_ram_read;
void * barray_ram_written_first;
unsigned char * save_state;
unsigned int save_state_size;
size_t sample_buffer_count;
int16_t * sample_buffer;
int32_t SampleRate;
int16_t samplebuf[16384];
size_t samples_in_buffer;
void * resampler;
int16_t samplebuf2[8192];
size_t samples_in_buffer_2;
const char * last_error;
char error_message[16384];
uint32_t MemoryState;
struct ai_controller g_ai;
struct pi_controller g_pi;
struct ri_controller g_ri;
struct si_controller g_si;
struct vi_controller g_vi;
struct r4300_core g_r4300;
struct rdp_core g_dp;
struct rsp_core g_sp;
int g_delay_si;
int g_delay_ai;
int g_delay_pi;
int g_delay_sp;
int g_delay_dp;
int g_disable_tlb_write_exception;
int g_gs_vi_counter;
unsigned int address, cpu_word;
unsigned char cpu_byte;
unsigned short cpu_hword;
unsigned long long cpu_dword, *rdword;
uint32_t EmptySpace[0x10000/4];
void (osal_fastcall *readmem[0x10000])(usf_state_t *);
void (osal_fastcall *readmemb[0x10000])(usf_state_t *);
void (osal_fastcall *readmemh[0x10000])(usf_state_t *);
void (osal_fastcall *readmemd[0x10000])(usf_state_t *);
void (osal_fastcall *writemem[0x10000])(usf_state_t *);
void (osal_fastcall *writememb[0x10000])(usf_state_t *);
void (osal_fastcall *writememh[0x10000])(usf_state_t *);
void (osal_fastcall *writememd[0x10000])(usf_state_t *);
unsigned char* g_rom;
int g_rom_size;
m64p_rom_header ROM_HEADER;
rom_params ROM_PARAMS;
precomp_instr interp_PC;
unsigned int r4300emu;
unsigned int count_per_op;
int llbit, rompause;
int stop;
long long int reg[32], hi, lo;
unsigned int next_interupt;
precomp_instr *PC;
long long int local_rs;
unsigned int delay_slot, skip_jump, dyna_interp, last_addr;
cpu_instruction_table current_instruction_table;
int reset_hard_job;
unsigned int g_cp0_regs[CP0_REGS_COUNT];
float *reg_cop1_simple[32];
double *reg_cop1_double[32];
int FCR0, FCR31;
long long int reg_cop1_fgr_64[32];
int rounding_mode;
int trunc_mode, round_mode,
ceil_mode, floor_mode;
int interupt_unsafe_state;
int SPECIAL_done;
struct interrupt_queue q;
tlb tlb_e[32];
unsigned int tlb_LUT_r[0x100000];
unsigned int tlb_LUT_w[0x100000];
#ifdef COUNT_INSTR
unsigned int instr_count[132];
#endif
char invalid_code[0x100000];
precomp_block *blocks[0x100000];
precomp_block *actual;
unsigned int jump_to_address;
precomp_instr *dst; int code_length; int max_code_length; unsigned char **inst_pointer; precomp_block *dst_block; int src; int fast_memory;
int no_compiled_jump ;
void (*recomp_func)(usf_state_t *);
int *SRC; int check_nop; int delay_slot_compiled;
int init_length;
#ifdef DYNAREC
#ifdef _MSC_VER
#define __i386__
#endif
unsigned int g_jump_start8;
unsigned int g_jump_start32;
jump_table *jumps_table;
int jumps_number, max_jumps_number;
#if defined(__x86_64__)
riprelative_table *riprel_table;
int riprel_number, max_riprel_number;
#endif
precomp_instr fake_instr;
int branch_taken;
unsigned int precomp_instr_size;
#if defined(__i386__)
long save_esp;
long save_eip;
unsigned long *return_address;
#endif
#if defined(__x86_64__)
unsigned long long *return_address;
long long save_rsp;
long long save_rip;
#endif
#if defined(__i386__)
unsigned int* reg_content[8];
precomp_instr* last_access[8];
precomp_instr* free_since[8];
int dirty[8];
int r64[8];
unsigned int* r0;
#endif
#if defined(__x86_64__)
unsigned long long * reg_content[8];
precomp_instr* last_access[8];
precomp_instr* free_since[8];
int dirty[8];
int is64bits[8];
unsigned long long *r0;
#endif
#endif
#ifdef DEBUG_INFO
FILE * debug_log;
#endif
};
void usf_set_audio_format(void *, unsigned int frequency, unsigned int bits);
void usf_push_audio_samples(void *, const void * buffer, size_t size);
#define USF_STATE_HELPER ((usf_state_helper_t *)(state))
#define USF_STATE ((usf_state_t *)(((uint8_t *)(state))+((usf_state_helper_t *)(state))->offset_to_structure))
#endif