Skip to content

Commit

Permalink
Merge pull request #37 from Kautenja/ntsc
Browse files Browse the repository at this point in the history
NTSC emulation
  • Loading branch information
Kautenja committed Jul 2, 2020
2 parents 80f0a33 + 3468525 commit 724dc69
Show file tree
Hide file tree
Showing 15 changed files with 1,300 additions and 118 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@
### 1.2.0 (2020-07-01)

- mixer (individual channel outputs + mix output)

### 1.3.0 (2020-07-02)

- NTSC emulation
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SOURCES += $(wildcard src/*.cpp)
SOURCES += $(wildcard src/nes/*.cpp)
SOURCES += $(wildcard src/nes/mappers/*.cpp)
SOURCES += $(wildcard src/nes/apu/*.cpp)
SOURCES += $(wildcard src/nes/ntsc/*.c)

DISTRIBUTABLES += $(wildcard LICENSE*) res

Expand Down
2 changes: 1 addition & 1 deletion manual/manual.tex
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
\setlength{\headheight}{15pt}
\pagestyle{fancy}
\lhead{KautenjaDSP}
\rhead{\itshape RackNES v1.2.0}
\rhead{\itshape RackNES v1.3.0}
\cfoot{\thepage}

% start the document
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"slug": "KautenjaDSP-RackNES",
"version": "1.2.0",
"version": "1.3.0",
"license": "GPL-3.0-or-later",
"name": "KautenjaDSP RackNES",
"brand": "KautenjaDSP",
Expand Down
29 changes: 20 additions & 9 deletions src/RackNES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ struct RackNES : Module {
/// A widget that displays a 32-bit RGBA pixel buffer.
struct Display : TransparentWidget {
private:
/// the size of the internal pixel buffer to render
const Vec image_size;
/// a pointer to the pixels to render
const uint8_t* pixels;
/// a pointer to the image to draw the display to
Expand All @@ -369,12 +371,18 @@ struct Display : TransparentWidget {
///
/// @param position the position of the screen on the module
/// @param pixels_ the pixels on the display to render
/// @param size the size of the screen
/// @param image_size the size of the input image
/// @param render_size the output size of the display to render
///
explicit Display(Vec position, const uint8_t* pixels_, Vec size) :
TransparentWidget(), pixels(pixels_) {
explicit Display(
Vec position,
const uint8_t* pixels_,
Vec image_size_,
Vec render_size
) :
TransparentWidget(), image_size(image_size_), pixels(pixels_) {
setPosition(position);
setSize(size);
setSize(render_size);
}

/// @brief Draw the display on the main context.
Expand All @@ -386,17 +394,19 @@ struct Display : TransparentWidget {
static constexpr int x = 0;
// the y position of the screen
static constexpr int y = 0;
// the alpha value of the SVG image
static constexpr float alpha = 1.f;
// don't do anything if the screen is not on
if (!is_on) return;
// return if the pixels aren't on the screen yet
if (pixels == nullptr) return;
// draw the screen
if (screen == -1) // check if the screen has been initialized yet
screen = nvgCreateImageRGBA(args.vg, box.size.x, box.size.y, 0, pixels);
screen = nvgCreateImageRGBA(args.vg, image_size.x, image_size.y, 0, pixels);
else // update the screen with the pixel data
nvgUpdateImage(args.vg, screen, pixels);
// get the screen as a fill paint (for a rectangle)
auto imgPaint = nvgImagePattern(args.vg, x, y, box.size.x, box.size.y, 0, screen, 1.0f);
auto imgPaint = nvgImagePattern(args.vg, x, y, box.size.x, box.size.y, 0, screen, alpha);
// create a path for the rectangle to show the screen
nvgBeginPath(args.vg);
// create a rectangle to draw the screen
Expand Down Expand Up @@ -445,9 +455,10 @@ struct RackNESWidget : ModuleWidget {
setPanel(APP->window->loadSvg(asset::plugin(plugin_instance, panel)));
// setup the display for the NES screen
display = new Display(
Vec(157, 18), // screen position
static_cast<RackNES*>(module)->screen, // pixel buffer
Vec(NES::Emulator::WIDTH, NES::Emulator::HEIGHT) // screen size
Vec(157, 18), // screen position
static_cast<RackNES*>(module)->screen, // pixel buffer
Vec(NES::Emulator::WIDTH, NES::Emulator::HEIGHT), // buffer size
Vec(NES::Emulator::WIDTH_NES, NES::Emulator::HEIGHT) // image size
);
addChild(display);
// panel screws
Expand Down
12 changes: 7 additions & 5 deletions src/nes/emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ class Emulator {
APU apu;

public:
/// The width of the NES screen in pixels
static const int WIDTH = SCANLINE_VISIBLE_DOTS;
/// The width of the NES screen in pixels (after NTSC filtering)
static constexpr int WIDTH = SCANLINE_VISIBLE_DOTS_NTSC;
/// The height of the NES screen in pixels
static const int HEIGHT = VISIBLE_SCANLINES;
static constexpr int HEIGHT = VISIBLE_SCANLINES;
/// the number of pixels on the NES
static const int PIXELS = WIDTH * HEIGHT;
static constexpr int PIXELS = WIDTH * HEIGHT;
/// the number of bytes in the screen (RGBx)
static const int SCREEN_BYTES = PIXELS * 4;
static constexpr int SCREEN_BYTES = PIXELS * sizeof(NES_Pixel);
/// The width of the NES screen in pixels
static constexpr int WIDTH_NES = SCANLINE_VISIBLE_DOTS;

/// @brief Initialize a new emulator.
Emulator() {
Expand Down
Loading

0 comments on commit 724dc69

Please sign in to comment.