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

📄 sdllink.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 2 页
字号:
	}
	SDL_PauseAudio(0);

	return TRUE;
}

int ReInitSound(void)
{
	return InitSound();
}

BOOL InitJoystickInput(void)
{
    int i; int max_num_joysticks;

	for (i = 0; i < 5; i++)
		JoystickInput[i] = NULL;
	// If it is possible to use SDL_NumJoysticks
	// before initialising SDL_INIT_JOYSTICK then
	// this call can be replaced with SDL_InitSubSystem
    max_num_joysticks = SDL_NumJoysticks();
	if (!max_num_joysticks)
	{
		printf("ZSNES could not find any joysticks.\n");
		SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
		return FALSE;
	}
	SDL_JoystickEventState(SDL_ENABLE);
	if (max_num_joysticks > 5) max_num_joysticks = 5;
	for (i = 0; i < max_num_joysticks; i++)
	{
		JoystickInput[i] = SDL_JoystickOpen(i);
		printf("Joystick %i (%i Buttons): %s\n", i,
		       SDL_JoystickNumButtons(JoystickInput[i]),
		       SDL_JoystickName(i));
	}

	return TRUE;
}

BOOL InitInput()
{
	InitJoystickInput();
	return TRUE;
}

int startgame(void)
{
	int status;

	if (!sdl_inited)
	{
		if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER |
	        SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
		{
			fprintf(stderr, "Could not initialize SDL!\n");
			return FALSE;
		}
		sdl_inited = -1;
	}

	BitDepth = (UseOpenGL ? 16 : 0);

	if (sdl_inited == 1) sw_end();
#ifdef __OPENGL__
	else if (sdl_inited == 2) gl_end();

	if (UseOpenGL)
	{
		status = gl_start(WindowWidth, WindowHeight, BitDepth, FullScreen);
	}
	else
#endif
	{
		status = sw_start(WindowWidth, WindowHeight, BitDepth, FullScreen);
	}

	if (!status) return FALSE;
	sdl_inited = UseOpenGL + 1;
	return TRUE;
}

void LinuxExit(void)
{
	if (sdl_inited)
	{
		SDL_WM_GrabInput(SDL_GRAB_OFF);	// probably redundant
		SDL_Quit();
	}
	exit(0);
}

void endgame()
{
	LinuxExit();
}

int i;
int count, x, count2;
DWORD Temp1;
DWORD SurfBufD;
DWORD CurrentPos;
DWORD WritePos;
DWORD SoundBufD;
DWORD SoundBufD2;
DWORD T60HZEnabled = 0;
DWORD T36HZEnabled = 0;
short *Sound;

//void WinUpdateDevices(); function removed since it was empty
extern unsigned char romispal;

void Start60HZ(void)
{
	update_ticks_pc2 = UPDATE_TICKS_UDP;
	if (romispal == 1)
	{
		update_ticks_pc = UPDATE_TICKS_GAMEPAL;
	}
	else
	{
		update_ticks_pc = UPDATE_TICKS_GAME;
	}

	start = SDL_GetTicks();
	start2 = SDL_GetTicks();
	//   QueryPerformanceCounter((LARGE_INTEGER*)&start);
	//   QueryPerformanceCounter((LARGE_INTEGER*)&start2);
	T36HZEnabled = 0;
	T60HZEnabled = 1;
}

void Stop60HZ(void)
{
	T60HZEnabled = 0;
}

void Start36HZ(void)
{
	update_ticks_pc2 = UPDATE_TICKS_UDP;
	update_ticks_pc = UPDATE_TICKS_GUI;
	//   QueryPerformanceCounter((LARGE_INTEGER*)&start);
	//   QueryPerformanceCounter((LARGE_INTEGER*)&start2);

	start = SDL_GetTicks();
	start2 = SDL_GetTicks();
	T60HZEnabled = 0;
	T36HZEnabled = 1;
}

void Stop36HZ(void)
{
	T36HZEnabled = 0;
}

DWORD FirstVid = 1;
DWORD FirstFull = 1;
extern BYTE GUIWFVID[];
extern BYTE GrayscaleMode;
extern BYTE V8Mode;
void clearwin();

void initwinvideo(void)
{
	DWORD newmode = 0;

	V8Mode = (GrayscaleMode == 1);

	if (CurMode != cvidmode)
	{
		CurMode = cvidmode;
		newmode = 1;
		WindowWidth = 256;
		WindowHeight = 224;

		FullScreen = GUIWFVID[cvidmode];
#ifdef __OPENGL__
		UseOpenGL = 0;
		if (cvidmode > 3)
		   UseOpenGL = 1;
#else
		if (cvidmode > 3)
		  cvidmode = 2; // set it to the default 512x448 W
#endif

		switch (cvidmode)
		{
			//case 0:
			default:
				WindowWidth = 256;
				WindowHeight = 224;
				break;
			case 1:
				WindowWidth = 320;
				WindowHeight = 240;
				break;
			case 2:
			case 5:
			case 13:
				WindowWidth = 512;
				WindowHeight = 448;
				break;
			case 3:
			case 6:
			case 16:
				WindowWidth = 640;
				WindowHeight = 480;
				break;
			case 7:
				WindowWidth = 640;
				WindowHeight = 576;
				break;
			case 8:
				WindowWidth = 768;
				WindowHeight = 672;
				break;
			case 9:
				WindowWidth = 896;
				WindowHeight = 784;
				break;
			case 10:
				WindowWidth = 1024;
				WindowHeight = 896;
				break;
			case 11:
			case 14:
				WindowWidth = 800;
				WindowHeight = 600;
				break;
			case 12:
			case 15:
				WindowWidth = 1024;
				WindowHeight = 768;
				break;
		}
		adjustMouseXScale();
		adjustMouseYScale();
	}

	if (startgame() != TRUE)
	{
		return;
	}

	if (newmode == 1)
		clearwin();

	if (FirstVid == 1)
	{
		FirstVid = 0;

		InitSound();
		InitInput();
	}

	if (((PrevStereoSound != StereoSound)
	     || (PrevSoundQuality != SoundQuality)))
		ReInitSound();
}

extern int DSPBuffer[];
extern int packettimeleft[256];
extern int PacketCounter;
extern int CounterA;
extern int CounterB;
extern void SoundProcess();
extern int GUI36hzcall(void);
extern int Game60hzcall(void);

void CheckTimers(void)
{
	int i;

	//QueryPerformanceCounter((LARGE_INTEGER*)&end2);
	end2 = SDL_GetTicks();

	while ((end2 - start2) >= update_ticks_pc2)
	{
		if (CounterA > 0)
			CounterA--;
		if (CounterB > 0)
			CounterB--;
		if (PacketCounter)
		{
			for (i = 0; i < 256; i++)
			{
				if (packettimeleft[i] > 0)
					packettimeleft[i]--;
			}
		}
		start2 += update_ticks_pc2;
	}

	if (T60HZEnabled)
	{
		//QueryPerformanceCounter((LARGE_INTEGER*)&end);
		end = SDL_GetTicks();

		while ((end - start) >= update_ticks_pc)
		{
			/*
			   _asm{
			   pushad
			   call Game60hzcall
			   popad
			   }
			 */
			Game60hzcall();
			start += update_ticks_pc;
		}
	}

	if (T36HZEnabled)
	{
		//QueryPerformanceCounter((LARGE_INTEGER*)&end);
		end = SDL_GetTicks();

		while ((end - start) >= update_ticks_pc)
		{
			/*
			   _asm{
			   pushad
			   call GUI36hzcall
			   popad
			   }
			 */
			GUI36hzcall();
			start += update_ticks_pc;
		}
	}
}

/* should we clear these on sound reset? */
DWORD BufferLeftOver = 0;
short Buffer[1800 * 2];

void UpdateSound(void *userdata, Uint8 * stream, int len)
{
	const int SPCSize = 256;
	int DataNeeded;
	int i;
	Uint8 *ptr;

	len /= 2;		/* only 16bit here */

	ptr = stream;
	DataNeeded = len;

	/* take care of the things we left behind last time */
	if (BufferLeftOver)
	{
		DataNeeded -= BufferLeftOver;

		memcpy(ptr, &Buffer[BufferLeftOver],
		       (SPCSize - BufferLeftOver) * 2);

		ptr += (SPCSize - BufferLeftOver) * 2;
		BufferLeftOver = 0;
	}

	if (len & 255)
	{			/* we'll save the rest first */
		DataNeeded -= 256;
	}

	while (DataNeeded > 0)
	{
		SoundProcess();

		for (i = 0; i < SPCSize; i++)
		{
			if (T36HZEnabled)
			{
				Buffer[i] = 0;
			}
			else
			{
				if (DSPBuffer[i] > 32767)
					Buffer[i] = 32767;
				else if (DSPBuffer[i] < -32767)
					Buffer[i] = -32767;
				else
					Buffer[i] = DSPBuffer[i];
			}
		}

		memcpy(ptr, &Buffer[0], SPCSize * 2);
		ptr += SPCSize * 2;

		DataNeeded -= SPCSize;
	}

	if (DataNeeded)
	{
		DataNeeded += 256;
		BufferLeftOver = DataNeeded;

		SoundProcess();

		for (i = 0; i < SPCSize; i++)
		{
			if (T36HZEnabled)
			{
				Buffer[i] = 0;
			}
			else
			{
				if (DSPBuffer[i] > 32767)
					Buffer[i] = 32767;
				else if (DSPBuffer[i] < -32767)
					Buffer[i] = -32767;
				else
					Buffer[i] = DSPBuffer[i];
			}
		}

		memcpy(ptr, &Buffer[0], DataNeeded * 2);
	}
}

void UpdateVFrame(void)
{
	/* rcg06172001 get menu animations running correctly... */
	/*if (GUIOn2 == 1 && IsActivated == 0) SDL_WaitEvent(NULL);*/
	if (GUIOn2 == 1 && IsActivated == 0)
		SDL_Delay(100);  /* spare the CPU a little. */

	CheckTimers();
	Main_Proc();
}

void clearwin()
{
	if (!sdl_inited) return;

#ifdef __OPENGL__
	if (UseOpenGL)
		gl_clearwin();
	else
#endif
		sw_clearwin();
}

void drawscreenwin(void)
{
#ifdef __OPENGL__
	if (UseOpenGL)
		gl_drawwin();
	else
#endif
		sw_drawwin();
}

int GetMouseX(void)
{
	return ((int) MouseX);
}
int GetMouseY(void)
{
	return ((int) MouseY);
}

int GetMouseMoveX(void)
{
	//   InputRead();
	//SDL_GetRelativeMouseState(&MouseMove2X, NULL);
	SDL_GetRelativeMouseState(&MouseMove2X, &MouseMove2Y);
	return (MouseMove2X);
}

int GetMouseMoveY(void)
{
	return (MouseMove2Y);
}
int GetMouseButton(void)
{
	return ((int) MouseButton);
}

void SetMouseMinX(int MinX)
{
	MouseMinX = MinX;
	adjustMouseXScale();
}
void SetMouseMaxX(int MaxX)
{
	MouseMaxX = MaxX;
	adjustMouseXScale();
}
void SetMouseMinY(int MinY)
{
	MouseMinY = MinY;
	adjustMouseYScale();
}
void SetMouseMaxY(int MaxY)
{
	MouseMaxY = MaxY;
	adjustMouseYScale();
}

// we can probably get rid of these functions since they are no
// longer called in sdlintrf.asm
void SetMouseX(int X)
{				/* MouseX=X; */
}
void SetMouseY(int Y)
{				/* MouseY=Y; */
}

void ZsnesPage()
{
	system("netscape -remote 'openURL(http://www.zsnes.com/)'");
}

short SystemTimewHour;
short SystemTimewMinute;
short SystemTimewSecond;

void GetLocalTime()
{
	time_t current;
	struct tm *timeptr;

	time(&current);
	timeptr = localtime(&current);
	SystemTimewHour = timeptr->tm_hour;
	SystemTimewMinute = timeptr->tm_min;
	SystemTimewSecond = timeptr->tm_sec;
}

⌨️ 快捷键说明

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