convert newlines to unix for sake of consistency

This commit is contained in:
punkrockguy318 2015-09-13 18:32:42 +00:00
parent 2bb7eb0696
commit 7ee8ca0bb2
1 changed files with 438 additions and 438 deletions

View File

@ -1,79 +1,79 @@
/* FCE Ultra - NES/Famicom Emulator /* FCE Ultra - NES/Famicom Emulator
* *
* Copyright notice for this file: * Copyright notice for this file:
* Copyright (C) 2002,2003 Xodnizel * Copyright (C) 2002,2003 Xodnizel
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "types.h" #include "types.h"
#include "file.h" #include "file.h"
#include "fceu.h" #include "fceu.h"
#include "driver.h" #include "driver.h"
#include "boards/mapinc.h" #include "boards/mapinc.h"
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
#include "fceulua.h" #include "fceulua.h"
#endif #endif
#include "palette.h" #include "palette.h"
#include "palettes/palettes.h" #include "palettes/palettes.h"
#ifndef M_PI #ifndef M_PI
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
#endif #endif
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
bool force_grayscale = false; bool force_grayscale = false;
pal palette_game[64*8]; //custom palette for an individual game. (formerly palettei) pal palette_game[64*8]; //custom palette for an individual game. (formerly palettei)
pal palette_user[64*8]; //user's overridden palette (formerly palettec) pal palette_user[64*8]; //user's overridden palette (formerly palettec)
pal palette_ntsc[64*8]; //mathematically generated NTSC palette (formerly paletten) pal palette_ntsc[64*8]; //mathematically generated NTSC palette (formerly paletten)
static bool palette_game_available; //whether palette_game is available static bool palette_game_available; //whether palette_game is available
static bool palette_user_available; //whether palette_user is available static bool palette_user_available; //whether palette_user is available
//ntsc parameters: //ntsc parameters:
bool ntsccol_enable = false; //whether NTSC palette is selected bool ntsccol_enable = false; //whether NTSC palette is selected
static int ntsctint = 46+10; static int ntsctint = 46+10;
static int ntschue = 72; static int ntschue = 72;
//the default basic palette //the default basic palette
int default_palette_selection = 0; int default_palette_selection = 0;
//library of default palettes //library of default palettes
static pal *default_palette[8]= static pal *default_palette[8]=
{ {
palette, palette,
rp2c04001, rp2c04001,
rp2c04002, rp2c04002,
rp2c04003, rp2c04003,
rp2c05004, rp2c05004,
}; };
static void CalculatePalette(void); static void CalculatePalette(void);
static void ChoosePalette(void); static void ChoosePalette(void);
static void WritePalette(void); static void WritePalette(void);
//points to the actually selected current palette //points to the actually selected current palette
pal *palo; pal *palo;
static float rtmul[] = { 1.239f, 0.794f, 1.019f, 0.905f, 1.023f, 0.741f, 0.75f }; static float rtmul[] = { 1.239f, 0.794f, 1.019f, 0.905f, 1.023f, 0.741f, 0.75f };
static float gtmul[] = { 0.915f, 1.086f, 0.98f, 1.026f, 0.908f, 0.987f, 0.75f }; static float gtmul[] = { 0.915f, 1.086f, 0.98f, 1.026f, 0.908f, 0.987f, 0.75f };
static float btmul[] = { 0.743f, 0.882f, 0.653f, 1.277f, 0.979f, 0.101f, 0.75f }; static float btmul[] = { 0.743f, 0.882f, 0.653f, 1.277f, 0.979f, 0.101f, 0.75f };
@ -93,10 +93,10 @@ static void ApplyDeemphasis(u8& r, u8& g, u8& b, int deemph_bits)
g = (u8)ng; g = (u8)ng;
b = (u8)nb; b = (u8)nb;
} }
static void ApplyDeemphasisComplete(pal* pal512) static void ApplyDeemphasisComplete(pal* pal512)
{ {
//for each deemph level beyond 0 //for each deemph level beyond 0
for(int i=1,idx=64;i<8;i++) for(int i=1,idx=64;i<8;i++)
{ {
//for each palette entry //for each palette entry
@ -104,363 +104,363 @@ static void ApplyDeemphasisComplete(pal* pal512)
{ {
pal512[idx] = pal512[p]; pal512[idx] = pal512[p];
ApplyDeemphasis(pal512[idx].r,pal512[idx].g,pal512[idx].b,i); ApplyDeemphasis(pal512[idx].r,pal512[idx].g,pal512[idx].b,i);
} }
} }
} }
void FCEUI_SetUserPalette(uint8 *pal, int nEntries) void FCEUI_SetUserPalette(uint8 *pal, int nEntries)
{ {
if(!pal) if(!pal)
{ {
palette_user_available = false; palette_user_available = false;
return; return;
} }
palette_user_available = true; palette_user_available = true;
memcpy(palette_user,pal,nEntries*3); memcpy(palette_user,pal,nEntries*3);
//if palette is incomplete, generate deemph entries //if palette is incomplete, generate deemph entries
if(nEntries != 512) if(nEntries != 512)
ApplyDeemphasisComplete(palette_user); ApplyDeemphasisComplete(palette_user);
FCEU_ResetPalette(); FCEU_ResetPalette();
} }
void FCEU_LoadGamePalette(void) void FCEU_LoadGamePalette(void)
{ {
palette_game_available = false; palette_game_available = false;
std::string path = FCEU_MakeFName(FCEUMKF_PALETTE,0,0); std::string path = FCEU_MakeFName(FCEUMKF_PALETTE,0,0);
FILE* fp = FCEUD_UTF8fopen(path,"rb"); FILE* fp = FCEUD_UTF8fopen(path,"rb");
if(fp) if(fp)
{ {
int readed = fread(palette_game,1,64*8*3,fp); int readed = fread(palette_game,1,64*8*3,fp);
int nEntries = readed/3; int nEntries = readed/3;
fclose(fp); fclose(fp);
//if palette is incomplete, generate deemph entries //if palette is incomplete, generate deemph entries
if(nEntries != 512) if(nEntries != 512)
ApplyDeemphasisComplete(palette_game); ApplyDeemphasisComplete(palette_game);
palette_game_available = true; palette_game_available = true;
} }
//not sure whether this is needed //not sure whether this is needed
FCEU_ResetPalette(); FCEU_ResetPalette();
} }
void FCEUI_SetNTSCTH(bool en, int tint, int hue) void FCEUI_SetNTSCTH(bool en, int tint, int hue)
{ {
ntsctint=tint; ntsctint=tint;
ntschue=hue; ntschue=hue;
ntsccol_enable = en; ntsccol_enable = en;
FCEU_ResetPalette(); FCEU_ResetPalette();
} }
//this prepares the 'deemph' palette which was a horrible idea to jam a single deemph palette into 0xC0-0xFF of the 8bpp palette. //this prepares the 'deemph' palette which was a horrible idea to jam a single deemph palette into 0xC0-0xFF of the 8bpp palette.
//its needed for GUI and lua and stuff, so we're leaving it, despite having a newer codepath for applying deemph //its needed for GUI and lua and stuff, so we're leaving it, despite having a newer codepath for applying deemph
static uint8 lastd=0; static uint8 lastd=0;
void SetNESDeemph_OldHacky(uint8 d, int force) void SetNESDeemph_OldHacky(uint8 d, int force)
{ {
static uint16 rtmul[]={ static uint16 rtmul[]={
static_cast<uint16>(32768*1.239), static_cast<uint16>(32768*1.239),
static_cast<uint16>(32768*.794), static_cast<uint16>(32768*.794),
static_cast<uint16>(32768*1.019), static_cast<uint16>(32768*1.019),
static_cast<uint16>(32768*.905), static_cast<uint16>(32768*.905),
static_cast<uint16>(32768*1.023), static_cast<uint16>(32768*1.023),
static_cast<uint16>(32768*.741), static_cast<uint16>(32768*.741),
static_cast<uint16>(32768*.75) static_cast<uint16>(32768*.75)
}; };
static uint16 gtmul[]={ static uint16 gtmul[]={
static_cast<uint16>(32768*.915), static_cast<uint16>(32768*.915),
static_cast<uint16>(32768*1.086), static_cast<uint16>(32768*1.086),
static_cast<uint16>(32768*.98), static_cast<uint16>(32768*.98),
static_cast<uint16>(32768*1.026), static_cast<uint16>(32768*1.026),
static_cast<uint16>(32768*.908), static_cast<uint16>(32768*.908),
static_cast<uint16>(32768*.987), static_cast<uint16>(32768*.987),
static_cast<uint16>(32768*.75) static_cast<uint16>(32768*.75)
}; };
static uint16 btmul[]={ static uint16 btmul[]={
static_cast<uint16>(32768*.743), static_cast<uint16>(32768*.743),
static_cast<uint16>(32768*.882), static_cast<uint16>(32768*.882),
static_cast<uint16>(32768*.653), static_cast<uint16>(32768*.653),
static_cast<uint16>(32768*1.277), static_cast<uint16>(32768*1.277),
static_cast<uint16>(32768*.979), static_cast<uint16>(32768*.979),
static_cast<uint16>(32768*.101), static_cast<uint16>(32768*.101),
static_cast<uint16>(32768*.75) static_cast<uint16>(32768*.75)
}; };
uint32 r,g,b; uint32 r,g,b;
int x; int x;
/* If it's not forced(only forced when the palette changes), /* If it's not forced(only forced when the palette changes),
don't waste cpu time if the same deemphasis bits are set as the last call. don't waste cpu time if the same deemphasis bits are set as the last call.
*/ */
if(!force) if(!force)
{ {
if(d==lastd) if(d==lastd)
return; return;
} }
else /* Only set this when palette has changed. */ else /* Only set this when palette has changed. */
{ {
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
FCEU_LuaUpdatePalette(); FCEU_LuaUpdatePalette();
#endif #endif
r=rtmul[6]; r=rtmul[6];
g=rtmul[6]; g=rtmul[6];
b=rtmul[6]; b=rtmul[6];
for(x=0;x<0x40;x++) for(x=0;x<0x40;x++)
{ {
uint32 m,n,o; uint32 m,n,o;
m=palo[x].r; m=palo[x].r;
n=palo[x].g; n=palo[x].g;
o=palo[x].b; o=palo[x].b;
m=(m*r)>>15; m=(m*r)>>15;
n=(n*g)>>15; n=(n*g)>>15;
o=(o*b)>>15; o=(o*b)>>15;
if(m>0xff) m=0xff; if(m>0xff) m=0xff;
if(n>0xff) n=0xff; if(n>0xff) n=0xff;
if(o>0xff) o=0xff; if(o>0xff) o=0xff;
FCEUD_SetPalette(x|0xC0,m,n,o); FCEUD_SetPalette(x|0xC0,m,n,o);
} }
} }
if(!d) return; /* No deemphasis, so return. */ if(!d) return; /* No deemphasis, so return. */
r=rtmul[d-1]; r=rtmul[d-1];
g=gtmul[d-1]; g=gtmul[d-1];
b=btmul[d-1]; b=btmul[d-1];
for(x=0;x<0x40;x++) for(x=0;x<0x40;x++)
{ {
uint32 m,n,o; uint32 m,n,o;
m=palo[x].r; m=palo[x].r;
n=palo[x].g; n=palo[x].g;
o=palo[x].b; o=palo[x].b;
m=(m*r)>>15; m=(m*r)>>15;
n=(n*g)>>15; n=(n*g)>>15;
o=(o*b)>>15; o=(o*b)>>15;
if(m>0xff) m=0xff; if(m>0xff) m=0xff;
if(n>0xff) n=0xff; if(n>0xff) n=0xff;
if(o>0xff) o=0xff; if(o>0xff) o=0xff;
FCEUD_SetPalette(x|0x40,m,n,o); FCEUD_SetPalette(x|0x40,m,n,o);
} }
lastd=d; lastd=d;
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
FCEU_LuaUpdatePalette(); FCEU_LuaUpdatePalette();
#endif #endif
} }
// Converted from Kevin Horton's qbasic palette generator. // Converted from Kevin Horton's qbasic palette generator.
static void CalculatePalette(void) static void CalculatePalette(void)
{ {
//PRECONDITION: ntsc palette is enabled //PRECONDITION: ntsc palette is enabled
if(!ntsccol_enable) if(!ntsccol_enable)
return; return;
int x,z; int x,z;
int r,g,b; int r,g,b;
double s,luma,theta; double s,luma,theta;
static uint8 cols[16]={0,24,21,18,15,12,9,6,3,0,33,30,27,0,0,0}; static uint8 cols[16]={0,24,21,18,15,12,9,6,3,0,33,30,27,0,0,0};
static uint8 br1[4]={6,9,12,12}; static uint8 br1[4]={6,9,12,12};
static double br2[4]={.29,.45,.73,.9}; static double br2[4]={.29,.45,.73,.9};
static double br3[4]={0,.24,.47,.77}; static double br3[4]={0,.24,.47,.77};
for(x=0;x<=3;x++) for(x=0;x<=3;x++)
for(z=0;z<16;z++) for(z=0;z<16;z++)
{ {
s=(double)ntsctint/128; s=(double)ntsctint/128;
luma=br2[x]; luma=br2[x];
if(z==0) {s=0;luma=((double)br1[x])/12;} if(z==0) {s=0;luma=((double)br1[x])/12;}
if(z>=13) if(z>=13)
{ {
s=luma=0; s=luma=0;
if(z==13) if(z==13)
luma=br3[x]; luma=br3[x];
} }
theta=(double)M_PI*(double)(((double)cols[z]*10+ (((double)ntschue/2)+300) )/(double)180); theta=(double)M_PI*(double)(((double)cols[z]*10+ (((double)ntschue/2)+300) )/(double)180);
r=(int)((luma+s*sin(theta))*256); r=(int)((luma+s*sin(theta))*256);
g=(int)((luma-(double)27/53*s*sin(theta)+(double)10/53*s*cos(theta))*256); g=(int)((luma-(double)27/53*s*sin(theta)+(double)10/53*s*cos(theta))*256);
b=(int)((luma-s*cos(theta))*256); b=(int)((luma-s*cos(theta))*256);
if(r>255) r=255; if(r>255) r=255;
if(g>255) g=255; if(g>255) g=255;
if(b>255) b=255; if(b>255) b=255;
if(r<0) r=0; if(r<0) r=0;
if(g<0) g=0; if(g<0) g=0;
if(b<0) b=0; if(b<0) b=0;
palette_ntsc[(x<<4)+z].r=r; palette_ntsc[(x<<4)+z].r=r;
palette_ntsc[(x<<4)+z].g=g; palette_ntsc[(x<<4)+z].g=g;
palette_ntsc[(x<<4)+z].b=b; palette_ntsc[(x<<4)+z].b=b;
} }
//can't call FCEU_ResetPalette(), it would be re-entrant //can't call FCEU_ResetPalette(), it would be re-entrant
//see precondition for this function //see precondition for this function
WritePalette(); WritePalette();
} }
void FCEU_ResetPalette(void) void FCEU_ResetPalette(void)
{ {
if(GameInfo) if(GameInfo)
{ {
ChoosePalette(); ChoosePalette();
WritePalette(); WritePalette();
} }
} }
static void ChoosePalette(void) static void ChoosePalette(void)
{ {
//if it's an NSF, there's NO palette? that's right, only the 'unvarying' palette will get used //if it's an NSF, there's NO palette? that's right, only the 'unvarying' palette will get used
if(GameInfo->type==GIT_NSF) if(GameInfo->type==GIT_NSF)
palo = NULL; palo = NULL;
//user palette takes priority over others //user palette takes priority over others
else if(palette_user_available) else if(palette_user_available)
palo = palette_user; palo = palette_user;
//NTSC takes priority next, if it's appropriate //NTSC takes priority next, if it's appropriate
else if(ntsccol_enable && !PAL && GameInfo->type!=GIT_VSUNI) else if(ntsccol_enable && !PAL && GameInfo->type!=GIT_VSUNI)
{ {
//for NTSC games, we can actually use the NTSC palette //for NTSC games, we can actually use the NTSC palette
palo = palette_ntsc; palo = palette_ntsc;
CalculatePalette(); CalculatePalette();
} }
//select the game's overridden palette if available //select the game's overridden palette if available
else if(palette_game_available) else if(palette_game_available)
palo = palette_game; palo = palette_game;
//finally, use a default built-in palette //finally, use a default built-in palette
else else
{ {
palo = default_palette[default_palette_selection]; palo = default_palette[default_palette_selection];
//need to calcualte a deemph on the fly.. sorry. maybe support otherwise later //need to calcualte a deemph on the fly.. sorry. maybe support otherwise later
ApplyDeemphasisComplete(palo); ApplyDeemphasisComplete(palo);
} }
} }
void WritePalette(void) void WritePalette(void)
{ {
int x; int x;
//set the 'unvarying' palettes to low < 128 palette entries //set the 'unvarying' palettes to low < 128 palette entries
for(x=0;x<7;x++) for(x=0;x<7;x++)
FCEUD_SetPalette(x,palette_unvarying[x].r,palette_unvarying[x].g,palette_unvarying[x].b); FCEUD_SetPalette(x,palette_unvarying[x].r,palette_unvarying[x].g,palette_unvarying[x].b);
if(GameInfo->type==GIT_NSF) if(GameInfo->type==GIT_NSF)
{ {
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
FCEU_LuaUpdatePalette(); FCEU_LuaUpdatePalette();
#endif #endif
} }
else else
{ {
//sets palette entries >= 128 with the 64 selected main colors //sets palette entries >= 128 with the 64 selected main colors
for(x=0;x<64;x++) for(x=0;x<64;x++)
FCEUD_SetPalette(128+x,palo[x].r,palo[x].g,palo[x].b); FCEUD_SetPalette(128+x,palo[x].r,palo[x].g,palo[x].b);
SetNESDeemph_OldHacky(lastd,1); SetNESDeemph_OldHacky(lastd,1);
} }
} }
void FCEUI_GetNTSCTH(int *tint, int *hue) void FCEUI_GetNTSCTH(int *tint, int *hue)
{ {
*tint = ntsctint; *tint = ntsctint;
*hue = ntschue; *hue = ntschue;
} }
static int controlselect=0; static int controlselect=0;
static int controllength=0; static int controllength=0;
void FCEUI_NTSCDEC(void) void FCEUI_NTSCDEC(void)
{ {
if(ntsccol_enable && GameInfo->type!=GIT_VSUNI &&!PAL && GameInfo->type!=GIT_NSF) if(ntsccol_enable && GameInfo->type!=GIT_VSUNI &&!PAL && GameInfo->type!=GIT_NSF)
{ {
int which; int which;
if(controlselect) if(controlselect)
{ {
if(controllength) if(controllength)
{ {
which=controlselect==1?ntschue:ntsctint; which=controlselect==1?ntschue:ntsctint;
which--; which--;
if(which<0) which=0; if(which<0) which=0;
if(controlselect==1) if(controlselect==1)
ntschue=which; ntschue=which;
else ntsctint=which; else ntsctint=which;
CalculatePalette(); CalculatePalette();
} }
controllength=360; controllength=360;
} }
} }
} }
void FCEUI_NTSCINC(void) void FCEUI_NTSCINC(void)
{ {
if(ntsccol_enable && GameInfo->type!=GIT_VSUNI && !PAL && GameInfo->type!=GIT_NSF) if(ntsccol_enable && GameInfo->type!=GIT_VSUNI && !PAL && GameInfo->type!=GIT_NSF)
if(controlselect) if(controlselect)
{ {
if(controllength) if(controllength)
{ {
switch(controlselect) switch(controlselect)
{ {
case 1:ntschue++; case 1:ntschue++;
if(ntschue>128) ntschue=128; if(ntschue>128) ntschue=128;
CalculatePalette(); CalculatePalette();
break; break;
case 2:ntsctint++; case 2:ntsctint++;
if(ntsctint>128) ntsctint=128; if(ntsctint>128) ntsctint=128;
CalculatePalette(); CalculatePalette();
break; break;
} }
} }
controllength=360; controllength=360;
} }
} }
void FCEUI_NTSCSELHUE(void) void FCEUI_NTSCSELHUE(void)
{ {
if(ntsccol_enable && GameInfo->type!=GIT_VSUNI && !PAL && GameInfo->type!=GIT_NSF){controlselect=1;controllength=360;} if(ntsccol_enable && GameInfo->type!=GIT_VSUNI && !PAL && GameInfo->type!=GIT_NSF){controlselect=1;controllength=360;}
} }
void FCEUI_NTSCSELTINT(void) void FCEUI_NTSCSELTINT(void)
{ {
if(ntsccol_enable && GameInfo->type!=GIT_VSUNI && !PAL && GameInfo->type!=GIT_NSF){controlselect=2;controllength=360;} if(ntsccol_enable && GameInfo->type!=GIT_VSUNI && !PAL && GameInfo->type!=GIT_NSF){controlselect=2;controllength=360;}
} }
void FCEU_DrawNTSCControlBars(uint8 *XBuf) void FCEU_DrawNTSCControlBars(uint8 *XBuf)
{ {
uint8 *XBaf; uint8 *XBaf;
int which=0; int which=0;
int x,x2; int x,x2;
if(!controllength) return; if(!controllength) return;
controllength--; controllength--;
if(!XBuf) return; if(!XBuf) return;
if(controlselect==1) if(controlselect==1)
{ {
DrawTextTrans(XBuf+128-12+180*256, 256, (uint8 *)"Hue", 0x85); DrawTextTrans(XBuf+128-12+180*256, 256, (uint8 *)"Hue", 0x85);
which=ntschue<<1; which=ntschue<<1;
} }
else if(controlselect==2) else if(controlselect==2)
{ {
DrawTextTrans(XBuf+128-16+180*256, 256, (uint8 *)"Tint", 0x85); DrawTextTrans(XBuf+128-16+180*256, 256, (uint8 *)"Tint", 0x85);
which=ntsctint<<1; which=ntsctint<<1;
} }
XBaf=XBuf+200*256; XBaf=XBuf+200*256;
for(x=0;x<which;x+=2) for(x=0;x<which;x+=2)
{ {
for(x2=6;x2>=-6;x2--) for(x2=6;x2>=-6;x2--)
{ {
XBaf[x-256*x2]=0x85; XBaf[x-256*x2]=0x85;
} }
} }
for(;x<256;x+=2) for(;x<256;x+=2)
{ {
for(x2=2;x2>=-2;x2--) for(x2=2;x2>=-2;x2--)
XBaf[x-256*x2]=0x85; XBaf[x-256*x2]=0x85;
} }
} }