/******************************************************************************
*
* Copyright (C) 2007-2017  Brian Berlin
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************
*
* FILENAME: debug.h
*
* DESCRIPTION:  This contains function declarations for debugger functions
*
* AUTHORS:  bberlin
*
* CHANGE LOG
*
*  VER     DATE     CHANGED BY   DESCRIPTION OF CHANGE
* ------  --------  ----------   ------------------------------------
* 0.5.0   02/11/07  bberlin      Creation, breakout from util
******************************************************************************/
#ifndef debugger_h
#define debugger_h

#include "boom6502.h"

/* Debug commands  */
#define PRINT 'p'
#define DEBUG_QUIT 'q'
#define TRACE 't'
#define STOPTRACE 'x'
#define BREAKPOINT 'b'
#define WATCH 'w'
#define DELETE_BK 'd'
#define STEP 's'
#define CONT 'c'
#define HELP 'h'

/* Debug arguments */
#define ARG_MODELINE "modeline"
#define ARG_SCANLINE "scanline"
#define ARG_VBLANK   "vblank"

/* Debug processor */
#define DEBUG_CPU "cpu"
#define DEBUG_ANTIC "antic"

#define DEBUG_MAX_BK 10

/* Debug constants */
typedef enum {
    BK_NONE,
    BK_SCANLINE,
    BK_MEM,
    BK_WATCH,
    BK_VBLANK
} e_debug_breakpoint;

typedef struct {
    int flag;
    int trace_cpu_flag;
    char trace_cpu_file[257];
    char trace_antic_file[257];
    int trace_antic_flag;
    int single_step_flag;
    int single_scanline_flag;
    int single_frame_flag;
    int cpu_crash_flag;
    KWORD cpu_crash_pc;
    KBYTE cpu_crash_opcode;
    int breakpoint_flag;
    e_debug_breakpoint breakpoint[DEBUG_MAX_BK];
    int breakpoint_place[DEBUG_MAX_BK];
} t_debug;

extern void (*debug_breakpoint_handler)(void);
void debug_set_breakpoint_handler(void (*func)(void));
int debug_get_breakpoint_flag(void);
void debug_set_breakpoint_flag(int flag);

void debug_init ( void );
void debug_check_scanline(void);
int debug_set_out_function ( int (*func) (int) );
void print_addr_val ( int access_type, KWORD addr, KBYTE val );
int debug_crash_to_gui ( void );
void debug_get_input (void);
void debug_print_value ( char *arg );
void debug_print_cpu_op ( int point_of_debug );
void debug_search_for_breakpoint (e_debug_breakpoint break_type, int value );
void debug_break_for_watch (int addr, int new_value, int old_value );
int debug_is_page_in_debug (int page);
void debug_print_string_to_trace (char *string);
void debug_open_default_trace (void);
void debug_close_default_trace (void);
void debug_open_trace (const char *filepath);
void debug_close_trace (void);

#endif
