diff options
| author | Ruediger Hanke | 2003-08-23 18:01:21 +0000 | 
|---|---|---|
| committer | Ruediger Hanke | 2003-08-23 18:01:21 +0000 | 
| commit | fda9c872188128862936da88f2a1ec41af5d5dd9 (patch) | |
| tree | a1a791d8cdb355778e341617fac7cc6f8c3411c4 | |
| parent | 6768da3e7689224e5b8fb0c0961b6f0829dd17c9 (diff) | |
| download | scummvm-rg350-fda9c872188128862936da88f2a1ec41af5d5dd9.tar.gz scummvm-rg350-fda9c872188128862936da88f2a1ec41af5d5dd9.tar.bz2 scummvm-rg350-fda9c872188128862936da88f2a1ec41af5d5dd9.zip  | |
little bugfix, safer code
svn-id: r9832
| -rw-r--r-- | backends/morphos/morphos.cpp | 127 | ||||
| -rw-r--r-- | backends/morphos/morphos.h | 5 | ||||
| -rw-r--r-- | backends/morphos/morphos_sound.cpp | 4 | ||||
| -rw-r--r-- | backends/morphos/morphos_sound.h | 3 | ||||
| -rw-r--r-- | backends/morphos/morphos_start.cpp | 11 | ||||
| -rw-r--r-- | backends/morphos/morphos_timer.cpp | 36 | ||||
| -rw-r--r-- | backends/morphos/morphos_timer.h | 3 | 
7 files changed, 123 insertions, 66 deletions
diff --git a/backends/morphos/morphos.cpp b/backends/morphos/morphos.cpp index d90205c750..d565a57d6c 100644 --- a/backends/morphos/morphos.cpp +++ b/backends/morphos/morphos.cpp @@ -79,6 +79,12 @@ OSystem_MorphOS *OSystem_MorphOS::create(SCALERTYPE gfx_scaler, bool full_screen  {  	OSystem_MorphOS *syst = new OSystem_MorphOS(gfx_scaler, full_screen); +	if (!syst || !syst->Initialise()) +	{ +		delete syst; +		error("Failed to create system object. Exiting."); +	} +  	return syst;  } @@ -117,7 +123,18 @@ OSystem_MorphOS::OSystem_MorphOS(SCALERTYPE gfx_mode, bool full_screen)  	TimerIORequest = NULL;  	InputMsgPort = NULL;  	InputIORequest = NULL; +	ThreadPort = NULL; +	OvlCMap = NULL; +	OvlBitMap = NULL; +	OvlSavedBuffer = NULL; +	TimerBase = NULL; +	ScummNoCursor = NULL; +	UpdateRegion = NULL; +	NewUpdateRegion = NULL; +} +bool OSystem_MorphOS::Initialise() +{  	OpenATimer(&TimerMsgPort, (IORequest **) &TimerIORequest, UNIT_MICROHZ);  	if ((InputMsgPort = CreateMsgPort())) @@ -140,11 +157,19 @@ OSystem_MorphOS::OSystem_MorphOS(SCALERTYPE gfx_mode, bool full_screen)  	}  	if (!InputIORequest) +	{  		warning("input.device could not be opened"); +		return false; +	} + +	ThreadPort = CreateMsgPort(); +	if (!ThreadPort) +	{ +		warning("Unable to create a message port"); +		return false; +	}  	OvlCMap = GetColorMap(256); -	OvlBitMap = NULL; -	OvlSavedBuffer = NULL;  	InitSemaphore(&CritSec); @@ -153,11 +178,22 @@ OSystem_MorphOS::OSystem_MorphOS(SCALERTYPE gfx_mode, bool full_screen)  	UpdateRegion = NewRegion();  	NewUpdateRegion = NewRegion();  	if (!UpdateRegion || !NewUpdateRegion) -		error("Could not create region for screen update"); +	{ +		warning("Could not create region for screen update"); +		return false; +	}  	if (!OvlCMap) -		error("Could not allocate overlay color map"); +	{ +		warning("Could not allocate overlay color map"); +		return false; +	}  	if (!ScummNoCursor) -		error("Could not allocate empty cursor image"); +	{ +		warning("Could not allocate empty cursor image"); +		return false; +	} + +	return true;  }  OSystem_MorphOS::~OSystem_MorphOS() @@ -172,13 +208,9 @@ OSystem_MorphOS::~OSystem_MorphOS()  	}  	if (OvlCMap) -	{  		FreeColorMap(OvlCMap); -		OvlCMap = NULL; -	} -	if (Scaler) -		delete Scaler; +	delete Scaler;  	if (UpdateRegion)  		DisposeRegion(UpdateRegion); @@ -186,6 +218,9 @@ OSystem_MorphOS::~OSystem_MorphOS()  	if (NewUpdateRegion)  		DisposeRegion(NewUpdateRegion); +	if (ThreadPort) +		DeleteMsgPort(ThreadPort); +  	if (CDrive && CDDABase)  	{  		CDDA_Stop(CDrive); @@ -210,23 +245,6 @@ OSystem_MorphOS::~OSystem_MorphOS()  	if (TimerMsgPort)  		DeleteMsgPort(TimerMsgPort); -	if (ScummMusicThread) -	{ -		if (!AttemptSemaphore(&ScummMusicThreadRunning)) -		{ -			Signal((Task *) ScummMusicThread, SIGBREAKF_CTRL_C); -			ObtainSemaphore(&ScummMusicThreadRunning);    /* Wait for thread to finish */ -		} -		ReleaseSemaphore(&ScummMusicThreadRunning); -	} - -	if (ScummSoundThread) -	{ -		Signal((Task *) ScummSoundThread, SIGBREAKF_CTRL_C); -		ObtainSemaphore(&ScummSoundThreadRunning);	 /* Wait for thread to finish */ -		ReleaseSemaphore(&ScummSoundThreadRunning); -	} -  	if (ScummNoCursor)  		FreeVec(ScummNoCursor); @@ -312,9 +330,14 @@ void OSystem_MorphOS::set_timer(int timer, int (*callback)(int))  void OSystem_MorphOS::create_thread(ThreadProc *proc, void *param)  { +	MusicStartup.mn_Node.ln_Type = NT_MESSAGE; +	MusicStartup.mn_ReplyPort = ThreadPort; +	MusicStartup.mn_Length = sizeof(MusicStartup); +  	ScummMusicThread = CreateNewProcTags(NP_Entry, (ULONG) proc, NP_CodeType, CODETYPE_PPC,  													 NP_Name, (ULONG) "ScummVM Music Thread", -													 NP_Priority, 60, NP_StackSize, 32000, +													 NP_Priority, 40, NP_StackSize, 32000, +													 NP_StartupMsg, &MusicStartup,  													 NP_PPC_Arg1, (ULONG) param, TAG_DONE);  } @@ -349,6 +372,9 @@ uint32 OSystem_MorphOS::property(int param, Property *value)  	switch (param)  	{ +		case PROP_GET_FULLSCREEN: +			return ScummScreen != NULL; +  		case PROP_TOGGLE_FULLSCREEN:  			CreateScreen(CSDSPTYPE_TOGGLE);  			return 1; @@ -490,6 +516,31 @@ void OSystem_MorphOS::update_cdrom()  void OSystem_MorphOS::quit()  { +	int num_threads = 0; + +	if (ScummMusicThread) +	{ +		num_threads++; +		Signal((Task *) ScummMusicThread, SIGBREAKF_CTRL_C); +		ScummMusicThread = NULL; +	} + +	if (ScummSoundThread) +	{ +		num_threads++; +		Signal((Task *) ScummSoundThread, SIGBREAKF_CTRL_C); +		ScummSoundThread = NULL; +	} + +	while (num_threads > 0) +	{ +		Message* msg; + +		WaitPort(ThreadPort); +		while (msg = GetMsg(ThreadPort)) +			num_threads--; +	} +  	exit(0);  } @@ -960,8 +1011,8 @@ void OSystem_MorphOS::warp_mouse(int x, int y)  			if ((NewPixel = (IEPointerPixel*) AllocVec(sizeof (IEPointerPixel), MEMF_PUBLIC)))  			{  				NewPixel->iepp_Screen = ScummWindow->WScreen; -				NewPixel->iepp_Position.X = x + ScummWindow->LeftEdge + ScummWindow->BorderLeft; -				NewPixel->iepp_Position.Y = x+ScummWindow->TopEdge + ScummWindow->BorderTop; +				NewPixel->iepp_Position.X = (x << ScummScale) + ScummWindow->LeftEdge + ScummWindow->BorderLeft; +				NewPixel->iepp_Position.Y = (y << ScummScale) + ScummWindow->TopEdge + ScummWindow->BorderTop;  				FakeIE->ie_EventAddress = NewPixel;  				FakeIE->ie_NextEvent = NULL; @@ -1414,15 +1465,27 @@ void OSystem_MorphOS::set_mouse_cursor(const byte *buf, uint w, uint h, int hots  bool OSystem_MorphOS::set_sound_proc(OSystem::SoundProc *proc, void *param, OSystem::SoundFormat format)  { +	if (ScummSoundThread) +	{ +		if (SoundProc == proc) +			return true; +		clear_sound_proc(); +	} +  	SoundProc = proc;  	SoundParam = param;  	/*  	 * Create Sound Thread  	 */ +	SoundStartup.mn_Node.ln_Type = NT_MESSAGE; +	SoundStartup.mn_ReplyPort = ThreadPort; +	SoundStartup.mn_Length = sizeof(SoundStartup); +  	ScummSoundThread = CreateNewProcTags(NP_Entry, (ULONG) &morphos_sound_thread,  													 NP_CodeType, CODETYPE_PPC,  													 NP_Name, (ULONG) "ScummVM Sound Thread", +													 NP_StartupMsg, &SoundStartup,  													 NP_PPC_Arg1, (ULONG) this,  													 NP_PPC_Arg2, AHIST_S16S, TAG_DONE);  	if (!ScummSoundThread) @@ -1448,9 +1511,9 @@ void OSystem_MorphOS::clear_sound_proc()  	if (ScummSoundThread)  	{  		Signal((Task *) ScummSoundThread, SIGBREAKF_CTRL_C); -		ObtainSemaphore(&ScummSoundThreadRunning);	 /* Wait for thread to finish */ -		ReleaseSemaphore(&ScummSoundThreadRunning);  		ScummSoundThread = NULL; +		/* Wait for thread to finish */ +		WaitPort(ThreadPort);  	}  } diff --git a/backends/morphos/morphos.h b/backends/morphos/morphos.h index 57c137d3f0..3164af83b4 100644 --- a/backends/morphos/morphos.h +++ b/backends/morphos/morphos.h @@ -40,6 +40,8 @@ class OSystem_MorphOS : public OSystem  					OSystem_MorphOS(SCALERTYPE gfx_mode, bool full_screen);  		virtual ~OSystem_MorphOS(); +		bool Initialise(); +  		// Set colors of the palette  		virtual void set_palette(const byte *colors, uint start, uint num); @@ -182,6 +184,9 @@ class OSystem_MorphOS : public OSystem  		Process 	 *ScummSoundThread;  		SoundProc *SoundProc;  		void      *SoundParam; +		MsgPort	 *ThreadPort; +		Message 	  MusicStartup; +		Message 	  SoundStartup;  		/* CD-ROM related attributes */  		CDRIVEPTR CDrive; diff --git a/backends/morphos/morphos_sound.cpp b/backends/morphos/morphos_sound.cpp index 0646f2bed8..70b344389d 100644 --- a/backends/morphos/morphos_sound.cpp +++ b/backends/morphos/morphos_sound.cpp @@ -190,8 +190,6 @@ int morphos_sound_thread(OSystem_MorphOS *syst, ULONG SampleType)  	ULONG signals;  	bool  initialized; -	ObtainSemaphore(&ScummSoundThreadRunning); -  	initialized = init_morphos_sound();  	if (!initialized)  	{ @@ -250,8 +248,6 @@ int morphos_sound_thread(OSystem_MorphOS *syst, ULONG SampleType)  	exit_morphos_sound(); -	ReleaseSemaphore(&ScummSoundThreadRunning); -	RemTask(NULL);  	return 0;  } diff --git a/backends/morphos/morphos_sound.h b/backends/morphos/morphos_sound.h index f9cd90d2e3..72d3801ac1 100644 --- a/backends/morphos/morphos_sound.h +++ b/backends/morphos/morphos_sound.h @@ -34,9 +34,6 @@ bool init_morphos_music(ULONG MidiUnit, ULONG DevFlags);  void exit_morphos_music();  bool etude_available(); -extern SignalSemaphore ScummMusicThreadRunning; -extern SignalSemaphore ScummSoundThreadRunning; -  extern STRPTR ScummMusicDriver;  extern LONG   ScummMidiUnit;  extern IOMidiRequest *ScummMidiRequest; diff --git a/backends/morphos/morphos_start.cpp b/backends/morphos/morphos_start.cpp index 176f7cc97f..a1cf354aa3 100644 --- a/backends/morphos/morphos_start.cpp +++ b/backends/morphos/morphos_start.cpp @@ -98,11 +98,8 @@ OSystem *OSystem_MorphOS_create(int game_id, int gfx_mode, bool full_screen)  void close_resources()  { -	if (TheSystem) -	{ -		delete TheSystem; -		TheSystem = NULL; -	} +	delete TheSystem; +	TheSystem = NULL;  	if (ScummPath)  	{ @@ -311,10 +308,6 @@ int main()  	char dbglvl[6];  	int argc = 0; -	InitSemaphore(&ScummSoundThreadRunning); -	InitSemaphore(&ScummMusicThreadRunning); - -	g_scumm = NULL;  	atexit(&close_resources);  	memset(args, '\0', sizeof (args)); diff --git a/backends/morphos/morphos_timer.cpp b/backends/morphos/morphos_timer.cpp index f3ba9e5341..8226bd67c5 100644 --- a/backends/morphos/morphos_timer.cpp +++ b/backends/morphos/morphos_timer.cpp @@ -35,16 +35,22 @@  Timer::Timer(Engine * engine)  { -	InitSemaphore(&TimerServiceSemaphore); - -	TimerServiceThread = CreateNewProcTags(NP_Entry, 	 (ULONG) TimerService, -														NP_CodeType, CODETYPE_PPC, -														NP_Name,  	 (ULONG) "ScummVM Timer Service", -														NP_Priority, 20, -														NP_PPC_Arg1, (ULONG) this, -														NP_PPC_Arg2, (ULONG) engine, -														TAG_DONE -													  ); +	if ((TimerServicePort = CreateMsgPort())) +	{ +		TimerServiceStartup.mn_Node.ln_Type = NT_MESSAGE; +		TimerServiceStartup.mn_ReplyPort = TimerServicePort; +		TimerServiceStartup.mn_Length = sizeof(TimerServiceStartup); + +		TimerServiceThread = CreateNewProcTags(NP_Entry, 	 (ULONG) TimerService, +															NP_CodeType, CODETYPE_PPC, +															NP_Name,  	 (ULONG) "ScummVM Timer Service", +															NP_Priority, 0, +															NP_StartupMsg, &TimerServiceStartup, +															NP_PPC_Arg1, (ULONG) this, +															NP_PPC_Arg2, (ULONG) engine, +															TAG_DONE +														  ); +	}  }  Timer::~Timer() @@ -52,8 +58,9 @@ Timer::~Timer()  	if (TimerServiceThread)  	{  		Signal((Task *) TimerServiceThread, SIGBREAKF_CTRL_C); -		ObtainSemaphore(&TimerServiceSemaphore); -		ReleaseSemaphore(&TimerServiceSemaphore); +		WaitPort(TimerServicePort); +		DeleteMsgPort(TimerServicePort); +		TimerServiceThread = NULL;  	}  } @@ -108,8 +115,6 @@ void Timer::TimerService(Timer *this_ptr, Engine *engine)  	ULONG timers = 0;  	TimerSlot timer_slots[MAX_TIMERS]; -	ObtainSemaphore(&this_ptr->TimerServiceSemaphore); -  	for (;;)  	{  		signals = Wait(signal_mask); @@ -224,8 +229,5 @@ void Timer::TimerService(Timer *this_ptr, Engine *engine)  		DeleteIORequest((IORequest *) timer_slots[t].ts_IORequest);  		DeleteMsgPort(timer_slots[t].ts_Port);  	} - -	ReleaseSemaphore(&this_ptr->TimerServiceSemaphore); -	RemTask(NULL);  } diff --git a/backends/morphos/morphos_timer.h b/backends/morphos/morphos_timer.h index 589ab113a1..de7e540fb0 100644 --- a/backends/morphos/morphos_timer.h +++ b/backends/morphos/morphos_timer.h @@ -70,7 +70,8 @@ class Timer  		static void TimerService(Timer *, Engine *);  		Process *TimerServiceThread; -		SignalSemaphore TimerServiceSemaphore; +		MsgPort *TimerServicePort; +		Message TimerServiceStartup;  		struct TimerSlot  		{  | 
