+ char buf[256];
+ int ret;
+
+ // cheat funcs are destructive, need a copy..
+ strncpy(buf, code, sizeof(buf));
+ buf[sizeof(buf) - 1] = 0;
+
+ if (index < NumCheats)
+ ret = EditCheat(index, "", buf);
+ else
+ ret = AddCheat("", buf);
+
+ if (ret != 0)
+ SysPrintf("Failed to set cheat %#u\n", index);
+ else if (index < NumCheats)
+ Cheats[index].Enabled = enabled;
+}
+
+/* multidisk support */
+static bool disk_ejected;
+static unsigned int disk_current_index;
+static struct disks_state {
+ char *fname;
+ int internal_index; // for multidisk eboots
+} disks[8];
+
+static bool disk_set_eject_state(bool ejected)
+{
+ // weird PCSX API..
+ SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
+ LidInterrupt();
+
+ disk_ejected = ejected;
+ return true;
+}
+
+static bool disk_get_eject_state(void)
+{
+ /* can't be controlled by emulated software */
+ return disk_ejected;
+}
+
+static unsigned int disk_get_image_index(void)
+{
+ return disk_current_index;
+}
+
+static bool disk_set_image_index(unsigned int index)
+{
+ if (index >= sizeof(disks) / sizeof(disks[0]))
+ return false;
+
+ CdromId[0] = '\0';
+ CdromLabel[0] = '\0';
+
+ if (disks[index].fname == NULL) {
+ SysPrintf("missing disk #%u\n", index);
+ CDR_shutdown();
+
+ // RetroArch specifies "no disk" with index == count,
+ // so don't fail here..
+ disk_current_index = index;
+ return true;
+ }
+
+ SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
+ disks[index].fname, disks[index].internal_index);
+
+ cdrIsoMultidiskSelect = disks[index].internal_index;
+ set_cd_image(disks[index].fname);
+ if (ReloadCdromPlugin() < 0) {
+ SysPrintf("failed to load cdr plugin\n");
+ return false;
+ }
+ if (CDR_open() < 0) {
+ SysPrintf("failed to open cdr plugin\n");
+ return false;
+ }
+
+ if (!disk_ejected) {
+ SetCdOpenCaseTime(time(NULL) + 2);
+ LidInterrupt();
+ }
+
+ disk_current_index = index;
+ return true;
+}
+
+static unsigned int disk_get_num_images(void)
+{
+ unsigned int count = 0;
+ size_t i;
+
+ for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++)
+ if (disks[i].fname != NULL)
+ count++;
+
+ return count;
+}
+
+static bool disk_replace_image_index(unsigned index,
+ const struct retro_game_info *info)
+{
+ char *old_fname;
+ bool ret = true;
+
+ if (index >= sizeof(disks) / sizeof(disks[0]))
+ return false;
+
+ old_fname = disks[index].fname;
+ disks[index].fname = NULL;
+ disks[index].internal_index = 0;
+
+ if (info != NULL) {
+ disks[index].fname = strdup(info->path);
+ if (index == disk_current_index)
+ ret = disk_set_image_index(index);
+ }
+
+ if (old_fname != NULL)
+ free(old_fname);
+
+ return ret;
+}
+
+static bool disk_add_image_index(void)
+{
+ // TODO??
+ return true;