2019-09-09 07:01:26 +00:00
|
|
|
#pragma once
|
2019-11-07 15:07:39 +00:00
|
|
|
#include "host_interface.h"
|
2020-01-24 04:51:05 +00:00
|
|
|
#include "types.h"
|
2019-09-20 06:47:41 +00:00
|
|
|
#include <memory>
|
2019-11-16 05:27:57 +00:00
|
|
|
#include <optional>
|
2020-01-24 04:51:05 +00:00
|
|
|
#include <string>
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2019-09-14 10:28:47 +00:00
|
|
|
class ByteStream;
|
2019-11-16 05:27:57 +00:00
|
|
|
class CDImage;
|
2019-09-14 10:28:47 +00:00
|
|
|
class StateWrapper;
|
|
|
|
|
2019-10-04 05:00:32 +00:00
|
|
|
namespace CPU {
|
2019-09-12 02:53:04 +00:00
|
|
|
class Core;
|
2019-11-19 10:30:04 +00:00
|
|
|
class CodeCache;
|
2020-01-24 04:51:05 +00:00
|
|
|
} // namespace CPU
|
2019-09-12 02:53:04 +00:00
|
|
|
|
|
|
|
class Bus;
|
|
|
|
class DMA;
|
2019-09-17 06:26:00 +00:00
|
|
|
class InterruptController;
|
2019-09-12 02:53:04 +00:00
|
|
|
class GPU;
|
2019-09-17 09:22:39 +00:00
|
|
|
class CDROM;
|
2019-09-20 06:47:41 +00:00
|
|
|
class Pad;
|
2019-12-08 14:51:52 +00:00
|
|
|
class Controller;
|
2019-09-20 13:40:19 +00:00
|
|
|
class Timers;
|
2019-09-24 13:44:38 +00:00
|
|
|
class SPU;
|
2019-09-29 02:51:34 +00:00
|
|
|
class MDEC;
|
2019-12-07 11:09:02 +00:00
|
|
|
class SIO;
|
2019-09-12 02:53:04 +00:00
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
class System
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~System();
|
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
/// Creates a new System.
|
|
|
|
static std::unique_ptr<System> Create(HostInterface* host_interface);
|
|
|
|
|
2019-10-26 02:55:56 +00:00
|
|
|
// Accessing components.
|
2019-09-12 14:18:13 +00:00
|
|
|
HostInterface* GetHostInterface() const { return m_host_interface; }
|
2019-10-04 05:00:32 +00:00
|
|
|
CPU::Core* GetCPU() const { return m_cpu.get(); }
|
|
|
|
Bus* GetBus() const { return m_bus.get(); }
|
2019-10-26 02:55:56 +00:00
|
|
|
DMA* GetDMA() const { return m_dma.get(); }
|
|
|
|
InterruptController* GetInterruptController() const { return m_interrupt_controller.get(); }
|
2019-10-04 05:00:32 +00:00
|
|
|
GPU* GetGPU() const { return m_gpu.get(); }
|
2019-10-26 02:55:56 +00:00
|
|
|
CDROM* GetCDROM() const { return m_cdrom.get(); }
|
|
|
|
Pad* GetPad() const { return m_pad.get(); }
|
|
|
|
Timers* GetTimers() const { return m_timers.get(); }
|
2019-10-10 16:20:21 +00:00
|
|
|
SPU* GetSPU() const { return m_spu.get(); }
|
2019-10-26 02:55:56 +00:00
|
|
|
MDEC* GetMDEC() const { return m_mdec.get(); }
|
2019-09-12 14:18:13 +00:00
|
|
|
|
2019-11-16 10:15:33 +00:00
|
|
|
ConsoleRegion GetRegion() const { return m_region; }
|
|
|
|
bool IsPALRegion() const { return m_region == ConsoleRegion::PAL; }
|
2019-09-13 16:07:31 +00:00
|
|
|
u32 GetFrameNumber() const { return m_frame_number; }
|
2019-09-27 15:09:31 +00:00
|
|
|
u32 GetInternalFrameNumber() const { return m_internal_frame_number; }
|
2019-10-04 10:48:29 +00:00
|
|
|
u32 GetGlobalTickCounter() const { return m_global_tick_counter; }
|
2019-09-13 16:07:31 +00:00
|
|
|
void IncrementFrameNumber() { m_frame_number++; }
|
2019-09-27 15:09:31 +00:00
|
|
|
void IncrementInternalFrameNumber() { m_internal_frame_number++; }
|
2019-09-13 16:07:31 +00:00
|
|
|
|
2019-11-07 15:07:39 +00:00
|
|
|
const Settings& GetSettings() { return m_host_interface->GetSettings(); }
|
2019-10-04 05:00:32 +00:00
|
|
|
|
2020-01-24 04:51:05 +00:00
|
|
|
const std::string& GetRunningPath() const { return m_running_game_path; }
|
|
|
|
const std::string& GetRunningCode() const { return m_running_game_code; }
|
|
|
|
const std::string& GetRunningTitle() const { return m_running_game_title; }
|
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
bool Boot(const char* filename);
|
2019-09-09 07:01:26 +00:00
|
|
|
void Reset();
|
|
|
|
|
2019-09-14 10:28:47 +00:00
|
|
|
bool LoadState(ByteStream* state);
|
|
|
|
bool SaveState(ByteStream* state);
|
|
|
|
|
2019-10-26 02:55:56 +00:00
|
|
|
/// Recreates the GPU component, saving/loading the state so it is preserved. Call when the GPU renderer changes.
|
2020-01-24 04:51:53 +00:00
|
|
|
bool RecreateGPU(GPURenderer renderer);
|
2019-10-26 02:55:56 +00:00
|
|
|
|
2020-01-24 04:51:33 +00:00
|
|
|
/// Updates GPU settings, without recreating the renderer.
|
|
|
|
void UpdateGPUSettings();
|
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
void RunFrame();
|
|
|
|
|
2019-11-16 05:27:57 +00:00
|
|
|
bool LoadEXE(const char* filename, std::vector<u8>& bios_image);
|
2019-09-22 15:28:00 +00:00
|
|
|
bool SetExpansionROM(const char* filename);
|
2019-09-14 03:22:05 +00:00
|
|
|
|
2019-09-20 13:59:48 +00:00
|
|
|
void SetDowncount(TickCount downcount);
|
|
|
|
void Synchronize();
|
2019-09-17 04:25:25 +00:00
|
|
|
|
2019-10-17 14:20:38 +00:00
|
|
|
// Adds ticks to the global tick counter, simulating the CPU being stalled.
|
|
|
|
void StallCPU(TickCount ticks);
|
|
|
|
|
2019-12-14 13:20:24 +00:00
|
|
|
// Access controllers for simulating input.
|
|
|
|
Controller* GetController(u32 slot) const;
|
|
|
|
void UpdateControllers();
|
2019-10-27 06:45:23 +00:00
|
|
|
void UpdateMemoryCards();
|
2019-11-23 10:22:09 +00:00
|
|
|
void UpdateCPUExecutionMode();
|
2019-09-20 06:47:41 +00:00
|
|
|
|
2019-09-20 10:14:00 +00:00
|
|
|
bool HasMedia() const;
|
|
|
|
bool InsertMedia(const char* path);
|
|
|
|
void RemoveMedia();
|
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
private:
|
2019-11-16 05:27:57 +00:00
|
|
|
System(HostInterface* host_interface);
|
|
|
|
|
2019-09-14 10:28:47 +00:00
|
|
|
bool DoState(StateWrapper& sw);
|
2020-01-24 04:51:53 +00:00
|
|
|
bool CreateGPU(GPURenderer renderer);
|
2019-11-16 05:27:57 +00:00
|
|
|
|
|
|
|
void InitializeComponents();
|
2019-09-14 10:28:47 +00:00
|
|
|
|
2020-01-24 04:51:05 +00:00
|
|
|
void UpdateRunningGame(const char* path, CDImage* image);
|
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
HostInterface* m_host_interface;
|
2019-09-12 02:53:04 +00:00
|
|
|
std::unique_ptr<CPU::Core> m_cpu;
|
2019-11-19 10:30:04 +00:00
|
|
|
std::unique_ptr<CPU::CodeCache> m_cpu_code_cache;
|
2019-09-12 02:53:04 +00:00
|
|
|
std::unique_ptr<Bus> m_bus;
|
|
|
|
std::unique_ptr<DMA> m_dma;
|
2019-09-17 06:26:00 +00:00
|
|
|
std::unique_ptr<InterruptController> m_interrupt_controller;
|
2019-09-12 02:53:04 +00:00
|
|
|
std::unique_ptr<GPU> m_gpu;
|
2019-09-17 09:22:39 +00:00
|
|
|
std::unique_ptr<CDROM> m_cdrom;
|
2019-09-20 06:47:41 +00:00
|
|
|
std::unique_ptr<Pad> m_pad;
|
2019-09-20 13:40:19 +00:00
|
|
|
std::unique_ptr<Timers> m_timers;
|
2019-09-24 13:44:38 +00:00
|
|
|
std::unique_ptr<SPU> m_spu;
|
2019-09-29 02:51:34 +00:00
|
|
|
std::unique_ptr<MDEC> m_mdec;
|
2019-12-07 11:09:02 +00:00
|
|
|
std::unique_ptr<SIO> m_sio;
|
2019-11-16 05:27:57 +00:00
|
|
|
ConsoleRegion m_region = ConsoleRegion::NTSC_U;
|
2019-11-23 10:22:09 +00:00
|
|
|
CPUExecutionMode m_cpu_execution_mode = CPUExecutionMode::Interpreter;
|
2019-09-13 16:07:31 +00:00
|
|
|
u32 m_frame_number = 1;
|
2019-09-27 15:09:31 +00:00
|
|
|
u32 m_internal_frame_number = 1;
|
2019-10-04 10:48:29 +00:00
|
|
|
u32 m_global_tick_counter = 0;
|
2020-01-24 04:51:05 +00:00
|
|
|
|
|
|
|
std::string m_running_game_path;
|
|
|
|
std::string m_running_game_code;
|
|
|
|
std::string m_running_game_title;
|
2019-09-09 07:01:26 +00:00
|
|
|
};
|