Hooked up sprite info data fields.

This commit is contained in:
mjbudd77 2021-04-16 14:42:39 -04:00
parent 369459ba63
commit 3613a7da4e
2 changed files with 396 additions and 43 deletions

View File

@ -1341,6 +1341,8 @@ static void drawSpriteTable(void)
{ {
spr = &oamPattern.sprite[i]; spr = &oamPattern.sprite[i];
spr->y = (oam[j]);
spr->x = (oam[j+3]);
spr->pal = (oam[j+2] & 0x03) | 0x04; spr->pal = (oam[j+2] & 0x03) | 0x04;
spr->pri = (oam[j+2] & 0x20) ? 1 : 0; spr->pri = (oam[j+2] & 0x20) ? 1 : 0;
spr->hFlip = (oam[j+2] & 0x40) ? 1 : 0; spr->hFlip = (oam[j+2] & 0x40) ? 1 : 0;
@ -2529,15 +2531,15 @@ spriteViewerDialog_t::spriteViewerDialog_t(QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
QMenuBar *menuBar; QMenuBar *menuBar;
QVBoxLayout *mainLayout, *vbox, *vbox1; QVBoxLayout *mainLayout, *vbox, *vbox1, *vbox2, *vbox3, *vbox4;
QHBoxLayout *hbox, *hbox1; QHBoxLayout *hbox, *hbox1, *hbox2;
QGridLayout *infoGrid, *grid; QGridLayout *infoGrid;
QGroupBox *frame; QGroupBox *frame;
QLabel *lbl; QLabel *lbl;
QActionGroup *group; //QActionGroup *group;
QMenu *fileMenu, *viewMenu, *colorMenu, *optMenu, *subMenu; //QMenu *fileMenu, *viewMenu, *colorMenu, *optMenu, *subMenu;
QAction *act; //QAction *act;
char stmp[64]; //char stmp[64];
int useNativeMenuBar; int useNativeMenuBar;
spriteViewWindow = this; spriteViewWindow = this;
@ -2565,71 +2567,107 @@ spriteViewerDialog_t::spriteViewerDialog_t(QWidget *parent)
mainLayout->addLayout( hbox1 ); mainLayout->addLayout( hbox1 );
vbox1 = new QVBoxLayout(); vbox1 = new QVBoxLayout();
hbox1->addLayout( vbox1 ); vbox2 = new QVBoxLayout();
hbox1->addLayout( vbox1, 1);
hbox = new QHBoxLayout(); hbox = new QHBoxLayout();
vbox1->addLayout( hbox ); vbox1->addLayout( hbox );
useSprRam = new QRadioButton( tr("Sprite RAM") ); useSprRam = new QRadioButton( tr("Sprite RAM") );
useCpuPag = new QRadioButton( tr("CPU Page #") ); useCpuPag = new QRadioButton( tr("CPU Page #") );
cpuPagIdx = new QSpinBox(this);
useSprRam->setChecked(true);
useSprRam->setEnabled(false); // TODO Implement CPU paging option
cpuPagIdx->setEnabled(false);
useCpuPag->setEnabled(false);
hbox->addWidget( new QLabel( tr("Data Source:") ) ); hbox->addWidget( new QLabel( tr("Data Source:") ) );
hbox->addWidget( useSprRam ); hbox->addWidget( useSprRam );
hbox->addWidget( useCpuPag ); hbox->addWidget( useCpuPag );
hbox->addWidget( cpuPagIdx );
frame = new QGroupBox( tr("Sprite Info") ); frame = new QGroupBox( tr("Sprite Info") );
infoGrid = new QGridLayout(); infoGrid = new QGridLayout();
vbox1->addWidget( frame ); vbox1->addWidget( frame );
frame->setLayout( infoGrid ); frame->setLayout( vbox2 );
//vbox2->addLayout( infoGrid );
lbl = new QLabel( tr("Sprite Index:") ); lbl = new QLabel( tr("Sprite Index:") );
spriteIndexBox = new QLineEdit(); spriteIndexBox = new QLineEdit();
spriteIndexBox->setReadOnly(true);
infoGrid->addWidget( lbl, 0, 0 ); infoGrid->addWidget( lbl, 0, 0 );
infoGrid->addWidget( spriteIndexBox, 0, 1 ); infoGrid->addWidget( spriteIndexBox, 0, 1 );
lbl = new QLabel( tr("Tile Address:") ); lbl = new QLabel( tr("Tile Address:") );
tileAddrBox = new QLineEdit(); tileAddrBox = new QLineEdit();
infoGrid->addWidget( lbl, 0, 2 ); tileAddrBox->setReadOnly(true);
infoGrid->addWidget( tileAddrBox, 0, 3 ); infoGrid->addWidget( lbl, 1, 0 );
infoGrid->addWidget( tileAddrBox, 1, 1 );
lbl = new QLabel( tr("Tile Index:") ); lbl = new QLabel( tr("Tile Index:") );
tileIndexBox = new QLineEdit(); tileIndexBox = new QLineEdit();
infoGrid->addWidget( lbl, 1, 0 ); tileIndexBox->setReadOnly(true);
infoGrid->addWidget( tileIndexBox, 1, 1 ); infoGrid->addWidget( lbl, 2, 0 );
infoGrid->addWidget( tileIndexBox, 2, 1 );
lbl = new QLabel( tr("Palette Address:") ); lbl = new QLabel( tr("Palette Address:") );
palAddrBox = new QLineEdit(); palAddrBox = new QLineEdit();
infoGrid->addWidget( lbl, 1, 2 ); palAddrBox->setReadOnly(true);
infoGrid->addWidget( palAddrBox, 1, 3 ); infoGrid->addWidget( lbl, 3, 0 );
infoGrid->addWidget( palAddrBox, 3, 1 );
lbl = new QLabel( tr("Tile:") ); hbox2 = new QHBoxLayout();
//tileIndexBox = new QLineEdit(); vbox3 = new QVBoxLayout();
infoGrid->addWidget( lbl, 2, 0, 5, 1, Qt::AlignTop ); frame = new QGroupBox( tr("Tile:") );
//infoGrid->addWidget( tileIndexBox, 2, 1 ); vbox = new QVBoxLayout();
tileView = new oamTileView_t(this);
frame->setLayout( vbox );
vbox->addWidget( tileView );
vbox2->addLayout( hbox2 );
vbox3->addWidget( frame, 4 );
hbox2->addLayout( vbox3, 1 );
lbl = new QLabel( tr("Palette:") ); frame = new QGroupBox( tr("Palette:") );
//tileIndexBox = new QLineEdit(); vbox = new QVBoxLayout();
infoGrid->addWidget( lbl, 2, 2, Qt::AlignTop ); vbox4 = new QVBoxLayout();
//infoGrid->addWidget( tileIndexBox, 2, 1 ); vbox4->addLayout( infoGrid );
hbox2->addLayout( vbox4, 1 );
frame->setLayout( vbox );
palView = new oamPaletteView_t(this);
vbox->addWidget( palView );
vbox3->addWidget( frame, 1 );
//infoGrid->addWidget( frame, 2, 2, 1, 2, Qt::AlignTop );
lbl = new QLabel( tr("Position (X,Y):") ); lbl = new QLabel( tr("Position (X,Y):") );
//tileIndexBox = new QLineEdit(); posBox = new QLineEdit();
infoGrid->addWidget( lbl, 3, 2, Qt::AlignTop ); hbox = new QHBoxLayout();
//infoGrid->addWidget( tileIndexBox, 2, 1 ); posBox->setReadOnly(true);
vbox4->addLayout( hbox, 1 );
hbox->addWidget( lbl );
hbox->addWidget( posBox );
hFlipBox = new QCheckBox( tr("Horizontal Flip") ); hFlipBox = new QCheckBox( tr("Horizontal Flip") );
infoGrid->addWidget( hFlipBox, 4, 2, 1, 2 ); hFlipBox->setFocusPolicy(Qt::NoFocus);
vbox4->addWidget( hFlipBox, 1 );
vFlipBox = new QCheckBox( tr("Vertical Flip") ); vFlipBox = new QCheckBox( tr("Vertical Flip") );
infoGrid->addWidget( vFlipBox, 5, 2, 1, 2 ); vFlipBox->setFocusPolicy(Qt::NoFocus);
vbox4->addWidget( vFlipBox, 1 );
bgPrioBox = new QCheckBox( tr("Background Priority") ); bgPrioBox = new QCheckBox( tr("Background Priority") );
infoGrid->addWidget( bgPrioBox, 6, 2, 1, 2 ); bgPrioBox->setFocusPolicy(Qt::NoFocus);
vbox4->addWidget( bgPrioBox, 1 );
vbox4->addStretch(10);
frame = new QGroupBox( tr("Preview:") );
vbox = new QVBoxLayout();
preView = new oamPreview_t(this);
frame->setLayout( vbox );
hbox1->addWidget( frame );
vbox->addWidget( preView );
lbl = new QLabel( tr("Preview:") );
//tileIndexBox = new QLineEdit();
infoGrid->addWidget( lbl, 7, 0 );
//infoGrid->addWidget( tileIndexBox, 2, 1 );
updateTimer = new QTimer( this ); updateTimer = new QTimer( this );
@ -2640,7 +2678,10 @@ spriteViewerDialog_t::spriteViewerDialog_t(QWidget *parent)
//---------------------------------------------------- //----------------------------------------------------
spriteViewerDialog_t::~spriteViewerDialog_t(void) spriteViewerDialog_t::~spriteViewerDialog_t(void)
{ {
if ( this == spriteViewWindow )
{
spriteViewWindow = NULL;
}
} }
//---------------------------------------------------- //----------------------------------------------------
void spriteViewerDialog_t::closeEvent(QCloseEvent *event) void spriteViewerDialog_t::closeEvent(QCloseEvent *event)
@ -2660,7 +2701,38 @@ void spriteViewerDialog_t::closeWindow(void)
//---------------------------------------------------- //----------------------------------------------------
void spriteViewerDialog_t::periodicUpdate(void) void spriteViewerDialog_t::periodicUpdate(void)
{ {
int idx;
char stmp[32];
idx = oamView->getSpriteIndex();
sprintf( stmp, "$%02X", idx );
spriteIndexBox->setText( tr(stmp) );
sprintf( stmp, "$%02X", oamPattern.sprite[idx].tNum );
tileIndexBox->setText( tr(stmp) );
sprintf( stmp, "$%04X", oamPattern.sprite[idx].chrAddr );
tileAddrBox->setText( tr(stmp) );
sprintf( stmp, "$%04X", 0x3F00 + (oamPattern.sprite[idx].pal*4) );
palAddrBox->setText( tr(stmp) );
sprintf( stmp, "%i,%i", oamPattern.sprite[idx].x, oamPattern.sprite[idx].y );
posBox->setText( tr(stmp) );
hFlipBox->setChecked( oamPattern.sprite[idx].hFlip );
vFlipBox->setChecked( oamPattern.sprite[idx].vFlip );
bgPrioBox->setChecked( oamPattern.sprite[idx].pri );
tileView->setIndex(idx);
tileView->setIndex(idx);
palView->setIndex(idx);
oamView->update(); oamView->update();
tileView->update();
palView->update();
preView->update();
} }
//---------------------------------------------------- //----------------------------------------------------
//-- OAM Pattern Viewer //-- OAM Pattern Viewer
@ -2680,14 +2752,21 @@ oamPatternView_t::oamPatternView_t( QWidget *parent )
//gridColor.setRgb(128,128,128); //gridColor.setRgb(128,128,128);
selSpriteBoxColor.setRgb(255,0,0); selSpriteBoxColor.setRgb(255,0,0);
selSprite.setX(-1); selSprite.setX(0);
selSprite.setY(-1); selSprite.setY(0);
spriteIdx = -1; spriteIdx = 0;
} }
//---------------------------------------------------- //----------------------------------------------------
oamPatternView_t::~oamPatternView_t(void) oamPatternView_t::~oamPatternView_t(void)
{ {
}
//----------------------------------------------------
int oamPatternView_t::getSpriteIndex(void){ return spriteIdx; }
//----------------------------------------------------
int oamPatternView_t::heightForWidth(int w) const
{
return 2*w;
} }
//---------------------------------------------------- //----------------------------------------------------
void oamPatternView_t::resizeEvent(QResizeEvent *event) void oamPatternView_t::resizeEvent(QResizeEvent *event)
@ -2735,7 +2814,7 @@ void oamPatternView_t::mouseMoveEvent(QMouseEvent *event)
{ {
selSprite = tile; selSprite = tile;
spriteIdx = tile.y()*8 + tile.x(); spriteIdx = tile.y()*8 + tile.x();
printf("Tile: (%i,%i) = %i \n", tile.x(), tile.y(), tile.y()*8 + tile.x() ); //printf("Tile: (%i,%i) = %i \n", tile.x(), tile.y(), tile.y()*8 + tile.x() );
} }
} }
@ -2764,7 +2843,7 @@ void oamPatternView_t::contextMenuEvent(QContextMenuEvent *event)
QMenu menu(this); QMenu menu(this);
//QMenu *subMenu; //QMenu *subMenu;
//QActionGroup *group; //QActionGroup *group;
char stmp[64]; //char stmp[64];
act = new QAction(tr("Open Tile &Editor"), &menu); act = new QAction(tr("Open Tile &Editor"), &menu);
act->setShortcut( QKeySequence(tr("E"))); act->setShortcut( QKeySequence(tr("E")));
@ -2776,7 +2855,7 @@ void oamPatternView_t::contextMenuEvent(QContextMenuEvent *event)
//---------------------------------------------------- //----------------------------------------------------
void oamPatternView_t::paintEvent(QPaintEvent *event) void oamPatternView_t::paintEvent(QPaintEvent *event)
{ {
int i,j,x,y,w,h,xx,yy,ii,jj,rr; int i,j,x,y,w,h,xx,yy,ii,jj;
QPainter painter(this); QPainter painter(this);
QPen pen; QPen pen;
//char showSelector; //char showSelector;
@ -2845,3 +2924,209 @@ void oamPatternView_t::paintEvent(QPaintEvent *event)
} }
} }
//---------------------------------------------------- //----------------------------------------------------
//-- OAM Tile View
//----------------------------------------------------
oamTileView_t::oamTileView_t(QWidget *parent)
: QWidget(parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
viewWidth = 8;
viewHeight = 16;
setMinimumWidth( viewWidth );
setMinimumHeight( viewHeight );
spriteIdx = 0;
}
//----------------------------------------------------
oamTileView_t::~oamTileView_t(void)
{
}
//----------------------------------------------------
void oamTileView_t::setIndex( int val )
{
spriteIdx = val;
}
//----------------------------------------------------
int oamTileView_t::heightForWidth(int w) const
{
return 2*w;
}
//----------------------------------------------------
void oamTileView_t::resizeEvent(QResizeEvent *event)
{
viewWidth = event->size().width();
viewHeight = event->size().height();
}
//----------------------------------------------------
void oamTileView_t::paintEvent(QPaintEvent *event)
{
int j,x,y,w,h,xx,yy;
QPainter painter(this);
//QPen pen;
//char showSelector;
//pen = painter.pen();
viewWidth = event->rect().width();
viewHeight = event->rect().height();
w = viewWidth / 8;
h = viewHeight / 16;
if ( w < h )
{
h = w;
}
else
{
w = h;
}
yy = 0;
for (j=0; j<2; j++)
{
for (y=0; y<8; y++)
{
xx = 0;
for (x=0; x < 8; x++)
{
painter.fillRect( xx, yy, w, h, oamPattern.sprite[ spriteIdx ].tile[j].pixel[y][x].color );
xx += w;
}
yy += h;
}
}
}
//----------------------------------------------------
//-- OAM Palette View
//----------------------------------------------------
oamPaletteView_t::oamPaletteView_t(QWidget *parent)
: QWidget(parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
viewHeight = 32;
viewWidth = viewHeight*4;
setMinimumWidth( viewWidth );
setMinimumHeight( viewHeight );
palIdx = 0;
}
//----------------------------------------------------
oamPaletteView_t::~oamPaletteView_t(void)
{
}
//----------------------------------------------------
void oamPaletteView_t::setIndex( int val )
{
palIdx = oamPattern.sprite[val].pal;
}
//----------------------------------------------------
int oamPaletteView_t::heightForWidth(int w) const
{
return w/4;
}
//----------------------------------------------------
void oamPaletteView_t::resizeEvent(QResizeEvent *event)
{
viewWidth = event->size().width();
viewHeight = event->size().height();
}
//----------------------------------------------------
void oamPaletteView_t::paintEvent(QPaintEvent *event)
{
int x,w,h,xx,yy,p,p2;
QPainter painter(this);
QColor color;
//QPen pen;
//char showSelector;
//pen = painter.pen();
viewWidth = event->rect().width();
viewHeight = event->rect().height();
w = viewWidth / 4;
h = viewHeight;
if ( w < h )
{
h = w;
}
else
{
w = h;
}
p2 = palIdx * 4;
yy = 0;
xx = 0;
for (x=0; x < 4; x++)
{
p = palcache[p2 | x];
color.setBlue( palo[p].b );
color.setGreen( palo[p].g );
color.setRed( palo[p].r );
painter.fillRect( xx, yy, w, h, color );
xx += w;
}
}
//----------------------------------------------------
//-- OAM Preview
//----------------------------------------------------
oamPreview_t::oamPreview_t(QWidget *parent)
: QWidget(parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
viewHeight = 240;
viewWidth = 256;
setMinimumWidth( viewWidth );
setMinimumHeight( viewHeight );
}
//----------------------------------------------------
oamPreview_t::~oamPreview_t(void)
{
}
//----------------------------------------------------
int oamPreview_t::heightForWidth(int w) const
{
return ((w*256)/240);
}
//----------------------------------------------------
void oamPreview_t::resizeEvent(QResizeEvent *event)
{
viewWidth = event->size().width();
viewHeight = event->size().height();
}
//----------------------------------------------------
void oamPreview_t::paintEvent(QPaintEvent *event)
{
int w,h;
QPainter painter(this);
//QColor color;
//QPen pen;
//char showSelector;
//pen = painter.pen();
viewWidth = event->rect().width();
viewHeight = event->rect().height();
w = viewWidth / 256;
h = viewHeight / 240;
if ( w < h )
{
h = w;
}
else
{
w = h;
}
}
//----------------------------------------------------

View File

@ -15,6 +15,7 @@
#include <QFrame> #include <QFrame>
#include <QTimer> #include <QTimer>
#include <QSlider> #include <QSlider>
#include <QSpinBox>
#include <QLineEdit> #include <QLineEdit>
#include <QGroupBox> #include <QGroupBox>
#include <QCloseEvent> #include <QCloseEvent>
@ -291,9 +292,6 @@ struct oamSpriteData_t
char val; char val;
} pixel[8][8]; } pixel[8][8];
int x;
int y;
} tile[2]; } tile[2];
uint8_t tNum; uint8_t tNum;
@ -303,6 +301,9 @@ struct oamSpriteData_t
uint8_t hFlip; uint8_t hFlip;
uint8_t vFlip; uint8_t vFlip;
int chrAddr; int chrAddr;
int x;
int y;
}; };
struct oamPatternTable_t struct oamPatternTable_t
@ -323,6 +324,8 @@ class oamPatternView_t : public QWidget
~oamPatternView_t(void); ~oamPatternView_t(void);
QPoint convPixToTile( QPoint p ); QPoint convPixToTile( QPoint p );
int getSpriteIndex(void);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
@ -330,6 +333,7 @@ class oamPatternView_t : public QWidget
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent * event); void mousePressEvent(QMouseEvent * event);
void contextMenuEvent(QContextMenuEvent *event); void contextMenuEvent(QContextMenuEvent *event);
int heightForWidth(int w) const;
int viewWidth; int viewWidth;
int viewHeight; int viewHeight;
@ -343,6 +347,64 @@ class oamPatternView_t : public QWidget
}; };
class oamTileView_t : public QWidget
{
Q_OBJECT
public:
oamTileView_t( QWidget *parent = 0);
~oamTileView_t(void);
void setIndex( int val );
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
int heightForWidth(int w) const;
private:
int viewWidth;
int viewHeight;
int spriteIdx;
};
class oamPaletteView_t : public QWidget
{
Q_OBJECT
public:
oamPaletteView_t( QWidget *parent = 0);
~oamPaletteView_t(void);
void setIndex( int val );
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
int heightForWidth(int w) const;
private:
int viewWidth;
int viewHeight;
int palIdx;
};
class oamPreview_t : public QWidget
{
Q_OBJECT
public:
oamPreview_t( QWidget *parent = 0);
~oamPreview_t(void);
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
int heightForWidth(int w) const;
private:
int viewWidth;
int viewHeight;
};
class spriteViewerDialog_t : public QDialog class spriteViewerDialog_t : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -352,6 +414,10 @@ class spriteViewerDialog_t : public QDialog
~spriteViewerDialog_t(void); ~spriteViewerDialog_t(void);
oamPatternView_t *oamView; oamPatternView_t *oamView;
oamPaletteView_t *palView;
oamTileView_t *tileView;
oamPreview_t *preView;
protected: protected:
void closeEvent(QCloseEvent *bar); void closeEvent(QCloseEvent *bar);
@ -359,10 +425,12 @@ class spriteViewerDialog_t : public QDialog
QTimer *updateTimer; QTimer *updateTimer;
QRadioButton *useSprRam; QRadioButton *useSprRam;
QRadioButton *useCpuPag; QRadioButton *useCpuPag;
QSpinBox *cpuPagIdx;
QLineEdit *spriteIndexBox; QLineEdit *spriteIndexBox;
QLineEdit *tileIndexBox; QLineEdit *tileIndexBox;
QLineEdit *tileAddrBox; QLineEdit *tileAddrBox;
QLineEdit *palAddrBox; QLineEdit *palAddrBox;
QLineEdit *posBox;
QCheckBox *hFlipBox; QCheckBox *hFlipBox;
QCheckBox *vFlipBox; QCheckBox *vFlipBox;
QCheckBox *bgPrioBox; QCheckBox *bgPrioBox;