Skip to content

Commit

Permalink
added support for sms carts
Browse files Browse the repository at this point in the history
  • Loading branch information
finger563 committed Nov 26, 2023
1 parent 2c28cdd commit 937d32d
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 5 deletions.
9 changes: 8 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "gbc_cart.hpp"
#include "nes_cart.hpp"
#include "sms_cart.hpp"
#include "heap_utils.hpp"
#include "string_utils.hpp"
#include "fs_init.hpp"
Expand Down Expand Up @@ -67,7 +68,13 @@ std::unique_ptr<Cart> make_cart(const RomInfo& info) {
.display = display,
.verbosity = espp::Logger::Verbosity::WARN
});
default:
case Emulator::SEGA_MASTER_SYSTEM:
case Emulator::SEGA_GAME_GEAR:
return std::make_unique<SmsCart>(Cart::Config{
.info = info,
.display = display,
.verbosity = espp::Logger::Verbosity::WARN
}); default:
return nullptr;
}
}
Expand Down
18 changes: 15 additions & 3 deletions main/rom_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,24 @@ std::vector<RomInfo> parse_metadata(const std::string& metadata_path) {
}
fmt::print("INFO: '{}', '{}', '{}'\n", rom_path, boxart_path, name);
Emulator platform = Emulator::UNKNOWN;
if (endsWith(rom_path, ".nes")) {
if (endsWith(rom_path, ".nes")) { // nes
platform = Emulator::NES;
} else if (endsWith(rom_path, ".gb")) {
} else if (endsWith(rom_path, ".gb")) { // game boy
platform = Emulator::GAMEBOY;
} else if (endsWith(rom_path, ".gbc")) {
} else if (endsWith(rom_path, ".gbc")) { // game boy color
platform = Emulator::GAMEBOY_COLOR;
} else if (endsWith(rom_path, ".sms")) { // sega master system
platform = Emulator::SEGA_MASTER_SYSTEM;
} else if (endsWith(rom_path, ".gg")) { // sega game gear
platform = Emulator::SEGA_GAME_GEAR;
} else if (endsWith(rom_path, ".gen")) { // genesis
platform = Emulator::GENESIS;
} else if (endsWith(rom_path, ".sfc")) { // snes
platform = Emulator::SNES;
} else if (endsWith(rom_path, ".rom")) { // msx
platform = Emulator::MSX;
} else if (endsWith(rom_path, ".wad")) { // doom
platform = Emulator::DOOM;
}
if (platform != Emulator::UNKNOWN) {
// for each row, create rom entry
Expand Down
2 changes: 1 addition & 1 deletion main/rom_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "format.hpp"
#include "string_utils.hpp"

enum class Emulator { UNKNOWN, NES, GAMEBOY, GAMEBOY_COLOR, SEGA_MASTER_SYSTEM, GENESIS, SNES };
enum class Emulator { UNKNOWN, NES, GAMEBOY, GAMEBOY_COLOR, SEGA_MASTER_SYSTEM, SEGA_GAME_GEAR, GENESIS, SNES, MSX, DOOM };

struct RomInfo {
std::string name;
Expand Down
99 changes: 99 additions & 0 deletions main/sms_cart.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#pragma once

#include "cart.hpp"
#include "sms.hpp"

class SmsCart : public Cart {
public:

SmsCart(const Cart::Config& config)
: Cart(config) {
init();
}

~SmsCart() {
deinit();
}

virtual void reset() override {
Cart::reset();
reset_sms();
}

virtual void load() override {
Cart::load();
load_sms(get_save_path());
}

virtual void save() override {
Cart::save();
save_sms(get_save_path(true));
}

virtual void init() override {
Cart::init();
init_sms(get_rom_filename(), romdata_, rom_size_bytes_);
start_sms_tasks();
}

virtual void deinit() override {
stop_sms_tasks();
deinit_sms();
}

virtual bool run() override {
run_sms_rom();
return Cart::run();
}

protected:
// SMS
static constexpr size_t SMS_WIDTH = 256;
static constexpr size_t SMS_HEIGHT = 192;

virtual void pre_menu() override {
Cart::pre_menu();
logger_.info("sms::pre_menu()");
stop_sms_tasks();
}

virtual void post_menu() override {
Cart::post_menu();
logger_.info("sms::post_menu()");
start_sms_tasks();
}

virtual void set_original_video_setting() override {
logger_.info("sms::video: original");
set_sms_video_original();
}

virtual std::pair<size_t, size_t> get_video_size() const override {
return std::make_pair(SMS_WIDTH, SMS_HEIGHT);
}

virtual std::vector<uint8_t> get_video_buffer() const override {
return get_sms_video_buffer();
}

virtual void set_fit_video_setting() override {
logger_.info("sms::video: fit");
set_sms_video_fit();
}

virtual void set_fill_video_setting() override {
logger_.info("sms::video: fill");
set_sms_video_fill();
}

virtual std::string get_save_extension() const override {
switch (info_.platform) {
case Emulator::SEGA_MASTER_SYSTEM:
return "_sms.sav";
case Emulator::SEGA_GAME_GEAR:
return "_gg.sav";
default:
return Cart::get_save_extension();
}
}
};

0 comments on commit 937d32d

Please sign in to comment.