Added ppu viewer selected tile movement via key board keys. Added selected tile indication to PPU viewer.

This commit is contained in:
mjbudd77 2021-01-31 21:09:21 -05:00
parent e74dbeeb51
commit 2940f1da66
4 changed files with 202 additions and 36 deletions

View File

@ -1016,18 +1016,21 @@ int ppuNameTableView_t::calcTableTileAddr( int NameTable, int TileX, int TileY
//----------------------------------------------------
void ppuNameTableView_t::computeNameTableProperties( int NameTable, int TileX, int TileY )
{
int TileID, PPUAddress, AttAddress, Attrib;
int TileID, PPUAddress, AttAddress, Attrib, ptable = 0;
if ( vnapage[0] == NULL )
{
return;
}
if (PPU[0]&0x10){ //use the correct pattern table based on this bit
ptable=0x1000;
}
ppuAddr = PPUAddress = 0x2000+(NameTable*0x400)+((TileY%30)*32)+(TileX%32);
TileID = vnapage[(PPUAddress>>10)&0x3][PPUAddress&0x3FF];
tileAddr = TileID << 4;
tileAddr = ptable | (TileID << 4);
atrbAddr = AttAddress = 0x23C0 | (PPUAddress & 0x0C00) | ((PPUAddress >> 4) & 0x38) | ((PPUAddress >> 2) & 0x07);
@ -1231,7 +1234,7 @@ void ppuNameTableView_t::contextMenuEvent(QContextMenuEvent *event)
redrawtables = true;
sprintf( stmp, "Open Tile %X%X in PPU Viewer", selTile.x(), selTile.y() );
sprintf( stmp, "Open Tile $%04X in PPU Viewer", tileAddr );
act = new QAction(tr(stmp), &menu);
//act->setShortcut( QKeySequence(tr("V")));
connect( act, SIGNAL(triggered(void)), this, SLOT(openTilePpuViewer(void)) );
@ -1261,7 +1264,18 @@ void ppuNameTableView_t::contextMenuEvent(QContextMenuEvent *event)
//----------------------------------------------------
void ppuNameTableView_t::openTilePpuViewer(void)
{
int pTable,x,y;
pTable = tileAddr >= 0x1000;
y = (tileAddr & 0x0F00) >> 8;
x = (tileAddr & 0x00F0) >> 4;
openPPUViewWindow( consoleWindow );
//printf("TileAddr: %04X %i,%X%X\n", tileAddr, pTable, x, y );
setPPUSelPatternTile( pTable, x, y );
setPPUSelPatternTile( !pTable, -1, -1 );
}
//----------------------------------------------------
void ppuNameTableView_t::openTileAddrHexEdit(void)
@ -1549,7 +1563,8 @@ static void DrawNameTable(int scanline, int ntnum, bool invalidateCache)
const uint8* chrp = FCEUPPU_GetCHR(ptable+chr,refreshaddr);
if (attview) chrp = ATTRIBUTE_VIEW_TILE;
nameTable[ntnum].tile[y][x].pTbl = ptable;
nameTable[ntnum].tile[y][x].pTbl = ptable;
nameTable[ntnum].tile[y][x].pTblAdr = ptable+chr;
//a good way to do it:
DrawChr( &nameTable[ntnum].tile[y][x], chrp, a);

View File

@ -30,6 +30,7 @@ struct ppuNameTableTile_t
int x;
int y;
int pTblAdr;
int pTbl;
int pal;
@ -38,6 +39,7 @@ struct ppuNameTableTile_t
x = y = 0;
pTbl = 0;
pal = 0;
pTblAdr = 0;
}
};

View File

@ -90,6 +90,24 @@ int openPPUViewWindow( QWidget *parent )
return 0;
}
//----------------------------------------------------
void setPPUSelPatternTile( int table, int x, int y )
{
if ( ppuViewWindow == NULL )
{
return;
}
if ( table )
{
table = 1;
}
else
{
table = 0;
}
ppuViewWindow->patternView[ table ]->setTileCoord( x, y );
ppuViewWindow->patternView[ table ]->updateSelTileLabel();
}
//----------------------------------------------------
ppuViewerDialog_t::ppuViewerDialog_t(QWidget *parent)
: QDialog( parent, Qt::Window )
{
@ -315,13 +333,15 @@ void ppuViewerDialog_t::closeWindow(void)
//----------------------------------------------------
void ppuViewerDialog_t::periodicUpdate(void)
{
cycleCount = (cycleCount + 1) % 30;
cycleCount = (cycleCount + 1) % 4;
if ( redrawWindow || (cycleCount == 0) )
{
this->update();
redrawWindow = false;
}
patternView[0]->updateCycleCounter();
patternView[1]->updateCycleCounter();
}
//----------------------------------------------------
void ppuViewerDialog_t::scanLineChanged( const QString &txt )
@ -364,11 +384,14 @@ ppuPatternView_t::ppuPatternView_t( int patternIndexID, QWidget *parent)
viewHeight = 256;
tileLabel = NULL;
mode = 0;
cycleCount = 0;
drawTileGrid = true;
hover2Focus = false;
selTileColor.setRgb(255,255,255);
gridColor.setRgb(128,128,128);
selTile.setX(-1);
selTile.setY(-1);
}
//----------------------------------------------------
void ppuPatternView_t::setPattern( ppuPatternTable_t *p )
@ -381,6 +404,13 @@ void ppuPatternView_t::setTileLabel( QLabel *l )
tileLabel = l;
}
//----------------------------------------------------
void ppuPatternView_t::setTileCoord( int x, int y )
{
selTile.setX(x);
selTile.setY(y);
cycleCount = 0;
}
//----------------------------------------------------
ppuPatternView_t::~ppuPatternView_t(void)
{
@ -475,14 +505,20 @@ void ppuPatternView_t::keyPressEvent(QKeyEvent *event)
if ( event->key() == Qt::Key_Z )
{
mode = !mode;
event->accept();
}
else if ( event->key() == Qt::Key_G )
{
drawTileGrid = !drawTileGrid;
event->accept();
}
else if ( event->key() == Qt::Key_E )
{
openTileEditor();
event->accept();
}
else if ( event->key() == Qt::Key_P )
{
@ -491,6 +527,8 @@ void ppuPatternView_t::keyPressEvent(QKeyEvent *event)
PPUViewSkip = 100;
FCEUD_UpdatePPUView( -1, 0 );
event->accept();
}
else if ( event->key() == Qt::Key_F5 )
{
@ -498,10 +536,102 @@ void ppuPatternView_t::keyPressEvent(QKeyEvent *event)
PPUViewSkip = 100;
FCEUD_UpdatePPUView( -1, 1 );
event->accept();
}
else if ( event->key() == Qt::Key_Up )
{
int y;
y = selTile.y();
y--;
if ( y < 0 )
{
y = 15;
}
selTile.setY(y);
cycleCount = 0;
updateSelTileLabel();
event->accept();
}
else if ( event->key() == Qt::Key_Down )
{
int y;
y = selTile.y();
y++;
if ( y >= 16 )
{
y = 0;
}
selTile.setY(y);
cycleCount = 0;
updateSelTileLabel();
event->accept();
}
else if ( event->key() == Qt::Key_Left )
{
int x;
x = selTile.x();
x--;
if ( x < 0 )
{
x = 15;
}
selTile.setX(x);
cycleCount = 0;
updateSelTileLabel();
event->accept();
}
else if ( event->key() == Qt::Key_Right )
{
int x;
x = selTile.x();
x++;
if ( x >= 16 )
{
x = 0;
}
selTile.setX(x);
cycleCount = 0;
updateSelTileLabel();
event->accept();
}
}
//----------------------------------------------------
void ppuPatternView_t::updateSelTileLabel(void)
{
char stmp[32];
if ( (selTile.y() >= 0) && (selTile.x() >= 0) )
{
sprintf( stmp, "Tile: $%X%X", selTile.y(), selTile.x() );
}
else
{
strcpy( stmp, "Tile:");
}
tileLabel->setText( tr(stmp) );
}
//----------------------------------------------------
void ppuPatternView_t::mouseMoveEvent(QMouseEvent *event)
{
if ( mode == 0 )
@ -512,11 +642,11 @@ void ppuPatternView_t::mouseMoveEvent(QMouseEvent *event)
{
if ( hover2Focus )
{
char stmp[64];
sprintf( stmp, "Tile: $%X%X", tile.y(), tile.x() );
tileLabel->setText( tr(stmp) );
selTile = tile;
cycleCount = 0;
updateSelTileLabel();
}
}
}
@ -530,11 +660,11 @@ void ppuPatternView_t::mousePressEvent(QMouseEvent * event)
{
if ( (tile.x() < 16) && (tile.y() < 16) )
{
char stmp[64];
sprintf( stmp, "Tile: $%X%X", tile.y(), tile.x() );
tileLabel->setText( tr(stmp) );
selTile = tile;
cycleCount = 0;
updateSelTileLabel();
}
}
}
@ -697,13 +827,20 @@ void ppuPatternView_t::selPalette8(void)
pindex[ patternIndex ] = 8;
}
//----------------------------------------------------
void ppuPatternView_t::updateCycleCounter(void)
{
cycleCount = (cycleCount + 1) % 30;
}
//----------------------------------------------------
void ppuPatternView_t::paintEvent(QPaintEvent *event)
{
int i,j,x,y,w,h,xx,yy,ii,jj,rr;
QPainter painter(this);
QPen pen;
char showSelector;
viewWidth = event->rect().width();
viewHeight = event->rect().height();
QPen pen;
pen = painter.pen();
@ -721,6 +858,8 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
xx = 0; yy = 0;
showSelector = (cycleCount < 20);
if ( mode == 1 )
{
w = viewWidth / 8;
@ -827,20 +966,23 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
}
}
xx = pattern->tile[ selTile.y() ][ selTile.x() ].x;
yy = pattern->tile[ selTile.y() ][ selTile.x() ].y;
if ( showSelector )
{
xx = pattern->tile[ selTile.y() ][ selTile.x() ].x;
yy = pattern->tile[ selTile.y() ][ selTile.x() ].y;
pen.setWidth( 3 );
pen.setColor( QColor( 0, 0, 0) );
painter.setPen( pen );
pen.setWidth( 3 );
pen.setColor( QColor( 0, 0, 0) );
painter.setPen( pen );
painter.drawRect( xx, yy, w*8, h*8 );
painter.drawRect( xx, yy, w*8, h*8 );
pen.setWidth( 1 );
pen.setColor( selTileColor );
painter.setPen( pen );
pen.setWidth( 1 );
pen.setColor( selTileColor );
painter.setPen( pen );
painter.drawRect( xx, yy, w*8, h*8 );
painter.drawRect( xx, yy, w*8, h*8 );
}
}
else
{
@ -885,20 +1027,23 @@ void ppuPatternView_t::paintEvent(QPaintEvent *event)
}
}
xx = pattern->tile[ selTile.y() ][ selTile.x() ].x;
yy = pattern->tile[ selTile.y() ][ selTile.x() ].y;
if ( showSelector )
{
xx = pattern->tile[ selTile.y() ][ selTile.x() ].x;
yy = pattern->tile[ selTile.y() ][ selTile.x() ].y;
pen.setWidth( 3 );
pen.setColor( QColor( 0, 0, 0) );
painter.setPen( pen );
pen.setWidth( 3 );
pen.setColor( QColor( 0, 0, 0) );
painter.setPen( pen );
painter.drawRect( xx, yy, w*8, h*8 );
painter.drawRect( xx, yy, w*8, h*8 );
pen.setWidth( 1 );
pen.setColor( selTileColor );
painter.setPen( pen );
pen.setWidth( 1 );
pen.setColor( selTileColor );
painter.setPen( pen );
painter.drawRect( xx, yy, w*8, h*8 );
painter.drawRect( xx, yy, w*8, h*8 );
}
}
}
//----------------------------------------------------

View File

@ -47,8 +47,11 @@ class ppuPatternView_t : public QWidget
ppuPatternView_t( int patternIndex, QWidget *parent = 0);
~ppuPatternView_t(void);
void updateCycleCounter(void);
void updateSelTileLabel(void);
void setPattern( ppuPatternTable_t *p );
void setTileLabel( QLabel *l );
void setTileCoord( int x, int y );
QPoint convPixToTile( QPoint p );
bool getDrawTileGrid(void){ return drawTileGrid; };
@ -65,6 +68,7 @@ class ppuPatternView_t : public QWidget
int patternIndex;
int viewWidth;
int viewHeight;
int cycleCount;
int mode;
bool drawTileGrid;
bool hover2Focus;
@ -244,10 +248,9 @@ class ppuViewerDialog_t : public QDialog
ppuViewerDialog_t(QWidget *parent = 0);
~ppuViewerDialog_t(void);
protected:
ppuPatternView_t *patternView[2];
ppuPalatteView_t *paletteView;
protected:
void closeEvent(QCloseEvent *bar);
private:
@ -275,4 +278,5 @@ class ppuViewerDialog_t : public QDialog
};
int openPPUViewWindow( QWidget *parent );
void setPPUSelPatternTile( int table, int x, int y );