⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msdos.cpp

📁 SFC游戏模拟器 snes9x 1.43 的原代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    void S9xSetEnvRate (Channel *, unsigned long, int, int);    void S9xSetEnvRate_end ();        extern long FilterValues[4][2];    extern int Echo [15360 + 14];    extern int DummyEchoBuffer [MAX_BUFFER_SIZE];    extern int MixBuffer [MAX_BUFFER_SIZE];    extern int EchoBuffer [MAX_BUFFER_SIZE];    extern int FilterTaps [8];    extern unsigned long Z;    extern int Loop [16];    LOCK_FUNCTION (S9xMixSamples);    LOCK_FUNCTION (S9xMixSamplesO);    LOCK_FUNCTION (MixStereo);    LOCK_FUNCTION (MixMono);    LOCK_FUNCTION (S9xAPUSetEndX);    LOCK_FUNCTION (S9xAPUSetEndOfSample);    LOCK_FUNCTION (S9xSetEnvelopeRate);    LOCK_FUNCTION (S9xSetEnvRate);    LOCK_VARIABLE (APU);    LOCK_VARIABLE (IAPU);    LOCK_VARIABLE (SoundData);    LOCK_VARIABLE (so);    LOCK_VARIABLE (FilterValues);    LOCK_VARIABLE (Echo);    LOCK_VARIABLE (DummyEchoBuffer);    LOCK_VARIABLE (MixBuffer);    LOCK_VARIABLE (EchoBuffer);    LOCK_VARIABLE (FilterTaps);    LOCK_VARIABLE (Z);    LOCK_VARIABLE (Loop);    _go32_dpmi_lock_data ((void *) IAPU.RAM, 64 * 1024);    _go32_dpmi_lock_data ((void *) IAPU.ShadowRAM, 64 * 1024);    _go32_dpmi_lock_data ((void *) IAPU.CachedSamples, 256 * 1024);    printf ("Rate: %d, Buffer size: %d, 16-bit: %s, Stereo: %s, Encoded: %s\n",	    so.playback_rate, so.buffer_size, so.sixteen_bit ? "yes" : "no",	    so.stereo ? "yes" : "no", so.encoded ? "yes" : "no");    so.mute_sound = FALSE;    return (TRUE);}void S9xGenerateSound (){}bool8 S9xReadMousePosition (int which1, int &x, int &y, uint32 &buttons){    if (which1 == 0)    {	buttons = mouse_b;	prev_mouse_x += mouse_x - screen_width / 2;	prev_mouse_y += mouse_y - screen_height / 2;	position_mouse (screen_width / 2, screen_height / 2);	x = prev_mouse_x;	y = prev_mouse_y;	return (TRUE);    }    return (FALSE);}bool8 S9xReadSuperScopePosition (int &x, int &y, uint32 &buttons){    buttons = (mouse_b & 3) | (superscope_turbo << 2) |	      (superscope_pause << 3);    x = (int) ((mouse_x - mouse_offset_x) / mouse_scale_h);    y = (int) ((mouse_y - mouse_offset_y) / mouse_scale_v);    return (TRUE);}#ifdef SIDEWINDER_SUPPORT#define INITIAL_TIMEOUT 200#define FIRST_STROBE_TIMEOUT 160#define MIN_FIRST_STOBE_LEN 32#define TIMEOUT 30#define INTER_SIDEWINDER_STROBE_LEN 16#define MODE_A_STROBES 15#define MODE_B_STROBES 5#define MAX_STROBES_PER_SIDEWINDER MODE_A_STROBES#define SW_PORT	    0x201extern int SidewinderToSNES [];extern int SidewinderToSNES2 [];int ReadSidewinders ();void InitSidewinders (){    num_sidewinders = ReadSidewinders ();}int ReadSidewinders (){    static SW_READ_DATA prev_ret = {0};    int j, i;    unsigned char b;    char *t;    int strobes = 0;    int start;    unsigned char data [SW_MAX_SIDEWINDERS * MAX_STROBES_PER_SIDEWINDER * 2];    unsigned char *p = data;    unsigned char *pend = p + sizeof (data);    struct SW_READ_DATA ret;    unsigned int buttons;    unsigned int parity;        for (i = 0; i < SW_MAX_SIDEWINDERS; i++)    {	ret.buttons [i] = 0;	ret.valid [i] = 0;    }	    ret.count = 0;    j = 0;        cli ();    outportb ((uint16) SW_PORT, (uint8) 0xff);    b = inportb ((uint16) SW_PORT);    b = inportb ((uint16) SW_PORT);    if (!(b & 0x10))    {	/* Search for bit 4 going from 0 to 1 */	do	{	    b = inportb ((uint16) SW_PORT);	    if (++j >= INITIAL_TIMEOUT)		goto exit;	} while (!(b & 0x10));    }	        j = 0;    do    {	b = inportb ((uint16) SW_PORT);	if (++j > FIRST_STROBE_TIMEOUT)	    goto exit;    } while (b & 0x10);        do    {	j = 0;	do	{	    b = inportb ((uint16) SW_PORT);	    if (++j > TIMEOUT)	    {		*p = j;		*(p + 1) = b;		p += 2;		goto exit;	    }	} while (!(b & 0x10));	*p = j;	*(p + 1) = b;	p += 2;	j = 0;	do	{	    b = inportb ((uint16) SW_PORT);	    if (++j > TIMEOUT)		goto exit;	} while (b & 0x10);    } while (p < pend);	    exit:    sti ();    start = 0;    strobes = 0;    for (i = 0; i < p - data; i += 2)    {	if (data [i] >= INTER_SIDEWINDER_STROBE_LEN)	{	    if (strobes == MODE_A_STROBES || strobes == MODE_B_STROBES)	    {		buttons = 0;		if (strobes == MODE_A_STROBES)		{		    for (j = 0; j < MODE_A_STROBES; j++)			buttons |= (((data [start + 1 + (j << 1)] >> 5) ^ 1) & 1) << j;		}		else		{		    for (j = 0; j < MODE_B_STROBES; j++)			buttons |= (((data [start + 1 + (j << 1)] >> 5) ^ 7) & 7) << (j * 3);		}		parity = 0;		for (j = 0; j < SW_NUM_SIDEWINDER_BUTTONS; j++)		    if (buttons & (1 << j))			parity++;		if ((parity & 1) != ((buttons >> SW_NUM_SIDEWINDER_BUTTONS) & 1))		{		    /* No partity error, update the joypad button state */		    ret.valid [ret.count] = 1;		    ret.buttons [ret.count++] = buttons & ~SW_PARITY_MASK;		}		else		    ret.valid [ret.count++] = 0;	    }	    else		ret.valid [ret.count++] = 0;	    start = i;	    strobes = 1;	}	else	    strobes++;    }    if (ret.count)    {	if (ret.count < 2)	    NumControllers = 2;	else	{	    if (ret.count > NumControllers)	    {		NumControllers = ret.count;		if (NumControllers > 5)		    NumControllers = 5;	    }	}	for (int s = 0; s < ret.count && s < 5; s++)	{	    if (ret.valid [s])	    {		for (int i = 0; i < SW_NUM_SIDEWINDER_BUTTONS; i++)		{		    if ((prev_ret.buttons [s] ^ ret.buttons [s]) & (1 << i))		    {			if (alternate_sidewinder_mapping)			{			    if (ret.buttons [s] & (1 << i))				joypads [s] |= SidewinderToSNES2 [i];			    else				joypads [s] &= ~SidewinderToSNES2 [i];			}			else			{			    if (ret.buttons [s] & (1 << i))				joypads [s] |= SidewinderToSNES [i];			    else				joypads [s] &= ~SidewinderToSNES [i];			}		    }		}		prev_ret.buttons [s] = ret.buttons [s];	    }	}    }    return (ret.count);}#endif#ifdef GRIP_SUPPORTvoid InitGrip (){    char buffer [_MAX_PATH];    FILE *fs = NULL;    const char *grip_dir = getenv ("GRIP");    uint8 *grip_library;    int size;    if (grip_dir)    {	strcpy (buffer, grip_dir);	strcat (buffer, "\\");	strcat (buffer, "GRIP.GLL");	fs = fopen (buffer, "rb");    }    if (!fs)	fs = fopen ("GRIP.GLL", "rb");    if (!fs)	fs = fopen ("C:\\GRIP\\GRIP.GLL", "rb");    if (!fs)	fs = fopen ("C:\\GRAVIS\\GRIP\\GRIP.GLL", "rb");    if (fs)    {	fseek (fs, 0, SEEK_END);	size = ftell (fs);	if (size > 32 * 1024)	{	    fclose (fs);	    return;	}	grip_library = new uint8 [size];	fseek (fs, 0, SEEK_SET);	if (fread (grip_library, 1, size, fs) != size)	{	    delete grip_library;	    fclose (fs);	    return;	}	fclose (fs);	if (!GrLink (grip_library, size))	{	    delete grip_library;	    return;	}	delete grip_library;	if (!GrInitialize ())	{	    GrUnlink ();	    return;	}	grip_initialised = TRUE;	printf ("Grip Initialised\n");    }}struct GripData{    GRIP_BITFIELD buttons;    GRIP_BITFIELD direction;};static uint32 GamePadProToSNES [10] = {    SNES_TR_MASK, SNES_TL_MASK, SNES_X_MASK, SNES_A_MASK,    SNES_Y_MASK, SNES_TL_MASK, SNES_B_MASK, SNES_TR_MASK,    SNES_START_MASK, SNES_SELECT_MASK};static uint32 GamePadProToSNESDir [4] = {    SNES_RIGHT_MASK, SNES_LEFT_MASK, SNES_UP_MASK, SNES_DOWN_MASK};static struct GripData grip_prev_data [5] = { {0, 0} };void ReadGrip (){    if (grip_initialised)    {	GrRefresh (0);	int count = 0;	int slot;	GRIP_BITFIELD connected = GrGetSlotMap ();	for (slot = 1; slot < 5; slot++)	{	    if (connected & (1 << slot))	    {		char product [17];		product [0] = 0;		GrGetProductName (slot, product);		if (strcasecmp (product, "GamePad Pro") == 0)		{		    GRIP_BITFIELD buttons;		    buttons = GrGetPackedValues (slot, GRIP_CLASS_BUTTON, 0, 9);		    int x = GrGetValue (slot, GRIP_CLASS_AXIS, 0);		    int y = GrGetValue (slot, GRIP_CLASS_AXIS, 1);		    GRIP_BITFIELD direction = 0;		    if (x > 1)			direction |= 1;		    else		    if (x < 1)			direction |= 2;		    if (y > 1)			direction |= 4;		    else		    if (y < 1)			direction |= 8;					    int i;		    for (i = 0; i < 10; i++)		    {			if ((grip_prev_data [slot].buttons ^ buttons) & (1 << i))			{			    if (buttons & (1 << i))				joypads [count] |= GamePadProToSNES [i];			    else				joypads [count] &= ~GamePadProToSNES [i];			}		    }		    for (i = 0; i < 4; i++)		    {			if ((grip_prev_data [slot].direction ^ direction) & (1 << i))			{			    if (direction & (1 << i))				joypads [count] |= GamePadProToSNESDir [i];			    else				joypads [count] &= ~GamePadProToSNESDir [i];			}		    }		    		    grip_prev_data [slot].buttons = buttons;		    grip_prev_data [slot].direction = direction;		}		else		{		}		count++;	    }	    if (count < 2)		NumControllers = 2;	    else	    if (count > NumControllers)		NumControllers = count;	}    }}#endifvoid _makepath (char *path, const char *drive, const char *dir,		const char *fname, const char *ext){    if (drive && *drive)    {	*path = *drive;	*(path + 1) = ':';	*(path + 2) = 0;    }    else	*path = 0;	    if (dir && *dir)    {	strcat (path, dir);	if (strlen (dir) != 1 || *dir != '\\')	    strcat (path, SLASH_STR);    }	    strcat (path, fname);    if (ext && *ext)    {        strcat (path, ".");        strcat (path, ext);    }}void _splitpath (const char *path, char *drive, char *dir, char *fname,		 char *ext){    if (*path && *(path + 1) == ':')    {	*drive = toupper (*path);	path += 2;    }    else	*drive = 0;    char *slash = strrchr (path, SLASH_CHAR);    if (!slash)	slash = strrchr (path, '/');    char *dot = strrchr (path, '.');    if (dot && slash && dot < slash)	dot = NULL;    if (!slash)    {	if (*drive)	    strcpy (dir, "\\");	else	    strcpy (dir, "");	strcpy (fname, path);        if (dot)        {	    *(fname + (dot - path)) = 0;	    strcpy (ext, dot + 1);        }	else	    strcpy (ext, "");    }    else    {	if (*drive && *path != '\\')	{	    strcpy (dir, "\\");	    strcat (dir, path);	    *(dir + (slash - path) + 1) = 0;	}	else	{	    strcpy (dir, path);	    if (slash - path == 0)		*(dir + 1) = 0;	    else		*(dir + (slash - path)) = 0;	}	strcpy (fname, slash + 1);        if (dot)	{	    *(fname + (dot - slash) - 1) = 0;    	    strcpy (ext, dot + 1);	}	else	    strcpy (ext, "");    }}extern volatile uint32 FrameTimer;void S9xSyncSpeed (){#ifdef NETPLAY_SUPPORT    if (Settings.NetPlay)    {	// XXX: Send joypad position update to server	// XXX: Wait for heart beat from server	S9xNetPlaySendJoypadUpdate (joypads [0]);	if (!S9xNetPlayCheckForHeartBeat ())	{	    do	    {		CHECK_SOUND ();		S9xProcessEvents (FALSE);		__dpmi_yield ();	    } while (!S9xNetPlayCheckForHeartBeat ());	    IPPU.RenderThisFrame = TRUE;	    IPPU.SkippedFrames = 0;	}	else	{	    if (IPPU.SkippedFrames < 10)	    {		IPPU.SkippedFrames++;		IPPU.RenderThisFrame = FALSE;	    }	    else	    {		IPPU.RenderThisFrame = TRUE;		IPPU.SkippedFrames = 0;	    }	}    }    else#endif    if (Settings.SkipFrames == AUTO_FRAMERATE)    {	while (FrameTimer == 0)	{	    S9xProcessEvents (FALSE);	    __dpmi_yield ();	}	if (FrameTimer > 10)	    FrameTimer = 10;	if (FrameTimer > 1 && IPPU.SkippedFrames < 10)	{	    IPPU.SkippedFrames++;	    IPPU.RenderThisFrame = FALSE;	}	else	{	    IPPU.RenderThisFrame = TRUE;	    IPPU.SkippedFrames = 0;	}	FrameTimer--;    }    else    {	if (++IPPU.FrameSkip >= Settings.SkipFrames)	{	    IPPU.FrameSkip = 0;	    IPPU.RenderThisFrame = TRUE;	    IPPU.SkippedFrames = 0;	}	else	{	    IPPU.SkippedFrames++;	    IPPU.RenderThisFrame = FALSE;	}    }}void S9xMessage (int type, int message_no, const char *str){    switch (type)    {    case S9X_ERROR:    case S9X_FATAL_ERROR:	fprintf (stderr, "%s\n", str);	return;    case S9X_TRACE:    case S9X_DEBUG:	printf ("%s\n", str);	break;    default:	switch (message_no)	{	case S9X_ROM_INFO:	case S9X_HEADERS_INFO:	case S9X_ROM_CONFUSING_FORMAT_INFO:	case S9X_ROM_INTERLEAVED_INFO:	case S9X_USAGE:	    fprintf (stderr, "%s\n", str);	    return;	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -