diff options
| -rw-r--r-- | gameDetector.cpp | 3 | ||||
| -rw-r--r-- | morphos/morphos.cpp | 58 | ||||
| -rw-r--r-- | morphos/morphos.h | 5 | ||||
| -rw-r--r-- | morphos/morphos_sound.cpp | 160 | ||||
| -rw-r--r-- | morphos/morphos_start.cpp | 47 | ||||
| -rw-r--r-- | sound/imuse.cpp | 48 | ||||
| -rw-r--r-- | sound/mididrv.cpp | 86 | ||||
| -rw-r--r-- | stdafx.h | 7 | 
8 files changed, 269 insertions, 145 deletions
| diff --git a/gameDetector.cpp b/gameDetector.cpp index 5fe230e1e6..7fdb3d64f9 100644 --- a/gameDetector.cpp +++ b/gameDetector.cpp @@ -446,6 +446,9 @@ MidiDriver *GameDetector::createMidi() {  #ifdef WIN32  	case MD_WINDOWS:	return MidiDriver_WIN_create();  #endif +#ifdef __MORPHOS__ +	case MD_AMIDI:		return MidiDriver_AMIDI_create(); +#endif  	}  	error("Invalid midi driver selected"); diff --git a/morphos/morphos.cpp b/morphos/morphos.cpp index 8c2ffe5f57..487ecbd45f 100644 --- a/morphos/morphos.cpp +++ b/morphos/morphos.cpp @@ -220,15 +220,16 @@ void OSystem_MorphOS::delay_msecs(uint msecs)  void *OSystem_MorphOS::create_thread(ThreadProc *proc, void *param)  { -/*	  MyEmulFunc.Trap      = TRAP_FUNC; -	MyEmulFunc.Address	= (ULONG)proc; -	MyEmulFunc.StackSize	= 8192; -	MyEmulFunc.Extension	= 0; -	MyEmulFunc.Arg1	   = (ULONG)param; -	MyEmulFunc.Arg2	   = (ULONG)ScummMidiUnit; -	MyEmulFunc.Arg3	   = (ULONG)args[ USG_NOMUSIC ]; -	ScummMusicThread = CreateNewProc( musicProcTags );*/ -	return NULL; +	static EmulFunc ThreadEmulFunc; + +	ThreadEmulFunc.Trap      = TRAP_FUNC; +	ThreadEmulFunc.Address	 = (ULONG)proc; +	ThreadEmulFunc.StackSize = 16000; +	ThreadEmulFunc.Extension = 0; +	ThreadEmulFunc.Arg1	    = (ULONG)param; +	musicProcTags[ 0 ].ti_Data = (ULONG)&ThreadEmulFunc; +	ScummMusicThread = CreateNewProc( musicProcTags ); +	return ScummMusicThread;  }  uint32 OSystem_MorphOS::property(int param, uint32 value) @@ -246,32 +247,35 @@ uint32 OSystem_MorphOS::property(int param, uint32 value)  			return 1;  		case PROP_OPEN_CD: -			FindCDTags[ 0 ].ti_Data = (ULONG)((GameID == GID_LOOM256) ? "LoomCD" : "Monkey1CD"); -			if( !CDDABase ) CDDABase = OpenLibrary( "cdda.library", 0 ); -			if( CDDABase ) +			if( value )  			{ -				CDrive = CDDA_FindNextDrive( NULL, FindCDTags ); -				if( CDrive ) +				FindCDTags[ 0 ].ti_Data = (ULONG)((GameID == GID_LOOM256) ? "LoomCD" : "Monkey1CD"); +				if( !CDDABase ) CDDABase = OpenLibrary( "cdda.library", 0 ); +				if( CDDABase )  				{ -					if( !CDDA_ObtainDrive( CDrive, CDDA_SHARED_ACCESS, NULL ) ) -					{ -						CDrive = NULL; -						warning( "Failed to obtain CD drive - music will not play" ); -					} -					else if( GameID == GID_LOOM256 ) +					CDrive = CDDA_FindNextDrive( NULL, FindCDTags ); +					if( CDrive )  					{ -						// Offset correction *may* be required -						struct CDS_TrackInfo ti; +						if( !CDDA_ObtainDrive( CDrive, CDDA_SHARED_ACCESS, NULL ) ) +						{ +							CDrive = NULL; +							warning( "Failed to obtain CD drive - music will not play" ); +						} +						else if( GameID == GID_LOOM256 ) +						{ +							// Offset correction *may* be required +							struct CDS_TrackInfo ti; -						if( CDDA_GetTrackInfo( CDrive, 1, 0, &ti ) ) -							CDDATrackOffset = ti.ti_TrackStart.tm_Format.tm_Frame-22650; +							if( CDDA_GetTrackInfo( CDrive, 1, 0, &ti ) ) +								CDDATrackOffset = ti.ti_TrackStart.tm_Format.tm_Frame-22650; +						}  					} +					else +						warning( "Could not find game CD inserted in CD-ROM drive - cd audio will not play" );  				}  				else -					warning( "Could not find game CD inserted in CD-ROM drive - cd audio will not play" ); +					warning( "Failed to open cdda.library - cd audio will not play" );  			} -			else -				warning( "Failed to open cdda.library - cd audio will not play" );  			break;  		case PROP_SHOW_DEFAULT_CURSOR: diff --git a/morphos/morphos.h b/morphos/morphos.h index b6259dd326..93dad021fa 100644 --- a/morphos/morphos.h +++ b/morphos/morphos.h @@ -188,6 +188,8 @@ class OSystem_MorphOS : public OSystem  };  int morphos_sound_thread( OSystem_MorphOS *syst, ULONG SampleType ); +bool init_morphos_music( ULONG MidiUnit ); +void exit_morphos_music();  int morphos_main( int argc, char *argv[] ); @@ -195,3 +197,6 @@ extern OSystem_MorphOS *TheSystem;  extern struct SignalSemaphore ScummMusicThreadRunning;  extern struct SignalSemaphore ScummSoundThreadRunning; +extern struct IOMidiRequest *ScummMidiRequest; +extern struct timerequest   *MusicTimerIORequest; + diff --git a/morphos/morphos_sound.cpp b/morphos/morphos_sound.cpp index 43de32f244..c20631ef8f 100644 --- a/morphos/morphos_sound.cpp +++ b/morphos/morphos_sound.cpp @@ -25,6 +25,8 @@  #include "stdafx.h"  #include "scumm.h" +#include "mididrv.h" +#include "imuse.h"  #include <dos/dos.h>  #include <exec/memory.h> @@ -53,40 +55,66 @@ static char					  *ahiBuf[ 2 ]		 = { NULL, NULL };  static struct MsgPort 		 *ScummMidiPort = NULL;  		 struct IOMidiRequest *ScummMidiRequest = NULL; +static struct MsgPort       *MusicTimerMsgPort = NULL; +		 struct timerequest   *MusicTimerIORequest = NULL; -bool init_morphos_music( ULONG MidiUnit, bool NoMusic ) +bool init_morphos_music( ULONG MidiUnit )  { -	if( !NoMusic ) +	ScummMidiPort = CreateMsgPort(); +	if( ScummMidiPort )  	{ -		ScummMidiPort = CreateMsgPort(); -		if( ScummMidiPort ) +		ScummMidiRequest = (struct IOMidiRequest *)CreateIORequest( ScummMidiPort, sizeof( struct IOMidiRequest ) ); +		if( ScummMidiRequest )  		{ -			ScummMidiRequest = (struct IOMidiRequest *)CreateIORequest( ScummMidiPort, sizeof( struct IOMidiRequest ) ); -			if( ScummMidiRequest ) -			{ -				ScummMidiRequest->amr_Version = 2; -				if( OpenDevice( "amidi.device", MidiUnit, (struct IORequest *)ScummMidiRequest, AMIDIF_MIDISERVER ) ) -				{ -					DeleteIORequest( (struct IORequest *)ScummMidiRequest ); -					DeleteMsgPort( ScummMidiPort ); -					ScummMidiRequest = NULL; -					ScummMidiPort = NULL; -				} -			} -			else +			ScummMidiRequest->amr_Version = 2; +			if( OpenDevice( "amidi.device", MidiUnit, (struct IORequest *)ScummMidiRequest, AMIDIF_MIDISERVER ) )  			{ +				DeleteIORequest( (struct IORequest *)ScummMidiRequest );  				DeleteMsgPort( ScummMidiPort ); +				ScummMidiRequest = NULL;  				ScummMidiPort = NULL;  			}  		} +		else +		{ +			DeleteMsgPort( ScummMidiPort ); +			ScummMidiPort = NULL; +		} +	} -		if( !ScummMidiRequest ) +	if( !ScummMidiRequest ) +	{ +		warning( "Could not open AMidi - music will not play" ); +		return false; +	} + +	MusicTimerMsgPort = CreateMsgPort(); +	if( MusicTimerMsgPort ) +	{ +		MusicTimerIORequest = (struct timerequest *)CreateIORequest( MusicTimerMsgPort, sizeof( struct timerequest ) ); +		if( MusicTimerIORequest ) +		{ +			if( OpenDevice( "timer.device", UNIT_MICROHZ, (struct IORequest *)MusicTimerIORequest, 0 ) ) +			{ +				DeleteIORequest( (struct IORequest *)MusicTimerIORequest ); +				DeleteMsgPort( MusicTimerMsgPort ); +				MusicTimerIORequest = NULL; +				MusicTimerMsgPort = NULL; +			} +		} +		else  		{ -			warning( "Could not open AMidi - music will not play" ); -			return false; +			DeleteMsgPort( MusicTimerMsgPort ); +			MusicTimerMsgPort = NULL;  		}  	} +	if( !MusicTimerIORequest ) +	{ +		warning( "Could not open timer device - music will not play" ); +		return false; +	} +  	return true;  } @@ -99,6 +127,13 @@ void exit_morphos_music()  		DeleteIORequest( (struct IORequest *)ScummMidiRequest );  		DeleteMsgPort( ScummMidiPort );  	} + +	if( MusicTimerIORequest ) +	{ +		CloseDevice( (struct IORequest *)MusicTimerIORequest ); +		DeleteIORequest( (struct IORequest *)MusicTimerIORequest ); +		DeleteMsgPort( MusicTimerMsgPort ); +	}  } @@ -177,91 +212,6 @@ static void exit_morphos_sound()  		DeleteMsgPort( ahiPort );  } - -int morphos_music_thread( Scumm *s, ULONG MidiUnit, bool NoMusic ) -{ -#if 0 -	int  old_time, cur_time; -	bool initialized; -   bool TimerAvailable = false; -	struct MsgPort     *TimerMsgPort; -	struct timerequest *TimerIORequest; - -	ObtainSemaphore( &ScummMusicThreadRunning ); - -	initialized = init_morphos_music( MidiUnit, NoMusic ); -	if( !initialized ) -		warning( "Sound could not be initialized" ); - -	TimerMsgPort = CreateMsgPort(); -	if( TimerMsgPort ) -	{ -		TimerIORequest = (struct timerequest *)CreateIORequest( TimerMsgPort, sizeof( struct timerequest ) ); -		if( TimerIORequest ) -		{ -			if( OpenDevice( "timer.device", UNIT_MICROHZ, (struct IORequest *)TimerIORequest, 0 ) == 0 ) -				TimerAvailable = true; -			else -			{ -				DeleteIORequest( (struct IORequest *)TimerIORequest ); -				DeleteMsgPort( TimerMsgPort ); -			} -		} -		else -			DeleteMsgPort( TimerMsgPort ); -	} - -	if( !TimerAvailable ) -	{ -		warning( "ScummVM Music Thread: no timer available! Sound and music will be disabled" ); -		Wait( SIGBREAKF_CTRL_F ); -	} -	else -	{ -		old_time = 0;//GetTicks(); - -		for(;;) -		{ -			if( CheckSignal( SIGBREAKF_CTRL_F ) ) -				break; - -/*			  if( !snd_driv.wave_based() ) -			{ -				cur_time = GetTicks(); -				while( old_time < cur_time ) -				{ -					old_time += 10; -					sound.on_timer(); -				}*/ -/*				  TimerIORequest->tr_time.tv_micro = (old_time-cur_time)*1000; -				if( TimerIORequest->tr_time.tv_micro == 0 ) -					TimerIORequest->tr_time.tv_micro = 100;*/ -/*				  TimerIORequest->tr_time.tv_micro = 10000; -			} -			else -				TimerIORequest->tr_time.tv_micro = 10000;*/ - -			TimerIORequest->tr_node.io_Command  = TR_ADDREQUEST; -			TimerIORequest->tr_time.tv_secs  = 0; -			DoIO( (struct IORequest *)TimerIORequest ); -		} -	} - -	if( TimerAvailable ) -	{ -		CloseDevice( (struct IORequest *)TimerIORequest ); -		DeleteIORequest( (struct IORequest *)TimerIORequest ); -		DeleteMsgPort( TimerMsgPort ); -	} - -	exit_morphos_music(); - -	ReleaseSemaphore( &ScummMusicThreadRunning ); -	return 0; -#endif -} - -  int morphos_sound_thread( OSystem_MorphOS *syst, ULONG SampleType )  {  	ULONG signals; diff --git a/morphos/morphos_start.cpp b/morphos/morphos_start.cpp index 2e4438611c..67d49c52be 100644 --- a/morphos/morphos_start.cpp +++ b/morphos/morphos_start.cpp @@ -40,13 +40,14 @@  extern "C" struct WBStartup *_WBenchMsg;  // For command line parsing -static STRPTR usageTemplate = "STORY/A,DATAPATH/K,WBWINDOW/S,SCALER/K,MIDIUNIT/K/N,NOMUSIC/S,VOLUME/K/N,TEMPO/K/N,ROLANDEMU/S,NOSUBTITLES=NST/S"; -typedef enum 					{ USG_STORY = 0,	USG_DATAPATH, 	USG_WBWINDOW,	USG_SCALER, 	USG_MIDIUNIT,	USG_NOMUSIC,	USG_VOLUME,		USG_TEMPO,	 USG_ROLANDEMU, USG_NOSUBTITLES } usageFields; -static LONG	  args[ 10 ] =  { (ULONG)NULL, 	 (ULONG)NULL,	 FALSE, 			 (ULONG)NULL,	 (ULONG)NULL, 	 false,			 (ULONG)NULL,	 (ULONG)NULL, false, false }; +static STRPTR usageTemplate = "STORY/A,DATAPATH/K,WBWINDOW/S,SCALER/K,AMIGA/S,MIDIUNIT/K/N,MUSIC/K,VOLUME/K/N,TEMPO/K/N,ROLANDEMU/S,NOSUBTITLES=NST/S"; +typedef enum 					{ USG_STORY = 0,	USG_DATAPATH, 	USG_WBWINDOW,	USG_SCALER, 	USG_AMIGA,	USG_MIDIUNIT,	USG_MUSIC,	 USG_VOLUME,	 USG_TEMPO,	  USG_ROLANDEMU, USG_NOSUBTITLES } usageFields; +static LONG	  args[ 11 ] =  { (ULONG)NULL, 	 (ULONG)NULL,	 FALSE, 			 (ULONG)NULL,	false,      (ULONG)NULL,   (ULONG)NULL, (ULONG)NULL,	 (ULONG)NULL, false, false };  static struct RDArgs *ScummArgs = NULL;  static char*ScummStory = NULL;  static char*ScummPath = NULL; +static STRPTR ScummMusicDriver = NULL;  static LONG ScummMidiUnit = 0;  static LONG ScummMidiVolume = 0;  static LONG ScummMidiTempo = 0; @@ -108,7 +109,17 @@ void close_resources()  		CloseLibrary( CyberGfxBase );  } -void ReadToolTypes( struct WBArg *OfFile ) +static STRPTR FindMusicDriver( STRPTR argval ) +{ +	if( !stricmp( argval, "off" ) )   return "-enull"; +	if( !stricmp( argval, "midi" ) )	 return "-eamidi"; +	if( !stricmp( argval, "adlib" ) ) return "-eadlib"; + +	error( "No such music driver supported. Possible values are off, Midi and Adlib." ); +	return NULL; +} + +static void ReadToolTypes( struct WBArg *OfFile )  {  	struct DiskObject *dobj;  	char 	*ToolValue; @@ -157,10 +168,12 @@ void ReadToolTypes( struct WBArg *OfFile )  	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "MUSIC" ) )  	{ -		if( MatchToolValue( ToolValue, "YES" ) ) -			args[ USG_NOMUSIC ] = FALSE; -		else if( MatchToolValue( ToolValue, "NO" ) ) -			args[ USG_NOMUSIC ] = TRUE; +		if( !(ScummMusicDriver = FindMusicDriver( ToolValue )) ) +		{ +			FreeDiskObject( dobj ); +			exit( 1 ); +		} +		args[ USG_MUSIC ] = (ULONG)&ScummMusicDriver;  	}  	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "MIDIUNIT" ) ) @@ -198,6 +211,14 @@ void ReadToolTypes( struct WBArg *OfFile )  			args[ USG_NOSUBTITLES ] = TRUE;  	} +	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "AMIGA" ) ) +	{ +		if( MatchToolValue( ToolValue, "YES" ) ) +			args[ USG_AMIGA ] = FALSE; +		else if( MatchToolValue( ToolValue, "NO" ) ) +			args[ USG_AMIGA ] = TRUE; +	} +  	FreeDiskObject( dobj );  } @@ -207,7 +228,7 @@ int main()  {  	int delta;  	int last_time, new_time; -	char *argv[ 10 ]; +	char *argv[ 15 ];  	char volume[ 6 ], tempo[ 12 ], scaler[ 14 ];  	char *SVMScalers[] = { "", "normal", "2x", "supereagle", "super2xsai" };  	int argc = 0; @@ -253,6 +274,12 @@ int main()  				exit( 1 );  		} +		if( args[ USG_MUSIC ] ) +		{ +			if( !(ScummMusicDriver = FindMusicDriver( (char *)args[ USG_MUSIC ] )) ) +				exit( 1 ); +		} +  		if( args[ USG_MIDIUNIT ] )  			ScummMidiUnit = *((LONG *)args[ USG_MIDIUNIT ]); @@ -286,6 +313,8 @@ int main()  	if( !args[ USG_WBWINDOW ]   ) argv[ argc++ ] = "-f";  	if( args[ USG_NOSUBTITLES ] ) argv[ argc++ ] = "-n";  	if( args[ USG_ROLANDEMU ] 	 ) argv[ argc++ ] = "-r"; +	if( args[ USG_AMIGA ]		 ) argv[ argc++ ] = "-a"; +	if( args[ USG_MUSIC ]	    ) argv[ argc++ ] = ScummMusicDriver;  	if( ScummGfxScaler != OSystem_MorphOS::ST_INVALID )  	{  		sprintf( scaler, "-g%s", SVMScalers[ (int)ScummGfxScaler ] ); diff --git a/sound/imuse.cpp b/sound/imuse.cpp index 4a1099b429..be566d4122 100644 --- a/sound/imuse.cpp +++ b/sound/imuse.cpp @@ -4219,6 +4219,7 @@ void IMuseGM::part_key_off(Part *part, byte note)  	}  } +#if !defined(__MORPHOS__)  int IMuseGM::midi_driver_thread(void *param) {  	IMuseGM *mid = (IMuseGM*) param;  	int old_time, cur_time; @@ -4235,6 +4236,53 @@ int IMuseGM::midi_driver_thread(void *param) {  		}  	}  } +#else +#include <exec/semaphores.h> +#include <proto/exec.h> +#include <proto/dos.h> +#include "../morphos/morphos.h" +int IMuseGM::midi_driver_thread( void *param ) +{ +	IMuseGM *mid = (IMuseGM*) param; +	int old_time, cur_time; +	bool initialized; + +	ObtainSemaphore( &ScummMusicThreadRunning ); + +	initialized = init_morphos_music( 0 ); + +	old_time = mid->_system->get_msecs(); + +	if( !initialized ) +		Wait( SIGBREAKF_CTRL_C ); +	else +	{ +		for(;;) +		{ +			MusicTimerIORequest->tr_time.tv_micro = 10000; +			MusicTimerIORequest->tr_node.io_Command  = TR_ADDREQUEST; +			MusicTimerIORequest->tr_time.tv_secs  = 0; +			DoIO( (struct IORequest *)MusicTimerIORequest ); + +			if( CheckSignal( SIGBREAKF_CTRL_C ) ) +				break; + +			cur_time = mid->_system->get_msecs(); +			while (old_time < cur_time) +			{ +				old_time += 10; +				mid->_se->on_timer(); +			} +		} +	} + +	exit_morphos_music(); + +	ReleaseSemaphore( &ScummMusicThreadRunning ); +	RemTask( NULL ); +	return 0; +} +#endif  void IMuseGM::init(IMuse *eng, OSystem *syst)  { diff --git a/sound/mididrv.cpp b/sound/mididrv.cpp index 39ab656775..405242f50c 100644 --- a/sound/mididrv.cpp +++ b/sound/mididrv.cpp @@ -26,10 +26,6 @@   * MorphOS support by Ruediger Hanke    */ -#ifdef __MORPHOS__ -#include <devices/timer.h> -#endif -  #include "stdafx.h"  #include "scumm.h"  #include "mididrv.h" @@ -269,6 +265,88 @@ MidiDriver *MidiDriver_WIN_create() {  #endif // WIN32 +#ifdef __MORPHOS__ +#include <exec/types.h> +#include <devices/amidi.h> + +#include <clib/alib_protos.h> +#include <proto/exec.h> + +extern struct IOMidiRequest *ScummMidiRequest; + +/* MorphOS MIDI driver */ +class MidiDriver_AMIDI : public MidiDriver { +public: +	void destroy(); +	int open(int mode); +	void close(); +	void send(uint32 b); +	void pause(bool pause); +	void set_stream_callback(void *param, StreamCallback *sc); + +private: +	StreamCallback *_stream_proc; +	void  *_stream_param; +	int 	 _mode; +	uint16 _time_div; + +	uint32 property(int prop, uint32 param); +}; + +void MidiDriver_AMIDI::set_stream_callback(void *param, StreamCallback *sc) { +	_stream_param = param; +	_stream_proc = sc; +} + +void MidiDriver_AMIDI::destroy() { +	close(); +	delete this; +} + +int MidiDriver_AMIDI::open(int mode) { +	_mode = mode; +	return 0; +} + +void MidiDriver_AMIDI::close() { +	_mode = 0; +} + +void MidiDriver_AMIDI::send(uint32 b) { +	if (_mode != MO_SIMPLE) +		error("MidiDriver_AMIDI:send called but driver is not in simple mode"); + +	if (ScummMidiRequest) { +		ULONG midi_data = b;				// you never know about an int's size ;-) +		ScummMidiRequest->amr_Std.io_Command = CMD_WRITE; +		ScummMidiRequest->amr_Std.io_Data = &midi_data; +		ScummMidiRequest->amr_Std.io_Length = 4; +		DoIO((struct IORequest *)ScummMidiRequest); +	} +} + +void MidiDriver_AMIDI::pause(bool pause) { +	if (_mode == MO_STREAMING) { +	} +} + +uint32 MidiDriver_AMIDI::property(int prop, uint32 param) { +	switch(prop) { +	/* 16-bit time division according to standard midi specification */ +	case PROP_TIMEDIV: +		_time_div = (uint16)param; +		return 1; +	} + +	return 0; +} + +MidiDriver *MidiDriver_AMIDI_create() { +	return new MidiDriver_AMIDI(); +} + +#endif // __MORPHOS__ +  /* NULL driver */  class MidiDriver_NULL : public MidiDriver { @@ -2,6 +2,9 @@   * $Id$   *   * $Log$ + * Revision 1.14  2002/04/18 21:40:23  tomjoad + * Reenable MorphOS Midi driver, small updates to CD open code (only when CD audio is requested) and start options + *   * Revision 1.13  2002/04/12 21:26:34  strigeus   * new video engine (expect broken non-sdl builds),   * simon the sorcerer 1 & 2 support (non SCUMM games) @@ -92,6 +95,10 @@  #else +#if defined(__MORPHOS__) +#include <devices/timer.h> +#undef CMD_INVALID +#endif  #if !defined(__APPLE__CW) && !(defined(__MWERKS__) && defined(macintosh))  #include <sys/types.h>  #include <sys/uio.h> | 
