Skip to content

Commit

Permalink
Remove std::array, solve some warnings with automatic conversions bet…
Browse files Browse the repository at this point in the history
…ween u64 and u32.
  • Loading branch information
Jonazan2 committed Apr 8, 2020
1 parent b7e0ae4 commit 5401d10
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool Cartridge::TryLoad( const char* romFile )
std::basic_ifstream<byte> cartridgeFile( romFile, std::ios::binary | std::ios::in | std::ios::ate );
if ( cartridgeFile.is_open() )
{
cartridgeSize = cartridgeFile.tellg();
cartridgeSize = static_cast< u32 >( cartridgeFile.tellg() );
cartridgeFile.seekg( 0 );

rom = new byte[ cartridgeSize ];
Expand Down
4 changes: 1 addition & 3 deletions Cartridge.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <array>

#include "Types.h"


Expand All @@ -17,7 +15,7 @@ class Cartridge
Count
};

static constexpr std::array< const char*, static_cast< size_t >( MirroringType::Count ) > MirroringTypeString =
static constexpr const char* MirroringTypeString [ static_cast< size_t >( MirroringType::Count ) ] =
{
"Horizontal",
"Vertical"
Expand Down
23 changes: 5 additions & 18 deletions Cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@
#include "Cpu.h"

#include <assert.h>
#include <array>
#include <unordered_map>

#include "Memory.h"


const std::unordered_map< Cpu::Flags, const char * > Cpu::FLAGS_STRING =
{
{ Cpu::Flags::Carry, "Carry" },
{ Cpu::Flags::Zero, "Zero" },
{ Cpu::Flags::InterruptDisable, "Interrupt Disable" },
{ Cpu::Flags::DecimalMode, "Decimal Mode" },
{ Cpu::Flags::Break, "Break" },
{ Cpu::Flags::Overflow, "Overflow" },
{ Cpu::Flags::Negative, "Negative" },
};


Cpu::Cpu( Memory *memory )
: memory( memory )
{
Expand Down Expand Up @@ -89,7 +76,7 @@ short Cpu::ExecuteSubroutineOrInterruptInstruction( byte opcode )

short Cpu::ExecuteBranchInstruction( byte opcode )
{
static constexpr std::array< Cpu::Flags, 4> OPERAND_TO_FLAG =
constexpr static const Cpu::Flags OPERAND_TO_FLAG [] =
{
Cpu::Flags::Negative,
Cpu::Flags::Overflow,
Expand Down Expand Up @@ -133,7 +120,7 @@ short Cpu::ExecuteMappableInstruction( byte opcode )
short Cpu::ExecuteInstructionCC00( byte opcode )
{
/* We only need the 'aaa' part of the instruction to map it since we already know that cc == 01 */
static constexpr std::array< MappableInstructionFunctionPtr, 8 > INSTRUCTION_MAP =
constexpr static const MappableInstructionFunctionPtr INSTRUCTION_MAP [] =
{
&Cpu::BIT,
&Cpu::JMPA,
Expand Down Expand Up @@ -166,7 +153,7 @@ short Cpu::ExecuteInstructionCC00( byte opcode )
short Cpu::ExecuteInstructionCC01( byte opcode )
{
/* We only need the 'aaa' part of the instruction to map it since we already know that cc == 01 */
static constexpr std::array< MappableInstructionFunctionPtr, 8 > INSTRUCTION_MAP =
constexpr static const MappableInstructionFunctionPtr INSTRUCTION_MAP [] =
{
&Cpu::ORA,
&Cpu::AND,
Expand Down Expand Up @@ -201,7 +188,7 @@ short Cpu::ExecuteInstructionCC01( byte opcode )

short Cpu::ExecuteInstructionCC10( byte opcode )
{
static constexpr std::array< MappableInstructionFunctionPtr, 8 > INSTRUCTION_MAP =
constexpr static const MappableInstructionFunctionPtr INSTRUCTION_MAP [] =
{
&Cpu::ASL,
&Cpu::ROL,
Expand All @@ -214,7 +201,7 @@ short Cpu::ExecuteInstructionCC10( byte opcode )
&Cpu::INC
};

static constexpr std::array< InstructionFunctionPtr, 4 > ACCUMULATOR_MODE_INSTRUCTION_MAP =
constexpr static const InstructionFunctionPtr ACCUMULATOR_MODE_INSTRUCTION_MAP [] =
{
&Cpu::ASLA,
&Cpu::ROLA,
Expand Down
11 changes: 10 additions & 1 deletion Cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ class Cpu
Carry = 0b0000'0001,
};

static const std::unordered_map<Cpu::Flags, const char *> FLAGS_STRING;
inline static const std::unordered_map< Cpu::Flags, const char * > FLAGS_STRING =
{
{ Cpu::Flags::Carry, "Carry" },
{ Cpu::Flags::Zero, "Zero" },
{ Cpu::Flags::InterruptDisable, "Interrupt Disable" },
{ Cpu::Flags::DecimalMode, "Decimal Mode" },
{ Cpu::Flags::Break, "Break" },
{ Cpu::Flags::Overflow, "Overflow" },
{ Cpu::Flags::Negative, "Negative" },
};


Cpu( Memory *memory );
Expand Down
5 changes: 2 additions & 3 deletions CpuTypes.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <unordered_map>
#include <array>

#include "Types.h"

Expand All @@ -26,7 +25,7 @@ enum class CpuAddressMode : byte
MAX
};

constexpr std::array<const char *, static_cast< byte > ( CpuAddressMode::MAX ) > ADDRESS_MODE_STRING =
static constexpr const char * ADDRESS_MODE_STRING [ static_cast< byte > ( CpuAddressMode::MAX ) ] =
{
"Implicit",
"Accumulator",
Expand All @@ -43,7 +42,7 @@ constexpr std::array<const char *, static_cast< byte > ( CpuAddressMode::MAX ) >
"Indexed Y",
};

constexpr std::array< byte, static_cast< byte > ( CpuAddressMode::MAX ) > ADDRESS_MODE_OPCODE_LENGTH =
static constexpr byte ADDRESS_MODE_OPCODE_LENGTH [ static_cast< byte > ( CpuAddressMode::MAX ) ] =
{
1, /* CpuAddressMode::Implicit */
1, /* CpuAddressMode::Accumulator */
Expand Down
5 changes: 5 additions & 0 deletions Debugger/MemoryDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include "Debugger.h"
#include "../Memory.h"

MemoryDebugger::MemoryDebugger()
: watcherAsBreakpoint( false )
{
}


void MemoryDebugger::ComposeView( const Memory *memory, DebuggerMode& mode )
{
Expand Down
2 changes: 1 addition & 1 deletion Debugger/MemoryDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum class DebuggerMode : byte;
class MemoryDebugger
{
public:
MemoryDebugger() = default;
MemoryDebugger();

void ComposeView( const Memory *memory, DebuggerMode& mode );
void UpdateWatcher( const Memory *memory, DebuggerMode& mode );
Expand Down
4 changes: 3 additions & 1 deletion Debugger/VideoDebugger.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "VideoDebugger.h"

#include <stdio.h>

#include "ImguiWrapper/imgui_impl_glfw_gl3.h"
#include "../Video.h"
#include "../Memory.h"
Expand Down Expand Up @@ -80,7 +82,7 @@ void VideoDebugger::ComposeView( u32 cycles, const Video &video, const Memory &m
ImGui::End();

{
const u32 lineHeight = ImGui::GetTextLineHeight();
const float lineHeight = ImGui::GetTextLineHeight();

ImGui::SetNextWindowSize( ImVec2( 260, 70 ), ImGuiCond_FirstUseEver );
ImGui::Begin( "NES Palette" );
Expand Down
2 changes: 1 addition & 1 deletion Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <assert.h>
#include "Cartridge.h"
#include "Video.h"

#include <cstring>

Memory::Memory( const Cartridge *cartridge, Video *video )
: cartridge( cartridge )
Expand Down
135 changes: 67 additions & 68 deletions PaletteColors.h
Original file line number Diff line number Diff line change
@@ -1,77 +1,76 @@
#pragma once

#include <array>
#include "Types.h"

static constexpr std::array< RGB, 64 > NES_PALETTE_COLORS =
static constexpr byte NES_PALETTE_COLORS_COUNT = 64;

static constexpr RGB NES_PALETTE_COLORS [ NES_PALETTE_COLORS_COUNT ] =
{
{
{ 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 },
{ 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 },
{ 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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 },
{ 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 }
};
3 changes: 3 additions & 0 deletions Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ using i64 = long long;
using u32 = unsigned int;
using i32 = int;

using u16 = unsigned short;
using i16 = short;

union Register
{
struct
Expand Down
5 changes: 3 additions & 2 deletions Video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


#include <assert.h>
#include <cstring>

#include "Cartridge.h"

Expand Down Expand Up @@ -42,8 +43,8 @@ void Video::MapCartridgeCHRToPPU()
/* TODO(Jonathan): Support more mappers here */
const Cartridge::Header &header = cartridge->GetHeader();
const byte * const cartridgeRom = cartridge->GetRom();
const u32 offset = (header.prgRomSizeKB * 1_KB) + 0x0010;
const u32 dataSize = header.chrRomSizeKB * 1_KB;
const u64 offset = (header.prgRomSizeKB * 1_KB) + 0x0010;
const u64 dataSize = header.chrRomSizeKB * 1_KB;
memcpy( memory, &cartridgeRom[ offset ], dataSize );
}

Expand Down

0 comments on commit 5401d10

Please sign in to comment.