Qt Ram watch logic in work.

This commit is contained in:
Matthew Budd 2020-10-07 21:01:39 -04:00
parent ab922df318
commit ff694ebe49
3 changed files with 403 additions and 0 deletions

View File

@ -639,6 +639,7 @@ int GuiCheatsDialog_t::activeCheatListCB (char *name, uint32 a, uint8 v, int c,
item->setTextAlignment( 0, Qt::AlignLeft);
item->setTextAlignment( 1, Qt::AlignLeft);
item->setTextAlignment( 2, Qt::AlignLeft);
actvCheatIdx++;

View File

@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <string>
#include <SDL.h>
@ -12,6 +13,11 @@
#include <QCloseEvent>
#include <QGroupBox>
#include "../../types.h"
#include "../../fceu.h"
#include "../../cheat.h"
#include "../../debug.h"
#include "Qt/main.h"
#include "Qt/dface.h"
#include "Qt/input.h"
@ -252,3 +258,279 @@ void RamWatchDialog_t::closeWindow(void)
deleteLater();
}
//----------------------------------------------------------------------------
void RamWatchDialog_t::updateRamWatchDisplay(void)
{
int idx=0;
QTreeWidgetItem *item;
std::list < ramWatch_t * >::iterator it;
char addrStr[32], valStr1[16], valStr2[16];
ramWatch_t *rw;
for (it = ramWatchList.ls.begin (); it != ramWatchList.ls.end (); it++)
{
rw = *it;
item = tree->topLevelItem(idx);
if ( item == NULL )
{
item = new QTreeWidgetItem();
tree->addTopLevelItem( item );
}
sprintf (addrStr, "0x%04X", rw->addr);
rw->updateMem ();
if (rw->size == 2)
{
if (rw->type)
{
sprintf (valStr1, "%6u", rw->val.u16);
}
else
{
sprintf (valStr1, "%6i", rw->val.i16);
}
sprintf (valStr2, "0x%04X", rw->val.u16);
}
else
{
if (rw->type)
{
sprintf (valStr1, "%6u", rw->val.u8);
}
else
{
sprintf (valStr1, "%6i", rw->val.i8);
}
sprintf (valStr2, "0x%02X", rw->val.u8);
}
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemNeverHasChildren );
//item->setFont(font);
item->setText( 0, tr(addrStr) );
item->setText( 1, tr(valStr1) );
item->setText( 2, tr(rw->name.c_str()) );
item->setTextAlignment( 0, Qt::AlignLeft);
item->setTextAlignment( 1, Qt::AlignLeft);
item->setTextAlignment( 2, Qt::AlignLeft);
idx++;
}
}
//----------------------------------------------------------------------------
void ramWatch_t::updateMem (void)
{
if (size == 1)
{
val.u8 = GetMem (addr);
}
else if (size == 2)
{
val.u16 = GetMem (addr) | (GetMem (addr + 1) << 8);
}
else
{
val.u8 = GetMem (addr);
}
}
//----------------------------------------------------------------------------
void RamWatchDialog_t::saveWatchFile (const char *filename)
{
int i;
FILE *fp;
const char *c;
std::list < ramWatch_t * >::iterator it;
ramWatch_t *rw;
fp = fopen (filename, "w");
if (fp == NULL)
{
printf ("Error: Failed to open file: %s\n", filename);
return;
}
for (it = ramWatchList.ls.begin (); it != ramWatchList.ls.end (); it++)
{
rw = *it;
c = rw->name.c_str ();
fprintf (fp, "0x%04x %c%i ", rw->addr, rw->type ? 'U' : 'S',
rw->size);
i = 0;
fprintf (fp, "\"");
while (c[i])
{
if (c[i] == '"')
{
fprintf (fp, "\\%c", c[i]);
}
else
{
fprintf (fp, "%c", c[i]);
}
i++;
}
fprintf (fp, "\"\n");
}
fclose (fp);
}
//----------------------------------------------------------------------------
void RamWatchDialog_t::loadWatchFile (const char *filename)
{
FILE *fp;
int i, j, a, t, s, literal;
char line[512], stmp[512];
ramWatch_t *rw;
fp = fopen (filename, "r");
if (fp == NULL)
{
printf ("Error: Failed to open file: %s\n", filename);
return;
}
while (fgets (line, sizeof (line) - 1, fp) > 0)
{
a = -1;
t = -1;
s = -1;
// Check for Comments
i = 0;
while (line[i] != 0)
{
if (literal)
{
literal = 0;
}
else
{
if (line[i] == '#')
{
line[i] = 0;
break;
}
else if (line[i] == '\\')
{
literal = 1;
}
}
i++;
}
i = 0;
j = 0;
while (isspace (line[i])) i++;
if ((line[i] == '0') && (tolower (line[i + 1]) == 'x'))
{
stmp[j] = '0';
j++;
i++;
stmp[j] = 'x';
j++;
i++;
while (isxdigit (line[i]))
{
stmp[j] = line[i];
i++;
j++;
}
}
else
{
while (isxdigit (line[i]))
{
stmp[j] = line[i];
i++;
j++;
}
}
stmp[j] = 0;
if (j == 0) continue;
a = strtol (stmp, NULL, 0);
while (isspace (line[i])) i++;
t = line[i];
i++;
s = line[i];
i++;
if ((t != 'U') && (t != 'S'))
{
printf ("Error: Invalid RAM Watch Byte Type: %c", t);
continue;
}
if (!isdigit (s))
{
printf ("Error: Invalid RAM Watch Byte Size: %c", s);
continue;
}
s = s - '0';
if ((s != 1) && (s != 2) && (s != 4))
{
printf ("Error: Invalid RAM Watch Byte Size: %i", s);
continue;
}
while (isspace (line[i])) i++;
if (line[i] == '"')
{
i++;
j = 0;
literal = 0;
while ((line[i] != 0))
{
if (literal)
{
literal = 0;
}
else
{
if (line[i] == '"')
{
break;
}
else if (line[i] == '\\')
{
literal = 1;
}
}
if (!literal)
{
stmp[j] = line[i];
j++;
}
i++;
}
stmp[j] = 0;
}
rw = new ramWatch_t;
rw->addr = a;
rw->type = (t == 'U') ? 1 : 0;
rw->size = s;
rw->name.assign (stmp);
ramWatchList.ls.push_back (rw);
}
fclose (fp);
//showAllRamWatchResults (1);
}
//----------------------------------------------------------------------------

View File

@ -3,6 +3,7 @@
#pragma once
#include <list>
#include <QWidget>
#include <QDialog>
#include <QVBoxLayout>
@ -18,6 +19,120 @@
#include "Qt/main.h"
struct ramWatch_t
{
std::string name;
int addr;
int type;
int size;
union
{
int8_t i8;
uint8_t u8;
int16_t i16;
uint16_t u16;
} val;
ramWatch_t (void)
{
addr = 0;
type = 0;
size = 0;
val.u16 = 0;
};
void updateMem (void);
};
struct ramWatchList_t
{
std::list <ramWatch_t*> ls;
ramWatchList_t (void)
{
}
~ramWatchList_t (void)
{
ramWatch_t *rw;
while (!ls.empty ())
{
rw = ls.front ();
delete rw;
ls.pop_front ();
}
}
size_t size (void)
{
return ls.size ();
};
void add_entry (const char *name, int addr, int type, int size)
{
ramWatch_t *rw = new ramWatch_t;
rw->name.assign (name);
rw->addr = addr;
rw->type = type;
rw->size = size;
ls.push_back (rw);
}
void updateMemoryValues (void)
{
ramWatch_t *rw;
std::list < ramWatch_t * >::iterator it;
for (it = ls.begin (); it != ls.end (); it++)
{
rw = *it;
rw->updateMem ();
}
}
ramWatch_t *getIndex (size_t idx)
{
size_t i = 0;
std::list < ramWatch_t * >::iterator it;
for (it = ls.begin (); it != ls.end (); it++)
{
if (i == idx)
{
return *it;
}
i++;
}
return NULL;
}
int deleteIndex (size_t idx)
{
size_t i = 0;
std::list < ramWatch_t * >::iterator it;
for (it = ls.begin (); it != ls.end (); it++)
{
if (i == idx)
{
delete *it;
ls.erase (it);
return 0;
}
i++;
}
return -1;
}
};
class RamWatchDialog_t : public QDialog
{
Q_OBJECT
@ -28,6 +143,8 @@ class RamWatchDialog_t : public QDialog
protected:
void closeEvent(QCloseEvent *event);
void loadWatchFile (const char *filename);
void saveWatchFile (const char *filename);
QFont font;
QTreeWidget *tree;
@ -40,9 +157,12 @@ class RamWatchDialog_t : public QDialog
QPushButton *sep_btn;
QPushButton *cht_btn;
ramWatchList_t ramWatchList;
int fontCharWidth;
private:
void updateRamWatchDisplay(void);
public slots:
void closeWindow(void);