/* Copyright (c) 2014, OpenEmu Team Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the OpenEmu Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import "OdysseyGameCore.h" #import "OEOdyssey2SystemResponderClient.h" #import #import #include #include "crc32.h" #include "audio.h" #include "vmachine.h" #include "config.h" #include "vdc.h" #include "cpu.h" #include "debug.h" #include "keyboard.h" #include "voice.h" #include "vpp.h" #include "wrapalleg.h" #include "score.h" #include "libretro.h" @interface OdysseyGameCore () { NSDictionary *virtualPhysicalKeyMap; } @end //uint16_t mbmp[EMUWIDTH * EMUHEIGHT]; //unsigned short int mbmp[TEX_WIDTH * TEX_HEIGHT]; uint16_t *mbmp; //short signed int SNDBUF[1024*2]; uint8_t soundBuffer[1056]; int SND; int RLOOP=0; int joystick_data[2][5]={{0,0,0,0,0},{0,0,0,0,0}}; void update_joy(void){ } int contax, o2flag, g74flag, c52flag, jopflag, helpflag; unsigned long crcx = ~0; static char bios[MAXC], scshot[MAXC], xrom[MAXC], romdir[MAXC], xbios[MAXC], biosdir[MAXC], arkivo[MAXC][MAXC], biossux[MAXC], romssux[MAXC], odyssey2[MAXC], g7400[MAXC], c52[MAXC], jopac[MAXC], file_l[MAXC], bios_l[MAXC], file_v[MAXC],scorefile[MAXC], statefile[MAXC], path2[MAXC]; extern void retro_destroybmp(void); static long filesize(FILE *stream){ long curpos, length; curpos = ftell(stream); fseek(stream, 0L, SEEK_END); length = ftell(stream); fseek(stream, curpos, SEEK_SET); return length; } static void load_bios(const char *biosname){ FILE *fn; static char s[MAXC+10]; unsigned long crc; int i; if ((biosname[strlen(biosname)-1]=='/') || (biosname[strlen(biosname)-1]=='\\') || (biosname[strlen(biosname)-1]==':')) { strcpy(s,biosname); strcat(s,odyssey2); fn = fopen(s,"rb"); if (!fn) { strcpy(s,biosname); strcat(s,odyssey2); fn = fopen(s,"rb"); } } else { strcpy(s,biosname); fn = fopen(biosname,"rb"); } if (!fn) { fprintf(stderr,"Error loading bios ROM (%s)\n",s); exit(EXIT_FAILURE); } if (fread(rom_table[0],1024,1,fn) != 1) { fprintf(stderr,"Error loading bios ROM %s\n",odyssey2); exit(EXIT_FAILURE); } strcpy(s,biosname); fn = fopen(biosname,"rb"); if (!fn) { fprintf(stderr,"Error loading bios ROM (%s)\n",s); exit(EXIT_FAILURE); } if (fread(rom_table[0],1024,1,fn) != 1) { fprintf(stderr,"Error loading bios ROM %s\n",odyssey2); exit(EXIT_FAILURE); } fclose(fn); for (i=1; i<8; i++) memcpy(rom_table[i],rom_table[0],1024); crc = crc32_buf(rom_table[0],1024); if (crc==0x8016A315) { printf("Odyssey2 bios ROM loaded\n"); app_data.vpp = 0; app_data.bios = ROM_O2; } else if (crc==0xE20A9F41) { printf("Videopac+ G7400 bios ROM loaded\n"); app_data.vpp = 1; app_data.bios = ROM_G7400; } else if (crc==0xA318E8D6) { if (!((!o2flag)&&(c52flag))) printf("C52 bios ROM loaded\n"); else printf("Ok\n"); app_data.vpp = 0; app_data.bios = ROM_C52; } else if (crc==0x11647CA5) { if (g74flag) printf("Jopac bios ROM loaded\n"); else printf(" Ok\n"); app_data.vpp = 1; app_data.bios = ROM_JOPAC; } else { printf("Bios ROM loaded (unknown version)\n"); app_data.vpp = 0; app_data.bios = ROM_UNKNOWN; } } static void load_cart(const char *file){ FILE *fn; long l; int i, nb; app_data.crc = crc32_file(file); if (app_data.crc == 0xAFB23F89) app_data.exrom = 1; /* Musician */ if (app_data.crc == 0x3BFEF56B) app_data.exrom = 1; /* Four in 1 Row! */ if (app_data.crc == 0x9B5E9356) app_data.exrom = 1; /* Four in 1 Row! (french) */ if (((app_data.crc == 0x975AB8DA) || (app_data.crc == 0xE246A812)) && (!app_data.debug)) { fprintf(stderr,"Error: file %s is an incomplete ROM dump\n",file_v); exit(EXIT_FAILURE); } fn=fopen(file,"rb"); if (!fn) { fprintf(stderr,"Error loading %s\n",file_v); exit(EXIT_FAILURE); } printf("Loading: \"%s\" Size: ",file_v); l = filesize(fn); if ((l % 1024) != 0) { fprintf(stderr,"Error: file %s is an invalid ROM dump\n",file_v); exit(EXIT_FAILURE); } /* special MegaCART design by Soeren Gust */ if ((l == 32768) || (l == 65536) || (l == 131072) || (l == 262144) || (l == 524288) || (l == 1048576)) { app_data.megaxrom = 1; app_data.bank = 1; megarom = malloc(1048576); if (megarom == NULL) { fprintf(stderr, "Out of memory loading %s\n", file); exit(EXIT_FAILURE); } if (fread(megarom, l, 1, fn) != 1) { fprintf(stderr,"Error loading %s\n",file); exit(EXIT_FAILURE); } /* mirror shorter files into full megabyte */ if (l < 65536) memcpy(megarom+32768,megarom,32768); if (l < 131072) memcpy(megarom+65536,megarom,65536); if (l < 262144) memcpy(megarom+131072,megarom,131072); if (l < 524288) memcpy(megarom+262144,megarom,262144); if (l < 1048576) memcpy(megarom+524288,megarom,524288); /* start in bank 0xff */ memcpy(&rom_table[0][1024], megarom + 4096*255 + 1024, 3072); printf("MegaCart %ldK", l / 1024); nb = 1; } else if (((l % 3072) == 0)) { app_data.three_k = 1; nb = l/3072; for (i=nb-1; i>=0; i--) { if (fread(&rom_table[i][1024],3072,1,fn) != 1) { fprintf(stderr,"Error loading %s\n",file); exit(EXIT_FAILURE); } } printf("%dK",nb*3); } else { nb = l/2048; if ((nb == 2) && (app_data.exrom)) { if (fread(&extROM[0], 1024,1,fn) != 1) { fprintf(stderr,"Error loading %s\n",file); exit(EXIT_FAILURE); } if (fread(&rom_table[0][1024],3072,1,fn) != 1) { fprintf(stderr,"Error loading %s\n",file); exit(EXIT_FAILURE); } printf("3K EXROM"); } else { for (i=nb-1; i>=0; i--) { if (fread(&rom_table[i][1024],2048,1,fn) != 1) { fprintf(stderr,"Error loading %s\n",file); exit(EXIT_FAILURE); } memcpy(&rom_table[i][3072],&rom_table[i][2048],1024); /* simulate missing A10 */ } printf("%dK",nb*2); } } fclose(fn); rom = rom_table[0]; if (nb==1) app_data.bank = 1; else if (nb==2) app_data.bank = app_data.exrom ? 1 : 2; else if (nb==4) app_data.bank = 3; else app_data.bank = 4; if ((rom_table[nb-1][1024+12]=='O') && (rom_table[nb-1][1024+13]=='P') && (rom_table[nb-1][1024+14]=='N') && (rom_table[nb-1][1024+15]=='B')) app_data.openb=1; printf(" CRC: %08lX\n",app_data.crc); } //int suck_bios() //{ // int i; // for (i=0; i