Skip to content

Commit

Permalink
Basic structure
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jun 25, 2024
1 parent 17e5c7b commit 4539c12
Show file tree
Hide file tree
Showing 33 changed files with 4,442 additions and 23 deletions.
12 changes: 10 additions & 2 deletions platforms/shared/desktop/Makefile.sources
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@ SOURCES_CXX := \
$(DESKTOP_SRC_DIR)/imgui/imgui_demo.cpp \
$(DESKTOP_SRC_DIR)/imgui/memory_editor.cpp \
$(SRC_DIR)/geargrafx_core.cpp \


$(SRC_DIR)/audio.cpp \
$(SRC_DIR)/cartridge.cpp \
$(SRC_DIR)/huc6270.cpp \
$(SRC_DIR)/huc6280.cpp \
$(SRC_DIR)/huc6280_functors.cpp \
$(SRC_DIR)/huc6280_opcodes.cpp \
$(SRC_DIR)/huc6280_psg.cpp \
$(SRC_DIR)/huc6280_timer.cpp \
$(SRC_DIR)/input.cpp \
$(SRC_DIR)/memory.cpp \
2 changes: 0 additions & 2 deletions platforms/shared/desktop/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ void config_read(void)
config_emulator.ffwd_speed = read_int("Emulator", "FFWD", 1);
config_emulator.save_slot = read_int("Emulator", "SaveSlot", 0);
config_emulator.start_paused = read_bool("Emulator", "StartPaused", false);
config_emulator.region = read_int("Emulator", "Region", 0);
config_emulator.savefiles_dir_option = read_int("Emulator", "SaveFilesDirOption", 0);
config_emulator.savefiles_path = read_string("Emulator", "SaveFilesPath");
config_emulator.savestates_dir_option = read_int("Emulator", "SaveStatesDirOption", 0);
Expand Down Expand Up @@ -219,7 +218,6 @@ void config_write(void)
write_int("Emulator", "FFWD", config_emulator.ffwd_speed);
write_int("Emulator", "SaveSlot", config_emulator.save_slot);
write_bool("Emulator", "StartPaused", config_emulator.start_paused);
write_int("Emulator", "Region", config_emulator.region);
write_int("Emulator", "SaveFilesDirOption", config_emulator.savefiles_dir_option);
write_string("Emulator", "SaveFilesPath", config_emulator.savefiles_path);
write_int("Emulator", "SaveStatesDirOption", config_emulator.savestates_dir_option);
Expand Down
1 change: 0 additions & 1 deletion platforms/shared/desktop/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ struct config_Emulator
bool start_paused = false;
bool ffwd = false;
int ffwd_speed = 1;
int region = 0;
bool show_info = false;
std::string recent_roms[config_max_recent_roms];
int savefiles_dir_option = 0;
Expand Down
21 changes: 21 additions & 0 deletions platforms/shared/desktop/emu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Geargrafx - PC Engine / TurboGrafx Emulator
* Copyright (C) 2024 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/

#define GUI_EMU_IMPORT
#include "emu.h"
77 changes: 77 additions & 0 deletions platforms/shared/desktop/emu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Geargrafx - PC Engine / TurboGrafx Emulator
* Copyright (C) 2024 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/

#ifndef EMU_H
#define EMU_H

#include "../../../src/geargrafx.h"

#ifdef EMU_IMPORT
#define EXTERN
#else
#define EXTERN extern
#endif

EXTERN u8* emu_frame_buffer;
// EXTERN u8* emu_debug_background_buffer;
// EXTERN u8* emu_debug_tile_buffer;
// EXTERN u8* emu_debug_sprite_buffers[64];

EXTERN bool emu_audio_sync;
// EXTERN bool emu_debug_disable_breakpoints_cpu;
// EXTERN bool emu_debug_disable_breakpoints_mem;
// EXTERN int emu_debug_tile_palette;
EXTERN bool emu_savefiles_dir_option;
EXTERN bool emu_savestates_dir_option;
EXTERN char emu_savefiles_path[4096];
EXTERN char emu_savestates_path[4096];

EXTERN void emu_init(void);
EXTERN void emu_destroy(void);
EXTERN void emu_update(void);
EXTERN void emu_load_rom(const char* file_path, Cartridge::ForceConfiguration config);
EXTERN void emu_key_pressed(GC_Controllers controller, GC_Keys key);
EXTERN void emu_key_released(GC_Controllers controller, GC_Keys key);
EXTERN void emu_pause(void);
EXTERN void emu_resume(void);
EXTERN bool emu_is_paused(void);
EXTERN bool emu_is_empty(void);
EXTERN void emu_reset(Cartridge::ForceConfiguration config);
EXTERN void emu_audio_mute(bool mute);
EXTERN void emu_audio_reset(void);
EXTERN bool emu_is_audio_enabled(void);
EXTERN void emu_save_ram(const char* file_path);
EXTERN void emu_load_ram(const char* file_path, Cartridge::ForceConfiguration config);
EXTERN void emu_save_state_slot(int index);
EXTERN void emu_load_state_slot(int index);
EXTERN void emu_save_state_file(const char* file_path);
EXTERN void emu_load_state_file(const char* file_path);
EXTERN void emu_get_runtime(GC_RuntimeInfo& runtime);
EXTERN void emu_get_info(char* info);
EXTERN GearcolecoCore* emu_get_core(void);
// EXTERN void emu_debug_step(void);
// EXTERN void emu_debug_continue(void);
// EXTERN void emu_debug_next_frame(void);
EXTERN void emu_video_no_sprite_limit(bool enabled);
EXTERN void emu_set_overscan(int overscan);
EXTERN void emu_save_screenshot(const char* file_path);

#undef EMU_IMPORT
#undef EXTERN
#endif /* EMU_H */
17 changes: 0 additions & 17 deletions platforms/shared/desktop/gui_menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,6 @@ static void menu_emulator(void)
{
gui_in_use = true;

if (ImGui::BeginMenu("Refresh Rate"))
{
ImGui::PushItemWidth(130.0f);
if (ImGui::Combo("##emu_rate", &config_emulator.region, "Auto\0NTSC (60 Hz)\0PAL (50 Hz)\0\0"))
{
if (config_emulator.region > 0)
{
config_emulator.ffwd = false;
config_audio.sync = true;
}
}
ImGui::PopItemWidth();
ImGui::EndMenu();
}

ImGui::Separator();

ImGui::MenuItem("Start Paused", "", &config_emulator.start_paused);

ImGui::Separator();
Expand Down
64 changes: 64 additions & 0 deletions src/audio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Geargrafx - PC Engine / TurboGrafx Emulator
* Copyright (C) 2024 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/

#include <istream>
#include <ostream>
#include "audio.h"

Audio::Audio()
{
m_elapsed_cycles = 0;
m_sample_rate = 44100;
m_mute = false;
}

Audio::~Audio()
{
}

void Audio::Init()
{

}

void Audio::Reset()
{
m_elapsed_cycles = 0;
}

void Audio::Mute(bool mute)
{
m_mute = mute;
}

void Audio::EndFrame(s16* sample_buffer, int* sample_count)
{
*sample_count = 0;
m_elapsed_cycles = 0;
}

// void Audio::SaveState(std::ostream& stream)
// {
// stream.write(reinterpret_cast<const char*> (&m_elapsed_cycles), sizeof(m_ElapsedCycles));
// }

// void Audio::LoadState(std::istream& stream)
// {
// stream.read(reinterpret_cast<char*> (&m_elapsed_cycles), sizeof(m_ElapsedCycles));
// }
44 changes: 44 additions & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Geargrafx - PC Engine / TurboGrafx Emulator
* Copyright (C) 2024 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/

#include "types.h"

class Audio
{
public:
Audio();
~Audio();
void Init();
void Reset();
void Mute(bool mute);
void Tick(unsigned int clock_cycles);
void EndFrame(s16* sample_buffer, int* sample_count);
// void SaveState(std::ostream& stream);
// void LoadState(std::istream& stream);

private:
u64 m_elapsed_cycles;
int m_sample_rate;
bool m_mute;
};

inline void Audio::Tick(unsigned int clock_cycles)
{
m_elapsed_cycles += clock_cycles;
}
18 changes: 18 additions & 0 deletions src/cartridge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Geargrafx - PC Engine / TurboGrafx Emulator
* Copyright (C) 2024 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/
48 changes: 48 additions & 0 deletions src/cartridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Geargrafx - PC Engine / TurboGrafx Emulator
* Copyright (C) 2024 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/

class Cartridge
{
public:
Cartridge();
~Cartridge();
void Init();
void Reset();
u32 GetCRC();
bool IsReady();
int GetROMSize();
int GetROMBankCount();
const char* GetFilePath();
const char* GetFileName();
u8* GetROM();
bool LoadFromFile(const char* path);
bool LoadFromBuffer(const u8* buffer, int size);

private:
bool LoadFromZipFile(const u8* buffer, int size);

private:
u8* m_pROM;
int m_iROMSize;
bool m_bReady;
char m_szFilePath[512];
char m_szFileName[512];
int m_iROMBankCount;
u32 m_iCRC;
};
8 changes: 8 additions & 0 deletions src/geargrafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@

#include "common.h"
#include "geargrafx_core.h"
#include "input.h"
#include "audio.h"
#include "cartridge.h"
#include "memory.h"
#include "huc6270.h"
#include "huc6280.h"
#include "huc6280_psg.h"
#include "huc6280_timer.h"

#endif /* GEARGRAFX_H */
Loading

0 comments on commit 4539c12

Please sign in to comment.