-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract video debugger from Debugger class into its own class. Add fi…
…le with the NES color palette in RGB. Display the NES Palette in the video debugger
- Loading branch information
Showing
9 changed files
with
225 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "VideoDebugger.h" | ||
|
||
#include "ImguiWrapper/imgui_impl_glfw_gl3.h" | ||
#include "../Video.h" | ||
#include "../PaletteColors.h" | ||
|
||
|
||
VideoDebugger::~VideoDebugger() | ||
{ | ||
delete leftPatternTableBuffer; | ||
delete rightPatternTableBuffer; | ||
delete nesPaletteTextureBuffer; | ||
} | ||
|
||
void VideoDebugger::CreateTextures() | ||
{ | ||
leftPatternTableBuffer = new RGB[ 128 * 128 ]; | ||
ImGuiGLFW::Texture leftPatternTexture = { 0, 128, 128, leftPatternTableBuffer }; | ||
leftPatternTableTextureID = ImGuiGLFW::CreateTexture( leftPatternTexture ); | ||
|
||
rightPatternTableBuffer = new RGB[ 128 * 128 ]; | ||
ImGuiGLFW::Texture rightPatternTexture = { 0, 128, 128, rightPatternTableBuffer }; | ||
rightPatternTableTextureID = ImGuiGLFW::CreateTexture( rightPatternTexture ); | ||
|
||
nesPaletteTextureBuffer = new RGB[ 64 ]; | ||
ImGuiGLFW::Texture paletteTexture = { 0, 16, 4, nesPaletteTextureBuffer }; | ||
nesPaletteTextureID = ImGuiGLFW::CreateTexture( paletteTexture ); | ||
GenerateNesPaletteTexture(); | ||
} | ||
|
||
void VideoDebugger::ComposeView( u32 cycles, Video &video ) | ||
{ | ||
UpdatePatternTable( video, 0x0000, leftPatternTableBuffer ); | ||
ImGui::SetNextWindowSize( ImVec2( 560, 560 ), ImGuiCond_FirstUseEver ); | ||
ImGui::Begin( "VRAM Left" ); | ||
ImGui::Image( leftPatternTableTextureID, ImVec2( 512, 512 ) ); | ||
ImGui::End(); | ||
|
||
UpdatePatternTable( video, 0x1000, rightPatternTableBuffer ); | ||
ImGui::SetNextWindowSize( ImVec2( 560, 560 ), ImGuiCond_FirstUseEver ); | ||
ImGui::Begin( "VRAM Right" ); | ||
ImGui::Image( rightPatternTableTextureID, ImVec2( 512, 512 ) ); | ||
ImGui::End(); | ||
|
||
ImGui::SetNextWindowSize( ImVec2( 260, 70 ), ImGuiCond_FirstUseEver ); | ||
ImGui::Begin( "NES Palette" ); | ||
ImGui::Image( nesPaletteTextureID, ImVec2( 256, 64 ) ); | ||
ImGui::End(); | ||
} | ||
|
||
void VideoDebugger::UpdatePatternTable( Video &video, word address, RGB *buffer ) | ||
{ | ||
constexpr static RGB palette[4] = { { 255,255,255 },{ 0xCC,0xCC,0xCC },{ 0x77,0x77,0x77 }, { 0x0,0x0,0x0 } }; | ||
|
||
const byte * const ppuMemory = video.GetPPUMemory(); | ||
assert( buffer != nullptr ); | ||
assert( ppuMemory != nullptr ); | ||
|
||
u32 vramPosition = 0; | ||
for ( u32 tile = 0; tile < 256; ++tile ) | ||
{ | ||
const u32 tileAddress = (tile * 0x10) + address; | ||
|
||
u32 localvramPosition = vramPosition; | ||
for ( byte row = 0; row < 8; ++row ) | ||
{ | ||
const byte firstByte = ppuMemory[ tileAddress + row ]; | ||
const byte secondByte = ppuMemory[ tileAddress + row + 0x07 ]; | ||
|
||
for ( byte column = 0; column < 8; ++column) | ||
{ | ||
byte mask = 0x01 << column; | ||
const byte value = ((secondByte & mask) >> column) << 1; | ||
const byte value2 = (firstByte & mask) >> column; | ||
const byte finalValue = value | value2; | ||
|
||
buffer[ localvramPosition + (7 - column) ] = palette[ finalValue ]; | ||
} | ||
localvramPosition += 128; | ||
} | ||
vramPosition += 8; | ||
|
||
if ( tile > 0 && (tile + 1) % 16 == 0) | ||
{ | ||
vramPosition += 128 * 7; | ||
} | ||
} | ||
} | ||
|
||
void VideoDebugger::GenerateNesPaletteTexture() | ||
{ | ||
for ( byte color = 0; color < 64; ++color ) | ||
{ | ||
nesPaletteTextureBuffer[ color ] = NES_PALETTE_COLORS[ color ]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "../Types.h" | ||
|
||
class Video; | ||
|
||
class VideoDebugger | ||
{ | ||
public: | ||
VideoDebugger() = default; | ||
~VideoDebugger(); | ||
|
||
void CreateTextures(); | ||
void ComposeView( u32 cycles, Video &video ); | ||
|
||
private: | ||
using ImTextureID = void *; | ||
|
||
/* Textures */ | ||
ImTextureID leftPatternTableTextureID; | ||
RGB *leftPatternTableBuffer; | ||
|
||
ImTextureID rightPatternTableTextureID; | ||
RGB *rightPatternTableBuffer; | ||
|
||
ImTextureID nesPaletteTextureID; | ||
RGB *nesPaletteTextureBuffer; | ||
|
||
|
||
void UpdatePatternTable( Video &video, word address, RGB *buffer ); | ||
void GenerateNesPaletteTexture(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include "Types.h" | ||
|
||
static constexpr std::array< RGB, 64 > NES_PALETTE_COLORS = | ||
{ | ||
{ | ||
{ 0x7C, 0x7C, 0x7C }, | ||
{ 0x00, 0x00, 0xFC }, | ||
{ 0x00, 0x00, 0xBC }, | ||
{ 0x44, 0x28, 0xBC }, | ||
{ 0x94, 0x00, 0x84 }, | ||
{ 0xA8, 0x00, 0x20 }, | ||
{ 0xA8, 0x10, 0x00 }, | ||
{ 0x88, 0x14, 0x00 }, | ||
{ 0x50, 0x30, 0x00 }, | ||
{ 0x00, 0x78, 0x00 }, | ||
{ 0x00, 0x68, 0x00 }, | ||
{ 0x00, 0x58, 0x00 }, | ||
{ 0x00, 0x40, 0x58 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
|
||
{ 0xBC, 0xBC, 0xBC }, | ||
{ 0x00, 0x78, 0xF8 }, | ||
{ 0x00, 0x58, 0xF8 }, | ||
{ 0x68, 0x44, 0xFC }, | ||
{ 0xD8, 0x00, 0xCC }, | ||
{ 0xE4, 0x00, 0x58 }, | ||
{ 0xF8, 0x38, 0x00 }, | ||
{ 0xE4, 0x5C, 0x10 }, | ||
{ 0xAC, 0x7C, 0x00 }, | ||
{ 0x00, 0xB8, 0x00 }, | ||
{ 0x00, 0xA8, 0x00 }, | ||
{ 0x00, 0xA8, 0x44 }, | ||
{ 0x00, 0x88, 0x88 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
|
||
{ 0xF8, 0xF8, 0xF8 }, | ||
{ 0x3C, 0xBC, 0xFC }, | ||
{ 0x68, 0x88, 0xFC }, | ||
{ 0x98, 0x78, 0xF8 }, | ||
{ 0xF8, 0x78, 0xF8 }, | ||
{ 0xF8, 0x58, 0x98 }, | ||
{ 0xF8, 0x78, 0x58 }, | ||
{ 0xFC, 0xA0, 0x44 }, | ||
{ 0xF8, 0xB8, 0x00 }, | ||
{ 0xB8, 0xF8, 0x18 }, | ||
{ 0x58, 0xD8, 0x54 }, | ||
{ 0x58, 0xF8, 0x98 }, | ||
{ 0x00, 0xE8, 0xD8 }, | ||
{ 0x78, 0x78, 0x78 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
|
||
{ 0xFC, 0xFC, 0xFC }, | ||
{ 0xA4, 0xE4, 0xFC }, | ||
{ 0xB8, 0xB8, 0xF8 }, | ||
{ 0xD8, 0xB8, 0xF8 }, | ||
{ 0xF8, 0xB8, 0xF8 }, | ||
{ 0xF8, 0xA4, 0xC0 }, | ||
{ 0xF0, 0xD0, 0xB0 }, | ||
{ 0xFC, 0xE0, 0xA8 }, | ||
{ 0xF8, 0xD8, 0x78 }, | ||
{ 0xD8, 0xF8, 0x78 }, | ||
{ 0xB8, 0xF8, 0xB8 }, | ||
{ 0xB8, 0xF8, 0xD8 }, | ||
{ 0x00, 0xFC, 0xFC }, | ||
{ 0xF8, 0xD8, 0xF8 }, | ||
{ 0x00, 0x00, 0x00 }, | ||
{ 0x00, 0x00, 0x00 } | ||
} | ||
}; |
Oops, something went wrong.