[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx: [525] trunk
Brought to you by:
fredm
|
From: <fr...@us...> - 2008-05-04 09:11:08
|
Revision: 525
http://fuse-for-macosx.svn.sourceforge.net/fuse-for-macosx/?rev=525&view=rev
Author: fredm
Date: 2008-05-04 02:11:05 -0700 (Sun, 04 May 2008)
Log Message:
-----------
Add support for TZX custom screenshot and tape inlay blocks.
Modified Paths:
--------------
trunk/FuseGenerator/GeneratePreviewForURL.m
trunk/FuseGenerator/GenerateThumbnailForURL.m
trunk/FuseGenerator/LibspectrumSCRExtractor.h
trunk/FuseGenerator/LibspectrumSCRExtractor.m
trunk/fuse/TODO
Modified: trunk/FuseGenerator/GeneratePreviewForURL.m
===================================================================
--- trunk/FuseGenerator/GeneratePreviewForURL.m 2008-04-29 13:50:38 UTC (rev 524)
+++ trunk/FuseGenerator/GeneratePreviewForURL.m 2008-05-04 09:11:05 UTC (rev 525)
@@ -1,5 +1,5 @@
/* GeneratePreviewForURL.m: Extract preview from libspectrum-supported Spectrum files
- Copyright (c) 2005 Fredrick Meunier
+ Copyright (c) 2007-2008 Fredrick Meunier
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
@@ -24,6 +24,7 @@
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <QuickLook/QuickLook.h>
+#include <QuickLook/QLGenerator.h>
#import "JWSpectrumScreen/JWSpectrumScreen.h"
#import "LibspectrumSCRExtractor.h"
@@ -36,42 +37,73 @@
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
- NSAutoreleasePool *pool;
- LibspectrumSCRExtractor *speccyFile;
+ NSAutoreleasePool *pool;
+ LibspectrumSCRExtractor *speccyFile;
- /* Don't assume that there is an autorelease pool around the calling of this function. */
- pool = [[NSAutoreleasePool alloc] init];
+ /* Don't assume that there is an autorelease pool around the calling of
+ this function. */
+ pool = [[NSAutoreleasePool alloc] init];
- speccyFile = [[[LibspectrumSCRExtractor alloc] initWithContentsOfURL:(NSURL*)url] autorelease];
+ speccyFile = [[[LibspectrumSCRExtractor alloc]
+ initWithContentsOfURL:(NSURL*)url] autorelease];
- JWSpectrumScreen* screen = [[[JWSpectrumScreen alloc] initFromData:[speccyFile scrData]] autorelease];
- NSBitmapImageRep* imageRep = [[screen imageRep] retain];
- NSSize canvasSize = [screen canvasSize];
-
- CGContextRef cgContext = QLPreviewRequestCreateContext(preview, *(CGSize *)&canvasSize, false, NULL);
- if(cgContext) {
- NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:(void*)cgContext flipped:YES];
- if(context) {
- [NSGraphicsContext saveGraphicsState];
- [NSGraphicsContext setCurrentContext:context];
-
- // Now we're ready to draw using Cocoa.
- NSImage* image = [[[NSImage alloc] initWithSize:canvasSize] autorelease];
- [image addRepresentation:imageRep];
- NSRect imageRect = NSMakeRect(0.0, 0.0, canvasSize.width, canvasSize.height);
- [image drawAtPoint:NSMakePoint(0.0, 0.0)
- fromRect:imageRect
- operation:NSCompositeSourceOver
- fraction:1.0];
- [NSGraphicsContext restoreGraphicsState];
- }
- QLPreviewRequestFlushContext(preview, cgContext);
- CFRelease(cgContext);
- }
-
+ /* No preview for tapes, these are going to have inlays etc. which are more
+ like album art in mp3s than file previews IMO */
+ if( [speccyFile class] == LIBSPECTRUM_CLASS_TAPE ) {
[pool release];
+ return noErr;
+ }
- return noErr;
+ switch( [speccyFile image_type] ) {
+ case TYPE_SCR:
+ {
+ JWSpectrumScreen* screen =
+ [[[JWSpectrumScreen alloc] initFromData:[speccyFile scrData]]
+ autorelease];
+ NSBitmapImageRep* imageRep = [[screen imageRep] retain];
+ NSSize canvasSize = [screen canvasSize];
+
+ CGContextRef cgContext =
+ QLPreviewRequestCreateContext( preview, *(CGSize *)&canvasSize,
+ false, NULL );
+ if( cgContext ) {
+ NSGraphicsContext* context =
+ [NSGraphicsContext graphicsContextWithGraphicsPort:(void*)cgContext
+ flipped:YES];
+ if(context) {
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext:context];
+
+ /* Now we're ready to draw using Cocoa. */
+ NSImage* image =
+ [[[NSImage alloc] initWithSize:canvasSize] autorelease];
+ [image addRepresentation:imageRep];
+ NSRect imageRect = NSMakeRect( 0.0, 0.0, canvasSize.width,
+ canvasSize.height );
+ [image drawAtPoint:NSMakePoint(0.0, 0.0)
+ fromRect:imageRect
+ operation:NSCompositeSourceOver
+ fraction:1.0];
+ [NSGraphicsContext restoreGraphicsState];
+ }
+ QLPreviewRequestFlushContext(preview, cgContext);
+ CFRelease(cgContext);
+ }
+ }
+ break;
+ case TYPE_IMAGEIO:
+ QLPreviewRequestSetDataRepresentation( preview,
+ (CFDataRef)[speccyFile scrData],
+ kUTTypeImage,
+ NULL );
+ break;
+ default:
+ break;
+ }
+
+ [pool release];
+
+ return noErr;
}
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
Modified: trunk/FuseGenerator/GenerateThumbnailForURL.m
===================================================================
--- trunk/FuseGenerator/GenerateThumbnailForURL.m 2008-04-29 13:50:38 UTC (rev 524)
+++ trunk/FuseGenerator/GenerateThumbnailForURL.m 2008-05-04 09:11:05 UTC (rev 525)
@@ -1,5 +1,5 @@
/* GenerateThumbnailForURL.m: Extract thumbnail from libspectrum-supported Spectrum files
- Copyright (c) 2005 Fredrick Meunier
+ Copyright (c) 2007-2008 Fredrick Meunier
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
@@ -24,6 +24,7 @@
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <QuickLook/QuickLook.h>
+#include <QuickLook/QLGenerator.h>
#import "JWSpectrumScreen/JWSpectrumScreen.h"
#import "LibspectrumSCRExtractor.h"
@@ -36,44 +37,64 @@
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
{
- NSAutoreleasePool *pool;
- LibspectrumSCRExtractor *speccyFile;
+ NSAutoreleasePool *pool;
+ LibspectrumSCRExtractor *speccyFile;
- /* Don't assume that there is an autorelease pool around the calling of this function. */
- pool = [[NSAutoreleasePool alloc] init];
+ /* Don't assume that there is an autorelease pool around the calling of this
+ function. */
+ pool = [[NSAutoreleasePool alloc] init];
- speccyFile = [[[LibspectrumSCRExtractor alloc] initWithContentsOfURL:(NSURL*)url] autorelease];
+ speccyFile = [[[LibspectrumSCRExtractor alloc]
+ initWithContentsOfURL:(NSURL*)url] autorelease];
- if( [speccyFile scrData] ) {
- JWSpectrumScreen* screen = [[[JWSpectrumScreen alloc] initFromData:[speccyFile scrData]] autorelease];
- NSBitmapImageRep* imageRep = [[screen imageRep] retain];
- NSSize canvasSize = [screen canvasSize];
-
- CGContextRef cgContext = QLThumbnailRequestCreateContext(thumbnail, *(CGSize *)&canvasSize, false, NULL);
- if(cgContext) {
- NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:(void*)cgContext flipped:YES];
- if(context) {
- [NSGraphicsContext saveGraphicsState];
- [NSGraphicsContext setCurrentContext:context];
-
- // Now we're ready to draw using Cocoa.
- NSImage* image = [[[NSImage alloc] initWithSize:canvasSize] autorelease];
- [image addRepresentation:imageRep];
- NSRect imageRect = NSMakeRect(0.0, 0.0, canvasSize.width, canvasSize.height);
- [image drawAtPoint:NSMakePoint(0.0, 0.0)
- fromRect:imageRect
- operation:NSCompositeSourceOver
- fraction:1.0];
- [NSGraphicsContext restoreGraphicsState];
- }
- QLThumbnailRequestFlushContext(thumbnail, cgContext);
- CFRelease(cgContext);
- }
+ switch( [speccyFile image_type] ) {
+ case TYPE_SCR:
+ {
+ JWSpectrumScreen* screen =
+ [[[JWSpectrumScreen alloc] initFromData:[speccyFile scrData]] autorelease];
+ NSBitmapImageRep* imageRep = [[screen imageRep] retain];
+ NSSize canvasSize = [screen canvasSize];
+
+ CGContextRef cgContext =
+ QLThumbnailRequestCreateContext( thumbnail, *(CGSize *)&canvasSize,
+ false, NULL );
+ if( cgContext ) {
+ NSGraphicsContext* context =
+ [NSGraphicsContext graphicsContextWithGraphicsPort:(void*)cgContext
+ flipped:YES];
+ if( context ) {
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext:context];
+
+ // Now we're ready to draw using Cocoa.
+ NSImage* image =
+ [[[NSImage alloc] initWithSize:canvasSize] autorelease];
+ [image addRepresentation:imageRep];
+ NSRect imageRect =
+ NSMakeRect( 0.0, 0.0, canvasSize.width, canvasSize.height );
+ [image drawAtPoint:NSMakePoint(0.0, 0.0)
+ fromRect:imageRect
+ operation:NSCompositeSourceOver
+ fraction:1.0];
+ [NSGraphicsContext restoreGraphicsState];
+ }
+ QLThumbnailRequestFlushContext( thumbnail, cgContext );
+ CFRelease( cgContext );
+ }
}
-
- [pool release];
+ break;
+ case TYPE_IMAGEIO:
+ QLThumbnailRequestSetImageWithData( thumbnail,
+ (CFDataRef)[speccyFile scrData],
+ (CFDictionaryRef)[speccyFile scrOptions] );
+ break;
+ default:
+ break;
+ }
+
+ [pool release];
- return noErr;
+ return noErr;
}
void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail)
Modified: trunk/FuseGenerator/LibspectrumSCRExtractor.h
===================================================================
--- trunk/FuseGenerator/LibspectrumSCRExtractor.h 2008-04-29 13:50:38 UTC (rev 524)
+++ trunk/FuseGenerator/LibspectrumSCRExtractor.h 2008-05-04 09:11:05 UTC (rev 525)
@@ -26,9 +26,17 @@
#include <sys/types.h>
#include <libspectrum.h>
+typedef enum image_t {
+ TYPE_NONE,
+ TYPE_SCR,
+ TYPE_IMAGEIO,
+} image_t;
+
@interface LibspectrumSCRExtractor : NSObject {
NSString *filename;
NSData *scrData;
+ NSDictionary *scrOptions;
+ image_t image_type;
unsigned char *buffer;
size_t length;
libspectrum_id_t type;
@@ -38,6 +46,8 @@
- (libspectrum_class_t) class;
- (NSData*) scrData;
+- (NSDictionary*) scrOptions;
+- (image_t) image_type;
- (void) processFile;
Modified: trunk/FuseGenerator/LibspectrumSCRExtractor.m
===================================================================
--- trunk/FuseGenerator/LibspectrumSCRExtractor.m 2008-04-29 13:50:38 UTC (rev 524)
+++ trunk/FuseGenerator/LibspectrumSCRExtractor.m 2008-05-04 09:11:05 UTC (rev 525)
@@ -1,5 +1,5 @@
/* LibspectrumSCRExtractor.m: Extract SCR image from libspectrum-supported Spectrum files
- Copyright (c) 2007 Fredrick Meunier
+ Copyright (c) 2007-2008 Fredrick Meunier
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
@@ -43,193 +43,264 @@
static int
mmap_file( const char *filename, unsigned char **buffer, size_t *length )
{
- int fd; struct stat file_info;
-
- if( ( fd = open( filename, O_RDONLY ) ) == -1 ) {
- NSLog(@"LibspectrumSCRExtractor: couldn't open `%s': %s\n", filename,
- strerror( errno ) );
- return 1;
- }
+ int fd; struct stat file_info;
- if( fstat( fd, &file_info) ) {
- NSLog(@"LibspectrumSCRExtractor: couldn't stat `%s': %s\n", filename,
- strerror( errno ) );
- close(fd);
- return 1;
- }
+ if( ( fd = open( filename, O_RDONLY ) ) == -1 ) {
+ NSLog(@"LibspectrumSCRExtractor: couldn't open `%s': %s\n", filename,
+ strerror( errno ) );
+ return 1;
+ }
- (*length) = file_info.st_size;
+ if( fstat( fd, &file_info) ) {
+ NSLog(@"LibspectrumSCRExtractor: couldn't stat `%s': %s\n", filename,
+ strerror( errno ) );
+ close(fd);
+ return 1;
+ }
- (*buffer) = mmap( 0, *length, PROT_READ, MAP_SHARED, fd, 0 );
- if( (*buffer) == (void*)-1 ) {
- NSLog(@"LibspectrumSCRExtractor: couldn't mmap `%s': %s\n", filename,
- strerror( errno ) );
- close(fd);
- return 1;
- }
+ (*length) = file_info.st_size;
- if( close(fd) ) {
- NSLog(@"LibspectrumSCRExtractor: couldn't close `%s': %s\n", filename,
- strerror( errno ) );
- munmap( *buffer, *length );
- return 1;
- }
+ (*buffer) = mmap( 0, *length, PROT_READ, MAP_SHARED, fd, 0 );
+ if( (*buffer) == (void*)-1 ) {
+ NSLog(@"LibspectrumSCRExtractor: couldn't mmap `%s': %s\n", filename,
+ strerror( errno ) );
+ close(fd);
+ return 1;
+ }
- return 0;
+ if( close(fd) ) {
+ NSLog(@"LibspectrumSCRExtractor: couldn't close `%s': %s\n", filename,
+ strerror( errno ) );
+ munmap( *buffer, *length );
+ return 1;
+ }
+
+ return 0;
}
@implementation LibspectrumSCRExtractor
- (id)initWithContentsOfURL:(NSURL*)aURL
{
- const char *fileString;
- self = [super init];
-
- fileString = [[NSFileManager defaultManager] fileSystemRepresentationWithPath:[aURL path]];
- filename = [NSString stringWithUTF8String:fileString];
+ const char *fileString;
+ self = [super init];
- scrData = nil;
+ fileString = [[NSFileManager defaultManager] fileSystemRepresentationWithPath:[aURL path]];
+ filename = [NSString stringWithUTF8String:fileString];
- return self;
+ scrData = nil;
+ scrOptions = nil;
+
+ image_type = TYPE_NONE;
+
+ return self;
}
- (libspectrum_class_t) class
{
- return lsclass;
+ if(!scrData) { [self processFile]; }
+
+ return lsclass;
}
- (NSData*) scrData
{
- if(!scrData) {
- [self processFile];
- }
-
- return scrData;
+ if(!scrData) { [self processFile]; }
+
+ return scrData;
}
+- (NSDictionary*) scrOptions
+{
+ if(!scrData) { [self processFile]; }
+
+ return scrOptions;
+}
+
+- (image_t) image_type
+{
+ if(!scrData) { [self processFile]; }
+
+ return image_type;
+}
+
- (void) processFile
{
- if( mmap_file( [filename UTF8String], &buffer, &length ) ) return;
+ if( mmap_file( [filename UTF8String], &buffer, &length ) ) return;
- if( libspectrum_identify_file( &type, [filename UTF8String], buffer, length ) ) {
- munmap( buffer, length );
- return;
- }
+ if( libspectrum_identify_file_with_class( &type, &lsclass,
+ [filename UTF8String],
+ buffer, length ) ) {
+ munmap( buffer, length );
+ return;
+ }
- if( libspectrum_identify_class( &lsclass, type ) ) {
- munmap( buffer, length );
- return;
- }
+ switch( lsclass ) {
- switch( lsclass ) {
+ case LIBSPECTRUM_CLASS_UNKNOWN:
+ NSLog( @"LibspectrumSCRExtractor: couldn't identify `%s'\n", [filename UTF8String] );
+ break;
- case LIBSPECTRUM_CLASS_UNKNOWN:
- NSLog( @"LibspectrumSCRExtractor: couldn't identify `%s'\n", [filename UTF8String] );
- break;
+ case LIBSPECTRUM_CLASS_RECORDING:
+ [self process_rzx];
+ break;
- case LIBSPECTRUM_CLASS_RECORDING:
- [self process_rzx];
- break;
+ case LIBSPECTRUM_CLASS_SNAPSHOT:
+ [self process_snap];
+ break;
- case LIBSPECTRUM_CLASS_SNAPSHOT:
- [self process_snap];
- break;
+ case LIBSPECTRUM_CLASS_TAPE:
+ [self process_tape];
+ break;
- case LIBSPECTRUM_CLASS_TAPE:
- [self process_tape];
- break;
+ case LIBSPECTRUM_CLASS_SCREENSHOT:
+ [self process_scr];
+ break;
- case LIBSPECTRUM_CLASS_SCREENSHOT:
- [self process_scr];
- break;
+ case LIBSPECTRUM_CLASS_MICRODRIVE:
+ [self process_mdr];
+ break;
- case LIBSPECTRUM_CLASS_MICRODRIVE:
- [self process_mdr];
- break;
+ case LIBSPECTRUM_CLASS_DISK_PLUS3:
+ case LIBSPECTRUM_CLASS_DISK_TRDOS:
+ case LIBSPECTRUM_CLASS_HARDDISK:
+ case LIBSPECTRUM_CLASS_CARTRIDGE_TIMEX:
+ case LIBSPECTRUM_CLASS_CARTRIDGE_IF2:
+ break;
- case LIBSPECTRUM_CLASS_DISK_PLUS3:
- case LIBSPECTRUM_CLASS_DISK_TRDOS:
- case LIBSPECTRUM_CLASS_HARDDISK:
- case LIBSPECTRUM_CLASS_CARTRIDGE_TIMEX:
- case LIBSPECTRUM_CLASS_CARTRIDGE_IF2:
- break;
+ default:
+ NSLog(@"LibspectrumSCRExtractor: loadFile: unknown class %d!\n", type );
+ }
- default:
- NSLog(@"LibspectrumSCRExtractor: loadFile: unknown class %d!\n", type );
- }
-
- if( munmap( buffer, length ) == -1 ) {
- NSLog(@"LibspectrumSCRExtractor: couldn't munmap `%s': %s\n", [filename UTF8String],
- strerror( errno ) );
- return;
- }
+ if( munmap( buffer, length ) == -1 ) {
+ NSLog(@"LibspectrumSCRExtractor: couldn't munmap `%s': %s\n", [filename UTF8String],
+ strerror( errno ) );
+ return;
+ }
}
-// If a tape has a ROM header block for Bytes length 6192, location 16384 followed by
-// a ROM data block of 6192 bytes, use that as a SCR
+// If a tape has a ROM header block for Bytes length 6192, location 16384
+// followed by a ROM data block of 6192 bytes, use that as a SCR
+// Also have a look at turbo blocks as sometimes the timing is just a bit
+// different from the ROM values, but are otherwise identical
+// And finally look for TZX custom blocks with loading screens or tape inlays
- (void) process_tape
{
- int error = 0;
+ int error = 0;
- libspectrum_tape *tape;
- libspectrum_tape_iterator iterator;
- libspectrum_tape_block *block;
+ libspectrum_tape *tape;
+ libspectrum_tape_iterator iterator;
+ libspectrum_tape_block *block;
- int seen_scr_header = 0;
+ int seen_scr_header = 0;
- error = libspectrum_tape_alloc( &tape );
- if( error != LIBSPECTRUM_ERROR_NONE ) {
- return;
- }
+ error = libspectrum_tape_alloc( &tape );
+ if( error != LIBSPECTRUM_ERROR_NONE ) { return; }
- error = libspectrum_tape_read( tape, buffer, length, LIBSPECTRUM_ID_UNKNOWN,
- [filename UTF8String] );
- if( error ) { return; }
+ error = libspectrum_tape_read( tape, buffer, length, LIBSPECTRUM_ID_UNKNOWN,
+ [filename UTF8String] );
+ if( error ) { return; }
- block = libspectrum_tape_iterator_init( &iterator, tape );
+ block = libspectrum_tape_iterator_init( &iterator, tape );
- while( block ) {
-
- switch( libspectrum_tape_block_type( block ) ) {
+ while( block ) {
+
+ switch( libspectrum_tape_block_type( block ) ) {
- case LIBSPECTRUM_TAPE_BLOCK_ROM:
- /* See if this looks like a standard Spectrum screen and if so
- display it */
- if( seen_scr_header ) {
- // SCREEN$ is 6912 bytes plus flag and checksum
- if( libspectrum_tape_block_data_length( block ) == STANDARD_SCR_SIZE + 2 ) {
- libspectrum_byte *data = libspectrum_tape_block_data( block );
+ case LIBSPECTRUM_TAPE_BLOCK_ROM:
+ case LIBSPECTRUM_TAPE_BLOCK_TURBO:
+ /* See if this looks like a standard Spectrum screen and if so
+ display it if we haben't already assigned an image */
+ if( scrData ) continue;
- scrData = [NSData dataWithBytes:(const void *)(data+1) length:STANDARD_SCR_SIZE];
- goto done;
- } else {
- seen_scr_header = 0;
- }
- } else {
- // Header is 17 bytes plus flag and checksum
- if( libspectrum_tape_block_data_length( block ) == 19 ) {
- libspectrum_byte *data = libspectrum_tape_block_data( block );
+ if( seen_scr_header ) {
+ // SCREEN$ is 6912 bytes plus flag and checksum
+ if( libspectrum_tape_block_data_length( block ) ==
+ STANDARD_SCR_SIZE + 2 ) {
+ libspectrum_byte *data = libspectrum_tape_block_data( block );
- /* Flag byte is 0x00 for headers, type is 3 for CODE, length is 6912 */
- if( data[0] == 0x00 && data[1] == 0x03 &&
- ( data[12] + data[13] * 0x100 == STANDARD_SCR_SIZE ) ) {
- seen_scr_header = 1;
- }
- }
- }
- break;
+ scrData = [NSData dataWithBytes:(const void *)(data+1)
+ length:STANDARD_SCR_SIZE];
- default:
- seen_scr_header = 0;
- }
-
- block = libspectrum_tape_iterator_next( &iterator );
+ image_type = TYPE_SCR;
+ goto done;
+ } else {
+ seen_scr_header = 0;
+ }
+ } else {
+ // Header is 17 bytes plus flag and checksum
+ if( libspectrum_tape_block_data_length( block ) == 19 ) {
+ libspectrum_byte *data = libspectrum_tape_block_data( block );
+
+ /* Flag byte is 0x00 for headers, type is 3 for CODE, length is 6912 */
+ if( data[0] == 0x00 && data[1] == 0x03 &&
+ ( data[12] + data[13] * 0x100 == STANDARD_SCR_SIZE ) ) {
+ seen_scr_header = 1;
+ }
+ }
+ }
+ break;
+
+ case LIBSPECTRUM_TAPE_BLOCK_CUSTOM:
+ {
+ char* description = libspectrum_tape_block_text( block );
+ if( !description ) { continue; }
+
+ if( !scrData &&
+ strncmp( "Spectrum Screen ", description, 0x10 ) == 0 ) {
+ size_t data_length = libspectrum_tape_block_data_length( block );
+ libspectrum_byte *data = libspectrum_tape_block_data( block );
+ size_t scr_length = data_length - data[0] - 2;
+
+ if( scr_length == STANDARD_SCR_SIZE ||
+ scr_length == HICOLOUR_SCR_SIZE ||
+ scr_length == HIRES_SCR_SIZE ) {
+ scrData = [NSData dataWithBytes:(const void *)(data+data[0]+2)
+ length:scr_length];
+
+ image_type = TYPE_SCR;
+ }
+ } else if( strncmp( "Picture ", description, 0x10 ) == 0 ) {
+ size_t data_length = libspectrum_tape_block_data_length( block );
+ libspectrum_byte *data = libspectrum_tape_block_data( block );
+ size_t picture_length = data_length - data[1] - 2;
+
+ /* Image is an 'Inlay Card' and is in GIF or JPEG format */
+ if( data[1] == 0 && ( data[0] == 0 || data[0] == 1 ) ) {
+ id myValue = nil;
+
+ switch( data[0] ) {
+ case 0: myValue = (NSString*)kUTTypeGIF; break;
+ case 1: myValue = (NSString*)kUTTypeJPEG; break;
+ }
+
+ scrOptions =
+ [NSDictionary dictionaryWithObject:myValue
+ forKey:(NSString*)kCGImageSourceTypeIdentifierHint];
+
+ scrData = [NSData dataWithBytes:data + data[1] + 2
+ length:picture_length];
+
+ image_type = TYPE_IMAGEIO;
+
+ goto done;
+ }
+ }
+ }
+ break;
+
+ default:
+ seen_scr_header = 0;
}
+
+ block = libspectrum_tape_iterator_next( &iterator );
+ }
+
done:
- error = libspectrum_tape_free( tape );
- if( error ) { return; }
+ error = libspectrum_tape_free( tape );
+ if( error ) { return; }
}
// FIXME: Could look for first screen file on cart?
@@ -240,152 +311,152 @@
// Populate scrData directly
- (void) process_scr
{
- scrData = [NSData dataWithBytes:(const void *)buffer length:length];
+ scrData = [NSData dataWithBytes:(const void *)buffer length:length];
+ image_type = TYPE_SCR;
}
// Extract first snap then delegate to process_snap2
- (void) process_rzx
{
- int error = 0;
- libspectrum_rzx *rzx;
- libspectrum_snap *snap;
-
- error = libspectrum_rzx_alloc( &rzx ); if( error ) return;
+ int error = 0;
+ libspectrum_rzx *rzx;
+ libspectrum_snap *snap;
- error = libspectrum_rzx_read( rzx, buffer, length );
- if( error != LIBSPECTRUM_ERROR_NONE ) {
- return;
- }
+ error = libspectrum_rzx_alloc( &rzx ); if( error ) return;
- error = libspectrum_rzx_start_playback( rzx, 0, &snap );
- if( error ) { return; }
+ error = libspectrum_rzx_read( rzx, buffer, length );
+ if( error != LIBSPECTRUM_ERROR_NONE ) { return; }
- if( snap ) {
- [self process_snap2:snap];
- }
+ error = libspectrum_rzx_start_playback( rzx, 0, &snap );
+ if( error ) { return; }
- error = libspectrum_rzx_free( rzx );
- if( error ) { return; }
+ if( snap ) {
+ [self process_snap2:snap];
+ }
+
+ error = libspectrum_rzx_free( rzx );
+ if( error ) { return; }
}
// Extract active screen from snap
- (void) process_snap
{
- int error = 0;
- libspectrum_snap *snap;
+ int error = 0;
+ libspectrum_snap *snap;
- error = libspectrum_snap_alloc( &snap );
- if( error != LIBSPECTRUM_ERROR_NONE ) {
- return;
- }
+ error = libspectrum_snap_alloc( &snap );
+ if( error != LIBSPECTRUM_ERROR_NONE ) { return; }
- error = libspectrum_snap_read( snap, buffer, length, type, [filename UTF8String] );
- if( error ) {
- libspectrum_snap_free( snap );
- return;
- }
+ error = libspectrum_snap_read( snap, buffer, length, type,
+ [filename UTF8String] );
+ if( error ) { libspectrum_snap_free( snap ); return; }
- [self process_snap2:snap];
+ [self process_snap2:snap];
- error = libspectrum_snap_free( snap );
- if( error ) { return; }
+ error = libspectrum_snap_free( snap );
+ if( error ) { return; }
}
- (void) process_snap2:(libspectrum_snap *)snap
{
- switch(libspectrum_snap_machine(snap)) {
- case LIBSPECTRUM_MACHINE_16:
- case LIBSPECTRUM_MACHINE_48:
- [self process_snap_sinclair48:snap];
- break;
-
- case LIBSPECTRUM_MACHINE_TC2048:
- case LIBSPECTRUM_MACHINE_TC2068:
- case LIBSPECTRUM_MACHINE_TS2068:
- [self process_snap_timex:snap];
- break;
-
- case LIBSPECTRUM_MACHINE_128:
- case LIBSPECTRUM_MACHINE_PLUS2:
- case LIBSPECTRUM_MACHINE_PENT:
- case LIBSPECTRUM_MACHINE_PLUS2A:
- case LIBSPECTRUM_MACHINE_PLUS3:
- case LIBSPECTRUM_MACHINE_SCORP:
- case LIBSPECTRUM_MACHINE_PLUS3E:
- case LIBSPECTRUM_MACHINE_PENT512:
- case LIBSPECTRUM_MACHINE_PENT1024:
- [self process_snap_sinclair128:snap];
- break;
+ switch(libspectrum_snap_machine(snap)) {
+ case LIBSPECTRUM_MACHINE_16:
+ case LIBSPECTRUM_MACHINE_48:
+ [self process_snap_sinclair48:snap];
+ break;
+
+ case LIBSPECTRUM_MACHINE_TC2048:
+ case LIBSPECTRUM_MACHINE_TC2068:
+ case LIBSPECTRUM_MACHINE_TS2068:
+ [self process_snap_timex:snap];
+ break;
+
+ case LIBSPECTRUM_MACHINE_128:
+ case LIBSPECTRUM_MACHINE_PLUS2:
+ case LIBSPECTRUM_MACHINE_PENT:
+ case LIBSPECTRUM_MACHINE_PLUS2A:
+ case LIBSPECTRUM_MACHINE_PLUS3:
+ case LIBSPECTRUM_MACHINE_SCORP:
+ case LIBSPECTRUM_MACHINE_PLUS3E:
+ case LIBSPECTRUM_MACHINE_PENT512:
+ case LIBSPECTRUM_MACHINE_PENT1024:
+ [self process_snap_sinclair128:snap];
+ break;
- case LIBSPECTRUM_MACHINE_SE:
- [self process_snap_se:snap];
- break;
-
- default:
- break;
- }
+ case LIBSPECTRUM_MACHINE_SE:
+ [self process_snap_se:snap];
+ break;
+
+ default:
+ break;
+ }
}
- (void) process_snap_sinclair48:(libspectrum_snap *)snap
{
- // Just need to copy out first 6912 bytes from page 5
- scrData = [NSData dataWithBytes:(const void *)libspectrum_snap_pages( snap, 5 ) length:STANDARD_SCR_SIZE];
+ // Just need to copy out first 6912 bytes from page 5
+ scrData = [NSData dataWithBytes:(const void *)libspectrum_snap_pages( snap, 5 )
+ length:STANDARD_SCR_SIZE];
+ image_type = TYPE_SCR;
}
- (void) process_snap_sinclair128:(libspectrum_snap *)snap
{
- // Check which screen page is active and copy standard 6912 bytes
- int screen = ( libspectrum_snap_out_128_memoryport( snap ) & 0x08 ) ? 7 : 5;
- scrData = [NSData dataWithBytes:(const void *)libspectrum_snap_pages( snap, screen ) length:STANDARD_SCR_SIZE];
+ // Check which screen page is active and copy standard 6912 bytes
+ int screen = ( libspectrum_snap_out_128_memoryport( snap ) & 0x08 ) ? 7 : 5;
+ scrData = [NSData dataWithBytes:(const void *)libspectrum_snap_pages( snap, screen )
+ length:STANDARD_SCR_SIZE];
+ image_type = TYPE_SCR;
}
- (void) process_snap_timex:(libspectrum_snap *)snap inPage:(int)page
{
- // Check which screen mode and pages are active and copy as appropriate
- libspectrum_byte scr_data[HIRES_SCR_SIZE];
- int scr_length;
+ // Check which screen mode and pages are active and copy as appropriate
+ libspectrum_byte scr_data[HIRES_SCR_SIZE];
+ int scr_length;
- memset( scr_data, 0, HIRES_SCR_SIZE );
+ memset( scr_data, 0, HIRES_SCR_SIZE );
- if( libspectrum_snap_out_scld_dec( snap ) & 0x04 ) {
- memcpy( scr_data,
- libspectrum_snap_pages( snap, page ),
- MONO_BITMAP_SIZE );
- memcpy( scr_data + MONO_BITMAP_SIZE,
- libspectrum_snap_pages( snap, page ) + ALTDFILE_OFFSET,
- MONO_BITMAP_SIZE );
- scr_data[HIRES_ATTR] = ( libspectrum_snap_out_scld_dec( snap ) & HIRESCOLMASK ) | 0x07;
- scr_length = HIRES_SCR_SIZE;
- } else if( libspectrum_snap_out_scld_dec( snap ) & 0x02 ) {
- memcpy( scr_data,
- libspectrum_snap_pages( snap, page ),
- MONO_BITMAP_SIZE );
- memcpy( scr_data + MONO_BITMAP_SIZE,
- libspectrum_snap_pages( snap, page ) + ALTDFILE_OFFSET,
- MONO_BITMAP_SIZE );
- scr_length = HICOLOUR_SCR_SIZE;
- } else { /* ALTDFILE and default */
- int offset = ( libspectrum_snap_out_scld_dec( snap ) & 0x01 ) ? ALTDFILE_OFFSET : 0x0000;
- scr_length = STANDARD_SCR_SIZE;
- memcpy( scr_data,
- libspectrum_snap_pages( snap, page ) + offset,
- scr_length );
- }
+ if( libspectrum_snap_out_scld_dec( snap ) & 0x04 ) {
+ memcpy( scr_data,
+ libspectrum_snap_pages( snap, page ),
+ MONO_BITMAP_SIZE );
+ memcpy( scr_data + MONO_BITMAP_SIZE,
+ libspectrum_snap_pages( snap, page ) + ALTDFILE_OFFSET,
+ MONO_BITMAP_SIZE );
+ scr_data[HIRES_ATTR] = ( libspectrum_snap_out_scld_dec( snap ) & HIRESCOLMASK ) | 0x07;
+ scr_length = HIRES_SCR_SIZE;
+ } else if( libspectrum_snap_out_scld_dec( snap ) & 0x02 ) {
+ memcpy( scr_data,
+ libspectrum_snap_pages( snap, page ),
+ MONO_BITMAP_SIZE );
+ memcpy( scr_data + MONO_BITMAP_SIZE,
+ libspectrum_snap_pages( snap, page ) + ALTDFILE_OFFSET,
+ MONO_BITMAP_SIZE );
+ scr_length = HICOLOUR_SCR_SIZE;
+ } else { /* ALTDFILE and default */
+ int offset = ( libspectrum_snap_out_scld_dec( snap ) & 0x01 ) ? ALTDFILE_OFFSET : 0x0000;
+ scr_length = STANDARD_SCR_SIZE;
+ memcpy( scr_data,
+ libspectrum_snap_pages( snap, page ) + offset,
+ scr_length );
+ }
- scrData = [NSData dataWithBytes:(const void *)scr_data length:scr_length];
+ scrData = [NSData dataWithBytes:(const void *)scr_data length:scr_length];
+ image_type = TYPE_SCR;
}
- (void) process_snap_timex:(libspectrum_snap *)snap
{
- // Timex screens are always in page 5
- [self process_snap_timex:snap inPage:5];
+ // Timex screens are always in page 5
+ [self process_snap_timex:snap inPage:5];
}
- (void) process_snap_se:(libspectrum_snap *)snap
{
- // SE uses the 128k port to decide which page, and then applies the Timex rule
- int screen = ( libspectrum_snap_out_128_memoryport( snap ) & 0x08 ) ? 7 : 5;
- [self process_snap_timex:snap inPage:screen];
+ // SE uses the 128k port to decide which page, and then applies the Timex rule
+ int screen = ( libspectrum_snap_out_128_memoryport( snap ) & 0x08 ) ? 7 : 5;
+ [self process_snap_timex:snap inPage:screen];
}
@end
Modified: trunk/fuse/TODO
===================================================================
--- trunk/fuse/TODO 2008-04-29 13:50:38 UTC (rev 524)
+++ trunk/fuse/TODO 2008-05-04 09:11:05 UTC (rev 525)
@@ -2,10 +2,10 @@
* Pentagon port #ff returning floating bus issues - it does it because the RusFAQ says so?
* Timex 2068 fusetests
-* Add TITLE tags to help files
* Console mode GUI
* C version of standard tape loader
* Add "proper" preferences window
+* Add TITLE tags to help files?
* SZX ZX Printer block?
* PAL Compsite emulation
* Seperate out sound buffer interleaving code to allow for the use of hardware etc.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|