Skip to content

Commit 079ff31

Browse files
committed
[mcp] New tool to list the most recent media
1 parent 777600e commit 079ff31

7 files changed

Lines changed: 79 additions & 23 deletions

File tree

MCP_README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ The server exposes tools organized in the following categories:
323323

324324
### Media & State Management
325325
- `get_media_info` - Get loaded ROM/CD info
326+
- `list_recent_media` - List the 10 most recent ROM files or CD-ROM images opened by Geargrafx
326327
- `load_media` - Load ROM file or CD-ROM image (.pce, .sgx, .hes, .cue, .zip). Automatically loads .sym symbol file if present
327328
- `load_bios` - Load a BIOS file for CD-ROM emulation. Two types: 'syscard' (System Card, 256KB) and 'gameexpress' (Game Express, 32KB)
328329
- `load_symbols` - Load debug symbols from file (.sym format with 'BANK:ADDRESS LABEL' entries)

platforms/shared/desktop/config.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,29 @@ void config_load_defaults(void)
206206
config_write();
207207
}
208208

209+
void config_push_recent_media(const std::string& path)
210+
{
211+
if (path.empty())
212+
return;
213+
214+
int slot = 0;
215+
for (slot = 0; slot < config_max_recent_roms; slot++)
216+
{
217+
if (config_emulator.recent_roms[slot].compare(path) == 0)
218+
break;
219+
}
220+
221+
if (slot >= config_max_recent_roms)
222+
slot = config_max_recent_roms - 1;
223+
224+
for (int index = slot; index > 0; index--)
225+
{
226+
config_emulator.recent_roms[index] = config_emulator.recent_roms[index - 1];
227+
}
228+
229+
config_emulator.recent_roms[0] = path;
230+
}
231+
209232
void config_read(void)
210233
{
211234
if (!config_ini_file->read(config_ini_data))

platforms/shared/desktop/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ EXTERN void config_destroy(void);
310310
EXTERN void config_read(void);
311311
EXTERN void config_write(void);
312312
EXTERN void config_load_defaults(void);
313+
EXTERN void config_push_recent_media(const std::string& path);
313314
EXTERN void config_update_hotkey_string(config_Hotkey* hotkey);
314315

315316
#undef CONFIG_IMPORT

platforms/shared/desktop/gui.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static bool loading_rom_active = false;
5252
static char loading_rom_path[4096] = "";
5353
static bool loading_physical_cdrom = false;
5454
static void main_window(void);
55-
static void push_recent_rom(std::string path);
5655
static void show_status_message(void);
5756
static void show_error_window(void);
5857
static void show_loading_popup(void);
@@ -445,7 +444,7 @@ void gui_load_rom(const char* path)
445444
loading_physical_cdrom = false;
446445

447446
gui_debug_auto_save_settings();
448-
push_recent_rom(path);
447+
config_push_recent_media(path);
449448
emu_resume();
450449

451450
strncpy(loading_rom_path, path, sizeof(loading_rom_path) - 1);
@@ -638,27 +637,6 @@ static void main_window(void)
638637
ImGui::PopStyleVar();
639638
}
640639

641-
static void push_recent_rom(std::string path)
642-
{
643-
int slot = 0;
644-
for (slot = 0; slot < config_max_recent_roms; slot++)
645-
{
646-
if (config_emulator.recent_roms[slot].compare(path) == 0)
647-
{
648-
break;
649-
}
650-
}
651-
652-
slot = MIN(slot, config_max_recent_roms - 1);
653-
654-
for (int i = slot; i > 0; i--)
655-
{
656-
config_emulator.recent_roms[i] = config_emulator.recent_roms[i - 1];
657-
}
658-
659-
config_emulator.recent_roms[0] = path;
660-
}
661-
662640
static void show_status_message(void)
663641
{
664642
if (status_message_active)

platforms/shared/desktop/mcp/mcp_debug_adapter.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ static void get_mouse_motion_delta(const std::string& button, int* delta_x, int*
5959
*delta_x = k_mcp_mouse_motion_step;
6060
}
6161

62+
static std::string get_file_name_from_path(const std::string& path)
63+
{
64+
size_t position = path.find_last_of("/\\");
65+
66+
if (position == std::string::npos)
67+
return path;
68+
69+
return path.substr(position + 1);
70+
}
71+
6272
struct DisassemblerBookmark
6373
{
6474
u16 address;
@@ -675,6 +685,31 @@ json DebugAdapter::GetMediaInfo()
675685
return info;
676686
}
677687

688+
json DebugAdapter::ListRecentMedia()
689+
{
690+
json result;
691+
json recent_media = json::array();
692+
693+
for (int index = 0; index < config_max_recent_roms; index++)
694+
{
695+
const std::string& path = config_emulator.recent_roms[index];
696+
697+
if (path.empty())
698+
continue;
699+
700+
json entry;
701+
entry["index"] = index;
702+
entry["file_path"] = path;
703+
entry["file_name"] = get_file_name_from_path(path);
704+
recent_media.push_back(entry);
705+
}
706+
707+
result["count"] = recent_media.size();
708+
result["recent_media"] = recent_media;
709+
710+
return result;
711+
}
712+
678713
json DebugAdapter::GetHuC6280Status()
679714
{
680715
json status;
@@ -1449,6 +1484,8 @@ json DebugAdapter::LoadMedia(const std::string& file_path)
14491484
result["is_cdrom"] = m_core->GetMedia()->IsCDROM();
14501485
result["is_sgx"] = m_core->GetMedia()->IsSGX();
14511486

1487+
config_push_recent_media(file_path);
1488+
14521489
return result;
14531490
}
14541491

platforms/shared/desktop/mcp/mcp_debug_adapter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class DebugAdapter
139139

140140
// Media and state management
141141
json GetMediaInfo();
142+
json ListRecentMedia();
142143
json LoadMedia(const std::string& file_path);
143144
json LoadBios(const std::string& file_path, bool syscard);
144145
json ListSaveStateSlots();

platforms/shared/desktop/mcp/mcp_server.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,17 @@ void McpServer::HandleToolsList(const json& request)
551551
}}
552552
});
553553

554+
tools.push_back({
555+
{"name", "list_recent_media"},
556+
{"title", "List Recent Media"},
557+
{"description", "List the 10 most recent ROMs or CD-ROM images opened by Geargrafx. Use file_path from an entry with load_media to reopen it"},
558+
{"inputSchema", {
559+
{"type", "object"},
560+
{"properties", json::object()},
561+
{"additionalProperties", false}
562+
}}
563+
});
564+
554565
// Chip status tools
555566
tools.push_back({
556567
{"name", "get_huc6280_status"},
@@ -1862,6 +1873,10 @@ json McpServer::ExecuteCommand(const std::string& toolName, const json& argument
18621873
{
18631874
return m_debugAdapter.GetMediaInfo();
18641875
}
1876+
else if (normalizedTool == "list_recent_media")
1877+
{
1878+
return m_debugAdapter.ListRecentMedia();
1879+
}
18651880
// Chip status
18661881
else if (normalizedTool == "get_huc6280_status")
18671882
{

0 commit comments

Comments
 (0)