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