[Scummvm-cvs-logs] CVS: scummvm/morphos morphos.h,NONE,1.1 morphos_start.cpp,NONE,1.1 Makefile,1.2,1.3 morphos.cpp,1.7,1.8 morphos_sound.cpp,1.5,1.6

Ruediger Hanke tomjoad at users.sourceforge.net
Sun Apr 14 12:44:11 CEST 2002


Update of /cvsroot/scummvm/scummvm/morphos
In directory usw-pr-cvs1:/tmp/cvs-serv25391/morphos

Modified Files:
	Makefile morphos.cpp morphos_sound.cpp 
Added Files:
	morphos.h morphos_start.cpp 
Log Message:
Updating MorphOS port to compile with current CVS state

--- NEW FILE: morphos.h ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2002 Rüdiger Hanke (MorphOS port)
 *
 * 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 the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * MorphOS-specific header file
 *
 * $Header: /cvsroot/scummvm/scummvm/morphos/morphos.h,v 1.1 2002/04/14 19:43:12 tomjoad Exp $
 *
 */

#include <exec/semaphores.h>
#include <libraries/cdda.h>

class OSystem_MorphOS : public OSystem
{
	public:
		typedef enum { ST_INVALID = 0, ST_NONE, ST_POINT, ST_SUPEREAGLE, ST_SUPER2XSAI } SCALERTYPE;

					OSystem_MorphOS( int game_id, SCALERTYPE gfx_mode, bool full_screen );
		virtual ~OSystem_MorphOS();

		// Set colors of the palette
		virtual void set_palette(const byte *colors, uint start, uint num);

		// Set the size of the video bitmap.
		// Typically, 320x200
		virtual void init_size(uint w, uint h);

		// Draw a bitmap to screen.
		// The screen will not be updated to reflect the new bitmap
		virtual void copy_rect(const byte *buf, int pitch, int x, int y, int w, int h);

		// Update the dirty areas of the screen
		virtual void update_screen();

		// Either show or hide the mouse cursor
		virtual bool show_mouse(bool visible);

		// Set the position of the mouse cursor
		virtual void set_mouse_pos(int x, int y);

		// Set the bitmap that's used when drawing the cursor.
		virtual void set_mouse_cursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y);

		// Shaking is used in SCUMM. Set current shake position.
		virtual void set_shake_pos(int shake_pos);

		// Get the number of milliseconds since the program was started.
		virtual uint32 get_msecs();

		// Delay for a specified amount of milliseconds
		virtual void delay_msecs(uint msecs);

		// Create a thread
		virtual void *create_thread(ThreadProc *proc, void *param);

		// Get the next event.
		// Returns true if an event was retrieved.
		virtual bool poll_event(Event *event);

		// Set the function to be invoked whenever samples need to be generated
		virtual void set_sound_proc(void *param, SoundProc *proc, byte format);
				  void fill_sound    (byte * stream, int len);

		virtual uint32 property(int param, uint32 value);

		// Quit
		virtual void quit();

		static OSystem_MorphOS *create  ( int game_id, SCALERTYPE gfx_scaler, bool full_screen );
		static uint32 make_color( int pixfmt, int r, int g, int b );

		static SCALERTYPE  FindScaler		  ( const char *ScalerName );

	private:
		typedef void (*ScalerFunc)( uint32 src_x, uint32 src_y, uint32 dest_x, uint32 dest_y, uint32 width, uint32 height );
		typedef enum { CSDSPTYPE_WINDOWED, CSDSPTYPE_FULLSCREEN, CSDSPTYPE_TOGGLE, CSDSPTYPE_KEEP } CS_DSPTYPE;

		struct GfxScaler
		{
			STRPTR 		gs_Name;
			SCALERTYPE	gs_Type;
		};

		static const int MAX_MOUSE_W = 40;
		static const int MAX_MOUSE_H = 40;

		void   		  create_screen   ( CS_DSPTYPE dspType );
		void 	 		  SwitchScalerTo  ( SCALERTYPE newScaler );
		void   		  Super2xSaI		( uint32 src_x, uint32 src_y, uint32 dest_x, uint32 dest_y, uint32 width, uint32 height );
		void   		  SuperEagle		( uint32 src_x, uint32 src_y, uint32 dest_x, uint32 dest_y, uint32 width, uint32 height );
		void   		  PointScaler		( uint32 src_x, uint32 src_y, uint32 dest_x, uint32 dest_y, uint32 width, uint32 height );

		void   draw_mouse();
		void   undraw_mouse();

		/* Display-related attributes */
		struct Screen  	  *ScummScreen;
		struct Window  	  *ScummWindow;
		char 						ScummWndTitle[ 125 ];
		APTR            		ScummBuffer;
		struct ScreenBuffer *ScummScreenBuffer[ 2 ];
		struct BitMap  	  *ScummRenderTo;
		bool			    		ScummPCMode;
		ULONG			   		ScummPaintBuffer;
		int						ScummScrWidth;
		int 						ScummScrHeight;
		int						ScummDepth;
		bool 						Scumm16ColFmt16;
		UWORD 		   	  *ScummNoCursor;
		ULONG 		    		ScummColors[256];
		USHORT 		    		ScummColors16[256];
		WORD			    		ScummWinX;
		WORD			    		ScummWinY;
		bool			    		ScummOrigMouse;
		int 			    		ScummShakePos;
		bool						FullScreenMode;

		/* Scaling-related attributes */
		uint32 					colorMask;
		uint32 					lowPixelMask;
		uint32 					qcolorMask;
		uint32 					qlowpixelMask;
		uint32 					redblueMask;
		uint32 					greenMask;
		int 						PixelsPerMask;
		byte 					  *src_line[4];
		byte 					  *dst_line[2];

		/* Sound-related attributes */
		struct Process *ScummMusicThread;
		struct Process *ScummSoundThread;
		SoundProc 		*SoundProc;
		void      		*SoundParam;

		/* CD-ROM related attributes */
		CDRIVEPTR 		 CDrive;
		ULONG 			 CDDATrackOffset;

		/* Scaling-related attributes */
		SCALERTYPE ScummScaler;
		int  		  ScummScale;
		static GfxScaler ScummScalers[ 10 ];

		/* Mouse cursor-related attributes */
		bool  MouseVisible, MouseDrawn;
		int   MouseX, MouseY;
		int   MouseWidth, MouseHeight;
		int   MouseOldX, MouseOldY;
		int   MouseOldWidth, MouseOldHeight;
		int   MouseHotspotX, MouseHotspotY;
		byte *MouseImage, MouseBackup[ MAX_MOUSE_W*MAX_MOUSE_H ];

		/* Timer-related attributes */
		struct MsgPort 	 *TimerMsgPort;
		struct timerequest *TimerIORequest;

		/* Game-related attributes */
		int   GameID;
};

int morphos_sound_thread( OSystem_MorphOS *syst, ULONG SampleType );

int morphos_main( int argc, char *argv[] );

extern OSystem_MorphOS *TheSystem;
extern struct SignalSemaphore ScummMusicThreadRunning;
extern struct SignalSemaphore ScummSoundThreadRunning;


--- NEW FILE: morphos_start.cpp ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2002 Rüdiger Hanke (MorphOS port)
 *
 * 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 the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * MorphOS startup handling
 *
 * $Header: /cvsroot/scummvm/scummvm/morphos/morphos_start.cpp,v 1.1 2002/04/14 19:43:12 tomjoad Exp $
 *
 */

#include <exec/types.h>
#include <exec/memory.h>
#include <exec/libraries.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/cdda.h>
#include <proto/cybergraphics.h>
#include <proto/icon.h>

#include "stdafx.h"
#include "scumm.h"
#include "morphos.h"

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 struct RDArgs *ScummArgs = NULL;

static char*ScummStory = NULL;
static char*ScummPath = NULL;
static LONG ScummMidiUnit = 0;
static LONG ScummMidiVolume = 0;
static LONG ScummMidiTempo = 0;
static OSystem_MorphOS::SCALERTYPE ScummGfxScaler = OSystem_MorphOS::ST_INVALID;

static BPTR OrigDirLock = 0;

struct Library *CDDABase = NULL;
struct Library *CyberGfxBase = NULL;

OSystem_MorphOS *TheSystem = NULL;

OSystem *OSystem_MorphOS_create( int game_id, int gfx_mode, bool full_screen)
{
	if( TheSystem )
		delete TheSystem;

	OSystem_MorphOS::SCALERTYPE gfx_scaler = OSystem_MorphOS::ST_NONE;
	switch( gfx_mode )
	{
		case GFX_DOUBLESIZE:
			gfx_scaler = OSystem_MorphOS::ST_POINT;
			break;

		case GFX_SUPEREAGLE:
			gfx_scaler = OSystem_MorphOS::ST_SUPEREAGLE;
			break;

		case GFX_SUPER2XSAI:
			gfx_scaler = OSystem_MorphOS::ST_SUPER2XSAI;
			break;
	}

	TheSystem = OSystem_MorphOS::create( game_id, gfx_scaler, full_screen );
	return TheSystem;
}

void close_resources()
{
	if( TheSystem )
		delete TheSystem;

	if( ScummPath )
		FreeVec( ScummPath );

	if( ScummStory )
		FreeVec( ScummStory );

	if( ScummArgs )
		FreeArgs( ScummArgs );

	if( OrigDirLock )
		CurrentDir( OrigDirLock );

	if( CDDABase )
		CloseLibrary( CDDABase );

	if( CyberGfxBase )
		CloseLibrary( CyberGfxBase );
}

void ReadToolTypes( struct WBArg *OfFile )
{
	struct DiskObject *dobj;
	char 	*ToolValue;
	char IconPath[ 256 ];

	NameFromLock( OfFile->wa_Lock, IconPath, 256 );
	AddPart( IconPath, OfFile->wa_Name, 256 );

	dobj = GetDiskObject( IconPath );
	if( dobj == NULL )
		return;

	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "STORY" ) )
	{
		if( ScummStory )
			FreeVec( ScummStory );
		ScummStory = (char *)AllocVec( strlen( ToolValue )+1, MEMF_PUBLIC );
		strcpy( ScummStory, ToolValue );
	}

	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "DATAPATH" ) )
	{
		if( ScummPath )
			FreeVec( ScummPath );
		ScummPath = (char *)AllocVec( strlen( ToolValue )+4, MEMF_PUBLIC );
		strcpy( ScummPath, "-p" );
		strcat( ScummPath, ToolValue );
	}

	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "WBWINDOW" ) )
	{
		if( MatchToolValue( ToolValue, "YES" ) )
			args[ USG_WBWINDOW ] = TRUE;
		else if( MatchToolValue( ToolValue, "NO" ) )
			args[ USG_WBWINDOW ] = FALSE;
	}

	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "SCALER" ) )
	{
		if( (ScummGfxScaler = OSystem_MorphOS::FindScaler( ToolValue )) == OSystem_MorphOS::ST_INVALID )
		{
			FreeDiskObject( dobj );
			exit( 1 );
		}
	}

	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( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "MIDIUNIT" ) )
		ScummMidiUnit = atoi( ToolValue );

	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "VOLUME" ) )
	{
		int vol = atoi( ToolValue );
		if( vol >= 0 && vol <= 100 )
		{
			ScummMidiVolume = vol;
			args[ USG_VOLUME ] = (ULONG)&ScummMidiVolume;
		}
	}

	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "TEMPO" ) )
	{
		ScummMidiTempo = atoi( ToolValue );
		args[ USG_TEMPO ] = (ULONG)&ScummMidiTempo;
	}

	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "ROLANDEMU" ) )
	{
		if( MatchToolValue( ToolValue, "YES" ) )
			args[ USG_ROLANDEMU ] = FALSE;
		else if( MatchToolValue( ToolValue, "NO" ) )
			args[ USG_ROLANDEMU ] = TRUE;
	}

	if( ToolValue = (char *)FindToolType( dobj->do_ToolTypes, "SUBTITLES" ) )
	{
		if( MatchToolValue( ToolValue, "YES" ) )
			args[ USG_NOSUBTITLES ] = FALSE;
		else if( MatchToolValue( ToolValue, "NO" ) )
			args[ USG_NOSUBTITLES ] = TRUE;
	}

	FreeDiskObject( dobj );
}

#undef main

int main()
{
	int delta;
	int last_time, new_time;
	char *argv[ 10 ];
	char volume[ 6 ], tempo[ 12 ], scaler[ 14 ];
	char *SVMScalers[] = { "", "normal", "2x", "supereagle", "super2xsai" };
	int argc = 0;

	InitSemaphore( &ScummSoundThreadRunning );
	InitSemaphore( &ScummMusicThreadRunning );

	CyberGfxBase = OpenLibrary( "cybergraphics.library", 41 );
	if( CyberGfxBase == NULL )
	{
		puts( "Failed to open cybergraphics.library" );
		exit( 1 );
	}

	atexit( &close_resources );

	if( _WBenchMsg == NULL )
	{
		/* Parse the command line here */
		ScummArgs = ReadArgs( usageTemplate, args, NULL );
		if( ScummArgs == NULL )
		{
			puts( "Error in command line - type \"ScummVM ?\" for usage.\n" );
			exit( 1 );
		}

		if( args[ USG_STORY ] )
		{
			ScummStory = (char *)AllocVec( strlen( (char *)args[ USG_STORY ] )+1, MEMF_PUBLIC );
			strcpy( ScummStory, (char *)args[ USG_STORY ] );
		}

		if( args[ USG_DATAPATH ] )
		{
			ScummPath = (char *)AllocVec( strlen( (char *)args[ USG_DATAPATH ] )+4, MEMF_PUBLIC );
			strcpy( ScummPath, "-p" );
			strcat( ScummPath, (char *)args[ USG_DATAPATH ] );
		}

		if( args[ USG_SCALER ] )
		{
			if( (ScummGfxScaler = OSystem_MorphOS::FindScaler( (char *)args[ USG_SCALER ] )) == OSystem_MorphOS::ST_INVALID )
				exit( 1 );
		}

		if( args[ USG_MIDIUNIT ] )
			ScummMidiUnit = *((LONG *)args[ USG_MIDIUNIT ]);

		if( args[ USG_TEMPO ] )
			ScummMidiTempo = *((LONG *)args[ USG_TEMPO ]);

		if( args[ USG_VOLUME ] )
			ScummMidiVolume = *((LONG *)args[ USG_VOLUME ]);
	}
	else
	{
		/* We've been started from Workbench */
		ReadToolTypes( &_WBenchMsg->sm_ArgList[ 0 ] );
		if( _WBenchMsg->sm_NumArgs > 1 )
		{
			ReadToolTypes( &_WBenchMsg->sm_ArgList[ 1 ] );
			OrigDirLock = CurrentDir( _WBenchMsg->sm_ArgList[ 1 ].wa_Lock );
		}
	}

	if( ScummPath )
	{
		char c = ScummPath[ strlen( ScummPath )-1 ];
		if( c != '/' && c != ':' )
			strcat( ScummPath, "/" );
	}

	argv[ argc++ ] = "ScummVM";
	argv[ argc++ ] = ScummStory;
	if( ScummPath ) 					argv[ argc++ ] = ScummPath;
	if( !args[ USG_WBWINDOW ]   ) argv[ argc++ ] = "-f";
	if( args[ USG_NOSUBTITLES ] ) argv[ argc++ ] = "-n";
	if( args[ USG_ROLANDEMU ] 	 ) argv[ argc++ ] = "-r";
	if( ScummGfxScaler != OSystem_MorphOS::ST_INVALID )
	{
		sprintf( scaler, "-g%s", SVMScalers[ (int)ScummGfxScaler ] );
		argv[ argc++ ] = scaler;
	}
	else
		argv[ argc++ ] = "-gsuper2xsai";
	if( args[ USG_VOLUME ] && ScummMidiVolume >= 0 && ScummMidiVolume <= 100 )
	{
		sprintf( volume, "-m%d", ScummMidiVolume );
		argv[ argc++ ] = volume;
	}
	if( args[ USG_TEMPO ] && ScummMidiTempo > 0 )
	{
		sprintf( tempo, "-t%lx", ScummMidiTempo );
		argv[ argc++ ] = tempo;
	}

	return morphos_main( argc, argv );
}


Index: Makefile
===================================================================
RCS file: /cvsroot/scummvm/scummvm/morphos/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Makefile	10 Apr 2002 20:48:27 -0000	1.2
--- Makefile	14 Apr 2002 19:43:11 -0000	1.3
***************
*** 1,7 ****
! vpath %.cpp ../:../sound/:../v3/:../v4/
  
  CC      = g++
  CFLAGS  = -Wno-multichar -fstrength-reduce -O2
! DEFINES =
  LDFLAGS := -noixemul -s
  INCLUDES:= -I../ -I../sound
--- 1,8 ----
! vpath %.cpp ../:../sound/:../v3/:../v4/:../simon/
! vpath %.h   ../
  
  CC      = g++
  CFLAGS  = -Wno-multichar -fstrength-reduce -O2
! DEFINES = -DNO_PPCINLINE_STDARG -DNO_PPCINLINE_VARARGS
  LDFLAGS := -noixemul -s
  INCLUDES:= -I../ -I../sound
***************
*** 10,20 ****
  ZIPFILE := scummvm-`date '+%Y-%m-%d'`.zip
  
! INCS	= ../scumm.h ../scummsys.h ../stdafx.h
  
  OBJS	= actor.o akos.o boxes.o costume.o gfx.o object.o resource.o \
! 	saveload.o script.o scummvm.o sound.o string.o \
! 	sys.o verbs.o morphos.o morphos_sound.o script_v1.o script_v2.o debug.o gui.o \
! 	imuse.o fmopl.o adlib.o gmidi.o debugrl.o vars.o insane.o \
! 	gameDetector.o init.o resource_v3.o resource_v4.o
  
  DISTFILES=$(OBJS:.o=.cpp) Makefile scumm.h scummsys.h stdafx.h stdafx.cpp \
--- 11,22 ----
  ZIPFILE := scummvm-`date '+%Y-%m-%d'`.zip
  
! INCS	= scumm.h scummsys.h stdafx.h
  
  OBJS	= actor.o akos.o boxes.o costume.o gfx.o object.o resource.o \
! 	saveload.o script.o scummvm.o sound.o string.o sys.o verbs.o \
! 	morphos.o morphos_sound.o morphos_start.o script_v1.o script_v2.o debug.o gui.o \
! 	imuse.o fmopl.o mixer.o mididrv.o debugrl.o vars.o insane.o \
! 	gameDetector.o init.o resource_v3.o resource_v4.o main.o \
! 	midi.o simon.o simonsys.o
  
  DISTFILES=$(OBJS:.o=.cpp) Makefile scumm.h scummsys.h stdafx.h stdafx.cpp \

Index: morphos.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/morphos/morphos.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** morphos.cpp	14 Apr 2002 18:13:08 -0000	1.7
--- morphos.cpp	14 Apr 2002 19:43:12 -0000	1.8
***************
*** 26,31 ****
  #include "stdafx.h"
  #include "scumm.h"
- #include "gui.h"
- #include "gameDetector.h"
  
  #include <exec/types.h>
--- 26,29 ----
***************
*** 33,36 ****
--- 31,35 ----
[...1889 lines suppressed...]
  {
! 	int scaler = 0;
! 	
! 	while( ScummScalers[ scaler ].gs_Name )
  	{
! 		if( !stricmp( ScalerName, ScummScalers[ scaler ].gs_Name ) )
! 			return ScummScalers[ scaler ].gs_Type;
! 		scaler++;
  	}
  
! 	if( ScummScalers[ scaler ].gs_Name == NULL )
! 	{
! 		puts( "Invalid scaler name. Please use one of the following:" );
! 		for( scaler = 0; ScummScalers[ scaler ].gs_Name != NULL; scaler++ )
! 			printf( "  %s\n", ScummScalers[ scaler ].gs_Name );
! 	}
  
! 	return ST_INVALID;
  }
  

Index: morphos_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/morphos/morphos_sound.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** morphos_sound.cpp	14 Apr 2002 18:13:08 -0000	1.5
--- morphos_sound.cpp	14 Apr 2002 19:43:12 -0000	1.6
***************
*** 32,37 ****
  #include <devices/amidi.h>
  
- #define NO_PPCINLINE_STDARG
- #define NO_PPCINLINE_VARARGS
  #include <clib/alib_protos.h>
  #include <proto/exec.h>
--- 32,35 ----
***************
*** 39,55 ****
  #include <proto/ahi.h>
  
! extern int GetTicks();
! extern Scumm scumm;
! extern IMuse sound;
! extern SOUND_DRIVER_TYPE snd_driv;
  
  #define AHI_BUF_SIZE	 (8*1024)
  
  struct SignalSemaphore ScummMusicThreadRunning;
  
  static struct MsgPort     *ahiPort    		 = NULL;
  static struct AHIRequest  *ahiReq[ 2 ]		 = { NULL, NULL };
  static UWORD					ahiCurBuf		 = 0;
! static BOOL						ahiReqSent[ 2 ] = { FALSE, FALSE };
  static BYTE						ahiDevice		 = -1;
  		 UBYTE					ahiUnit  		 = AHI_DEFAULT_UNIT;
--- 37,51 ----
  #include <proto/ahi.h>
  
! #include "morphos.h"
  
  #define AHI_BUF_SIZE	 (8*1024)
  
  struct SignalSemaphore ScummMusicThreadRunning;
+ struct SignalSemaphore ScummSoundThreadRunning;
  
  static struct MsgPort     *ahiPort    		 = NULL;
  static struct AHIRequest  *ahiReq[ 2 ]		 = { NULL, NULL };
  static UWORD					ahiCurBuf		 = 0;
! static bool						ahiReqSent[ 2 ] = { false, false };
  static BYTE						ahiDevice		 = -1;
  		 UBYTE					ahiUnit  		 = AHI_DEFAULT_UNIT;
***************
*** 59,63 ****
  		 struct IOMidiRequest *ScummMidiRequest = NULL;
  
! bool init_morphos_sound( ULONG MidiUnit, bool NoMusic )
  {
  	if( !NoMusic )
--- 55,59 ----
  		 struct IOMidiRequest *ScummMidiRequest = NULL;
  
! bool init_morphos_music( ULONG MidiUnit, bool NoMusic )
  {
  	if( !NoMusic )
***************
*** 86,92 ****
--- 82,108 ----
  
  		if( !ScummMidiRequest )
+ 		{
  			warning( "Could not open AMidi - music will not play" );
+ 			return false;
+ 		}
  	}
  
+ 	return true;
+ }
+ 
+ 
+ void exit_morphos_music()
+ {
+ 	if( ScummMidiRequest )
+ 	{
+ 		CloseDevice( (struct IORequest *)ScummMidiRequest );
+ 		DeleteIORequest( (struct IORequest *)ScummMidiRequest );
+ 		DeleteMsgPort( ScummMidiPort );
+ 	}
+ }
+ 
+ 
+ static bool init_morphos_sound()
+ {
  	if( !(ahiPort = CreateMsgPort()) )
  		return false;
***************
*** 136,152 ****
  	CopyMem( ahiReq[ 0 ], ahiReq[ 1 ], sizeof( struct AHIRequest ) );
  
  	return true;
  }
  
  
! void exit_morphos_sound()
  {
- 	if( ScummMidiRequest )
- 	{
- 		CloseDevice( (struct IORequest *)ScummMidiRequest );
- 		DeleteIORequest( (struct IORequest *)ScummMidiRequest );
- 		DeleteMsgPort( ScummMidiPort );
- 	}
- 
  	if( ahiReq[ 1 ] )
  		FreeVec( ahiReq[ 1 ] );
--- 152,165 ----
  	CopyMem( ahiReq[ 0 ], ahiReq[ 1 ], sizeof( struct AHIRequest ) );
  
+ 	ahiCurBuf = 0;
+ 	ahiReqSent[ 0 ] = FALSE;
+ 	ahiReqSent[ 1 ] = FALSE;
+ 
  	return true;
  }
  
  
! static void exit_morphos_sound()
  {
  	if( ahiReq[ 1 ] )
  		FreeVec( ahiReq[ 1 ] );
***************
*** 168,171 ****
--- 181,185 ----
  int morphos_music_thread( Scumm *s, ULONG MidiUnit, bool NoMusic )
  {
+ #if 0
  	int  old_time, cur_time;
  	bool initialized;
***************
*** 176,180 ****
  	ObtainSemaphore( &ScummMusicThreadRunning );
  
! 	initialized = init_morphos_sound( MidiUnit, NoMusic );
  	if( !initialized )
  		warning( "Sound could not be initialized" );
--- 190,194 ----
  	ObtainSemaphore( &ScummMusicThreadRunning );
  
! 	initialized = init_morphos_music( MidiUnit, NoMusic );
  	if( !initialized )
  		warning( "Sound could not be initialized" );
***************
*** 205,223 ****
  	else
  	{
! 		old_time = GetTicks();
  
  		for(;;)
  		{
  			if( CheckSignal( SIGBREAKF_CTRL_F ) )
- 			{
- 				if( ahiReqSent[ ahiCurBuf ] )
- 				{
- 					AbortIO( (struct IORequest *)ahiReq[ ahiCurBuf ] );
- 					WaitIO ( (struct IORequest *)ahiReq[ ahiCurBuf ] );
- 				}
  				break;
- 			}
  
! 			if( !snd_driv.wave_based() )
  			{
  				cur_time = GetTicks();
--- 219,230 ----
  	else
  	{
! 		old_time = 0;//GetTicks();
  
  		for(;;)
  		{
  			if( CheckSignal( SIGBREAKF_CTRL_F ) )
  				break;
  
! /*			  if( !snd_driv.wave_based() )
  			{
  				cur_time = GetTicks();
***************
*** 226,246 ****
  					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( !initialized )
! 				continue;
  
! 			if( !ahiReqSent[ ahiCurBuf ] || CheckIO( (struct IORequest *)ahiReq[ ahiCurBuf ] ) )
  			{
  				struct AHIRequest *req = ahiReq[ ahiCurBuf ];
--- 233,284 ----
  					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;
! 	bool  initialized;
! 
! 	ObtainSemaphore( &ScummSoundThreadRunning );
! 
! 	initialized = init_morphos_sound();
! 	if( !initialized )
! 	{
! 		warning( "Sound could not be initialized. The game may hang at some point (press Ctrl-z then)." );
! 		Wait( SIGBREAKF_CTRL_C );
! 	}
! 	else
! 	{
! 		for(;;)
! 		{
! 			while( !ahiReqSent[ ahiCurBuf ] || CheckIO( (struct IORequest *)ahiReq[ ahiCurBuf ] ) )
  			{
  				struct AHIRequest *req = ahiReq[ ahiCurBuf ];
***************
*** 250,263 ****
  					WaitIO( (struct IORequest *)req );
  
! 				if( CheckSignal( SIGBREAKF_CTRL_F ) )
! 					break;
! 
! 				scumm.mixWaves( (int16 *)ahiBuf[ ahiCurBuf ], AHI_BUF_SIZE >> 1 );
! 
  				req->ahir_Std.io_Message.mn_Node.ln_Pri = 0;
  				req->ahir_Std.io_Command = CMD_WRITE;
  				req->ahir_Std.io_Data    = ahiBuf[ ahiCurBuf ];
  				req->ahir_Std.io_Length  = AHI_BUF_SIZE;
! 				req->ahir_Type				 = AHIST_M16S;
  				req->ahir_Frequency		 = SAMPLES_PER_SEC;
  				req->ahir_Position  		 = 0x8000;
--- 288,298 ----
  					WaitIO( (struct IORequest *)req );
  
! 				syst->fill_sound( (byte *)ahiBuf[ ahiCurBuf ], AHI_BUF_SIZE );
! 	
  				req->ahir_Std.io_Message.mn_Node.ln_Pri = 0;
  				req->ahir_Std.io_Command = CMD_WRITE;
  				req->ahir_Std.io_Data    = ahiBuf[ ahiCurBuf ];
  				req->ahir_Std.io_Length  = AHI_BUF_SIZE;
! 				req->ahir_Type				 = SampleType;
  				req->ahir_Frequency		 = SAMPLES_PER_SEC;
  				req->ahir_Position  		 = 0x8000;
***************
*** 266,285 ****
  				SendIO( (struct IORequest *)req );
  
! 				ahiReqSent[ ahiCurBuf ] = TRUE;
  				ahiCurBuf = ahiOtherBuf;
  			}
  		}
- 	}
  
! 	if( TimerAvailable )
! 	{
! 		CloseDevice( (struct IORequest *)TimerIORequest );
! 		DeleteIORequest( (struct IORequest *)TimerIORequest );
! 		DeleteMsgPort( TimerMsgPort );
  	}
  
  	exit_morphos_sound();
  
! 	ReleaseSemaphore( &ScummMusicThreadRunning );
  	return 0;
  }
--- 301,333 ----
  				SendIO( (struct IORequest *)req );
  
! 				ahiReqSent[ ahiCurBuf ] = true;
  				ahiCurBuf = ahiOtherBuf;
  			}
+ 
+ 			signals = Wait( SIGBREAKF_CTRL_C | (1 << ahiPort->mp_SigBit) );
+ 
+ 			if( signals & SIGBREAKF_CTRL_C )
+ 				break;
  		}
  
! 		if( ahiReqSent[ ahiCurBuf ] )
! 		{
! 			AbortIO( (struct IORequest *)ahiReq[ ahiCurBuf ] );
! 			WaitIO ( (struct IORequest *)ahiReq[ ahiCurBuf ] );
! 			ahiReqSent[ ahiCurBuf ] = false;
! 		}
! 
! 		if( ahiReqSent[ !ahiCurBuf ] )
! 		{
! 			AbortIO( (struct IORequest *)ahiReq[ !ahiCurBuf ] );
! 			WaitIO ( (struct IORequest *)ahiReq[ !ahiCurBuf ] );
! 			ahiReqSent[ !ahiCurBuf ] = false;
! 		}
  	}
  
  	exit_morphos_sound();
  
! 	ReleaseSemaphore( &ScummSoundThreadRunning );
! 	RemTask( NULL );
  	return 0;
  }





More information about the Scummvm-git-logs mailing list