Re-organized Qt PPU viewer to have each pattern table in its own frame.

This commit is contained in:
Matthew Budd 2020-10-04 20:36:33 -04:00
parent fa55d6024b
commit ccb8b63282
2 changed files with 84 additions and 70 deletions

View File

@ -36,7 +36,7 @@ static int PPUViewScanline = 0;
//static int PPUViewRefresh = 0; //static int PPUViewRefresh = 0;
static bool PPUView_maskUnusedGraphics = true; static bool PPUView_maskUnusedGraphics = true;
static bool PPUView_invertTheMask = false; static bool PPUView_invertTheMask = false;
static int PPUView_sprite16Mode = 0; static int PPUView_sprite16Mode[2] = { 0, 0 };
static int pindex0 = 0, pindex1 = 0; static int pindex0 = 0, pindex1 = 0;
static QColor ppuv_palette[PALETTEHEIGHT][PALETTEWIDTH]; static QColor ppuv_palette[PALETTEHEIGHT][PALETTEWIDTH];
static uint8_t pallast[32+3] = { 0 }; // palette cache for change comparison static uint8_t pallast[32+3] = { 0 }; // palette cache for change comparison
@ -44,18 +44,8 @@ static uint8_t palcache[36] = { 0 }; //palette cache for drawing
static uint8_t chrcache0[0x1000] = {0}, chrcache1[0x1000] = {0}, logcache0[0x1000] = {0}, logcache1[0x1000] = {0}; //cache CHR, fixes a refresh problem when right-clicking static uint8_t chrcache0[0x1000] = {0}, chrcache1[0x1000] = {0}, logcache0[0x1000] = {0}, logcache1[0x1000] = {0}; //cache CHR, fixes a refresh problem when right-clicking
//pattern table bitmap arrays //pattern table bitmap arrays
struct patternTable_t static ppuPatternTable_t pattern0;
{ static ppuPatternTable_t pattern1;
struct
{
struct
{
QColor color;
} pixel[16][8];
} tile[16][16];
};
static patternTable_t pattern0;
static patternTable_t pattern1;
//---------------------------------------------------- //----------------------------------------------------
int openPPUViewWindow( QWidget *parent ) int openPPUViewWindow( QWidget *parent )
{ {
@ -74,8 +64,8 @@ ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
: QDialog( parent ) : QDialog( parent )
{ {
QVBoxLayout *mainLayout, *vbox; QVBoxLayout *mainLayout, *vbox;
QVBoxLayout *patternVbox[2];
QHBoxLayout *hbox; QHBoxLayout *hbox;
QGroupBox *frame;
QGridLayout *grid; QGridLayout *grid;
ppuViewWindow = this; ppuViewWindow = this;
@ -87,25 +77,46 @@ ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
setLayout( mainLayout ); setLayout( mainLayout );
vbox = new QVBoxLayout(); vbox = new QVBoxLayout();
frame = new QGroupBox( tr("Pattern Tables") ); hbox = new QHBoxLayout();
patternView = new ppuPatternView_t(this);
grid = new QGridLayout; grid = new QGridLayout;
patternVbox[0] = new QVBoxLayout();
vbox->addWidget( patternView, 10 ); patternVbox[1] = new QVBoxLayout();
vbox->addLayout( grid, 1 ); patternFrame[0] = new QGroupBox( tr("Pattern Table 0") );
frame->setLayout( vbox ); patternFrame[1] = new QGroupBox( tr("Pattern Table 1") );
patternView[0] = new ppuPatternView_t( 0, this);
patternView[1] = new ppuPatternView_t( 1, this);
sprite8x16Cbox[0] = new QCheckBox( tr("Sprites 8x16 Mode") );
sprite8x16Cbox[1] = new QCheckBox( tr("Sprites 8x16 Mode") );
tileLabel[0] = new QLabel( tr("Pattern 0 Tile:") ); tileLabel[0] = new QLabel( tr("Pattern 0 Tile:") );
tileLabel[1] = new QLabel( tr("Pattern 1 Tile:") ); tileLabel[1] = new QLabel( tr("Pattern 1 Tile:") );
sprite8x16Cbox = new QCheckBox( tr("Sprites 8x16 Mode") );
sprite8x16Cbox[0]->setChecked( PPUView_sprite16Mode[0] );
sprite8x16Cbox[1]->setChecked( PPUView_sprite16Mode[1] );
patternVbox[0]->addWidget( patternView[0], 10 );
patternVbox[0]->addWidget( tileLabel[0], 1 );
patternVbox[0]->addWidget( sprite8x16Cbox[0], 1 );
patternVbox[1]->addWidget( patternView[1], 10 );
patternVbox[1]->addWidget( tileLabel[1], 1 );
patternVbox[1]->addWidget( sprite8x16Cbox[1], 1 );
patternFrame[0]->setLayout( patternVbox[0] );
patternFrame[1]->setLayout( patternVbox[1] );
hbox->addWidget( patternFrame[0] );
hbox->addWidget( patternFrame[1] );
mainLayout->addLayout( hbox, 10 );
mainLayout->addLayout( grid, 1 );
maskUnusedCbox = new QCheckBox( tr("Mask unused Graphics (Code/Data Logger)") ); maskUnusedCbox = new QCheckBox( tr("Mask unused Graphics (Code/Data Logger)") );
invertMaskCbox = new QCheckBox( tr("Invert the Mask (Code/Data Logger)") ); invertMaskCbox = new QCheckBox( tr("Invert the Mask (Code/Data Logger)") );
sprite8x16Cbox->setChecked( PPUView_sprite16Mode );
maskUnusedCbox->setChecked( PPUView_maskUnusedGraphics ); maskUnusedCbox->setChecked( PPUView_maskUnusedGraphics );
invertMaskCbox->setChecked( PPUView_invertTheMask ); invertMaskCbox->setChecked( PPUView_invertTheMask );
connect( sprite8x16Cbox, SIGNAL(stateChanged(int)), this, SLOT(sprite8x16Changed(int))); connect( sprite8x16Cbox[0], SIGNAL(stateChanged(int)), this, SLOT(sprite8x16Changed0(int)));
connect( sprite8x16Cbox[1], SIGNAL(stateChanged(int)), this, SLOT(sprite8x16Changed1(int)));
hbox = new QHBoxLayout(); hbox = new QHBoxLayout();
refreshSlider = new QSlider( Qt::Horizontal ); refreshSlider = new QSlider( Qt::Horizontal );
@ -113,20 +124,15 @@ ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
hbox->addWidget( refreshSlider ); hbox->addWidget( refreshSlider );
hbox->addWidget( new QLabel( tr("Less") ) ); hbox->addWidget( new QLabel( tr("Less") ) );
grid->addWidget( tileLabel[0], 0, 0, Qt::AlignLeft ); grid->addWidget( maskUnusedCbox, 0, 0, Qt::AlignLeft );
grid->addWidget( tileLabel[1], 0, 1, Qt::AlignLeft ); grid->addWidget( invertMaskCbox, 1, 0, Qt::AlignLeft );
grid->addWidget( sprite8x16Cbox, 1, 0, Qt::AlignLeft ); grid->addLayout( hbox, 0, 1, Qt::AlignRight );
grid->addWidget( maskUnusedCbox, 2, 0, Qt::AlignLeft );
grid->addWidget( invertMaskCbox, 3, 0, Qt::AlignLeft );
grid->addLayout( hbox, 1, 1, Qt::AlignRight );
hbox = new QHBoxLayout(); hbox = new QHBoxLayout();
scanLineEdit = new QLineEdit(); scanLineEdit = new QLineEdit();
hbox->addWidget( new QLabel( tr("Display on Scanline:") ) ); hbox->addWidget( new QLabel( tr("Display on Scanline:") ) );
hbox->addWidget( scanLineEdit ); hbox->addWidget( scanLineEdit );
grid->addLayout( hbox, 2, 1, Qt::AlignRight ); grid->addLayout( hbox, 1, 1, Qt::AlignRight );
mainLayout->addWidget( frame, 10 );
vbox = new QVBoxLayout(); vbox = new QVBoxLayout();
paletteFrame = new QGroupBox( tr("Palettes:") ); paletteFrame = new QGroupBox( tr("Palettes:") );
@ -137,6 +143,9 @@ ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
mainLayout->addWidget( paletteFrame, 1 ); mainLayout->addWidget( paletteFrame, 1 );
patternView[0]->setPattern( &pattern0 );
patternView[1]->setPattern( &pattern1 );
FCEUD_UpdatePPUView( -1, 1 ); FCEUD_UpdatePPUView( -1, 1 );
} }
@ -163,18 +172,29 @@ void ppuViewerDialog_t::closeWindow(void)
deleteLater(); deleteLater();
} }
//---------------------------------------------------- //----------------------------------------------------
void ppuViewerDialog_t::sprite8x16Changed(int state) void ppuViewerDialog_t::sprite8x16Changed0(int state)
{ {
PPUView_sprite16Mode = (state == Qt::Unchecked) ? 0 : 1; PPUView_sprite16Mode[0] = (state == Qt::Unchecked) ? 0 : 1;
} }
//---------------------------------------------------- //----------------------------------------------------
ppuPatternView_t::ppuPatternView_t(QWidget *parent) void ppuViewerDialog_t::sprite8x16Changed1(int state)
{
PPUView_sprite16Mode[1] = (state == Qt::Unchecked) ? 0 : 1;
}
//----------------------------------------------------
ppuPatternView_t::ppuPatternView_t( int patternIndexID, QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setMinimumWidth( 512 ); patternIndex = patternIndexID;
setMinimumWidth( 256 );
setMinimumHeight( 256 ); setMinimumHeight( 256 );
} }
//---------------------------------------------------- //----------------------------------------------------
void ppuPatternView_t::setPattern( ppuPatternTable_t *p )
{
pattern = p;
}
//----------------------------------------------------
ppuPatternView_t::~ppuPatternView_t(void) ppuPatternView_t::~ppuPatternView_t(void)
{ {
@ -182,16 +202,15 @@ ppuPatternView_t::~ppuPatternView_t(void)
//---------------------------------------------------- //----------------------------------------------------
void ppuPatternView_t::paintEvent(QPaintEvent *event) void ppuPatternView_t::paintEvent(QPaintEvent *event)
{ {
int i,j,x,y,w,h,w2,xx,yy; int i,j,x,y,w,h,xx,yy;
QPainter painter(this); QPainter painter(this);
int viewWidth = event->rect().width(); int viewWidth = event->rect().width();
int viewHeight = event->rect().height(); int viewHeight = event->rect().height();
//printf("PPU PatternView %ix%i \n", viewWidth, viewHeight ); //printf("PPU PatternView %ix%i \n", viewWidth, viewHeight );
w = viewWidth / 256; w = viewWidth / 128;
h = viewHeight / 128; h = viewHeight / 128;
w2= viewWidth / 2;
xx = 0; yy = 0; xx = 0; yy = 0;
@ -207,29 +226,7 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
for (y=0; y < 8; y++) for (y=0; y < 8; y++)
{ {
painter.fillRect( xx, yy, w, h, pattern0.tile[j][i].pixel[y][x].color ); painter.fillRect( xx, yy, w, h, pattern->tile[j][i].pixel[y][x].color );
yy += h;
}
xx += w;
}
}
}
xx = w2; yy = 0;
for (i=0; i<16; i++) //Columns
{
for (j=0; j<16; j++) //Rows
{
xx = w2 + (i*8)*w;
for (x=0; x < 8; x++)
{
yy = (j*8)*h;
for (y=0; y < 8; y++)
{
painter.fillRect( xx, yy, w, h, pattern1.tile[j][i].pixel[y][x].color );
yy += h; yy += h;
} }
xx += w; xx += w;
@ -238,7 +235,7 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
} }
} }
//---------------------------------------------------- //----------------------------------------------------
static void DrawPatternTable( patternTable_t *pattern, uint8_t *table, uint8_t *log, uint8_t pal) static void DrawPatternTable( ppuPatternTable_t *pattern, uint8_t *table, uint8_t *log, uint8_t pal)
{ {
int i,j,x,y,index=0; int i,j,x,y,index=0;
int p=0,tmp; int p=0,tmp;

View File

@ -20,16 +20,31 @@
#include "Qt/main.h" #include "Qt/main.h"
struct ppuPatternTable_t
{
struct
{
struct
{
QColor color;
} pixel[8][8];
} tile[16][16];
};
class ppuPatternView_t : public QWidget class ppuPatternView_t : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
ppuPatternView_t(QWidget *parent = 0); ppuPatternView_t( int patternIndex, QWidget *parent = 0);
~ppuPatternView_t(void); ~ppuPatternView_t(void);
void setPattern( ppuPatternTable_t *p );
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
int patternIndex;
ppuPatternTable_t *pattern;
}; };
class ppuPalatteView_t : public QWidget class ppuPalatteView_t : public QWidget
@ -55,15 +70,16 @@ class ppuViewerDialog_t : public QDialog
protected: protected:
//QTimer *inputTimer; //QTimer *inputTimer;
ppuPatternView_t *patternView; ppuPatternView_t *patternView[2];
ppuPalatteView_t *paletteView; ppuPalatteView_t *paletteView;
void closeEvent(QCloseEvent *bar); void closeEvent(QCloseEvent *bar);
private: private:
QGroupBox *patternFrame[2];
QGroupBox *paletteFrame; QGroupBox *paletteFrame;
QLabel *tileLabel[2]; QLabel *tileLabel[2];
QCheckBox *sprite8x16Cbox; QCheckBox *sprite8x16Cbox[2];
QCheckBox *maskUnusedCbox; QCheckBox *maskUnusedCbox;
QCheckBox *invertMaskCbox; QCheckBox *invertMaskCbox;
QSlider *refreshSlider; QSlider *refreshSlider;
@ -73,7 +89,8 @@ class ppuViewerDialog_t : public QDialog
void closeWindow(void); void closeWindow(void);
private slots: private slots:
//void updatePeriodic(void); //void updatePeriodic(void);
void sprite8x16Changed(int state); void sprite8x16Changed0(int state);
void sprite8x16Changed1(int state);
}; };