diff --git a/zsnes/src/chips/sa1regs.asm b/zsnes/src/chips/sa1regs.asm index 3230f70e..fb9fb3de 100644 --- a/zsnes/src/chips/sa1regs.asm +++ b/zsnes/src/chips/sa1regs.asm @@ -43,7 +43,8 @@ EXTSYM regptr,regptw,romdata,SA1Status,debstop4,SDD1BankA,curromsize EXTSYM debuggeron EXTSYM Get_Time,Get_TimeDate EXTSYM spc7110romptr,SPC7110Entries -EXTSYM SPC7110IndexSize,SPC7110nfname +EXTSYM SPC7110IndexSize,SPC7110nfname,SPC7110filep +EXTSYM SPC7_Convert_Upper,SPC7_Convert_Lower EXTSYM Open_File,Close_File,Read_File,File_Seek ; EXTSYM Msgptr,MessageOn EXTSYM irqv2,irqv,nmiv2,nmiv @@ -774,8 +775,8 @@ SPC4806w: mov [SPC7110TempPosition],eax mov eax,[edx+8] mov [SPC7110TempLength],eax - mov edx,SPC7110nfname - add edx,9 + + mov edx,dword[SPC7110filep] mov eax,[SPCCompPtr] and eax,0FFFFFFh mov ecx,6 @@ -796,7 +797,18 @@ SPC4806w: mov edx,SPC7110nfname call Open_File + jnc .nocaseerror + pushad + call SPC7_Convert_Upper + popad + call Open_File + jnc .nocaseerror + pushad + call SPC7_Convert_Lower + popad + call Open_File jc .error +.nocaseerror mov bx,ax mov dx,[SPC7110TempPosition] mov cx,[SPC7110TempPosition+2] diff --git a/zsnes/src/init.asm b/zsnes/src/init.asm index da699afa..ec8767b2 100644 --- a/zsnes/src/init.asm +++ b/zsnes/src/init.asm @@ -125,6 +125,7 @@ EXTSYM MirrorROM EXTSYM SplittedROM EXTSYM addOnStart EXTSYM addOnSize +EXTSYM SPC7PackIndexLoad,SPC7110IndexSize EXTSYM SetaCmdEnable,setaramdata EXTSYM setaaccessbankr8,setaaccessbankw8,setaaccessbankr8a,setaaccessbankw8a @@ -3029,21 +3030,16 @@ SECTION .text SECTION .data -SPC7110DIRA db 'FEOEZSP7',0 -SPC7110DIRB db 'SMHT-SP7',0 SDD1DIRA db 'SOCNSDD1',0 SDD1DIRB db 'SFZ2SDD1',0 SDD1DIRC db 'SFA2SDD1',0 SDD1DIRD db 'SF2ESDD1',0 -SPC7110IndexName db 'index.bin',0 SPC7110DirEntry db '*.bin',0 NEWSYM SDD1Offset, dd 65536*8 %ifndef __LINUX__ NEWSYM SDD1nfname, db ' \_00000-0.bin',0 -NEWSYM SPC7110nfname, db ' \ .bin',0 %else NEWSYM SDD1nfname, db ' /_00000-0.bin',0 -NEWSYM SPC7110nfname, db ' / .bin',0 %endif NEWSYM SDD1ifname, db 'sdd1gfx.idx',0 NEWSYM SDD1dfname, db 'sdd1gfx.dat',0 @@ -3056,7 +3052,6 @@ SECTION .bss SPC7110Allocated resb 1 SPC7110CPtr resd 1 SPC7110CPtr2 resd 1 -NEWSYM SPC7110IndexSize, resd 1 NEWSYM SPC7110Entries, resd 1 SDD1PatchAddr resd 1 SDD1PatchOfs resd 1 @@ -3119,31 +3114,12 @@ NEWSYM SPC7110Load .noSDD1a ret .spc7110 - mov edx,SPC7110DIRA - cmp al,0F9h - je .noSPC7110b - mov edx,SPC7110DIRB -.noSPC7110b - mov eax,[edx] - mov [SPC7110nfname],eax - mov eax,[edx+4] - mov [SPC7110nfname+4],eax - call Change_Single_Dir - jc near .nodir - mov edx,SPC7110IndexName - call Open_File - jc near .noindex - mov bx,ax - mov edx,[romdata] - add edx,580000h - mov ecx,12*32768 - call Read_File - mov [SPC7110IndexSize],eax - call Close_File - mov dword[SPC7110Entries],0 - mov edx,PrevDir - call Change_Single_Dir - ret + pushad + call SPC7PackIndexLoad + popad + cmp dword[SPC7110IndexSize],0 + je .nodir + ret .sdd1b cmp byte[SPC7110Allocated],0 jne .notalloc diff --git a/zsnes/src/initc.c b/zsnes/src/initc.c index ebe66db0..ade70a76 100755 --- a/zsnes/src/initc.c +++ b/zsnes/src/initc.c @@ -19,11 +19,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #ifdef __LINUX__ #include "gblhdr.h" +#define DIR_SLASH "/" #else #include #include #include #include +#define DIR_SLASH "\\" #endif #include "zip/zunzip.h" @@ -46,6 +48,17 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define Mbit_bytes 0x20000 + +void Debug_WriteString(char *str) +{ + FILE *fp = 0; + fp = fopen("zsnes.dbg", "w"); + if (!fp) { return; } + fputs(str, fp); + fclose(fp); +} + + //I want to port over the more complicated //functions from init.asm, or replace with //better versions from NSRT. -Nach @@ -414,16 +427,16 @@ void loadFile(char *filename) stat_results.st_size -= 512; fseek(fp, 512, SEEK_SET); } - + fread(ROM+curromspace, stat_results.st_size, 1, fp); fclose(fp); - + curromspace += stat_results.st_size; - + if (!multifile) { return; } (*incrementer)++; - } + } else { return; @@ -546,7 +559,7 @@ void loadZipFile(char *filename) { //Sets current file to the file we liked before if (unzLocateFile(zipfile, ourFile, 1) != UNZ_OK) - { + { if (NSS) { (*incrementer)--; @@ -638,7 +651,7 @@ void SplitSetup(char *basepath, char *basefile, unsigned int MirrorSystem) loadFile(basepath); } } - + if ((curromspace & 0x7FFF) == 512) { memmove(ROM, ROM+512, addOnStart); @@ -676,7 +689,7 @@ void SplitSupport() unsigned char *ROM = (unsigned char *)romdata; SplittedROM = false; - //Same Game add on + //Same Game add on if (ROM[Hi+26] == 0x33 && curromspace == 0x80000 && !ROM[Hi+21] && !ROM[Hi+22] && !ROM[Hi+23]) { @@ -748,7 +761,7 @@ void loadROM() { char *ext = ZOpenFileName+strlen(ZOpenFileName)-4; if (!strcasecmp(ext, ".zip")) - { + { isCompressed = true; isZip = true; loadZipFile(ZOpenFileName); @@ -759,23 +772,23 @@ void loadROM() { char *ext = ZOpenFileName+strlen(ZOpenFileName)-3; if (!strcasecmp(ext, ".gz")) - { + { isCompressed = true; loadGZipFile(ZOpenFileName); } } - + if (!isCompressed) { loadFile(ZOpenFileName); } Header512 = false; - + if (!curromspace) { return; } - + if (!strncmp("GAME DOCTOR SF 3", (char *)romdata, 16) || !strncmp("SUPERUFO", (char *)romdata+8, 8)) - { + { Header512 = true; - } + } else { int HeadRemain = (curromspace & 0x7FFF); @@ -783,7 +796,7 @@ void loadROM() { case 0: break; - + case 512: Header512 = true; break; @@ -1274,3 +1287,82 @@ void Setper2exec() opexec358cph = (unsigned char)(opexec358cph*(per2exec*0.01)); } +extern char FEOEZPath[1024]; +extern char SJNSPath[1024]; +extern char MDHPath[1024]; +extern char SPL4Path[1024]; +char *SPC7110filep; +char SPC7110nfname[1024+12]; //12 is / plus 6.3 +unsigned int SPC7110IndexSize; +extern unsigned int SPC7110Entries; +void SPC7PackIndexLoad() +{ + unsigned char *ROM = (unsigned char *)romdata; + FILE *fp = 0; + SPC7110IndexSize = 0; + + //Get correct path for the ROM we just loaded + if (!strncmp(ROM+infoloc, "HU TENGAI MAKYO ZERO ", 21)) + { + strcpy(SPC7110nfname, *FEOEZPath ? FEOEZPath : "FEOEZSP7"); + } + else if (!strncmp(ROM+infoloc, "JUMP TENGAIMAKYO ZERO", 21)) + { + strcpy(SPC7110nfname, *SJNSPath ? SJNSPath : "SJNS-SP7"); + } + else if (!strncmp(ROM+infoloc, "MOMOTETSU HAPPY ", 21)) + { + strcpy(SPC7110nfname, *MDHPath ? MDHPath : "MDH-SP7"); + } + else if (!strncmp(ROM+infoloc, "SUPER POWER LEAG 4 ", 21)) + { + strcpy(SPC7110nfname, *SPL4Path ? SPL4Path : "SPL4-SP7"); + } + + //Add a slash if needed + if (SPC7110nfname[strlen(SPC7110nfname)-1] != *DIR_SLASH) + { + strcat(SPC7110nfname, DIR_SLASH); + } + + //Set the pointer to after the slash - needed for sa1regs.asm + SPC7110filep = SPC7110nfname+strlen(SPC7110nfname); + + //Index file; + strcat(SPC7110nfname, "index.bin"); + + //Load the index + fp = fopen(SPC7110nfname, "rb"); + if (!fp) { return; } + SPC7110IndexSize = fread(ROM+0x580000, 1, 12*32768, fp); + fclose(fp); + + SPC7110Entries = 0; + + //Get file pointer ready for individual pack files + strcpy(SPC7110filep, "123456.bin"); //Extension Lower Case +} + +void SPC7_Convert_Upper() +{ + char *i = SPC7110filep; + while (*i) + { + if (islower(*i)) { *i = toupper(*i); } //To make extension Upper case + i++; + } +} + +void SPC7_Convert_Lower() +{ + char *i = SPC7110filep; + while (*i) + { + if (isupper(*i)) { *i = tolower(*i); } //To make everything Lower case + i++; + } +} + + + +