full ym2612 save/load for 940
authornotaz <notasas@gmail.com>
Wed, 25 Jun 2008 21:53:53 +0000 (21:53 +0000)
committernotaz <notasas@gmail.com>
Wed, 25 Jun 2008 21:53:53 +0000 (21:53 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@495 be3aeb3a-fb24-0410-a615-afba39da0efa

gp2x/940ctl.c
gp2x/940ctl.h

index 4a571ff..b372d92 100644 (file)
@@ -33,7 +33,7 @@ _940_ctl_t *shared_ctl = 0;
 unsigned char *mp3_mem = 0;\r
 \r
 #define MP3_SIZE_MAX (0x400000 + 0x800000) // 12M\r
-#define CODE940_FILE "pico940_v2.bin"\r
+#define CODE940_FILE "pico940_v3.bin"\r
 \r
 int crashed_940 = 0;\r
 \r
@@ -69,7 +69,8 @@ int YM2612Write_940(unsigned int a, unsigned int v, int scanline)
 \r
        //printf("%05i:%03i: ym w ([%i] %02x)\n", Pico.m.frame_count, Pico.m.scanline, a, v);\r
 \r
-       switch (a) {\r
+       switch (a)\r
+       {\r
                case 0: /* address port 0 */\r
                        if (addr_A1 == 0 && ST_address == v)\r
                                return 0; /* address already selected, don't send this command to 940 */\r
@@ -186,6 +187,61 @@ void YM2612PicoStateLoad_940(void)
        addr_A1 = *(INT32 *) (REGS + 0x200);\r
 }\r
 \r
+void YM2612PicoStateSave2_940(int tat, int tbt)\r
+{\r
+       UINT8 *ym_remote_regs, *ym_local_regs;\r
+       add_job_940(JOB940_PICOSTATESAVE2);\r
+       if (CHECK_BUSY(JOB940_PICOSTATESAVE2)) wait_busy_940(JOB940_PICOSTATESAVE2);\r
+\r
+       ym_remote_regs = (UINT8 *) shared_ctl->writebuff0;\r
+       ym_local_regs  = YM2612GetRegs();\r
+       if (*(UINT32 *)(ym_remote_regs + 0x100) != 0x41534d59) {\r
+               printf("code940 didn't return valid save data\n");\r
+               return;\r
+       }\r
+\r
+       /* copy addin data only */\r
+       memcpy(ym_local_regs,         ym_remote_regs,         0x20);\r
+       memcpy(ym_local_regs + 0x100, ym_remote_regs + 0x100, 0x30);\r
+       memcpy(ym_local_regs + 0x0b8, ym_remote_regs + 0x0b8, 0x48);\r
+       memcpy(ym_local_regs + 0x1b8, ym_remote_regs + 0x1b8, 0x48);\r
+       *(INT32 *)(ym_local_regs + 0x108) = tat;\r
+       *(INT32 *)(ym_local_regs + 0x10c) = tbt;\r
+}\r
+\r
+int YM2612PicoStateLoad2_940(int *tat, int *tbt)\r
+{\r
+       UINT8 *ym_remote_regs, *ym_local_regs;\r
+       ym_local_regs  = YM2612GetRegs();\r
+       ym_remote_regs = (UINT8 *) shared_ctl->writebuff0;\r
+\r
+       if (*(UINT32 *)(ym_local_regs + 0x100) != 0x41534d59)\r
+               return -1;\r
+\r
+       *tat = *(INT32 *)(ym_local_regs + 0x108);\r
+       *tbt = *(INT32 *)(ym_local_regs + 0x10c);\r
+\r
+       if (CHECK_BUSY(JOB940_YM2612UPDATEONE)) wait_busy_940(JOB940_YM2612UPDATEONE);\r
+\r
+       /* flush writes */\r
+       if (shared_ctl->writebuffsel == 1) {\r
+               shared_ctl->writebuff0[writebuff_ptr & 0xffff] = 0xffff;\r
+       } else {\r
+               shared_ctl->writebuff1[writebuff_ptr & 0xffff] = 0xffff;\r
+       }\r
+       shared_ctl->writebuffsel ^= 1;\r
+       writebuff_ptr = 0;\r
+       add_job_940(JOB940_PICOSTATELOAD2_PREP);\r
+       if (CHECK_BUSY(JOB940_PICOSTATELOAD2_PREP)) wait_busy_940(JOB940_PICOSTATELOAD2_PREP);\r
+\r
+       memcpy(ym_remote_regs, ym_local_regs, 0x200);\r
+\r
+       add_job_940(JOB940_PICOSTATELOAD2);\r
+       if (CHECK_BUSY(JOB940_PICOSTATELOAD2)) wait_busy_940(JOB940_PICOSTATELOAD2);\r
+\r
+       return 0;\r
+}\r
+\r
 \r
 static void internal_reset(void)\r
 {\r
@@ -200,7 +256,7 @@ void sharedmem_init(void)
        if (shared_mem != NULL) return;\r
 \r
        shared_mem = (unsigned char *) mmap(0, 0x210000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x2000000);\r
-       if(shared_mem == MAP_FAILED)\r
+       if (shared_mem == MAP_FAILED)\r
        {\r
                printf("mmap(shared_data) failed with %i\n", errno);\r
                exit(1);\r
@@ -230,7 +286,6 @@ void sharedmem_deinit(void)
 \r
 extern char **g_argv;\r
 \r
-/* none of the functions in this file should be called before this one */\r
 void YM2612Init_940(int baseclock, int rate)\r
 {\r
        printf("YM2612Init_940()\n");\r
index 3251282..f845819 100644 (file)
@@ -9,3 +9,5 @@ int  YM2612Write_940(unsigned int a, unsigned int v, int scanline);
 \r
 int  YM2612PicoTick_940(int n);\r
 void YM2612PicoStateLoad_940(void);\r
+void YM2612PicoStateSave2_940(int tat, int tbt);\r
+int  YM2612PicoStateLoad2_940(int *tat, int *tbt);\r