//
// 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: debugger.h $
// Revision 1.9  1998/05/25 20:56:48  BREAKPOINT
// Removed debugger code from release builds.  Only usable when _DEBUG is #defined (a debug build).
// Revision 1.8  1998/05/25 04:39:26  BREAKPOINT
// Added 'Call Stack' to debugger which shows the history of JAL[R]/JR RA instructions.
// Revision 1.7  1998/05/24 23:16:32  BREAKPOINT
// Added 'breakpoint on Count' to debugger.
// Revision 1.6  1998/04/07 23:29:40  BREAKPOINT
// Fixed up debugger... added 'Safe_Read*()' calls to access memory without causing crashes when reading from unmapped memory.
// Revision 1.5  1998/04/05 23:51:26  BREAKPOINT
// Added RSP register debug window
// Revision 1.4  1998/04/05 19:46:19  BREAKPOINT
// Added RSP debugger *ONLY* when _DEBUG is defined!
// Revision 1.3  1998/03/22 17:52:30  BREAKPOINT
// New breakpoint detection routine to speed up debugging and emulation by changing the opcode to and invalid one.
// Needs more work, also Breakpoint on RegV is broken too.
// Revision 1.2  1998/01/31 19:54:29  BREAKPOINT
// Minor changes to allow assembly to call C.
// Revision 1.1  1998/01/10 01:26:04  BREAKPOINT
// Initial revision
//

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

#ifndef DEBUGGER_H
#define DEBUGGER_H

#ifdef _DEBUG

void _cdecl CountBreakpoint(void);

extern FARPROC debugproc, registerproc, memoryproc, callstackproc, rspdebugproc, rspregisterproc;
extern HWND debughWnd, registerhWnd, memoryhWnd, callstackhWnd, rspdebughWnd, rspregisterhWnd;

BOOL APIENTRY DebuggerProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY RegisterProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY MemoryProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY CallStackProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY RSPDebuggerProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL APIENTRY RSPRegisterProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

void RefreshRSPDebugger(void);
void RefreshRSPRegisters(void);
void RefreshDebugger(void);
void RefreshRegisters(void);
void RefreshMemory(void);
void RefreshCallStack(void);

#endif // _DEBUG


// This is okay to put here... it doesn't do anything unless _DEBUG is defined anyway.
void RefreshDebugAll(void);

extern ulong raw_opcode_ulong, raw_opcode_addr;
extern uchar raw_opcode[4];
extern bool is_outside_memory;

void ToggleBreakpoint(ulong addr);
bool HasBreakpoint(ulong addr);

void AddBPRegValue(ulong val);
void SearchMemory(ulong val);

struct BPNode
{
    struct BPNode *prev;
    struct BPNode *next;

    ulong PC;
    ulong opcode;
};

extern BPNode *FirstBPNode;
extern BPNode *LastBPNode;

#define NUM_BREAKPOINTS     8

#ifdef DEBUGGER_NO_EXTERN
struct
#else
extern struct
#endif
{
    bool  active;
    ulong value;
} bkpt_regv[NUM_BREAKPOINTS];

#endif
