Skip to content

Commit 937d32d

Browse files
committed
added support for sms carts
1 parent 2c28cdd commit 937d32d

File tree

4 files changed

+123
-5
lines changed

4 files changed

+123
-5
lines changed

main/main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "gbc_cart.hpp"
2626
#include "nes_cart.hpp"
27+
#include "sms_cart.hpp"
2728
#include "heap_utils.hpp"
2829
#include "string_utils.hpp"
2930
#include "fs_init.hpp"
@@ -67,7 +68,13 @@ std::unique_ptr<Cart> make_cart(const RomInfo& info) {
6768
.display = display,
6869
.verbosity = espp::Logger::Verbosity::WARN
6970
});
70-
default:
71+
case Emulator::SEGA_MASTER_SYSTEM:
72+
case Emulator::SEGA_GAME_GEAR:
73+
return std::make_unique<SmsCart>(Cart::Config{
74+
.info = info,
75+
.display = display,
76+
.verbosity = espp::Logger::Verbosity::WARN
77+
}); default:
7178
return nullptr;
7279
}
7380
}

main/rom_info.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,24 @@ std::vector<RomInfo> parse_metadata(const std::string& metadata_path) {
4343
}
4444
fmt::print("INFO: '{}', '{}', '{}'\n", rom_path, boxart_path, name);
4545
Emulator platform = Emulator::UNKNOWN;
46-
if (endsWith(rom_path, ".nes")) {
46+
if (endsWith(rom_path, ".nes")) { // nes
4747
platform = Emulator::NES;
48-
} else if (endsWith(rom_path, ".gb")) {
48+
} else if (endsWith(rom_path, ".gb")) { // game boy
4949
platform = Emulator::GAMEBOY;
50-
} else if (endsWith(rom_path, ".gbc")) {
50+
} else if (endsWith(rom_path, ".gbc")) { // game boy color
5151
platform = Emulator::GAMEBOY_COLOR;
52+
} else if (endsWith(rom_path, ".sms")) { // sega master system
53+
platform = Emulator::SEGA_MASTER_SYSTEM;
54+
} else if (endsWith(rom_path, ".gg")) { // sega game gear
55+
platform = Emulator::SEGA_GAME_GEAR;
56+
} else if (endsWith(rom_path, ".gen")) { // genesis
57+
platform = Emulator::GENESIS;
58+
} else if (endsWith(rom_path, ".sfc")) { // snes
59+
platform = Emulator::SNES;
60+
} else if (endsWith(rom_path, ".rom")) { // msx
61+
platform = Emulator::MSX;
62+
} else if (endsWith(rom_path, ".wad")) { // doom
63+
platform = Emulator::DOOM;
5264
}
5365
if (platform != Emulator::UNKNOWN) {
5466
// for each row, create rom entry

main/rom_info.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "format.hpp"
88
#include "string_utils.hpp"
99

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

1212
struct RomInfo {
1313
std::string name;

main/sms_cart.hpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#pragma once
2+
3+
#include "cart.hpp"
4+
#include "sms.hpp"
5+
6+
class SmsCart : public Cart {
7+
public:
8+
9+
SmsCart(const Cart::Config& config)
10+
: Cart(config) {
11+
init();
12+
}
13+
14+
~SmsCart() {
15+
deinit();
16+
}
17+
18+
virtual void reset() override {
19+
Cart::reset();
20+
reset_sms();
21+
}
22+
23+
virtual void load() override {
24+
Cart::load();
25+
load_sms(get_save_path());
26+
}
27+
28+
virtual void save() override {
29+
Cart::save();
30+
save_sms(get_save_path(true));
31+
}
32+
33+
virtual void init() override {
34+
Cart::init();
35+
init_sms(get_rom_filename(), romdata_, rom_size_bytes_);
36+
start_sms_tasks();
37+
}
38+
39+
virtual void deinit() override {
40+
stop_sms_tasks();
41+
deinit_sms();
42+
}
43+
44+
virtual bool run() override {
45+
run_sms_rom();
46+
return Cart::run();
47+
}
48+
49+
protected:
50+
// SMS
51+
static constexpr size_t SMS_WIDTH = 256;
52+
static constexpr size_t SMS_HEIGHT = 192;
53+
54+
virtual void pre_menu() override {
55+
Cart::pre_menu();
56+
logger_.info("sms::pre_menu()");
57+
stop_sms_tasks();
58+
}
59+
60+
virtual void post_menu() override {
61+
Cart::post_menu();
62+
logger_.info("sms::post_menu()");
63+
start_sms_tasks();
64+
}
65+
66+
virtual void set_original_video_setting() override {
67+
logger_.info("sms::video: original");
68+
set_sms_video_original();
69+
}
70+
71+
virtual std::pair<size_t, size_t> get_video_size() const override {
72+
return std::make_pair(SMS_WIDTH, SMS_HEIGHT);
73+
}
74+
75+
virtual std::vector<uint8_t> get_video_buffer() const override {
76+
return get_sms_video_buffer();
77+
}
78+
79+
virtual void set_fit_video_setting() override {
80+
logger_.info("sms::video: fit");
81+
set_sms_video_fit();
82+
}
83+
84+
virtual void set_fill_video_setting() override {
85+
logger_.info("sms::video: fill");
86+
set_sms_video_fill();
87+
}
88+
89+
virtual std::string get_save_extension() const override {
90+
switch (info_.platform) {
91+
case Emulator::SEGA_MASTER_SYSTEM:
92+
return "_sms.sav";
93+
case Emulator::SEGA_GAME_GEAR:
94+
return "_gg.sav";
95+
default:
96+
return Cart::get_save_extension();
97+
}
98+
}
99+
};

0 commit comments

Comments
 (0)