#ifndef _CRAPPYDBG_H_
#define _CRAPPYDBG_H_

/*----------------------------------------------------------------------------*/
/*- Crappy Debugger (TM) addresses. ------------------------------------------*/
/* See sc_global_data.h for more details. */
#define DBG_BASE_ADDRESS 0x002FFFD0


/**
 * Set pointer to debug string, then increment
 * counter in order to notify that a new debug
 * message has been written.
 * (this is only useful when using yabause)
**/
#define CRAP_DBG(STRADR)  (*(volatile unsigned long *)(DBG_BASE_ADDRESS+0x04)) = (unsigned long)(STRADR); (*(volatile unsigned long *)(DBG_BASE_ADDRESS+0x00))++



/* Example of code to add into yabause for using crappy debugger
 * File: src/sh2core.c, line 152
 * Note: this is a quick-and-dirty and non-portable (windows only) code.
 */
#if 0
//////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#define COPYSTUB_START_PARAMS 0x002FFFC0

unsigned long _prev_cntr = 0;
void FASTCALL SH2Exec(SH2_struct *context, u32 cycles)
{
    /* Crappy debugger stuff START */
    unsigned long cntr = MappedMemoryReadLong(0x002FFFD0);
    if(cntr == (_prev_cntr+1))
    {
        unsigned long adr = MappedMemoryReadLong(0x002FFFD4);
        char str[256];
        int i;
        memset(str, '\0', sizeof(str));
        for(i=0; i<sizeof(str)-1; i++)
        {
            unsigned char c = MappedMemoryReadByte(adr + i);
            if(c < ' ')
            {
                break;
            }
            else
            {
                str[i] = c;
            }
        }
        str[i] = '\0';
        if((str[0] == 'D') && (str[1] == 'B') && (str[2] == 'G'))
        {
            char tmp[512];
            unsigned long data[3];
            data[0] = MappedMemoryReadLong(COPYSTUB_START_PARAMS + 0);
            data[1] = MappedMemoryReadLong(COPYSTUB_START_PARAMS + 4);
            data[2] = MappedMemoryReadLong(COPYSTUB_START_PARAMS + 8);
            sprintf(tmp, "COPYSTUB ->src=0x%08X len=%d dst=0x%08X", data[0], data[1], data[2]);
            OutputDebugString(tmp);
        }
        else
        {
            OutputDebugString(str);
        }
    }
    if(cntr != _prev_cntr)
    {
        _prev_cntr = cntr;
    }

    // // Display current address.
    // char tmp[512];
    // sprintf(tmp, "PC%08X IN%04X", context->regs.PC, context->instruction);
    // OutputDebugString(tmp);

    /* Crappy debugger stuff END */

   CurrentSH2 = context;
#endif //0


#endif
