4 static void Byteswap(unsigned char *data,int len)
\r
8 if (len<2) return; // Too short
\r
12 unsigned short *pd=(unsigned short *)(data+i);
\r
13 int value=*pd; // Get 2 bytes
\r
15 value=(value<<8)|(value>>8); // Byteswap it
\r
16 *pd=(unsigned short)value; // Put 2b ytes
\r
22 // Interleve a 16k block and byteswap
\r
23 static int InterleveBlock(unsigned char *dest,unsigned char *src)
\r
26 for (i=0;i<0x2000;i++) dest[(i<<1) ]=src[ i]; // Odd
\r
27 for (i=0;i<0x2000;i++) dest[(i<<1)+1]=src[0x2000+i]; // Even
\r
31 // Decode a SMD file
\r
32 static int DecodeSmd(unsigned char *data,int len)
\r
34 unsigned char *temp=NULL;
\r
37 temp=(unsigned char *)malloc(0x4000);
\r
38 if (temp==NULL) return 1;
\r
39 memset(temp,0,0x4000);
\r
41 // Interleve each 16k block and shift down by 0x200:
\r
42 for (i=0; i+0x4200<=len; i+=0x4000)
\r
44 InterleveBlock(temp,data+0x200+i); // Interleve 16k to temporary buffer
\r
45 memcpy(data+i,temp,0x4000); // Copy back in
\r
52 int PicoCartLoad(FILE *f,unsigned char **prom,unsigned int *psize)
\r
54 unsigned char *rom=NULL; int size=0;
\r
55 if (f==NULL) return 1;
\r
57 fseek(f,0,SEEK_END); size=ftell(f); fseek(f,0,SEEK_SET);
\r
59 size=(size+3)&~3; // Round up to a multiple of 4
\r
61 // Allocate space for the rom plus padding
\r
62 rom=(unsigned char *)malloc(size+4);
\r
63 if (rom==NULL) { fclose(f); return 1; }
\r
64 memset(rom,0,size+4);
\r
66 fread(rom,1,size,f); // Load up the rom
\r
70 if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD
\r
71 else Byteswap(rom,size); // Just byteswap
\r
73 if (prom) *prom=rom;
\r
74 if (psize) *psize=size;
\r
79 // Insert/remove a cartridge:
\r
80 int PicoCartInsert(unsigned char *rom,unsigned int romsize)
\r
82 // Make sure movie playing/recording is stopped:
\r
83 if (PmovFile) fclose(PmovFile);
\r
84 PmovFile=NULL; PmovAction=0;
\r
86 memset(&Pico,0,sizeof(Pico)); // Blank Pico state
\r
88 Pico.romsize=romsize;
\r