From 5232c20c0fa2c80964fe1d3f597c239bcf93d6fc Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 7 Apr 2007 13:57:00 +0000 Subject: [PATCH] gpfce patch git-svn-id: file:///home/notaz/opt/svn/fceu@91 be3aeb3a-fb24-0410-a615-afba39da0efa --- Makefile.base | 2 +- banksw.h | 2 +- cart.c | 6 +- drawing.h | 8 +- drivers/cli/input.c | 387 ++++++++++++++++++++++++++++++++++- drivers/cli/keyscan.h | 5 +- drivers/cli/main.c | 21 +- drivers/cli/sdl-joystick.c | 15 +- drivers/cli/sdl-sound.c | 180 ++++++++--------- drivers/cli/sdl-video.c | 373 +++++++++++++++++++++++++++++++++- drivers/cli/sdl.c | 100 ++++++++- drivers/cli/sdl.h | 2 + drivers/cli/svgalib.c | 7 +- drivers/cli/throttle.c | 9 +- drivers/cli/throttle.h | 2 +- drivers/cli/unix-basedir.h | 15 -- drivers/cli/unix-netplay.c | 15 +- fce.c | 403 +++---------------------------------- fce.h | 5 +- fceline.h | 97 +-------- general.c | 32 +-- input.c | 2 +- mappers/simple.c | 5 +- memory.c | 29 ++- nsf.c | 10 +- palettes/rp2c04001.h | 128 ++++++------ sound.c | 53 ++++- sound.h | 1 + state.c | 1 + svga.c | 3 + unif.c | 5 +- video.c | 11 +- zlib/unzip.c | 4 +- 33 files changed, 1211 insertions(+), 727 deletions(-) diff --git a/Makefile.base b/Makefile.base index 3e3f273..0a71b12 100644 --- a/Makefile.base +++ b/Makefile.base @@ -1,4 +1,4 @@ -CFLAGS = -Wall -Winline ${TFLAGS} +CFLAGS = -Wall ${TFLAGS} OBJECTS = fce.o x6502.o video.o general.o endian.o svga.o sound.o nsf.o fds.o netplay.o ines.o state.o unif.o input.o file.o cart.o crc32.o memory.o cheat.o debug.o fceu: fceu2 diff --git a/banksw.h b/banksw.h index f45c489..ce9b263 100644 --- a/banksw.h +++ b/banksw.h @@ -90,7 +90,7 @@ void FASTAPASS(2) ROM_BANK16(uint32 A, uint32 V) } } -void FASTAPASS(1) ROM_BANK32(uint32 V) +void FASTAPASS(2) ROM_BANK32(uint32 V) { setprg32(0x8000,V); PRGBankList[0]=V<<2; diff --git a/cart.c b/cart.c index 030e764..0f9e10e 100644 --- a/cart.c +++ b/cart.c @@ -90,13 +90,13 @@ void ResetCartMapping(void) for(x=0;x<32;x++) { - Page[x]=nothing-x*2048; + Page[x]=(uint8 *)(nothing-x*2048); PRGptr[x]=CHRptr[x]=0; PRGsize[x]=CHRsize[x]=0; } for(x=0;x<8;x++) { - MMC5SPRVPage[x]=MMC5BGVPage[x]=VPageR[x]=nothing-0x400*x; + MMC5SPRVPage[x]=MMC5BGVPage[x]=VPageR[x]=(uint8 *)(nothing-0x400*x); } } @@ -291,7 +291,7 @@ void FASTAPASS(2) setchr4(unsigned int A, unsigned int V) setchr4r(0,A,V); } -void FASTAPASS(1) setchr8(unsigned int V) +void FASTAPASS(2) setchr8(unsigned int V) { setchr8r(0,V); } diff --git a/drawing.h b/drawing.h index 4e7bfec..8850c7a 100644 --- a/drawing.h +++ b/drawing.h @@ -40,7 +40,7 @@ static void DrawMessage(void) howlong--; t=XBuf+(FSettings.LastSLine-29)*272+32; if(t>=XBuf) - DrawTextTrans(t,272,errmsg,132); + DrawTextTrans(t,272,(uint8 *)errmsg,132); } } @@ -109,7 +109,7 @@ static void DrawState(void) void DrawTextTrans(uint8 *dest, uint32 width, uint8 *textmsg, uint8 fgcolor) { - uint8 length=strlen(textmsg); + uint8 length=strlen((char *)textmsg); uint8 x; uint8 y; uint8 z; @@ -128,12 +128,12 @@ void DrawBars(void) if(controlselect==1) { - DrawTextTrans(XBuf+128-12+180*272, 272, "Hue", 0x85); + DrawTextTrans(XBuf+128-12+180*272, 272, (uint8 *)"Hue", 0x85); which=ntschue<<1; } else if(controlselect==2) { - DrawTextTrans(XBuf+128-16+180*272, 272, "Tint", 0x85); + DrawTextTrans(XBuf+128-16+180*272, 272, (uint8 *)"Tint", 0x85); which=ntsctint<<1; } diff --git a/drivers/cli/input.c b/drivers/cli/input.c index b946c5b..212c34d 100644 --- a/drivers/cli/input.c +++ b/drivers/cli/input.c @@ -27,8 +27,23 @@ #define JOY_LEFT 0x40 #define JOY_RIGHT 0x80 + +#include "minimal.h" +extern int swapbuttons; +extern int stretch_offset; +extern void SetVideoScaling(int pixels,int width,int height); +long UpdateGamepadGP2X(void); + + + + + static void UpdateFKB(void); + + + + /* UsrInputType[] is user-specified. InputType[] is current (game loading can override user settings) */ @@ -62,14 +77,17 @@ static void DoCheatSeq(void) #include "keyscan.h" static char *keys; static int DIPS=0; +#ifndef GP2X static uint8 keyonce[MK_COUNT]; #define KEY(__a) keys[MK(__a)] #define keyonly(__a,__z) {if(KEY(__a)){if(!keyonce[MK(__a)]) {keyonce[MK(__a)]=1;__z}}else{keyonce[MK(__a)]=0;}} +#endif + static int JoySwap=0; static int cidisabled=0; static int KeyboardUpdate(void) { - +#ifndef GP2X if(!UpdateKeyboard()) if(keys) return 0; @@ -156,10 +174,14 @@ static int KeyboardUpdate(void) keyonly(9,FCEUI_SelectState(9);) } return 1; +#else + return 1; +#endif } static uint32 KeyboardDodo(void) { +#ifndef GP2X uint32 JS=0; if(gametype!=GIT_NSF) @@ -186,8 +208,12 @@ static uint32 KeyboardDodo(void) if(x!=(JOY_LEFT|JOY_RIGHT)) JS|=x<>8)|((JSreturn&0xFF00)<<8); + if(gametype==GIT_FDS) + { + NoWaiting&=~1; + if ((pad & GP2X_PUSH) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_L)) && (!(pad & GP2X_R)) && (!(lastpad2 & GP2X_PUSH))) + { + DriverInterface(DES_FDSSELECT,0); + } + else if ((pad & GP2X_L) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_PUSH)) && (!(pad & GP2X_R))&& (!(lastpad2 & GP2X_L))) + { + DriverInterface(DES_FDSINSERT,0); + } + else if ((pad & GP2X_R) && (!(pad & GP2X_SELECT)) && (!(pad & GP2X_L)) && (!(pad & GP2X_PUSH)) && (!(lastpad2 & GP2X_R))) + { + DriverInterface(DES_FDSEJECT,0); + } + } +#else + UpdateGamepadGP2X(); b=KeyboardUpdate(); for(x=0;x<2;x++) @@ -266,10 +325,326 @@ void FCEUD_UpdateInput(void) } if(t&2) GetMouseData(MouseData); + +#endif +} + + + + + +//#ifdef GP2X + +extern void ResetNES(void); +extern void CleanSurface(void); + +char soundvolmeter[21]; +int soundvolIndex=0; +int L_count=0; +int R_count=0; +extern int CurrentState; +int TurboFireOff=1; +int TurboFireTop=0; // 0 is none // 1 is A & X turbo // 2 is Y & B turbo +int TurboFireBottom=0; +int turbo_toggle_A=0; +int turbo_toggle_B=0; + +static void setsoundvol(int soundvolume) +{ + //FCEUI_SetSoundVolume(soundvol); + // draw on screen :D + gp2x_sound_volume(soundvolume, soundvolume); + int meterval=soundvolume/5; + for (soundvolIndex=0; soundvolIndex < 20; soundvolIndex++) + { + if (soundvolIndex < meterval) + { + soundvolmeter[soundvolIndex]='*'; + } + else + { + soundvolmeter[soundvolIndex]='_'; + } + } + soundvolmeter[20]=0; + FCEU_DispMessage("|%s|", soundvolmeter); } +/** + * GP2x joystick reader + * + */ +INLINE long UpdateGamepadGP2X(void) +{ + uint32 JS=0; + + unsigned long pad=gp2x_joystick_read(); +#define L_down (pad & GP2X_L) +#define R_down (pad & GP2X_R) +#define last_L_down (lastpad & GP2X_L) +#define last_R_down (lastpad & GP2X_R) + + if (L_down && R_down && (!(pad & GP2X_PUSH)) + && (!(last_R_down && last_L_down))) + { + ResetNES(); + puts("Reset"); + JSreturn=0; + lastpad=pad; + return pad; + } + + + + + if (pad & GP2X_VOL_UP) + { + soundvol+=1; + if (soundvol >= 100) soundvol=100; + //FCEUI_SetSoundVolume(soundvol); + setsoundvol(soundvol); + } + if (pad & GP2X_VOL_DOWN) + { + soundvol-=1; + if (soundvol < 0) soundvol=0; + //FCEUI_SetSoundVolume(soundvol); + setsoundvol(soundvol); + } + if (pad & GP2X_PUSH) + { + // only if it's something else then last time, and not moving around the joystick + if (!((pad & GP2X_UP) ||(pad & GP2X_DOWN) || (pad & GP2X_LEFT) || (pad & GP2X_RIGHT))) + { + if (pad & GP2X_SELECT) + { + if ((lastpad & GP2X_SELECT) && (lastpad & GP2X_PUSH)) + { + // still pressed down from stretching from last one + JSreturn=0; + lastpad=pad; + return 0; + } + if (stretch_offset == 32) + { + stretch_offset=0; + } + else + { + stretch_offset=32; + } + + if (stretch_offset == 32) + { + SetVideoScaling(320, 320, 240); + CleanSurface(); + } + else + { + SetVideoScaling(320, 256, 240); + } + + JSreturn=0; + lastpad=pad; + return pad; + } + else if (L_down && R_down) + { + FCEUI_CloseGame(); + puts("Quit"); + JSreturn=0; + return 0; + } + else if (R_down && (!((lastpad & GP2X_R) && (lastpad & GP2X_PUSH)))) + { + FCEUI_LoadState(); + JSreturn=0; + lastpad=pad; + return 0; + } + else if (L_down && (!((lastpad & GP2X_L) && (lastpad & GP2X_PUSH)))) + { + FCEUI_SaveState(); + JSreturn=0; + lastpad=pad; + return 0; + } + } + } + + // r is toggle savestate + if (R_down) + { + if (last_R_down) + { + R_count++; + if ((R_count & 31)== 31) + { + CurrentState=(CurrentState+1) % 10; + FCEUI_DispMessage("Now Using Save State %d", CurrentState); + } + } + } + else + { + R_count=0; + } + + // l is toggle turbo + if (L_down) + { + if (last_L_down) + { + L_count++; + if ((L_count & 31)== 31) + { + // 0 is none // 1 is Y & B turbo // 2 is X & A turbo + if ((!TurboFireTop) && (!TurboFireBottom)) + { + // was off + TurboFireTop=1; + TurboFireBottom=0; + if (swapbuttons) + { + FCEUI_DispMessage("Turbo A and Y"); + } + else + { + FCEUI_DispMessage("Turbo Y and B"); + } + } + else if (TurboFireTop) + { + TurboFireTop=0; + TurboFireBottom=1; + if (swapbuttons) + { + FCEUI_DispMessage("Turbo X and B"); + } + else + { + FCEUI_DispMessage("Turbo A and X"); + } + } + else + { + TurboFireTop=0; + TurboFireBottom=0; + FCEUI_DispMessage("Turbo Off"); + } + + } + } + } + else + { + L_count=0; + } + + + + //unsigned long padTmp=0; + // shift the bits in + // up + //padTmp=(pad & GP2X_UP) ; // 1 is 2^0, + JS |= ((pad & GP2X_UP) << (4-0)); // 0x10 is 2^4 + + //padTmp=(pad & GP2X_DOWN); // 0x10 is 2^4, + JS |= ((pad & GP2X_DOWN) << (5-4)); // 0x20 is 2^5 + + //padTmp=(pad & GP2X_LEFT); // 0x4 is 2^2, + JS |= ((pad & GP2X_LEFT) << (6-2)); // 0x40 is 2^6 + + //padTmp=(pad & GP2X_RIGHT); // 0x40 is 2^6, + JS |= ((pad & GP2X_RIGHT) << (7-6)); // 0x80 is 2^7 + + +#define A_down (pad & GP2X_A) +#define B_down (pad & GP2X_B) +#define X_down (pad & GP2X_X) +#define Y_down (pad & GP2X_Y) + + // should be 2 cycles held, 1 cycle release + turbo_toggle_A=(turbo_toggle_A+1) % 3; + turbo_toggle_B=(turbo_toggle_B+1) % 3; + + // 0 is none // 1 is Y & B turbo // 2 is X & A turbo + // B or X are both considered A + //padTmp=B_down >> 13; // 2^13, + + if (!(TurboFireTop && (!turbo_toggle_A))) + { + JS |= ((B_down >> 13) << 0); // 0x1 is 2^0 + } + // A or Y are both considered B + //padTmp=A_down >> 12; // 2^13, + if (!(TurboFireBottom && (!turbo_toggle_B))) + { + JS |= ((A_down >> 12) << 1); // 0x2 is 2^1 + } + + if (swapbuttons) + { + //padTmp=X_down >> 14; // 2^13, + if (!(TurboFireBottom && (!turbo_toggle_A))) + { +// JS |= ((X_down >> 14) << 0); // 0x1 is 2^0 + JS |= ((Y_down >> 15) << 0); // 0x1 is 2^0 + } + + //padTmp=Y_down >> 15; // 2^13, + if (!(TurboFireTop && (!turbo_toggle_B))) + { + JS |= ((X_down >> 14) << 1); // 0x2 is 2^1 + } + } + else + { + //padTmp=X_down >> 14; // 2^13, + if (!(TurboFireBottom && (!turbo_toggle_A))) + { + JS |= ((X_down >> 14) << 0); // 0x1 is 2^0 + } + + //padTmp=Y_down >> 15; // 2^13, + if (!(TurboFireTop && (!turbo_toggle_B))) + { + JS |= ((Y_down >> 15) << 1); // 0x2 is 2^1 + } + } + + // select + //padTmp=(pad & GP2X_SELECT) >> 9; // 0x40 is 2^9, + JS |= (((pad & GP2X_SELECT) >> 9) << 2); // 0x4 is 2^2 + + // start + //padTmp=(pad & GP2X_START) >> 8; // 2^8, + JS |= (((pad & GP2X_START) >> 8) << 3); // 0x8 is 2^3 + + + JSreturn = JS; + lastpad=pad; + + return pad; + //JSreturn=(JS&0xFF000000)|(JS&0xFF)|((JS&0xFF0000)>>8)|((JS&0xFF00)<<8); +} +//#endif + + + + + + + + + + + + + static void InitOtherInput(void) { + void *InputDPtr; int t; @@ -282,7 +657,7 @@ static void InitOtherInput(void) InputDPtr=0; switch(InputType[x]) { - case SI_POWERPAD:InputDPtr=&powerpadbuf[x];break; + //case SI_POWERPAD:InputDPtr=&powerpadbuf[x];break; case SI_GAMEPAD:InputDPtr=((uint8 *)&JSreturn)+(x<<1);break; case SI_ARKANOID:InputDPtr=MouseData;t|=1;break; case SI_ZAPPER:InputDPtr=MouseData; @@ -310,8 +685,9 @@ static void InitOtherInput(void) InitMouse(); inited|=16; } -} +} +#ifndef GP2X int fkbmap[0x48]= { MK(F1),MK(F2),MK(F3),MK(F4),MK(F5),MK(F6),MK(F7),MK(F8), @@ -326,9 +702,11 @@ int fkbmap[0x48]= MK(DELETE),MK(END),MK(PAGEDOWN), MK(CURSORUP),MK(CURSORLEFT),MK(CURSORRIGHT),MK(CURSORDOWN) }; +#endif static void UpdateFKB(void) { +#ifndef GP2X int x; for(x=0;x<0x48;x++) @@ -337,4 +715,5 @@ static void UpdateFKB(void) if(keys[fkbmap[x]]) fkbkeys[x]=1; } +#endif } diff --git a/drivers/cli/keyscan.h b/drivers/cli/keyscan.h index af82127..4dc73de 100644 --- a/drivers/cli/keyscan.h +++ b/drivers/cli/keyscan.h @@ -1,5 +1,4 @@ #ifdef SVGALIB - #include #define SCANCODE_DELETE SCANCODE_REMOVE #define SCANCODE_KP_MINUS SCANCODE_KEYPADMINUS @@ -7,6 +6,7 @@ #define MK(k) SCANCODE_##k #define MK_COUNT 256 #elif SDL +#ifndef GP2X #include #define SDLK_A SDLK_a #define SDLK_B SDLK_b @@ -160,7 +160,8 @@ #define SCAN_F10 0x44 #define SCAN_F11 0x57 #define SCAN_F12 0x58 - #define MK_COUNT 256 #define MK(k) SCAN_##k #endif + +#endif diff --git a/drivers/cli/main.c b/drivers/cli/main.c index b65b36d..15a2b5b 100644 --- a/drivers/cli/main.c +++ b/drivers/cli/main.c @@ -46,11 +46,15 @@ #include "dface.h" static int ntsccol=0,ntschue=-1,ntsctint=-1; -static int soundvol=100; -static int inited=0; +int soundvol=70; +int inited=0; +int swapbuttons=0; +int showfps=0; -int srendlinev[2]={8,0}; +int srendlinev[2]={0,0}; +//int srendlinev[2]={0,0}; int erendlinev[2]={239,239}; +//int erendlinev[2]={231,239}; int srendline,erendline; @@ -98,7 +102,7 @@ static void LoadCPalette(void) return; } fread(tmpp,1,192,fp); - FCEUI_SetPaletteArray(tmpp); + FCEUI_SetPaletteArray((uint8 *)tmpp); fclose(fp); } @@ -217,6 +221,8 @@ static void DoArgs(int argc, char *argv[]) {"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE}, {"-slstart",0,&srendlinev[0],0},{"-slend",0,&erendlinev[0],0}, {"-slstartp",0,&srendlinev[1],0},{"-slendp",0,&erendlinev[1],0}, + {"-swapbuttons",&swapbuttons, 0, 0}, + {"-showfps",&showfps, 0, 0}, {0,(void *)DriverArgs,0,0}, {0,0,0,0} }; @@ -236,8 +242,7 @@ static void DoArgs(int argc, char *argv[]) FCEUI_SetVidSystem(1); if(docheckie[1]) FCEUI_SetGameGenie(1); - - FCEUI_DisableSpriteLimitation(eoptions&1); + FCEUI_DisableSpriteLimitation(1); FCEUI_SaveExtraDataUnderBase(eoptions&2); FCEUI_SetSnapName(eoptions&EO_SNAPNAME); @@ -247,7 +252,11 @@ static void DoArgs(int argc, char *argv[]) if(erendlinev[x]239) erendlinev[x]=239; } + printf("main() setrendered lines: %d, %d, %d, %d\n",srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); + printf("main() clip sides %d\n", eoptions&EO_CLIPSIDES); + srendlinev[0]=0; FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); + FCEUI_SetRenderedLines(0,erendlinev[0],srendlinev[1],erendlinev[1]); FCEUI_SetSoundVolume(soundvol); DriverInterface(DES_NTSCCOL,&ntsccol); DoDriverArgs(); diff --git a/drivers/cli/sdl-joystick.c b/drivers/cli/sdl-joystick.c index 1a3fecf..167c777 100644 --- a/drivers/cli/sdl-joystick.c +++ b/drivers/cli/sdl-joystick.c @@ -27,8 +27,8 @@ #include #include "sdl.h" +#ifndef GP2X static SDL_Joystick *jo[4] = {NULL, NULL, NULL, NULL}; - static void ConfigJoystick (int z); #define JOY_A 0x01 @@ -39,10 +39,12 @@ static void ConfigJoystick (int z); #define JOY_DOWN 0x20 #define JOY_LEFT 0x40 #define JOY_RIGHT 0x80 +#endif /* Gets the current joystick position information. */ uint32 GetJSOr (void) { +#ifndef GP2X int n; /* joystick index */ int b; /* button index */ int *joym; /* pointer to a joystick's button map */ @@ -76,11 +78,15 @@ uint32 GetJSOr (void) } return ret; +#else + return 0; +#endif } /* Cleanup opened joysticks. */ void KillJoysticks (void) { +#ifndef GP2X int n; /* joystick index */ for (n = 0; n < 4; n++) @@ -90,11 +96,13 @@ void KillJoysticks (void) } SDL_QuitSubSystem(SDL_INIT_JOYSTICK); return; +#endif } /* Initialize joysticks. */ int InitJoysticks (void) { +#ifndef GP2X int n; /* joystick index */ if(!(joy[0]|joy[1]|joy[2]|joy[3])) return(0); @@ -123,6 +131,7 @@ int InitJoysticks (void) } return (1); +#endif } #define WNOINPUT(); for(;;){uint8 t; if(read(fileno(stdin),&t,1)==-1) \ @@ -131,6 +140,7 @@ int InitJoysticks (void) /* Configure a joystick button. */ static void BConfig (int n, int b) { +#ifndef GP2X SDL_Event event; /* SDL event structure */ WNOINPUT(); while (1) @@ -155,11 +165,13 @@ static void BConfig (int n, int b) WNOINPUT(); return; +#endif } /* Joystick button and axis configuration. */ void ConfigJoystick (int n) { +#ifndef GP2X int sa; /* buffer value */ char buf[128]; /* input buffer */ @@ -197,4 +209,5 @@ void ConfigJoystick (int n) BConfig(n, 0); fcntl(fileno(stdin), F_SETFL, sa); +#endif } diff --git a/drivers/cli/sdl-sound.c b/drivers/cli/sdl-sound.c index bbe716b..c5cd806 100644 --- a/drivers/cli/sdl-sound.c +++ b/drivers/cli/sdl-sound.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2002 Ben Parnell + * Copyright (C) 2002 Xodnizel * * 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 @@ -19,130 +19,124 @@ */ #include +#include +#include +#include +#include +#include +#include +#include + #include "sdl.h" +#include "minimal.h" -#ifndef DSPSOUND +#define GP2X_SOUND 1 -//#define BSIZE (32768-1024) +extern INLINE SpeedThrottle(void); +extern void pthread_yield(void); +extern void FCEUI_FrameSkip(int x); -static int32 BSIZE; -static volatile int16 AudioBuf[32768]; -static volatile uint32 readoffs,writeoffs; -void fillaudio(void *udata, uint8 *stream, int len) -{ - int16 *dest=(int16 *)stream; +//extern int dosound; +extern int soundvol; - len>>=1; - while(len) +// always have this call +INLINE void gp2x_sound_frame(void *blah, void *buff, int samples) { - *dest=AudioBuf[readoffs]; - dest++; - readoffs=(readoffs+1)&32767; - len--; - } } -void WriteSound(int32 *Buffer, int Count, int NoWaiting) -{ - while(Count) - { - while(writeoffs==((readoffs-BSIZE)&32767)) - if(NoWaiting) - return; - AudioBuf[writeoffs]=*Buffer; - writeoffs=(writeoffs+1)&32767; - Buffer++; - Count--; - } -} -int InitSound(void) -{ - if(_sound) - { - SDL_AudioSpec spec; - if(_lbufsize<_ebufsize) + + +//static int sexy_in_function=0; +#define NumSexyBufferBuffers 2 +struct timespec gp2x_sleep_ts; +int firstentry=1; +//int firstprint=1; +struct timeval sleeptimer; + + + +pthread_t gp2x_sexy_sound_thread=0; +int** SexyBufferBuffers=NULL; +int SexyBufferBufferCounts[NumSexyBufferBuffers]; +int gp2x_sound_inited=0; +int gp2x_in_sound_thread=0; +extern unsigned long gp2x_dev[8]; + +pthread_cond_t gp2x_sound_cond=PTHREAD_COND_INITIALIZER; +pthread_mutex_t gp2x_sound_mutex = PTHREAD_MUTEX_INITIALIZER; +int zzdebug01_entry=0; +int zzdebug01_wait=0; +int hasSound=0; +extern unsigned long fps; +extern unsigned long avg_fps; +extern unsigned long framesRendered; +extern unsigned long ticks; + +int throttlecount=0; + +void WriteSound(int32 *Buffer, int Count) { - puts("Ack, lbufsize must not be smaller than ebufsize!"); - return(0); + write(gp2x_dev[3], Buffer, Count<<1); + pthread_yield(); + SpeedThrottle(); } - if(_lbufsize<6 || _lbufsize>13) + +void* gp2x_write_sound(void* blah) { - puts("lbufsize out of range"); - return(0); - } - if(_ebufsize<5) + gp2x_in_sound_thread=1; { - puts("ebufsize out of range"); - return(0); - } - memset(&spec,0,sizeof(spec)); - if(SDL_InitSubSystem(SDL_INIT_AUDIO)<0) + if (hasSound) { - puts(SDL_GetError()); - return(0); + hasSound=0; } - if(_sound==1) _sound=44100; - spec.freq=_sound; - spec.format=AUDIO_S16; - spec.channels=1; - spec.samples=1<<_ebufsize; - spec.callback=fillaudio; - spec.userdata=0; - - if(SDL_OpenAudio(&spec,0)<0) + else { - puts(SDL_GetError()); - SDL_QuitSubSystem(SDL_INIT_AUDIO); - return(0); } - FCEUI_Sound(_sound); - BSIZE=32768-(1<<_lbufsize); - SDL_PauseAudio(0); - return(1); + } - return(0); + gp2x_in_sound_thread=0; + return NULL; } void SilenceSound(int n) { - SDL_PauseAudio(n); - + soundvol=0; } -void KillSound(void) +int InitSound(FCEUGI *gi) { - SDL_CloseAudio(); - SDL_QuitSubSystem(SDL_INIT_AUDIO); + Settings.sound=22050; + FCEUI_Sound(Settings.sound); + gp2x_sound_volume(soundvol, soundvol); + printf("InitSound() sound_rate: %d\n", Settings.sound); + if(firstentry) + { + firstentry=0; + gp2x_sound_inited=1; + } + return 1 ; } -#else -#include "../common/unixdsp.h" - -void WriteSound(int32 *Buffer, int Count, int NoWaiting) +uint32 GetMaxSound(void) { - WriteUNIXDSPSound(Buffer, Count, NoWaiting); + return(4096); } -int InitSound(void) -{ - if(_sound) +uint32 GetWriteSound(void) { - int rate; - if(_sound==1) - _sound=48000; - rate=_sound; - if(InitUNIXDSPSound(&rate,_f8bit?0:1,8,8)) - { - FCEUI_Sound(rate); - return(1); - } - } - return(0); + return 1024; } -void KillSound(void) + +int KillSound(void) { - KillUNIXDSPSound(); + FCEUI_Sound(0); + gp2x_sound_inited=0; + + return 1; } -#endif + + + + diff --git a/drivers/cli/sdl-video.c b/drivers/cli/sdl-video.c index 5ca240c..f2d404c 100644 --- a/drivers/cli/sdl-video.c +++ b/drivers/cli/sdl-video.c @@ -21,14 +21,38 @@ #include #include #include +#include +#include #include "sdl.h" #include "../common/vidblit.h" + +#ifdef GP2X +#include "minimal.h" + +char* fps_str=NULL; +#endif +extern int showfps; + +int stretch_offset=32; + +unsigned long framesRendered; +unsigned long fps; +unsigned long fps_samplecount=0; +unsigned long total_fps=-1; +unsigned long ticks; + +pthread_t gp2x_video_thread=0; +uint8 * XBufHelper=NULL; + + #define _sline srendline #define _eline erendline +#ifndef GP2X SDL_Surface *screen; +#endif static int tlines; static int inited=0; @@ -37,8 +61,125 @@ static int exs,eys,eefx; #define NWIDTH (256-((eoptions&EO_CLIPSIDES)?16:0)) #define NOFFSET (eoptions&EO_CLIPSIDES?8:0) -static void CleanSurface(void) + + +int paletterefresh; +#ifdef GP2X +static int screenSizeInBytes = 320 * 240; +#endif +#define FPS_COLOR 61 + + + + +static unsigned char fontdata8x8[] = +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3C,0x42,0x99,0xBD,0xBD,0x99,0x42,0x3C,0x3C,0x42,0x81,0x81,0x81,0x81,0x42,0x3C, + 0xFE,0x82,0x8A,0xD2,0xA2,0x82,0xFE,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00, + 0x80,0xC0,0xF0,0xFC,0xF0,0xC0,0x80,0x00,0x01,0x03,0x0F,0x3F,0x0F,0x03,0x01,0x00, + 0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0x00,0xEE,0xEE,0xEE,0xCC,0x00,0xCC,0xCC,0x00, + 0x00,0x00,0x30,0x68,0x78,0x30,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00, + 0x3C,0x66,0x7A,0x7A,0x7E,0x7E,0x3C,0x00,0x0E,0x3E,0x3A,0x22,0x26,0x6E,0xE4,0x40, + 0x18,0x3C,0x7E,0x3C,0x3C,0x3C,0x3C,0x00,0x3C,0x3C,0x3C,0x3C,0x7E,0x3C,0x18,0x00, + 0x08,0x7C,0x7E,0x7E,0x7C,0x08,0x00,0x00,0x10,0x3E,0x7E,0x7E,0x3E,0x10,0x00,0x00, + 0x58,0x2A,0xDC,0xC8,0xDC,0x2A,0x58,0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00,0x00, + 0x00,0x10,0x10,0x38,0x38,0x7C,0xFE,0x00,0xFE,0x7C,0x38,0x38,0x10,0x10,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x18,0x00,0x18,0x18,0x00, + 0x6C,0x6C,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00, + 0x10,0x38,0x60,0x38,0x0C,0x78,0x10,0x00,0x40,0xA4,0x48,0x10,0x24,0x4A,0x04,0x00, + 0x18,0x34,0x18,0x3A,0x6C,0x66,0x3A,0x00,0x18,0x18,0x20,0x00,0x00,0x00,0x00,0x00, + 0x30,0x60,0x60,0x60,0x60,0x60,0x30,0x00,0x0C,0x06,0x06,0x06,0x06,0x06,0x0C,0x00, + 0x10,0x54,0x38,0x7C,0x38,0x54,0x10,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00, + 0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00, + 0x38,0x4C,0xC6,0xC6,0xC6,0x64,0x38,0x00,0x18,0x38,0x18,0x18,0x18,0x18,0x7E,0x00, + 0x7C,0xC6,0x0E,0x3C,0x78,0xE0,0xFE,0x00,0x7E,0x0C,0x18,0x3C,0x06,0xC6,0x7C,0x00, + 0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x0C,0x00,0xFC,0xC0,0xFC,0x06,0x06,0xC6,0x7C,0x00, + 0x3C,0x60,0xC0,0xFC,0xC6,0xC6,0x7C,0x00,0xFE,0xC6,0x0C,0x18,0x30,0x30,0x30,0x00, + 0x78,0xC4,0xE4,0x78,0x86,0x86,0x7C,0x00,0x7C,0xC6,0xC6,0x7E,0x06,0x0C,0x78,0x00, + 0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30, + 0x1C,0x38,0x70,0xE0,0x70,0x38,0x1C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00, + 0x70,0x38,0x1C,0x0E,0x1C,0x38,0x70,0x00,0x7C,0xC6,0xC6,0x1C,0x18,0x00,0x18,0x00, + 0x3C,0x42,0x99,0xA1,0xA5,0x99,0x42,0x3C,0x38,0x6C,0xC6,0xC6,0xFE,0xC6,0xC6,0x00, + 0xFC,0xC6,0xC6,0xFC,0xC6,0xC6,0xFC,0x00,0x3C,0x66,0xC0,0xC0,0xC0,0x66,0x3C,0x00, + 0xF8,0xCC,0xC6,0xC6,0xC6,0xCC,0xF8,0x00,0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xFE,0x00, + 0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xC0,0x00,0x3E,0x60,0xC0,0xCE,0xC6,0x66,0x3E,0x00, + 0xC6,0xC6,0xC6,0xFE,0xC6,0xC6,0xC6,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x7E,0x00, + 0x06,0x06,0x06,0x06,0xC6,0xC6,0x7C,0x00,0xC6,0xCC,0xD8,0xF0,0xF8,0xDC,0xCE,0x00, + 0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0xC6,0xEE,0xFE,0xFE,0xD6,0xC6,0xC6,0x00, + 0xC6,0xE6,0xF6,0xFE,0xDE,0xCE,0xC6,0x00,0x7C,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00, + 0xFC,0xC6,0xC6,0xC6,0xFC,0xC0,0xC0,0x00,0x7C,0xC6,0xC6,0xC6,0xDE,0xCC,0x7A,0x00, + 0xFC,0xC6,0xC6,0xCE,0xF8,0xDC,0xCE,0x00,0x78,0xCC,0xC0,0x7C,0x06,0xC6,0x7C,0x00, + 0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00, + 0xC6,0xC6,0xC6,0xEE,0x7C,0x38,0x10,0x00,0xC6,0xC6,0xD6,0xFE,0xFE,0xEE,0xC6,0x00, + 0xC6,0xEE,0x3C,0x38,0x7C,0xEE,0xC6,0x00,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x00, + 0xFE,0x0E,0x1C,0x38,0x70,0xE0,0xFE,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, + 0x60,0x60,0x30,0x18,0x0C,0x06,0x06,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, + 0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, + 0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x66,0x3C,0x00, + 0x60,0x7C,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x3C,0x66,0x60,0x60,0x66,0x3C,0x00, + 0x06,0x3E,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x3C,0x00, + 0x1C,0x30,0x78,0x30,0x30,0x30,0x30,0x00,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x3C, + 0x60,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x00, + 0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x38,0x60,0x60,0x66,0x6C,0x78,0x6C,0x66,0x00, + 0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0xEC,0xFE,0xFE,0xFE,0xD6,0xC6,0x00, + 0x00,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3C,0x00, + 0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06, + 0x00,0x7E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x3C,0x60,0x3C,0x06,0x66,0x3C,0x00, + 0x30,0x78,0x30,0x30,0x30,0x30,0x1C,0x00,0x00,0x66,0x66,0x66,0x66,0x6E,0x3E,0x00, + 0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0xC6,0xD6,0xFE,0xFE,0x7C,0x6C,0x00, + 0x00,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x66,0x66,0x66,0x66,0x3E,0x06,0x3C, + 0x00,0x7E,0x0C,0x18,0x30,0x60,0x7E,0x00,0x0E,0x18,0x0C,0x38,0x0C,0x18,0x0E,0x00, + 0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x70,0x18,0x30,0x1C,0x30,0x18,0x70,0x00, + 0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x10,0x28,0x10,0x54,0xAA,0x44,0x00,0x00, +}; + +static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color, int flip) +{ + int i,l,slen; + slen=strlen(text); + + screen=screen+x+y*320; + + for (i=0;ipitch*screen->h; @@ -46,27 +187,55 @@ static void CleanSurface(void) if(SDL_MUSTLOCK(screen)) SDL_LockSurface(screen); - memset((uint8*)screen->pixels, 0x80, x); + memset((uint8*)screen->pixels, 0x3F, x); if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); SDL_UpdateRect(screen, 0, 0, 0, 0); +#endif } -static int paletterefresh; + void KillVideo(void) { +#ifdef GP2X + if (fps_str) + free(fps_str); + inited&=~1; + + +#else if(inited&1) { SDL_QuitSubSystem(SDL_INIT_VIDEO); } inited=0; +#endif } int InitVideo(void) { +#ifdef GP2X + + + fps_str=malloc(3); + fps_str[0]='5'; fps_str[1]='0'; fps_str[2]=0; + + CleanSurface(); + + + inited|=1; + + puts("Initialized GP2X VIDEO via minimal"); + + srendline=0; + erendline=239; + return 1; + + +#else const SDL_VideoInfo *vinf; int flags=0; @@ -131,11 +300,14 @@ int InitVideo(void) SDL_WM_SetCaption("FCE Ultra","FCE Ultra"); paletterefresh=1; + printf("srendline %d, erendline %d\n", srendline, erendline); return 1; +#endif } void ToggleFS(void) { +#ifndef GP2X KillVideo(); _fullscreen=!_fullscreen; @@ -148,7 +320,11 @@ void ToggleFS(void) exit(1); } } +#endif } + + +#ifndef GP2X static SDL_Color psdl[256]; void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) @@ -172,14 +348,199 @@ static void RedoPalette(void) { SDL_SetPalette(screen,SDL_PHYSPAL,psdl,0,256); } +#else + + + +void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) +{ + gp2x_video_color8(index, r, g, b); + gp2x_video_setpalette(); + + + paletterefresh = 1; +} +void FCEUD_GetPalette(uint8 index, uint8 * r, uint8 * g, uint8 * b) +{ + *r = (uint8) gp2x_palette[(index << 1) + 1]; + *g = (uint8) (gp2x_palette[(index << 1) + 0] >> 8); + *b = (uint8) gp2x_palette[(index << 1) + 0]; +} + +static void RedoPalette(void) +{ +} + + + +unsigned int gp2x_ticks_per_ms=7372800; +int needfpsflip=1; +#ifdef FRAMESKIP +int skipval=16; +int framecount=0; +int numrepeats=0; +int doskipping=0; +#endif + + +INLINE void printFps(uint8 *screen) +{ + int y; + int* destt; + + if (needfpsflip) + { + if (stretch_offset > 0) + { + y=240; + while (y--) + { + + int* dest=(int *) (screen+((y << 8) + (y << 6))+stretch_offset); + + destt=dest - 8; + destt[0]=0x3F3F3F3F; destt[1]=0x3F3F3F3F; destt[2]=0x3F3F3F3F; destt[3]=0x3F3F3F3F; + destt[4]=0x3F3F3F3F; destt[5]=0x3F3F3F3F; destt[6]=0x3F3F3F3F; destt[7]=0x3F3F3F3F; + + destt=dest + 64; + destt[0]=0x3F3F3F3F; destt[1]=0x3F3F3F3F; destt[2]=0x3F3F3F3F; destt[3]=0x3F3F3F3F; + destt[4]=0x3F3F3F3F; destt[5]=0x3F3F3F3F; destt[6]=0x3F3F3F3F; destt[7]=0x3F3F3F3F; + } + if (showfps) + { + gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); + } + } + + if (needfpsflip <= 3) + { + if (showfps) + { + gp2x_text(screen, 0, 0, fps_str, FPS_COLOR, 0); + } + needfpsflip++; + } + else + { + needfpsflip=0; + } + } +#ifdef FRAMESKIP + if ((fps < 59) && doskipping && ((framesRendered % skipval) == (skipval-1))) + { + FCEUI_FrameSkip(1); + } +#endif + if ((framesRendered & 0x3F) != 0x3F) + { + return; + } + + unsigned long currTime=gp2x_timer_read_ms(); + fps= (unsigned long)( framesRendered * 7372800 / (currTime - ticks)); + if (fps > 90) + fps=90; + + if (fps > 30) + { + fps_samplecount++; + total_fps+=fps; + } + if (stretch_offset && showfps) + { + sprintf(fps_str, "%d", (int)fps); + needfpsflip=1; + fps_str[2]=0; + gp2x_text(screen, 0, 0, fps_str, stretch_offset, 0); + } + +#ifdef FRAMESKIP + if (fps < 59) + { + numrepeats++; + if (numrepeats >= 4) + { + if (skipval > 4) + { + skipval-=2; + } + doskipping=1; + printf("skipping every %dth frame, currfps=%d\n", skipval, fps); + numrepeats=0; + } + } + else + { + numrepeats=0; + } +#endif + ticks = currTime; + framesRendered = 0; +} +#endif + + + + + + + + + + void LockConsole(){} void UnlockConsole(){} + + +#ifdef GP2X + +void BlitScreen(uint8 * XBuf) +{ + + int x, y, yinc; + if (!XBuf) return; + XBufHelper=XBuf; + framesRendered++; + XBuf = XBuf ; + + y=240; + yinc=272*(y-1); + while (y--) + { + int* dest=(int *) (gp2x_screen8+((y << 8) + (y << 6))+stretch_offset); + + int* src=(int *) (XBuf+yinc); + x=64; + while (x--) + { + dest[x]=src[x]; + } + yinc-=272; + } + + if (paletterefresh) + { + gp2x_video_setpalette(); + paletterefresh = 0; + } + + printFps(gp2x_screen8); + gp2x_video_flip(); +} + + + + +#else +extern void SpeedThrottle(); void BlitScreen(uint8 *XBuf) { uint8 *dest; int xo=0,yo=0; + SpeedThrottle(); + if(paletterefresh) { RedoPalette(); @@ -210,6 +571,11 @@ void BlitScreen(uint8 *XBuf) SDL_UnlockSurface(screen); SDL_UpdateRect(screen, xo, yo, NWIDTH*exs, tlines*eys); + + if (0) + { + gp2x_text(NULL, 0, 0, NULL, 0, 0); + } } uint32 PtoV(uint16 x, uint16 y) @@ -226,3 +592,4 @@ uint32 PtoV(uint16 x, uint16 y) } return(x|(y<<16)); } +#endif diff --git a/drivers/cli/sdl.c b/drivers/cli/sdl.c index dfa5d40..a2bdc69 100644 --- a/drivers/cli/sdl.c +++ b/drivers/cli/sdl.c @@ -1,12 +1,22 @@ #include #include #include +#include #include "sdl.h" #include "sdl-video.h" #ifdef NETWORK #include "unix-netplay.h" #endif +#include "minimal.h" +//extern int soundvol; +int CLImain(int argc, char *argv[]); +extern int gp2x_in_sound_thread; +extern void pthread_yield(void); +extern void SetVideoScaling(int, int, int); + +//#define SOUND_RATE 44100 +#define SOUND_RATE 22050 DSETTINGS Settings; CFGSTRUCT DriverConfig[]={ @@ -63,7 +73,9 @@ char *DriverUsage= -server Be a host/server for TCP/IP network play.\n\ -netport x Use TCP/IP port x for network play."; +#ifdef NETWORK static int docheckie[2]={0,0}; +#endif ARGPSTRUCT DriverArgs[]={ {"-joy1",0,&joy[0],0},{"-joy2",0,&joy[1],0}, {"-joy3",0,&joy[2],0},{"-joy4",0,&joy[3],0}, @@ -92,12 +104,38 @@ ARGPSTRUCT DriverArgs[]={ {0,0,0,0} }; + + + + +void GetBaseDirectory(char *BaseDirectory) +{ + char *ol; + +#ifdef GP2X + ol="/mnt/sd/roms/nes"; +#else + ol=getenv("HOME"); +#endif + BaseDirectory[0]=0; + if(ol) + { + strncpy(BaseDirectory,ol,2047); + BaseDirectory[2047]=0; +#ifdef GP2X + strcat(BaseDirectory,"/fceultra"); +#else + strcat(BaseDirectory,"/.fceultra"); +#endif + } +} + static void SetDefaults(void) { _xres=320; _yres=240; _fullscreen=0; - _sound=48000; + _sound=SOUND_RATE; // 48000 wrong #ifdef DSPSOUND _f8bit=0; #else @@ -150,6 +188,7 @@ int InitMouse(void) void KillMouse(void){} void GetMouseData(uint32 *d) { +#ifndef GP2X int x,y; uint32 t; @@ -162,6 +201,7 @@ void GetMouseData(uint32 *d) t=PtoV(x,y); d[0]=t&0xFFFF; d[1]=(t>>16)&0xFFFF; +#endif } int InitKeyboard(void) @@ -181,14 +221,63 @@ void KillKeyboard(void) char *GetKeyboard(void) { +#ifndef GP2X SDL_PumpEvents(); - return(SDL_GetKeyState(0)); + return (char *)(SDL_GetKeyState(0)); +#else + return NULL; +#endif } #include "unix-basedir.h" +extern int showfps; +extern int swapbuttons; int main(int argc, char *argv[]) { - puts("\nStarting FCE Ultra "VERSION_STRING"...\n"); + + puts("Starting GPFCE - Port version 0.2 05-29-2006"); + puts("Based on FCE Ultra "VERSION_STRING"..."); + puts("Ported by Zheng Zhu\n"); +#ifdef GP2X + // stereo + //gp2x_init (1000, 8, SOUND_RATE, 16, 1, 60); + + // mono 44khz + //gp2x_init (1000, 8, SOUND_RATE<<1, 16, 0, 60); + // mono 22khz + gp2x_init (1000, 8, SOUND_RATE, 16, 0, 60); + + SetDefaults(); + int ret=CLImain(argc,argv); + + // unscale the screen, in case this is bad. + SetVideoScaling(320, 320, 240); + + gp2x_deinit(); + // make sure sound thread has exited cleanly + while (gp2x_in_sound_thread) pthread_yield(); + printf("Sound thread exited\n"); + printf("Exiting main(). terminated"); + if (showfps && swapbuttons) + { + execl("./selector","./selector","./gpfce_showfps_swapbuttons_config",NULL); + } + else if (showfps) + { + execl("./selector","./selector","./gpfce_showfps_config",NULL); + } + else if (swapbuttons) + { + execl("./selector","./selector","./gpfce_swapbuttons_config",NULL); + } + else + { + execl("./selector","./selector","./gpfce_config",NULL); + } + return(ret?0:-1); +#else + gp2x_init (1000, 8, SOUND_RATE, 16, 1, 60); + if(SDL_Init(0)) { printf("Could not initialize SDL: %s.\n", SDL_GetError()); @@ -209,7 +298,12 @@ int main(int argc, char *argv[]) { int ret=CLImain(argc,argv); SDL_Quit(); + // make sure sound thread has exited cleanly + while (gp2x_in_sound_thread) pthread_yield(); + printf("Sound thread exited\n"); + printf("Exiting main(). terminated"); return(ret); } +#endif } diff --git a/drivers/cli/sdl.h b/drivers/cli/sdl.h index a235951..f8b2bab 100644 --- a/drivers/cli/sdl.h +++ b/drivers/cli/sdl.h @@ -1,4 +1,6 @@ +#ifndef GP2X #include +#endif #include "../../driver.h" #include "../common/args.h" #include "../common/config.h" diff --git a/drivers/cli/svgalib.c b/drivers/cli/svgalib.c index 7d293e9..3e3cd4d 100644 --- a/drivers/cli/svgalib.c +++ b/drivers/cli/svgalib.c @@ -15,7 +15,7 @@ #include "lnx-joystick.h" #include "unix-netplay.h" -static int soundo=48000; +//static int soundo=0; static int f8bit=0; static int sfragsize=7,snfrags=8; @@ -90,9 +90,10 @@ void DoDriverArgs(void) for(x=0;x<4;x++) if(!joy[x]) memset(joyBMap[x],0,4*sizeof(int)); } - +/* int InitSound(void) { + printf("Called InitSound svgalib.c\n"); if(soundo) { int rate; @@ -106,7 +107,7 @@ int InitSound(void) } } return(0); -} +}*/ void WriteSound(int32 *Buffer, int Count, int NoWaiting) { diff --git a/drivers/cli/throttle.c b/drivers/cli/throttle.c index 604cef7..91879ae 100644 --- a/drivers/cli/throttle.c +++ b/drivers/cli/throttle.c @@ -7,7 +7,10 @@ static uint64 desiredfps; void RefreshThrottleFPS(void) { - desiredfps=FCEUI_GetDesiredFPS()>>8; + uint64 f=FCEUI_GetDesiredFPS(); + // great, a bit faster than before + //f = (f*65) >> 6; + desiredfps=f>>8; tfreq=1000000; tfreq<<=16; /* Adjustment for fps returned from FCEUI_GetDesiredFPS(). */ } @@ -23,7 +26,7 @@ static uint64 GetCurTime(void) return(ret); } -void SpeedThrottle(void) +INLINE void SpeedThrottle(void) { static uint64 ttime,ltime; @@ -32,7 +35,9 @@ void SpeedThrottle(void) ttime=GetCurTime(); if( (ttime-ltime) < (tfreq/desiredfps) ) + { goto waiter; + } if( (ttime-ltime) >= (tfreq*4/desiredfps)) ltime=ttime; else diff --git a/drivers/cli/throttle.h b/drivers/cli/throttle.h index 0b0ad9f..0ea9365 100644 --- a/drivers/cli/throttle.h +++ b/drivers/cli/throttle.h @@ -1,2 +1,2 @@ void RefreshThrottleFPS(void); -void SpeedThrottle(void); +INLINE void SpeedThrottle(void); diff --git a/drivers/cli/unix-basedir.h b/drivers/cli/unix-basedir.h index 4f6808c..e69de29 100644 --- a/drivers/cli/unix-basedir.h +++ b/drivers/cli/unix-basedir.h @@ -1,15 +0,0 @@ -#include -void GetBaseDirectory(char *BaseDirectory) -{ - char *ol; - - ol=getenv("HOME"); - BaseDirectory[0]=0; - if(ol) - { - strncpy(BaseDirectory,ol,2047); - BaseDirectory[2047]=0; - strcat(BaseDirectory,"/.fceultra"); - } -} - diff --git a/drivers/cli/unix-netplay.c b/drivers/cli/unix-netplay.c index d5d1cc4..8e777db 100644 --- a/drivers/cli/unix-netplay.c +++ b/drivers/cli/unix-netplay.c @@ -30,8 +30,9 @@ #ifndef socklen_t #define socklen_t int #endif - +#ifdef NETWORK static int Socket=-1; +#endif #include "main.h" #include "unix-netplay.h" @@ -41,6 +42,7 @@ int netplay=0; int FCEUD_NetworkConnect(void) { +#ifdef NETWORK struct sockaddr_in sockn; int TSocket; @@ -105,6 +107,7 @@ int FCEUD_NetworkConnect(void) } Socket=TSocket; } +#endif return(1); } @@ -114,6 +117,7 @@ int FCEUD_NetworkConnect(void) int FCEUD_NetworkRecvData(uint8 *data, uint32 len, int block) { +#ifdef NETWORK if(block) { int t; @@ -140,19 +144,28 @@ int FCEUD_NetworkRecvData(uint8 *data, uint32 len, int block) } return(1); } +#else + return 1; +#endif } /* 0 on failure, 1 on success. This function should always block. */ int FCEUD_NetworkSendData(uint8 *Value, uint32 len) { +#ifdef NETWORK return(send(Socket,Value,len,0)==len); +#else + return 0; +#endif } void FCEUD_NetworkClose(void) { +#ifdef NETWORK if(Socket>0) close(Socket); Socket=-1; +#endif } diff --git a/fce.c b/fce.c index 653a3f6..5b72b3b 100644 --- a/fce.c +++ b/fce.c @@ -46,13 +46,14 @@ #include "input.h" #include "file.h" #include "crc32.h" +#include "ppu.h" #define Pal (PALRAM) -static void FetchSpriteData(void); + static void FASTAPASS(1) RefreshLine(uint8 *target); static void PRefreshLine(void); -static void FASTAPASS(1) RefreshSprite(uint8 *target); + static void ResetPPU(void); static void PowerPPU(void); @@ -81,7 +82,7 @@ uint8 PPUCHRRAM; static uint8 deemp=0; static int deempcnt[8]; -static int tosprite=256; +int tosprite=256; FCEUGI FCEUGameInfo; void (*GameInterface)(int h); @@ -198,7 +199,6 @@ uint8 XOffset=0; uint32 TempAddr,RefreshAddr; -static int maxsprites=8; /* scanline is equal to the current visible scanline we're on. */ @@ -209,12 +209,12 @@ uint8 PPU[4]; uint8 PPUSPL; uint8 GameMemBlock[131072]; -uint8 NTARAM[0x800],PALRAM[0x20],SPRAM[0x100],SPRBUF[0x100]; +uint8 NTARAM[0x800],PALRAM[0x20]; uint8 RAM[0x800]; uint8 PAL=0; -#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V)>>10][(V)] + #define MMC5BGVRAMADR(V) &MMC5BGVPage[(V)>>10][(V)] #define VRAMADR(V) &VPage[(V)>>10][(V)] @@ -320,6 +320,7 @@ static DECLFW(B2004) PPUSPL++; } PPU[3]++; + } static DECLFW(B2005) @@ -401,7 +402,7 @@ static DECLFW(B4014) X6502_AddCycles(512); } -static void FASTAPASS(1) BGRender(uint8 *target) +void BGRender(uint8 *target) { uint32 tem; RefreshLine(target); @@ -414,7 +415,8 @@ static void FASTAPASS(1) BGRender(uint8 *target) } #ifdef FRAMESKIP -static int FSkip=0; +extern int framesRendered; +int FSkip=0; void FCEUI_FrameSkip(int x) { FSkip=x; @@ -524,7 +526,7 @@ static void FASTAPASS(1) RefreshLine(uint8 *target) { uint32 vofs; int X1; - register uint8 *P=target; + uint8 *P=target; vofs=0; @@ -551,7 +553,7 @@ static void FASTAPASS(1) RefreshLine(uint8 *target) for(X1=33;X1;X1--,P+=8) { uint8 *C; - register uint8 cc,zz,zz2; + uint8 cc,zz,zz2; uint32 vadr; if((tochange<=0 && MMC5HackSPMode&0x40) || @@ -597,8 +599,8 @@ static void FASTAPASS(1) RefreshLine(uint8 *target) for(X1=33;X1;X1--,P+=8) { uint8 *C; - register uint8 cc; - register uint8 zz2; + uint8 cc; + uint8 zz2; uint32 vadr; if((tochange<=0 && MMC5HackSPMode&0x40) || @@ -641,8 +643,8 @@ static void FASTAPASS(1) RefreshLine(uint8 *target) for(X1=33;X1;X1--,P+=8) { uint8 *C; - register uint8 cc; - register uint8 zz2; + uint8 cc; + uint8 zz2; uint32 vadr; C=MMC5HackVROMPTR; @@ -665,7 +667,7 @@ static void FASTAPASS(1) RefreshLine(uint8 *target) for(X1=33;X1;X1--,P+=8) { uint8 *C; - register uint8 cc,zz,zz2; + uint8 cc,zz,zz2; uint32 vadr; zz=RefreshAddr&0x1F; @@ -690,7 +692,7 @@ static void FASTAPASS(1) RefreshLine(uint8 *target) for(X1=33;X1;X1--,P+=8) { uint8 *C; - register uint8 cc,zz,zz2; + uint8 cc,zz,zz2; uint32 vadr; zz=RefreshAddr&0x1F; @@ -716,7 +718,7 @@ static void FASTAPASS(1) RefreshLine(uint8 *target) for(X1=33;X1;X1--,P+=8) { uint8 *C; - register uint8 cc,zz,zz2; + uint8 cc,zz,zz2; uint32 vadr; zz=RefreshAddr&0x1F; @@ -805,379 +807,25 @@ static void DoHBlank(void) //fprintf(stderr,"%3d: $%04x\n",scanline,RefreshAddr); } -#define V_FLIP 0x80 -#define H_FLIP 0x40 -#define SP_BACK 0x20 - -typedef struct { - uint8 y,no,atr,x; -} SPR; - -typedef struct { - uint8 ca[2],atr,x; -} SPRB; - -uint8 sprlinebuf[256+8]; - -void FCEUI_DisableSpriteLimitation(int a) -{ - maxsprites=a?64:8; -} - -static uint8 nosprites,SpriteBlurp; -static void FetchSpriteData(void) -{ - SPR *spr; - uint8 H; - int n,vofs; - spr=(SPR *)SPRAM; - H=8; - - nosprites=SpriteBlurp=0; - - vofs=(unsigned int)(PPU[0]&0x8&(((PPU[0]&0x20)^0x20)>>2))<<9; - H+=(PPU[0]&0x20)>>2; - - if(!PPU_hook) - for(n=63;n>=0;n--,spr++) - { - if((unsigned int)(scanline-spr->y)>=H) continue; - - if(nospritesy); - - if (Sprite16) - vadr = ((spr->no&1)<<12) + ((spr->no&0xFE)<<4); - else - vadr = (spr->no<<4)+vofs; - - if (spr->atr&V_FLIP) - { - vadr+=7; - vadr-=t; - vadr+=(PPU[0]&0x20)>>1; - vadr-=t&8; - } - else - { - vadr+=t; - vadr+=t&8; - } - - /* Fix this geniestage hack */ - if(MMC5Hack && geniestage!=1) C = MMC5SPRVRAMADR(vadr); - else C = VRAMADR(vadr); - - - dst.ca[0]=C[0]; - dst.ca[1]=C[8]; - dst.x=spr->x; - dst.atr=spr->atr; - - - *(uint32 *)&SPRBUF[nosprites<<2]=*(uint32 *)&dst; - } - - nosprites++; - } - else - { - PPU_status|=0x20; - break; - } - } - else - for(n=63;n>=0;n--,spr++) - { - if((unsigned int)(scanline-spr->y)>=H) continue; - - if(nospritesy); - - if (Sprite16) - vadr = ((spr->no&1)<<12) + ((spr->no&0xFE)<<4); - else - vadr = (spr->no<<4)+vofs; - - if (spr->atr&V_FLIP) - { - vadr+=7; - vadr-=t; - vadr+=(PPU[0]&0x20)>>1; - vadr-=t&8; - } - else - { - vadr+=t; - vadr+=t&8; - } - - if(MMC5Hack) C = MMC5SPRVRAMADR(vadr); - else C = VRAMADR(vadr); - dst.ca[0]=C[0]; - PPU_hook(vadr); - dst.ca[1]=C[8]; - PPU_hook(vadr|8); - dst.x=spr->x; - dst.atr=spr->atr; - - - *(uint32 *)&SPRBUF[nosprites<<2]=*(uint32 *)&dst; - } - - nosprites++; - } - else - { - PPU_status|=0x20; - break; - } - } -} -static void FASTAPASS(1) RefreshSprite(uint8 *target) -{ - int n; - SPRB *spr; - uint8 *P=target; - if(!nosprites) return; - #ifdef FRAMESKIP - if(FSkip) - { - if(!SpriteBlurp) - { - nosprites=0; - return; - } - else - nosprites=1; - } - #endif - FCEU_dwmemset(sprlinebuf,0x80808080,256); - nosprites--; - spr = (SPRB*)SPRBUF+nosprites; - for(n=nosprites;n>=0;n--,spr--) - { - register uint8 J,atr,c1,c2; - int x=spr->x; - uint8 *C; - uint8 *VB; - - P+=x; - - c1=((spr->ca[0]>>1)&0x55)|(spr->ca[1]&0xAA); - c2=(spr->ca[0]&0x55)|((spr->ca[1]<<1)&0xAA); - - J=spr->ca[0]|spr->ca[1]; - atr=spr->atr; - - if(J) - { - if(n==0 && SpriteBlurp && !(PPU_status&0x40)) - { - int z,ze=x+8; - if(ze>256) {ze=256;} - if(ScreenON && (scanlineFSettings.LastSLine - #ifdef FRAMESKIP - || FSkip - #endif - )) - BGRender(target); - - if(!(atr&H_FLIP)) - { - for(z=x;z>(z-x))) - { - if(!(target[z]&64)) - tosprite=z; - } - } - } - else - { - for(z=x;z>=2;c2>>=2; - if (J&0x08) C[3]=VB[c1&3]|0x40;; - if (J&0x04) C[2]=VB[c2&3]|0x40;; - c1>>=2;c2>>=2; - if (J&0x20) C[5]=VB[c1&3]|0x40;; - if (J&0x10) C[4]=VB[c2&3]|0x40;; - c1>>=2;c2>>=2; - if (J&0x80) C[7]=VB[c1]|0x40;; - if (J&0x40) C[6]=VB[c2]|0x40;; - } else { - if (J&0x02) C[6]=VB[c1&3]|0x40; - if (J&0x01) C[7]=VB[c2&3]|0x40; - c1>>=2;c2>>=2; - if (J&0x08) C[4]=VB[c1&3]|0x40; - if (J&0x04) C[5]=VB[c2&3]|0x40; - c1>>=2;c2>>=2; - if (J&0x20) C[2]=VB[c1&3]|0x40; - if (J&0x10) C[3]=VB[c2&3]|0x40; - c1>>=2;c2>>=2; - if (J&0x80) *C=VB[c1]|0x40; - if (J&0x40) C[1]=VB[c2]|0x40; - } - } else { - if (atr&H_FLIP) - { - if (J&0x02) C[1]=VB[(c1&3)]; - if (J&0x01) *C=VB[(c2&3)]; - c1>>=2;c2>>=2; - if (J&0x08) C[3]=VB[(c1&3)]; - if (J&0x04) C[2]=VB[(c2&3)]; - c1>>=2;c2>>=2; - if (J&0x20) C[5]=VB[(c1&3)]; - if (J&0x10) C[4]=VB[(c2&3)]; - c1>>=2;c2>>=2; - if (J&0x80) C[7]=VB[c1]; - if (J&0x40) C[6]=VB[c2]; - }else{ - if (J&0x02) C[6]=VB[(c1&3)]; - if (J&0x01) C[7]=VB[(c2&3)]; - c1>>=2;c2>>=2; - if (J&0x08) C[4]=VB[(c1&3)]; - if (J&0x04) C[5]=VB[(c2&3)]; - c1>>=2;c2>>=2; - if (J&0x20) C[2]=VB[(c1&3)]; - if (J&0x10) C[3]=VB[(c2&3)]; - c1>>=2;c2>>=2; - if (J&0x80) *C=VB[c1]; - if (J&0x40) C[1]=VB[c2]; - } - } - } - P-=x; - } - nosprites=0; - #ifdef FRAMESKIP - if(FSkip) return; - #endif - { - uint8 n=((PPU[1]&4)^4)<<1; - loopskie: - { - uint32 t=*(uint32 *)(sprlinebuf+n); - if(t!=0x80808080) - { - #ifdef LSB_FIRST - if(!(t&0x80)) - { - if(!(t&0x40)) // Normal sprite - P[n]=sprlinebuf[n]; - else if(P[n]&64) // behind bg sprite - P[n]=sprlinebuf[n]; - } - if(!(t&0x8000)) - { - if(!(t&0x4000)) // Normal sprite - P[n+1]=(sprlinebuf+1)[n]; - else if(P[n+1]&64) // behind bg sprite - P[n+1]=(sprlinebuf+1)[n]; - } - if(!(t&0x800000)) - { - if(!(t&0x400000)) // Normal sprite - P[n+2]=(sprlinebuf+2)[n]; - else if(P[n+2]&64) // behind bg sprite - P[n+2]=(sprlinebuf+2)[n]; - } - if(!(t&0x80000000)) - { - if(!(t&0x40000000)) // Normal sprite - P[n+3]=(sprlinebuf+3)[n]; - else if(P[n+3]&64) // behind bg sprite - P[n+3]=(sprlinebuf+3)[n]; - } - #else - if(!(t&0x80000000)) - { - if(!(t&0x40)) // Normal sprite - P[n]=sprlinebuf[n]; - else if(P[n]&64) // behind bg sprite - P[n]=sprlinebuf[n]; - } - if(!(t&0x800000)) - { - if(!(t&0x4000)) // Normal sprite - P[n+1]=(sprlinebuf+1)[n]; - else if(P[n+1]&64) // behind bg sprite - P[n+1]=(sprlinebuf+1)[n]; - } - if(!(t&0x8000)) - { - if(!(t&0x400000)) // Normal sprite - P[n+2]=(sprlinebuf+2)[n]; - else if(P[n+2]&64) // behind bg sprite - P[n+2]=(sprlinebuf+2)[n]; - } - if(!(t&0x80)) - { - if(!(t&0x40000000)) // Normal sprite - P[n+3]=(sprlinebuf+3)[n]; - else if(P[n+3]&64) // behind bg sprite - P[n+3]=(sprlinebuf+3)[n]; - } - #endif - } - } - n+=4; - if(n) goto loopskie; - } -} +// ============================// +// end of new code +// ===========================// void ResetMapping(void) { @@ -1346,7 +994,7 @@ int FCEUI_Initialize(void) FSettings.UsrFirstSLine[0]=8; FSettings.UsrFirstSLine[1]=0; FSettings.UsrLastSLine[0]=FSettings.UsrLastSLine[1]=239; - FSettings.SoundVolume=65536; // 100% + FSettings.SoundVolume=65535; // 100% return 1; } @@ -1462,13 +1110,14 @@ void EmLoop(void) { FCEU_PutImageDummy(); FSkip--; - FCEUD_Update(0,WaveFinal,ssize); + framesRendered++; + FCEUD_Update(0,WaveFinalMono,ssize); } else #endif { FCEU_PutImage(); - FCEUD_Update(XBuf+8,WaveFinal,ssize); + FCEUD_Update(XBuf+8,WaveFinalMono,ssize); } UpdateInput(); } diff --git a/fce.h b/fce.h index ba90d75..6c4865c 100644 --- a/fce.h +++ b/fce.h @@ -30,8 +30,11 @@ extern uint8 MMC5HackSPMode; extern uint8 MMC5HackSPScroll; extern uint8 MMC5HackSPPage; -extern uint8 RAM[0x800],SPRAM[0x100],NTARAM[0x800],PALRAM[0x20],SPRAM[0x100],SPRBUF[0x100]; extern uint8 GameMemBlock[131072]; +extern uint8 NTARAM[0x800],PALRAM[0x20]; + +extern uint8 RAM[0x800]; + extern uint32 RefreshAddr,TempAddr; extern uint8 vtoggle,XOffset,VRAMBuffer,PPUGenLatch; diff --git a/fceline.h b/fceline.h index 5ba0ab7..d79e9df 100644 --- a/fceline.h +++ b/fceline.h @@ -1,100 +1,6 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 BERO - * Copyright (C) 2002 Ben Parnell - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifdef C80x86 -{ - int dummy,dummy1,dummy2; - __asm__ __volatile__( - "xorl %%edx,%%edx\n\t" - "movb (%%esi),%%cl\n\t" - "movb 8(%%esi),%%dl\n\t" - "movl %%ebx,%%esi\n\t" - "addl %%eax,%%esi\n\t" - "xorl %%ebx,%%ebx\n\t" - "movb %%cl,%%bl\n\t" - "movb %%dl,%%al\n\t" - "shrb $1,%%bl\n\t" - "andb $0xaa,%%al\n\t" - "andb $0x55,%%bl\n\t" - - "andb $0x55,%%cl\n\t" - "shlb $1,%%dl\n\t" - "andb $0xaa,%%dl\n\t" - "orb %%al, %%bl\n\t" // Stick c1 into bl - "orb %%cl, %%dl\n\t" // Stick c2 into dl - "xorl %%eax, %%eax\n\t" - "xorl %%ecx, %%ecx\n\t" - /* At this point, bl contains c1, and dl contains c2 */ - /* and edi contains P, esi contains VRAM[] */ - /* al will be used for zz, cl will be used for zz2 */ - "movb %%bl,%%al\n\t" - "movb %%dl,%%cl\n\t" - "andb $3,%%al\n\t" - "andb $3,%%cl\n\t" - "movb (%%esi,%%eax),%%bh\n\t" - "movb (%%esi,%%ecx),%%dh\n\t" - "movb %%bh,6(%%edi)\n\t" - "movb %%dh,7(%%edi)\n\t" - - "movb %%bl,%%al\n\t" - "movb %%dl,%%cl\n\t" - "shrb $2,%%al\n\t" - "shrb $2,%%cl\n\t" - "andb $3,%%al\n\t" - "andb $3,%%cl\n\t" - "movb (%%esi,%%eax),%%bh\n\t" - "movb (%%esi,%%ecx),%%dh\n\t" - "movb %%bh,4(%%edi)\n\t" - "movb %%dh,5(%%edi)\n\t" - - "movb %%bl,%%al\n\t" - "movb %%dl,%%cl\n\t" - "shrb $4,%%al\n\t" - "shrb $4,%%cl\n\t" - "andb $3,%%al\n\t" - "andb $3,%%cl\n\t" - "movb (%%esi,%%eax),%%bh\n\t" - "movb (%%esi,%%ecx),%%dh\n\t" - "movb %%bh,2(%%edi)\n\t" - "movb %%dh,3(%%edi)\n\t" - -// "movb %%bl,%%al\n\t" -// "movb %%dl,%%cl\n\t" - "xorb %%bh,%%bh\n\t" - "xorb %%dh,%%dh\n\t" - "shrb $6,%%bl\n\t" - "shrb $6,%%dl\n\t" - "movb (%%esi,%%ebx),%%al\n\t" - "movb (%%esi,%%edx),%%cl\n\t" - "movb %%al,0(%%edi)\n\t" - "movb %%cl,1(%%edi)\n\t" - : "=S" (dummy), "=a" (dummy1), "=b" (dummy2) - : "D" (P), "S" (C), "a" (cc), "b" (PALRAM) - : "%ecx", "%edx" - ); - -} -#else { uint8 *S=PALRAM+cc; - register uint8 c1,c2; + uint8 c1,c2; c1=((C[0]>>1)&0x55)|(C[8]&0xAA); c2=(C[0]&0x55)|((C[8]<<1)&0xAA); @@ -109,4 +15,3 @@ P[0]=S[c1>>6]; P[1]=S[c2>>6]; } -#endif diff --git a/general.c b/general.c index b0c1942..4b0c0cf 100644 --- a/general.c +++ b/general.c @@ -63,54 +63,54 @@ char *FCEU_MakeFName(int type, int id1, char *cd1) switch(type) { case FCEUMKF_STATE:if(odirs[FCEUIOD_STATE]) - sprintf(ret,"%s"PSS"%s.fc%d",odirs[FCEUIOD_STATE],FileBase,id1); + sprintf(((char*)ret),"%s"PSS"%s.fc%d",odirs[FCEUIOD_STATE],FileBase,id1); else - sprintf(ret,"%s"PSS"fcs"PSS"%s.fc%d",BaseDirectory,FileBase,id1); + sprintf(((char*)ret),"%s"PSS"fcs"PSS"%s.fc%d",BaseDirectory,FileBase,id1); break; case FCEUMKF_SNAP: if(FSettings.SnapName) { if(odirs[FCEUIOD_SNAPS]) - sprintf(ret,"%s"PSS"%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1); + sprintf(((char*)ret),"%s"PSS"%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1); else - sprintf(ret,"%s"PSS"snaps"PSS"%s-%d.%s",BaseDirectory,FileBase,id1,cd1); + sprintf(((char*)ret),"%s"PSS"snaps"PSS"%s-%d.%s",BaseDirectory,FileBase,id1,cd1); } else { if(odirs[FCEUIOD_SNAPS]) - sprintf(ret,"%s"PSS"%d.%s",odirs[FCEUIOD_SNAPS],id1,cd1); + sprintf(((char*)ret),"%s"PSS"%d.%s",odirs[FCEUIOD_SNAPS],id1,cd1); else - sprintf(ret,"%s"PSS"snaps"PSS"%d.%s",BaseDirectory,id1,cd1); + sprintf(((char*)ret),"%s"PSS"snaps"PSS"%d.%s",BaseDirectory,id1,cd1); } break; case FCEUMKF_SAV:if(odirs[FCEUIOD_NV]) { - sprintf(ret,"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); + sprintf(((char*)ret),"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); } else { if(FSettings.SUnderBase) - sprintf(ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1); + sprintf(((char*)ret),"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1); else - sprintf(ret,"%s"PSS"%s.%s",FileBaseDirectory,FileBase,cd1); + sprintf(((char*)ret),"%s"PSS"%s.%s",FileBaseDirectory,FileBase,cd1); } break; case FCEUMKF_CHEAT: if(odirs[FCEUIOD_CHEATS]) - sprintf(ret,"%s"PSS"%s.cht",odirs[FCEUIOD_CHEATS],FileBase); + sprintf(((char*)ret),"%s"PSS"%s.cht",odirs[FCEUIOD_CHEATS],FileBase); else - sprintf(ret,"%s"PSS"cheats"PSS"%s.cht",BaseDirectory,FileBase); + sprintf(((char*)ret),"%s"PSS"cheats"PSS"%s.cht",BaseDirectory,FileBase); break; - case FCEUMKF_GGROM:sprintf(ret,"%s"PSS"gg.rom",BaseDirectory);break; - case FCEUMKF_FDSROM:sprintf(ret,"%s"PSS"disksys.rom",BaseDirectory);break; + case FCEUMKF_GGROM:sprintf(((char*)ret),"%s"PSS"gg.rom",BaseDirectory);break; + case FCEUMKF_FDSROM:sprintf(((char*)ret),"%s"PSS"disksys.rom",BaseDirectory);break; case FCEUMKF_PALETTE: if(odirs[FCEUIOD_MISC]) - sprintf(ret,"%s"PSS"%s.pal",odirs[FCEUIOD_MISC],FileBase); + sprintf(((char*)ret),"%s"PSS"%s.pal",odirs[FCEUIOD_MISC],FileBase); else - sprintf(ret,"%s"PSS"gameinfo"PSS"%s.pal",BaseDirectory,FileBase); + sprintf(((char*)ret),"%s"PSS"gameinfo"PSS"%s.pal",BaseDirectory,FileBase); break; } - return(ret); + return((char *)ret); } void GetFileBase(char *f) diff --git a/input.c b/input.c index be6b360..5bf8e96 100644 --- a/input.c +++ b/input.c @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - +#include #include "types.h" #include "x6502.h" diff --git a/mappers/simple.c b/mappers/simple.c index 8f1ad74..9318933 100644 --- a/mappers/simple.c +++ b/mappers/simple.c @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - +#include #include "mapinc.h" static uint8 latche; @@ -57,6 +57,7 @@ DECLFW(Mapper7_write) void Mapper7_init(void) { onemir(0); + ROM_BANK32(0); SetWriteHandler(0x8000,0xFFFF,Mapper7_write); AddExState(&latche, 1, 0, "LATC"); } @@ -229,7 +230,7 @@ static DECLFW(Mapper96_write) static void FP_FASTAPASS(1) M96Hook(uint32 A) { - if(A<0x2000) + if((A&0x3000)!=0x2000) return; M96LA=(A>>8)&3; setchr4r(0x10,0x0000,(latche&4)|M96LA); diff --git a/memory.c b/memory.c index bec7270..8fb701d 100644 --- a/memory.c +++ b/memory.c @@ -40,6 +40,8 @@ void FCEU_free(void *ptr) // Might do something with this and FCEU_malloc later free(ptr); } + + void FASTAPASS(3) FCEU_memmove(void *d, void *s, uint32 l) { uint32 x; @@ -51,17 +53,32 @@ void FASTAPASS(3) FCEU_memmove(void *d, void *s, uint32 l) t|=(int)l; if(t&3) // Not 4-byte aligned and/or length is not a multiple of 4. + { + uint8 *tmpd, *tmps; + + tmpd = d; + tmps = s; + for(x=l;x;x--) // This could be optimized further, though(more tests could be performed). { - *(uint8*)d=*(uint8 *)s; - ((uint8 *)d)++; - ((uint8 *)s)++; + *tmpd=*tmps; + tmpd++; + tmps++; + } } else + { + uint32 *tmpd, *tmps; + + tmpd = d; + tmps = s; + for(x=l>>2;x;x--) { - *(uint32*)d=*(uint32*)s; - ((uint32 *)d)++; - ((uint32 *)s)++; + *tmpd=*tmps; + tmpd++; + tmps++; } } +} + diff --git a/nsf.c b/nsf.c index cadb726..2d287d2 100644 --- a/nsf.c +++ b/nsf.c @@ -383,13 +383,13 @@ void DrawNSF(uint8 *XBuf) tmpb=NSFBG+8; z=(z+1)&127; - DrawTextTrans(XBuf+10*272+4+(((31-strlen(NSFHeader.SongName))<<2)), 272, NSFHeader.SongName, 38); - DrawTextTrans(XBuf+30*272+4+(((31-strlen(NSFHeader.Artist))<<2)), 272, NSFHeader.Artist, 38); - DrawTextTrans(XBuf+50*272+4+(((31-strlen(NSFHeader.Copyright))<<2)), 272, NSFHeader.Copyright, 38); + DrawTextTrans(XBuf+10*272+4+(((31-strlen((char *)(NSFHeader.SongName)))<<2)), 272, NSFHeader.SongName, 38); + DrawTextTrans(XBuf+30*272+4+(((31-strlen((char *)(NSFHeader.Artist)))<<2)), 272, NSFHeader.Artist, 38); + DrawTextTrans(XBuf+50*272+4+(((31-strlen((char *)(NSFHeader.Copyright)))<<2)), 272, NSFHeader.Copyright, 38); - DrawTextTrans(XBuf+90*272+4+(((31-strlen("Song:"))<<2)), 272, "Song:", 38); + DrawTextTrans(XBuf+90*272+4+(((31-strlen("Song:"))<<2)), 272, (uint8 *)"Song:", 38); sprintf(snbuf,"<%d/%d>",CurrentSong,NSFHeader.TotalSongs); - DrawTextTrans(XBuf+102*272+4+(((31-strlen(snbuf))<<2)), 272, snbuf, 38); + DrawTextTrans(XBuf+102*272+4+(((31-strlen(snbuf))<<2)), 272, (uint8 *)snbuf, 38); GetSoundBuffer(&Bufpl); for(x=0;x<256;x++) diff --git a/palettes/rp2c04001.h b/palettes/rp2c04001.h index f2526b9..8752b2e 100644 --- a/palettes/rp2c04001.h +++ b/palettes/rp2c04001.h @@ -1,64 +1,64 @@ -{ 0x3f<<2, 0x31<<2, 0x36<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x36<<2, 0x0a<<2, 0x00<<2, }, -{ 0x17<<2, 0x25<<2, 0x3f<<2, }, -{ 0x00<<2, 0x20<<2, 0x22<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x39<<2, 0x00<<2, 0x16<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x1d<<2, 0x1d<<2, 0x1d<<2, }, -{ 0x3f<<2, 0x26<<2, 0x0e<<2, }, -{ 0x2a<<2, 0x00<<2, 0x04<<2, }, -{ 0x23<<2, 0x00<<2, 0x1d<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x10<<2, 0x0b<<2, 0x00<<2, }, -{ 0x3f<<2, 0x3f<<2, 0x3f<<2, }, -{ 0x0f<<2, 0x2f<<2, 0x3f<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x20<<2, 0x34<<2, 0x04<<2, }, -{ 0x27<<2, 0x3f<<2, 0x3c<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x3f<<2, 0x2f<<2, 0x2c<<2, }, -{ 0x08<<2, 0x0e<<2, 0x3b<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x16<<2, 0x3e<<2, 0x26<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x09<<2, 0x06<<2, 0x23<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x2a<<2, 0x39<<2, 0x3f<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x13<<2, 0x37<<2, 0x12<<2, }, -{ 0x00<<2, 0x3a<<2, 0x36<<2, }, -{ 0x06<<2, 0x0f<<2, 0x17<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x1f<<2, 0x02<<2, 0x00<<2, }, -{ 0x3f<<2, 0x31<<2, 0x3f<<2, }, -{ 0x29<<2, 0x00<<2, 0x00<<2, }, -{ 0x20<<2, 0x00<<2, 0x3c<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x3f<<2, 0x1d<<2, 0x18<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x25<<2, 0x00<<2, }, -{ 0x2f<<2, 0x2f<<2, 0x2f<<2, }, -{ 0x00<<2, 0x14<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x32<<2, 0x13<<2, 0x03<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x1c<<2, 0x3b<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, -{ 0x3f<<2, 0x1d<<2, 0x2d<<2, }, -{ 0x22<<2, 0x1c<<2, 0x00<<2, }, -{ 0x00<<2, 0x00<<2, 0x00<<2, }, +{0xfc, 0xc4, 0xd8}, +{0x40, 0x88, 0xfc}, +{0xd8, 0x28, 0x00}, +{0x5c, 0x94, 0xfc}, +{0x00, 0x80, 0x88}, +{0x00, 0x44, 0x00}, +{0x00, 0x00, 0x00}, +{0xe4, 0x00, 0x58}, +{0xfc, 0xfc, 0xfc}, +{0x74, 0x74, 0x74}, +{0xfc, 0x98, 0x38}, +{0xa8, 0x00, 0x10}, +{0x8c, 0x00, 0x74}, +{0xfc, 0x98, 0x38}, +{0x40, 0x2c, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0x3c, 0xbc, 0xfc}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x80, 0xd0, 0x10}, +{0x9c, 0xfc, 0xf0}, +{0xc4, 0xd4, 0xfc}, +{0xfc, 0xbc, 0xb0}, +{0x20, 0x38, 0xec}, +{0x00, 0x00, 0x00}, +{0x58, 0xf8, 0x98}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0xbc, 0xbc, 0xbc}, +{0xf4, 0x78, 0xfc}, +{0x24, 0x18, 0x8c}, +{0x00, 0x00, 0x00}, +{0xa8, 0xe4, 0xfc}, +{0x00, 0x00, 0x00}, +{0x4c, 0xdc, 0x48}, +{0x00, 0xe8, 0xd8}, +{0x18, 0x3c, 0x5c}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x7c, 0x08, 0x00}, +{0xfc, 0xc4, 0xfc}, +{0xa4, 0x00, 0x00}, +{0x80, 0x00, 0xf0}, +{0x00, 0x00, 0xa8}, +{0xfc, 0x74, 0x60}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x94, 0x00}, +{0xbc, 0xbc, 0xbc}, +{0x00, 0x50, 0x00}, +{0xe0, 0xfc, 0xa0}, +{0x00, 0x00, 0x00}, +{0xfc, 0xd8, 0xa8}, +{0xc8, 0x4c, 0x0c}, +{0x00, 0x00, 0x00}, +{0x00, 0x70, 0xec}, +{0x00, 0x44, 0x00}, +{0x00, 0x00, 0x00}, +{0xe0, 0xfc, 0xa0}, +{0xfc, 0x74, 0xb4}, +{0x88, 0x70, 0x00}, +{0x00, 0x00, 0x00}, diff --git a/sound.c b/sound.c index 76f85a0..61c8fcd 100644 --- a/sound.c +++ b/sound.c @@ -44,6 +44,7 @@ uint32 soundtsi; uint32 Wave[2048]; int32 WaveFinal[2048]; +int16 WaveFinalMono[2048]; EXPSOUND GameExpSound={0,0,0}; @@ -63,6 +64,8 @@ uint16 nreg; int32 lengthcount[4]; +extern int soundvol; + static const uint8 Slengthtable[0x20]= { 0x5,0x7f,0xA,0x1,0x14,0x2,0x28,0x3,0x50,0x4,0x1E,0x5,0x7,0x6,0x0E,0x7, @@ -861,11 +864,14 @@ int64 highp; // 0 through 65536, 0 = no high pass, 65536 = max int64 lowp; // 0 through 65536, 65536 = max low pass(total attenuation) // 65536 = no low pass -static void FilterSound(uint32 *in, int32 *out, int count) +static void FilterSound(uint32 *in, int32 *out, int16 *outMono, int count) { static int64 acc=0, acc2=0; - - for(;count;count--,in++,out++) + //int index=0; + //int16* tmp; + //int16* outorig=out; + //int32 prev=-99999; + for(;count;count--,in++,out++)//,index++) { int64 diff; @@ -874,21 +880,50 @@ static void FilterSound(uint32 *in, int32 *out, int count) acc+=(diff*highp)>>16; acc2+=((diff-acc2)*lowp)>>16; *in=0; - *out=(acc2*(int64)FSettings.SoundVolume)>>(24+16); + + // don't change the sound here +// *out=(acc2*(int64)FSettings.SoundVolume)>>(24+16); + // volume, 4 times louder by default?? +// *out = acc2 >> 24; + // just a bit louder. Hope it's okay + /* + *out = acc2 >> 22; if(*out<-32767) *out=-32767; if(*out>32767) *out=32767; - //*out=((int64)(acc2>>24)*(int64)FSettings.SoundVolume)>>16; //acc2>>24; + // go one back + + // do MONO + tmp=(int16 *)(out-1); + // don't do this the first time + if (prev == -99999) continue; + // the middle one should be interpolated + tmp[1]=(int16)((*out + prev) >> 1); + prev = *out; + */ + //outMono[index] = (int16)*out; + *outMono = (int16)(acc2 >> 24); + //if(*outMono<-16384) *outMono=-16384; + //if(*outMono>16384) *outMono=16384; + outMono++; + + // out=((int64)(acc2>>24)*(int64)FSettings.SoundVolume)>>16; //acc2>>24; + } + // do one more } + + + int FlushEmulateSound(void) { uint32 end; int x; + if(!timestamp) return(0); - if(!FSettings.SndRate) + if(!FSettings.SndRate || (soundvol == 0)) { end=0; goto nosoundo; @@ -904,10 +939,12 @@ int FlushEmulateSound(void) if(GameExpSound.Fill) GameExpSound.Fill(end&0xF); - FilterSound(Wave,WaveFinal,end>>4); - +// FilterSound(Wave,WaveFinal,end>>4); + FilterSound(Wave,WaveFinal,WaveFinalMono,end>>4); +// printf("count %d, num ints %d\n", end, (end >> 4)); if(FCEUGameInfo.type==GIT_NSF) { + printf("IS NSF"); int x,s=0,si=end/1024; // Only want 1/4 of the output buffer to be displayed for(x=0;x<256;x++) { diff --git a/sound.h b/sound.h index 53c397b..c5adc3e 100644 --- a/sound.h +++ b/sound.h @@ -66,6 +66,7 @@ void GetSoundBuffer(int32 **W); int FlushEmulateSound(void); extern uint32 Wave[2048]; extern int32 WaveFinal[2048]; +extern int16 WaveFinalMono[2048]; extern uint32 soundtsinc; void SetNESSoundMap(void); diff --git a/state.c b/state.c index ac48818..058b30c 100644 --- a/state.c +++ b/state.c @@ -38,6 +38,7 @@ #include "general.h" #include "state.h" #include "memory.h" +#include "ppu.h" static SFORMAT SFMDATA[64]; static int SFEXINDEX; diff --git a/svga.c b/svga.c index 815af19..a52e035 100644 --- a/svga.c +++ b/svga.c @@ -339,6 +339,8 @@ void SetNESDeemph(uint8 d, int force) if(n>0xff) n=0xff; if(o>0xff) o=0xff; FCEUD_SetPalette(x|0x40,m,n,o); + + } } if(!d) return; /* No deemphasis, so return. */ @@ -362,6 +364,7 @@ void SetNESDeemph(uint8 d, int force) if(o>0xff) o=0xff; FCEUD_SetPalette(x|0xC0,m,n,o); + } lastd=d; diff --git a/unif.c b/unif.c index f54ad39..07ec184 100644 --- a/unif.c +++ b/unif.c @@ -373,9 +373,10 @@ static int InitializeBoard(void) if(strcmp(sboardname,bmap[x].name)) continue; if(!malloced[16] && (bmap[x].flags&BMCFLAG_CHRROK)) { - if((malloced[16]=UNIFchrrama=FCEU_malloc(8192))) + UNIFchrrama=FCEU_malloc(8192); + if((malloced[16]=(uint8 *)UNIFchrrama)) { - SetupCartCHRMapping(0,UNIFchrrama,8192,1); + SetupCartCHRMapping(0,(uint8 *)UNIFchrrama,8192,1); AddExState(UNIFchrrama, 8192, 0,"CHRR"); } else diff --git a/video.c b/video.c index 5ab1bc9..245a6b1 100644 --- a/video.c +++ b/video.c @@ -53,7 +53,7 @@ int InitVirtualVideo(void) { m=(uint32) XBuf; m+=8;m&=0xFFFFFFF8; - (uint32)XBuf=m; + XBuf=(uint8 *)m; } memset(XBuf,128,272*240); @@ -145,7 +145,7 @@ static int WritePNGChunk(FILE *fp, uint32 size, char *type, uint8 *data) if(fwrite(data,1,size,fp)!=size) return 0; - crc=CalcCRC32(0,type,4); + crc=CalcCRC32(0,(uint8 *)type,4); if(size) crc=CalcCRC32(crc,data,size); @@ -207,9 +207,12 @@ int SaveSnapshot(void) { char pdata[256*3]; + + //void FCEUD_GetPalette(uint8 i,uint8 *r, unsigned char *g, unsigned char *b); for(x=0;x<256;x++) - FCEUD_GetPalette(x,pdata+x*3,pdata+x*3+1,pdata+x*3+2); - if(!WritePNGChunk(pp,256*3,"PLTE",pdata)) + FCEUD_GetPalette(x,(uint8*)(pdata+x*3),(unsigned char*)(pdata+x*3+1),(unsigned char*)(pdata+x*3+2)); + // static int WritePNGChunk(FILE *fp, uint32 size, char *type, uint8 *data) + if(!WritePNGChunk(pp,256*3,"PLTE",(uint8 *)pdata)) goto PNGerr; } diff --git a/zlib/unzip.c b/zlib/unzip.c index d156fae..73d6026 100644 --- a/zlib/unzip.c +++ b/zlib/unzip.c @@ -162,7 +162,7 @@ local int unzlocal_getShort (fin,pX) uLong *pX; { uLong x ; - int i; + int i=0; int err; err = unzlocal_getByte(fin,&i); @@ -184,7 +184,7 @@ local int unzlocal_getLong (fin,pX) uLong *pX; { uLong x ; - int i; + int i=0; int err; err = unzlocal_getByte(fin,&i); -- 2.39.5