Fix multiline support
[picodrive.git] / platform / libretro / libretro.c
index 73733fd..0f060e6 100644 (file)
@@ -713,7 +713,7 @@ void retro_cheat_reset(void)
        PicoPatchUnload();
 }
 
-void retro_cheat_set(unsigned index, bool enabled, const char *buff)
+void retro_cheat_set(unsigned index, bool enabled, const char *code)
 {
        struct patch
        {
@@ -721,11 +721,22 @@ void retro_cheat_set(unsigned index, bool enabled, const char *buff)
                unsigned short data;
        } pt;
        int array_len = 0;
+       char *buff;
+       bool multiline=0;
 
        //TODO: Split multi-line codes properly
+       if (strstr(code,"+")){
+               multiline=1;
+               buff = strtok(code,"+");
+       } else {
+               buff=code;
+       }
 
+       while (buff != NULL)
+       {
                decode(buff, &pt);
-               if (pt.addr == (unsigned int)-1 || pt.data == (unsigned short)-1){
+               if (pt.addr == (unsigned int)-1 || pt.data == (unsigned short)-1)
+               {
                        log_cb(RETRO_LOG_ERROR,"CHEATS: Invalid code: %s\n",buff);
                        return;
                }
@@ -754,6 +765,10 @@ void retro_cheat_set(unsigned index, bool enabled, const char *buff)
                else
                        PicoPatches[PicoPatchCount].data_old = (unsigned short) m68k_read16(PicoPatches[PicoPatchCount].addr);
                PicoPatchCount++;
+
+               if (!multiline)
+                       break;
+       }
 }
 
 /* multidisk support */