Skip to content

Commit 655bc18

Browse files
committed
zip file support, compile with more optimizations
1 parent b8a6de7 commit 655bc18

File tree

8 files changed

+3095
-18
lines changed

8 files changed

+3095
-18
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
22
set(CMAKE_VERBOSE_MAKEFILE OFF)
33

44
set(VERSION_MAJOR 1)
5-
set(VERSION_MINOR 94)
5+
set(VERSION_MINOR 95)
66

77
if(BUILD_PSP2)
88
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
@@ -81,6 +81,8 @@ set(SRC_FILES
8181
src/scsi-none.cpp
8282
src/sdlgfx.cpp
8383
src/writelog.cpp
84+
src/unzip.c
85+
src/ioapi.c
8486
src/zfile.cpp
8587
src/menu/fade.cpp
8688
src/gp2x/gp2x.cpp
@@ -230,7 +232,7 @@ if(BUILD_NX)
230232
-mtp=soft
231233
#-fPIE is neccessary to prevent crash on startup
232234
-fPIE
233-
-O1
235+
-O3
234236
-ffast-math
235237
-fno-asynchronous-unwind-tables
236238
-funroll-loops

README.MD

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ On the Switch, since v1.84, please use nsp injection to start uae4all2, otherwis
44

55
Recent Changes
66
======
7-
1.94
7+
1.95
88

9-
- fix hdf settings with non-zero hd dir causing wrong mounted drives
10-
- implement .adz floppy disk format support (read only)
11-
- widescreen file dialog to show longer filenames
9+
- add support for .zip floppy files (read-only)
10+
- on Switch, also compile with optimization level 3
1211

1312
Description
1413
=====
@@ -301,6 +300,11 @@ Compiling
301300
302301
CHANGELOG
303302
=====
303+
1.95
304+
305+
- add support for .zip floppy files (read-only)
306+
- on Switch, also compile with optimization level 3
307+
304308
1.94
305309
306310
- fix hdf settings with non-zero hd dir causing wrong mounted drives

src/gp2x/menu/menu_load.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,32 +198,32 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
198198
#endif
199199
#ifdef __PSP2__
200200
else if (current_drive==0)
201-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF0 (Triangle = Info)");
201+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF0 (Triangle = Info)");
202202
else if (current_drive==1)
203-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF1 (Triangle = Info)");
203+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF1 (Triangle = Info)");
204204
else if (current_drive==2)
205-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF2 (Triangle = Info)");
205+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF2 (Triangle = Info)");
206206
else if (current_drive==3)
207-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF3 (Triangle = Info)");
207+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF3 (Triangle = Info)");
208208
#else
209209
#ifdef __SWITCH__
210210
else if (current_drive==0)
211-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF0 (X = Info)");
211+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF0 (X = Info)");
212212
else if (current_drive==1)
213-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF1 (X = Info)");
213+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF1 (X = Info)");
214214
else if (current_drive==2)
215-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF2 (X = Info)");
215+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF2 (X = Info)");
216216
else if (current_drive==3)
217-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF3 (X = Info)");
217+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF3 (X = Info)");
218218
#else
219219
else if (current_drive==0)
220-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF0");
220+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF0");
221221
else if (current_drive==1)
222-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF1");
222+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF1");
223223
else if (current_drive==2)
224-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF2");
224+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF2");
225225
else if (current_drive==3)
226-
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ into DF3");
226+
text_draw_window(x_win,y_win,w_win,h_win,"Insert .ADF or .ADZ or .ZIP into DF3");
227227
#endif
228228
#endif
229229
else

src/ioapi.c

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
/* ioapi.h -- IO base function header for compress/uncompress .zip
2+
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3+
4+
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5+
6+
Modifications for Zip64 support
7+
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
8+
9+
For more info read MiniZip_info.txt
10+
11+
*/
12+
13+
#if defined(__PSP2__) || defined(__SWITCH__)
14+
#define IOAPI_NO_64
15+
#endif
16+
17+
18+
#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
19+
#define _CRT_SECURE_NO_WARNINGS
20+
#endif
21+
22+
#if defined(__APPLE__) || defined(IOAPI_NO_64)
23+
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
24+
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
25+
#define FTELLO_FUNC(stream) ftello(stream)
26+
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
27+
#else
28+
#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
29+
#define FTELLO_FUNC(stream) ftello64(stream)
30+
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
31+
#endif
32+
33+
34+
#include "ioapi.h"
35+
36+
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
37+
{
38+
if (pfilefunc->zfile_func64.zopen64_file != NULL)
39+
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
40+
else
41+
{
42+
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
43+
}
44+
}
45+
46+
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
47+
{
48+
if (pfilefunc->zfile_func64.zseek64_file != NULL)
49+
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
50+
else
51+
{
52+
uLong offsetTruncated = (uLong)offset;
53+
if (offsetTruncated != offset)
54+
return -1;
55+
else
56+
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
57+
}
58+
}
59+
60+
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
61+
{
62+
if (pfilefunc->zfile_func64.zseek64_file != NULL)
63+
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
64+
else
65+
{
66+
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
67+
if ((tell_uLong) == MAXU32)
68+
return (ZPOS64_T)-1;
69+
else
70+
return tell_uLong;
71+
}
72+
}
73+
74+
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
75+
{
76+
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
77+
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
78+
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
79+
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
80+
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
81+
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
82+
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
83+
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
84+
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
85+
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
86+
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
87+
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
88+
}
89+
90+
91+
92+
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
93+
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
94+
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
95+
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
96+
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
97+
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
98+
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
99+
100+
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
101+
{
102+
FILE* file = NULL;
103+
const char* mode_fopen = NULL;
104+
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
105+
mode_fopen = "rb";
106+
else
107+
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
108+
mode_fopen = "r+b";
109+
else
110+
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
111+
mode_fopen = "wb";
112+
113+
if ((filename!=NULL) && (mode_fopen != NULL))
114+
file = fopen(filename, mode_fopen);
115+
return file;
116+
}
117+
118+
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
119+
{
120+
FILE* file = NULL;
121+
const char* mode_fopen = NULL;
122+
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
123+
mode_fopen = "rb";
124+
else
125+
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
126+
mode_fopen = "r+b";
127+
else
128+
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
129+
mode_fopen = "wb";
130+
131+
if ((filename!=NULL) && (mode_fopen != NULL))
132+
file = FOPEN_FUNC((const char*)filename, mode_fopen);
133+
return file;
134+
}
135+
136+
137+
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
138+
{
139+
uLong ret;
140+
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
141+
return ret;
142+
}
143+
144+
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
145+
{
146+
uLong ret;
147+
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
148+
return ret;
149+
}
150+
151+
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
152+
{
153+
long ret;
154+
ret = ftell((FILE *)stream);
155+
return ret;
156+
}
157+
158+
159+
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
160+
{
161+
ZPOS64_T ret;
162+
ret = FTELLO_FUNC((FILE *)stream);
163+
return ret;
164+
}
165+
166+
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
167+
{
168+
int fseek_origin=0;
169+
long ret;
170+
switch (origin)
171+
{
172+
case ZLIB_FILEFUNC_SEEK_CUR :
173+
fseek_origin = SEEK_CUR;
174+
break;
175+
case ZLIB_FILEFUNC_SEEK_END :
176+
fseek_origin = SEEK_END;
177+
break;
178+
case ZLIB_FILEFUNC_SEEK_SET :
179+
fseek_origin = SEEK_SET;
180+
break;
181+
default: return -1;
182+
}
183+
ret = 0;
184+
if (fseek((FILE *)stream, offset, fseek_origin) != 0)
185+
ret = -1;
186+
return ret;
187+
}
188+
189+
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
190+
{
191+
int fseek_origin=0;
192+
long ret;
193+
switch (origin)
194+
{
195+
case ZLIB_FILEFUNC_SEEK_CUR :
196+
fseek_origin = SEEK_CUR;
197+
break;
198+
case ZLIB_FILEFUNC_SEEK_END :
199+
fseek_origin = SEEK_END;
200+
break;
201+
case ZLIB_FILEFUNC_SEEK_SET :
202+
fseek_origin = SEEK_SET;
203+
break;
204+
default: return -1;
205+
}
206+
ret = 0;
207+
208+
if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
209+
ret = -1;
210+
211+
return ret;
212+
}
213+
214+
215+
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
216+
{
217+
int ret;
218+
ret = fclose((FILE *)stream);
219+
return ret;
220+
}
221+
222+
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
223+
{
224+
int ret;
225+
ret = ferror((FILE *)stream);
226+
return ret;
227+
}
228+
229+
void fill_fopen_filefunc (pzlib_filefunc_def)
230+
zlib_filefunc_def* pzlib_filefunc_def;
231+
{
232+
pzlib_filefunc_def->zopen_file = fopen_file_func;
233+
pzlib_filefunc_def->zread_file = fread_file_func;
234+
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
235+
pzlib_filefunc_def->ztell_file = ftell_file_func;
236+
pzlib_filefunc_def->zseek_file = fseek_file_func;
237+
pzlib_filefunc_def->zclose_file = fclose_file_func;
238+
pzlib_filefunc_def->zerror_file = ferror_file_func;
239+
pzlib_filefunc_def->opaque = NULL;
240+
}
241+
242+
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
243+
{
244+
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
245+
pzlib_filefunc_def->zread_file = fread_file_func;
246+
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
247+
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
248+
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
249+
pzlib_filefunc_def->zclose_file = fclose_file_func;
250+
pzlib_filefunc_def->zerror_file = ferror_file_func;
251+
pzlib_filefunc_def->opaque = NULL;
252+
}

0 commit comments

Comments
 (0)