New loading code.

This commit is contained in:
n-a-c-h
2003-11-29 20:21:49 +00:00
parent 88e52e34e8
commit 418dc55d27
7 changed files with 357 additions and 871 deletions

View File

@@ -54,9 +54,9 @@ WINOBJ=${WINDIR}/copyvwin.o \
WINDOSOBJ=${DOSDIR}/debug.o ${DOSDIR}/joy.o ${DOSDIR}/modemrtn.o ${DOSDIR}/vesa2.o\ WINDOSOBJ=${DOSDIR}/debug.o ${DOSDIR}/joy.o ${DOSDIR}/modemrtn.o ${DOSDIR}/vesa2.o\
${DOSDIR}/initvid.o ${DOSDIR}/sw.o ${DOSDIR}/gppro.o ${DOSDIR}/vesa12.o ${DOSDIR}/initvid.o ${DOSDIR}/sw.o ${DOSDIR}/gppro.o ${DOSDIR}/vesa12.o
#PREOBJ=${OBJDIR}/unzip.o ${OBJDIR}/zzip.o ${DOSDIR}/zsipx.o #PREOBJ=${OBJDIR}/unzip.o ${DOSDIR}/zsipx.o
ZIPOBJ=${ZIPDIR}/zzip.o ${ZIPDIR}/unzip.o ${ZIPDIR}/zpng.o ZIPOBJ=${ZIPDIR}/unzip.o ${ZIPDIR}/zpng.o
EFFECTSOBJ=${EFFECTSDIR}/burn.o ${EFFECTSDIR}/water.o ${EFFECTSDIR}/smoke.o EFFECTSOBJ=${EFFECTSDIR}/burn.o ${EFFECTSDIR}/water.o ${EFFECTSDIR}/smoke.o
@@ -79,7 +79,6 @@ ALL: @ZSNESEXE@
${ZIPDIR}/zpng.o: ${ZIPDIR}/zpng.c ${ZIPDIR}/zpng.h ${ZIPDIR}/zpng.o: ${ZIPDIR}/zpng.c ${ZIPDIR}/zpng.h
${ZIPDIR}/unzip.o: ${ZIPDIR}/unzip.c ${ZIPDIR}/zunzip.h ${ZIPDIR}/unzip.o: ${ZIPDIR}/unzip.c ${ZIPDIR}/zunzip.h
${ZIPDIR}/zzip.o: ${ZIPDIR}/zzip.c ${ZIPDIR}/zunzip.h
${EFFECTSDIR}/water.o: ${EFFECTSDIR}/water.c ${EFFECTSDIR}/fixsin.h gblhdr.h ${EFFECTSDIR}/water.o: ${EFFECTSDIR}/water.c ${EFFECTSDIR}/fixsin.h gblhdr.h
${EFFECTSDIR}/smoke.o: ${EFFECTSDIR}/smoke.c ${EFFECTSDIR}/smoke.o: ${EFFECTSDIR}/smoke.c
${EFFECTSDIR}/burn.o: ${EFFECTSDIR}/burn.c ${EFFECTSDIR}/burn.o: ${EFFECTSDIR}/burn.c
@@ -183,8 +182,8 @@ endmem.o: endmem.asm macros.mac
${DOSDIR}/modemrtn.o: ${DOSDIR}/modemrtn.asm macros.mac ${DOSDIR}/modemrtn.o: ${DOSDIR}/modemrtn.asm macros.mac
install: install:
@INSTALL@ -m 0755 @ZSNESEXE@ @prefix@/bin @INSTALL@ -D -m 0755 @ZSNESEXE@ @prefix@/bin
@INSTALL@ -m 0644 linux/zsnes.1 @prefix@/man/man1 @INSTALL@ -D -m 0644 linux/zsnes.1 @prefix@/man/man1
uninstall: uninstall:
rm -f @prefix@/bin/$(notdir @ZSNESEXE@) @prefix@/man/man5/zsnes.5 rm -f @prefix@/bin/$(notdir @ZSNESEXE@) @prefix@/man/man5/zsnes.5

View File

@@ -113,6 +113,16 @@ EXTSYM sramaccessbankw8,sramaccessbankw8s,GenerateBank0TableSA1
EXTSYM ScrDispl,wramreadptr,wramwriteptr EXTSYM ScrDispl,wramreadptr,wramwriteptr
EXTSYM pl1Ltk,pl1Rtk,pl2Ltk,pl2Rtk,pl3Ltk,pl3Rtk,pl4Ltk,pl4Rtk,pl5Ltk,pl5Rtk EXTSYM pl1Ltk,pl1Rtk,pl2Ltk,pl2Rtk,pl3Ltk,pl3Rtk,pl4Ltk,pl4Rtk,pl5Ltk,pl5Rtk
EXTSYM loadstate2, headerhack EXTSYM loadstate2, headerhack
;initc.c
EXTSYM clearmem
EXTSYM PatchUsingIPS
EXTSYM loadZipFile
EXTSYM ZOpenFileName
EXTSYM loadROM
EXTSYM CalcChecksum
EXTSYM BankCheck
EXTSYM MirrorROM
%ifdef __LINUX__ %ifdef __LINUX__
EXTSYM LoadDir, popdir, pushdir EXTSYM LoadDir, popdir, pushdir
%endif %endif
@@ -192,7 +202,6 @@ NEWSYM init
dec ecx dec ecx
jnz .rbackupl jnz .rbackupl
mov byte[virqnodisable],0 mov byte[virqnodisable],0
EXTSYM clearmem
pushad pushad
call clearmem call clearmem
popad popad
@@ -488,6 +497,7 @@ ebm db 166,95,66,223,17,11,103,180,156,68,108,120,138,55,203,205,178,210,39,252,
SECTION .text SECTION .text
;******************************************************* ;*******************************************************
; Read Input Device Reads from Keyboard, etc. ; Read Input Device Reads from Keyboard, etc.
;******************************************************* ;*******************************************************
@@ -1700,12 +1710,15 @@ setwram1fff:
SECTION .bss SECTION .bss
NEWSYM curromsize, resb 1 NEWSYM curromsize, resb 1
NEWSYM cromptradd, resd 1 NEWSYM cromptradd, resd 1
NEWSYM NoiseDisTemp, resd 2
NEWSYM lorommapmode2, resb 1 NEWSYM lorommapmode2, resb 1
NEWSYM MMXSRAMFix, resb 1 NEWSYM MMXSRAMFix, resb 1
SECTION .text SECTION .text
NEWSYM initsnes NEWSYM initsnes
mov byte[ForceNewGfxOff],0 mov byte[ForceNewGfxOff],0
mov dword[NoiseDisTemp],0
mov dword[NoiseDisTemp+4],0
mov byte[MMXSRAMFix],0 mov byte[MMXSRAMFix],0
;Megaman/Rockman X ;Megaman/Rockman X
@@ -1961,6 +1974,8 @@ NEWSYM initsnes
mov byte[opexec358],187 mov byte[opexec358],187
mov byte[opexec268cph],30 mov byte[opexec268cph],30
mov byte[opexec358cph],30 mov byte[opexec358cph],30
mov dword[NoiseDisTemp],01000101h
mov dword[NoiseDisTemp+4],01h
mov edi,memtabler8+40h*4 mov edi,memtabler8+40h*4
mov ecx,30h mov ecx,30h
@@ -2879,7 +2894,6 @@ NEWSYM PatchIPS
%endif %endif
mov edx,fname+1 mov edx,fname+1
mov [patchfile],edx mov [patchfile],edx
EXTSYM PatchUsingIPS
pushad pushad
call PatchUsingIPS call PatchUsingIPS
popad popad
@@ -2894,7 +2908,6 @@ NEWSYM PatchIPS
ret ret
SECTION .bss SECTION .bss
NEWSYM Header512, resb 1
NEWSYM Prevextn, resd 1 NEWSYM Prevextn, resd 1
NEWSYM IPSPatched, resb 1 NEWSYM IPSPatched, resb 1
SECTION .text SECTION .text
@@ -2999,8 +3012,6 @@ SECTION .data
.opened db 'File opened successfully!',13,10,0 .opened db 'File opened successfully!',13,10,0
.mult db 'Multiple file format detected.',13,10,13,10,0 .mult db 'Multiple file format detected.',13,10,13,10,0
SECTION .bss SECTION .bss
.multfound resb 1
.first resb 1
.cchar resb 1 .cchar resb 1
.dotpos resd 1 .dotpos resd 1
.curfileofs resd 1 .curfileofs resd 1
@@ -3020,279 +3031,16 @@ InGUI resb 1
SECTION .data SECTION .data
%ifdef __LINUX__
tempdirname db '/tmp/zziptmp',0
%else
tempdirname db 'zziptmp_.__z',0
%endif
PrevDir db '..',0 PrevDir db '..',0
GUIfindBlank db '*.',0 GUIfindBlank db '*.',0
SECTION .text SECTION .text
%macro UnZipSearch 1
mov cx,20h
mov edx,%1
call Get_First_Entry
jc %%notfound
test byte[DTALoc+15h],10h
jnz %%notfound
jmp .found
%%notfound
%endmacro
SECTION .bss SECTION .bss
ZipError resb 1 ZipError resb 1
SECTION .text SECTION .text
UnZipFile:
; cmp byte[OSPort],1
; jne .noasm
; mov ax,03h
; int 10h
; mov edx,InvalidZip
; call PrintStr
; jmp DosExit
;.noasm
; get Drive/Dir
%ifdef __LINUX__
mov ebx,GUIcurrentdir
%else
mov ebx,GUIcurrentdir+3
%endif
mov edx,GUIcurrentdir
call Get_Dir
%ifndef __LINUX__
add byte[GUIcurrentdir],65
%endif
cmp byte[InGUI],0
je near .nochange
; locate end of string & append filename
%ifdef __LINUX__
mov eax,GUIcurrentdir
%else
mov eax,GUIcurrentdir+3
%endif
.loop
cmp byte[eax],0
je .endfound
inc eax
jmp .loop
.endfound
cmp byte[eax-2],':'
je .noaddslash
%ifdef __LINUX__
mov byte[eax],'/'
%else
mov byte[eax],'\'
%endif
inc eax
.noaddslash
mov ebx,fname+1
.loopb
mov cl,[ebx]
mov [eax],cl
or cl,cl
jz .zero
inc eax
inc ebx
jmp .loopb
.zero
; Change to Save Directory
mov dl,[SRAMDrive]
mov ebx,SRAMDir
call Change_Dir
.nochange
; Change to Temp Directory
mov edx,tempdirname
call Change_Single_Dir
jnc near .notfail
; Create Temp Directory
mov edx,tempdirname
call Create_Dir
; jc near .fail
; Change to Temp Directory
mov edx,tempdirname
call Change_Single_Dir
jc near .fail
.notfail
; mov ax,03h
; int 10h
; mov edx,GUIcurrentdir
; call PrintStr
; jmp DosExit
; Erase contents of the zip directory if there are any stuff
mov esi,mode7tab
call ZipDeleteRecurse
; UnZip File
mov eax,GUIcurrentdir
cmp byte[InGUI],1
je .nogui
mov eax,fname+1
.nogui
push eax
call extractzip
pop eax
cmp byte[ZipError],0
jne near .failed
; Find valid rom file
UnZipSearch GUIsmcfind
UnZipSearch GUIsfcfind
UnZipSearch GUIswcfind
UnZipSearch GUIfigfind
UnZipSearch GUImgdfind
UnZipSearch GUIufofind
UnZipSearch GUIfind058
UnZipSearch GUIfind078
UnZipSearch GUIfindUSA
UnZipSearch GUIfindEUR
UnZipSearch GUIfindJAP
UnZipSearch GUIfindBIN
UnZipSearch GUIfindZIP
UnZipSearch GUIfind1
UnZipSearch GUIfindIC7
UnZipSearch GUIfindIC6
UnZipSearch GUIfindIC5
UnZipSearch GUIfindIC4
UnZipSearch GUIfindIC3
UnZipSearch GUIfindIC2
UnZipSearch GUIfindIC1
UnZipSearch GUIfindBlank
.failed
call ZipDelete
jmp .fail
.found
mov byte[ZipSupport],1
mov edx,DTALoc+1Eh
mov eax,fname+1
.continue
mov bl,[edx]
mov [eax],bl
inc eax
inc edx
or bl,bl
jnz .continue
ret
mov ax,3
int 10h
mov edx,DTALoc+1Eh
; mov edx,GUIcurrentdir
call PrintStr
jmp DosExit
.fail
mov byte[ZipSupport],2
ret
%ifdef __LINUX__
GUIfindIC7 db '*.[Ii][Cc]7',0
GUIfindIC6 db '*.[Ii][Cc]6',0
GUIfindIC5 db '*.[Ii][Cc]5',0
GUIfindIC4 db '*.[Ii][Cc]4',0
GUIfindIC3 db '*.[Ii][Cc]3',0
GUIfindIC2 db '*.[Ii][Cc]2',0
GUIfindIC1 db '*.[Ii][Cc]1',0
%else
GUIfindIC7 db '*.iC7',0
GUIfindIC6 db '*.iC6',0
GUIfindIC5 db '*.iC5',0
GUIfindIC4 db '*.iC4',0
GUIfindIC3 db '*.iC3',0
GUIfindIC2 db '*.iC2',0
GUIfindIC1 db '*.iC1',0
%endif
ZipDelete:
mov esi,mode7tab
call ZipDeleteRecurse
mov edx,PrevDir
call Change_Single_Dir
mov edx,tempdirname
call Remove_Dir
call Makemode7Table
ret
SECTION .bss
tempzip resb 1
SECTION .text
ZipDeleteRecurse:
; Find all directories
mov edx,GUIfindall
mov cx,10h
call Get_First_Entry
jc near .notfounddir
.moreentries2
test byte[DTALoc+15h],10h
jz .nodir
cmp byte[DTALoc+1Eh],'.'
jne .founddir
.nodir
call Get_Next_Entry
jnc .moreentries2
jmp .notfounddir
.founddir
cmp byte[tempzip],3
jne .notone
%ifndef __LINUX__
mov ax,03h
int 10h
%endif
jmp DosExit
.notone
push edx
mov ecx,43
mov edi,DTALoc
.loop
mov al,[edi]
mov [esi],al
inc edi
inc esi
dec ecx
jnz .loop
mov edx,DTALoc+1Eh
call Change_Single_Dir
inc byte[tempzip]
call ZipDeleteRecurse
sub esi,43
mov edx,PrevDir
call Change_Single_Dir
mov edx,esi
add edx,1Eh
call Remove_Dir
jc .faildirdel
pop edx
jmp ZipDeleteRecurse
.faildirdel
pop edx
.notfounddir
; ah = 41h, edx = ptr to file
mov cx,20h
mov edx,GUIfindall
call Get_First_Entry
jc .notfound
.moreentries
push edx
mov edx,DTALoc+1Eh
call Delete_File
pop edx
call Get_Next_Entry
jnc .moreentries
.notfound
ret
SECTION .data SECTION .data
SPC7110DIRA db 'FEOEZSP7',0 SPC7110DIRA db 'FEOEZSP7',0
@@ -3653,246 +3401,27 @@ NEWSYM loadfileGUI
je .nosound je .nosound
mov byte[spcon],1 mov byte[spcon],1
.nosound .nosound
; determine if it's a .zip file or not
mov eax,fname
mov byte[ZipSupport],0
.ziploop
inc eax
cmp byte[eax],0
jne .ziploop
sub eax,4
; cmp byte[eax+1],'.'
; jne .finishzipd2
; cmp byte[eax+2],'g'
; je .zokay4
; cmp byte[eax+2],'G'
; jne .finishzipd2
;.zokay4
; cmp byte[eax+3],'z'
; je .zokay5
; cmp byte[eax+3],'Z'
; jne .finishzipd2
;.zokay5
; jmp .zokay3
.finishzipd2
cmp byte[eax],'.'
jne near .finishzipd
inc eax
cmp byte[eax],'z'
je .zokay1
cmp byte[eax],'Z'
jne .finishzipd
.zokay1
inc eax
cmp byte[eax],'i'
je .zokay2
cmp byte[eax],'I'
jne .finishzipd
.zokay2
inc eax
cmp byte[eax],'p'
je .zokay3
cmp byte[eax],'P'
jne .finishzipd
.zokay3
call UnZipFile
cmp byte[ZipSupport],2
jne .finishzipd
cmp byte[InGUI],1
je .zipfail
jmp .failed
.zipfail
ret
.finishzipd
mov byte[TextFile], 0 mov byte[TextFile], 0
mov dword[MessageOn],0 mov dword[MessageOn],0
mov byte[loadedfromgui],1 mov byte[loadedfromgui],1
mov byte[Header512],0
mov byte[yesoutofmemory],0 mov byte[yesoutofmemory],0
mov byte[.fail],0 mov byte[.fail],0
; determine header size
mov dword[.curfileofs],0
mov byte[.first],1
mov byte[.multfound],0
mov dword[curromspace],0
; open file
mov edx,fname+1
call Open_File
jc near .failed
.nextfile
cmp byte[.first],1
je .nomul
cmp byte[.multfound],0
jne .nomul
push eax
push edx
mov byte[.multfound],1
cmp byte[InGUI],1
je .ingui
; mov edx,.mult
; mov ah,9
; call Output_Text
.ingui
pop edx
pop eax
.nomul
mov bx,ax
mov ecx,4194304+32768
cmp byte[Sup48mbit],0
je .no48mb
add ecx,2097152
.no48mb
cmp byte[Sup16mbit],0
je .no16mb
sub ecx,2097152
.no16mb
mov [maxromspace],ecx
sub dword[maxromspace],32768
sub ecx,[.curfileofs]
jnc .nooverflow
xor ecx,ecx
.nooverflow
mov edx,[headdata]
add edx,[.curfileofs]
call Read_File
jc near .failed
or eax,eax
jz near .success2
add dword[curromspace],eax
mov esi,[headdata]
add esi,[.curfileofs]
mov edi,[headdata]
add edi,[.curfileofs]
add [.curfileofs],eax
mov ecx,eax
and ecx,32767
cmp ecx,512
je near .yesheader
; check if .smc header
push esi
push eax
push ebx
xor ecx,ecx
mov ebx,512
.nextzerocheck
cmp byte[esi],0
jne .notzero
inc ecx
.notzero
inc esi
dec ebx
jnz .nextzerocheck
pop ebx
pop eax
pop esi
cmp ecx,450
jb .nomove
.yesheader
mov byte[Header512],1
mov edi,esi
add edi,512
sub eax,512
; move eax # of bytes from edi to esi
sub dword[curromspace],512
sub dword[.curfileofs],512
.next
mov cl,[edi]
mov [esi],cl
inc esi
inc edi
dec eax
jnz .next
.nomove
mov ecx,1
mov edx,.temp
call Read_File
cmp eax,0
je .success
mov byte[.fail],1
jmp .success
.success2
mov byte[.fail],0
.success
call Close_File
jc near .failed
; check for 2nd+ part of file
mov edi,fname+1
mov byte[.cchar],'\'
; get position of . or \ (You suck nasm)
.nextsearch
cmp byte[edi],0
je .nomore
cmp byte[edi],'.'
jne .notdot
mov byte[.cchar],'.'
mov [.dotpos],edi
.notdot
cmp byte[edi],'\'
jne .notslash
mov byte[.cchar],'\'
.notslash
inc edi
jmp .nextsearch
.nomore
cmp byte[.cchar],'\'
jne .noslashb
mov [.dotpos],edi
.noslashb
mov edi,[.dotpos]
; search for .1, .2, etc.
cmp byte[edi],'.'
jne .nonumer
cmp byte[edi+1],'1'
jb .nonumer
cmp byte[edi+1],'8'
ja .nonumer
cmp byte[edi+2],0
jne .nonumer
inc byte[edi+1]
xor ecx,ecx
mov byte[.first],2
mov edx,fname+1 mov edx,fname+1
call Open_File mov dword[ZOpenFileName],edx
jnc near .nextfile pushad
dec byte[edi+1] call loadROM
.nonumer popad
mov edi,[.dotpos]
; search for ICx files cmp dword[curromspace],0
cmp byte[edi],'.' je .failed
jne .noicfile
cmp byte[edi+3],'1'
jb .noicfile ;dec dword[curromspace]
cmp byte[edi+3],'7' mov eax,dword[curromspace]
ja .noicfile mov dword[.curfileofs],eax
cmp byte[edi+4],0 dec dword[.curfileofs]
jne .noicfile
dec byte[edi+3]
xor ecx,ecx
mov byte[.first],2
mov edx,fname+1
call Open_File
jnc near .nextfile
inc byte[edi+3]
.noicfile
; search for A,B,C, etc.
cmp byte[.first],0
je .yesgd
cmp byte[edi-1],'A'
je .yesgd
cmp byte[edi-1],'a'
je .yesgd
jmp .nogdformat
.yesgd
mov byte[.first],0
inc byte[edi-1]
mov edx,fname+1
call Open_File
jnc near .nextfile
dec byte[edi-1]
.nogdformat
mov byte[TextFile], 1
mov byte[IPSPatched],0
mov byte[lorommapmode2],0 mov byte[lorommapmode2],0
mov esi,[romdata] mov esi,[romdata]
@@ -3951,12 +3480,6 @@ NEWSYM loadfileGUI
jnz .loopcheck jnz .loopcheck
.skipall .skipall
cmp byte[ZipSupport],1
jne .nottempdirdel
call PatchIPS
call ZipDelete
.nottempdirdel
call convertsram call convertsram
mov byte[SramExists],0 mov byte[SramExists],0
@@ -4019,10 +3542,6 @@ NEWSYM loadfileGUI
ret ret
.failed .failed
cmp byte[ZipSupport],1
jne .nottempdirdelb
call ZipDelete
.nottempdirdelb
.failed2 .failed2
cmp byte[InGUI],1 cmp byte[InGUI],1
je .noguic je .noguic
@@ -4040,8 +3559,6 @@ SECTION .data
SECTION .bss SECTION .bss
.multfound resb 1
.first resb 1
.cchar resb 1 .cchar resb 1
.dotpos resd 1 .dotpos resd 1
.curfileofs resd 1 .curfileofs resd 1
@@ -4350,7 +3867,6 @@ NEWSYM showinfogui
shr ecx,2 shr ecx,2
jnz .crcprintloop jnz .crcprintloop
EXTSYM CalcChecksum
pushad pushad
call CalcChecksum call CalcChecksum
popad popad
@@ -4911,12 +4427,10 @@ NEWSYM CheckROMType
call SetAddressingModes call SetAddressingModes
call GenerateBank0Table call GenerateBank0Table
EXTSYM BankCheck
pushad pushad
call BankCheck call BankCheck
popad popad
EXTSYM MirrorROM
pushad pushad
call MirrorROM call MirrorROM
popad popad
@@ -5175,8 +4689,8 @@ NEWSYM CheckROMType
je .initdsp je .initdsp
cmp byte[DSP3Enable],1 cmp byte[DSP3Enable],1
je .initdsp je .initdsp
cmp byte[DSP4Enable],1 cmp byte[DSP4Enable],0
je .initdsp je .notDSP1Hi
; call InitDSP4 ; call InitDSP4
jmp .notDSP1Hi jmp .notDSP1Hi
.initdsp .initdsp

View File

@@ -17,7 +17,20 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifdef __LINUX__
#include "gblhdr.h"
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#endif
#include <sys/stat.h>
#include "zip/zunzip.h"
#ifndef __GNUC__
#define strcasecmp stricmp
#endif
//C++ style code in C //C++ style code in C
#define bool unsigned char #define bool unsigned char
@@ -351,6 +364,310 @@ void MirrorROM()
} }
} }
//File loading code
extern char *ZOpenFileName;
bool Header512;
void loadFile()
{
bool multifile = false;
char *incrementer = 0;
unsigned char *ROM = (unsigned char *)romdata;
if (strlen(ZOpenFileName) >= 3) //Char + ".1"
{
char *ext = ZOpenFileName+strlen(ZOpenFileName)-2;
if (!strcmp(ext, ".1") || !strcasecmp(ext, ".A"))
{
incrementer = ext + 1;
multifile = true;
}
}
for (;;)
{
struct stat stat_results;
stat(ZOpenFileName, &stat_results);
if (stat_results.st_size <= maxromspace+512-curromspace)
{
FILE *fp = 0;
fp = fopen(ZOpenFileName, "rb");
if (!fp) { return; }
if (curromspace && ((stat_results.st_size & 0x7FFF) == 512))
{
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;
}
}
}
void loadGZipFile()
{
int size, err;
FILE *fp = 0;
fp = fopen(ZOpenFileName, "rb");
if (!fp) { return; }
fseek(fp, -4, SEEK_END);
size = fgetc(fp) | (fgetc(fp) << 8) | (fgetc(fp) << 16) | (fgetc(fp) << 24);
fclose(fp);
if (size > maxromspace+512) { return; }
//Open GZip file for decompression
gzFile GZipFile = gzopen(ZOpenFileName, "rb");
//Decompress file into memory
err = gzread(GZipFile, romdata, size);
//Close compressed file
gzclose(GZipFile);
if (err != size) { return; }
curromspace = size;
}
//void Output_Text();
//asm volatile("movl _ZOpenFileName, %edx \n"
// "movb $9, %ah \n"
// "call _Output_Text \n");
//system("pause");
void loadZipFile()
{
int err, fileSize;
unsigned char *ROM = (unsigned char *)romdata;
bool multifile = false;
char *incrementer = 0;
unzFile zipfile = unzOpen(ZOpenFileName); //Open zip file
int cFile = unzGoToFirstFile(zipfile); //Set cFile to first compressed file
unz_file_info cFileInfo; //Create variable to hold info for a compressed file
int LargestGoodFile = 0; //To keep track of largest file
//Variables for the file we pick
char ourFile[256];
ourFile[0] = '\n';
while(cFile == UNZ_OK) //While not at end of compressed file list
{
//Temporary char array for file name
char cFileName[256];
//Gets info on current file, and places it in cFileInfo
unzGetCurrentFileInfo(zipfile, &cFileInfo, cFileName, 256, NULL, 0, NULL, 0);
//Get the file's size
fileSize = cFileInfo.uncompressed_size;
//Find split files
if (strlen(cFileName) >= 3) //Char + ".1"
{
char *ext = cFileName+strlen(cFileName)-2;
if (!strcmp(ext, ".1") || !strcasecmp(ext, ".A"))
{
strcpy(ourFile, cFileName);
incrementer = ourFile+strlen(ourFile)-1;
multifile = true;
break;
}
}
//Find Nintendo Super System ROMs
if (strlen(cFileName) >= 5) //Char + ".IC2"
{
char *ext = cFileName+strlen(cFileName)-4;
if (!strcasecmp(ext, ".IC3"))
{
strcpy(ourFile, cFileName);
incrementer = ourFile+strlen(ourFile)-1;
multifile = true;
break;
}
}
//Check for valid ROM based on size
if ((fileSize < maxromspace+512) && fileSize > LargestGoodFile)
{
strcpy(ourFile, cFileName);
LargestGoodFile = fileSize;
}
//Go to next file in zip file
cFile = unzGoToNextFile(zipfile);
}
//No files found
if (ourFile[0] == '\n')
{
unzClose(zipfile);
return;
}
for (;;)
{
//Sets current file to the file we liked before
if (unzLocateFile(zipfile, ourFile, 1) != UNZ_OK)
{
unzClose(zipfile);
return;
}
//Gets info on current file, and places it in cFileInfo
unzGetCurrentFileInfo(zipfile, &cFileInfo, ourFile, 256, NULL, 0, NULL, 0);
//Get the file's size
fileSize = cFileInfo.uncompressed_size;
//Too big?
if (curromspace + fileSize > maxromspace+512)
{
unzClose(zipfile);
return;
}
//Open file
unzOpenCurrentFile(zipfile);
//Read file into memory
err = unzReadCurrentFile(zipfile, ROM+curromspace, fileSize);
//Close file
unzCloseCurrentFile(zipfile);
//Encountered error?
if (err != fileSize)
{
unzClose(zipfile);
return;
}
if (curromspace && ((fileSize & 0x7FFF) == 512))
{
fileSize -= 512;
memmove(ROM+curromspace, ROM+curromspace+512, fileSize);
}
curromspace += fileSize;
if (!multifile)
{
unzClose(zipfile);
return;
}
(*incrementer)++;
//Code to find next ROM for NSS games
if ((incrementer[-1] == 'C' || incrementer[-1] == 'c'))
{
if (*incrementer == '4') { *incrementer = '2'; }
if (*incrementer == '3') { *incrementer = '8'; }
}
}
}
extern bool Sup48mbit;
extern bool Sup16mbit;
void loadROM()
{
bool isCompressed = false;
curromspace = 0;
maxromspace = 4194304;
if (Sup48mbit) { maxromspace += 2097152; }
if (Sup16mbit) { maxromspace -= 2097152; } //I don't get it either
if (strlen(ZOpenFileName) >= 5) //Char + ".zip"
{
char *ext = ZOpenFileName+strlen(ZOpenFileName)-4;
if (!strcasecmp(ext, ".zip"))
{
isCompressed = true;
loadZipFile();
}
}
if (strlen(ZOpenFileName) >= 4) //Char + ".gz"
{
char *ext = ZOpenFileName+strlen(ZOpenFileName)-3;
if (!strcasecmp(ext, ".gz"))
{
isCompressed = true;
loadGZipFile();
}
}
if (!isCompressed) { loadFile(); }
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);
switch(HeadRemain)
{
case 0:
break;
case 512:
Header512 = true;
break;
default:
//SMC/SWC header
if (romdata[8] == 0xAA && romdata[9]==0xBB && romdata[10]== 4)
{
Header512 = true;
}
//FIG header
else if ((romdata[4] == 0x77 && romdata[5] == 0x83) ||
(romdata[4] == 0xDD && romdata[5] == 0x82) ||
(romdata[4] == 0xDD && romdata[5] == 2) ||
(romdata[4] == 0xF7 && romdata[5] == 0x83) ||
(romdata[4] == 0xFD && romdata[5] == 0x82) ||
(romdata[4] == 0x00 && romdata[5] == 0x80) ||
(romdata[4] == 0x47 && romdata[5] == 0x83) ||
(romdata[4] == 0x11 && romdata[5] == 2))
{
Header512 = true;
}
break;
}
}
if (Header512)
{
curromspace -= 512;
memmove((unsigned char *)romdata, ((unsigned char *)romdata)+512, curromspace);
}
}
//Memory Setup functions //Memory Setup functions
extern unsigned char wramdataa[65536]; extern unsigned char wramdataa[65536];
@@ -687,3 +1004,4 @@ void Setper2exec()
opexec268cph = opexec268cph*(per2exec*0.01); opexec268cph = opexec268cph*(per2exec*0.01);
opexec358cph = opexec358cph*(per2exec*0.01); opexec358cph = opexec358cph*(per2exec*0.01);
} }

View File

@@ -1,3 +1,3 @@
/Fezsnesw.exe chips\dsp1proc.obj dos\sw.obj dos\gppro.obj dos\vesa12.obj dos\zsipx.obj dos\modemrtn.obj dos\joy.obj dos\debug.obj dos\vesa2.obj dos\initvid.obj cfgload.obj endmem.obj init.obj initc.obj uic.obj patch.obj ui.obj vcache.obj effects\water.obj effects\smoke.obj effects\burn.obj version.obj video\procvid.obj win\copyvwin.obj win\winintrf.obj win\winlink.obj win\zloaderw.obj win\ztcp.obj win\zfilew.obj win\zipxw.obj video\makev16b.obj video\makev16t.obj video\makevid.obj video\mode716.obj video\mode716b.obj video\mode716d.obj video\mode716e.obj video\mode716t.obj video\mode7.obj video\mode7ext.obj video\mv16tms.obj video\newg162.obj video\newgfx16.obj video\newgfx2.obj video\newgfx.obj video\m716text.obj video\2xsaiw.obj video\sw_draw.obj video/hq3x16.obj video/hq3x32.obj gui\gui.obj gui\menu.obj cpu\addrni.obj cpu\dma.obj cpu\dsp.obj cpu\dspproc.obj cpu\execute.obj cpu\irq.obj cpu\memory.obj cpu\spc700.obj cpu\stable.obj cpu\table.obj cpu\tableb.obj cpu\tablec.obj chips\dsp1emu.obj chips\fxemu2.obj chips\fxemu2b.obj chips\fxemu2c.obj chips\fxtable.obj chips\sa1proc.obj chips\sa1regs.obj chips\sfxproc.obj zip\unzip.obj zip\zzip.obj zip\zpng.obj zlib.lib libpng.lib wsock32.lib user32.lib gdi32.lib shell32.lib winmm.lib ddraw.lib dsound.lib dinput8.lib d3dx.lib /link /section:.text,erw /Fezsnesw.exe chips\dsp1proc.obj dos\sw.obj dos\gppro.obj dos\vesa12.obj dos\zsipx.obj dos\modemrtn.obj dos\joy.obj dos\debug.obj dos\vesa2.obj dos\initvid.obj cfgload.obj endmem.obj init.obj initc.obj uic.obj patch.obj ui.obj vcache.obj effects\water.obj effects\smoke.obj effects\burn.obj version.obj video\procvid.obj win\copyvwin.obj win\winintrf.obj win\winlink.obj win\zloaderw.obj win\ztcp.obj win\zfilew.obj win\zipxw.obj video\makev16b.obj video\makev16t.obj video\makevid.obj video\mode716.obj video\mode716b.obj video\mode716d.obj video\mode716e.obj video\mode716t.obj video\mode7.obj video\mode7ext.obj video\mv16tms.obj video\newg162.obj video\newgfx16.obj video\newgfx2.obj video\newgfx.obj video\m716text.obj video\2xsaiw.obj video\sw_draw.obj video/hq3x16.obj video/hq3x32.obj gui\gui.obj gui\menu.obj cpu\addrni.obj cpu\dma.obj cpu\dsp.obj cpu\dspproc.obj cpu\execute.obj cpu\irq.obj cpu\memory.obj cpu\spc700.obj cpu\stable.obj cpu\table.obj cpu\tableb.obj cpu\tablec.obj chips\dsp1emu.obj chips\fxemu2.obj chips\fxemu2b.obj chips\fxemu2c.obj chips\fxtable.obj chips\sa1proc.obj chips\sa1regs.obj chips\sfxproc.obj zip\unzip.obj zip\zpng.obj zlib.lib libpng.lib wsock32.lib user32.lib gdi32.lib shell32.lib winmm.lib ddraw.lib dsound.lib dinput8.lib d3dx.lib /link /section:.text,erw

View File

@@ -54,7 +54,7 @@ WINOBJ=${WINDIR}/copywin.o ${WINDIR}/winintrf.o ${WINDIR}/winlink.o\
PREOBJ=${OBJDIR}/dosbuff.o ${OBJDIR}/ipx.o ${OBJDIR}/zipx.o PREOBJ=${OBJDIR}/dosbuff.o ${OBJDIR}/ipx.o ${OBJDIR}/zipx.o
ZIPOBJ=${ZIPDIR}/zzip.o ${ZIPDIR}/unzip.o ${ZIPDIR}/zpng.o ZIPOBJ=${ZIPDIR}/unzip.o ${ZIPDIR}/zpng.o
EFFECTSOBJ=${EFFECTSDIR}/burn.o ${EFFECTSDIR}/water.o ${EFFECTSDIR}/smoke.o EFFECTSOBJ=${EFFECTSDIR}/burn.o ${EFFECTSDIR}/water.o ${EFFECTSDIR}/smoke.o
@@ -100,7 +100,6 @@ ${EFFECTSDIR}/smoke.o: ${EFFECTSDIR}/smoke.c
${EFFECTSDIR}/burn.o: ${EFFECTSDIR}/burn.c ${EFFECTSDIR}/burn.o: ${EFFECTSDIR}/burn.c
${DOSDIR}/zfile.o: ${DOSDIR}/zfile.c ${DOSDIR}/zfile.o: ${DOSDIR}/zfile.c
${ZIPDIR}/unzip.o: ${ZIPDIR}/unzip.c ${ZIPDIR}/zunzip.h ${ZIPDIR}/unzip.o: ${ZIPDIR}/unzip.c ${ZIPDIR}/zunzip.h
${ZIPDIR}/zzip.o: ${ZIPDIR}/zzip.c ${ZIPDIR}/zunzip.h
${ZIPDIR}/zpng.o: ${ZIPDIR}/zpng.c ${ZIPDIR}/zpng.h ${ZIPDIR}/zpng.o: ${ZIPDIR}/zpng.c ${ZIPDIR}/zpng.h
${VIDEODIR}/procvid.o: ${VIDEODIR}/procvid.asm macros.mac ${VIDEODIR}/copyvid.inc ${VIDEODIR}/2xSaImmx.inc ${VIDEODIR}/procvid.o: ${VIDEODIR}/procvid.asm macros.mac ${VIDEODIR}/copyvid.inc ${VIDEODIR}/2xSaImmx.inc
${CHIPDIR}/dsp1proc.o: ${CHIPDIR}/dsp1proc.asm macros.mac ${CHIPDIR}/dsp1proc.o: ${CHIPDIR}/dsp1proc.asm macros.mac

View File

@@ -63,7 +63,7 @@ WINDOSOBJ=${DOSDIR}/debug.obj ${DOSDIR}/joy.obj ${DOSDIR}/modemrtn.obj ${DOSDIR}
PREOBJ= PREOBJ=
ZIPOBJ=${ZIPDIR}/zzip.obj ${ZIPDIR}/unzip.obj ${ZIPDIR}/zpng.obj ZIPOBJ=${ZIPDIR}/unzip.obj ${ZIPDIR}/zpng.obj
EFFECTSOBJ=${EFFECTSDIR}/burn.obj ${EFFECTSDIR}/water.obj ${EFFECTSDIR}/smoke.obj EFFECTSOBJ=${EFFECTSDIR}/burn.obj ${EFFECTSDIR}/water.obj ${EFFECTSDIR}/smoke.obj
@@ -103,7 +103,6 @@ ${WINDIR}/zloaderw.obj: ${WINDIR}/zloaderw.c
${WINDIR}/ztcp.obj: ${WINDIR}/ztcp.c ${WINDIR}/ztcp.obj: ${WINDIR}/ztcp.c
${WINDIR}/winlink.obj: ${WINDIR}/winlink.cpp ${WINDIR}/resource.h ${WINDIR}/winlink.obj: ${WINDIR}/winlink.cpp ${WINDIR}/resource.h
${ZIPDIR}/unzip.obj: ${ZIPDIR}/unzip.c ${ZIPDIR}/zunzip.h ${ZIPDIR}/unzip.obj: ${ZIPDIR}/unzip.c ${ZIPDIR}/zunzip.h
${ZIPDIR}/zzip.obj: ${ZIPDIR}/zzip.c ${ZIPDIR}/zunzip.h
${ZIPDIR}/zpng.obj: ${ZIPDIR}/zpng.c ${ZIPDIR}/zpng.h ${ZIPDIR}/zpng.obj: ${ZIPDIR}/zpng.c ${ZIPDIR}/zpng.h
${DOSDIR}/initvid.o:${DOSDIR}/initvid.asm macros.mac ${DOSDIR}/initvid.o:${DOSDIR}/initvid.asm macros.mac
${DOSDIR}/modemrtn.o: ${DOSDIR}/modemrtn.asm macros.mac ${DOSDIR}/modemrtn.o: ${DOSDIR}/modemrtn.asm macros.mac

View File

@@ -1,343 +0,0 @@
//Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later
//version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifdef __LINUX__
#include "../gblhdr.h"
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#endif
#ifdef __WIN32__
#include <direct.h>
#include <sys/utime.h>
#endif
#ifdef __MSDOS__
#include <utime.h>
#include <sys/stat.h>
#endif
#include "zunzip.h"
#define CASESENSITIVITY (0)
#define WRITEBUFFERSIZE (8192)
unsigned int ZipError=0;
// 1 : Cannot open file
// 2 : Could not create directory
// 3 : Zip error
// 4 : Memory error
// 5 : Error opening file
// 6 : Error Writing file
#ifndef __LINUX__
#ifndef __MSDOS__
#ifndef __WIN32__
struct utimbuf {
time_t actime;
time_t modtime;
};
#endif
#endif
#endif
void change_file_date(const char *filename,uLong dosdate,tm_unz tmu_date)
{
struct utimbuf ut;
struct tm newdate;
newdate.tm_sec = tmu_date.tm_sec;
newdate.tm_min=tmu_date.tm_min;
newdate.tm_hour=tmu_date.tm_hour;
newdate.tm_mday=tmu_date.tm_mday;
newdate.tm_mon=tmu_date.tm_mon;
if (tmu_date.tm_year > 1900)
newdate.tm_year=tmu_date.tm_year - 1900;
else
newdate.tm_year=tmu_date.tm_year ;
newdate.tm_isdst=-1;
ut.actime=ut.modtime=mktime(&newdate);
utime(filename,&ut);
}
int mymkdir(const char *dirname)
{
#ifdef __LINUX__
return(mkdir(dirname, (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)));
#else
#ifdef __MSDOS__
return(mkdir(dirname, (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)));
#else
return(mkdir(dirname));
#endif
#endif
}
int makedir (char *newdir)
{
char *buffer ;
char *p;
int len = strlen(newdir);
if (len <= 0)
return 0;
buffer = (char*)malloc(len+1);
strcpy(buffer,newdir);
if (buffer[len-1] == '/') {
buffer[len-1] = '\0';
}
if (mymkdir(buffer) == 0)
{
free(buffer);
return 1;
}
p = buffer+1;
while (1)
{
char hold;
while(*p && *p != '\\' && *p != '/')
p++;
hold = *p;
*p = 0;
if ((mymkdir(buffer) == -1) && (errno == ENOENT))
{
ZipError=2;
free(buffer);
return 0;
}
if (hold == 0)
break;
*p++ = hold;
}
free(buffer);
return 1;
}
int do_extract_currentfile(unzFile uf,
const int* popt_extract_without_path,
int *popt_overwrite)
{
char filename_inzip[256];
char* filename_withoutpath;
char* p;
int err=UNZ_OK;
FILE *fout=NULL;
void* buf;
uInt size_buf;
unz_file_info file_info;
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
if (err!=UNZ_OK)
{
ZipError=3;
return err;
}
size_buf = WRITEBUFFERSIZE;
buf = (void*)malloc(size_buf);
if (buf==NULL)
{
ZipError=4;
return UNZ_INTERNALERROR;
}
p = filename_withoutpath = filename_inzip;
while ((*p) != '\0')
{
if (((*p)=='/') || ((*p)=='\\'))
filename_withoutpath = p+1;
p++;
}
if ((*filename_withoutpath)=='\0')
{
if ((*popt_extract_without_path)==0)
{
mymkdir(filename_inzip);
}
}
else
{
char* write_filename;
int skip=0;
if ((*popt_extract_without_path)==0)
write_filename = filename_inzip;
else
write_filename = filename_withoutpath;
err = unzOpenCurrentFile(uf);
if (err!=UNZ_OK)
{
ZipError=4;
}
if (((*popt_overwrite)==0) && (err==UNZ_OK))
{
char rep='A';
FILE* ftestexist;
ftestexist = fopen(write_filename,"rb");
if (ftestexist!=NULL)
{
fclose(ftestexist);
rep='N';
}
if (rep == 'N')
skip = 1;
if (rep == 'A')
*popt_overwrite=1;
}
if ((skip==0) && (err==UNZ_OK))
{
fout=fopen(write_filename,"wb");
/* some zipfile don't contain directory alone before file */
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
(filename_withoutpath!=(char*)filename_inzip))
{
char c=*(filename_withoutpath-1);
*(filename_withoutpath-1)='\0';
makedir(write_filename);
*(filename_withoutpath-1)=c;
fout=fopen(write_filename,"wb");
}
if (fout==NULL)
{
ZipError=5;
}
}
if (fout!=NULL)
{
do
{
err = unzReadCurrentFile(uf,buf,size_buf);
if (err<0)
{
ZipError=4;
break;
}
if (err>0)
if (fwrite(buf,err,1,fout)!=1)
{
ZipError=6;
err=UNZ_ERRNO;
break;
}
}
while (err>0);
fclose(fout);
if (err==0)
change_file_date(write_filename,file_info.dosDate,
file_info.tmu_date);
}
if (err==UNZ_OK)
{
err = unzCloseCurrentFile (uf);
if (err!=UNZ_OK)
{
ZipError=4;
}
}
else
unzCloseCurrentFile(uf); /* don't lose the error */
}
free(buf);
return err;
}
int do_extract(unzFile uf,int opt_extract_without_path,int opt_overwrite)
{
uLong i;
unz_global_info gi;
int err;
err = unzGetGlobalInfo (uf,&gi);
if (err!=UNZ_OK)
ZipError=4;
for (i=0;i<gi.number_entry;i++)
{
if (do_extract_currentfile(uf,&opt_extract_without_path,
&opt_overwrite) != UNZ_OK)
break;
if ((i+1)<gi.number_entry)
{
err = unzGoToNextFile(uf);
if (err!=UNZ_OK)
{
ZipError=4;
break;
}
}
}
return 0;
}
void extractzip(char *FileToExtract)
{
unzFile uf=NULL;
#ifdef __LINUX__
// I really don't like hardcoding these sizes...
char oldpath[128];
extern char InitDir;
getcwd(oldpath, 128);
chdir(&InitDir);
#endif
uf = unzOpen(FileToExtract);
#ifdef __LINUX__
chdir(oldpath);
#endif
if (uf==NULL)
{
ZipError=1;
return;
}
ZipError=0;
do_extract(uf,0,0);
}