Here comes the new debug code...

there's good chance that I just broke the cocoa and
windows frontends, sorry about that.
This commit is contained in:
yabause 2008-11-21 22:36:40 +00:00
parent 9575c907a7
commit ffc9f0284f
11 changed files with 184 additions and 312 deletions

View File

@ -50,6 +50,7 @@
#include "debug.h"
#include "render3D.h"
#include "GPU_osd.h"
#include "debug.h"
ARM9_struct ARM9Mem;

View File

@ -25,6 +25,7 @@
#include "mem.h"
#include <string.h> //mem funcs
#include <stdarg.h> //va_start, etc
#include "debug.h"
#include "softrender.h"

View File

@ -25,7 +25,7 @@
#define __GPU_OSD_
#include <stdlib.h>
#include "debug.h"
#include "types.h"
#define OSD_MAX_LINES 10

View File

@ -90,7 +90,7 @@ void mmu_log_debug(u32 adr, u8 proc, const char *fmt, ...)
_vsnprintf(msg,511,fmt,list);
va_end(list);
printlog("MMU ARM%s 0x%08X: %s\n",proc==ARMCPU_ARM9?"9":"7",adr, msg);
LOG("MMU ARM%s 0x%08X: %s\n",proc==ARMCPU_ARM9?"9":"7",adr, msg);
}
}
#else
@ -234,7 +234,6 @@ void MMU_Init(void) {
int i;
LOG("MMU init\n");
//printlog("MMU init\n");
memset(&MMU, 0, sizeof(MMU_struct));
@ -747,7 +746,6 @@ u8 FASTCALL _MMU_read8(u32 adr)
if(proc==ARMCPU_ARM9 && adr<0x02000000)
{
//printlog("MMU ITCM (08) Read %08X: %08X\n", adr, T1ReadByte(ARM9Mem.ARM9_ITCM, adr&0x7FFF));
return T1ReadByte(ARM9Mem.ARM9_ITCM, adr&0x7FFF);
}
@ -786,7 +784,6 @@ u16 FASTCALL _MMU_read16(u32 adr)
#endif
if(proc==ARMCPU_ARM9 && adr<0x02000000)
{
//printlog("MMU ITCM (16) Read %08X: %08X\n", adr, T1ReadWord(ARM9Mem.ARM9_ITCM, adr&0x7FFF));
return T1ReadWord(ARM9Mem.ARM9_ITCM, adr&0x7FFF);
}
@ -813,8 +810,7 @@ u16 FASTCALL _MMU_read16(u32 adr)
return (gfx3d_GetNumVertex()&8191);
case REG_IPCFIFORECV : /* TODO (clear): ??? */
printlog("MMU read16: IPCFIFORECV\n");
//printlog("Stopped IPCFIFORECV\n");
LOG("MMU read16: IPCFIFORECV\n");
execute = FALSE;
return 1;
@ -827,10 +823,8 @@ u16 FASTCALL _MMU_read16(u32 adr)
return (u16)(MMU.reg_IE[proc]>>16);
case REG_IF :
//printlog("MMU read16 (low): REG_IF\n");
return (u16)MMU.reg_IF[proc];
case REG_IF + 2 :
//printlog("MMU read16 (high): REG_IF\n");
return (u16)(MMU.reg_IF[proc]>>16);
case REG_TM0CNTL :
@ -868,7 +862,6 @@ u32 FASTCALL _MMU_read32(u32 adr)
if(proc==ARMCPU_ARM9 && adr<0x02000000)
{
//printlog("MMU ITCM (32) Read %08X: %08X\n", adr, T1ReadLong(ARM9Mem.ARM9_ITCM, adr&0x7FFF));
return T1ReadLong(ARM9Mem.ARM9_ITCM, adr&0x7FFF);
}
@ -939,12 +932,10 @@ u32 FASTCALL _MMU_read32(u32 adr)
case REG_IE :
return MMU.reg_IE[proc];
case REG_IF :
//printlog("MMU read32: REG_IF\n");
return MMU.reg_IF[proc];
case REG_IPCFIFORECV :
{
u16 cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184);
//printlog("MMU read32: REG_IPCFIFORECV (%X)\n", cnt_l);
if (!(cnt_l & 0x8000)) return 0; // FIFO disabled
u16 cnt_r = T1ReadWord(MMU.MMU_MEM[proc^1][0x40], 0x184);
u32 val = FIFOget(&MMU.fifos[proc]);
@ -1031,7 +1022,6 @@ void FASTCALL _MMU_write8(u32 adr, u8 val)
#endif
if(proc==ARMCPU_ARM9 && adr<0x02000000)
{
//printlog("MMU ITCM (08) Write %08X: %08X\n", adr, val);
T1WriteByte(ARM9Mem.ARM9_ITCM, adr&0x7FFF, val);
return ;
}
@ -1428,7 +1418,6 @@ void FASTCALL _MMU_write16(u32 adr, u16 val)
#endif
if(proc==ARMCPU_ARM9 && adr<0x02000000)
{
//printlog("MMU ITCM (16) Write %08X: %08X\n", adr, val);
T1WriteWord(ARM9Mem.ARM9_ITCM, adr&0x7FFF, val);
return ;
}
@ -1852,11 +1841,9 @@ void FASTCALL _MMU_write16(u32 adr, u16 val)
case REG_IF :
//execute = FALSE;
//printlog("MMU write16 (low): REG_IF (%X)\n", val);
MMU.reg_IF[proc] &= (~((u32)val));
return;
case REG_IF + 2 :
//printlog("MMU write16 (high): REG_IF (%X)\n", val);
//execute = FALSE;
MMU.reg_IF[proc] &= (~(((u32)val)<<16));
return;
@ -1877,8 +1864,6 @@ void FASTCALL _MMU_write16(u32 adr, u16 val)
u32 cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184) ;
u32 cnt_r = T1ReadWord(MMU.MMU_MEM[proc^1][0x40], 0x184) ;
//printlog("MMU write16 (%s): REG_IPCFIFOCNT 0x(%08X)\n", proc?"ARM9":"ARM7",REG_IPCFIFOCNT);
//printlog(" --- val=%X\n",val);
if ((val & 0x8000) && !(cnt_l & 0x8000))
{
@ -2102,7 +2087,6 @@ void FASTCALL _MMU_write32(u32 adr, u32 val)
#endif
if(proc==ARMCPU_ARM9 && adr<0x02000000)
{
//printlog("MMU ITCM (32) Write %08X: %08X\n", adr, val);
T1WriteLong(ARM9Mem.ARM9_ITCM, adr&0x7FFF, val);
return ;
}
@ -2543,7 +2527,6 @@ void FASTCALL _MMU_write32(u32 adr, u32 val)
case 0x04000600: // Geometry Engine Status Register (R and R/W)
{
//printlog("MMU write32: Geometry Engine Status Register (R and R/W)\n");
MMU.fifos[proc].irq = (val>>30) & 0x03;
return;
}
@ -2687,7 +2670,6 @@ void FASTCALL _MMU_write32(u32 adr, u32 val)
return;
case REG_IF :
//printlog("MMU write32: REG_IF (%X)\n", val);
MMU.reg_IF[proc] &= (~val);
return;
@ -2884,7 +2866,7 @@ void FASTCALL _MMU_write32(u32 adr, u32 val)
case REG_IPCSYNC :
{
//execute=FALSE;
printlog("MMU write 32 IPCSYNC\n");
LOG("MMU write 32 IPCSYNC\n");
u32 remote = (proc+1)&1;
u32 IPCSYNC_remote = T1ReadLong(MMU.MMU_MEM[remote][0x40], 0x180);
T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x180, (val&0xFFF0)|((IPCSYNC_remote>>8)&0xF));
@ -2915,7 +2897,7 @@ void FASTCALL _MMU_write32(u32 adr, u32 val)
}
T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, val & 0xBFF4);
#else
printlog("MMU write32: REG_IPCFIFOCNT\n");
LOG("MMU write32: REG_IPCFIFOCNT\n");
#endif
//execute = FALSE;
return;
@ -2925,7 +2907,6 @@ void FASTCALL _MMU_write32(u32 adr, u32 val)
u16 cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184);
if (!(cnt_l & 0x8000)) return; //FIFO disabled
u16 cnt_r = T1ReadWord(MMU.MMU_MEM[proc^1][0x40], 0x184);
//printlog("MMU write32 (%s): REG_IPCFIFOSEND (%X-%X) val=%X\n", proc?"ARM9":"ARM7",cnt_l,cnt_r,val);
//FIFOadd(MMU.fifos+(proc^1), val);
FIFOadd(&MMU.fifos[proc^1], val);
cnt_l = (cnt_l & 0xFFFC) | (MMU.fifos[proc^1].full?0x0002:0);
@ -3122,7 +3103,7 @@ void FASTCALL _MMU_write32(u32 adr, u32 val)
//Transfer starts at next frame.
//Main Memory Display/Capture is supported for Display Engine A only.
printlog("MMU write32: REG_DISPA_DISPMMEMFIFO\n");
LOG("MMU write32: REG_DISPA_DISPMMEMFIFO\n");
#endif
break;
}

View File

@ -618,9 +618,6 @@ int main(int argc, char ** argv) {
}
#endif
#ifdef DEBUG
LogStart();
#endif
#ifdef GDB_STUB
NDS_Init( arm9_memio, &arm9_ctrl_iface,
arm7_memio, &arm7_ctrl_iface);
@ -847,9 +844,5 @@ int main(int argc, char ** argv) {
}
#endif
#ifdef DEBUG
LogStop();
#endif
return 0;
}

View File

@ -1,6 +1,6 @@
/* Copyright 2005 Guillaume Duhamel
/* Copyright (C) 2008 Guillaume Duhamel
This file is part of DeSmuME.
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -20,140 +20,77 @@
#include "debug.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
//////////////////////////////////////////////////////////////////////////////
std::vector<Logger *> Logger::channels;
Debug * DebugInit(const char * n, DebugOutType t, char * s) {
Debug * d;
if ((d = (Debug *) malloc(sizeof(Debug))) == NULL)
return NULL;
d->output_type = t;
if ((d->name = strdup(n)) == NULL)
{
free(d);
return NULL;
}
switch(t) {
case DEBUG_STREAM:
d->output.stream = fopen(s, "w");
break;
case DEBUG_STRING:
d->output.string = s;
break;
case DEBUG_STDOUT:
d->output.stream = stdout;
break;
case DEBUG_STDERR:
d->output.stream = stderr;
break;
}
return d;
static void defaultCallback(const Logger& logger, const char * message) {
logger.getOutput() << message;
}
//////////////////////////////////////////////////////////////////////////////
void DebugDeInit(Debug * d) {
if (d == NULL)
return;
switch(d->output_type) {
case DEBUG_STREAM:
if (d->output.stream)
fclose(d->output.stream);
break;
case DEBUG_STRING:
case DEBUG_STDOUT:
case DEBUG_STDERR:
break;
}
if (d->name)
free(d->name);
free(d);
Logger::Logger() {
out = &std::cout;
callback = defaultCallback;
flags = 0;
}
//////////////////////////////////////////////////////////////////////////////
void Logger::vprintf(const char * format, va_list l, const char * file, unsigned int line) {
char buffer[1024];
char * cur = buffer;
void DebugChangeOutput(Debug * d, DebugOutType t, char * s) {
if (t != d->output_type) {
if (d->output_type == DEBUG_STREAM)
{
if (d->output.stream)
fclose(d->output.stream);
}
d->output_type = t;
}
switch(t) {
case DEBUG_STREAM:
d->output.stream = fopen(s, "w");
break;
case DEBUG_STRING:
d->output.string = s;
break;
case DEBUG_STDOUT:
d->output.stream = stdout;
break;
case DEBUG_STDERR:
d->output.stream = stderr;
break;
if (flags & Logger::FILE) cur += sprintf(cur, "%s:", file);
if (flags & Logger::LINE) cur += sprintf(cur, "%d:", line);
if (flags) cur += sprintf(cur, " ");
::vsnprintf(cur, 1024, format, l);
callback(*this, buffer);
}
void Logger::setOutput(std::ostream * out) {
this->out = out;
}
void Logger::setCallback(void (*callback)(const Logger& logger, const char * message)) {
this->callback = callback;
}
void Logger::setFlag(unsigned int flag) {
this->flags = flag;
}
void Logger::fixSize(unsigned int channel) {
while(channel >= channels.size()) {
channels.push_back(new Logger());
}
}
//////////////////////////////////////////////////////////////////////////////
std::ostream& Logger::getOutput() const {
return *out;
}
void Logger::log(unsigned int channel, const char * file, unsigned int line, const char * format, ...) {
fixSize(channel);
void DebugPrintf(Debug * d, const char * file, u32 line, const char * format, ...) {
va_list l;
if (d == NULL)
return;
va_start(l, format);
switch(d->output_type) {
case DEBUG_STDOUT:
case DEBUG_STDERR:
case DEBUG_STREAM:
if (d->output.stream == NULL)
break;
fprintf(d->output.stream, "%s (%s:%ld): ", d->name, file, line);
vfprintf(d->output.stream, format, l);
break;
case DEBUG_STRING:
{
int i;
if (d->output.string == NULL)
break;
i = sprintf(d->output.string, "%s (%s:%ld): ", d->name, file, line);
vsprintf(d->output.string + i, format, l);
}
break;
}
channels[channel]->vprintf(format, l, file, line);
va_end(l);
}
//////////////////////////////////////////////////////////////////////////////
void Logger::log(unsigned int channel, const char * file, unsigned int line, std::ostream& os) {
fixSize(channel);
Debug * MainLog;
//////////////////////////////////////////////////////////////////////////////
void LogStart(void) {
MainLog = DebugInit("main", DEBUG_STDERR, NULL);
// MainLog = DebugInit("main", DEBUG_STREAM, "stdout.txt");
channels[channel]->setOutput(&os);
}
//////////////////////////////////////////////////////////////////////////////
void Logger::log(unsigned int channel, const char * file, unsigned int line, unsigned int flag) {
fixSize(channel);
void LogStop(void) {
DebugDeInit(MainLog);
channels[channel]->setFlag(flag);
}
//////////////////////////////////////////////////////////////////////////////
void Logger::log(unsigned int channel, const char * file, unsigned int line, void (*callback)(const Logger& logger, const char * message)) {
fixSize(channel);
channels[channel]->setCallback(callback);
}

View File

@ -1,6 +1,6 @@
/* Copyright 2005-2006 Guillaume Duhamel
/* Copyright (C) 2008 Guillaume Duhamel
This file is part of DeSmuME.
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -17,87 +17,63 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DEBUG_H
#define DEBUG_H
#ifndef LOGGER_H
#define LOGGER_H
#include "types.h"
#include <stdio.h>
#include <vector>
#include <iostream>
#ifdef _WIN32
#include "windows/console.h"
#endif
class Logger {
protected:
void (*callback)(const Logger& logger, const char * format);
std::ostream * out;
unsigned int flags;
#if defined(BETA_VERSION) && defined(WIN32)
void OpenConsole();
void CloseConsole();
void printlog(const char *fmt, ...);
#else
#define OpenConsole()
#define CloseConsole()
#define printlog(...)
#endif
static std::vector<Logger *> channels;
typedef enum { DEBUG_STRING, DEBUG_STREAM , DEBUG_STDOUT, DEBUG_STDERR } DebugOutType;
static void fixSize(unsigned int channel);
public:
Logger();
typedef struct {
DebugOutType output_type;
union {
FILE * stream;
char * string;
} output;
char * name;
} Debug;
void vprintf(const char * format, va_list l, const char * filename, unsigned int line);
void setOutput(std::ostream * out);
void setCallback(void (*callback)(const Logger& logger, const char * message));
void setFlag(unsigned int flag);
Debug * DebugInit(const char *, DebugOutType, char *);
void DebugDeInit(Debug *);
std::ostream& getOutput() const;
void DebugChangeOutput(Debug *, DebugOutType, char *);
static const int LINE = 1;
static const int FILE = 2;
void DebugPrintf(Debug *, const char *, u32, const char *, ...);
extern Debug * MainLog;
void LogStart(void);
void LogStop(void);
static void log(unsigned int channel, const char * file, unsigned int line, const char * format, ...);
static void log(unsigned int channel, const char * file, unsigned int line, std::ostream& os);
static void log(unsigned int channel, const char * file, unsigned int line, unsigned int flag);
static void log(unsigned int channel, const char * file, unsigned int line, void (*callback)(const Logger& logger, const char * message));
};
#ifdef DEBUG
#define LOG(...) DebugPrintf(MainLog, __FILE__, __LINE__, __VA_ARGS__)
#else
#if defined(WIN32) && defined(BETA_VERSION) && defined(OLD_LOG)
#define LOG(...) printlog(__VA_ARGS__)
#define LOGC(channel, ...) Logger::log(channel, __FILE__, __LINE__, __VA_ARGS__)
#define LOG(...) LOGC(0, __VA_ARGS__)
#define GPULOG(...) LOGC(1, __VA_ARGS__)
#define DIVLOG(...) LOGC(2, __VA_ARGS__)
#define SQRTLOG(...) LOGC(3, __VA_ARGS__)
#define DMALOG(...) LOGC(3, __VA_ARGS__)
#else
#define LOGC(...)
#define LOG(...)
#endif
#endif
#ifdef GPUDEBUG
#define GPULOG(...) DebugPrintf(MainLog, __FILE__, __LINE__, __VA_ARGS__)
#else
#define GPULOG(...)
#endif
#ifdef DIVDEBUG
#define DIVLOG(...) DebugPrintf(MainLog, __FILE__, __LINE__, __VA_ARGS__)
#else
#define DIVLOG(...)
#endif
#ifdef SQRTDEBUG
#define SQRTLOG(...) DebugPrintf(MainLog, __FILE__, __LINE__, __VA_ARGS__)
#else
#define SQRTLOG(...)
#endif
#ifdef CARDDEBUG
#define CARDLOG(...) DebugPrintf(MainLog, __FILE__, __LINE__, __VA_ARGS__)
#else
#define CARDLOG(...)
#endif
#ifdef DMADEBUG
#define DMALOG(...) DebugPrintf(MainLog, __FILE__, __LINE__, __VA_ARGS__)
#else
#define DMALOG(...)
#endif
#endif
#define INFOC(channel, ...) Logger::log(channel, __FILE__, __LINE__, __VA_ARGS__)
#define INFO(...) INFOC(10, __VA_ARGS__)
#endif

View File

@ -394,10 +394,6 @@ common_gtk_glade_main( struct configured_features *my_config) {
//g_thread_init(NULL);
register_gl_fun(my_gl_Begin,my_gl_End);
#endif
#ifdef DEBUG
LogStart();
#endif
init_keyvals();
#ifdef GDB_STUB
@ -555,9 +551,6 @@ common_gtk_glade_main( struct configured_features *my_config) {
SDL_DestroySemaphore( glade_fps_limiter_semaphore);
}
#ifdef DEBUG
LogStop();
#endif
/* Unload joystick */
uninit_joy();

View File

@ -1460,10 +1460,6 @@ common_gtk_main( struct configured_features *my_config)
bad_glob_cflash_disk_image_file = my_config->cflash_disk_image_file;
#ifdef DEBUG
LogStart();
#endif
#ifdef GDB_STUB
if ( my_config->arm9_gdb_port != 0) {
arm9_gdb_stub = createStub_gdb( my_config->arm9_gdb_port,
@ -1926,9 +1922,6 @@ common_gtk_main( struct configured_features *my_config)
SDL_DestroySemaphore( fps_limiter_semaphore);
}
#ifdef DEBUG
LogStop();
#endif
/* Unload joystick */
uninit_joy();

View File

@ -102,7 +102,7 @@ void mc_reset_com(memory_chip_t *mc)
{
u32 addr, size;
printlog("autodetectsize = %d\n",mc->autodetectsize);
LOG("autodetectsize = %d\n",mc->autodetectsize);
if (mc->autodetectsize == (32768+2))
{

View File

@ -1223,9 +1223,6 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
hAccel = LoadAccelerators(hAppInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL));
#ifdef DEBUG
LogStart();
#endif
mainMenu = LoadMenu(hThisInstance, "MENU_PRINCIPAL"); //Load Menu, and store handle
if (!MainWindow->setMenu(mainMenu))
{