dosbox-wii/src/debug/debug_gui.cpp

279 lines
7.4 KiB
C++
Raw Normal View History

2009-05-02 23:03:37 +02:00
/*
2009-05-03 00:18:08 +02:00
* Copyright (C) 2002-2006 The DOSBox Team
2009-05-02 23:03:37 +02:00
*
* 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 2 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
2009-05-03 00:02:15 +02:00
* GNU General Public License for more details.
2009-05-02 23:03:37 +02:00
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2009-05-03 00:18:08 +02:00
/* $Id: debug_gui.cpp,v 1.28 2006/02/09 11:47:48 qbix79 Exp $ */
2009-05-02 23:03:37 +02:00
#include "dosbox.h"
2009-05-03 00:18:08 +02:00
2009-05-02 23:12:18 +02:00
#if C_DEBUG
2009-05-02 23:35:44 +02:00
#include "setup.h"
2009-05-02 23:03:37 +02:00
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <curses.h>
#include <string.h>
2009-05-02 23:35:44 +02:00
#include "support.h"
2009-05-02 23:03:37 +02:00
#include "regs.h"
#include "debug.h"
#include "debug_inc.h"
2009-05-02 23:35:44 +02:00
struct _LogGroup {
char * front;
bool enabled;
};
2009-05-03 00:18:08 +02:00
#include <list>
#include <string>
using namespace std;
#define MAX_LOG_BUFFER 500
static list<string> logBuff;
static list<string>::iterator logBuffPos = logBuff.end();
2009-05-02 23:35:44 +02:00
2009-05-02 23:43:00 +02:00
static _LogGroup loggrp[LOG_MAX]={{"",true},{0,false}};
static FILE* debuglog;
2009-05-02 23:35:44 +02:00
extern int old_cursor_state;
2009-05-02 23:03:37 +02:00
2009-05-02 23:43:00 +02:00
void DEBUG_ShowMsg(char * format,...) {
char buf[512];
2009-05-02 23:35:44 +02:00
va_list msg;
va_start(msg,format);
2009-05-02 23:43:00 +02:00
vsprintf(buf,format,msg);
2009-05-02 23:35:44 +02:00
va_end(msg);
2009-05-03 00:08:43 +02:00
/* Add newline if not present */
Bitu len=strlen(buf);
if(buf[len-1]!='\n') strcat(buf,"\n");
if(debuglog) fprintf(debuglog,"%s",buf);
if (logBuffPos!=logBuff.end()) {
logBuffPos=logBuff.end();
DEBUG_RefreshPage(0);
mvwprintw(dbg.win_out,dbg.win_out->_maxy-1, 0, "");
}
2009-05-03 00:18:08 +02:00
logBuff.push_back(buf);
if (logBuff.size() > MAX_LOG_BUFFER)
2009-05-03 00:08:43 +02:00
logBuff.pop_front();
2009-05-03 00:18:08 +02:00
2009-05-03 00:08:43 +02:00
logBuffPos = logBuff.end();
wprintw(dbg.win_out,"%s",buf);
wrefresh(dbg.win_out);
}
void DEBUG_RefreshPage(char scroll) {
if (scroll==-1 && logBuffPos!=logBuff.begin()) logBuffPos--;
else if (scroll==1 && logBuffPos!=logBuff.end()) logBuffPos++;
2009-05-03 00:18:08 +02:00
list<string>::iterator i = logBuffPos;
2009-05-03 00:08:43 +02:00
int rem_lines = dbg.win_out->_maxy;
wclear(dbg.win_out);
while (rem_lines > 0 && i!=logBuff.begin()) {
2009-05-03 00:18:08 +02:00
rem_lines -= (int) ((*--i).size() / dbg.win_out->_maxx) + 1;
/* Const cast is needed for pdcurses which has no const char in mvwprintw (bug maybe) */
mvwprintw(dbg.win_out,rem_lines-1, 0, const_cast<char*>((*i).c_str()));
2009-05-03 00:08:43 +02:00
}
2009-05-02 23:03:37 +02:00
wrefresh(dbg.win_out);
}
2009-05-02 23:43:00 +02:00
void LOG::operator() (char* format, ...){
char buf[512];
va_list msg;
va_start(msg,format);
vsprintf(buf,format,msg);
va_end(msg);
if (d_type>=LOG_MAX) return;
if ((d_severity!=LOG_ERROR) && (!loggrp[d_type].enabled)) return;
2009-05-03 00:08:43 +02:00
DEBUG_ShowMsg("%10d: %s:%s\n",cycle_count,loggrp[d_type].front,buf);
2009-05-02 23:43:00 +02:00
}
2009-05-02 23:03:37 +02:00
static void Draw_RegisterLayout(void) {
mvwaddstr(dbg.win_reg,0,0,"EAX=");
mvwaddstr(dbg.win_reg,1,0,"EBX=");
mvwaddstr(dbg.win_reg,2,0,"ECX=");
mvwaddstr(dbg.win_reg,3,0,"EDX=");
mvwaddstr(dbg.win_reg,0,14,"ESI=");
mvwaddstr(dbg.win_reg,1,14,"EDI=");
mvwaddstr(dbg.win_reg,2,14,"EBP=");
mvwaddstr(dbg.win_reg,3,14,"ESP=");
mvwaddstr(dbg.win_reg,0,28,"DS=");
mvwaddstr(dbg.win_reg,0,38,"ES=");
mvwaddstr(dbg.win_reg,0,48,"FS=");
mvwaddstr(dbg.win_reg,0,58,"GS=");
mvwaddstr(dbg.win_reg,0,68,"SS=");
mvwaddstr(dbg.win_reg,1,28,"CS=");
mvwaddstr(dbg.win_reg,1,38,"EIP=");
2009-05-03 00:18:08 +02:00
mvwaddstr(dbg.win_reg,2,75,"CPL");
mvwaddstr(dbg.win_reg,2,68,"IOPL");
2009-05-02 23:03:37 +02:00
mvwaddstr(dbg.win_reg,1,52,"C Z S O A P D I T ");
}
static void DrawBars(void) {
if (has_colors()) {
attrset(COLOR_PAIR(PAIR_BLACK_BLUE));
}
/* Show the Register bar */
2009-05-03 00:08:43 +02:00
mvaddstr(dbg.win_reg->_begy-1,0, "---(Register Overview )---");
2009-05-02 23:03:37 +02:00
/* Show the Data Overview bar perhaps with more special stuff in the end */
2009-05-03 00:08:43 +02:00
mvaddstr(dbg.win_data->_begy-1,0,"---(Data Overview Scroll: r/f )---");
2009-05-02 23:03:37 +02:00
/* Show the Code Overview perhaps with special stuff in bar too */
2009-05-03 00:08:43 +02:00
mvaddstr(dbg.win_code->_begy-1,0,"---(Code Overview Scroll: up/down )---");
2009-05-03 00:02:15 +02:00
/* Show the Variable Overview bar */
2009-05-03 00:08:43 +02:00
mvaddstr(dbg.win_var->_begy-1,0, "---(Variable Overview )---");
2009-05-02 23:03:37 +02:00
/* Show the Output OverView */
2009-05-03 00:08:43 +02:00
mvaddstr(dbg.win_out->_begy-1,0, "---(OutPut/Input Scroll: home/end )---");
2009-05-02 23:03:37 +02:00
attrset(0);
}
static void MakeSubWindows(void) {
/* The Std output win should go in bottem */
/* Make all the subwindows */
int outy=1;
/* The Register window */
dbg.win_reg=subwin(dbg.win_main,4,dbg.win_main->_maxx,outy,0);
outy+=5;
/* The Data Window */
dbg.win_data=subwin(dbg.win_main,10,dbg.win_main->_maxx,outy,0);
outy+=11;
/* The Code Window */
2009-05-02 23:12:18 +02:00
dbg.win_code=subwin(dbg.win_main,11,dbg.win_main->_maxx,outy,0);
outy+=12;
2009-05-03 00:02:15 +02:00
/* The Variable Window */
dbg.win_var=subwin(dbg.win_main,4,dbg.win_main->_maxx,outy,0);
outy+=5;
/* The Output Window */
2009-05-02 23:03:37 +02:00
dbg.win_out=subwin(dbg.win_main,dbg.win_main->_maxy-outy-1,dbg.win_main->_maxx,outy,0);
dbg.input_y=dbg.win_main->_maxy-1;
scrollok(dbg.win_out,TRUE);
DrawBars();
Draw_RegisterLayout();
refresh();
}
static void MakePairs(void) {
init_pair(PAIR_BLACK_BLUE, COLOR_BLACK, COLOR_CYAN);
init_pair(PAIR_BYELLOW_BLACK, COLOR_YELLOW /*| FOREGROUND_INTENSITY */, COLOR_BLACK);
2009-05-02 23:12:18 +02:00
init_pair(PAIR_GREEN_BLACK, COLOR_GREEN /*| FOREGROUND_INTENSITY */, COLOR_BLACK);
init_pair(PAIR_BLACK_GREY, COLOR_BLACK /*| FOREGROUND_INTENSITY */, COLOR_WHITE);
init_pair(PAIR_GREY_RED, COLOR_WHITE/*| FOREGROUND_INTENSITY */, COLOR_RED);
2009-05-02 23:03:37 +02:00
}
2009-05-02 23:35:44 +02:00
static void LOG_Destroy(Section* sec) {
if(debuglog) fclose(debuglog);
}
static void LOG_Init(Section * sec) {
Section_prop * sect=static_cast<Section_prop *>(sec);
const char * blah=sect->Get_string("logfile");
if(blah && blah[0] &&(debuglog = fopen(blah,"wt+"))){
}else{
debuglog=0;
}
sect->AddDestroyFunction(LOG_Destroy);
char buf[1024];
for (Bitu i=1;i<LOG_MAX;i++) {
strcpy(buf,loggrp[i].front);
2009-05-02 23:43:00 +02:00
buf[strlen(buf)]=0;
lowcase(buf);
2009-05-02 23:35:44 +02:00
loggrp[i].enabled=sect->Get_bool(buf);
}
}
void LOG_StartUp(void) {
/* Setup logging groups */
2009-05-02 23:43:00 +02:00
loggrp[LOG_ALL].front="ALL";
loggrp[LOG_VGA].front="VGA";
loggrp[LOG_VGAGFX].front="VGAGFX";
loggrp[LOG_VGAMISC].front="VGAMISC";
loggrp[LOG_INT10].front="INT10";
loggrp[LOG_SB].front="SBLASTER";
loggrp[LOG_DMA].front="DMA";
2009-05-02 23:35:44 +02:00
2009-05-02 23:43:00 +02:00
loggrp[LOG_FPU].front="FPU";
loggrp[LOG_CPU].front="CPU";
loggrp[LOG_PAGING].front="PAGING";
2009-05-02 23:35:44 +02:00
2009-05-02 23:43:00 +02:00
loggrp[LOG_FCB].front="FCB";
loggrp[LOG_FILES].front="FILES";
loggrp[LOG_IOCTL].front="IOCTL";
2009-05-02 23:35:44 +02:00
loggrp[LOG_EXEC].front="EXEC";
2009-05-02 23:43:00 +02:00
loggrp[LOG_DOSMISC].front="DOSMISC";
loggrp[LOG_PIT].front="PIT";
loggrp[LOG_KEYBOARD].front="KEYBOARD";
loggrp[LOG_PIC].front="PIC";
2009-05-02 23:35:44 +02:00
2009-05-02 23:43:00 +02:00
loggrp[LOG_MOUSE].front="MOUSE";
loggrp[LOG_BIOS].front="BIOS";
loggrp[LOG_GUI].front="GUI";
loggrp[LOG_MISC].front="MISC";
2009-05-02 23:35:44 +02:00
2009-05-02 23:43:00 +02:00
loggrp[LOG_IO].front="IO";
2009-05-02 23:35:44 +02:00
/* Register the log section */
Section_prop * sect=control->AddSection_prop("log",LOG_Init);
sect->Add_string("logfile","");
char buf[1024];
for (Bitu i=1;i<LOG_MAX;i++) {
strcpy(buf,loggrp[i].front);
lowcase(buf);
sect->Add_bool(buf,true);
}
}
2009-05-02 23:03:37 +02:00
void DBGUI_StartUp(void) {
/* Start the main window */
dbg.win_main=initscr();
2009-05-02 23:35:44 +02:00
cbreak(); /* take input chars one at a time, no wait for \n */
noecho(); /* don't echo input */
2009-05-02 23:03:37 +02:00
nodelay(dbg.win_main,true);
keypad(dbg.win_main,true);
2009-05-02 23:35:44 +02:00
#ifndef WIN32
2009-05-02 23:53:27 +02:00
resizeterm(50,81);
2009-05-02 23:35:44 +02:00
touchwin(dbg.win_main);
old_cursor_state = curs_set(0);
#endif
start_color();
2009-05-02 23:03:37 +02:00
cycle_count=0;
MakePairs();
MakeSubWindows();
}
#endif