sdl: code cleanup; pre-release code review (in progress)
This commit is contained in:
parent
118b82544c
commit
b0c2758324
|
@ -5,10 +5,10 @@
|
||||||
|
|
||||||
#define MAXBUTTCONFIG 4
|
#define MAXBUTTCONFIG 4
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8 ButtType[MAXBUTTCONFIG];
|
uint8 ButtType[MAXBUTTCONFIG];
|
||||||
uint8 DeviceNum[MAXBUTTCONFIG];
|
uint8 DeviceNum[MAXBUTTCONFIG];
|
||||||
uint16 ButtonNum[MAXBUTTCONFIG];
|
uint16 ButtonNum[MAXBUTTCONFIG];
|
||||||
uint32 NumC;
|
uint32 NumC;
|
||||||
//uint64 DeviceID[MAXBUTTCONFIG]; /* TODO */
|
//uint64 DeviceID[MAXBUTTCONFIG]; /* TODO */
|
||||||
} ButtConfig;
|
} ButtConfig;
|
||||||
|
|
||||||
|
@ -54,5 +54,5 @@ void InputCfg(const std::string &);
|
||||||
|
|
||||||
std::string GetUserText(const char* title);
|
std::string GetUserText(const char* title);
|
||||||
const char* ButtonName(const ButtConfig* bc, int which);
|
const char* ButtonName(const ButtConfig* bc, int which);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -41,36 +41,35 @@ static int s_jinited = 0;
|
||||||
int
|
int
|
||||||
DTestButtonJoy(ButtConfig *bc)
|
DTestButtonJoy(ButtConfig *bc)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
for(x = 0; x < bc->NumC; x++)
|
for(x = 0; x < bc->NumC; x++)
|
||||||
{
|
{
|
||||||
if(bc->ButtonNum[x] & 0x2000)
|
if(bc->ButtonNum[x] & 0x2000)
|
||||||
{
|
{
|
||||||
/* Hat "button" */
|
/* Hat "button" */
|
||||||
if(SDL_JoystickGetHat(s_Joysticks[bc->DeviceNum[x]],
|
if(SDL_JoystickGetHat(s_Joysticks[bc->DeviceNum[x]],
|
||||||
((bc->ButtonNum[x] >> 8) & 0x1F)) &
|
((bc->ButtonNum[x] >> 8) & 0x1F)) &
|
||||||
(bc->ButtonNum[x]&0xFF))
|
(bc->ButtonNum[x]&0xFF))
|
||||||
return(1);
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(bc->ButtonNum[x] & 0x8000)
|
else if(bc->ButtonNum[x] & 0x8000)
|
||||||
{
|
{
|
||||||
/* Axis "button" */
|
/* Axis "button" */
|
||||||
int pos;
|
int pos;
|
||||||
pos = SDL_JoystickGetAxis(s_Joysticks[bc->DeviceNum[x]],
|
pos = SDL_JoystickGetAxis(s_Joysticks[bc->DeviceNum[x]],
|
||||||
bc->ButtonNum[x] & 16383);
|
bc->ButtonNum[x] & 16383);
|
||||||
if ((bc->ButtonNum[x] & 0x4000) && pos <= -16383) {
|
if ((bc->ButtonNum[x] & 0x4000) && pos <= -16383) {
|
||||||
return(1);
|
return 1;
|
||||||
} else if (!(bc->ButtonNum[x] & 0x4000) && pos >= 16363) {
|
} else if (!(bc->ButtonNum[x] & 0x4000) && pos >= 16363) {
|
||||||
return(1);
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(SDL_JoystickGetButton(s_Joysticks[bc->DeviceNum[x]],
|
else if(SDL_JoystickGetButton(s_Joysticks[bc->DeviceNum[x]],
|
||||||
bc->ButtonNum[x]))
|
bc->ButtonNum[x]))
|
||||||
return(1);
|
return 1;
|
||||||
}
|
}
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,20 +78,20 @@ DTestButtonJoy(ButtConfig *bc)
|
||||||
int
|
int
|
||||||
KillJoysticks()
|
KillJoysticks()
|
||||||
{
|
{
|
||||||
int n; /* joystick index */
|
int n; /* joystick index */
|
||||||
|
|
||||||
if(!s_jinited) {
|
if(!s_jinited) {
|
||||||
return(-1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(n = 0; n < MAX_JOYSTICKS; n++) {
|
for(n = 0; n < MAX_JOYSTICKS; n++) {
|
||||||
if (s_Joysticks[n] != 0) {
|
if (s_Joysticks[n] != 0) {
|
||||||
SDL_JoystickClose(s_Joysticks[n]);
|
SDL_JoystickClose(s_Joysticks[n]);
|
||||||
}
|
}
|
||||||
s_Joysticks[n]=0;
|
s_Joysticks[n]=0;
|
||||||
}
|
}
|
||||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,24 +100,24 @@ KillJoysticks()
|
||||||
int
|
int
|
||||||
InitJoysticks()
|
InitJoysticks()
|
||||||
{
|
{
|
||||||
int n; /* joystick index */
|
int n; /* joystick index */
|
||||||
int total;
|
int total;
|
||||||
|
|
||||||
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
|
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
|
||||||
|
|
||||||
total = SDL_NumJoysticks();
|
total = SDL_NumJoysticks();
|
||||||
if(total>MAX_JOYSTICKS) {
|
if(total>MAX_JOYSTICKS) {
|
||||||
total = MAX_JOYSTICKS;
|
total = MAX_JOYSTICKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(n = 0; n < total; n++) {
|
for(n = 0; n < total; n++) {
|
||||||
/* Open the joystick under SDL. */
|
/* Open the joystick under SDL. */
|
||||||
s_Joysticks[n] = SDL_JoystickOpen(n);
|
s_Joysticks[n] = SDL_JoystickOpen(n);
|
||||||
//printf("Could not open joystick %d: %s.\n",
|
//printf("Could not open joystick %d: %s.\n",
|
||||||
//joy[n] - 1, SDL_GetError());
|
//joy[n] - 1, SDL_GetError());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_jinited = 1;
|
s_jinited = 1;
|
||||||
return(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@ static void *HiBuffer;
|
||||||
|
|
||||||
typedef void APIENTRY (*glBindTexture_Func)(GLenum target,GLuint texture);
|
typedef void APIENTRY (*glBindTexture_Func)(GLenum target,GLuint texture);
|
||||||
typedef void APIENTRY (*glColorTableEXT_Func)(GLenum target,
|
typedef void APIENTRY (*glColorTableEXT_Func)(GLenum target,
|
||||||
GLenum internalformat, GLsizei width, GLenum format, GLenum type,
|
GLenum internalformat, GLsizei width, GLenum format, GLenum type,
|
||||||
const GLvoid *table);
|
const GLvoid *table);
|
||||||
typedef void APIENTRY (*glTexImage2D_Func)(GLenum target, GLint level,
|
typedef void APIENTRY (*glTexImage2D_Func)(GLenum target, GLint level,
|
||||||
GLint internalFormat,
|
GLint internalFormat,
|
||||||
GLsizei width, GLsizei height, GLint border,
|
GLsizei width, GLsizei height, GLint border,
|
||||||
GLenum format, GLenum type,
|
GLenum format, GLenum type,
|
||||||
const GLvoid *pixels);
|
const GLvoid *pixels);
|
||||||
typedef void APIENTRY (*glBegin_Func)(GLenum mode);
|
typedef void APIENTRY (*glBegin_Func)(GLenum mode);
|
||||||
typedef void APIENTRY (*glVertex2f_Func)(GLfloat x, GLfloat y);
|
typedef void APIENTRY (*glVertex2f_Func)(GLfloat x, GLfloat y);
|
||||||
typedef void APIENTRY (*glTexCoord2f_Func)(GLfloat s, GLfloat t);
|
typedef void APIENTRY (*glTexCoord2f_Func)(GLfloat s, GLfloat t);
|
||||||
|
@ -43,14 +43,14 @@ typedef void APIENTRY (*glEnable_Func)(GLenum cap);
|
||||||
typedef void APIENTRY (*glBlendFunc_Func)(GLenum sfactor, GLenum dfactor);
|
typedef void APIENTRY (*glBlendFunc_Func)(GLenum sfactor, GLenum dfactor);
|
||||||
typedef const GLubyte* APIENTRY (*glGetString_Func)(GLenum name);
|
typedef const GLubyte* APIENTRY (*glGetString_Func)(GLenum name);
|
||||||
typedef void APIENTRY (*glViewport_Func)(GLint x, GLint y,GLsizei width,
|
typedef void APIENTRY (*glViewport_Func)(GLint x, GLint y,GLsizei width,
|
||||||
GLsizei height);
|
GLsizei height);
|
||||||
typedef void APIENTRY (*glGenTextures_Func)(GLsizei n, GLuint *textures);
|
typedef void APIENTRY (*glGenTextures_Func)(GLsizei n, GLuint *textures);
|
||||||
typedef void APIENTRY (*glDeleteTextures_Func)(GLsizei n,
|
typedef void APIENTRY (*glDeleteTextures_Func)(GLsizei n,
|
||||||
const GLuint *textures);
|
const GLuint *textures);
|
||||||
typedef void APIENTRY (*glTexParameteri_Func)(GLenum target, GLenum pname,
|
typedef void APIENTRY (*glTexParameteri_Func)(GLenum target, GLenum pname,
|
||||||
GLint param);
|
GLint param);
|
||||||
typedef void APIENTRY (*glClearColor_Func)(GLclampf red, GLclampf green,
|
typedef void APIENTRY (*glClearColor_Func)(GLclampf red, GLclampf green,
|
||||||
GLclampf blue, GLclampf alpha);
|
GLclampf blue, GLclampf alpha);
|
||||||
typedef void APIENTRY (*glLoadIdentity_Func)(void);
|
typedef void APIENTRY (*glLoadIdentity_Func)(void);
|
||||||
typedef void APIENTRY (*glClear_Func)(GLbitfield mask);
|
typedef void APIENTRY (*glClear_Func)(GLbitfield mask);
|
||||||
typedef void APIENTRY (*glMatrixMode_Func)(GLenum mode);
|
typedef void APIENTRY (*glMatrixMode_Func)(GLenum mode);
|
||||||
|
@ -78,216 +78,216 @@ glDisable_Func p_glDisable;
|
||||||
void
|
void
|
||||||
SetOpenGLPalette(uint8 *data)
|
SetOpenGLPalette(uint8 *data)
|
||||||
{
|
{
|
||||||
if(!HiBuffer) {
|
if(!HiBuffer) {
|
||||||
p_glBindTexture(GL_TEXTURE_2D, textures[0]);
|
p_glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||||
p_glColorTableEXT(GL_TEXTURE_2D, GL_RGB, 256,
|
p_glColorTableEXT(GL_TEXTURE_2D, GL_RGB, 256,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, data);
|
GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
} else {
|
} else {
|
||||||
SetPaletteBlitToHigh((uint8*)data);
|
SetPaletteBlitToHigh((uint8*)data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BlitOpenGL(uint8 *buf)
|
BlitOpenGL(uint8 *buf)
|
||||||
{
|
{
|
||||||
p_glClear(GL_COLOR_BUFFER_BIT);
|
p_glClear(GL_COLOR_BUFFER_BIT);
|
||||||
p_glBindTexture(GL_TEXTURE_2D, textures[0]);
|
p_glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||||
if(HiBuffer) {
|
if(HiBuffer) {
|
||||||
Blit8ToHigh(buf, (uint8*)HiBuffer, 256, 240, 256*4, 1, 1);
|
Blit8ToHigh(buf, (uint8*)HiBuffer, 256, 240, 256*4, 1, 1);
|
||||||
|
|
||||||
p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0,
|
p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, HiBuffer);
|
GL_RGBA, GL_UNSIGNED_BYTE, HiBuffer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//glPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
|
//glPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
|
||||||
p_glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0,
|
p_glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0,
|
||||||
GL_COLOR_INDEX,GL_UNSIGNED_BYTE,buf);
|
GL_COLOR_INDEX,GL_UNSIGNED_BYTE,buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
p_glBegin(GL_QUADS);
|
p_glBegin(GL_QUADS);
|
||||||
p_glTexCoord2f(1.0f*left/256, 1.0f*bottom/256); // Bottom left of picture.
|
p_glTexCoord2f(1.0f*left/256, 1.0f*bottom/256); // Bottom left of picture.
|
||||||
p_glVertex2f(-1.0f, -1.0f); // Bottom left of target.
|
p_glVertex2f(-1.0f, -1.0f); // Bottom left of target.
|
||||||
|
|
||||||
p_glTexCoord2f(1.0f*right/256, 1.0f*bottom/256);// Bottom right of picture.
|
p_glTexCoord2f(1.0f*right/256, 1.0f*bottom/256);// Bottom right of picture.
|
||||||
p_glVertex2f( 1.0f, -1.0f); // Bottom right of target.
|
p_glVertex2f( 1.0f, -1.0f); // Bottom right of target.
|
||||||
|
|
||||||
p_glTexCoord2f(1.0f*right/256, 1.0f*top/256); // Top right of our picture.
|
p_glTexCoord2f(1.0f*right/256, 1.0f*top/256); // Top right of our picture.
|
||||||
p_glVertex2f( 1.0f, 1.0f); // Top right of target.
|
p_glVertex2f( 1.0f, 1.0f); // Top right of target.
|
||||||
|
|
||||||
p_glTexCoord2f(1.0f*left/256, 1.0f*top/256); // Top left of our picture.
|
p_glTexCoord2f(1.0f*left/256, 1.0f*top/256); // Top left of our picture.
|
||||||
p_glVertex2f(-1.0f, 1.0f); // Top left of target.
|
p_glVertex2f(-1.0f, 1.0f); // Top left of target.
|
||||||
p_glEnd();
|
p_glEnd();
|
||||||
|
|
||||||
//glDisable(GL_BLEND);
|
//glDisable(GL_BLEND);
|
||||||
if(scanlines) {
|
if(scanlines) {
|
||||||
p_glEnable(GL_BLEND);
|
p_glEnable(GL_BLEND);
|
||||||
|
|
||||||
p_glBindTexture(GL_TEXTURE_2D, textures[1]);
|
p_glBindTexture(GL_TEXTURE_2D, textures[1]);
|
||||||
p_glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
|
p_glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
|
||||||
|
|
||||||
p_glBegin(GL_QUADS);
|
p_glBegin(GL_QUADS);
|
||||||
|
|
||||||
p_glTexCoord2f(1.0f*left/256,
|
p_glTexCoord2f(1.0f*left/256,
|
||||||
1.0f*bottom/256); // Bottom left of our picture.
|
1.0f*bottom/256); // Bottom left of our picture.
|
||||||
p_glVertex2f(-1.0f, -1.0f); // Bottom left of target.
|
p_glVertex2f(-1.0f, -1.0f); // Bottom left of target.
|
||||||
|
|
||||||
p_glTexCoord2f(1.0f*right/256,
|
p_glTexCoord2f(1.0f*right/256,
|
||||||
1.0f*bottom/256); // Bottom right of our picture.
|
1.0f*bottom/256); // Bottom right of our picture.
|
||||||
p_glVertex2f( 1.0f, -1.0f); // Bottom right of target.
|
p_glVertex2f( 1.0f, -1.0f); // Bottom right of target.
|
||||||
|
|
||||||
p_glTexCoord2f(1.0f*right/256,
|
p_glTexCoord2f(1.0f*right/256,
|
||||||
1.0f*top/256); // Top right of our picture.
|
1.0f*top/256); // Top right of our picture.
|
||||||
p_glVertex2f( 1.0f, 1.0f); // Top right of target.
|
p_glVertex2f( 1.0f, 1.0f); // Top right of target.
|
||||||
|
|
||||||
p_glTexCoord2f(1.0f*left/256,
|
p_glTexCoord2f(1.0f*left/256,
|
||||||
1.0f*top/256); // Top left of our picture.
|
1.0f*top/256); // Top left of our picture.
|
||||||
p_glVertex2f(-1.0f, 1.0f); // Top left of target.
|
p_glVertex2f(-1.0f, 1.0f); // Top left of target.
|
||||||
|
|
||||||
p_glEnd();
|
p_glEnd();
|
||||||
p_glDisable(GL_BLEND);
|
p_glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
KillOpenGL(void)
|
KillOpenGL(void)
|
||||||
{
|
{
|
||||||
if(textures[0]) {
|
if(textures[0]) {
|
||||||
p_glDeleteTextures(2, &textures[0]);
|
p_glDeleteTextures(2, &textures[0]);
|
||||||
}
|
}
|
||||||
textures[0]=0;
|
textures[0]=0;
|
||||||
if(HiBuffer) {
|
if(HiBuffer) {
|
||||||
free(HiBuffer);
|
free(HiBuffer);
|
||||||
HiBuffer=0;
|
HiBuffer=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Rectangle, left, right(not inclusive), top, bottom(not inclusive). */
|
/* Rectangle, left, right(not inclusive), top, bottom(not inclusive). */
|
||||||
|
|
||||||
int
|
int
|
||||||
InitOpenGL(int l,
|
InitOpenGL(int l,
|
||||||
int r,
|
int r,
|
||||||
int t,
|
int t,
|
||||||
int b,
|
int b,
|
||||||
double xscale,
|
double xscale,
|
||||||
double yscale,
|
double yscale,
|
||||||
int efx,
|
int efx,
|
||||||
int ipolate,
|
int ipolate,
|
||||||
int stretchx,
|
int stretchx,
|
||||||
int stretchy,
|
int stretchy,
|
||||||
SDL_Surface *screen)
|
SDL_Surface *screen)
|
||||||
{
|
{
|
||||||
const char *extensions;
|
const char *extensions;
|
||||||
|
|
||||||
#define LFG(x) if(!(p_##x = (x##_Func) SDL_GL_GetProcAddress(#x))) return(0);
|
#define LFG(x) if(!(p_##x = (x##_Func) SDL_GL_GetProcAddress(#x))) return(0);
|
||||||
|
|
||||||
#define LFGN(x) p_##x = (x##_Func) SDL_GL_GetProcAddress(#x)
|
#define LFGN(x) p_##x = (x##_Func) SDL_GL_GetProcAddress(#x)
|
||||||
|
|
||||||
LFG(glBindTexture);
|
LFG(glBindTexture);
|
||||||
LFGN(glColorTableEXT);
|
LFGN(glColorTableEXT);
|
||||||
LFG(glTexImage2D);
|
LFG(glTexImage2D);
|
||||||
LFG(glBegin);
|
LFG(glBegin);
|
||||||
LFG(glVertex2f);
|
LFG(glVertex2f);
|
||||||
LFG(glTexCoord2f);
|
LFG(glTexCoord2f);
|
||||||
LFG(glEnd);
|
LFG(glEnd);
|
||||||
LFG(glEnable);
|
LFG(glEnable);
|
||||||
LFG(glBlendFunc);
|
LFG(glBlendFunc);
|
||||||
LFG(glGetString);
|
LFG(glGetString);
|
||||||
LFG(glViewport);
|
LFG(glViewport);
|
||||||
LFG(glGenTextures);
|
LFG(glGenTextures);
|
||||||
LFG(glDeleteTextures);
|
LFG(glDeleteTextures);
|
||||||
LFG(glTexParameteri);
|
LFG(glTexParameteri);
|
||||||
LFG(glClearColor);
|
LFG(glClearColor);
|
||||||
LFG(glLoadIdentity);
|
LFG(glLoadIdentity);
|
||||||
LFG(glClear);
|
LFG(glClear);
|
||||||
LFG(glMatrixMode);
|
LFG(glMatrixMode);
|
||||||
LFG(glDisable);
|
LFG(glDisable);
|
||||||
|
|
||||||
left=l;
|
left=l;
|
||||||
right=r;
|
right=r;
|
||||||
top=t;
|
top=t;
|
||||||
bottom=b;
|
bottom=b;
|
||||||
|
|
||||||
HiBuffer=0;
|
HiBuffer=0;
|
||||||
|
|
||||||
extensions=(const char*)p_glGetString(GL_EXTENSIONS);
|
extensions=(const char*)p_glGetString(GL_EXTENSIONS);
|
||||||
|
|
||||||
if((efx&2) || !extensions || !p_glColorTableEXT || !strstr(extensions,"GL_EXT_paletted_texture"))
|
if((efx&2) || !extensions || !p_glColorTableEXT || !strstr(extensions,"GL_EXT_paletted_texture"))
|
||||||
{
|
{
|
||||||
if(!(efx&2)) // Don't want to print out a warning message in this case...
|
if(!(efx&2)) // Don't want to print out a warning message in this case...
|
||||||
FCEU_printf("Paletted texture extension not found. Using slower texture format...\n");
|
FCEU_printf("Paletted texture extension not found. Using slower texture format...\n");
|
||||||
HiBuffer=FCEU_malloc(4*256*256);
|
HiBuffer=FCEU_malloc(4*256*256);
|
||||||
memset(HiBuffer,0x00,4*256*256);
|
memset(HiBuffer,0x00,4*256*256);
|
||||||
#ifndef LSB_FIRST
|
#ifndef LSB_FIRST
|
||||||
InitBlitToHigh(4,0xFF000000,0xFF0000,0xFF00,efx&2,0,0);
|
InitBlitToHigh(4,0xFF000000,0xFF0000,0xFF00,efx&2,0,0);
|
||||||
#else
|
#else
|
||||||
InitBlitToHigh(4,0xFF,0xFF00,0xFF0000,efx&2,0,0);
|
InitBlitToHigh(4,0xFF,0xFF00,0xFF0000,efx&2,0,0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(screen->flags & SDL_FULLSCREEN)
|
if(screen->flags & SDL_FULLSCREEN)
|
||||||
{
|
{
|
||||||
xscale=(double)screen->w / (double)(r-l);
|
xscale=(double)screen->w / (double)(r-l);
|
||||||
yscale=(double)screen->h / (double)(b-t);
|
yscale=(double)screen->h / (double)(b-t);
|
||||||
if(xscale<yscale) yscale = xscale;
|
if(xscale<yscale) yscale = xscale;
|
||||||
if(yscale<xscale) xscale = yscale;
|
if(yscale<xscale) xscale = yscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
int rw=(int)((r-l)*xscale);
|
int rw=(int)((r-l)*xscale);
|
||||||
int rh=(int)((b-t)*yscale);
|
int rh=(int)((b-t)*yscale);
|
||||||
int sx=(screen->w-rw)/2; // Start x
|
int sx=(screen->w-rw)/2; // Start x
|
||||||
int sy=(screen->h-rh)/2; // Start y
|
int sy=(screen->h-rh)/2; // Start y
|
||||||
|
|
||||||
if(stretchx) { sx=0; rw=screen->w; }
|
if(stretchx) { sx=0; rw=screen->w; }
|
||||||
if(stretchy) { sy=0; rh=screen->h; }
|
if(stretchy) { sy=0; rh=screen->h; }
|
||||||
p_glViewport(sx, sy, rw, rh);
|
p_glViewport(sx, sy, rw, rh);
|
||||||
}
|
}
|
||||||
p_glGenTextures(2, &textures[0]);
|
p_glGenTextures(2, &textures[0]);
|
||||||
scanlines=0;
|
scanlines=0;
|
||||||
|
|
||||||
if(efx&1)
|
if(efx&1)
|
||||||
{
|
{
|
||||||
uint8 *buf;
|
uint8 *buf;
|
||||||
int x,y;
|
int x,y;
|
||||||
|
|
||||||
scanlines=1;
|
scanlines=1;
|
||||||
|
|
||||||
p_glBindTexture(GL_TEXTURE_2D, textures[1]);
|
p_glBindTexture(GL_TEXTURE_2D, textures[1]);
|
||||||
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
||||||
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
||||||
|
|
||||||
buf=(uint8*)FCEU_dmalloc(256*(256*2)*4);
|
buf=(uint8*)FCEU_dmalloc(256*(256*2)*4);
|
||||||
|
|
||||||
for(y=0;y<(256*2);y++)
|
for(y=0;y<(256*2);y++)
|
||||||
for(x=0;x<256;x++)
|
for(x=0;x<256;x++)
|
||||||
{
|
{
|
||||||
buf[y*256*4+x*4]=0;
|
buf[y*256*4+x*4]=0;
|
||||||
buf[y*256*4+x*4+1]=0;
|
buf[y*256*4+x*4+1]=0;
|
||||||
buf[y*256*4+x*4+2]=0;
|
buf[y*256*4+x*4+2]=0;
|
||||||
buf[y*256*4+x*4+3]=(y&1)?0x00:0xFF; //?0xa0:0xFF; // <-- Pretty
|
buf[y*256*4+x*4+3]=(y&1)?0x00:0xFF; //?0xa0:0xFF; // <-- Pretty
|
||||||
//buf[y*256+x]=(y&1)?0x00:0xFF;
|
//buf[y*256+x]=(y&1)?0x00:0xFF;
|
||||||
}
|
}
|
||||||
p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, (scanlines==2)?256*4:512, 0,
|
p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, (scanlines==2)?256*4:512, 0,
|
||||||
GL_RGBA,GL_UNSIGNED_BYTE,buf);
|
GL_RGBA,GL_UNSIGNED_BYTE,buf);
|
||||||
FCEU_dfree(buf);
|
FCEU_dfree(buf);
|
||||||
}
|
}
|
||||||
p_glBindTexture(GL_TEXTURE_2D, textures[0]);
|
p_glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||||
|
|
||||||
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
||||||
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
||||||
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
|
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
|
||||||
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
|
p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
|
||||||
p_glEnable(GL_TEXTURE_2D);
|
p_glEnable(GL_TEXTURE_2D);
|
||||||
p_glDisable(GL_DEPTH_TEST);
|
p_glDisable(GL_DEPTH_TEST);
|
||||||
p_glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Background color to black.
|
p_glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Background color to black.
|
||||||
p_glMatrixMode(GL_MODELVIEW);
|
p_glMatrixMode(GL_MODELVIEW);
|
||||||
p_glLoadIdentity();
|
p_glLoadIdentity();
|
||||||
|
|
||||||
// In a double buffered setup with page flipping, be sure to clear both buffers.
|
// In a double buffered setup with page flipping, be sure to clear both buffers.
|
||||||
p_glClear(GL_COLOR_BUFFER_BIT);
|
p_glClear(GL_COLOR_BUFFER_BIT);
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
p_glClear(GL_COLOR_BUFFER_BIT);
|
p_glClear(GL_COLOR_BUFFER_BIT);
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
|
|
||||||
return(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,5 @@ void SetOpenGLPalette(uint8 *data);
|
||||||
void BlitOpenGL(uint8 *buf);
|
void BlitOpenGL(uint8 *buf);
|
||||||
void KillOpenGL(void);
|
void KillOpenGL(void);
|
||||||
int InitOpenGL(int l, int r, int t, int b, double xscale,double yscale, int efx, int ipolate,
|
int InitOpenGL(int l, int r, int t, int b, double xscale,double yscale, int efx, int ipolate,
|
||||||
int stretchx, int stretchy, SDL_Surface *screen);
|
int stretchx, int stretchy, SDL_Surface *screen);
|
||||||
|
|
||||||
|
|
|
@ -46,29 +46,25 @@ static int s_mute = 0;
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
fillaudio(void *udata,
|
fillaudio(void *udata,
|
||||||
uint8 *stream,
|
uint8 *stream,
|
||||||
int len)
|
int len)
|
||||||
{
|
{
|
||||||
int16 *tmps = (int16*)stream;
|
int16 *tmps = (int16*)stream;
|
||||||
len >>= 1;
|
len >>= 1;
|
||||||
// debug code
|
while(len) {
|
||||||
//printf("s_BufferIn: %i s_BufferWrite = %i s_BufferRead = %i s_BufferSize = %i\n",
|
int16 sample = 0;
|
||||||
// s_BufferIn, s_BufferWrite, s_BufferRead, s_BufferSize);
|
if(s_BufferIn) {
|
||||||
|
sample = s_Buffer[s_BufferRead];
|
||||||
|
s_BufferRead = (s_BufferRead + 1) % s_BufferSize;
|
||||||
|
s_BufferIn--;
|
||||||
|
} else {
|
||||||
|
sample = 0;
|
||||||
|
}
|
||||||
|
|
||||||
while(len) {
|
*tmps = sample;
|
||||||
int16 sample = 0;
|
tmps++;
|
||||||
if(s_BufferIn) {
|
len--;
|
||||||
sample = s_Buffer[s_BufferRead];
|
}
|
||||||
s_BufferRead = (s_BufferRead + 1) % s_BufferSize;
|
|
||||||
s_BufferIn--;
|
|
||||||
} else {
|
|
||||||
sample = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
*tmps = sample;
|
|
||||||
tmps++;
|
|
||||||
len--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,72 +73,71 @@ fillaudio(void *udata,
|
||||||
int
|
int
|
||||||
InitSound()
|
InitSound()
|
||||||
{
|
{
|
||||||
int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq;
|
int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq;
|
||||||
SDL_AudioSpec spec;
|
SDL_AudioSpec spec;
|
||||||
|
|
||||||
g_config->getOption("SDL.Sound", &sound);
|
g_config->getOption("SDL.Sound", &sound);
|
||||||
if(!sound) {
|
if(!sound) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&spec, 0, sizeof(spec));
|
memset(&spec, 0, sizeof(spec));
|
||||||
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
|
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
|
||||||
puts(SDL_GetError());
|
puts(SDL_GetError());
|
||||||
KillSound();
|
KillSound();
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
char driverName[8];
|
char driverName[8];
|
||||||
SDL_AudioDriverName(driverName, 8);
|
SDL_AudioDriverName(driverName, 8);
|
||||||
|
|
||||||
fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName);
|
fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName);
|
||||||
|
|
||||||
// load configuration variables
|
// load configuration variables
|
||||||
g_config->getOption("SDL.Sound.Rate", &soundrate);
|
g_config->getOption("SDL.Sound.Rate", &soundrate);
|
||||||
g_config->getOption("SDL.Sound.BufSize", &soundbufsize);
|
g_config->getOption("SDL.Sound.BufSize", &soundbufsize);
|
||||||
g_config->getOption("SDL.Sound.Volume", &soundvolume);
|
g_config->getOption("SDL.Sound.Volume", &soundvolume);
|
||||||
g_config->getOption("SDL.Sound.Quality", &soundq);
|
g_config->getOption("SDL.Sound.Quality", &soundq);
|
||||||
g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume);
|
g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume);
|
||||||
g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume);
|
g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume);
|
||||||
g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume);
|
g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume);
|
||||||
g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume);
|
g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume);
|
||||||
g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume);
|
g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume);
|
||||||
|
|
||||||
spec.freq = soundrate;
|
spec.freq = soundrate;
|
||||||
spec.format = AUDIO_S16SYS;
|
spec.format = AUDIO_S16SYS;
|
||||||
spec.channels = 1;
|
spec.channels = 1;
|
||||||
spec.samples = 512;
|
spec.samples = 512;
|
||||||
spec.callback = fillaudio;
|
spec.callback = fillaudio;
|
||||||
spec.userdata = 0;
|
spec.userdata = 0;
|
||||||
|
|
||||||
s_BufferSize = soundbufsize * soundrate / 1000;
|
s_BufferSize = soundbufsize * soundrate / 1000;
|
||||||
|
|
||||||
// For safety, set a bare minimum:
|
// For safety, set a bare minimum:
|
||||||
if (s_BufferSize < spec.samples * 2)
|
if (s_BufferSize < spec.samples * 2)
|
||||||
s_BufferSize = spec.samples * 2;
|
s_BufferSize = spec.samples * 2;
|
||||||
|
|
||||||
s_Buffer = (int *)FCEU_dmalloc(sizeof(int) * s_BufferSize);
|
s_Buffer = (int *)FCEU_dmalloc(sizeof(int) * s_BufferSize);
|
||||||
if (!s_Buffer)
|
if (!s_Buffer)
|
||||||
return 0;
|
return 0;
|
||||||
s_BufferRead = s_BufferWrite = s_BufferIn = 0;
|
s_BufferRead = s_BufferWrite = s_BufferIn = 0;
|
||||||
|
|
||||||
//printf("SDL Size: %d, Internal size: %d\n",spec.samples,s_BufferSize);
|
if(SDL_OpenAudio(&spec, 0) < 0)
|
||||||
|
{
|
||||||
if(SDL_OpenAudio(&spec, 0) < 0) {
|
puts(SDL_GetError());
|
||||||
puts(SDL_GetError());
|
KillSound();
|
||||||
KillSound();
|
return 0;
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
SDL_PauseAudio(0);
|
SDL_PauseAudio(0);
|
||||||
|
|
||||||
FCEUI_SetSoundVolume(soundvolume);
|
FCEUI_SetSoundVolume(soundvolume);
|
||||||
FCEUI_SetSoundQuality(soundq);
|
FCEUI_SetSoundQuality(soundq);
|
||||||
FCEUI_Sound(soundrate);
|
FCEUI_Sound(soundrate);
|
||||||
FCEUI_SetTriangleVolume(soundtrianglevolume);
|
FCEUI_SetTriangleVolume(soundtrianglevolume);
|
||||||
FCEUI_SetSquare1Volume(soundsquare1volume);
|
FCEUI_SetSquare1Volume(soundsquare1volume);
|
||||||
FCEUI_SetSquare2Volume(soundsquare2volume);
|
FCEUI_SetSquare2Volume(soundsquare2volume);
|
||||||
FCEUI_SetNoiseVolume(soundnoisevolume);
|
FCEUI_SetNoiseVolume(soundnoisevolume);
|
||||||
FCEUI_SetPCMVolume(soundpcmvolume);
|
FCEUI_SetPCMVolume(soundpcmvolume);
|
||||||
return(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +147,7 @@ InitSound()
|
||||||
uint32
|
uint32
|
||||||
GetMaxSound(void)
|
GetMaxSound(void)
|
||||||
{
|
{
|
||||||
return(s_BufferSize);
|
return(s_BufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,7 +156,7 @@ GetMaxSound(void)
|
||||||
uint32
|
uint32
|
||||||
GetWriteSound(void)
|
GetWriteSound(void)
|
||||||
{
|
{
|
||||||
return(s_BufferSize - s_BufferIn);
|
return(s_BufferSize - s_BufferIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,25 +166,25 @@ void
|
||||||
WriteSound(int32 *buf,
|
WriteSound(int32 *buf,
|
||||||
int Count)
|
int Count)
|
||||||
{
|
{
|
||||||
extern int EmulationPaused;
|
extern int EmulationPaused;
|
||||||
if (EmulationPaused == 0)
|
if (EmulationPaused == 0)
|
||||||
while(Count)
|
while(Count)
|
||||||
{
|
{
|
||||||
while(s_BufferIn == s_BufferSize)
|
while(s_BufferIn == s_BufferSize)
|
||||||
{
|
{
|
||||||
SDL_Delay(1);
|
SDL_Delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
s_Buffer[s_BufferWrite] = *buf;
|
s_Buffer[s_BufferWrite] = *buf;
|
||||||
Count--;
|
Count--;
|
||||||
s_BufferWrite = (s_BufferWrite + 1) % s_BufferSize;
|
s_BufferWrite = (s_BufferWrite + 1) % s_BufferSize;
|
||||||
|
|
||||||
SDL_LockAudio();
|
SDL_LockAudio();
|
||||||
s_BufferIn++;
|
s_BufferIn++;
|
||||||
SDL_UnlockAudio();
|
SDL_UnlockAudio();
|
||||||
|
|
||||||
buf++;
|
buf++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,7 +193,7 @@ WriteSound(int32 *buf,
|
||||||
void
|
void
|
||||||
SilenceSound(int n)
|
SilenceSound(int n)
|
||||||
{
|
{
|
||||||
SDL_PauseAudio(n);
|
SDL_PauseAudio(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,14 +202,14 @@ SilenceSound(int n)
|
||||||
int
|
int
|
||||||
KillSound(void)
|
KillSound(void)
|
||||||
{
|
{
|
||||||
FCEUI_Sound(0);
|
FCEUI_Sound(0);
|
||||||
SDL_CloseAudio();
|
SDL_CloseAudio();
|
||||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||||
if(s_Buffer) {
|
if(s_Buffer) {
|
||||||
free((void *)s_Buffer);
|
free((void *)s_Buffer);
|
||||||
s_Buffer = 0;
|
s_Buffer = 0;
|
||||||
}
|
}
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,32 +220,32 @@ KillSound(void)
|
||||||
void
|
void
|
||||||
FCEUD_SoundVolumeAdjust(int n)
|
FCEUD_SoundVolumeAdjust(int n)
|
||||||
{
|
{
|
||||||
int soundvolume;
|
int soundvolume;
|
||||||
g_config->getOption("SDL.SoundVolume", &soundvolume);
|
g_config->getOption("SDL.SoundVolume", &soundvolume);
|
||||||
|
|
||||||
switch(n) {
|
switch(n) {
|
||||||
case -1:
|
case -1:
|
||||||
soundvolume -= 10;
|
soundvolume -= 10;
|
||||||
if(soundvolume < 0) {
|
if(soundvolume < 0) {
|
||||||
soundvolume = 0;
|
soundvolume = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
soundvolume = 100;
|
soundvolume = 100;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
soundvolume += 10;
|
soundvolume += 10;
|
||||||
if(soundvolume > 150) {
|
if(soundvolume > 150) {
|
||||||
soundvolume = 150;
|
soundvolume = 150;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_mute = 0;
|
s_mute = 0;
|
||||||
FCEUI_SetSoundVolume(soundvolume);
|
FCEUI_SetSoundVolume(soundvolume);
|
||||||
g_config->setOption("SDL.SoundVolume", soundvolume);
|
g_config->setOption("SDL.SoundVolume", soundvolume);
|
||||||
|
|
||||||
FCEU_DispMessage("Sound volume %d.",0, soundvolume);
|
FCEU_DispMessage("Sound volume %d.",0, soundvolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,16 +254,16 @@ FCEUD_SoundVolumeAdjust(int n)
|
||||||
void
|
void
|
||||||
FCEUD_SoundToggle(void)
|
FCEUD_SoundToggle(void)
|
||||||
{
|
{
|
||||||
if(s_mute) {
|
if(s_mute) {
|
||||||
int soundvolume;
|
int soundvolume;
|
||||||
g_config->getOption("SDL.SoundVolume", &soundvolume);
|
g_config->getOption("SDL.SoundVolume", &soundvolume);
|
||||||
|
|
||||||
s_mute = 0;
|
s_mute = 0;
|
||||||
FCEUI_SetSoundVolume(soundvolume);
|
FCEUI_SetSoundVolume(soundvolume);
|
||||||
FCEU_DispMessage("Sound mute off.",0);
|
FCEU_DispMessage("Sound mute off.",0);
|
||||||
} else {
|
} else {
|
||||||
s_mute = 1;
|
s_mute = 1;
|
||||||
FCEUI_SetSoundVolume(0);
|
FCEUI_SetSoundVolume(0);
|
||||||
FCEU_DispMessage("Sound mute on.",0);
|
FCEU_DispMessage("Sound mute on.",0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,12 @@ bool MaxSpeed = false;
|
||||||
void
|
void
|
||||||
RefreshThrottleFPS()
|
RefreshThrottleFPS()
|
||||||
{
|
{
|
||||||
uint64 fps = FCEUI_GetDesiredFPS(); // Do >> 24 to get in Hz
|
uint64 fps = FCEUI_GetDesiredFPS(); // Do >> 24 to get in Hz
|
||||||
desired_frametime = 16777216.0l / (fps * g_fpsScale);
|
desired_frametime = 16777216.0l / (fps * g_fpsScale);
|
||||||
|
|
||||||
Lasttime=0;
|
Lasttime=0;
|
||||||
Nexttime=0;
|
Nexttime=0;
|
||||||
InFrame=0;
|
InFrame=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,47 +44,47 @@ RefreshThrottleFPS()
|
||||||
int
|
int
|
||||||
SpeedThrottle()
|
SpeedThrottle()
|
||||||
{
|
{
|
||||||
if(g_fpsScale >= 32)
|
if(g_fpsScale >= 32)
|
||||||
{
|
{
|
||||||
return 0; /* Done waiting */
|
return 0; /* Done waiting */
|
||||||
}
|
}
|
||||||
uint64 time_left;
|
uint64 time_left;
|
||||||
uint64 cur_time;
|
uint64 cur_time;
|
||||||
|
|
||||||
if(!Lasttime)
|
if(!Lasttime)
|
||||||
Lasttime = SDL_GetTicks();
|
Lasttime = SDL_GetTicks();
|
||||||
|
|
||||||
if(!InFrame)
|
if(!InFrame)
|
||||||
{
|
{
|
||||||
InFrame = 1;
|
InFrame = 1;
|
||||||
Nexttime = Lasttime + desired_frametime * 1000;
|
Nexttime = Lasttime + desired_frametime * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_time = SDL_GetTicks();
|
cur_time = SDL_GetTicks();
|
||||||
if(cur_time >= Nexttime)
|
if(cur_time >= Nexttime)
|
||||||
time_left = 0;
|
time_left = 0;
|
||||||
else
|
else
|
||||||
time_left = Nexttime - cur_time;
|
time_left = Nexttime - cur_time;
|
||||||
|
|
||||||
if(time_left > 50)
|
if(time_left > 50)
|
||||||
{
|
{
|
||||||
time_left = 50;
|
time_left = 50;
|
||||||
/* In order to keep input responsive, don't wait too long at once */
|
/* In order to keep input responsive, don't wait too long at once */
|
||||||
/* 50 ms wait gives us a 20 Hz responsetime which is nice. */
|
/* 50 ms wait gives us a 20 Hz responsetime which is nice. */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
InFrame = 0;
|
InFrame = 0;
|
||||||
|
|
||||||
/*fprintf(stderr, "attempting to sleep %Ld ms, frame complete=%s\n",
|
/*fprintf(stderr, "attempting to sleep %Ld ms, frame complete=%s\n",
|
||||||
time_left, InFrame?"no":"yes");*/
|
time_left, InFrame?"no":"yes");*/
|
||||||
SDL_Delay(time_left);
|
SDL_Delay(time_left);
|
||||||
|
|
||||||
if(!InFrame)
|
if(!InFrame)
|
||||||
{
|
{
|
||||||
Lasttime = SDL_GetTicks();
|
Lasttime = SDL_GetTicks();
|
||||||
return 0; /* Done waiting */
|
return 0; /* Done waiting */
|
||||||
}
|
}
|
||||||
return 1; /* Must still wait some more */
|
return 1; /* Must still wait some more */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,13 +92,13 @@ SpeedThrottle()
|
||||||
*/
|
*/
|
||||||
void IncreaseEmulationSpeed(void)
|
void IncreaseEmulationSpeed(void)
|
||||||
{
|
{
|
||||||
g_fpsScale *= LOGMUL;
|
g_fpsScale *= LOGMUL;
|
||||||
|
|
||||||
if(g_fpsScale > Fastest) g_fpsScale = Fastest;
|
if(g_fpsScale > Fastest) g_fpsScale = Fastest;
|
||||||
|
|
||||||
RefreshThrottleFPS();
|
RefreshThrottleFPS();
|
||||||
|
|
||||||
FCEU_DispMessage("emulation speed %.1f%%",0, g_fpsScale*100.0);
|
FCEU_DispMessage("emulation speed %.1f%%",0, g_fpsScale*100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,13 +106,13 @@ void IncreaseEmulationSpeed(void)
|
||||||
*/
|
*/
|
||||||
void DecreaseEmulationSpeed(void)
|
void DecreaseEmulationSpeed(void)
|
||||||
{
|
{
|
||||||
g_fpsScale /= LOGMUL;
|
g_fpsScale /= LOGMUL;
|
||||||
if(g_fpsScale < Slowest)
|
if(g_fpsScale < Slowest)
|
||||||
g_fpsScale = Slowest;
|
g_fpsScale = Slowest;
|
||||||
|
|
||||||
RefreshThrottleFPS();
|
RefreshThrottleFPS();
|
||||||
|
|
||||||
FCEU_DispMessage("emulation speed %.1f%%",0, g_fpsScale*100.0);
|
FCEU_DispMessage("emulation speed %.1f%%",0, g_fpsScale*100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,30 +121,30 @@ void DecreaseEmulationSpeed(void)
|
||||||
void
|
void
|
||||||
FCEUD_SetEmulationSpeed(int cmd)
|
FCEUD_SetEmulationSpeed(int cmd)
|
||||||
{
|
{
|
||||||
MaxSpeed = false;
|
MaxSpeed = false;
|
||||||
|
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
case EMUSPEED_SLOWEST:
|
case EMUSPEED_SLOWEST:
|
||||||
g_fpsScale = Slowest;
|
g_fpsScale = Slowest;
|
||||||
break;
|
break;
|
||||||
case EMUSPEED_SLOWER:
|
case EMUSPEED_SLOWER:
|
||||||
DecreaseEmulationSpeed();
|
DecreaseEmulationSpeed();
|
||||||
break;
|
break;
|
||||||
case EMUSPEED_NORMAL:
|
case EMUSPEED_NORMAL:
|
||||||
g_fpsScale = Normal;
|
g_fpsScale = Normal;
|
||||||
break;
|
break;
|
||||||
case EMUSPEED_FASTER:
|
case EMUSPEED_FASTER:
|
||||||
IncreaseEmulationSpeed();
|
IncreaseEmulationSpeed();
|
||||||
break;
|
break;
|
||||||
case EMUSPEED_FASTEST:
|
case EMUSPEED_FASTEST:
|
||||||
g_fpsScale = Fastest;
|
g_fpsScale = Fastest;
|
||||||
MaxSpeed = true;
|
MaxSpeed = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefreshThrottleFPS();
|
RefreshThrottleFPS();
|
||||||
|
|
||||||
FCEU_DispMessage("emulation speed %.1f%%",0, g_fpsScale*100.0);
|
FCEU_DispMessage("emulation speed %.1f%%",0, g_fpsScale*100.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,5 +8,5 @@ bool FCEUI_AviEnableHUDrecording();
|
||||||
void FCEUI_SetAviEnableHUDrecording(bool enable);
|
void FCEUI_SetAviEnableHUDrecording(bool enable);
|
||||||
bool FCEUI_AviDisableMovieMessages();
|
bool FCEUI_AviDisableMovieMessages();
|
||||||
void FCEUI_SetAviDisableMovieMessages(bool disable);
|
void FCEUI_SetAviDisableMovieMessages(bool disable);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -70,10 +70,10 @@ static void
|
||||||
en32(uint8 *buf,
|
en32(uint8 *buf,
|
||||||
uint32 morp)
|
uint32 morp)
|
||||||
{
|
{
|
||||||
buf[0] = morp;
|
buf[0] = morp;
|
||||||
buf[1] = morp >> 8;
|
buf[1] = morp >> 8;
|
||||||
buf[2] = morp >> 16;
|
buf[2] = morp >> 16;
|
||||||
buf[3] = morp >> 24;
|
buf[3] = morp >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -86,155 +86,157 @@ static uint32 de32(uint8 *morp)
|
||||||
int
|
int
|
||||||
FCEUD_NetworkConnect(void)
|
FCEUD_NetworkConnect(void)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sockin;
|
struct sockaddr_in sockin;
|
||||||
struct hostent *phostentb;
|
struct hostent *phostentb;
|
||||||
unsigned long hadr;
|
unsigned long hadr;
|
||||||
int TSocket, tcpopt, error;
|
int TSocket, tcpopt, error;
|
||||||
int netdivisor;
|
int netdivisor;
|
||||||
|
|
||||||
// get any required configuration variables
|
// get any required configuration variables
|
||||||
int port, localPlayers;
|
int port, localPlayers;
|
||||||
std::string server, username, password, key;
|
std::string server, username, password, key;
|
||||||
g_config->getOption("SDL.NetworkIP", &server);
|
g_config->getOption("SDL.NetworkIP", &server);
|
||||||
g_config->getOption("SDL.NetworkUsername", &username);
|
g_config->getOption("SDL.NetworkUsername", &username);
|
||||||
g_config->getOption("SDL.NetworkPassword", &password);
|
g_config->getOption("SDL.NetworkPassword", &password);
|
||||||
g_config->getOption("SDL.NetworkGameKey", &key);
|
g_config->getOption("SDL.NetworkGameKey", &key);
|
||||||
g_config->getOption("SDL.NetworkPort", &port);
|
g_config->getOption("SDL.NetworkPort", &port);
|
||||||
g_config->getOption("SDL.NetworkPlayers", &localPlayers);
|
g_config->getOption("SDL.NetworkPlayers", &localPlayers);
|
||||||
|
|
||||||
|
|
||||||
g_config->setOption("SDL.NetworkIP", "");
|
g_config->setOption("SDL.NetworkIP", "");
|
||||||
g_config->setOption("SDL.NetworkPassword", "");
|
g_config->setOption("SDL.NetworkPassword", "");
|
||||||
g_config->setOption("SDL.NetworkGameKey", "");
|
g_config->setOption("SDL.NetworkGameKey", "");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// only initialize if remote server is specified
|
// only initialize if remote server is specified
|
||||||
if(!server.size()) {
|
if(!server.size()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TSocket = socket(AF_INET, SOCK_STREAM, 0);
|
TSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if(TSocket < 0) {
|
if(TSocket < 0) {
|
||||||
char* s = "Error creating stream socket.";
|
char* s = "Error creating stream socket.";
|
||||||
puts(s);
|
puts(s);
|
||||||
FCEU_DispMessage(s,0);
|
FCEU_DispMessage(s,0);
|
||||||
FCEUD_NetworkClose();
|
FCEUD_NetworkClose();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to setup TCP_NODELAY to avoid network jitters
|
// try to setup TCP_NODELAY to avoid network jitters
|
||||||
tcpopt = 1;
|
tcpopt = 1;
|
||||||
#ifdef BEOS
|
#ifdef BEOS
|
||||||
error = setsockopt(TSocket, SOL_SOCKET, TCP_NODELAY, &tcpopt, sizeof(int));
|
error = setsockopt(TSocket, SOL_SOCKET, TCP_NODELAY, &tcpopt, sizeof(int));
|
||||||
#elif WIN32
|
#elif WIN32
|
||||||
error = setsockopt(TSocket, SOL_TCP, TCP_NODELAY,
|
error = setsockopt(TSocket, SOL_TCP, TCP_NODELAY,
|
||||||
(char*)&tcpopt, sizeof(int));
|
(char*)&tcpopt, sizeof(int));
|
||||||
#else
|
#else
|
||||||
error = setsockopt(TSocket, SOL_TCP, TCP_NODELAY, &tcpopt, sizeof(int));
|
error = setsockopt(TSocket, SOL_TCP, TCP_NODELAY, &tcpopt, sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
if(error) {
|
if(error) {
|
||||||
puts("Nodelay fail");
|
puts("Nodelay fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&sockin, 0, sizeof(sockin));
|
||||||
|
sockin.sin_family = AF_INET;
|
||||||
|
hadr = inet_addr(server.c_str());
|
||||||
|
if(hadr != INADDR_NONE) {
|
||||||
|
sockin.sin_addr.s_addr = hadr;
|
||||||
|
} else {
|
||||||
|
puts("*** Looking up host name...");
|
||||||
|
phostentb = gethostbyname(server.c_str());
|
||||||
|
if(!phostentb) {
|
||||||
|
puts("Error getting host network information.");
|
||||||
|
FCEU_DispMessage("Error getting host info",0);
|
||||||
|
close(TSocket);
|
||||||
|
FCEUD_NetworkClose();
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
memcpy(&sockin.sin_addr, phostentb->h_addr, phostentb->h_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
sockin.sin_port = htons(port);
|
||||||
|
puts("*** Connecting to remote host...");
|
||||||
|
error = connect(TSocket, (struct sockaddr *)&sockin, sizeof(sockin));
|
||||||
|
if(error < 0) {
|
||||||
|
puts("Error connecting to remote host.");
|
||||||
|
FCEU_DispMessage("Error connecting to server",0);
|
||||||
|
close(TSocket);
|
||||||
|
FCEUD_NetworkClose();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_Socket = TSocket;
|
||||||
|
|
||||||
|
puts("*** Sending initialization data to server...");
|
||||||
|
uint8 *sendbuf;
|
||||||
|
uint8 buf[5];
|
||||||
|
uint32 sblen;
|
||||||
|
|
||||||
|
sblen = 4 + 16 + 16 + 64 + 1 + username.size();
|
||||||
|
sendbuf = (uint8 *)FCEU_dmalloc(sblen);
|
||||||
|
memset(sendbuf, 0, sblen);
|
||||||
|
|
||||||
|
// XXX soules - should use htons instead of en32() from above!
|
||||||
|
//uint32 data = htons(sblen - 4);
|
||||||
|
//memcpy(sendbuf, &data, sizeof(data));
|
||||||
|
en32(sendbuf, sblen - 4);
|
||||||
|
|
||||||
|
if(key.size())
|
||||||
|
{
|
||||||
|
struct md5_context md5;
|
||||||
|
uint8 md5out[16];
|
||||||
|
|
||||||
|
md5_starts(&md5);
|
||||||
|
md5_update(&md5, (uint8*)&GameInfo->MD5.data, 16);
|
||||||
|
md5_update(&md5, (uint8 *)key.c_str(), key.size());
|
||||||
|
md5_finish(&md5, md5out);
|
||||||
|
memcpy(sendbuf + 4, md5out, 16);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
memcpy(sendbuf + 4, (uint8*)&GameInfo->MD5.data, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&sockin, 0, sizeof(sockin));
|
if(password.size()) {
|
||||||
sockin.sin_family = AF_INET;
|
struct md5_context md5;
|
||||||
hadr = inet_addr(server.c_str());
|
uint8 md5out[16];
|
||||||
if(hadr != INADDR_NONE) {
|
|
||||||
sockin.sin_addr.s_addr = hadr;
|
|
||||||
} else {
|
|
||||||
puts("*** Looking up host name...");
|
|
||||||
phostentb = gethostbyname(server.c_str());
|
|
||||||
if(!phostentb) {
|
|
||||||
puts("Error getting host network information.");
|
|
||||||
FCEU_DispMessage("Error getting host info",0);
|
|
||||||
close(TSocket);
|
|
||||||
FCEUD_NetworkClose();
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
memcpy(&sockin.sin_addr, phostentb->h_addr, phostentb->h_length);
|
|
||||||
}
|
|
||||||
|
|
||||||
sockin.sin_port = htons(port);
|
md5_starts(&md5);
|
||||||
puts("*** Connecting to remote host...");
|
md5_update(&md5, (uint8 *)password.c_str(), password.size());
|
||||||
error = connect(TSocket, (struct sockaddr *)&sockin, sizeof(sockin));
|
md5_finish(&md5, md5out);
|
||||||
if(error < 0) {
|
memcpy(sendbuf + 4 + 16, md5out, 16);
|
||||||
puts("Error connecting to remote host.");
|
}
|
||||||
FCEU_DispMessage("Error connecting to server",0);
|
|
||||||
close(TSocket);
|
|
||||||
FCEUD_NetworkClose();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_Socket = TSocket;
|
memset(sendbuf + 4 + 16 + 16, 0, 64);
|
||||||
|
|
||||||
puts("*** Sending initialization data to server...");
|
sendbuf[4 + 16 + 16 + 64] = (uint8)localPlayers;
|
||||||
uint8 *sendbuf;
|
|
||||||
uint8 buf[5];
|
|
||||||
uint32 sblen;
|
|
||||||
|
|
||||||
sblen = 4 + 16 + 16 + 64 + 1 + username.size();
|
if(username.size()) {
|
||||||
sendbuf = (uint8 *)FCEU_dmalloc(sblen);
|
memcpy(sendbuf + 4 + 16 + 16 + 64 + 1,
|
||||||
memset(sendbuf, 0, sblen);
|
username.c_str(), username.size());
|
||||||
|
}
|
||||||
// XXX soules - should use htons instead of en32() from above!
|
|
||||||
//uint32 data = htons(sblen - 4);
|
|
||||||
//memcpy(sendbuf, &data, sizeof(data));
|
|
||||||
en32(sendbuf, sblen - 4);
|
|
||||||
|
|
||||||
if(key.size()) {
|
|
||||||
struct md5_context md5;
|
|
||||||
uint8 md5out[16];
|
|
||||||
|
|
||||||
md5_starts(&md5);
|
|
||||||
md5_update(&md5, (uint8*)&GameInfo->MD5.data, 16);
|
|
||||||
md5_update(&md5, (uint8 *)key.c_str(), key.size());
|
|
||||||
md5_finish(&md5, md5out);
|
|
||||||
memcpy(sendbuf + 4, md5out, 16);
|
|
||||||
} else {
|
|
||||||
memcpy(sendbuf + 4, (uint8*)&GameInfo->MD5.data, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(password.size()) {
|
|
||||||
struct md5_context md5;
|
|
||||||
uint8 md5out[16];
|
|
||||||
|
|
||||||
md5_starts(&md5);
|
|
||||||
md5_update(&md5, (uint8 *)password.c_str(), password.size());
|
|
||||||
md5_finish(&md5, md5out);
|
|
||||||
memcpy(sendbuf + 4 + 16, md5out, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(sendbuf + 4 + 16 + 16, 0, 64);
|
|
||||||
|
|
||||||
sendbuf[4 + 16 + 16 + 64] = (uint8)localPlayers;
|
|
||||||
|
|
||||||
if(username.size()) {
|
|
||||||
memcpy(sendbuf + 4 + 16 + 16 + 64 + 1,
|
|
||||||
username.c_str(), username.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
send(s_Socket, (char*)sendbuf, sblen, 0);
|
send(s_Socket, (char*)sendbuf, sblen, 0);
|
||||||
#else
|
#else
|
||||||
send(s_Socket, sendbuf, sblen, 0);
|
send(s_Socket, sendbuf, sblen, 0);
|
||||||
#endif
|
#endif
|
||||||
FCEU_dfree(sendbuf);
|
FCEU_dfree(sendbuf);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
recv(s_Socket, (char*)buf, 1, 0);
|
recv(s_Socket, (char*)buf, 1, 0);
|
||||||
#else
|
#else
|
||||||
recv(s_Socket, buf, 1, MSG_WAITALL);
|
recv(s_Socket, buf, 1, MSG_WAITALL);
|
||||||
#endif
|
#endif
|
||||||
netdivisor = buf[0];
|
netdivisor = buf[0];
|
||||||
|
|
||||||
puts("*** Connection established.");
|
puts("*** Connection established.");
|
||||||
FCEU_DispMessage("Connection established.",0);
|
FCEU_DispMessage("Connection established.",0);
|
||||||
|
|
||||||
FCEUDnetplay = 1;
|
FCEUDnetplay = 1;
|
||||||
FCEUI_NetplayStart(localPlayers, netdivisor);
|
FCEUI_NetplayStart(localPlayers, netdivisor);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,116 +244,116 @@ int
|
||||||
FCEUD_SendData(void *data,
|
FCEUD_SendData(void *data,
|
||||||
uint32 len)
|
uint32 len)
|
||||||
{
|
{
|
||||||
int check = 0, error = 0;
|
int check = 0, error = 0;
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
error = ioctl(fileno(stdin), FIONREAD, &check);
|
error = ioctl(fileno(stdin), FIONREAD, &check);
|
||||||
#endif
|
#endif
|
||||||
if(!error && check) {
|
if(!error && check) {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char *f;
|
char *f;
|
||||||
fgets(buf, 1024, stdin);
|
fgets(buf, 1024, stdin);
|
||||||
if((f=strrchr(buf,'\n'))) {
|
if((f=strrchr(buf,'\n'))) {
|
||||||
*f = 0;
|
*f = 0;
|
||||||
}
|
}
|
||||||
FCEUI_NetplayText((uint8 *)buf);
|
FCEUI_NetplayText((uint8 *)buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
send(s_Socket, (char*)data, len ,0);
|
send(s_Socket, (char*)data, len ,0);
|
||||||
#else
|
#else
|
||||||
send(s_Socket, data, len ,0);
|
send(s_Socket, data, len ,0);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
FCEUD_RecvData(void *data,
|
FCEUD_RecvData(void *data,
|
||||||
uint32 len)
|
uint32 len)
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
NoWaiting &= ~2;
|
NoWaiting &= ~2;
|
||||||
|
|
||||||
for(;;) {
|
for(;;)
|
||||||
fd_set funfun;
|
{
|
||||||
struct timeval popeye;
|
fd_set funfun;
|
||||||
|
struct timeval popeye;
|
||||||
|
|
||||||
popeye.tv_sec=0;
|
popeye.tv_sec=0;
|
||||||
popeye.tv_usec=100000;
|
popeye.tv_usec=100000;
|
||||||
|
|
||||||
FD_ZERO(&funfun);
|
FD_ZERO(&funfun);
|
||||||
FD_SET(s_Socket, &funfun);
|
FD_SET(s_Socket, &funfun);
|
||||||
|
|
||||||
switch(select(s_Socket + 1,&funfun,0,0,&popeye)) {
|
switch(select(s_Socket + 1,&funfun,0,0,&popeye)) {
|
||||||
case 0: continue;
|
case 0: continue;
|
||||||
case -1:return(0);
|
case -1:return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(FD_ISSET(s_Socket,&funfun)) {
|
if(FD_ISSET(s_Socket,&funfun)) {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
size = recv(s_Socket, (char*)data, len, 0);
|
size = recv(s_Socket, (char*)data, len, 0);
|
||||||
#else
|
#else
|
||||||
size = recv(s_Socket, data, len, MSG_WAITALL);
|
size = recv(s_Socket, data, len, MSG_WAITALL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(size == len) {
|
if(size == len) {
|
||||||
//unsigned long beefie;
|
//unsigned long beefie;
|
||||||
|
|
||||||
FD_ZERO(&funfun);
|
FD_ZERO(&funfun);
|
||||||
FD_SET(s_Socket, &funfun);
|
FD_SET(s_Socket, &funfun);
|
||||||
|
|
||||||
popeye.tv_sec = popeye.tv_usec = 0;
|
popeye.tv_sec = popeye.tv_usec = 0;
|
||||||
if(select(s_Socket + 1, &funfun, 0, 0, &popeye) == 1)
|
if(select(s_Socket + 1, &funfun, 0, 0, &popeye) == 1)
|
||||||
//if(!ioctl(s_Socket,FIONREAD,&beefie))
|
//if(!ioctl(s_Socket,FIONREAD,&beefie))
|
||||||
// if(beefie)
|
// if(beefie)
|
||||||
{
|
{
|
||||||
NoWaiting|=2;
|
NoWaiting|=2;
|
||||||
//puts("Yaya");
|
}
|
||||||
}
|
return 1;
|
||||||
return(1);
|
} else {
|
||||||
} else {
|
return 0;
|
||||||
return(0);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FCEUD_NetworkClose(void)
|
FCEUD_NetworkClose(void)
|
||||||
{
|
{
|
||||||
if(s_Socket > 0) {
|
if(s_Socket > 0) {
|
||||||
#ifdef BEOS
|
#ifdef BEOS
|
||||||
closesocket(s_Socket);
|
closesocket(s_Socket);
|
||||||
#else
|
#else
|
||||||
close(s_Socket);
|
close(s_Socket);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
s_Socket = -1;
|
s_Socket = -1;
|
||||||
|
|
||||||
if(FCEUDnetplay) {
|
if(FCEUDnetplay) {
|
||||||
FCEUI_NetplayStop();
|
FCEUI_NetplayStop();
|
||||||
}
|
}
|
||||||
FCEUDnetplay = 0;
|
FCEUDnetplay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FCEUD_NetplayText(uint8 *text)
|
FCEUD_NetplayText(uint8 *text)
|
||||||
{
|
{
|
||||||
char *tot = (char *)FCEU_dmalloc(strlen((const char *)text) + 1);
|
char *tot = (char *)FCEU_dmalloc(strlen((const char *)text) + 1);
|
||||||
char *tmp;
|
char *tmp;
|
||||||
if (!tot)
|
if (!tot)
|
||||||
return;
|
return;
|
||||||
strcpy(tot, (const char *)text);
|
strcpy(tot, (const char *)text);
|
||||||
tmp = tot;
|
tmp = tot;
|
||||||
|
|
||||||
while(*tmp) {
|
while(*tmp) {
|
||||||
if(*tmp < 0x20) {
|
if(*tmp < 0x20) {
|
||||||
*tmp = ' ';
|
*tmp = ' ';
|
||||||
}
|
}
|
||||||
tmp++;
|
tmp++;
|
||||||
}
|
}
|
||||||
puts(tot);
|
puts(tot);
|
||||||
FCEU_dfree(tot);
|
FCEU_dfree(tot);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue