Rewrote and enabled lazyusf support, now working properly

CQTexperiment
Chris Moeller 2014-02-12 23:34:52 -08:00
parent 06b1058b47
commit f2b981acba
3 changed files with 103 additions and 60 deletions

View File

@ -21,6 +21,7 @@
8360EF6E17F92E86005208A4 /* HighlyExperimental.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8360EF4417F92C92005208A4 /* HighlyExperimental.framework */; }; 8360EF6E17F92E86005208A4 /* HighlyExperimental.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8360EF4417F92C92005208A4 /* HighlyExperimental.framework */; };
8384904A180764B500E7332D /* SSEQPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83848FEC1807624000E7332D /* SSEQPlayer.framework */; }; 8384904A180764B500E7332D /* SSEQPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83848FEC1807624000E7332D /* SSEQPlayer.framework */; };
8384904B180764C200E7332D /* SSEQPlayer.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83848FEC1807624000E7332D /* SSEQPlayer.framework */; }; 8384904B180764C200E7332D /* SSEQPlayer.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83848FEC1807624000E7332D /* SSEQPlayer.framework */; };
83D4481E18ACA5C8000F443A /* lazyusf in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83D4481B18ACA5AD000F443A /* lazyusf */; };
83DE0CBC180B02CC00269051 /* vio2sf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83DE0C3A180A9BD500269051 /* vio2sf.framework */; }; 83DE0CBC180B02CC00269051 /* vio2sf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83DE0C3A180A9BD500269051 /* vio2sf.framework */; };
83DE0CBD180B02D800269051 /* vio2sf.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83DE0C3A180A9BD500269051 /* vio2sf.framework */; }; 83DE0CBD180B02D800269051 /* vio2sf.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83DE0C3A180A9BD500269051 /* vio2sf.framework */; };
83DE0CC0180B27C200269051 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 83DE0CBF180B27C200269051 /* libz.dylib */; }; 83DE0CC0180B27C200269051 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 83DE0CBF180B27C200269051 /* libz.dylib */; };
@ -129,6 +130,16 @@
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
83D4481A18ACA591000F443A /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 6;
files = (
83D4481E18ACA5C8000F443A /* lazyusf in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
83F18C3717F9300400471B6C /* CopyFiles */ = { 83F18C3717F9300400471B6C /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase; isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -167,6 +178,7 @@
8360EEF317F92AC8005208A4 /* HighlyComplete-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HighlyComplete-Prefix.pch"; sourceTree = "<group>"; }; 8360EEF317F92AC8005208A4 /* HighlyComplete-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HighlyComplete-Prefix.pch"; sourceTree = "<group>"; };
8360EF3E17F92C91005208A4 /* HighlyExperimental.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = HighlyExperimental.xcodeproj; path = ../../Frameworks/HighlyExperimental/HighlyExperimental.xcodeproj; sourceTree = "<group>"; }; 8360EF3E17F92C91005208A4 /* HighlyExperimental.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = HighlyExperimental.xcodeproj; path = ../../Frameworks/HighlyExperimental/HighlyExperimental.xcodeproj; sourceTree = "<group>"; };
83848FE61807623F00E7332D /* SSEQPlayer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SSEQPlayer.xcodeproj; path = ../../Frameworks/SSEQPlayer/SSEQPlayer.xcodeproj; sourceTree = "<group>"; }; 83848FE61807623F00E7332D /* SSEQPlayer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SSEQPlayer.xcodeproj; path = ../../Frameworks/SSEQPlayer/SSEQPlayer.xcodeproj; sourceTree = "<group>"; };
83D4481B18ACA5AD000F443A /* lazyusf */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = lazyusf; path = ../../ThirdParty/lazyusf/lazyusf; sourceTree = "<group>"; };
83DE0C34180A9BD400269051 /* vio2sf.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = vio2sf.xcodeproj; path = ../../Frameworks/vio2sf/vio2sf.xcodeproj; sourceTree = "<group>"; }; 83DE0C34180A9BD400269051 /* vio2sf.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = vio2sf.xcodeproj; path = ../../Frameworks/vio2sf/vio2sf.xcodeproj; sourceTree = "<group>"; };
83DE0CBF180B27C200269051 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; 83DE0CBF180B27C200269051 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -226,6 +238,7 @@
8360EEDB17F92AC8005208A4 = { 8360EEDB17F92AC8005208A4 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
83D4481D18ACA5B1000F443A /* External */,
8360EEED17F92AC8005208A4 /* HighlyComplete */, 8360EEED17F92AC8005208A4 /* HighlyComplete */,
8360EEE617F92AC8005208A4 /* Frameworks */, 8360EEE617F92AC8005208A4 /* Frameworks */,
8360EEE517F92AC8005208A4 /* Products */, 8360EEE517F92AC8005208A4 /* Products */,
@ -306,6 +319,14 @@
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
83D4481D18ACA5B1000F443A /* External */ = {
isa = PBXGroup;
children = (
83D4481B18ACA5AD000F443A /* lazyusf */,
);
name = External;
sourceTree = "<group>";
};
83DE0C35180A9BD400269051 /* Products */ = { 83DE0C35180A9BD400269051 /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -325,6 +346,7 @@
8360EEE117F92AC8005208A4 /* Frameworks */, 8360EEE117F92AC8005208A4 /* Frameworks */,
8360EEE217F92AC8005208A4 /* Resources */, 8360EEE217F92AC8005208A4 /* Resources */,
83F18C3717F9300400471B6C /* CopyFiles */, 83F18C3717F9300400471B6C /* CopyFiles */,
83D4481A18ACA591000F443A /* CopyFiles */,
); );
buildRules = ( buildRules = (
); );

View File

@ -32,6 +32,10 @@
#include <zlib.h> #include <zlib.h>
#include <dlfcn.h>
// #define USF_LOG
@interface psf_file_container : NSObject { @interface psf_file_container : NSObject {
NSLock * lock; NSLock * lock;
NSMutableDictionary * list; NSMutableDictionary * list;
@ -879,11 +883,16 @@ static int twosf_info(void * context, const char * name, const char * value)
return 0; return 0;
} }
#if 0
struct usf_loader_state struct usf_loader_state
{ {
#ifdef USF_LOG
FILE * log; FILE * log;
FILE * fLazyusf; #endif
NSTask * task;
NSPipe * pipe_stdin;
NSPipe * pipe_stdout;
NSFileHandle * file_stdin;
NSFileHandle * file_stdout;
bool donewriting; bool donewriting;
uint32_t enablecompare; uint32_t enablecompare;
uint32_t enablefifofull; uint32_t enablefifofull;
@ -891,7 +900,11 @@ struct usf_loader_state
uint32_t pairsleft; uint32_t pairsleft;
usf_loader_state() usf_loader_state()
: log(NULL), fLazyusf(NULL), :
#ifdef USF_LOG
log(NULL),
#endif
task(nil), pipe_stdin(nil), pipe_stdout(nil),
enablecompare(0), enablefifofull(0), enablecompare(0), enablefifofull(0),
samplerate(0), pairsleft(0) { } samplerate(0), pairsleft(0) { }
@ -900,64 +913,88 @@ struct usf_loader_state
close(); close();
} }
void fwrite( const void * buf, ssize_t size, ssize_t count, FILE * f ) void fwrite( const void * buf, ssize_t size, ssize_t count )
{ {
::fwrite( buf, size, count, f ); [file_stdin writeData:[NSData dataWithBytes:buf length:size * count]];
#ifdef USF_LOG
if ( log ) if ( log )
{
::fwrite( buf, size, count, log ); ::fwrite( buf, size, count, log );
fflush( log );
}
#endif
}
ssize_t fread( void * buf, ssize_t size, ssize_t count )
{
NSData * data = [file_stdout readDataOfLength:size * count];
if ( data && [data length] )
{
memcpy( buf, [data bytes], [data length] );
return [data length] / size;
}
return 0;
} }
void open() void open()
{ {
close(); close();
#ifdef USF_LOG
log = fopen("/tmp/lazyusf_transaction", "w"); log = fopen("/tmp/lazyusf_transaction", "w");
fLazyusf = popen( "/usr/local/bin/lazyusf", "r+" ); #endif
fwrite( &enablecompare, sizeof(enablecompare), 1, fLazyusf ); Dl_info info;
fwrite( &enablefifofull, sizeof(enablefifofull), 1, fLazyusf ); dladdr( (void*) &twosf_info, &info );
NSString * base_path = [[NSString stringWithUTF8String:info.dli_fname] stringByDeletingLastPathComponent];
task = [[NSTask alloc] init];
[task setLaunchPath:[base_path stringByAppendingPathComponent:@"lazyusf"]];
pipe_stdin = [[NSPipe alloc] init];
pipe_stdout = [[NSPipe alloc] init];
[task setStandardInput:pipe_stdin];
[task setStandardOutput:pipe_stdout];
file_stdin = [pipe_stdin fileHandleForWriting];
file_stdout = [pipe_stdout fileHandleForReading];
[task launch];
fwrite( &enablecompare, sizeof(enablecompare), 1 );
fwrite( &enablefifofull, sizeof(enablefifofull), 1 );
donewriting = false; donewriting = false;
} }
void close() void close()
{ {
if (fLazyusf) if (task != nil)
{ {
uint32_t zero = 0; uint32_t zero = 0;
fwrite( &zero, sizeof(uint32_t), 1, fLazyusf ); fwrite( &zero, sizeof(uint32_t), 1 );
pclose( fLazyusf ); [task release];
task = nil;
[pipe_stdin release];
pipe_stdin = nil;
[pipe_stdout release];
pipe_stdout = nil;
} }
fLazyusf = NULL; #ifdef USF_LOG
if (log) fclose(log); if (log) fclose(log);
log = NULL; log = NULL;
#endif
} }
bool opened() bool opened()
{ {
return fLazyusf != NULL; return task != nil;
} }
void write_reserved( const uint8_t * reserved, uint32_t reserved_size ) void write_reserved( const uint8_t * reserved, uint32_t reserved_size )
{ {
fwrite( &reserved_size, sizeof(reserved_size), 1, fLazyusf ); fwrite( &reserved_size, sizeof(reserved_size), 1 );
if ( reserved_size ) fwrite( reserved, 1, reserved_size, fLazyusf ); if ( reserved_size ) fwrite( reserved, 1, reserved_size );
}
ssize_t fread( void * buf, ssize_t size, ssize_t count, FILE * f )
{
int d = fileno( f );
for (;;)
{
ssize_t r = read( d, buf, size * count );
if ( r == -1 && errno == EAGAIN )
{
usleep( 1000 );
continue;
}
else if ( r > 0 )
return r / size;
else
return -1;
}
} }
BOOL read_samples( int16_t * out, uint32_t out_pairs ) BOOL read_samples( int16_t * out, uint32_t out_pairs )
@ -965,37 +1002,35 @@ struct usf_loader_state
if ( !donewriting ) if ( !donewriting )
{ {
write_reserved( NULL, 0 ); write_reserved( NULL, 0 );
fflush( fLazyusf ); #ifdef USF_LOG
fclose( log ); log = NULL; fclose( log ); log = NULL;
int d = fileno(fLazyusf); #endif
fcntl(d, F_SETFL, fcntl(d, F_GETFL, 0) | O_NONBLOCK);
donewriting = true; donewriting = true;
} }
while ( out_pairs ) while ( out_pairs )
{ {
if ( !pairsleft ) if ( !pairsleft )
{ {
if (fread( &samplerate, sizeof(samplerate), 1, fLazyusf ) < 0) return NO; if (fread( &samplerate, sizeof(samplerate), 1 ) < 1) return NO;
if (fread( &pairsleft, sizeof(pairsleft), 1, fLazyusf ) < 0) return NO; if (fread( &pairsleft, sizeof(pairsleft), 1 ) < 1) return NO;
pairsleft >>= 1; pairsleft >>= 1;
} }
if ( pairsleft ) if ( pairsleft )
{ {
if ( pairsleft >= out_pairs ) if ( pairsleft > out_pairs )
{ {
if (fread( out, sizeof(int16_t) * 2, out_pairs, fLazyusf ) < 0) return NO; if (fread( out, sizeof(int16_t) * 2, out_pairs ) < out_pairs) return NO;
pairsleft -= out_pairs; pairsleft -= out_pairs;
return YES; return YES;
} }
if (fread( out, sizeof(int16_t) * 2, pairsleft, fLazyusf ) < 0) return NO; if (fread( out, sizeof(int16_t) * 2, pairsleft ) < pairsleft) return NO;
out += pairsleft * 2; out += pairsleft * 2;
out_pairs -= pairsleft; out_pairs -= pairsleft;
pairsleft = 0; pairsleft = 0;
uint32_t one = 1; uint32_t one = 1;
fwrite( &one, sizeof(one), 1, fLazyusf ); fwrite( &one, sizeof(one), 1 );
fflush( fLazyusf );
} }
} }
return YES; return YES;
@ -1029,7 +1064,6 @@ static int usf_info(void * context, const char * name, const char * value)
return 0; return 0;
} }
#endif
- (BOOL)initializeDecoder - (BOOL)initializeDecoder
{ {
@ -1098,7 +1132,6 @@ static int usf_info(void * context, const char * name, const char * value)
free( state.data ); free( state.data );
} }
#if 0
else if ( type == 0x21 ) else if ( type == 0x21 )
{ {
struct usf_loader_state * uUsf = new usf_loader_state; struct usf_loader_state * uUsf = new usf_loader_state;
@ -1108,7 +1141,6 @@ static int usf_info(void * context, const char * name, const char * value)
if ( psf_load( [currentUrl UTF8String], &source_callbacks, 0x21, usf_loader, uUsf, usf_info, uUsf ) <= 0 ) if ( psf_load( [currentUrl UTF8String], &source_callbacks, 0x21, usf_loader, uUsf, usf_info, uUsf ) <= 0 )
return NO; return NO;
} }
#endif
else if ( type == 0x22 ) else if ( type == 0x22 )
{ {
struct gsf_loader_state state; struct gsf_loader_state state;
@ -1383,7 +1415,6 @@ static int usf_info(void * context, const char * name, const char * value)
sega_execute( emulatorCore, 0x7fffffff, ( int16_t * ) buf, &howmany ); sega_execute( emulatorCore, 0x7fffffff, ( int16_t * ) buf, &howmany );
frames = howmany; frames = howmany;
} }
#if 0
else if ( type == 0x21 ) else if ( type == 0x21 )
{ {
struct usf_loader_state * uUsf = ( struct usf_loader_state * ) emulatorCore; struct usf_loader_state * uUsf = ( struct usf_loader_state * ) emulatorCore;
@ -1393,7 +1424,6 @@ static int usf_info(void * context, const char * name, const char * value)
sampleRate = uUsf->samplerate; sampleRate = uUsf->samplerate;
} }
#endif
else if ( type == 0x22 ) else if ( type == 0x22 )
{ {
GBASystem * system = ( GBASystem * ) emulatorCore; GBASystem * system = ( GBASystem * ) emulatorCore;
@ -1507,13 +1537,10 @@ static int usf_info(void * context, const char * name, const char * value)
- (void)closeDecoder - (void)closeDecoder
{ {
if ( emulatorCore ) { if ( emulatorCore ) {
#if 0
if ( type == 0x21 ) { if ( type == 0x21 ) {
struct usf_loader_state * uUsf = ( struct usf_loader_state * ) emulatorCore; struct usf_loader_state * uUsf = ( struct usf_loader_state * ) emulatorCore;
delete uUsf; delete uUsf;
} else } else if ( type == 0x22 ) {
#endif
if ( type == 0x22 ) {
GBASystem * system = ( GBASystem * ) emulatorCore; GBASystem * system = ( GBASystem * ) emulatorCore;
CPUCleanUp( system ); CPUCleanUp( system );
soundShutdown( system ); soundShutdown( system );
@ -1604,7 +1631,6 @@ static int usf_info(void * context, const char * name, const char * value)
} }
while (framesRead < frame); while (framesRead < frame);
} }
#if 0
else if ( type == 0x21 ) else if ( type == 0x21 )
{ {
struct usf_loader_state * uUsf = ( struct usf_loader_state * ) emulatorCore; struct usf_loader_state * uUsf = ( struct usf_loader_state * ) emulatorCore;
@ -1617,7 +1643,6 @@ static int usf_info(void * context, const char * name, const char * value)
framesRead += howmany; framesRead += howmany;
} while (framesRead < frame); } while (framesRead < frame);
} }
#endif
else if ( type == 0x22 ) else if ( type == 0x22 )
{ {
GBASystem * system = ( GBASystem * ) emulatorCore; GBASystem * system = ( GBASystem * ) emulatorCore;
@ -1739,11 +1764,7 @@ static int usf_info(void * context, const char * name, const char * value)
+ (NSArray *)fileTypes + (NSArray *)fileTypes
{ {
return [NSArray arrayWithObjects:@"psf",@"minipsf",@"psf2", @"minipsf2", @"ssf", @"minissf", @"dsf", @"minidsf", @"qsf", @"miniqsf", @"gsf", @"minigsf", @"ncsf", @"minincsf", @"2sf", @"mini2sf", return [NSArray arrayWithObjects:@"psf",@"minipsf",@"psf2", @"minipsf2", @"ssf", @"minissf", @"dsf", @"minidsf", @"qsf", @"miniqsf", @"gsf", @"minigsf", @"ncsf", @"minincsf", @"2sf", @"mini2sf", @"usf", @"miniusf", nil];
#if 0
@"usf", @"miniusf",
#endif
nil];
} }
+ (NSArray *)mimeTypes + (NSArray *)mimeTypes

BIN
ThirdParty/lazyusf/lazyusf vendored Executable file

Binary file not shown.