+++ /dev/null
-\r
-// This file is part of the PicoDrive Megadrive Emulator\r
-\r
-// Copyright (c) 2011 FinalDave (emudave (at) gmail.com)\r
-\r
-// This code is licensed under the GNU General Public License version 2.0 and the MAME License.\r
-// You can choose the license that has the most advantages for you.\r
-\r
-// SVN repository can be found at http://code.google.com/p/cyclone68000/\r
-\r
-#include "PicoInt.h"\r
-\r
-static void Byteswap(unsigned char *data,int len)\r
-{\r
- int i=0;\r
-\r
- if (len<2) return; // Too short\r
-\r
- do\r
- {\r
- unsigned short *pd=(unsigned short *)(data+i);\r
- int value=*pd; // Get 2 bytes\r
-\r
- value=(value<<8)|(value>>8); // Byteswap it\r
- *pd=(unsigned short)value; // Put 2b ytes\r
- i+=2;\r
- } \r
- while (i+2<=len);\r
-}\r
-\r
-// Interleve a 16k block and byteswap\r
-static int InterleveBlock(unsigned char *dest,unsigned char *src)\r
-{\r
- int i=0;\r
- for (i=0;i<0x2000;i++) dest[(i<<1) ]=src[ i]; // Odd\r
- for (i=0;i<0x2000;i++) dest[(i<<1)+1]=src[0x2000+i]; // Even\r
- return 0;\r
-}\r
-\r
-// Decode a SMD file\r
-static int DecodeSmd(unsigned char *data,int len)\r
-{\r
- unsigned char *temp=NULL;\r
- int i=0;\r
-\r
- temp=(unsigned char *)malloc(0x4000);\r
- if (temp==NULL) return 1;\r
- memset(temp,0,0x4000);\r
-\r
- // Interleve each 16k block and shift down by 0x200:\r
- for (i=0; i+0x4200<=len; i+=0x4000)\r
- {\r
- InterleveBlock(temp,data+0x200+i); // Interleve 16k to temporary buffer\r
- memcpy(data+i,temp,0x4000); // Copy back in\r
- }\r
-\r
- free(temp);\r
- return 0;\r
-}\r
-\r
-int PicoCartLoad(FILE *f,unsigned char **prom,unsigned int *psize)\r
-{\r
- unsigned char *rom=NULL; int size=0;\r
- if (f==NULL) return 1;\r
-\r
- fseek(f,0,SEEK_END); size=ftell(f); fseek(f,0,SEEK_SET);\r
-\r
- size=(size+3)&~3; // Round up to a multiple of 4\r
-\r
- // Allocate space for the rom plus padding\r
- rom=(unsigned char *)malloc(size+4);\r
- if (rom==NULL) { fclose(f); return 1; }\r
- memset(rom,0,size+4);\r
-\r
- fread(rom,1,size,f); // Load up the rom\r
- fclose(f);\r
-\r
- // Check for SMD:\r
- if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD\r
- else Byteswap(rom,size); // Just byteswap\r
- \r
- if (prom) *prom=rom;\r
- if (psize) *psize=size;\r
-\r
- return 0;\r
-}\r
-\r
-// Insert/remove a cartridge:\r
-int PicoCartInsert(unsigned char *rom,unsigned int romsize)\r
-{\r
- // Make sure movie playing/recording is stopped:\r
- if (PmovFile) fclose(PmovFile);\r
- PmovFile=NULL; PmovAction=0;\r
-\r
- memset(&Pico,0,sizeof(Pico)); // Blank Pico state\r
- Pico.rom=rom;\r
- Pico.romsize=romsize;\r
- PicoReset();\r
-\r
- return 0;\r
-}\r