Skip to content

Commit

Permalink
Merge pull request #58 from benvenutti/feature/update-clang-format-style
Browse files Browse the repository at this point in the history
Add space to angled brackets
  • Loading branch information
benvenutti authored Aug 19, 2024
2 parents 1b5abb4 + 2e1c289 commit ae2840c
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInAngles: true
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: true
Expand Down
20 changes: 11 additions & 9 deletions app-qtwidget/src/IoDeviceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@

namespace detail
{
const std::map<Qt::Key, int> keymap = { { Qt::Key_X, 0x0 }, { Qt::Key_1, 0x1 }, { Qt::Key_2, 0x2 }, { Qt::Key_3, 0x3 },
{ Qt::Key_Q, 0x4 }, { Qt::Key_W, 0x5 }, { Qt::Key_E, 0x6 }, { Qt::Key_A, 0x7 },
{ Qt::Key_S, 0x8 }, { Qt::Key_D, 0x9 }, { Qt::Key_Z, 0xa }, { Qt::Key_C, 0xb },
{ Qt::Key_4, 0xc }, { Qt::Key_R, 0xd }, { Qt::Key_F, 0xe }, { Qt::Key_V, 0xf } };
const std::map< Qt::Key, int > keymap = { { Qt::Key_X, 0x0 }, { Qt::Key_1, 0x1 }, { Qt::Key_2, 0x2 },
{ Qt::Key_3, 0x3 }, { Qt::Key_Q, 0x4 }, { Qt::Key_W, 0x5 },
{ Qt::Key_E, 0x6 }, { Qt::Key_A, 0x7 }, { Qt::Key_S, 0x8 },
{ Qt::Key_D, 0x9 }, { Qt::Key_Z, 0xa }, { Qt::Key_C, 0xb },
{ Qt::Key_4, 0xc }, { Qt::Key_R, 0xd }, { Qt::Key_F, 0xe },
{ Qt::Key_V, 0xf } };
} // namespace detail

void IoDeviceImpl::set( const int key, const bool pressed )
{
if ( const auto it = detail::keymap.find( static_cast<Qt::Key>( key ) ); it != detail::keymap.end() )
if ( const auto it = detail::keymap.find( static_cast< Qt::Key >( key ) ); it != detail::keymap.end() )
{
m_keypad[static_cast<size_t>( it->second )] = pressed;
m_keypad[static_cast< size_t >( it->second )] = pressed;
}
}

bool IoDeviceImpl::isKeyPressed( const model::chip8::key key ) const
{
return m_keypad[static_cast<size_t>( key )];
return m_keypad[static_cast< size_t >( key )];
}

std::optional<model::chip8::key> IoDeviceImpl::pressedKey() const
std::optional< model::chip8::key > IoDeviceImpl::pressedKey() const
{
if ( const auto it = std::ranges::find( m_keypad, std::true_type::value ); it != m_keypad.end() )
{
return static_cast<model::chip8::key>( std::distance( std::begin( m_keypad ), it ) );
return static_cast< model::chip8::key >( std::distance( std::begin( m_keypad ), it ) );
}

return std::nullopt;
Expand Down
4 changes: 2 additions & 2 deletions app-qtwidget/src/IoDeviceImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class IoDeviceImpl : public model::IoDevice

bool isKeyPressed( model::chip8::key key ) const override;

std::optional<model::chip8::key> pressedKey() const override;
std::optional< model::chip8::key > pressedKey() const override;

void set( int key, bool pressed );

private:
std::array<bool, model::chip8::keypad_size> m_keypad = {};
std::array< bool, model::chip8::keypad_size > m_keypad = {};
};
2 changes: 1 addition & 1 deletion app-qtwidget/src/ScreenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

ScreenWidget::ScreenWidget( const std::uint32_t* buffer, int w, int h )
: QWidget{ nullptr }
, m_buffer{ reinterpret_cast<const uchar*>( buffer ) }
, m_buffer{ reinterpret_cast< const uchar* >( buffer ) }
, m_screenWidth{ w }
, m_screenHeight{ h }
{
Expand Down
12 changes: 6 additions & 6 deletions model/include/model/CPU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace model
class CPU
{
public:
using Stack = std::array<chip8::word_t, chip8::stack_size>;
using VideoBuffer = std::array<std::uint32_t, chip8::display_size>;
using Stack = std::array< chip8::word_t, chip8::stack_size >;
using VideoBuffer = std::array< std::uint32_t, chip8::display_size >;

CPU( MMU& mmu, IoDevice& ioDevice, RandomNumberGenerator& rndGenerator );

Expand All @@ -24,7 +24,7 @@ class CPU

chip8::byte_t readRegister( chip8::reg id ) const;
void writeRegister( chip8::reg id, chip8::byte_t value );
void loadToRegisters( const std::vector<chip8::byte_t>& values );
void loadToRegisters( const std::vector< chip8::byte_t >& values );

chip8::word_t pc() const
{
Expand Down Expand Up @@ -141,9 +141,9 @@ class CPU
bool m_drawFlag{ false };
bool m_isInterrupted{ false };

std::array<chip8::byte_t, chip8::num_registers> m_registers = {};
Stack m_stack = {};
VideoBuffer m_frameBuffer;
std::array< chip8::byte_t, chip8::num_registers > m_registers = {};
Stack m_stack = {};
VideoBuffer m_frameBuffer;

MMU& m_mmu;
IoDevice& m_ioDevice;
Expand Down
2 changes: 1 addition & 1 deletion model/include/model/Chip8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ enum class key
kf
};

const std::vector<byte_t> font_set{
const std::vector< byte_t > font_set{
0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
0x20, 0x60, 0x20, 0x20, 0x70, // 1
0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2
Expand Down
2 changes: 1 addition & 1 deletion model/include/model/IoDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class IoDevice

virtual bool isKeyPressed( chip8::key key ) const = 0;

virtual std::optional<chip8::key> pressedKey() const = 0;
virtual std::optional< chip8::key > pressedKey() const = 0;
};

} // namespace model
9 changes: 5 additions & 4 deletions model/include/model/MMU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class MMU

[[nodiscard]] chip8::word_t readWord( const chip8::word_t address ) const
{
const auto msb = static_cast<chip8::word_t>( m_memory[address] << std::numeric_limits<chip8::byte_t>::digits );
const auto lsb = static_cast<chip8::word_t>( m_memory[address + 1] );
const auto msb =
static_cast< chip8::word_t >( m_memory[address] << std::numeric_limits< chip8::byte_t >::digits );
const auto lsb = static_cast< chip8::word_t >( m_memory[address + 1] );

return msb | lsb;
}
Expand All @@ -39,7 +40,7 @@ class MMU
m_memory[address] = byte;
}

template <typename T>
template < typename T >
void load( const T& rom, chip8::word_t address )
{
const auto length = std::min( size() - address, std::size( rom ) );
Expand Down Expand Up @@ -78,7 +79,7 @@ class MMU
}

private:
std::array<chip8::byte_t, chip8::ram_size> m_memory = {};
std::array< chip8::byte_t, chip8::ram_size > m_memory = {};
};

} // namespace model
4 changes: 2 additions & 2 deletions model/include/model/MersenneByteTwister.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class MersenneByteTwister : public RandomNumberGenerator
}

private:
mutable std::mt19937 m_generator{ std::random_device{}() };
mutable std::uniform_int_distribution<unsigned short> m_distribution{ 0x00u, 0xFFu };
mutable std::mt19937 m_generator{ std::random_device{}() };
mutable std::uniform_int_distribution< unsigned short > m_distribution{ 0x00u, 0xFFu };
};

} // namespace model
8 changes: 4 additions & 4 deletions model/include/model/WordDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ namespace model::WordDecoder
/// Reads byte value of X on pattern vXvv.
inline chip8::byte_t readX( const chip8::word_t instr )
{
return static_cast<chip8::byte_t>( ( instr & 0x0F00 ) >> 8 );
return static_cast< chip8::byte_t >( ( instr & 0x0F00 ) >> 8 );
}

/// Reads byte value of Y on pattern vvYv.
inline chip8::byte_t readY( const chip8::word_t instr )
{
return static_cast<chip8::byte_t>( ( instr & 0x00F0 ) >> 4 );
return static_cast< chip8::byte_t >( ( instr & 0x00F0 ) >> 4 );
}

/// Reads byte value of N on pattern vvvN.
inline chip8::byte_t readN( const chip8::word_t instr )
{
return static_cast<chip8::byte_t>( instr & 0x000F );
return static_cast< chip8::byte_t >( instr & 0x000F );
}

/// Reads byte value of NN on pattern vvNN.
inline chip8::byte_t readNN( const chip8::word_t instr )
{
return static_cast<chip8::byte_t>( instr & 0x00FF );
return static_cast< chip8::byte_t >( instr & 0x00FF );
}

/// Reads word value of NNN on pattern vNNN.
Expand Down
20 changes: 10 additions & 10 deletions model/src/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ CPU::CPU( MMU& mmu, IoDevice& ioDevice, RandomNumberGenerator& rndGenerator )

chip8::byte_t CPU::readRegister( chip8::reg id ) const
{
return m_registers.at( static_cast<std::size_t>( id ) );
return m_registers.at( static_cast< std::size_t >( id ) );
}

void CPU::writeRegister( chip8::reg id, chip8::byte_t value )
{
m_registers.at( static_cast<std::size_t>( id ) ) = value;
m_registers.at( static_cast< std::size_t >( id ) ) = value;
}

void CPU::loadToRegisters( const std::vector<chip8::byte_t>& values )
void CPU::loadToRegisters( const std::vector< chip8::byte_t >& values )
{
const auto size = std::min( values.size(), m_registers.size() );
std::copy_n( std::begin( values ), size, std::begin( m_registers ) );
Expand Down Expand Up @@ -315,7 +315,7 @@ void CPU::bitwiseVxXorVy()
void CPU::shiftVxRight()
{
const auto x = WordDecoder::readX( m_instruction );
const auto mask = static_cast<chip8::byte_t>( 0x1 );
const auto mask = static_cast< chip8::byte_t >( 0x1 );
auto& vx = m_registers.at( x );

writeRegister( chip8::reg::vf, vx & mask );
Expand Down Expand Up @@ -429,8 +429,8 @@ void CPU::draw()
{
if ( ( rowPixels & ( 0x80 >> row ) ) != 0 )
{
const auto offset =
static_cast<size_t>( ( x + row + ( ( y + line ) * chip8::display_width ) ) % chip8::display_size );
const auto offset = static_cast< size_t >( ( x + row + ( ( y + line ) * chip8::display_width ) )
% chip8::display_size );

auto& pixel = m_frameBuffer.at( offset );

Expand All @@ -450,7 +450,7 @@ void CPU::draw()

void CPU::executeSkipIfVxIsPressed()
{
const auto key = static_cast<chip8::key>( m_registers.at( WordDecoder::readX( m_instruction ) ) );
const auto key = static_cast< chip8::key >( m_registers.at( WordDecoder::readX( m_instruction ) ) );

if ( m_ioDevice.isKeyPressed( key ) )
{
Expand All @@ -460,7 +460,7 @@ void CPU::executeSkipIfVxIsPressed()

void CPU::executeSkipIfVxIsNotPressed()
{
const auto key = static_cast<chip8::key>( m_registers.at( WordDecoder::readX( m_instruction ) ) );
const auto key = static_cast< chip8::key >( m_registers.at( WordDecoder::readX( m_instruction ) ) );

if ( !m_ioDevice.isKeyPressed( key ) )
{
Expand All @@ -475,7 +475,7 @@ void CPU::executeWaitPressedKeyToVx()
if ( const auto pressedKey = m_ioDevice.pressedKey() )
{
const auto x = WordDecoder::readX( m_instruction );
m_registers.at( x ) = static_cast<chip8::byte_t>( *pressedKey );
m_registers.at( x ) = static_cast< chip8::byte_t >( *pressedKey );
m_isInterrupted = false;
}
}
Expand All @@ -497,7 +497,7 @@ void CPU::executeLoadRandomToVx()
{
const auto x = WordDecoder::readX( m_instruction );
const auto nn = WordDecoder::readNN( m_instruction );
m_registers.at( x ) = nn & static_cast<chip8::byte_t>( m_rndGenerator.get() );
m_registers.at( x ) = nn & static_cast< chip8::byte_t >( m_rndGenerator.get() );
}

} // namespace model
4 changes: 2 additions & 2 deletions model/src/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ bool VM::loadRom( const std::string& fileName )
{
std::noskipws( in );

const std::vector<chip8::byte_t> data{ std::istream_iterator<chip8::byte_t>{ in },
std::istream_iterator<chip8::byte_t>{} };
const std::vector< chip8::byte_t > data{ std::istream_iterator< chip8::byte_t >{ in },
std::istream_iterator< chip8::byte_t >{} };

in.close();
m_mmu.load( data, chip8::init_rom_load_address );
Expand Down
10 changes: 5 additions & 5 deletions model/tests/CPU.memory.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ SCENARIO_METHOD( CpuFixture,
const model::chip8::word_t address{ 1024 };
cpu.iaddr( address );

const std::vector<model::chip8::byte_t> bytes{ 0x10, 0x11, 0x12, 0x13, 0x24, 0x25, 0x26, 0x27,
0x38, 0x39, 0x3A, 0x3B, 0x4C, 0x4D, 0x4E, 0x4F };
const std::vector< model::chip8::byte_t > bytes{ 0x10, 0x11, 0x12, 0x13, 0x24, 0x25, 0x26, 0x27,
0x38, 0x39, 0x3A, 0x3B, 0x4C, 0x4D, 0x4E, 0x4F };
cpu.loadToRegisters( bytes );

WHEN( "the CPU executes a FX55 opcode" )
Expand All @@ -58,7 +58,7 @@ SCENARIO_METHOD( CpuFixture,
{
for ( model::chip8::word_t i = 0u; i <= 0xFu; ++i )
{
const auto r = cpu.readRegister( static_cast<model::chip8::reg>( i ) );
const auto r = cpu.readRegister( static_cast< model::chip8::reg >( i ) );
const auto m = mmu.readByte( address + i );
REQUIRE( r == m );
}
Expand All @@ -77,7 +77,7 @@ SCENARIO_METHOD( CpuFixture,
const model::chip8::word_t address{ 1024 };
cpu.iaddr( address );

const std::vector<model::chip8::byte_t> bytes = { 0x10, 0x11, 0x12, 0x13, 0x24, 0x25 };
const std::vector< model::chip8::byte_t > bytes = { 0x10, 0x11, 0x12, 0x13, 0x24, 0x25 };
mmu.load( bytes, address );

WHEN( "the CPU executes a FX65 opcode" )
Expand All @@ -88,7 +88,7 @@ SCENARIO_METHOD( CpuFixture,
{
for ( model::chip8::word_t i = 0u; i <= 0x5u; ++i )
{
const auto r = cpu.readRegister( static_cast<model::chip8::reg>( i ) );
const auto r = cpu.readRegister( static_cast< model::chip8::reg >( i ) );
const auto m = mmu.readByte( address + i );
REQUIRE( r == m );
}
Expand Down
20 changes: 10 additions & 10 deletions model/tests/MMU.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ SCENARIO( "Comparing two identical MMUs using the equal operator", "[mmu]" )
{
model::MMU mmu1;
model::MMU mmu2;
std::ranges::fill( mmu1, static_cast<model::chip8::byte_t>( 0xFFu ) );
std::ranges::fill( mmu2, static_cast<model::chip8::byte_t>( 0xFFu ) );
std::ranges::fill( mmu1, static_cast< model::chip8::byte_t >( 0xFFu ) );
std::ranges::fill( mmu2, static_cast< model::chip8::byte_t >( 0xFFu ) );

WHEN( "the MMUs are compared using the equal operator" )
{
Expand Down Expand Up @@ -143,8 +143,8 @@ SCENARIO( "MMU loads a rom that fits at the given valid address", "[mmu]" )
{
GIVEN( "A rom and a MMU" )
{
std::vector<std::uint8_t> data{ 0xFF, 0x11, 0xCC, 0x33 };
model::MMU mmu;
std::vector< std::uint8_t > data{ 0xFF, 0x11, 0xCC, 0x33 };
model::MMU mmu;

WHEN( "the MMU loads the rom at a valid address with enough memory space" )
{
Expand All @@ -165,8 +165,8 @@ SCENARIO( "MMU loads a rom that does not fit at the given valid address", "[mmu]
{
GIVEN( "A rom and a MMU" )
{
std::vector<std::uint8_t> data{ 0xFF, 0x11, 0xCC, 0x33 };
model::MMU mmu;
std::vector< std::uint8_t > data{ 0xFF, 0x11, 0xCC, 0x33 };
model::MMU mmu;

WHEN( "the MMU loads the rom at a valid address without enough space" )
{
Expand All @@ -186,9 +186,9 @@ SCENARIO( "MMU loads a rom to an invalid memory address", "[mmu]" )
{
GIVEN( "A rom and a MMU" )
{
std::vector<std::uint8_t> data{ 0xFF, 0x11, 0xCC, 0x33 };
model::MMU mmu;
model::MMU originalMmu{ mmu };
std::vector< std::uint8_t > data{ 0xFF, 0x11, 0xCC, 0x33 };
model::MMU mmu;
model::MMU originalMmu{ mmu };

WHEN( "the MMU loads the rom at an invalid address" )
{
Expand All @@ -206,7 +206,7 @@ SCENARIO( "MMU clears its memory", "[mmu]" )
GIVEN( "A MMU with initialized values" )
{
model::MMU mmu;
std::ranges::fill( mmu, static_cast<model::chip8::byte_t>( 0xFFu ) );
std::ranges::fill( mmu, static_cast< model::chip8::byte_t >( 0xFFu ) );

WHEN( "the MMU clears the memory" )
{
Expand Down
Loading

0 comments on commit ae2840c

Please sign in to comment.