Skip to content

Commit

Permalink
Qt: implement a sprite viewer window (#345)
Browse files Browse the repository at this point in the history
* Qt: begin work on a sprite viewer window

* Slight cleanup

* Attempt to make sprite bitmap rendering code more reusable

* Render sprite atlas test

* Qt: allow creating multiple sprite viewer windows.

* Qt: improve layout of the sprite viewer

* Qt: improve sprite viewer layout a bit

* Qt: set minimum width for sprite attribute group box

* Qt: cosmetic debugger UI adjustments

* Qt: improve sprite viewer layout

* Cleanup

* Move debug UI classes into a subfolder

* Deduplicate RGB565 decoding in the debugger UI
  • Loading branch information
fleroviux authored Jan 5, 2024
1 parent edcde23 commit e52f292
Show file tree
Hide file tree
Showing 20 changed files with 471 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/nba/include/nba/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct CoreBase {
virtual auto GetROM() -> ROM& = 0;
virtual auto GetPRAM() -> u8* = 0;
virtual auto GetVRAM() -> u8* = 0;
virtual auto GetOAM() -> u8* = 0;
// @todo: come up with a solution for reading write-only registers.
virtual auto PeekByteIO(u32 address) -> u8 = 0;
virtual auto PeekHalfIO(u32 address) -> u16 = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/nba/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ auto Core::GetVRAM() -> u8* {
return ppu.GetVRAM();
}

auto Core::GetOAM() -> u8* {
return ppu.GetOAM();
}

auto Core::PeekByteIO(u32 address) -> u8 {
return bus.hw.ReadByte(address);
}
Expand Down
1 change: 1 addition & 0 deletions src/nba/src/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct Core final : CoreBase {
auto GetROM() -> ROM& override;
auto GetPRAM() -> u8* override;
auto GetVRAM() -> u8* override;
auto GetOAM() -> u8* override;
auto PeekByteIO(u32 address) -> u8 override;
auto PeekHalfIO(u32 address) -> u16 override;
auto PeekWordIO(u32 address) -> u32 override;
Expand Down
4 changes: 4 additions & 0 deletions src/nba/src/hw/ppu/ppu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ struct PPU {
return vram;
}

auto GetOAM() -> u8* {
return oam;
}

template<typename T>
auto ALWAYS_INLINE ReadPRAM(u32 address) noexcept -> T {
return read<T>(pram, address & 0x3FF);
Expand Down
22 changes: 14 additions & 8 deletions src/platform/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@

include(version.cmake)

set(SOURCES
src/widget/background_viewer_window.cpp
src/widget/background_viewer.cpp
src/widget/debugger/ppu/background_viewer_window.cpp
src/widget/debugger/ppu/background_viewer.cpp
src/widget/debugger/ppu/sprite_viewer.cpp
src/widget/debugger/ppu/sprite_viewer_window.cpp
src/widget/debugger/ppu/palette_box.cpp
src/widget/debugger/ppu/palette_viewer_window.cpp
src/widget/controller_manager.cpp
src/widget/input_window.cpp
src/widget/main_window.cpp
src/widget/screen.cpp
src/widget/palette_box.cpp
src/widget/palette_viewer_window.cpp
src/config.cpp
src/main.cpp
)

set(HEADERS
src/widget/background_viewer_window.hpp
src/widget/background_viewer.hpp
src/widget/debugger/ppu/background_viewer_window.hpp
src/widget/debugger/ppu/background_viewer.hpp
src/widget/debugger/ppu/palette_box.hpp
src/widget/debugger/ppu/palette_viewer_window.hpp
src/widget/debugger/ppu/sprite_viewer.hpp
src/widget/debugger/ppu/sprite_viewer_window.hpp
src/widget/debugger/utility.hpp
src/widget/controller_manager.hpp
src/widget/input_window.hpp
src/widget/main_window.hpp
src/widget/palette_box.hpp
src/widget/palette_viewer_window.hpp
src/widget/screen.hpp
src/config.hpp
version.in.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QScrollArea>
#include <QVBoxLayout>

#include "widget/debugger/utility.hpp"
#include "background_viewer.hpp"

BackgroundViewer::BackgroundViewer(nba::CoreBase* core, QWidget* parent) : QWidget(parent), core(core) {
Expand Down Expand Up @@ -66,6 +67,7 @@ BackgroundViewer::BackgroundViewer(nba::CoreBase* core, QWidget* parent) : QWidg
const auto group_box = new QGroupBox{};
group_box->setLayout(grid);
group_box->setTitle(tr("Background"));
group_box->setMinimumWidth(220);

info_vbox->addWidget(group_box);
}
Expand Down Expand Up @@ -100,6 +102,7 @@ BackgroundViewer::BackgroundViewer(nba::CoreBase* core, QWidget* parent) : QWidg
const auto group_box = new QGroupBox{};
group_box->setLayout(grid);
group_box->setTitle(tr("Tile"));
group_box->setMinimumWidth(220);

info_vbox->addWidget(group_box);

Expand Down Expand Up @@ -431,14 +434,7 @@ void BackgroundViewer::PresentBackground() {

for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
const u16 color_rgb565 = image_rgb565[i];

// @todo: de-duplicate the RGB565 to RGB32 conversion.
const int r = (color_rgb565 >> 0) & 31;
const int g = ((color_rgb565 >> 4) & 62) | (color_rgb565 >> 15);
const int b = (color_rgb565 >> 10) & 31;

destination[i++] = 0xFF000000 | (r << 3 | r >> 2) << 16 | (g << 2 | g >> 4) << 8 | (b << 3 | b >> 2);
destination[i++] = Rgb565ToArgb8888(image_rgb565[i]);
}

i += skip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <QLabel>
#include <QPainter>

#include "widget/palette_box.hpp"
#include "palette_box.hpp"

struct BackgroundViewer : QWidget {
BackgroundViewer(nba::CoreBase* core, QWidget* parent = nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <QDialog>
#include <QTabWidget>

#include "widget/background_viewer.hpp"
#include "background_viewer.hpp"

struct BackgroundViewerWindow : QDialog {
BackgroundViewerWindow(nba::CoreBase* core, QWidget* parent = nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstring>
#include <QPainter>

#include "widget/debugger/utility.hpp"
#include "palette_box.hpp"

PaletteBox::PaletteBox(int rows, int columns, QWidget* parent) : QWidget(parent), rows(rows), columns(columns) {
Expand All @@ -27,13 +28,7 @@ void PaletteBox::Draw(u16* palette_rgb565, int stride) {

for(int y = 0; y < rows; y++) {
for(int x = 0; x < columns; x++) {
const u16 color_rgb565 = palette_rgb565[y * stride + x];

const int r = (color_rgb565 >> 0) & 31;
const int g = ((color_rgb565 >> 4) & 62) | (color_rgb565 >> 15);
const int b = (color_rgb565 >> 10) & 31;

palette_argb8888[i++] = 0xFF000000 | (r << 3 | r >> 2) << 16 | (g << 2 | g >> 4) << 8 | (b << 3 | b >> 2);
palette_argb8888[i++] = Rgb565ToArgb8888(palette_rgb565[y * stride + x]);
}
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <QDialog>
#include <QLabel>

#include "widget/palette_box.hpp"
#include "palette_box.hpp"

struct PaletteViewerWindow : QDialog {
PaletteViewerWindow(nba::CoreBase* core, QWidget* parent = nullptr);
Expand Down
Loading

0 comments on commit e52f292

Please sign in to comment.