//
// Project UnReality: The First Nintendo 64 Emulator
// Copyright (C) 1997-1998, Cold Fusion Entertainment
// All rights reserved
//
// This source code is unpublished propietary information of Cold Fusion Entertainment.  No portion of this software
// may be disclosed to any third party or copied or duplicated in any form, in whole or in part, without the prior
// written consent of Cold Fusion Entertainment.
// 

//
// $Log: unreal.h $
// Revision 1.14  1998/05/25 20:56:49  BREAKPOINT
// Removed debugger code from release builds.  Only usable when _DEBUG is #defined (a debug build).
// Revision 1.13  1998/05/25 04:39:30  BREAKPOINT
// Added 'Call Stack' to debugger which shows the history of JAL[R]/JR RA instructions.
// Revision 1.12  1998/05/14 20:12:27  BREAKPOINT
// Added exception handling to RSP so it would stop crashing during MKT.  :)
// Revision 1.11  1998/04/05 23:50:56  BREAKPOINT
// Added RSP register debug window
// Revision 1.10  1998/04/05 19:46:21  BREAKPOINT
// Added RSP debugger *ONLY* when _DEBUG is defined!
// Revision 1.9  1998/04/02 21:18:52  BREAKPOINT
// Implemented new memory mapping routines and changed ROM loading code.
// Revision 1.8  1998/03/22 17:53:23  BREAKPOINT
// Final changes to fix audio stuff.
// Revision 1.7  1998/03/10 22:02:57  BREAKPOINT
// Second pass with DeltaPlayer in Project UnReality... now working quite
// well, just need streaming buffer playback and static buffers for emulation.
// Revision 1.6  1998/03/10 01:13:00  BREAKPOINT
// First pass at adding DeltaPlayer to Project UnReality...
// Revision 1.5  1998/03/08 19:13:25  BREAKPOINT
// Version 0.3b.3 checkin... I need to really check this stuff in more often..
// Revision 1.4  1998/01/31 20:01:42  BREAKPOINT
// Added support for saving debugger window positions and FPS counter.
// Revision 1.3  1998/01/20 00:32:54  BREAKPOINT
// Added 'LastPath' to config block.
// Revision 1.2  1998/01/10 21:57:35  BREAKPOINT
// Initial changes to move to assembly version of R4300i assembly core
// Revision 1.1  1998/01/10 01:28:44  BREAKPOINT
// Initial revision
//

//---------------------------------------------------------------------------------------------------------------------

#ifndef UNREAL_H
#define UNREAL_H

#include <stdio.h>
#include <windows.h>
#include <types.h>

#include "r4300i.h"

#define TYPE_DISABLED				0x00
#define TYPE_KEYBOARD				0x01
#define TYPE_JOYSTICK_BUTTON		0x02
#define TYPE_JOYSTICK_MOVE			0x03
#define TYPE_MOUSE_BUTTON			0x04
#define TYPE_MOUSE_MOVE				0x05

#define MAX_BUTTONS			0x0E

#define BUTTON_A			0x00
#define BUTTON_B			0x01
#define BUTTON_Z			0x02
#define BUTTON_L			0x03
#define BUTTON_R			0x04
#define BUTTON_START		0x05
#define BUTTON_C_UP			0x06
#define BUTTON_C_LEFT		0x07
#define BUTTON_C_RIGHT		0x08
#define BUTTON_C_DOWN		0x09
#define BUTTON_DPAD_UP		0x0A
#define BUTTON_DPAD_LEFT	0x0B
#define BUTTON_DPAD_RIGHT	0x0C
#define BUTTON_DPAD_DOWN	0x0D

typedef struct
{
	bool  Controller_Active;

	bool  Toggle_Active;
	uchar Type_Toggle;
	uchar Val_Toggle;

	uchar Type[MAX_BUTTONS];
	uchar Val[MAX_BUTTONS];

	uchar Type_Analog;
	bool  Analog_Input_Digital;			// TRUE if analog stick's input is digital (ie: gamepad joystick)
} ContCfgBlock;

typedef struct
{
    bool Windowed;
    bool Resizeable;
    int  DDrawDev;
	bool FPSLock;
	bool ShowFPS;
	bool Upscale320;
	char LastPath[256];

	int  DebugXpos, DebugYpos;
	int  RSPDebugXpos, RSPDebugYpos;
	int  RegXpos, RegYpos;
	int  RSPRegXpos, RSPRegYpos;
	int  MemXpos, MemYpos;
	int  CallXpos, CallYpos;

	ContCfgBlock Cont[4];

    bool  DisableAudio;
    int   SoundDev;
    bool  ForceSoftwareMix;
    bool  ThreadMix;
    uchar SoundBitDepth;
    uchar SoundMixRate;
    uchar SoundChannels;
    bool  SoundHighQ;
    bool  SoundInterp;
    uchar SoundPriority;
    bool  SoundEmuCubic;
    bool  SoundEmuXTCPlay;

    uchar SoundMixN64;
    char  LastSoundPath[256];
} Unreal_Config;

typedef struct
{
    uchar Filename[256];
    uchar Name[21];
    uchar ID[3];
    uchar Country;
    uchar Manufacturer;

    ulong EntryPoint;
    ulong Checksum1;
    ulong Checksum2;
} V64_Header;

void Save_Config(void);
BOOL APIENTRY LoadProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

#ifndef NO_EXTERN_UNREAL_H
extern "C"
{
    extern bool running;                    // Needed because 'running' is required for access to the assembly core...
    extern bool want_to_exit;
    extern HANDLE hRunEvent;
	extern HANDLE hDebugEvent;

	extern LPVOID N64Memory, RDRAM, RDRAM_REGS, RDRAM_TEMP_MEM, SP_DATA_MEM, SP_INST_MEM, SP_REGS, SP_PC, SP_IMEM_BIST;	
	extern LPVOID DP_CTRL_REGS, DP_SPAN_REGS, MIPS_REGS, VIDEO_REGS, AUDIO_REGS, PERIF_REGS, RDRAM_INTF_REGS, SERIAL_REGS;	
	extern LPVOID PIF_ROM, PIF_RAM, LEO, CART1DOM;
}
#endif

extern HINSTANCE MainhInst;
extern bool loaded, inDebugger, stop_on_unhandled, log_mmio_reg, has_focus;
extern HWND MainhWnd;
extern HMENU MainhMenu;

extern ulong ROM_size;
extern Unreal_Config cfg;
extern V64_Header v64h;

extern ulong win_Xsize, win_Ysize;

extern HANDLE hEmuThread;

// Exception handling.
int Eval_EmulationException(LPEXCEPTION_POINTERS xcpt);
extern EXCEPTION_POINTERS xp;
extern EXCEPTION_RECORD xr; 
extern CONTEXT cr; 

void dswap(uchar *dest, uchar *src, ulong blocks);
void StartEmulationThread(void);
void TerminateEmulationThread(void);

#endif
