revision 837:4eae2ddccf9c
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 837:4eae2ddccf9c |
parent | 836:d314bf370949 |
child | 838:9abb2fa58934 |
author | nkeynes |
date | Thu Aug 28 01:39:51 2008 +0000 (15 years ago) |
Extract the disc title (where available) and display in the title bar
1.1 --- a/src/cocoaui/cocoa_win.c Thu Aug 28 00:08:12 2008 +00001.2 +++ b/src/cocoaui/cocoa_win.c Thu Aug 28 01:39:51 2008 +00001.3 @@ -19,6 +19,7 @@1.4 #include "cocoaui/cocoaui.h"1.5 #include "lxdream.h"1.6 #include "dreamcast.h"1.7 +#include "gdrom/gdrom.h"1.8 #include <ApplicationServices/ApplicationServices.h>1.10 @interface NSWindow (OSX10_5_and_later)1.11 @@ -155,9 +156,7 @@1.12 [self setDelegate: [NSApp delegate]];1.13 [self setContentMinSize: contentRect.size];1.14 [self setAcceptsMouseMovedEvents: YES];1.15 -1.16 - NSString *title = [[NSString alloc] initWithCString: lxdream_package_name encoding: NSASCIIStringEncoding];1.17 - [self setTitle: title];1.18 + [self updateTitle];1.20 NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamToolbar"];1.21 [toolbar setDelegate: [[LxdreamToolbarDelegate alloc] init]];1.22 @@ -169,6 +168,18 @@1.23 }1.24 }1.26 +- (void)updateTitle1.27 +{1.28 + NSString *title;1.29 + const char *disc_title = gdrom_get_current_disc_title();1.30 + if( disc_title == NULL ) {1.31 + title = [NSString stringWithCString: lxdream_package_name];1.32 + } else {1.33 + title = [NSString stringWithFormat: @"%s - %s", lxdream_package_name, disc_title];1.34 + }1.35 + [self setTitle: title];1.36 +}1.37 +1.38 - (void)setStatusText: (const gchar *)text1.39 {1.40 if( isGrabbed ) {
2.1 --- a/src/cocoaui/cocoaui.c Thu Aug 28 00:08:12 2008 +00002.2 +++ b/src/cocoaui/cocoaui.c Thu Aug 28 01:39:51 2008 +00002.3 @@ -58,6 +58,14 @@2.4 - (void) setAppleMenu:(NSMenu *)aMenu;2.5 @end2.7 +gboolean cocoa_gui_disc_changed( gdrom_disc_t disc, const gchar *disc_name, void *user_data )2.8 +{2.9 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];2.10 + LxdreamMainWindow *window = (LxdreamMainWindow *)user_data;2.11 + [window updateTitle];2.12 + [pool release];2.13 +}2.14 +2.15 /**2.16 * Produces the menu title by looking the text up in gettext, removing any2.17 * underscores, and returning the result as an NSString.2.18 @@ -306,6 +314,8 @@2.19 [window makeKeyAndOrderFront: nil];2.20 [NSApp activateIgnoringOtherApps: YES];2.22 + register_gdrom_disc_change_hook( cocoa_gui_disc_changed, window );2.23 +2.24 [pool release];2.25 return TRUE;2.26 }
3.1 --- a/src/cocoaui/cocoaui.h Thu Aug 28 00:08:12 2008 +00003.2 +++ b/src/cocoaui/cocoaui.h Thu Aug 28 01:39:51 2008 +00003.3 @@ -64,6 +64,7 @@3.4 }3.5 - (id)initWithContentRect:(NSRect)contentRect;3.6 - (void)setStatusText:(const gchar *)text;3.7 +- (void)updateTitle;3.8 - (void)setRunning:(BOOL)isRunning;3.9 - (BOOL)isGrabbed;3.10 - (void)setIsGrabbed:(BOOL)grab;
4.1 --- a/src/gdrom/gddriver.h Thu Aug 28 00:08:12 2008 +00004.2 +++ b/src/gdrom/gddriver.h Thu Aug 28 01:39:51 2008 +00004.3 @@ -165,6 +165,7 @@4.4 */4.5 void (*close)( struct gdrom_disc *disc );4.6 const gchar *name; /* Device name / Image filename */4.7 + char title[129]; /* Disc title (if any) */4.8 };4.10 typedef struct gdrom_image {
5.1 --- a/src/gdrom/gdimage.c Thu Aug 28 00:08:12 2008 +00005.2 +++ b/src/gdrom/gdimage.c Thu Aug 28 01:39:51 2008 +00005.3 @@ -467,39 +467,6 @@5.4 }5.5 }5.7 -void gdrom_image_dump_info( gdrom_disc_t d ) {5.8 - gdrom_image_t disc = (gdrom_image_t)d;5.9 - int i;5.10 - int last_session = disc->track[disc->track_count-1].session;5.11 - gboolean is_bootable = FALSE;5.12 -5.13 - INFO( "Disc ID: %s, %d tracks in %d sessions", disc->mcn, disc->track_count,5.14 - disc->track[disc->track_count-1].session + 1 );5.15 - if( last_session > 0 ) {5.16 - /* Boot track is the first data track of the last session, provided that it5.17 - * cannot be a single-session disc.5.18 - */5.19 - int boot_track = -1;5.20 - for( i=disc->track_count-1; i>=0 && disc->track[i].session == last_session; i-- ) {5.21 - if( disc->track[i].flags & TRACK_DATA ) {5.22 - boot_track = i;5.23 - }5.24 - }5.25 - if( boot_track != -1 ) {5.26 - unsigned char boot_sector[MAX_SECTOR_SIZE];5.27 - uint32_t length = sizeof(boot_sector);5.28 - if( d->read_sector( d, disc->track[boot_track].lba, 0x28,5.29 - boot_sector, &length ) == PKT_ERR_OK ) {5.30 - bootstrap_dump(boot_sector, FALSE);5.31 - is_bootable = TRUE;5.32 - }5.33 - }5.34 - }5.35 - if( !is_bootable ) {5.36 - WARN( "Disc does not appear to be bootable" );5.37 - }5.38 -}5.39 -5.40 gdrom_device_t gdrom_device_new( const gchar *name, const gchar *dev_name )5.41 {5.42 struct gdrom_device *dev = g_malloc0( sizeof(struct gdrom_device) );5.43 @@ -520,3 +487,41 @@5.44 }5.45 g_free( dev );5.46 }5.47 +5.48 +/**5.49 + * Check the disc for a useable DC bootstrap, and update the disc5.50 + * with the title accordingly.5.51 + * @return TRUE if we found a bootstrap, otherwise FALSE.5.52 + */5.53 +gboolean gdrom_image_read_info( gdrom_disc_t d ) {5.54 + gdrom_image_t disc = (gdrom_image_t)d;5.55 + if( disc->track_count > 0 ) {5.56 + /* Find the first data track of the last session */5.57 + int last_session = disc->track[disc->track_count-1].session;5.58 + int i, boot_track = -1;5.59 + for( i=disc->track_count-1; i>=0 && disc->track[i].session == last_session; i-- ) {5.60 + if( disc->track[i].flags & TRACK_DATA ) {5.61 + boot_track = i;5.62 + }5.63 + }5.64 + if( boot_track != -1 ) {5.65 + unsigned char boot_sector[MAX_SECTOR_SIZE];5.66 + uint32_t length = sizeof(boot_sector);5.67 + if( d->read_sector( d, disc->track[boot_track].lba, 0x28,5.68 + boot_sector, &length ) == PKT_ERR_OK ) {5.69 + if( memcmp( boot_sector, "SEGA SEGAKATANA SEGA ENTERPRISES", 32) == 0 ) {5.70 + /* Got magic */5.71 + memcpy( d->title, boot_sector+128, 128 );5.72 + for( i=127; i>=0; i-- ) {5.73 + if( !isspace(d->title[i]) )5.74 + break;5.75 + }5.76 + d->title[i+1] = '\0';5.77 + }5.78 + bootstrap_dump(boot_sector, FALSE);5.79 + return TRUE;5.80 + }5.81 + }5.82 + }5.83 + return FALSE;5.84 +}
6.1 --- a/src/gdrom/gdrom.c Thu Aug 28 00:08:12 2008 +00006.2 +++ b/src/gdrom/gdrom.c Thu Aug 28 01:39:51 2008 +00006.3 @@ -125,7 +125,7 @@6.4 gdrom_disc->close(gdrom_disc);6.5 }6.6 gdrom_disc = disc;6.7 - gdrom_image_dump_info( disc );6.8 + gdrom_image_read_info( disc );6.9 gdrom_fire_disc_changed( disc );6.10 }6.11 }6.12 @@ -163,6 +163,15 @@6.13 }6.14 }6.16 +const gchar *gdrom_get_current_disc_title()6.17 +{6.18 + if( gdrom_disc == NULL || gdrom_disc->title[0] == '\0' ) {6.19 + return NULL;6.20 + } else {6.21 + return gdrom_disc->title;6.22 + }6.23 +}6.24 +6.25 gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *rel_name )6.26 {6.27 gchar *dirname = g_path_get_dirname(base_name);6.28 @@ -170,3 +179,4 @@6.29 g_free(dirname);6.30 return pathname;6.31 }6.32 +
7.1 --- a/src/gdrom/gdrom.h Thu Aug 28 00:08:12 2008 +00007.2 +++ b/src/gdrom/gdrom.h Thu Aug 28 01:39:51 2008 +00007.3 @@ -52,9 +52,9 @@7.4 gdrom_disc_t gdrom_image_open( const gchar *filename );7.6 /**7.7 - * Dump image info7.8 + * Read image bootstrap info7.9 */7.10 -void gdrom_image_dump_info( gdrom_disc_t d );7.11 +gboolean gdrom_image_read_info( gdrom_disc_t d );7.14 /**7.15 @@ -73,6 +73,8 @@7.17 const gchar *gdrom_get_current_disc_name();7.19 +const gchar *gdrom_get_current_disc_title();7.20 +7.21 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,7.22 int mode, unsigned char *buf, uint32_t *length );
8.1 --- a/src/gtkui/gtk_win.c Thu Aug 28 00:08:12 2008 +00008.2 +++ b/src/gtkui/gtk_win.c Thu Aug 28 01:39:51 2008 +00008.3 @@ -379,3 +379,16 @@8.4 win->use_grab = use_grab;8.5 }8.6 }8.7 +8.8 +void main_window_update_title( main_window_t win )8.9 +{8.10 + const char *disc = gdrom_get_current_disc_title();8.11 +8.12 + if( disc == NULL ) {8.13 + gtk_window_set_title( GTK_WINDOW(win->window), lxdream_package_name );8.14 + } else {8.15 + char buf[256];8.16 + snprintf( buf, sizeof(buf), "%s - %s", lxdream_package_name, disc );8.17 + gtk_window_set_title( GTK_WINDOW(win->window), buf );8.18 + }8.19 +}8.20 \ No newline at end of file
9.1 --- a/src/gtkui/gtkui.c Thu Aug 28 00:08:12 2008 +00009.2 +++ b/src/gtkui/gtkui.c Thu Aug 28 01:39:51 2008 +00009.3 @@ -195,6 +195,11 @@9.4 return gtk_gui_init_ok;9.5 }9.7 +gboolean gtk_gui_disc_changed( gdrom_disc_t disc, const gchar *disc_name, void *ptr )9.8 +{9.9 + main_window_update_title( main_win );9.10 +}9.11 +9.12 gboolean gui_init( gboolean withDebug )9.13 {9.14 if( gtk_gui_init_ok ) {9.15 @@ -231,6 +236,7 @@9.16 if( withDebug ) {9.17 gtk_gui_show_debugger();9.18 }9.19 + register_gdrom_disc_change_hook( gtk_gui_disc_changed, NULL );9.21 return TRUE;9.22 } else {
10.1 --- a/src/gtkui/gtkui.h Thu Aug 28 00:08:12 2008 +000010.2 +++ b/src/gtkui/gtkui.h Thu Aug 28 01:39:51 2008 +000010.3 @@ -49,6 +49,7 @@10.4 void main_window_set_speed( main_window_t win, double speed );10.5 void main_window_set_fullscreen( main_window_t win, gboolean fullscreen );10.6 void main_window_set_use_grab( main_window_t win, gboolean grab );10.7 +void main_window_update_title( main_window_t win );10.9 debug_window_t debug_window_new( const gchar *title, GtkWidget *menubar,10.10 GtkWidget *toolbar, GtkAccelGroup *accel );
.