Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playstation emulator code refactoring and bugfixes #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pscx_emulator/pscx_bios.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "pscx_bios.h"
#include "pscx_common.h"

#include <fstream>
#include <iterator>

Bios::BiosState Bios::loadBios(std::string path)
Bios::BiosState Bios::loadBios(const std::string& path)
{
std::basic_ifstream<uint8_t> biosFile(path, std::ios::in | std::ios::binary);

if (!biosFile.good())
return BIOS_STATE_INCORRECT_FILENAME;
return BiosState::BIOS_STATE_INCORRECT_FILENAME;

const uint32_t biosSize = 512 * 1024; // 512 kb

Expand All @@ -18,9 +19,9 @@ Bios::BiosState Bios::loadBios(std::string path)
biosFile.close();

if (m_data.size() != biosSize)
return BIOS_STATE_INVALID_BIOS_SIZE;
return BiosState::BIOS_STATE_INVALID_BIOS_SIZE;

return BIOS_STATE_SUCCESS;
return BiosState::BIOS_STATE_SUCCESS;
}

template<> uint32_t Bios::load<uint32_t>(uint32_t offset) const
Expand All @@ -35,6 +36,7 @@ template<> uint32_t Bios::load<uint32_t>(uint32_t offset) const

template<> uint16_t Bios::load<uint16_t>(uint32_t offset) const
{
PCSX_UNUSED(offset);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions pscx_emulator/pscx_bios.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace pscx_memory;
// BIOS image
struct Bios
{
enum BiosState
enum class BiosState
{
BIOS_STATE_SUCCESS,
BIOS_STATE_INCORRECT_FILENAME,
Expand All @@ -22,7 +22,7 @@ struct Bios
std::vector<uint8_t> m_data;

// Load a BIOS image from the file that is located in 'path'
BiosState loadBios(std::string path);
BiosState loadBios(const std::string& path);

template<typename T>
T load(uint32_t offset) const;
Expand Down
5 changes: 3 additions & 2 deletions pscx_emulator/pscx_cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void CdRom::sync(TimeKeeper& timeKeeper, InterruptState& irqState)
{
Cycles delta = timeKeeper.sync(Peripheral::PERIPHERAL_CDROM);

CommandState newCommandState;
CommandState newCommandState{ CommandState::COMMAND_STATE_INVALID };
switch (m_commandState)
{
case CommandState::COMMAND_STATE_IDLE:
Expand Down Expand Up @@ -248,6 +248,7 @@ void CdRom::sync(TimeKeeper& timeKeeper, InterruptState& irqState)
}
}

assert(("Invalid command state", newCommandState != CommandState::COMMAND_STATE_INVALID));
m_commandState = newCommandState;

// See if we have a read pending.
Expand Down Expand Up @@ -789,7 +790,7 @@ CommandState CdRom::ackGetId()
{
if (m_disc)
{
uint8_t regionSymbol;
uint8_t regionSymbol{};
switch (m_disc->getRegion())
{
case Region::REGION_JAPAN:
Expand Down
7 changes: 4 additions & 3 deletions pscx_emulator/pscx_cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// Various IRQ codes used by the CDROM controller and their
// signification.
enum IrqCode
enum class IrqCode
{
// A CD sector has been read and is ready to be processed.
IRQ_CODE_SECTOR_READY = 1,
Expand All @@ -24,7 +24,7 @@ enum IrqCode
};

// CDROM controller state machine.
enum CommandState
enum class CommandState
{
// Controller is idle.
COMMAND_STATE_IDLE,
Expand All @@ -45,7 +45,7 @@ enum CommandState
};

// CDROM data read state machine.
enum ReadState
enum class ReadState
{
READ_STATE_IDLE,
// We're expection a sector
Expand Down Expand Up @@ -119,6 +119,7 @@ struct CdRom
m_readPosition(MinuteSecondFrame::createZeroTimestamp()),
m_doubleSpeed(false),
m_xaAdpcmToSpu(false),
m_rxSector(nullptr),
m_rxActive(false),
m_rxIndex(0x0),
m_rxOffset(0x0),
Expand Down
9 changes: 7 additions & 2 deletions pscx_emulator/pscx_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

#if _DEBUG
#define LOG(msg) \
//std::cout << __FILE__ << "(" << __LINE__ << "): " << msg << std::endl
std::cout << __FILE__ << "(" << __LINE__ << "): " << msg << std::endl
#else
#define LOG(msg)
#endif

#define WARN(msg) \
std::cerr << __FILE__ << "(" << __LINE__ << "): " << msg << std::endl
std::cerr << __FILE__ << "(" << __LINE__ << "): " << msg << std::endl

template <class... Args>
void PCSX_UNUSED(Args&&...)
{
}
2 changes: 1 addition & 1 deletion pscx_emulator/pscx_cop0.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "pscx_interrupts.h"

// Exception types ( sd stored in the 'CAUSE' register )
enum Exception
enum class Exception
{
// Interrupt Request
EXCEPTION_INTERRUPT = 0x0,
Expand Down
Loading