From 987332078d2c97ba37b73d2b946377906fb486d7 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 7 Apr 2007 14:03:06 +0000 Subject: [PATCH] gpfce patch part2 git-svn-id: file:///home/notaz/opt/svn/fceu@92 be3aeb3a-fb24-0410-a615-afba39da0efa --- Makefile | 28 + Makefile.gp2x | 28 + README.compile.gp2x | 6 + drivers/cli/dos-joystick.c | 190 ------ drivers/cli/dos-joystick.h | 27 - drivers/cli/dos-keyboard.c | 131 ---- drivers/cli/dos-mouse.c | 77 --- drivers/cli/dos-sound.c | 567 ----------------- drivers/cli/dos-sound.h | 26 - drivers/cli/dos-video.c | 246 -------- drivers/cli/dos-video.h | 22 - drivers/cli/dos.c | 128 ---- drivers/cli/dos.h | 28 - drivers/cli/minimal.c | 476 +++++++++++++++ drivers/cli/minimal.h | 108 ++++ drivers/cli/minimal_940t.h | 96 +++ drivers/win/cheat.c | 471 --------------- drivers/win/cheat.h | 1 - drivers/win/common.h | 20 - drivers/win/config.c | 132 ---- drivers/win/input.c | 288 --------- drivers/win/input.h | 25 - drivers/win/joystick.c | 407 ------------- drivers/win/joystick.h | 16 - drivers/win/keyboard.c | 458 -------------- drivers/win/keyboard.h | 22 - drivers/win/keyscan.h | 125 ---- drivers/win/main.c | 338 ----------- drivers/win/netplay.c | 415 ------------- drivers/win/res.res | Bin 27108 -> 0 bytes drivers/win/sound.c | 457 -------------- drivers/win/throttle.c | 73 --- drivers/win/video.c | 1174 ------------------------------------ drivers/win/wave.c | 125 ---- drivers/win/window.c | 855 -------------------------- palettes/conv.c | 74 +++ palettes/palettes.h | 94 +++ palettes/rp2c04001.old | 64 ++ palettes/rp2c04002.h | 64 ++ palettes/rp2c04003.h | 64 ++ palettes/rp2c05004.h | 64 ++ ppu.c | 803 ++++++++++++++++++++++++ ppu.h | 5 + 43 files changed, 1974 insertions(+), 6844 deletions(-) create mode 100644 Makefile create mode 100644 Makefile.gp2x create mode 100644 README.compile.gp2x delete mode 100644 drivers/cli/dos-joystick.c delete mode 100644 drivers/cli/dos-joystick.h delete mode 100644 drivers/cli/dos-keyboard.c delete mode 100644 drivers/cli/dos-mouse.c delete mode 100644 drivers/cli/dos-sound.c delete mode 100644 drivers/cli/dos-sound.h delete mode 100644 drivers/cli/dos-video.c delete mode 100644 drivers/cli/dos-video.h delete mode 100644 drivers/cli/dos.c delete mode 100644 drivers/cli/dos.h create mode 100644 drivers/cli/minimal.c create mode 100644 drivers/cli/minimal.h create mode 100644 drivers/cli/minimal_940t.h delete mode 100644 drivers/win/cheat.c delete mode 100644 drivers/win/cheat.h delete mode 100644 drivers/win/common.h delete mode 100644 drivers/win/config.c delete mode 100644 drivers/win/input.c delete mode 100644 drivers/win/input.h delete mode 100644 drivers/win/joystick.c delete mode 100644 drivers/win/joystick.h delete mode 100644 drivers/win/keyboard.c delete mode 100644 drivers/win/keyboard.h delete mode 100644 drivers/win/keyscan.h delete mode 100644 drivers/win/main.c delete mode 100644 drivers/win/netplay.c delete mode 100644 drivers/win/res.res delete mode 100644 drivers/win/sound.c delete mode 100644 drivers/win/throttle.c delete mode 100644 drivers/win/video.c delete mode 100644 drivers/win/wave.c delete mode 100644 drivers/win/window.c create mode 100644 palettes/conv.c create mode 100644 palettes/palettes.h create mode 100644 palettes/rp2c04001.old create mode 100644 palettes/rp2c04002.h create mode 100644 palettes/rp2c04003.h create mode 100644 palettes/rp2c05004.h create mode 100644 ppu.c create mode 100644 ppu.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1e061ab --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +CC = arm-linux-gcc +TFLAGS = -mcpu=arm920t -O3 -Izlib -DGP2X=1 -DLSB_FIRST -DSDL -DUNIX -DPSS_STYLE=1 -DZLIB -D_REENTRANT +RM = rm -f +B = drivers/pc/ + +all: fceu + mv fceu gpfce + +include zlib/Makefile + +OBJDRIVER = ${B}minimal.o ${B}sdl.o ${B}main.o ${B}throttle.o ${B}unix-netplay.o ${B}sdl-sound.o ${B}sdl-video.o ${B}sdl-joystick.o drivers/common/cheat.o drivers/common/config.o drivers/common/args.o drivers/common/vidblit.o ${UNZIPOBJS} ppu.o +LDRIVER = -L /mnt/sd/lib -L/mnt/sd/gp2x/usr/lib -lm -lpthread -lz -static +# `arm-linux-sdl-config --libs` + +include Makefile.base + +${B}sdl-joystick.o: ${B}sdl-joystick.c +${B}main.o: ${B}main.c ${B}main.h ${B}usage.h ${B}input.c ${B}keyscan.h +${B}sdl.o: ${B}sdl.c ${B}sdl.h +${B}sdl-video.o: ${B}sdl-video.c +${B}sdl-video.o: ${B}minimal.c +${B}sdl-sound.o: ${B}sdl-sound.c +#${B}sdl-netplay.o: ${B}sdl-netplay.c +${B}unix-netplay.o: ${B}unix-netplay.c +${B}throttle.o: ${B}throttle.c ${B}main.h ${B}throttle.h +ppu.o: ppu.c ppu.h + +include Makefile.common diff --git a/Makefile.gp2x b/Makefile.gp2x new file mode 100644 index 0000000..1e061ab --- /dev/null +++ b/Makefile.gp2x @@ -0,0 +1,28 @@ +CC = arm-linux-gcc +TFLAGS = -mcpu=arm920t -O3 -Izlib -DGP2X=1 -DLSB_FIRST -DSDL -DUNIX -DPSS_STYLE=1 -DZLIB -D_REENTRANT +RM = rm -f +B = drivers/pc/ + +all: fceu + mv fceu gpfce + +include zlib/Makefile + +OBJDRIVER = ${B}minimal.o ${B}sdl.o ${B}main.o ${B}throttle.o ${B}unix-netplay.o ${B}sdl-sound.o ${B}sdl-video.o ${B}sdl-joystick.o drivers/common/cheat.o drivers/common/config.o drivers/common/args.o drivers/common/vidblit.o ${UNZIPOBJS} ppu.o +LDRIVER = -L /mnt/sd/lib -L/mnt/sd/gp2x/usr/lib -lm -lpthread -lz -static +# `arm-linux-sdl-config --libs` + +include Makefile.base + +${B}sdl-joystick.o: ${B}sdl-joystick.c +${B}main.o: ${B}main.c ${B}main.h ${B}usage.h ${B}input.c ${B}keyscan.h +${B}sdl.o: ${B}sdl.c ${B}sdl.h +${B}sdl-video.o: ${B}sdl-video.c +${B}sdl-video.o: ${B}minimal.c +${B}sdl-sound.o: ${B}sdl-sound.c +#${B}sdl-netplay.o: ${B}sdl-netplay.c +${B}unix-netplay.o: ${B}unix-netplay.c +${B}throttle.o: ${B}throttle.c ${B}main.h ${B}throttle.h +ppu.o: ppu.c ppu.h + +include Makefile.common diff --git a/README.compile.gp2x b/README.compile.gp2x new file mode 100644 index 0000000..96355c3 --- /dev/null +++ b/README.compile.gp2x @@ -0,0 +1,6 @@ +1) Use Linux on x86 +2) Rename drivers/cli to drivers/pc +3) Use GCC 4.1.0 +4) Need GP2X libraries + + diff --git a/drivers/cli/dos-joystick.c b/drivers/cli/dos-joystick.c deleted file mode 100644 index 3729187..0000000 --- a/drivers/cli/dos-joystick.c +++ /dev/null @@ -1,190 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "dos.h" -#include "dos-joystick.h" - -#define JOY_A 1 -#define JOY_B 2 -#define JOY_SELECT 4 -#define JOY_START 8 -#define JOY_UP 0x10 -#define JOY_DOWN 0x20 -#define JOY_LEFT 0x40 -#define JOY_RIGHT 0x80 - -int joy=0; -int joyBMap[4]; - -static int32 joybuttons=0; -static uint32 joyx=0; -static uint32 joyy=0; -static uint32 joyxcenter; -static uint32 joyycenter; - -static void ConfigJoystick(void); -volatile int soundjoyer=0; -volatile int soundjoyeron=0; - -/* Crude method to detect joystick. */ -static int DetectJoystick(void) -{ - uint8 b; - - outportb(0x201,0); - b=inportb(0x201); - sleep(1); - if((inportb(0x201)&3)==(b&3)) - return 0; - else - return 1; -} - -void UpdateJoyData(void) -{ - uint32 xc,yc; - - - joybuttons=((inportb(0x201)&0xF0)^0xF0)>>4; - - xc=yc=0; - - { - outportb(0x201,0); - - for(;;) - { - uint8 b; - - b=inportb(0x201); - if(!(b&3)) - break; - if(b&1) xc++; - if(b&2) yc++; - } - } - - joyx=xc; - joyy=yc; -} - -uint32 GetJSOr(void) -{ - int y; - unsigned long ret; - ret=0; - - if(!soundo) - UpdateJoyData(); - for(y=0;y<4;y++) - if(joybuttons&joyBMap[y]) ret|=(1<=joyxcenter*1.75) ret|=JOY_RIGHT<<((joy-1)<<3); - if(joyy<=joyycenter*.25) ret|=JOY_UP<<((joy-1)<<3); - else if(joyy>=joyycenter*1.75) ret|=JOY_DOWN<<((joy-1)<<3); - - return ret; -} - -int InitJoysticks(void) -{ - if(!joy) return(0); - if(!DetectJoystick()) - { - printf("Joystick not detected!\n"); - joy=0; - return 0; - } - if(soundo) - { - soundjoyeron=1; - while(!soundjoyer); - } - else - UpdateJoyData(); - - joyxcenter=joyx; - joyycenter=joyy; - - if(!(joyBMap[0]|joyBMap[1]|joyBMap[2]|joyBMap[3])) - ConfigJoystick(); - return(1); -} - -static void BConfig(int b) -{ - int c=0; - uint32 st=time(0); - - while(time(0)< (st+4) ) - { - if(!soundo) - UpdateJoyData(); - if(joybuttons) c=joybuttons; - else if(c && !joybuttons) - { - joyBMap[b]=c; - break; - } - - } -} - -void KillJoysticks(void) -{ - -} - -static void ConfigJoystick(void) -{ - static char *genb="** Press button for "; - - printf("\n\n Joystick button configuration:\n\n"); - printf(" Push and release the button to map to the virtual joystick.\n"); - printf(" If you do not wish to assign a button, wait a few seconds\n"); - printf(" and the configuration will continue.\n\n"); - printf(" Press enter to continue...\n"); - getchar(); - - printf("%s\"Select\".\n",genb); - BConfig(2); - - printf("%s\"Start\".\n",genb); - BConfig(3); - - printf("%s\"B\".\n",genb); - BConfig(1); - - printf("%s\"A\".\n",genb); - BConfig(0); -} - diff --git a/drivers/cli/dos-joystick.h b/drivers/cli/dos-joystick.h deleted file mode 100644 index 6cfaee5..0000000 --- a/drivers/cli/dos-joystick.h +++ /dev/null @@ -1,27 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -void UpdateJoyData(void); -uint32 GetJSOr(void); -int InitJoysticks(void); - -/* Variables to save in config file. */ -extern int joy; -extern int joyBMap[4]; diff --git a/drivers/cli/dos-keyboard.c b/drivers/cli/dos-keyboard.c deleted file mode 100644 index 22ca9e8..0000000 --- a/drivers/cli/dos-keyboard.c +++ /dev/null @@ -1,131 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include -#include -#include -#include -#include -#include -#include "keyscan.h" - -static unsigned char lastsc; -static char keybuf[256]; -int newk; - -/* Read scan code from port $60 */ -/* Acknowledge interrupt( output $20 to port $20) */ - -static void ihandler(_go32_dpmi_registers *r) -{ - unsigned char scode=inp(0x60); /* Get scan code. */ - - - if(scode!=0xE0) - { - int offs=0; - - /* I'm only interested in preserving the independent status of the - right ALT and CONTROL keys. - */ - if(lastsc==0xE0) - if((scode&0x7F)==SCAN_LEFTALT || (scode&0x7F)==SCAN_LEFTCONTROL) - offs=0x80; - - - keybuf[(scode&0x7f)|offs]=((scode&0x80)^0x80); - newk++; - } - lastsc=scode; - - outp(0x20,0x20); /* Acknowledge interrupt. */ -} - -static _go32_dpmi_seginfo KBIBack,KBIBackRM; -static _go32_dpmi_seginfo KBI,KBIRM; -static _go32_dpmi_registers KBIRMRegs; -static int initdone=0; - -int InitKeyboard(void) -{ - /* I'll assume that the keyboard is in the correct scancode mode(translated - mode 2, I think). - */ - newk=0; - memset(keybuf,0,sizeof(keybuf)); - KBIRM.pm_offset=KBI.pm_offset=(int)ihandler; - KBIRM.pm_selector=KBI.pm_selector=_my_cs(); - - _go32_dpmi_get_real_mode_interrupt_vector(9,&KBIBackRM); - _go32_dpmi_allocate_real_mode_callback_iret(&KBIRM, &KBIRMRegs); - _go32_dpmi_set_real_mode_interrupt_vector(9,&KBIRM); - - _go32_dpmi_get_protected_mode_interrupt_vector(9,&KBIBack); - _go32_dpmi_allocate_iret_wrapper(&KBI); - _go32_dpmi_set_protected_mode_interrupt_vector(9,&KBI); - lastsc=0; - initdone=1; - return(1); -} - -void KillKeyboard(void) -{ - if(initdone) - { - _go32_dpmi_set_protected_mode_interrupt_vector(9,&KBIBack); - _go32_dpmi_free_iret_wrapper(&KBI); - - _go32_dpmi_set_real_mode_interrupt_vector(9,&KBIBackRM); - _go32_dpmi_free_real_mode_callback(&KBIRM); - initdone=0; - } -} - -/* In FCE Ultra, it doesn't matter if the key states change - in the middle of the keyboard handling code. If you want - to use this code elsewhere, you may want to memcpy() keybuf - to another buffer and return that when GetKeyboard() is - called. -*/ - -char *GetKeyboard(void) -{ - return keybuf; -} - -/* Returns 1 on new scan codes generated, 0 on no new scan codes. */ -int UpdateKeyboard(void) -{ - int t=newk; - - if(t) - { - asm volatile( - "subl %%eax,_newk\n\t" - : - : "a" (t) - ); - - if(keybuf[SCAN_LEFTCONTROL] && keybuf[SCAN_C]) - raise(SIGINT); - return(1); - } - return(0); -} diff --git a/drivers/cli/dos-mouse.c b/drivers/cli/dos-mouse.c deleted file mode 100644 index ae3e341..0000000 --- a/drivers/cli/dos-mouse.c +++ /dev/null @@ -1,77 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include -#include - -#include "dos.h" - -int InitMouse(void) -{ - __dpmi_regs regs; - - memset(®s,0,sizeof(regs)); - regs.x.ax=0; - __dpmi_int(0x33,®s); - if(regs.x.ax!=0xFFFF) - return(0); - - memset(®s,0,sizeof(regs)); - regs.x.ax=0x7; - regs.x.cx=0; // Min X - regs.x.dx=260; // Max X - __dpmi_int(0x33,®s); - - memset(®s,0,sizeof(regs)); - regs.x.ax=0x8; - regs.x.cx=0; // Min Y - regs.x.dx=260; // Max Y - __dpmi_int(0x33,®s); - - memset(®s,0,sizeof(regs)); - regs.x.ax=0xF; - regs.x.cx=8; // Mickey X - regs.x.dx=8; // Mickey Y - __dpmi_int(0x33,®s); - - memset(®s,0,sizeof(regs)); - regs.x.ax=0x2; - __dpmi_int(0x33,®s); - - return(1); -} - -uint32 GetMouseData(uint32 *x, uint32 *y) -{ - __dpmi_regs regs; - - memset(®s,0,sizeof(regs)); - regs.x.ax=0x3; - __dpmi_int(0x33,®s); - - *x=regs.x.cx; - *y=regs.x.dx; - return(regs.x.bx&3); -} - -void KillMouse(void) -{ - -} diff --git a/drivers/cli/dos-sound.c b/drivers/cli/dos-sound.c deleted file mode 100644 index 19ef271..0000000 --- a/drivers/cli/dos-sound.c +++ /dev/null @@ -1,567 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dos.h" -#include "dos-sound.h" -#include "dos-joystick.h" - - -static void SBIRQHandler(_go32_dpmi_registers *r); -static uint32 LMBuffer; /* Address of low memory DMA playback buffer. */ -static int LMSelector; - -static uint8 *WaveBuffer; -static unsigned int IVector, SBIRQ, SBDMA, SBDMA16, SBPort; -static int DSPV,hsmode; -static int format; -static int frags, fragsize, fragtotal; -static volatile int WritePtr, ReadPtr; -static volatile int hbusy; -static volatile int whichbuf; - - -static uint8 PICMask; -/* Protected mode interrupt vector info. */ -static _go32_dpmi_seginfo SBIH,SBIHOld; - -/* Real mode interrupt vector info. */ -static _go32_dpmi_seginfo SBIHRM,SBIHRMOld; -static _go32_dpmi_registers SBIHRMRegs; - -static int WriteDSP(uint8 V) -{ - int x; - - for(x=65536;x;x--) - { - if(!(inportb(SBPort+0xC)&0x80)) - { - outportb(SBPort+0xC,V); - return(1); - } - } - return(0); -} - -static int ReadDSP(uint8 *V) -{ - int x; - - for(x=65536;x;x--) /* Should be more than enough time... */ - { - if(inportb(SBPort+0xE)&0x80) - { - *V=inportb(SBPort+0xA); - return(1); - } - } - return(0); -} - - -static int SetVectors(void) -{ - SBIH.pm_offset=SBIHRM.pm_offset=(int)SBIRQHandler; - SBIH.pm_selector=SBIHRM.pm_selector=_my_cs(); - - /* Get and set real mode interrupt vector. */ - _go32_dpmi_get_real_mode_interrupt_vector(IVector,&SBIHRMOld); - _go32_dpmi_allocate_real_mode_callback_iret(&SBIHRM, &SBIHRMRegs); - _go32_dpmi_set_real_mode_interrupt_vector(IVector,&SBIHRM); - - /* Get and set protected mode interrupt vector. */ - _go32_dpmi_get_protected_mode_interrupt_vector(IVector,&SBIHOld); - _go32_dpmi_allocate_iret_wrapper(&SBIH); - _go32_dpmi_set_protected_mode_interrupt_vector(IVector,&SBIH); - - return(1); -} - -static void ResetVectors(void) -{ - _go32_dpmi_set_protected_mode_interrupt_vector(IVector,&SBIHOld); - _go32_dpmi_free_iret_wrapper(&SBIH); - _go32_dpmi_set_real_mode_interrupt_vector(IVector,&SBIHRMOld); - _go32_dpmi_free_real_mode_callback(&SBIHRM); -} - -int GetBLASTER(void) -{ - int check=0; - char *s; - - if(!(s=getenv("BLASTER"))) - { - puts(" Error getting BLASTER environment variable."); - return(0); - } - - while(*s) - { - switch(toupper(*s)) - { - case 'A': check|=(sscanf(s+1,"%x",&SBPort)==1)?1:0;break; - case 'I': check|=(sscanf(s+1,"%d",&SBIRQ)==1)?2:0;break; - case 'D': check|=(sscanf(s+1,"%d",&SBDMA)==1)?4:0;break; - case 'H': check|=(sscanf(s+1,"%d",&SBDMA16)==1)?8:0;break; - } - s++; - } - - if((check^7)&7 || SBDMA>=4 || (SBDMA16<=4 && check&8) || SBIRQ>15) - { - puts(" Invalid or incomplete BLASTER environment variable."); - return(0); - } - if(!(check&8)) - format=0; - return(1); -} - -static int ResetDSP(void) -{ - uint8 b; - - outportb(SBPort+0x6,0x1); - delay(10); - outportb(SBPort+0x6,0x0); - delay(10); - - if(ReadDSP(&b)) - if(b==0xAA) - return(1); - return(0); -} - -static int GetDSPVersion(void) -{ - int ret; - uint8 t; - - if(!WriteDSP(0xE1)) - return(0); - if(!ReadDSP(&t)) - return(0); - ret=t<<8; - if(!ReadDSP(&t)) - return(0); - ret|=t; - - return(ret); -} - -static void KillDMABuffer(void) -{ - __dpmi_free_dos_memory(LMSelector); -} - -static int MakeDMABuffer(void) -{ - uint32 size; - int32 tmp; - - size=fragsize*2; /* Two buffers in the DMA buffer. */ - size<<=format; /* Twice the size for 16-bit than for 8-bit. */ - - size<<=1; /* Double the size in case the first 2 buffers - cross a 64KB or 128KB page boundary. - */ - size=(size+15)>>4; /* Convert to paragraphs */ - - if((tmp=__dpmi_allocate_dos_memory(size,&LMSelector))<0) - return(0); - - LMBuffer=tmp<<=4; - - if(format) /* Check for and fix 128KB page boundary crossing. */ - { - if((LMBuffer&0x20000) != ((LMBuffer+fragsize*2*2-1)&0x20000)) - LMBuffer+=fragsize*2*2; - } - else /* Check for and fix 64KB page boundary crossing. */ - { - if((LMBuffer&0x10000) != ((LMBuffer+fragsize*2-1)&0x10000)) - LMBuffer+=fragsize*2; - } - - DOSMemSet(LMBuffer, format?0:128, (fragsize*2)<>8); - - /* Page of buffer. */ - outportb(PPorts[format?SBDMA16:SBDMA],LMBuffer>>16); - - /* Offset of buffer within page. */ - if(format) - tmp=((SBDMA16&3)<<2)+0xc0; - else - tmp=SBDMA<<1; - - outportb(tmp,(LMBuffer>>format)); - outportb(tmp,(LMBuffer>>(8+format))); -} - -int InitSB(int Rate, int bittage) -{ - hsmode=hbusy=0; - whichbuf=1; - puts("Initializing Sound Blaster..."); - - format=bittage?1:0; - frags=8; - - if(Rate<=11025) - fragsize=1<<5; - else if(Rate<=22050) - fragsize=1<<6; - else - fragsize=1<<7; - - fragtotal=frags*fragsize; - WaveBuffer=malloc(fragtotal<65535)) - { - printf(" Unsupported playback rate: %d samples per second\n",Rate); - return(0); - } - - if(!GetBLASTER()) - return(0); - - /* Disable IRQ line in PIC0 or PIC1 */ - if(SBIRQ>7) - { - PICMask=inportb(0xA1); - outportb(0xA1,PICMask|(1<<(SBIRQ&7))); - } - else - { - PICMask=inportb(0x21); - outportb(0x21,PICMask|(1<>8,DSPV&0xFF); - if(DSPV<0x201) - { - printf(" DSP version number is too low.\n"); - return(0); - } - - if(DSPV<0x400) - format=0; - if(!MakeDMABuffer()) - { - puts(" Error creating low-memory DMA buffer."); - return(0); - } - - if(SBIRQ>7) IVector=SBIRQ+0x68; - else IVector=SBIRQ+0x8; - - if(!SetVectors()) - { - puts(" Error setting interrupt vectors."); - KillDMABuffer(); - return(0); - } - - /* Reenable IRQ line. */ - if(SBIRQ>7) - outportb(0xA1,PICMask&(~(1<<(SBIRQ&7)))); - else - outportb(0x21,PICMask&(~(1<=0x400) - { - WriteDSP(0x41); // Set sampling rate - WriteDSP(Rate>>8); // High byte - WriteDSP(Rate&0xFF); // Low byte - if(!format) - { - WriteDSP(0xC6); // 8-bit output - WriteDSP(0x00); // 8-bit mono unsigned PCM - } - else - { - WriteDSP(0xB6); // 16-bit output - WriteDSP(0x10); // 16-bit mono signed PCM - } - WriteDSP((fragsize-1)&0xFF);// Low byte of size - WriteDSP((fragsize-1)>>8); // High byte of size - } - else - { - int tc,command; - if(Rate>22050) - { - tc=(65536-(256000000/Rate))>>8; - Rate=256000000/(65536-(tc<<8)); - command=0x90; // High-speed auto-initialize DMA mode transfer - hsmode=1; - } - else - { - tc=256-(1000000/Rate); - Rate=1000000/(256-tc); - command=0x1c; // Auto-initialize DMA mode transfer - } - WriteDSP(0x40); // Set DSP time constant - WriteDSP(tc); // time constant - WriteDSP(0x48); // Set DSP block transfer size - WriteDSP((fragsize-1)&0xFF); - WriteDSP((fragsize-1)>>8); - - WriteDSP(command); - } - - /* Enable DMA */ - if(format) - outportb(0xd4,SBDMA16&3); - else - outportb(0xa,SBDMA); - - printf(" %d hz, %d-bit\n",Rate,8<=8) - outportb(0xA0,0x20); - whichbuf^=1; - return; - } - hbusy=1; - - { - /* This code seems to fail on many SB emulators. Bah. - SCREW SB EMULATORS. ^_^ */ - uint32 count; - uint32 block; - uint32 port; - - if(format) - port=((SBDMA16&3)*4)+0xc2; - else - port=(SBDMA*2)+1; - - count=inportb(port); - count|=inportb(port)<<8; - - if(count>=fragsize) - block=1; - else - block=0; - dest=LMBuffer+((block*fragsize)<>2;x;x--,dest+=4) - { - _farnspokel(dest,sby); - } - } - else - { - for(x=(fragsize<>2;x;x--,dest+=4,src++) - { - _farnspokel(dest,*src); - } - ReadPtr=(ReadPtr+fragsize)&(fragtotal-1); - } - - if(soundjoyeron) - { - static int coot=0; - if(!coot) - { - UpdateJoyData(); - soundjoyer=1; - } - coot=(coot+1)&3; - } - hbusy=0; - outportb(0x20,0x20); - if(SBIRQ>=8) - outportb(0xA0,0x20); -} - -void SilenceSound(int s) -{ - ssilence=s; -} - -void WriteSBSound(int32 *Buffer, int Count, int NoBlocking) -{ - int x; - - if(!format) - { - for(x=0;x>8)^128; - WritePtr=(WritePtr+1)&(fragtotal-1); - } - } - else // 16 bit - { - for(x=0;x7)?0xA1:0x21,PICMask|(1<<(SBIRQ&7))); - ResetVectors(); - outportb((SBIRQ>7)?0xA1:0x21,PICMask); - KillDMABuffer(); -} diff --git a/drivers/cli/dos-sound.h b/drivers/cli/dos-sound.h deleted file mode 100644 index 7f5185a..0000000 --- a/drivers/cli/dos-sound.h +++ /dev/null @@ -1,26 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -int InitSB(int Rate, int bittage); -void KillSB(void); - -void WriteSBSound(int32 *Buffer, int Count, int NoBlocking); -void SilenceSound(int s); - diff --git a/drivers/cli/dos-video.c b/drivers/cli/dos-video.c deleted file mode 100644 index 574c824..0000000 --- a/drivers/cli/dos-video.c +++ /dev/null @@ -1,246 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 \Firebug\ - * 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 - */ - -#include -#include -#include -#include -#include -#include - -#include "dos.h" -#include "dos-video.h" - -#define TEXT 3 -#define G320x200x256 0x13 - -static void vga_waitretrace(void) -{ - while(inp(0x3da)&0x8); - while(!(inp(0x3da)&0x8)); -} - -static void vga_setmode(int mode) -{ - __dpmi_regs regs; - - memset(®s,0,sizeof(regs)); - regs.x.ax=mode; - - __dpmi_int(0x10,®s); -} - -void vga_setpalette(int i, int r, int g, int b) -{ - outp(0x3c8,i); - outp(0x3c9,r); - outp(0x3c9,g); - outp(0x3c9,b); -} - -int FCEUDvmode=1; - -static int vidready=0; - -/* Part of the VGA low-level mass register setting code derived from - code by \Firebug\. -*/ - -#include "vgatweak.c" - -void SetBorder(void) -{ - inportb(0x3da); - outportb(0x3c0,(0x11|0x20)); - outportb(0x3c0,0x80); -} - -void TweakVGA(int VGAMode) -{ - int I; - - vga_waitretrace(); - - outportb(0x3C8,0x00); - for(I=0;I<768;I++) outportb(0x3C9,0x00); - - outportb(0x3D4,0x11); - I=inportb(0x3D5)&0x7F; - outportb(0x3D4,0x11); - outportb(0x3D5,I); - - switch(VGAMode) - { - case 1: for(I=0;I<25;I++) VGAPortSet(v256x240[I]);break; - case 2: for(I=0;I<25;I++) VGAPortSet(v256x256[I]);break; - case 3: for(I=0;I<25;I++) VGAPortSet(v256x256S[I]);break; - case 6: for(I=0;I<25;I++) VGAPortSet(v256x224S[I]);break; - case 8: for(I=0;I<25;I++) VGAPortSet(v256x224_103[I]);break; - default: break; - } - - outportb(0x3da,0); -} - - -static uint8 palettedbr[256],palettedbg[256],palettedbb[256]; - -static void FlushPalette(void) -{ - int x; - for(x=0;x<256;x++) - { - int z=x; - vga_setpalette(z,palettedbr[x]>>2,palettedbg[x]>>2,palettedbb[x]>>2); - } -} - -void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) -{ - palettedbr[index]=r; - palettedbg[index]=g; - palettedbb[index]=b; - if(vidready) - { - vga_setpalette(index,r>>2,g>>2,b>>2); - } -} - - -void FCEUD_GetPalette(uint8 i, uint8 *r, uint8 *g, uint8 *b) -{ - *r=palettedbr[i]; - *g=palettedbg[i]; - *b=palettedbb[i]; -} - -static uint32 ScreenLoc; - -int InitVideo(void) -{ - vidready=0; - switch(FCEUDvmode) - { - default: - case 1: - case 2: - case 3: - case 6: - case 8: - vga_setmode(G320x200x256); - vidready|=1; - ScreenLoc=0xa0000; - TweakVGA(FCEUDvmode); - SetBorder(); - DOSMemSet(ScreenLoc, 128, 256*256); - break; - } - vidready|=2; - FlushPalette(); - return 1; -} - -void KillVideo(void) -{ - if(vidready) - { - vga_setmode(TEXT); - vidready=0; - } -} -void LockConsole(void){} -void UnlockConsole(void){} -void BlitScreen(uint8 *XBuf) -{ - uint32 dest; - int tlines; - - if(eoptions&4 && !NoWaiting) - vga_waitretrace(); - - tlines=erendline-srendline+1; - - dest=ScreenLoc; - - switch(FCEUDvmode) - { - case 1:dest+=(((240-tlines)>>1)<<8);break; - case 2: - case 3:dest+=(((256-tlines)>>1)<<8);break; - case 4: - case 5:dest+=(((240-tlines)>>1)*640+((640-512)>>1));break; - case 8: - case 6:if(tlines>224) tlines=224;dest+=(((224-tlines)>>1)<<8);break; - } - - XBuf+=(srendline<<8)+(srendline<<4); - - _farsetsel(_dos_ds); - if(eoptions&DO_CLIPSIDES) - { - asm volatile( - "agoop1:\n\t" - "movl $30,%%eax\n\t" - "agoop2:\n\t" - "movl (%%esi),%%edx\n\t" - "movl 4(%%esi),%%ecx\n\t" - ".byte 0x64 \n\t" - "movl %%edx,(%%edi)\n\t" - ".byte 0x64 \n\t" - "movl %%ecx,4(%%edi)\n\t" - "addl $8,%%esi\n\t" - "addl $8,%%edi\n\t" - "decl %%eax\n\t" - "jne agoop2\n\t" - "addl $32,%%esi\n\t" - "addl $16,%%edi\n\t" - "decb %%bl\n\t" - "jne agoop1\n\t" - : - : "S" (XBuf+8), "D" (dest+8), "b" (tlines) - : "%eax","%cc","%edx","%ecx" ); - } - else - { - asm volatile( - "goop1:\n\t" - "movl $32,%%eax\n\t" - "goop2:\n\t" - "movl (%%esi),%%edx\n\t" - "movl 4(%%esi),%%ecx\n\t" - ".byte 0x64 \n\t" - "movl %%edx,(%%edi)\n\t" - ".byte 0x64 \n\t" - "movl %%ecx,4(%%edi)\n\t" - "addl $8,%%esi\n\t" - "addl $8,%%edi\n\t" - "decl %%eax\n\t" - "jne goop2\n\t" - "addl $16,%%esi\n\t" - "decb %%bl\n\t" - "jne goop1\n\t" - : - : "S" (XBuf), "D" (dest), "b" (tlines) - : "%eax","%cc","%edx","%ecx" ); - } -} - - diff --git a/drivers/cli/dos-video.h b/drivers/cli/dos-video.h deleted file mode 100644 index ee09b51..0000000 --- a/drivers/cli/dos-video.h +++ /dev/null @@ -1,22 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -extern int FCEUDvmode; - diff --git a/drivers/cli/dos.c b/drivers/cli/dos.c deleted file mode 100644 index 8ba1578..0000000 --- a/drivers/cli/dos.c +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "dos.h" -#include "dos-joystick.h" -#include "dos-video.h" -#include "dos-sound.h" -#include "../common/args.h" -#include "../common/config.h" - -/* _CRT0_FLAG_LOCK_MEMORY might not always result in all memory being locked. - Bummer. I'll add code to explicitly lock the data touched by the sound - interrupt handler(and the handler itself), if necessary(though that might - be tricky...). I'll also to cover the data the keyboard - interrupt handler touches. -*/ - -int _crt0_startup_flags = _CRT0_FLAG_FILL_SBRK_MEMORY | _CRT0_FLAG_LOCK_MEMORY | _CRT0_FLAG_USE_DOS_SLASHES; - -static int f8bit=0; -int soundo=44100; -int doptions=0; - - -CFGSTRUCT DriverConfig[]={ - NAC("sound",soundo), - AC(doptions), - AC(f8bit), - AC(FCEUDvmode), - NACA("joybmap",joyBMap), - AC(joy), - ENDCFGSTRUCT -}; - -char *DriverUsage= -"-vmode x Select video mode(all are 8 bpp).\n\ - 1 = 256x240 6 = 256x224(with scanlines)\n\ - 2 = 256x256 8 = 256x224\n\ - 3 = 256x256(with scanlines)\n\ --vsync x Wait for the screen's vertical retrace before updating the\n\ - screen. Refer to the documentation for caveats.\n\ - 0 = Disabled.\n\ - 1 = Enabled.\n\ --sound x Sound.\n\ - 0 = Disabled.\n\ - Otherwise, x = playback rate.\n\ --f8bit x Force 8-bit sound.\n\ - 0 = Disabled.\n\ - 1 = Enabled.\n\ --joy x Joystick mapped to virtual joystick x(1-4).\n\ - 0 = Disabled, reset configuration.\n\ - 1 = Enabled."; - -ARGPSTRUCT DriverArgs[]={ - {"-vmode",0,&FCEUDvmode,0}, - {"-sound",0,&soundo,0}, - {"-f8bit",0,&f8bit,0}, - {"-joy",0,&joy,0}, - {"-vsync",0,&eoptions,0x8004}, - {0,0,0,0} -}; - -void DoDriverArgs(void) -{ - if(!joy) memset(joyBMap,0,4); -} - -int InitSound(void) -{ - if(soundo) - { - if(soundo==1) - soundo=44100; - soundo=InitSB(soundo,f8bit?0:1); - FCEUI_Sound(soundo); - } - return(soundo?1:0); -} - -void WriteSound(int32 *Buffer, int Count, int NoWaiting) -{ - WriteSBSound(Buffer,Count,NoWaiting); -} - -void KillSound(void) -{ - if(soundo) - KillSB(); -} - -void DOSMemSet(uint32 A, uint8 V, uint32 count) -{ - uint32 x; - - _farsetsel(_dos_ds); - for(x=0;x=0;x--) - { - if(arg0[x]=='/' || arg0[x]=='\\') - { - strncpy(BaseDirectory,arg0,x); - break; - } - } - - BaseDirectory[x]=0; -} - -int main(int argc, char *argv[]) -{ - puts("\nStarting FCE Ultra "VERSION_STRING"...\n"); - arg0=argv[0]; - return(CLImain(argc,argv)); -} - diff --git a/drivers/cli/dos.h b/drivers/cli/dos.h deleted file mode 100644 index 05bc8e5..0000000 --- a/drivers/cli/dos.h +++ /dev/null @@ -1,28 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include "../../driver.h" -#include "main.h" - -extern int eoptions; -extern int soundo; -void DOSMemSet(uint32 A, uint8 V, uint32 count); -#define DO_CLIPSIDES 1 - diff --git a/drivers/cli/minimal.c b/drivers/cli/minimal.c new file mode 100644 index 0000000..193fa9e --- /dev/null +++ b/drivers/cli/minimal.c @@ -0,0 +1,476 @@ +/* + GP2X minimal library v0.A by rlyeh, 2005. emulnation.info@rlyeh (swap it!) + + + GP2X 920t/940t CPUs library with a FIFO message system. + + GP2X video library with double buffering. + + GP2X sound library with double buffering. + + GP2X blitter library. + + GP2X timer library. + + GP2X joystick library. + + Thanks to Squidge, Robster, snaff, Reesy and NK, for the help & previous work! :-) + + + License + ======= + + Free for non-commercial projects (it would be nice receiving a mail from you). + Other cases, ask me first. + + GamePark Holdings is not allowed to use this library and/or use parts from it. + + + Known projects using the library or parts from it + ================================================= + + REminiscence-0.1.8 (rlyeh) + Atari800 GP2X pre-release 3 (foft) + XUMP (kedo) + MAME2X (Franxis) + DrMD for GP2X (Reesy) + + + What's new + ========== + + 0.A: 940t disabled all time unless required + sound is paused by default now, use gp2x_sound_pause() to unlock it + + fixed functions: + - gp2x_sound_play() ; increased the number of sampling buffers + - gp2x_timer_read() ; it should work again. broken at some point before + - gp2x_dualcore_launch_program_from_disk() ; it missed the code uploading call + + added functions: + - gp2x_sound_pause() + - gp2x_timer_delay() + - gp2x_dualcore_pause() + + 0.9: initial FIFO message system for dual cpu cores. + initial 48 Mb support. + initial quadruple buffering in 8bbp mode. + + added functions: + - gp2x_dualcore_exec() ; initial FIFO message system for dual cpu cores. + - gp2x_dualcore_sync() ; initial FIFO message system for dual cpu cores. + + improved functions: + - gp2x_video_flip() ; initial quadruple buffering in 8bbp mode. + + 0.8: initial dual cores cpu support. + very basic blit functions by popular demand ;-) + vsync & hsync waiting code (thanks Reesy) + + added functions: + - gp2x_launch_program() ; initial dual cores cpu support. + - gp2x_launch_program_from_disk() ; initial dual cores cpu support. + - gp2x_launch_subprogram() ; initial dual cores cpu support. + - gp2x_blitter_rect15() ; very basic blit function by popular demand ;-) + - gp2x_blitter_rect8() ; very basic blit function by popular demand ;-) + - gp2x_video_hsync() ; hsync waiting code (thanks Reesy) + - gp2x_video_vsync() ; vsync waiting code (thanks Reesy) + + fixed functions: + - gp2x_video_color8() ; bugfixed a stupid typo (thanks Franxis for the bug report) + + 0.7: added functions: + - gp2x_sound_volume() + + fixed functions: + - gp2x_deinit() ; fixed menu launch code when exiting. + + improved functions: + - gp2x_timer_read() ; rewritten timer. it should be more accurate now. + - gp2x_init() ; faster init code. + + 0.6: added functions: + - gp2x_timer_read() + - gp2x_sound_pause() + + fixed functions: + - gp2x_video_setpalette() ; palette handling was incorrect. fixed. + + 0.5: improved functions: + - gp2x_init() ; better and cleaner initalizing code. + - gp2x_init() ; sound patched for real stereo output (by using NK's solution) + + 0.4: lots of cleanups. + sound is threaded and double buffered now. + 8 bpp video support. + + fixed functions: + - gp2x_deinit() ; better and cleaner exiting code. + + 0.3: shorter library. + + fixed functions: + - gp2x_joystick_read() ; improved joystick diagonal detection. + + 0.2: better code layout. + public release. + + 0.1: beta release. +*/ + +#include "minimal.h" + + unsigned char *gp2x_screen8 ,*gp2x_upperRAM; + unsigned long gp2x_dev[8]={0,0,0,0,0,0,0,0}, gp2x_physvram[8], *gp2x_memregl, gp2x_volume, gp2x_ticks_per_second; +volatile unsigned long gp2x_sound_pausei=1, gp2x_ticks=0, gp2x_sound=0, *gp2x_dualcore_ram; + unsigned short *gp2x_memregs, *gp2x_screen15, *gp2x_logvram15[4], gp2x_sound_buffer[4+((44100/25)*2)*8]; //25 Hz gives our biggest supported sampling buffer +volatile unsigned short gp2x_palette[512]; + pthread_t gp2x_sound_thread=0; + +extern void gp2x_sound_frame(void *blah, void *buff, int samples); + + +void gp2x_video_flip(void) +{ + unsigned long address=gp2x_physvram[gp2x_physvram[7]]; + + if(++gp2x_physvram[7]==4) gp2x_physvram[7]=0; + gp2x_screen15=gp2x_logvram15[gp2x_physvram[7]]; + gp2x_screen8=(unsigned char *)gp2x_screen15; + + gp2x_memregs[0x290E>>1]=(unsigned short)(address & 0xFFFF); + gp2x_memregs[0x2910>>1]=(unsigned short)(address >> 16); + gp2x_memregs[0x2912>>1]=(unsigned short)(address & 0xFFFF); + gp2x_memregs[0x2914>>1]=(unsigned short)(address >> 16); +} + +void gp2x_video_flip_single(void) +{ + unsigned long address=gp2x_physvram[0]; + + gp2x_screen15=gp2x_logvram15[0]; + gp2x_screen8=(unsigned char *)gp2x_screen15; + + gp2x_memregs[0x290E>>1]=(unsigned short)(address & 0xFFFF); + gp2x_memregs[0x2910>>1]=(unsigned short)(address >> 16); + gp2x_memregs[0x2912>>1]=(unsigned short)(address & 0xFFFF); + gp2x_memregs[0x2914>>1]=(unsigned short)(address >> 16); +} + + +void gp2x_video_setgamma(unsigned short gamma) /*0..255*/ +{ + int i=256*3; + gp2x_memregs[0x295C>>1]=0; + while(i--) gp2x_memregs[0x295E>>1]=gamma; +} + +void gp2x_video_setpalette(void) +{ + unsigned short *g=(unsigned short *)gp2x_palette; int i=512; + gp2x_memregs[0x2958>>1]=0; + while(i--) gp2x_memregs[0x295A>>1]=*g++; +} + +void gp2x_blitter_rect15(gp2x_rect *r) +{ + int x, y; unsigned short *data=r->data15, *offset=&gp2x_screen15[r->x+r->y*320]; + + y=r->h; if(r->solid) + while(y--) { x=r->w; while(x--) *offset++=*data++; offset+=320-x; } + else + while(y--) { x=r->w; while(x--) { if(*data) *offset=*data; offset++, data++; } + offset+=320-x; } +} + +void gp2x_blitter_rect8(gp2x_rect *r) +{ + int x, y; unsigned char *data=r->data8, *offset=&gp2x_screen8[r->x+r->y*320]; + + y=r->h; if(r->solid) + while(y--) { x=r->w; while(x--) *offset++=*data++; offset+=320-x; } + else + while(y--) { x=r->w; while(x--) { if(*data) *offset=*data; offset++, data++; } + offset+=320-x; } +} + +unsigned long gp2x_joystick_read(void) +{ + unsigned long value=(gp2x_memregs[0x1198>>1] & 0x00FF); + + if(value==0xFD) value=0xFA; + if(value==0xF7) value=0xEB; + if(value==0xDF) value=0xAF; + if(value==0x7F) value=0xBE; + + return ~((gp2x_memregs[0x1184>>1] & 0xFF00) | value | (gp2x_memregs[0x1186>>1] << 16)); +} + +void gp2x_sound_volume(int l, int r) +{ + l=(((l*0x50)/100)<<8)|((r*0x50)/100); //0x5A, 0x60 + ioctl(gp2x_dev[4], SOUND_MIXER_WRITE_PCM, &l); //SOUND_MIXER_WRITE_VOLUME +} + +void gp2x_timer_delay(unsigned long ticks) +{ + unsigned long target=gp2x_memregl[0x0A00>>2]+ticks*gp2x_ticks_per_second; + while(gp2x_memregl[0x0A00>>2]>2]/gp2x_ticks_per_second; +} + +unsigned long gp2x_timer_read_ms(void) +{ + return gp2x_memregl[0x0A00>>2]; +} + + +void gp2x_sound_pause(int yes) { gp2x_sound_pausei=yes; } + + +static void *gp2x_sound_play(void *blah) +{ + int flip=0, flyp=gp2x_sound_buffer[1]; + struct timespec ts; ts.tv_sec=0, ts.tv_nsec=gp2x_sound_buffer[2]; + + while(!gp2x_sound) + { + nanosleep(&ts, NULL); + + + if(!gp2x_sound_pausei) + { + // [1] is sound buffer size at 22050, 16, stereo, it is 1468 (367*4) + // [0] number of bytes?, at 22050,16,stereo, it is 367 + // first half of buffer + + // first one is 368 + + + gp2x_sound_frame(blah, (void *)(&gp2x_sound_buffer[4+flip]), gp2x_sound_buffer[0]); + // write out to second half of buffer + write(gp2x_dev[3], (void *)(&gp2x_sound_buffer[4+flyp]), gp2x_sound_buffer[1]); + + flip+=gp2x_sound_buffer[1]; + if(flip==gp2x_sound_buffer[1]*8) flip=0; + flyp+=gp2x_sound_buffer[1]; + if(flyp==gp2x_sound_buffer[1]*8) flyp=0; + } + } + return NULL; +} + +static void gp2x_initqueue(gp2x_queue *q, unsigned long queue_items, unsigned long *position920t, unsigned long *position940t) +{ + q->head = q->tail = q->items = 0; + q->max_items = queue_items; + if(position920t) q->place920t=position920t; else q->place920t=(unsigned long *)malloc(sizeof(unsigned long) * queue_items); + if(position940t) q->place940t=position940t; + memset(q->place920t, 0, sizeof(unsigned long) * queue_items); +} + +static void gp2x_enqueue(gp2x_queue *q, unsigned long data) +{ + while(q->items==q->max_items); /*waiting for tail to decrease...*/ + q->place920t[q->head = (q->head < q->max_items ? q->head+1 : 0)] = data; + q->items++; +} + +/* UNUSED + static unsigned long gp2x_dequeue(gp2x_queue *q) +{ + while(!q->items); //waiting for head to increase... + q->items--; + return q->place920t[q->tail = (q->tail < q->max_items ? q->tail+1 : 0)]; +} */ + + + + void gp2x_dualcore_pause(int yes) { if(yes) gp2x_memregs[0x0904>>1] &= 0xFFFE; else gp2x_memregs[0x0904>>1] |= 1; } +static void gp2x_940t_reset(int yes) { gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (0x03); } +static void gp2x_940t_pause(int yes) { gp2x_dualcore_pause(yes); } + +static void gp2x_dualcore_registers(int save) +{ + static unsigned short regs[8]; + + if(save) + { + regs[0]=gp2x_memregs[0x0904>>1]; regs[1]=gp2x_memregs[0x0912>>1]; + regs[2]=gp2x_memregs[0x091c>>1]; regs[3]=gp2x_memregs[0x3b40>>1]; + regs[4]=gp2x_memregs[0x3b42>>1]; regs[5]=gp2x_memregs[0x3b48>>1]; + regs[6]=gp2x_memregs[0x3b44>>1]; regs[7]=gp2x_memregs[0x3b46>>1]; + + gp2x_940t_reset(1); + gp2x_940t_pause(1); + } + else + { + gp2x_memregs[0x0904>>1]=regs[0]; gp2x_memregs[0x0912>>1]=regs[1]; + gp2x_memregs[0x091c>>1]=regs[2]; gp2x_memregs[0x3b40>>1]=regs[3]; + gp2x_memregs[0x3b42>>1]=regs[4]; gp2x_memregs[0x3b48>>1]=regs[5]; + gp2x_memregs[0x3b44>>1]=regs[6]; gp2x_memregs[0x3b46>>1]=regs[7]; + } +} + +void gp2x_dualcore_sync(void) +{ + gp2x_queue *q=(gp2x_queue *)gp2x_1stcore_data_ptr(GP2X_QUEUE_ARRAY_PTR); + while(q->items); +} + +void gp2x_dualcore_exec(unsigned long command) { gp2x_enqueue((gp2x_queue *)gp2x_1stcore_data_ptr(GP2X_QUEUE_ARRAY_PTR),command); } + +void gp2x_dualcore_launch_program(unsigned long *area, unsigned long size) +{ + unsigned long i=0, *arm940t_ram=(unsigned long *)gp2x_dualcore_ram; + + gp2x_940t_reset(1); + + gp2x_memregs[0x3B40>>1] = 0; //disable interrupts + gp2x_memregs[0x3B42>>1] = 0; + gp2x_memregs[0x3B44>>1] = 0xffff; + gp2x_memregs[0x3B46>>1] = 0xffff; + + gp2x_940t_pause(0); + + while(i < size) *arm940t_ram++=area[i++]; + + gp2x_initqueue((gp2x_queue *)gp2x_1stcore_data_ptr(GP2X_QUEUE_ARRAY_PTR), GP2X_QUEUE_MAX_ITEMS, (unsigned long *)gp2x_1stcore_data_ptr(GP2X_QUEUE_DATA_PTR), (unsigned long *)gp2x_2ndcore_data_ptr(GP2X_QUEUE_DATA_PTR)); + + gp2x_940t_reset(0); +} + +void gp2x_dualcore_launch_program_from_disk(const char *file, unsigned long offset, unsigned long size) +{ + FILE *in; void *data; + + if((in=fopen(file, "rb"))==NULL) return; + if((data=malloc(size))==NULL) { fclose(in); return; } + fseek(in, 0L, offset); + fread(data, 1, size, in); + gp2x_dualcore_launch_program((unsigned long *)data, size); + free(data); + fclose(in); +} + +void gp2x_init(int ticks_per_second, int bpp, int rate, int bits, int stereo, int Hz) +{ + struct fb_fix_screeninfo fixed_info; + static int first=1; + + // GP2X_DO_SOUND + int gp2x_do_sound=1; + int frag=0; + int channels=1; + int stereoLocal=0; + + gp2x_ticks_per_second=7372800/ticks_per_second; + + if(!gp2x_dev[0]) gp2x_dev[0] = open("/dev/fb0", O_RDWR); + if(!gp2x_dev[1]) gp2x_dev[1] = open("/dev/fb1", O_RDWR); + if(!gp2x_dev[2]) gp2x_dev[2] = open("/dev/mem", O_RDWR); + + // don't run sound right now + if ( gp2x_do_sound) + { + if(!gp2x_dev[3]) gp2x_dev[3] = open("/dev/dsp", O_WRONLY); + if(!gp2x_dev[4]) gp2x_dev[4] = open("/dev/mixer", O_RDWR); + } + + gp2x_dualcore_ram=(unsigned long *)mmap(0, 0x1000000, PROT_READ|PROT_WRITE, MAP_SHARED, gp2x_dev[2], 0x03000000); +/*gp2x_dualcore_ram=(unsigned long *)mmap(0, 0x2000000, PROT_READ|PROT_WRITE, MAP_SHARED, gp2x_dev[2], 0x02000000);*/ + gp2x_memregl=(unsigned long *)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, gp2x_dev[2], 0xc0000000); + gp2x_memregs=(unsigned short *)gp2x_memregl; + + if(first) { printf(MINILIB_VERSION "\n"); + gp2x_dualcore_registers(1); + gp2x_sound_volume(100,100); + gp2x_memregs[0x0F16>>1] = 0x830a; usleep(100000); + gp2x_memregs[0x0F58>>1] = 0x100c; usleep(100000); } + + ioctl(gp2x_dev[gp2x_physvram[7]=0], FBIOGET_FSCREENINFO, &fixed_info); + gp2x_screen15=gp2x_logvram15[2]=gp2x_logvram15[0]=(unsigned short *)mmap(0, 320*240*2, PROT_WRITE, MAP_SHARED, gp2x_dev[0], 0); + gp2x_screen8=(unsigned char *)gp2x_screen15; + gp2x_physvram[2]=gp2x_physvram[0]=fixed_info.smem_start; + + ioctl(gp2x_dev[1], FBIOGET_FSCREENINFO, &fixed_info); + gp2x_logvram15[3]=gp2x_logvram15[1]=(unsigned short *)mmap(0, 320*240*2, PROT_WRITE, MAP_SHARED, gp2x_dev[1], 0); + gp2x_physvram[3]=gp2x_physvram[1]=fixed_info.smem_start; + + gp2x_memregs[0x28DA>>1]=(((bpp+1)/8)<<9)|0xAB; /*8/15/16/24bpp...*/ + gp2x_memregs[0x290C>>1]=320*((bpp+1)/8); /*line width in bytes*/ + + memset(gp2x_screen15, 0, 320*240*2); gp2x_video_flip(); + memset(gp2x_screen15, 0, 320*240*2); gp2x_video_flip(); + + if(bpp==8) gp2x_physvram[2]+=320*240, gp2x_physvram[3]+=320*240, + gp2x_logvram15[2]+=320*240/2, gp2x_logvram15[3]+=320*240/2; + + + if ( gp2x_do_sound) + { + + ioctl(gp2x_dev[3], SNDCTL_DSP_SPEED, &rate); + ioctl(gp2x_dev[3], SNDCTL_DSP_SETFMT, &bits); + + ioctl(gp2x_dev[3], SNDCTL_DSP_CHANNELS, &channels); + ioctl(gp2x_dev[3], SNDCTL_DSP_STEREO, &stereoLocal); + + frag = 0x40000|13; + ioctl(gp2x_dev[3], SNDCTL_DSP_SETFRAGMENT, &frag); + + + printf("minimal() do sound, rate %d, bits %d, stereo %d, frag %d\n", rate, bits, stereo, frag); + + if(first) + { + first=0; + } + } + +} + + +extern int fcloseall(void); +void gp2x_deinit(void) +{ + while((gp2x_sound++)<1000000); //wait arm920t threads to finish + + gp2x_dualcore_registers(0); + + gp2x_memregs[0x28DA>>1]=0x4AB; //set video mode + gp2x_memregs[0x290C>>1]=640; + + { int i; for(i=0;i<8;i++) if(gp2x_dev[i]) close(gp2x_dev[i]); } //close all devices + + fcloseall(); //close all files + +} + + +void SetVideoScaling(int pixels,int width,int height) +{ + float x, y; + float xscale,yscale; + + int bpp=(gp2x_memregs[0x28DA>>1]>>9)&0x3; /* bytes per pixel */ + + if(gp2x_memregs[0x2800>>1]&0x100) /* TV-Out ON? */ + { + xscale=489.0; /* X-Scale with TV-Out (PAL or NTSC) */ + if (gp2x_memregs[0x2818>>1] == 287) /* PAL? */ + yscale=(pixels*274.0)/320.0; /* Y-Scale with PAL */ + else if (gp2x_memregs[0x2818>>1] == 239) /* NTSC? */ + yscale=(pixels*331.0)/320.0; /* Y-Scale with NTSC */ + } + else /* TV-Out OFF? */ + { + xscale=1024.0; /* X-Scale for LCD */ + yscale=pixels; /* Y-Scale for LCD */ + } + + x=(xscale*width)/320.0; + y=(yscale*bpp*height)/240.0; + gp2x_memregs[0x2906>>1]=(unsigned short)x; /* scale horizontal */ + gp2x_memregl[0x2908>>2]=(unsigned long)y; /* scale vertical */ + gp2x_memregs[0x290C>>1]=pixels*bpp; /* Set Video Width */ +} diff --git a/drivers/cli/minimal.h b/drivers/cli/minimal.h new file mode 100644 index 0000000..53127b9 --- /dev/null +++ b/drivers/cli/minimal.h @@ -0,0 +1,108 @@ +/* + + GP2X minimal library v0.A by rlyeh, (c) 2005. emulnation.info@rlyeh (swap it!) + + Thanks to Squidge, Robster, snaff, Reesy and NK, for the help & previous work! :-) + + License + ======= + + Free for non-commercial projects (it would be nice receiving a mail from you). + Other cases, ask me first. + + GamePark Holdings is not allowed to use this library and/or use parts from it. + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include + +#include +#include +#include + +#ifndef __MINIMAL_H__ +#define __MINIMAL_H__ + +#define MINILIB_VERSION "GP2X minimal library v0.A by rlyeh, (c) 2005." + +typedef struct gp2x_queue { volatile unsigned long head, tail, items, max_items; unsigned long *place920t, *place940t; } gp2x_queue; +typedef struct gp2x_rect { int x,y,w,h,solid; unsigned short *data15; unsigned char *data8; } gp2x_rect; + +extern void gp2x_timer_delay(unsigned long ticks); +extern void gp2x_sound_pause(int yes); +extern void gp2x_dualcore_pause(int yes); +extern void gp2x_blitter_rect15(gp2x_rect *r); +extern void gp2x_blitter_rect8(gp2x_rect *r); + + + +//extern void gp2x_sound_frame (void *blah, void *bufferg, int samples); + +enum { GP2X_UP=0x1, GP2X_LEFT=0x4, GP2X_DOWN=0x10, GP2X_RIGHT=0x40, + GP2X_START=1<<8, GP2X_SELECT=1<<9, GP2X_L=1<<10, GP2X_R=1<<11, + GP2X_A=1<<12, GP2X_B=1<<13, GP2X_X=1<<14, GP2X_Y=1<<15, + GP2X_VOL_UP=1<<23, GP2X_VOL_DOWN=1<<22, GP2X_PUSH=1<<27 }; + + +#define GP2X_QUEUE_MAX_ITEMS 16 +#define GP2X_QUEUE_ARRAY_PTR ((0x1000-(sizeof(gp2x_queue)<<2))) +#define GP2X_QUEUE_DATA_PTR (GP2X_QUEUE_ARRAY_PTR-(GP2X_QUEUE_MAX_ITEMS<<2)) + +#define gp2x_2ndcore_code(v) (*(volatile unsigned long *)(v)) +#define gp2x_1stcore_code(v) gp2x_dualcore_ram[(v)>>2] +#define gp2x_2ndcore_data(v) gp2x_2ndcore_code((v)+0x100000) +#define gp2x_1stcore_data(v) gp2x_1stcore_code((v)+0x100000) +#define gp2x_dualcore_data(v) gp2x_1stcore_data(v) + +#define gp2x_2ndcore_code_ptr(v) ((volatile unsigned long *)(v)) +#define gp2x_1stcore_code_ptr(v) (&gp2x_dualcore_ram[(v)>>2]) +#define gp2x_2ndcore_data_ptr(v) gp2x_2ndcore_code_ptr((v)+0x100000) +#define gp2x_1stcore_data_ptr(v) gp2x_1stcore_code_ptr((v)+0x100000) + +#define gp2x_video_wait_vsync() while(gp2x_memregs[0x1182>>1]&(1<<4)); +#define gp2x_video_wait_hsync() while(gp2x_memregs[0x1182>>1]&(1<<5)); + +#define gp2x_video_color8(C,R,G,B) do gp2x_palette[((C)<<1)+0]=((G)<<8)|(B),gp2x_palette[((C)<<1)+1]=(R); while(0) +#define gp2x_video_color15(R,G,B,A) ((((R)&0xF8)<<8)|(((G)&0xF8)<<3)|(((B)&0xF8)>>3)|((A)<<5)) + + +extern volatile unsigned short gp2x_palette[512]; +extern unsigned short *gp2x_screen15; +extern unsigned char *gp2x_screen8; +extern volatile unsigned long *gp2x_dualcore_ram; + +extern void gp2x_init(int tickspersecond, int bpp, int rate, int bits, int stereo, int hz); +extern void gp2x_deinit(void); + +extern void gp2x_video_flip(void); +extern void gp2x_video_flip_single(void); +extern void gp2x_video_setpalette(void); + +extern unsigned long gp2x_joystick_read(void); + +extern void gp2x_sound_volume(int left, int right); + +extern unsigned long gp2x_timer_read(void); +extern unsigned long gp2x_timer_read_ms(void); + +extern void gp2x_dualcore_enable(int on); +extern void gp2x_dualcore_sync(void); +extern void gp2x_dualcore_exec(unsigned long command); +extern void gp2x_dualcore_launch_program(unsigned long *area, unsigned long size); +extern void gp2x_dualcore_launch_program_from_disk(const char *file, unsigned long offset, unsigned long size); + +#define gp2x_dualcore_declare_subprogram(name) extern void gp2x_dualcore_launch_## name ##_subprogram(void); +#define gp2x_dualcore_launch_subprogram(name) gp2x_dualcore_launch_## name ##_subprogram() + +#endif + diff --git a/drivers/cli/minimal_940t.h b/drivers/cli/minimal_940t.h new file mode 100644 index 0000000..82cd1c0 --- /dev/null +++ b/drivers/cli/minimal_940t.h @@ -0,0 +1,96 @@ +/* + + GP2X minimal library v0.A by rlyeh, (c) 2005. emulnation.info@rlyeh (swap it!) + + Thanks to Squidge, Robster, snaff, Reesy and NK, for the help & previous work! :-) + + License + ======= + + Free for non-commercial projects (it would be nice receiving a mail from you). + Other cases, ask me first. + + GamePark Holdings is not allowed to use this library and/or use parts from it. + +*/ + +#include "minimal.h" + +#ifndef __MINIMAL_H_STUB_940T__ +#define __MINIMAL_H_STUB_940T__ + +#undef gp2x_dualcore_data +#define gp2x_dualcore_data(v) gp2x_2ndcore_data(v) + +#define main gp2x_2ndcore_run + +static void gp2x_2ndcore_start(void) __attribute__((naked)); + +static void gp2x_2ndcore_start(void) +{ + unsigned long gp2x_dequeue(gp2x_queue *q) + { + unsigned long data; + + while(!q->items); //waiting for head to increase... + + data=q->place940t[q->tail = (q->tail < q->max_items ? q->tail+1 : 0)]; + q->items--; + + return data; + } + +#define gp2x_dualcore_name_subprogram(name) \ +/* 00000020 <_start>: */ \ +/* 0:*/ asm volatile (".word 0xe59ff02c"); /* ldr pc, [pc, #44] ; 34 */ \ +/* 4:*/ asm volatile (".word 0xe59ff028"); /* ldr pc, [pc, #40] ; 34 */ \ +/* 8:*/ asm volatile (".word 0xe59ff024"); /* ldr pc, [pc, #36] ; 34 */ \ +/* c:*/ asm volatile (".word 0xe59ff020"); /* ldr pc, [pc, #32] ; 34 */ \ +/* 10:*/ asm volatile (".word 0xe59ff01c"); /* ldr pc, [pc, #28] ; 34 */ \ +/* 14:*/ asm volatile (".word 0xe59ff018"); /* ldr pc, [pc, #24] ; 34 */ \ +/* 18:*/ asm volatile (".word 0xe59ff014"); /* ldr pc, [pc, #20] ; 34 */ \ +/* 1c:*/ asm volatile (".word 0xe59ff010"); /* ldr pc, [pc, #16] ; 34 */ \ +/* 00000020 <_init>: */ \ +/* 20:*/ asm volatile (".word 0xe59fd010"); /* ldr sp, [pc, #16] ; 38 */ \ +/* 24:*/ asm volatile (".word 0xe59fc010"); /* ldr ip, [pc, #16] ; 3c */ \ +/* 28:*/ asm volatile (".word 0xe59fb010"); /* ldr fp, [pc, #16] ; 40 */ \ +/* 2c:*/ asm volatile (".word 0xe92d1800"); /* stmdb sp!, {fp, ip} */ \ +/* 30:*/ asm volatile (".word 0xea000004"); /* b 48 */ \ +/* 00000034 : */ \ +/* 34:*/ asm volatile (".word 0x00000020"); /* */ \ +/* 00000038 : */ \ +/* 38:*/ asm volatile (".word 0x000ffffc"); /* */ \ +/* 0000003c : */ \ +/* 3c:*/ asm volatile (".word 0xdeadbeef"); /* */ \ +/* 00000040 : */ \ +/* 40:*/ asm volatile (".word 0x1ee7face"); /* */ \ +/* 00000044 : */ \ +/* 44:*/ asm volatile (".word 0x00100019"); /* */ \ +/* 00000048 : */ \ +/* our main code starts here... */ \ +/* 48:*/ asm volatile (".word 0xe3a0003f"); /* mov r0, #63 ; 0x3f */ \ +/* 4c:*/ asm volatile (".word 0xee060f10"); /* mcr 15, 0, r0, cr6, cr0, {0} */ \ +/* 50:*/ asm volatile (".word 0xee060f30"); /* mcr 15, 0, r0, cr6, cr0, {1} */ \ +/* 54:*/ asm volatile (".word 0xe51f0018"); /* ldr r0, [pc, #-24] ; 44 */ \ +/* 58:*/ asm volatile (".word 0xee060f11"); /* mcr 15, 0, r0, cr6, cr1, {0} */ \ +/* 5c:*/ asm volatile (".word 0xee060f31"); /* mcr 15, 0, r0, cr6, cr1, {1} */ \ +/* 60:*/ asm volatile (".word 0xe3a00001"); /* mov r0, #1 ; 0x1 */ \ +/* 64:*/ asm volatile (".word 0xee020f10"); /* mcr 15, 0, r0, cr2, cr0, {0} */ \ +/* 68:*/ asm volatile (".word 0xee020f30"); /* mcr 15, 0, r0, cr2, cr0, {1} */ \ +/* 6c:*/ asm volatile (".word 0xee030f10"); /* mcr 15, 0, r0, cr3, cr0, {0} */ \ +/* 70:*/ asm volatile (".word 0xe3a0000f"); /* mov r0, #15 ; 0xf */ \ +/* 74:*/ asm volatile (".word 0xee050f10"); /* mcr 15, 0, r0, cr5, cr0, {0} */ \ +/* 78:*/ asm volatile (".word 0xee050f30"); /* mcr 15, 0, r0, cr5, cr0, {1} */ \ +/* 7c:*/ asm volatile (".word 0xee110f10"); /* mrc 15, 0, r0, cr1, cr0, {0} */ \ +/* 80:*/ asm volatile (".word 0xe3800001"); /* orr r0, r0, #1 ; 0x1 */ \ +/* 84:*/ asm volatile (".word 0xe3800004"); /* orr r0, r0, #4 ; 0x4 */ \ +/* 88:*/ asm volatile (".word 0xe3800a01"); /* orr r0, r0, #4096 ; 0x1000 */ \ +/* 8c:*/ asm volatile (".word 0xe3800103"); /* orr r0, r0, #-1073741824 ; 0xc0000000 */ \ +/* 90:*/ asm volatile (".word 0xee010f10"); /* mcr 15, 0, r0, cr1, cr0, {0} */ \ + while(1) gp2x_2ndcore_run(gp2x_dequeue((gp2x_queue *)gp2x_2ndcore_data_ptr(GP2X_QUEUE_ARRAY_PTR))); \ +} \ +void gp2x_dualcore_launch_##name##_subprogram(void) { gp2x_dualcore_launch_program((unsigned long *)&gp2x_2ndcore_start, ((int)&gp2x_dualcore_launch_##name##_subprogram)-((int)&gp2x_2ndcore_start)); } + +#endif + + diff --git a/drivers/win/cheat.c b/drivers/win/cheat.c deleted file mode 100644 index 3b53c2f..0000000 --- a/drivers/win/cheat.c +++ /dev/null @@ -1,471 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include "common.h" - -#include "cheat.h" - -static int selcheat; -static int scheatmethod=0; -static uint8 cheatval1=0; -static uint8 cheatval2=0; - -static void ConfigAddCheat(HWND wnd); - - -static uint16 StrToU16(char *s) -{ - unsigned int ret=0; - sscanf(s,"%4x",&ret); - return ret; -} - -static uint8 StrToU8(char *s) -{ - unsigned int ret=0; - sscanf(s,"%d",&ret); - return ret; -} - - -/* Need to be careful where these functions are used. */ -static char *U16ToStr(uint16 a) -{ - static char TempArray[16]; - sprintf(TempArray,"%04X",a); - return TempArray; -} - -static char *U8ToStr(uint8 a) -{ - static char TempArray[16]; - sprintf(TempArray,"%03d",a); - return TempArray; -} - - -static HWND RedoCheatsWND; -static int RedoCheatsCallB(char *name, uint32 a, uint8 v, int s) -{ - SendDlgItemMessage(RedoCheatsWND,101,LB_ADDSTRING,0,(LPARAM)(LPSTR)name); - return(1); -} - -static void RedoCheatsLB(HWND hwndDlg) -{ - SendDlgItemMessage(hwndDlg,101,LB_RESETCONTENT,0,0); - RedoCheatsWND=hwndDlg; - FCEUI_ListCheats(RedoCheatsCallB); -} - - -BOOL CALLBACK CheatsConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch(uMsg) - { - case WM_INITDIALOG: - RedoCheatsLB(hwndDlg); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - switch(HIWORD(wParam)) - { - case BN_CLICKED: - if(selcheat>=0) - { - if(LOWORD(wParam)==107) - FCEUI_SetCheat(selcheat,0,-1,-1,1); - else if(LOWORD(wParam)==108) - FCEUI_SetCheat(selcheat,0,-1,-1,0); - } - break; - case EN_KILLFOCUS: - if(selcheat>=0) - { - char TempArray[256]; - int32 t; - - GetDlgItemText(hwndDlg,LOWORD(wParam),TempArray,256); - switch(LOWORD(wParam)) - { - case 102:FCEUI_SetCheat(selcheat,TempArray,-1,-1,-1); - SendDlgItemMessage(hwndDlg,101,LB_INSERTSTRING,selcheat,(LPARAM)(LPCTSTR)TempArray); - SendDlgItemMessage(hwndDlg,101,LB_DELETESTRING,selcheat+1,0); - SendDlgItemMessage(hwndDlg,101,LB_SETCURSEL,selcheat,0); - break; - case 103:t=StrToU16(TempArray); - FCEUI_SetCheat(selcheat,0,t,-1,-1); - break; - case 104:t=StrToU8(TempArray); - FCEUI_SetCheat(selcheat,0,-1,t,-1); - break; - } - } - break; - } - - switch(LOWORD(wParam)) - { - case 101: - if(HIWORD(wParam)==LBN_SELCHANGE) - { - char *s; - uint32 a; - uint8 b; - int status; - - selcheat=SendDlgItemMessage(hwndDlg,101,LB_GETCURSEL,0,(LPARAM)(LPSTR)0); - if(selcheat<0) break; - - FCEUI_GetCheat(selcheat,&s,&a,&b,&status); - SetDlgItemText(hwndDlg,102,(LPTSTR)s); - SetDlgItemText(hwndDlg,103,(LPTSTR)U16ToStr(a)); - SetDlgItemText(hwndDlg,104,(LPTSTR)U8ToStr(b)); - - CheckRadioButton(hwndDlg,107,108,status?107:108); - } - break; - } - - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 106: - if(selcheat>=0) - { - FCEUI_DelCheat(selcheat); - SendDlgItemMessage(hwndDlg,101,LB_DELETESTRING,selcheat,0); - selcheat=-1; - SetDlgItemText(hwndDlg,102,(LPTSTR)""); - SetDlgItemText(hwndDlg,103,(LPTSTR)""); - SetDlgItemText(hwndDlg,104,(LPTSTR)""); - CheckRadioButton(hwndDlg,107,108,0); // Is this correct? - } - break; - case 105: - ConfigAddCheat(hwndDlg); - RedoCheatsLB(hwndDlg); - break; - case 1: - gornk: - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - - -void ConfigCheats(HWND hParent) -{ - if(!GI) - { - FCEUD_PrintError("You must have a game loaded before you can manipulate cheats."); - return; - } - - if(GI->type==GIT_NSF) - { - FCEUD_PrintError("Sorry, you can't cheat with NSFs."); - return; - } - - selcheat=-1; - DialogBox(fceu_hInstance,"CHEATS",hParent,CheatsConCallB); -} - - - - - - -HWND cfcallbw; - -int cfcallb(uint32 a, uint8 last, uint8 current) -{ - char temp[16]; - - sprintf(temp,"%04X:%03d:%03d",(unsigned int)a,last,current); - SendDlgItemMessage(cfcallbw,108,LB_ADDSTRING,0,(LPARAM)(LPSTR)temp); - return(1); -} - -static int scrollindex; -static int scrollnum; -static int scrollmax; - -int cfcallbinsert(uint32 a, uint8 last, uint8 current) -{ - char temp[16]; - - sprintf(temp,"%04X:%03d:%03d",(unsigned int)a,last,current); - SendDlgItemMessage(cfcallbw,108,LB_INSERTSTRING,13,(LPARAM)(LPSTR)temp); - return(1); -} - -int cfcallbinsertt(uint32 a, uint8 last, uint8 current) -{ - char temp[16]; - - sprintf(temp,"%04X:%03d:%03d",(unsigned int)a,last,current); - SendDlgItemMessage(cfcallbw,108,LB_INSERTSTRING,0,(LPARAM)(LPSTR)temp); - return(1); -} - - -void AddTheThing(HWND hwndDlg, char *s, int a, int v) -{ - if(FCEUI_AddCheat(s,a,v)) - MessageBox(hwndDlg,"Cheat Added","Cheat Added",MB_OK); -} - - -static void DoGet(void) -{ - int n=FCEUI_CheatSearchGetCount(); - int t; - scrollnum=n; - scrollindex=-32768; - - SendDlgItemMessage(cfcallbw,108,LB_RESETCONTENT,0,0); - FCEUI_CheatSearchGetRange(0,13,cfcallb); - - t=-32768+n-1-13; - if(t<-32768) - t=-32768; - scrollmax=t; - SendDlgItemMessage(cfcallbw,120,SBM_SETRANGE,-32768,t); - SendDlgItemMessage(cfcallbw,120,SBM_SETPOS,-32768,1); -} - - -BOOL CALLBACK AddCheatCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - static int lbfocus; - static HWND hwndLB; - cfcallbw=hwndDlg; - - - switch(uMsg) - { - case WM_VSCROLL: - if(scrollnum>13) - { - switch((int)LOWORD(wParam)) - { - case SB_TOP: - scrollindex=-32768; - SendDlgItemMessage(hwndDlg,120,SBM_SETPOS,scrollindex,1); - SendDlgItemMessage(hwndDlg,108,LB_RESETCONTENT,13,0); - FCEUI_CheatSearchGetRange(scrollindex+32768,scrollindex+32768+13,cfcallb); - break; - case SB_BOTTOM: - scrollindex=scrollmax; - SendDlgItemMessage(hwndDlg,120,SBM_SETPOS,scrollindex,1); - SendDlgItemMessage(hwndDlg,108,LB_RESETCONTENT,13,0); - FCEUI_CheatSearchGetRange(scrollindex+32768,scrollindex+32768+13,cfcallb); - break; - case SB_LINEUP: - if(scrollindex>-32768) - { - scrollindex--; - SendDlgItemMessage(hwndDlg,120,SBM_SETPOS,scrollindex,1); - SendDlgItemMessage(hwndDlg,108,LB_DELETESTRING,13,0); - FCEUI_CheatSearchGetRange(scrollindex+32768,scrollindex+32768,cfcallbinsertt); - } - break; - - case SB_PAGEUP: - scrollindex-=14; - if(scrollindex<-32768) scrollindex=-32768; - SendDlgItemMessage(hwndDlg,120,SBM_SETPOS,scrollindex,1); - SendDlgItemMessage(hwndDlg,108,LB_RESETCONTENT,13,0); - FCEUI_CheatSearchGetRange(scrollindex+32768,scrollindex+32768+13,cfcallb); - break; - - case SB_LINEDOWN: - if(scrollindexscrollmax) - scrollindex=scrollmax; - SendDlgItemMessage(hwndDlg,120,SBM_SETPOS,scrollindex,1); - SendDlgItemMessage(hwndDlg,108,LB_RESETCONTENT,0,0); - FCEUI_CheatSearchGetRange(scrollindex+32768,scrollindex+32768+13,cfcallb); - break; - - case SB_THUMBPOSITION: - case SB_THUMBTRACK: - scrollindex=(short int)HIWORD(wParam); - SendDlgItemMessage(hwndDlg,120,SBM_SETPOS,scrollindex,1); - SendDlgItemMessage(hwndDlg,108,LB_RESETCONTENT,0,0); - FCEUI_CheatSearchGetRange(32768+scrollindex,32768+scrollindex+13,cfcallb); - break; - } - - } - break; - - case WM_INITDIALOG: - SetDlgItemText(hwndDlg,110,(LPTSTR)U8ToStr(cheatval1)); - SetDlgItemText(hwndDlg,111,(LPTSTR)U8ToStr(cheatval2)); - DoGet(); - CheckRadioButton(hwndDlg,115,118,scheatmethod+115); - lbfocus=0; - hwndLB=0; - break; - - case WM_VKEYTOITEM: - if(lbfocus) - { - int real; - - real=SendDlgItemMessage(hwndDlg,108,LB_GETCURSEL,0,(LPARAM)(LPSTR)0); - switch((int)LOWORD(wParam)) - { - case VK_UP: - /* mmmm....recursive goodness */ - if(!real) - SendMessage(hwndDlg,WM_VSCROLL,SB_LINEUP,0); - return(-1); - break; - case VK_DOWN: - if(real==13) - SendMessage(hwndDlg,WM_VSCROLL,SB_LINEDOWN,0); - return(-1); - break; - case VK_PRIOR: - SendMessage(hwndDlg,WM_VSCROLL,SB_PAGEUP,0); - break; - case VK_NEXT: - SendMessage(hwndDlg,WM_VSCROLL,SB_PAGEDOWN,0); - break; - case VK_HOME: - SendMessage(hwndDlg,WM_VSCROLL,SB_TOP,0); - break; - case VK_END: - SendMessage(hwndDlg,WM_VSCROLL,SB_BOTTOM,0); - break; - } - return(-2); - } - break; - - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - switch(LOWORD(wParam)) - { - case 108: - switch(HIWORD(wParam)) - { - case LBN_SELCHANGE: - { - char TempArray[32]; - SendDlgItemMessage(hwndDlg,108,LB_GETTEXT,SendDlgItemMessage(hwndDlg,108,LB_GETCURSEL,0,(LPARAM)(LPSTR)0),(LPARAM)(LPCTSTR)TempArray); - TempArray[4]=0; - SetDlgItemText(hwndDlg,201,(LPTSTR)TempArray); - } - break; - case LBN_SETFOCUS: - lbfocus=1; - break; - case LBN_KILLFOCUS: - lbfocus=0; - break; - } - break; - } - - switch(HIWORD(wParam)) - { - case BN_CLICKED: - if(LOWORD(wParam)>=115 && LOWORD(wParam)<=118) - scheatmethod=LOWORD(wParam)-115; - break; - case EN_CHANGE: - { - char TempArray[256]; - GetDlgItemText(hwndDlg,LOWORD(wParam),TempArray,256); - switch(LOWORD(wParam)) - { - case 110:cheatval1=StrToU8(TempArray);break; - case 111:cheatval2=StrToU8(TempArray);break; - } - } - break; - } - - - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 112: - FCEUI_CheatSearchBegin(); - DoGet(); - break; - case 113: - FCEUI_CheatSearchEnd(scheatmethod,cheatval1,cheatval2); - DoGet(); - break; - case 114: - FCEUI_CheatSearchSetCurrentAsOriginal(); - DoGet(); - break; - case 107: - FCEUI_CheatSearchShowExcluded(); - DoGet(); - break; - case 105: - { - int a,v; - char temp[256]; - - GetDlgItemText(hwndDlg,201,temp,4+1); - a=StrToU16(temp); - GetDlgItemText(hwndDlg,202,temp,3+1); - v=StrToU8(temp); - - GetDlgItemText(hwndDlg,200,temp,256); - AddTheThing(hwndDlg,temp,a,v); - } - break; - case 106: - gornk: - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - -static void ConfigAddCheat(HWND wnd) -{ - DialogBox(fceu_hInstance,"ADDCHEAT",wnd,AddCheatCallB); -} diff --git a/drivers/win/cheat.h b/drivers/win/cheat.h deleted file mode 100644 index b3cd3cc..0000000 --- a/drivers/win/cheat.h +++ /dev/null @@ -1 +0,0 @@ -void ConfigCheats(HWND hParent); diff --git a/drivers/win/common.h b/drivers/win/common.h deleted file mode 100644 index 91b8d3d..0000000 --- a/drivers/win/common.h +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -#ifndef WIN32 -#define WIN32 -#endif -#undef WINNT -#define NONAMELESSUNION - -#define DIRECTSOUND_VERSION 0x0700 -#define DIRECTDRAW_VERSION 0x0700 -#define DIRECTINPUT_VERSION 0x700 -#include "../../driver.h" - -extern HWND hAppWnd; -extern HINSTANCE fceu_hInstance; - -extern int NoWaiting; -extern FCEUGI *GI; diff --git a/drivers/win/config.c b/drivers/win/config.c deleted file mode 100644 index 761a7a9..0000000 --- a/drivers/win/config.c +++ /dev/null @@ -1,132 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -/****************************************************************/ -/* FCE Ultra */ -/* */ -/* This file contains code to interface to the standard */ -/* FCE Ultra configuration file saving/loading code. */ -/* */ -/****************************************************************/ -#include "../common/config.h" - -static CFGSTRUCT fceuconfig[]={ - - ACS(rfiles[0]), - ACS(rfiles[1]), - ACS(rfiles[2]), - ACS(rfiles[3]), - ACS(rfiles[4]), - ACS(rfiles[5]), - ACS(rfiles[6]), - ACS(rfiles[7]), - ACS(rfiles[8]), - ACS(rfiles[9]), - - AC(ntsccol),AC(ntsctint),AC(ntschue), - - AC(soundsleep), - NAC("palyo",palyo), - NAC("genie",genie), - NAC("fs",fullscreen), - NAC("vgamode",vmod), - NAC("sound",soundo), - - ACS(gfsdir), - - NACS("odcheats",DOvers[0]), - NACS("odmisc",DOvers[1]), - NACS("odnonvol",DOvers[2]), - NACS("odstates",DOvers[3]), - NACS("odsnaps",DOvers[4]), - NACS("odbase",DOvers[5]), - - NAC("winsizemul",winsizemul), - - AC(soundrate), - AC(soundbuftime), - AC(soundoptions), - AC(soundvolume), - - NAC("eoptions",eoptions), - NACA("cpalette",cpalette), - - ACA(joy), - ACA(joyA),ACA(joyB),ACA(joySelect),ACA(joyStart), - - AC(joyOptions), - ACA(joyUp),ACA(joyDown),ACA(joyLeft),ACA(joyRight), - - NACA("InputType",UsrInputType), - NAC("keyben",keybEnable), - - NACA("keybm0",keyBMap[0]), - NACA("keybm1",keyBMap[1]), - NACA("keybm2",keyBMap[2]), - NACA("keybm3",keyBMap[3]), - NACA("ppasc0",powerpadsc[0]), - NACA("ppasc1",powerpadsc[1]), - - NAC("ppaside",powerpadside), - NAC("vmcx",vmodes[0].x), - NAC("vmcy",vmodes[0].y), - NAC("vmcb",vmodes[0].bpp), - NAC("vmcf",vmodes[0].flags), - NAC("vmcxs",vmodes[0].xscale), - NAC("vmcys",vmodes[0].yscale), - - NAC("srendline",srendlinen), - NAC("erendline",erendlinen), - NAC("srendlinep",srendlinep), - NAC("erendlinep",erendlinep), - - AC(UsrInputTypeFC), - AC(winsync), - AC(fssync), - AC(NoFourScore), - ACA(fkbmap), - ENDCFGSTRUCT -}; - -static void SaveConfig(char *filename) -{ - DriverInterface(DES_GETNTSCTINT,&ntsctint); - DriverInterface(DES_GETNTSCHUE,&ntschue); - SaveFCEUConfig(filename,fceuconfig); -} - -static void LoadConfig(char *filename) -{ - DriverInterface(DES_GETNTSCTINT,&ntsctint); - DriverInterface(DES_GETNTSCHUE,&ntschue); - LoadFCEUConfig(filename,fceuconfig); - DriverInterface(DES_NTSCCOL,&ntsccol); - DriverInterface(DES_SETNTSCTINT,&ntsctint); - DriverInterface(DES_SETNTSCHUE,&ntschue); - - palyo&=1; - FCEUI_SetVidSystem(palyo); - genie&=1; - FCEUI_SetGameGenie(genie); - fullscreen&=1; - soundo&=1; - FCEUI_SetSoundVolume(soundvolume); -} - diff --git a/drivers/win/input.c b/drivers/win/input.c deleted file mode 100644 index aea3f47..0000000 --- a/drivers/win/input.c +++ /dev/null @@ -1,288 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include "common.h" -#include - -#include "input.h" -#include "keyboard.h" -#include "joystick.h" - - -int UsrInputType[2]={SI_GAMEPAD,SI_GAMEPAD}; -int UsrInputTypeFC=SIFC_NONE; -int InputType[2]; -int InputTypeFC; - -int NoFourScore=0; - -static uint32 powerpadbuf[2]; - -LPDIRECTINPUT7 lpDI; - -void FixGIGO(void) -{ - InputType[0]=UsrInputType[0]; - InputType[1]=UsrInputType[1]; - InputTypeFC=UsrInputTypeFC; - - if(GI) - { - if(GI->input[0]>=0) - InputType[0]=GI->input[0]; - if(GI->input[1]>=0) - InputType[1]=GI->input[1]; - if(GI->inputfc>=0) - InputTypeFC=GI->inputfc; - CreateInputStuff(); - } -} - -static uint32 JSreturn; -static uint32 mousedata[3]; - - -static void ConfigGamePad(HWND hParent, int port); - -int InitDInput(void) -{ - HRESULT ddrval; - - ddrval=DirectInputCreateEx(fceu_hInstance,DIRECTINPUT_VERSION,&IID_IDirectInput7,(LPVOID *)&lpDI,0); - if(ddrval!=DI_OK) - { - FCEUD_PrintError("DirectInput: Error creating DirectInput object."); - return 0; - } - return 1; -} - -static int screenmode=0; -void InputScreenChanged(int fs) -{ - int x; - for(x=0;x<2;x++) - if(InputType[x]==SI_ZAPPER) - FCEUI_SetInput(x,SI_ZAPPER,mousedata,fs); - if(InputTypeFC==SIFC_SHADOW) - FCEUI_SetInputFC(SIFC_SHADOW,mousedata,fs); - screenmode=fs; -} - -void InitInputStuff(void) -{ - KeyboardInitialize(); - InitJoysticks(hAppWnd); -} - -void CreateInputStuff(void) -{ - void *InputDPtr=0; - int x; - int TAttrib; - - for(x=0;x<2;x++) - { - TAttrib=0; - switch(InputType[x]) - { - case SI_GAMEPAD:InputDPtr=((uint8 *)&JSreturn)+(x<<1); - break; - case SI_POWERPAD:InputDPtr=&powerpadbuf[x];break; - case SI_ARKANOID:InputDPtr=mousedata;break; - case SI_ZAPPER:InputDPtr=mousedata; - TAttrib=screenmode; - break; - } - FCEUI_SetInput(x,InputType[x],InputDPtr,TAttrib); - } - - TAttrib=0; - switch(InputTypeFC) - { - case SIFC_SHADOW:InputDPtr=mousedata;TAttrib=screenmode;break; - case SIFC_ARKANOID:InputDPtr=mousedata;break; - case SIFC_FKB:InputDPtr=fkbkeys;memset(fkbkeys,0,sizeof(fkbkeys));break; - } - FCEUI_SetInputFC(InputTypeFC,InputDPtr,TAttrib); - FCEUI_DisableFourScore(NoFourScore); -} - -void DestroyInput(void) -{ - KillJoysticks(); - KeyboardClose(); -} - -void FCEUD_UpdateInput(void) -{ - int x; - uint32 JS; - int t=0; - - KeyboardUpdate(); - - for(x=0;x<2;x++) - switch(InputType[x]) - { - case SI_GAMEPAD:t|=1;break; - case SI_ARKANOID:t|=2;break; - case SI_ZAPPER:t|=2;break; - case SI_POWERPAD:powerpadbuf[x]=UpdatePPadData(x);break; - } - switch(InputTypeFC) - { - case SIFC_ARKANOID:t|=2;break; - case SIFC_SHADOW:t|=2;break; - case SIFC_FKB: if(cidisabled) UpdateFKB();break; - } - if(t&1) - { - JS=KeyboardDodo(); - if(joy[0]|joy[1]|joy[2]|joy[3]) - JS|=(uint32)GetJSOr(); - JSreturn=(JS&0xFF000000)|(JS&0xFF)|((JS&0xFF0000)>>8)|((JS&0xFF00)<<8); - } - if(t&2) - GetMouseData(&mousedata[0], &mousedata[1], &mousedata[2]); -} - - -BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - static void (*boopar[5])(HWND hParent, int port)={0,ConfigGamePad,0,ConfigKeyboardiePowerpad,0}; - static void (*boopar2[5])(HWND hParent)={0,0,0,0,ConfigFKB}; - static char *strn[5]={"","Gamepad","Zapper","Power Pad","Arkanoid Paddle"}; - static char *strf[5]={"","Arkanoid Paddle","Hyper Shot gun","4-Player Adapter","Family Keyboard"}; - int x; - - switch(uMsg) { - case WM_INITDIALOG: - for(x=0;x<2;x++) - { - int y; - - for(y=0;y<5;y++) - SendDlgItemMessage(hwndDlg,104+x,CB_ADDSTRING,0,(LPARAM)(LPSTR)strn[y]); - - SendDlgItemMessage(hwndDlg,104+x,CB_SETCURSEL,UsrInputType[x],(LPARAM)(LPSTR)0); - EnableWindow(GetDlgItem(hwndDlg,106+x),boopar[InputType[x]]?1:0); - SetDlgItemText(hwndDlg,200+x,(LPTSTR)strn[InputType[x]]); - } - - - { - int y; - for(y=0;y<5;y++) - SendDlgItemMessage(hwndDlg,110,CB_ADDSTRING,0,(LPARAM)(LPSTR)strf[y]); - SendDlgItemMessage(hwndDlg,110,CB_SETCURSEL,UsrInputTypeFC,(LPARAM)(LPSTR)0); - EnableWindow(GetDlgItem(hwndDlg,111),boopar2[InputTypeFC]?1:0); - SetDlgItemText(hwndDlg,202,(LPTSTR)strf[InputTypeFC]); - } - - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(HIWORD(wParam)==CBN_SELENDOK) - { - switch(LOWORD(wParam)) - { - case 104: - case 105:UsrInputType[LOWORD(wParam)-104]=InputType[LOWORD(wParam)-104]=SendDlgItemMessage(hwndDlg,LOWORD(wParam),CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - EnableWindow( GetDlgItem(hwndDlg,LOWORD(wParam)+2),boopar[InputType[LOWORD(wParam)-104]]?1:0); - SetDlgItemText(hwndDlg,200+LOWORD(wParam)-104,(LPTSTR)strn[InputType[LOWORD(wParam)-104]]); - break; - case 110:UsrInputTypeFC=InputTypeFC=SendDlgItemMessage(hwndDlg,110,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - EnableWindow(GetDlgItem(hwndDlg,111),boopar2[InputTypeFC]?1:0); - SetDlgItemText(hwndDlg,202,(LPTSTR)strf[InputTypeFC]); - break; - - } - - } - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 111: - if(boopar2[InputTypeFC]) - boopar2[InputTypeFC](hwndDlg); - break; - - case 107: - case 106: - { - int t=(wParam&0xFFFF)-106; - if(boopar[InputType[t]]) - boopar[InputType[t]](hwndDlg,t); - } - break; - case 1: - gornk: - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - -void ConfigInput(HWND hParent) -{ - DialogBox(fceu_hInstance,"INPUTCONFIG",hParent,InputConCallB); - CreateInputStuff(); -} - - -static int porttemp; - -BOOL CALLBACK GPConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch(uMsg) { - case WM_INITDIALOG: - if(NoFourScore) - CheckDlgButton(hwndDlg,200,BST_CHECKED); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 107:ConfigJoystickies(hwndDlg, porttemp);break; - case 106:ConfigKeyboardie(hwndDlg, porttemp);break; - case 1: - gornk: - NoFourScore=0; - if(IsDlgButtonChecked(hwndDlg,200)==BST_CHECKED) - NoFourScore=1; - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - -static void ConfigGamePad(HWND hParent, int port) -{ - porttemp=port; - DialogBox(fceu_hInstance,"GAMEPADCONFIG",hParent,GPConCallB); -} - - diff --git a/drivers/win/input.h b/drivers/win/input.h deleted file mode 100644 index 559f1af..0000000 --- a/drivers/win/input.h +++ /dev/null @@ -1,25 +0,0 @@ -void ConfigInput(HWND hParent); -int InitDInput(void); -void CreateInputStuff(void); -void InitInputStuff(void); -void DestroyInput(void); -void InputScreenChanged(int fs); -void FixGIGO(void); - -extern LPDIRECTINPUT7 lpDI; - -#define JOY_A 1 -#define JOY_B 2 -#define JOY_SELECT 4 -#define JOY_START 8 -#define JOY_UP 0x10 -#define JOY_DOWN 0x20 -#define JOY_LEFT 0x40 -#define JOY_RIGHT 0x80 - - -extern int InputType[2]; -extern int InputTypeFC; -extern int NoFourScore; -extern int UsrInputType[2]; -extern int UsrInputTypeFC; diff --git a/drivers/win/joystick.c b/drivers/win/joystick.c deleted file mode 100644 index 375b7af..0000000 --- a/drivers/win/joystick.c +++ /dev/null @@ -1,407 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include "common.h" -#include - -#include "input.h" -#include "joystick.h" - - -HRESULT ddrval; - -static GUID joyGUID[64]; - -static int joycounter; - -static LPDIRECTINPUTDEVICE7 lpJoy[4]={0,0,0,0}; - -int joyOptions[4]={0,0,0,0}; -int joyA[4]={1,1,1,1}; -int joyB[4]={0,0,0,0}; -int joySelect[4]={2,2,2,2}; -int joyStart[4]={3,3,3,3}; -int joyUp[4]={4,4,4,4}; -int joyDown[4]={5,5,5,5}; -int joyLeft[4]={6,6,6,6}; -int joyRight[4]={7,7,7,7}; - -int joy[4]={0,0,0,0}; - -static int JoyXMax[4]; -static int JoyXMin[4]; - -static int JoyYMax[4]; -static int JoyYMin[4]; - -static DIJOYSTATE2 JoyStatus; - -static void ShowDIJErr(int w, char *s) -{ - char tempo[128]; - sprintf(tempo,"DirectInput: Joystick %d: %s",w+1,s); - FCEUD_PrintError(tempo); -} - -static void JoyAutoRestore(HRESULT ddrval,LPDIRECTINPUTDEVICE7 lpJJoy) -{ - switch(ddrval) - { - case DIERR_INPUTLOST: - case DIERR_NOTACQUIRED: - IDirectInputDevice7_Acquire(lpJJoy); - break; - } -} - -static int GetJoystickButton(int x) -{ - int errc=0; - int z; - - if(lpJoy[x]) - { - doagaino: - if(errc>8) return(-1); - - ddrval=IDirectInputDevice7_Poll(lpJoy[x]); - if(ddrval!=DI_OK && ddrval!=DI_NOEFFECT) {JoyAutoRestore(ddrval,lpJoy[x]);errc++;goto doagaino;} - - ddrval=IDirectInputDevice7_GetDeviceState(lpJoy[x],sizeof(JoyStatus),&JoyStatus); - if(ddrval!=DI_OK) {JoyAutoRestore(ddrval,lpJoy[x]);errc++;goto doagaino;} - - for(z=0;z<128;z++) - if(JoyStatus.rgbButtons[z]&0x80) - return z; - } - return(-1); -} - -uint32 GetJSOr(void) -{ - unsigned long ret; - int x; - ret=0; - - for(x=0;x<4;x++) - { - if(lpJoy[x]) - { - - ddrval=IDirectInputDevice7_Poll(lpJoy[x]); - if(ddrval!=DI_OK && ddrval!=DI_NOEFFECT) JoyAutoRestore(ddrval,lpJoy[x]); - - ddrval=IDirectInputDevice7_GetDeviceState(lpJoy[x],sizeof(JoyStatus),&JoyStatus); - if(ddrval!=DI_OK) JoyAutoRestore(ddrval,lpJoy[x]); - - if(joyOptions[x]&1) - { - if(JoyStatus.rgbButtons[joyUp[x]&127]&0x80) ret|=JOY_UP<<(x<<3); - if(JoyStatus.rgbButtons[joyDown[x]&127]&0x80) ret|=JOY_DOWN<<(x<<3); - if(JoyStatus.rgbButtons[joyLeft[x]&127]&0x80) ret|=JOY_LEFT<<(x<<3); - if(JoyStatus.rgbButtons[joyRight[x]&127]&0x80) ret|=JOY_RIGHT<<(x<<3); - } - else - { - if(JoyStatus.lX>=JoyXMax[x]) - ret|=JOY_RIGHT<<(x<<3); - else if(JoyStatus.lX<=JoyXMin[x]) - ret|=JOY_LEFT<<(x<<3); - - if(JoyStatus.lY>=JoyYMax[x]) - ret|=JOY_DOWN<<(x<<3); - else if(JoyStatus.lY<=JoyYMin[x]) - ret|=JOY_UP<<(x<<3); - } - if(JoyStatus.rgbButtons[joyA[x]&127]&0x80) ret|=1<<(x<<3); - if(JoyStatus.rgbButtons[joyB[x]&127]&0x80) ret|=2<<(x<<3); - if(JoyStatus.rgbButtons[joySelect[x]&127]&0x80) ret|=4<<(x<<3); - if(JoyStatus.rgbButtons[joyStart[x]&127]&0x80) ret|=8<<(x<<3); - } - } - - return ret; -} - -static void KillJoystick(int w) -{ - if(lpJoy[w]) - { - IDirectInputDevice7_Unacquire(lpJoy[w]); - IDirectInputDevice7_Release(lpJoy[w]); - lpJoy[w]=0; - } -} - -void KillJoysticks(void) -{ - int x; - for(x=0;x<4;x++) - KillJoystick(x); -} - -static BOOL CALLBACK JoystickFound(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) -{ - if(joycounter<64) - { - joyGUID[joycounter]=lpddi->guidInstance; - joycounter++; - if(pvRef) - { - SendDlgItemMessage(pvRef,106,CB_ADDSTRING,0,(LPARAM)(LPSTR)lpddi->tszProductName); - SendDlgItemMessage(pvRef,112,CB_ADDSTRING,0,(LPARAM)(LPSTR)lpddi->tszProductName); - } - return DIENUM_CONTINUE; - } - else - return 0; -} - -void InitJoystick(int w, HWND wnd) -{ - if(joy[w]) - { - if(joy[w]>joycounter) - { - ShowDIJErr(w,"Not found."); - joy[w]=0; - return; - } - ddrval=IDirectInput7_CreateDeviceEx(lpDI,&joyGUID[joy[w]-1],&IID_IDirectInputDevice7,(LPVOID *)&lpJoy[w],0); - if(ddrval != DI_OK) - { - ShowDIJErr(w,"Error creating device."); - joy[w]=0; - return; - } - ddrval=IDirectInputDevice7_SetCooperativeLevel(lpJoy[w],wnd,DISCL_FOREGROUND|DISCL_NONEXCLUSIVE); - if (ddrval != DI_OK) - { - ShowDIJErr(w,"Error setting cooperative level."); - KillJoystick(w); - joy[w]=0; - return; - } - ddrval=IDirectInputDevice7_SetDataFormat(lpJoy[w],&c_dfDIJoystick2); - if (ddrval != DI_OK) - { - ShowDIJErr(w,"Error setting data format."); - KillJoystick(w); - joy[w]=0; - return; - } - - { - DIPROPRANGE diprg; - int r; - - memset(&diprg,0,sizeof(DIPROPRANGE)); - diprg.diph.dwSize=sizeof(DIPROPRANGE); - diprg.diph.dwHeaderSize=sizeof(DIPROPHEADER); - diprg.diph.dwHow=DIPH_BYOFFSET; - diprg.diph.dwObj=DIJOFS_X; - ddrval=IDirectInputDevice7_GetProperty(lpJoy[w],DIPROP_RANGE,&diprg.diph); - if(ddrval!=DI_OK) - { - ShowDIJErr(w,"Error getting X axis range."); - joy[w]=0; - KillJoystick(w); - joy[w]=0; - return; - } - r=diprg.lMax-diprg.lMin; - JoyXMax[w]=diprg.lMax-(r>>2); - JoyXMin[w]=diprg.lMin+(r>>2); - - memset(&diprg,0,sizeof(DIPROPRANGE)); - diprg.diph.dwSize=sizeof(DIPROPRANGE); - diprg.diph.dwHeaderSize=sizeof(DIPROPHEADER); - diprg.diph.dwHow=DIPH_BYOFFSET; - diprg.diph.dwObj=DIJOFS_Y; - ddrval=IDirectInputDevice7_GetProperty(lpJoy[w],DIPROP_RANGE,&diprg.diph); - if(ddrval!=DI_OK) - { - ShowDIJErr(w,"Error getting X axis range."); - KillJoystick(w); - joy[w]=0; - return; - } - r=diprg.lMax-diprg.lMin; - JoyYMax[w]=diprg.lMax-(r>>2); - JoyYMin[w]=diprg.lMin+(r>>2); - } - - } -} - -void InitJoysticks(HWND wnd) -{ - int x; - - joycounter=0; - IDirectInput7_EnumDevices(lpDI, DIDEVTYPE_JOYSTICK,JoystickFound,0,DIEDFL_ATTACHEDONLY); - - for(x=0;x<4;x++) - InitJoystick(x,wnd); -} - - -static int joyconport; - -static BOOL CALLBACK JoyConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - char tempo[64]; - int x; - static int bid; - - switch(uMsg) { - case WM_TIMER: - if(bid>=200 && bid<=215) - { - int z; - - /* GetJoystickButton() makes sure there is a joystick, - so we don't need to here. - */ - if(bid<=207) - { - if( (z=GetJoystickButton(joyconport))!=-1) - SetDlgItemInt(hwndDlg,bid,z,0); - } - else - { - if( (z=GetJoystickButton(2+joyconport))!=-1) - SetDlgItemInt(hwndDlg,bid,z,0); - } - } - break; - case WM_INITDIALOG: - bid=0; - SetTimer(hwndDlg,666,20,0); /* Every 20ms(50x a second).*/ - - InitJoysticks(hwndDlg); - - SendDlgItemMessage(hwndDlg,106,CB_ADDSTRING,0,(LPARAM)(LPSTR)""); - SendDlgItemMessage(hwndDlg,112,CB_ADDSTRING,0,(LPARAM)(LPSTR)""); - - sprintf(tempo,"Virtual Gamepad %d",joyconport+1); - SetDlgItemText(hwndDlg,102,tempo); - sprintf(tempo,"Virtual Gamepad %d",joyconport+3); - SetDlgItemText(hwndDlg,104,tempo); - - for(x=0;x<=2;x+=2) - { - SetDlgItemInt(hwndDlg,200+(x<<2),joySelect[x+joyconport],0); - SetDlgItemInt(hwndDlg,201+(x<<2),joyStart[x+joyconport],0); - SetDlgItemInt(hwndDlg,202+(x<<2),joyB[x+joyconport],0); - SetDlgItemInt(hwndDlg,203+(x<<2),joyA[x+joyconport],0); - - SetDlgItemInt(hwndDlg,204+(x<<2),joyUp[x+joyconport],0); - SetDlgItemInt(hwndDlg,205+(x<<2),joyDown[x+joyconport],0); - SetDlgItemInt(hwndDlg,206+(x<<2),joyLeft[x+joyconport],0); - SetDlgItemInt(hwndDlg,207+(x<<2),joyRight[x+joyconport],0); - - } - joycounter=0; - IDirectInput7_EnumDevices(lpDI, DIDEVTYPE_JOYSTICK,JoystickFound,hwndDlg,DIEDFL_ATTACHEDONLY); - - SendDlgItemMessage(hwndDlg,106,CB_SETCURSEL,joy[0+joyconport],(LPARAM)(LPSTR)0); - SendDlgItemMessage(hwndDlg,112,CB_SETCURSEL,joy[2+joyconport],(LPARAM)(LPSTR)0); - - if(joyOptions[joyconport]&1) - CheckDlgButton(hwndDlg,300,BST_CHECKED); - if(joyOptions[joyconport+2]&1) - CheckDlgButton(hwndDlg,301,BST_CHECKED); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(HIWORD(wParam)==EN_SETFOCUS) - { - bid=LOWORD(wParam); - } - else if(HIWORD(wParam)==EN_KILLFOCUS) - { - bid=0; - } - else if(HIWORD(wParam)==CBN_SELENDOK) - { - switch(LOWORD(wParam)) - { - case 106: - KillJoystick(joyconport); - joy[0+(joyconport)]=SendDlgItemMessage(hwndDlg,106,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - InitJoystick(joyconport,hwndDlg); - SendDlgItemMessage(hwndDlg,106,CB_SETCURSEL,joy[0+joyconport],(LPARAM)(LPSTR)0); - break; - case 112: - KillJoystick(2+joyconport); - joy[2+(joyconport)]=SendDlgItemMessage(hwndDlg,112,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - InitJoystick(2+joyconport,hwndDlg); - SendDlgItemMessage(hwndDlg,112,CB_SETCURSEL,joy[2+joyconport],(LPARAM)(LPSTR)0); - break; - } - } - - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 1: - gornk: - - KillTimer(hwndDlg,666); - KillJoysticks(); - - for(x=0;x<=2;x+=2) - { - joySelect[x+(joyconport)]=GetDlgItemInt(hwndDlg,200+(x<<2),0,0); - joyStart[x+(joyconport)]=GetDlgItemInt(hwndDlg,201+(x<<2),0,0); - joyB[x+(joyconport)]=GetDlgItemInt(hwndDlg,202+(x<<2),0,0); - joyA[x+(joyconport)]=GetDlgItemInt(hwndDlg,203+(x<<2),0,0); - - joyUp[x+(joyconport)]=GetDlgItemInt(hwndDlg,204+(x<<2),0,0); - joyDown[x+(joyconport)]=GetDlgItemInt(hwndDlg,205+(x<<2),0,0); - joyLeft[x+(joyconport)]=GetDlgItemInt(hwndDlg,206+(x<<2),0,0); - joyRight[x+(joyconport)]=GetDlgItemInt(hwndDlg,207+(x<<2),0,0); - } - if(IsDlgButtonChecked(hwndDlg,300)==BST_CHECKED) - joyOptions[joyconport]|=1; - else - joyOptions[joyconport]&=~1; - if(IsDlgButtonChecked(hwndDlg,301)==BST_CHECKED) - joyOptions[joyconport+2]|=1; - else - joyOptions[joyconport+2]&=~1; - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - -void ConfigJoystickies(HWND hParent, int port) -{ - joyconport=port; - - KillJoysticks(); - DialogBox(fceu_hInstance,"JOYCONFIG",hParent,JoyConCallB); - InitJoysticks(hAppWnd); -} - diff --git a/drivers/win/joystick.h b/drivers/win/joystick.h deleted file mode 100644 index a5cdb40..0000000 --- a/drivers/win/joystick.h +++ /dev/null @@ -1,16 +0,0 @@ -void ConfigJoystickies(HWND hParent, int port); -void InitJoysticks(HWND wnd); -void KillJoysticks(void); -uint32 GetJSOr(void); - -extern int joyOptions[4]; -extern int joyA[4]; -extern int joyB[4]; -extern int joySelect[4]; -extern int joyStart[4]; -extern int joyUp[4]; -extern int joyDown[4]; -extern int joyLeft[4]; -extern int joyRight[4]; -extern int joy[4]; - diff --git a/drivers/win/keyboard.c b/drivers/win/keyboard.c deleted file mode 100644 index b521081..0000000 --- a/drivers/win/keyboard.c +++ /dev/null @@ -1,458 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#include "common.h" -#include - - -#include "input.h" -#include "keyboard.h" - -#include "keyscan.h" - - -HRESULT ddrval; - -static LPDIRECTINPUTDEVICE7 lpdid=0; -static int porttemp; - - -int keyBMap[4][8]={ - {SCAN_LEFTALT,SCAN_LEFTCONTROL,SCAN_TAB,SCAN_ENTER,SCAN_BL_CURSORUP,SCAN_BL_CURSORDOWN,SCAN_BL_CURSORLEFT,SCAN_BL_CURSORRIGHT}, - {SCAN_LEFTALT,SCAN_LEFTCONTROL,SCAN_TAB,SCAN_ENTER,SCAN_BL_CURSORUP,SCAN_BL_CURSORDOWN,SCAN_BL_CURSORLEFT,SCAN_BL_CURSORRIGHT}, - {SCAN_LEFTALT,SCAN_LEFTCONTROL,SCAN_TAB,SCAN_ENTER,SCAN_BL_CURSORUP,SCAN_BL_CURSORDOWN,SCAN_BL_CURSORLEFT,SCAN_BL_CURSORRIGHT}, - {SCAN_LEFTALT,SCAN_LEFTCONTROL,SCAN_TAB,SCAN_ENTER,SCAN_BL_CURSORUP,SCAN_BL_CURSORDOWN,SCAN_BL_CURSORLEFT,SCAN_BL_CURSORRIGHT} - }; -int keybEnable=1; - -int powerpadside=0; -int powerpadsc[2][12]={ - { - SCAN_O,SCAN_P,SCAN_BRACKET_LEFT, - SCAN_BRACKET_RIGHT,SCAN_K,SCAN_L,SCAN_SEMICOLON,SCAN_APOSTROPHE, - SCAN_M,SCAN_COMMA,SCAN_PERIOD,SCAN_SLASH - }, - { - SCAN_O,SCAN_P,SCAN_BRACKET_LEFT, - SCAN_BRACKET_RIGHT,SCAN_K,SCAN_L,SCAN_SEMICOLON,SCAN_APOSTROPHE, - SCAN_M,SCAN_COMMA,SCAN_PERIOD,SCAN_SLASH - } - }; - - - - -void KeyboardClose(void) -{ - if(lpdid) IDirectInputDevice7_Unacquire(lpdid); - lpdid=0; -} - -static char keys[256]; -static void KeyboardUpdateState(void) -{ - ddrval=IDirectInputDevice7_GetDeviceState(lpdid,256,keys); - switch(ddrval) - { - case DIERR_INPUTLOST: - case DIERR_NOTACQUIRED: - IDirectInputDevice7_Acquire(lpdid); - break; - } -} - -int KeyboardInitialize(void) -{ - - if(lpdid) - return(1); - - ddrval=IDirectInput7_CreateDeviceEx(lpDI, &GUID_SysKeyboard,&IID_IDirectInputDevice7, (LPVOID *)&lpdid,0); - if(ddrval != DI_OK) - { - FCEUD_PrintError("DirectInput: Error creating keyboard device."); - return 0; - } - - ddrval=IDirectInputDevice7_SetCooperativeLevel(lpdid, hAppWnd,DISCL_FOREGROUND|DISCL_NONEXCLUSIVE); - if(ddrval != DI_OK) - { - FCEUD_PrintError("DirectInput: Error setting keyboard cooperative level."); - return 0; - } - - ddrval=IDirectInputDevice7_SetDataFormat(lpdid,&c_dfDIKeyboard); - if(ddrval != DI_OK) - { - FCEUD_PrintError("DirectInput: Error setting keyboard data format."); - return 0; - } - - ddrval=IDirectInputDevice7_Acquire(lpdid); - if(ddrval != DI_OK) - { - FCEUD_PrintError("DirectInput: Error acquiring keyboard."); - return 0; - } - return 1; -} - -static int DIPS=0; -static uint8 keyonce[256]; -#define KEY(__a) keys[SCAN_##__a] -#define keyonly(__a,__z) {if(KEY(__a)){if(!keyonce[SCAN_##__a]) {keyonce[SCAN_##__a]=1;__z}} else{keyonce[SCAN_##__a]=0;}} -int cidisabled=0; - -void KeyboardUpdate(void) -{ - KeyboardUpdateState(); - - if(InputTypeFC==SIFC_FKB && cidisabled) - return; - - NoWaiting&=~1; - if(KEY(GRAVE)) - NoWaiting|=1; - - if(GI) - { - if(GI->type==GIT_FDS) - { - keyonly(S,DriverInterface(DES_FDSSELECT,0);) - keyonly(I,DriverInterface(DES_FDSINSERT,0);) - keyonly(E,DriverInterface(DES_FDSEJECT,0);) - } - - if(GI->type!=GIT_NSF) - { - keyonly(F5,FCEUI_SaveState();) - keyonly(F7,FCEUI_LoadState();) - } - keyonly(F9,FCEUI_SaveSnapshot();) - - if(GI->type==GIT_VSUNI) - { - keyonly(C,DriverInterface(DES_VSUNICOIN,0);) - keyonly(V,DIPS^=1;DriverInterface(DES_VSUNITOGGLEDIPVIEW,0);) - if(!(DIPS&1)) goto DIPSless; - keyonly(1,DriverInterface(DES_VSUNIDIPSET,(void *)1);) - keyonly(2,DriverInterface(DES_VSUNIDIPSET,(void *)2);) - keyonly(3,DriverInterface(DES_VSUNIDIPSET,(void *)3);) - keyonly(4,DriverInterface(DES_VSUNIDIPSET,(void *)4);) - keyonly(5,DriverInterface(DES_VSUNIDIPSET,(void *)5);) - keyonly(6,DriverInterface(DES_VSUNIDIPSET,(void *)6);) - keyonly(7,DriverInterface(DES_VSUNIDIPSET,(void *)7);) - keyonly(8,DriverInterface(DES_VSUNIDIPSET,(void *)8);) - } - else - { - keyonly(H,DriverInterface(DES_NTSCSELHUE,0);) - keyonly(T,DriverInterface(DES_NTSCSELTINT,0);) - if(KEY(KP_MINUS) || KEY(MINUS)) DriverInterface(DES_NTSCDEC,0); - if(KEY(KP_PLUS) || KEY(EQUAL)) DriverInterface(DES_NTSCINC,0); - - DIPSless: - keyonly(0,FCEUI_SelectState(0);) - keyonly(1,FCEUI_SelectState(1);) - keyonly(2,FCEUI_SelectState(2);) - keyonly(3,FCEUI_SelectState(3);) - keyonly(4,FCEUI_SelectState(4);) - keyonly(5,FCEUI_SelectState(5);) - keyonly(6,FCEUI_SelectState(6);) - keyonly(7,FCEUI_SelectState(7);) - keyonly(8,FCEUI_SelectState(8);) - keyonly(9,FCEUI_SelectState(9);) - } - } -} - -uint32 KeyboardDodo(void) -{ - uint32 JS=0; - - - if(GI) - if(GI->type!=GIT_NSF) - { - int x,y,u,b; - - for(u=0;u<4;u++) - { - if(keybEnable&(1<=0;b--) - if(keys[tmpo[b]]) JS|=(1<>16)) - { - wParam&=0xFFFF; - if((wParam>=600 && wParam<=607) || (wParam>=610 && wParam<=617)) - inkeyloop=wParam; - else switch(wParam) - { - case 1: - gornk: - for(x=0;x<2;x++) - { - for(y=0;y<8;y++) - keyBMap[porttemp+(x<<1)][y]=GetDlgItemInt(hwndDlg,600+y+x*10,0,0); - - if(IsDlgButtonChecked(hwndDlg,320+x)==BST_CHECKED) - keybEnable|=(1<<((x<<1)+porttemp)); - else - keybEnable&=~(1<<((x<<1)+porttemp)); - } - - EndDialog(hwndDlg,0); - break; - } - } - } - return 0; -} - -static BOOL CALLBACK KeyPPConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - int x; - char tempo[64]; - - switch(uMsg) { - case WM_USER+666: - if(inkeyloop) - { - SetDlgItemInt(hwndDlg,inkeyloop,lParam,0); - inkeyloop=0; - } - break; - case WM_INITDIALOG: - for(x=0;x<12;x++) - SetDlgItemInt(hwndDlg,500+x,powerpadsc[porttemp][x],0); - CheckDlgButton(hwndDlg,300+((powerpadside>>porttemp)&1),BST_CHECKED); - sprintf(tempo,"Virtual Power Pad %d",porttemp+1); - SetDlgItemText(hwndDlg,302,tempo); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(!(wParam>>16)) - { - wParam&=0xFFFF; - if(wParam>=500 && wParam<=511) - inkeyloop=wParam; - else switch(wParam) - { - case 1: - gornk: - for(x=0;x<12;x++) - powerpadsc[porttemp][x]=GetDlgItemInt(hwndDlg,500+x,0,0); - powerpadside&=~(1<>16)) - { - wParam&=0xFFFF; - if(wParam>=300 && wParam<=371) - inkeyloop=wParam; - else switch(wParam) - { - case 1: - gornk: - EndDialog(hwndDlg,0); - break; - } - } - } - return 0; -} - -static HHOOK hHook; -static LRESULT CALLBACK FilterFunc(int nCode, WORD wParam, DWORD lParam) -{ - MSG FAR *ptrMsg; - LPARAM tmpo; - - if(nCode>=0) - { - if(nCode==MSGF_DIALOGBOX) - { - ptrMsg=(MSG FAR *)lParam; - if(ptrMsg->message==WM_KEYDOWN || ptrMsg->message==WM_SYSKEYDOWN) - { - tmpo=((ptrMsg->lParam>>16)&0x7F)|((ptrMsg->lParam>>17)&0x80); - PostMessage(GetParent(ptrMsg->hwnd),WM_USER+666,0,tmpo); - if(inkeyloop) return 1; - } - } - } - return CallNextHookEx(hHook,nCode,wParam,lParam); -} - - -void ConfigKeyboardie(HWND hParent, int port) -{ - porttemp=port; - - hHook=SetWindowsHookEx(WH_MSGFILTER,(HOOKPROC)FilterFunc,fceu_hInstance,GetCurrentThreadId()); - DialogBox(fceu_hInstance,"KEYCONFIG",hParent,KeyConCallB); - UnhookWindowsHookEx(hHook); -} - -void ConfigKeyboardiePowerpad(HWND hParent, int port) -{ - porttemp=port; - - hHook=SetWindowsHookEx(WH_MSGFILTER,(HOOKPROC)FilterFunc,fceu_hInstance,GetCurrentThreadId()); - DialogBox(fceu_hInstance,"KEYPPCONFIG",hParent,KeyPPConCallB); - UnhookWindowsHookEx(hHook); -} - -void ConfigFKB(HWND hParent) -{ - hHook=SetWindowsHookEx(WH_MSGFILTER,(HOOKPROC)FilterFunc,fceu_hInstance,GetCurrentThreadId()); - DialogBox(fceu_hInstance,"FKBCONFIG",hParent,FKBConCallB); - UnhookWindowsHookEx(hHook); -} diff --git a/drivers/win/keyboard.h b/drivers/win/keyboard.h deleted file mode 100644 index f118fc6..0000000 --- a/drivers/win/keyboard.h +++ /dev/null @@ -1,22 +0,0 @@ -void KeyboardClose(void); -int KeyboardInitialize(void); -void KeyboardUpdate(void); -uint32 KeyboardDodo(void); -uint32 UpdatePPadData(int w); -void UpdateFKB(void); - - -void ConfigFKB(HWND hParent); -void ConfigKeyboardie(HWND hParent, int port); -void ConfigKeyboardiePowerpad(HWND hParent, int port); - -extern int cidisabled; - -/* Config stuff: */ -extern int keyBMap[4][8]; -extern int keybEnable; -extern int powerpadside; -extern int powerpadsc[2][12]; - -extern int fkbmap[0x48]; -extern uint8 fkbkeys[0x48]; diff --git a/drivers/win/keyscan.h b/drivers/win/keyscan.h deleted file mode 100644 index 689d780..0000000 --- a/drivers/win/keyscan.h +++ /dev/null @@ -1,125 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -#define SCAN_GRAVE 0x29 -#define SCAN_1 0x02 -#define SCAN_2 0x03 -#define SCAN_3 0x04 -#define SCAN_4 0x05 -#define SCAN_5 0x06 -#define SCAN_6 0x07 -#define SCAN_7 0x08 -#define SCAN_8 0x09 -#define SCAN_9 0x0A -#define SCAN_0 0x0B -#define SCAN_MINUS 0x0C -#define SCAN_EQUAL 0x0D -#define SCAN_BACKSLASH 0x2B -#define SCAN_BACKSPACE 0x0E -#define SCAN_TAB 0x0F -#define SCAN_Q 0x10 -#define SCAN_W 0x11 -#define SCAN_E 0x12 -#define SCAN_R 0x13 -#define SCAN_T 0x14 -#define SCAN_Y 0x15 -#define SCAN_U 0x16 -#define SCAN_I 0x17 -#define SCAN_O 0x18 -#define SCAN_P 0x19 -#define SCAN_BRACKET_LEFT 0x1A -#define SCAN_BRACKET_RIGHT 0x1B -#define SCAN_LOWBACKSLASH 0x2B -#define SCAN_CAPSLOCK 0x3A -#define SCAN_A 0x1E -#define SCAN_S 0x1F -#define SCAN_D 0x20 -#define SCAN_F 0x21 -#define SCAN_G 0x22 -#define SCAN_H 0x23 -#define SCAN_J 0x24 -#define SCAN_K 0x25 -#define SCAN_L 0x26 -#define SCAN_SEMICOLON 0x27 -#define SCAN_APOSTROPHE 0x28 -#define SCAN_ENTER 0x1C -#define SCAN_LEFTSHIFT 0x2A -#define SCAN_Z 0x2C -#define SCAN_X 0x2D -#define SCAN_C 0x2E -#define SCAN_V 0x2F -#define SCAN_B 0x30 -#define SCAN_N 0x31 -#define SCAN_M 0x32 -#define SCAN_COMMA 0x33 -#define SCAN_PERIOD 0x34 -#define SCAN_SLASH 0x35 -#define SCAN_RIGHTSHIFT 0x36 -#define SCAN_LEFTCONTROL 0x1D -#define SCAN_LEFTALT 0x38 -#define SCAN_SPACE 0x39 - -#define SCAN_RIGHTALT (0x38|0x80) -#define SCAN_RIGHTCONTROL (0x1D|0x80) -#define SCAN_BL_INSERT (0x52|0x80) -#define SCAN_BL_DELETE (0x53|0x80) -#define SCAN_BL_CURSORLEFT (0x4B|0x80) -#define SCAN_BL_HOME (0x47|0x80) -#define SCAN_BL_END (0x4F|0x80) -#define SCAN_BL_CURSORUP (0x48|0x80) -#define SCAN_BL_CURSORDOWN (0x50|0x80) -#define SCAN_BL_PAGEUP (0x49|0x80) -#define SCAN_BL_PAGEDOWN (0x51|0x80) -#define SCAN_BL_CURSORRIGHT (0x4D|0x80) - -#define SCAN_SCROLLLOCK 0x46 -/* Keys in the key pad area. */ -#define SCAN_NUMLOCK 0x45 -#define SCAN_HOME 0x47 -#define SCAN_CURSORLEFT 0x4B -#define SCAN_END 0x4F -#define SCAN_SLASH 0x35 -#define SCAN_CURSORUP 0x48 -#define SCAN_CENTER 0x4C -#define SCAN_CURSORDOWN 0x50 -#define SCAN_INSERT 0x52 -#define SCAN_ASTERISK 0x37 -#define SCAN_PAGEUP 0x49 -#define SCAN_CURSORRIGHT 0x4D -#define SCAN_PAGEDOWN 0x51 -#define SCAN_KP_DELETE 0x53 -#define SCAN_KP_MINUS 0x4A -#define SCAN_KP_PLUS 0x4E -#define SCAN_KP_ENTER 0x1C - -#define SCAN_ESCAPE 0x01 -#define SCAN_F1 0x3B -#define SCAN_F2 0x3C -#define SCAN_F3 0x3D -#define SCAN_F4 0x3E -#define SCAN_F5 0x3F -#define SCAN_F6 0x40 -#define SCAN_F7 0x41 -#define SCAN_F8 0x42 -#define SCAN_F9 0x43 -#define SCAN_F10 0x44 -#define SCAN_F11 0x57 -#define SCAN_F12 0x58 - diff --git a/drivers/win/main.c b/drivers/win/main.c deleted file mode 100644 index 2faf4eb..0000000 --- a/drivers/win/main.c +++ /dev/null @@ -1,338 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - - -#include "common.h" - -#include -#include -#include -#include -#include -#include -#include -#include // For directories configuration dialog. - -#include "input.h" -#include "joystick.h" -#include "keyboard.h" -#include "cheat.h" - - -#define EO_BGRUN 1 - -#define EO_CPALETTE 4 -#define EO_NOSPRLIM 8 -#define EO_BSAV 16 -#define EO_FSAFTERLOAD 32 -#define EO_FOAFTERSTART 64 -#define EO_NOTHROTTLE 128 -#define EO_CLIPSIDES 256 -#define EO_SNAPNAME 512 - -/* EO_USERFORCE is something I've been playing with. - The code for it isn't finished. -*/ -#define EO_USERFORCE 1024 - - -#define VNSCLIP ((eoptions&EO_CLIPSIDES)?8:0) -#define VNSWID ((eoptions&EO_CLIPSIDES)?240:256) - -static int eoptions=EO_BGRUN; - -void ResetVideo(void); -void ShowCursorAbs(int w); -void HideFWindow(int h); -int SetMainWindowStuff(void); -int GetClientAbsRect(LPRECT lpRect); -void UpdateFCEUWindow(void); - - -HWND hAppWnd=0; -HINSTANCE fceu_hInstance; - -HRESULT ddrval; - -FCEUGI *GI=0; - -// cheats, misc, nonvol, states, snaps, base -static char *DOvers[6]={0,0,0,0,0,0}; -static char *defaultds[5]={"cheats","gameinfo","sav","fcs","snaps"}; - -static char TempArray[2048]; -static char BaseDirectory[2048]; - -void SetDirs(void) -{ - int x; - static int jlist[5]= - {FCEUIOD_CHEATS,FCEUIOD_MISC,FCEUIOD_NV,FCEUIOD_STATE,FCEUIOD_SNAPS}; - - for(x=0;x<5;x++) - FCEUI_SetDirOverride(jlist[x], DOvers[x]); - if(DOvers[5]) - FCEUI_SetBaseDirectory(DOvers[5]); - else - FCEUI_SetBaseDirectory(BaseDirectory); - FCEUI_SaveExtraDataUnderBase(eoptions&EO_BSAV); -} -/* Remove empty, unused directories. */ -void RemoveDirs(void) -{ - int x; - - for(x=0;x<5;x++) - if(!DOvers[x]) - { - sprintf(TempArray,"%s\\%s",DOvers[5]?DOvers[5]:BaseDirectory,defaultds[x]); - RemoveDirectory(TempArray); - } -} - -void CreateDirs(void) -{ - int x; - - for(x=0;x<5;x++) - if(!DOvers[x]) - { - sprintf(TempArray,"%s\\%s",DOvers[5]?DOvers[5]:BaseDirectory,defaultds[x]); - CreateDirectory(TempArray,0); - } -} - -static char *gfsdir=0; -void GetBaseDirectory(void) -{ - int x; - BaseDirectory[0]=0; - GetModuleFileName(0,(LPTSTR)BaseDirectory,2047); - - for(x=strlen(BaseDirectory);x>=0;x--) - { - if(BaseDirectory[x]=='\\' || BaseDirectory[x]=='/') - {BaseDirectory[x]=0;break;} - } -} - -static int exiting=0; -int BlockingCheck(void) -{ - MSG msg; - - while( PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ) ) { - if( GetMessage( &msg, 0, 0, 0)>0 ) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - if(exiting) return(0); - - return(1); -} - -int NoWaiting=0; -static int fullscreen=0; -static int soundflush=0; -static int soundsleep=0; -static int genie=0; -static int palyo=0; -static int windowedfailed; -static int winsizemul=1; -static int winwidth,winheight; - -static volatile int nofocus=0; -static volatile int userpause=0; - -#define SO_FORCE8BIT 1 -#define SO_SECONDARY 2 -#define SO_GFOCUS 4 -#define SO_D16VOL 8 - -static int soundrate=44100; -static int soundbuftime=46; -static int soundbufsize; -static int soundoptions=0; -static int soundvolume=100; - -static unsigned int srendline,erendline; -static unsigned int srendlinen=8; -static unsigned int erendlinen=239; -static unsigned int srendlinep=0; -static unsigned int erendlinep=239; - - -static unsigned int totallines; - -static void FixFL(void) -{ - FCEUI_GetCurrentVidSystem(&srendline,&erendline); - totallines=erendline-srendline+1; -} - -static void UpdateRendBounds(void) -{ - FCEUI_SetRenderedLines(srendlinen,erendlinen,srendlinep,erendlinep); - FixFL(); -} - -static uint8 cpalette[192]; -static int vmod=1; -static int soundo=1; -static int ntsccol=0,ntsctint,ntschue; - -void FCEUD_PrintError(char *s) -{ - if(fullscreen) ShowCursorAbs(1); - MessageBox(0,s,"FCE Ultra Error",MB_ICONERROR|MB_OK|MB_SETFOREGROUND|MB_TOPMOST); - if(fullscreen)ShowCursorAbs(0); -} - -void ShowAboutBox(void) -{ - sprintf(TempArray,"FCE Ultra "VERSION_STRING"\n\nhttp://fceultra.sourceforge.net\n\n"__TIME__"\n"__DATE__"\n""gcc "__VERSION__); - MessageBox(hAppWnd,TempArray,"About FCE Ultra",MB_OK); -} - -void DoFCEUExit(void) -{ - exiting=1; - if(GI) - { - FCEUI_CloseGame(); - GI=0; - } -} - -static int changerecursive=0; - -#include "throttle.c" - -#include "netplay.c" -#include "sound.c" -#include "video.c" -#include "window.c" -#include "config.c" - - -int DriverInitialize(void) -{ - if(!InitializeDDraw()) - return(0); - - if(soundo) - soundo=InitSound(); - - SetVideoMode(fullscreen); - InitInputStuff(); /* Initialize DInput interfaces. */ - CreateInputStuff(); /* Create and set virtual NES/FC devices. */ - return 1; -} - -static void DriverKill(void) -{ - sprintf(TempArray,"%s/fceu.cfg",BaseDirectory); - SaveConfig(TempArray); - DestroyInput(); - ResetVideo(); - if(soundo) TrashSound(); - CloseWave(); - ByebyeWindow(); -} - - -int main(int argc,char *argv[]) -{ - char *t; - - if(!FCEUI_Initialize()) - goto doexito; - - fceu_hInstance=GetModuleHandle(0); - - GetBaseDirectory(); - - sprintf(TempArray,"%s\\fceu.cfg",BaseDirectory); - LoadConfig(TempArray); - FixGIGO(); /* Since a game doesn't have to be - loaded before the GUI can be used, make - sure the temporary input type variables - are set. - */ - - - CreateDirs(); - SetDirs(); - - DoVideoConfigFix(); - DoMiscConfigFix(); - - if(eoptions&EO_CPALETTE) - FCEUI_SetPaletteArray(cpalette); - - t=0; - if(argc>1) - t=argv[1]; - if(!t) fullscreen=0; - - CreateMainWindow(); - - if(!InitDInput()) - goto doexito; - - if(!DriverInitialize()) - goto doexito; - - InitSpeedThrottle(); - UpdateMenu(); - - if(t) - ALoad(t); - else if(eoptions&EO_FOAFTERSTART) - LoadNewGamey(hAppWnd); - - doloopy: - UpdateFCEUWindow(); - if(GI) - { - FCEUI_Emulate(); - RedrawWindow(hAppWnd,0,0,RDW_ERASE|RDW_INVALIDATE); - StopSound(); - } - Sleep(50); - if(!exiting) - goto doloopy; - - doexito: - DriverKill(); - return(0); -} - -void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) -{ - FCEUD_BlitScreen(XBuf); - if(Count) - FCEUD_WriteSoundData(Buffer,Count); - FCEUD_UpdateInput(); -} - diff --git a/drivers/win/netplay.c b/drivers/win/netplay.c deleted file mode 100644 index 6c7ac45..0000000 --- a/drivers/win/netplay.c +++ /dev/null @@ -1,415 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -static char netplayhost[256]={0}; -static int netplayport=0xFCE; - -static int netplayon=0; -static int netplaytype=0; - -static HWND hwndns=0; - -static SOCKET Socket=INVALID_SOCKET; -static int wsainit=0; - -static volatile int abortnetplay=0; -static volatile int concommand=0; - -static void WSE(char *ahh) -{ - char tmp[256]; - sprintf(tmp,"Winsock: %s",ahh); - FCEUD_PrintError(tmp); -} - -int SetBlockingSock(SOCKET Socko) -{ - unsigned long t; - t=1; - if(ioctlsocket(Socko,FIONBIO,&t)) - { - WSE("Error setting socket to non-blocking mode!\n"); - return 0; - } - return 1; -} - -BOOL CALLBACK BoogaDooga(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch(uMsg) { - case WM_USER+1: - if(WSAGETASYNCERROR(lParam)) - concommand=1; - else - concommand=2; - break; - case WM_USER: - if(WSAGETSELECTEVENT(lParam)==FD_CONNECT) - { - if(WSAGETSELECTERROR(lParam)) - concommand=1; - else - concommand=2; - } - break; - case WM_INITDIALOG: - if(!netplaytype) SetDlgItemText(hwndDlg,100,(LPTSTR)"Waiting for a connection..."); - else SetDlgItemText(hwndDlg,100,(LPTSTR)"Attempting to establish a connection..."); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 1: - gornk: - abortnetplay=1; - EndDialog(hwndDlg,0); - break; - } - } - return 0; - -} - -static void CloseNSDialog(void) -{ - if(hwndns) - { - SendMessage(hwndns,WM_COMMAND,1,0); - hwndns=0; - } -} - -void CreateStatusDialog(void) -{ - hwndns=CreateDialog(fceu_hInstance,"NETSTAT",hAppWnd,BoogaDooga); -} - -void FCEUD_NetworkClose(void) -{ - CloseNSDialog(); - if(Socket!=INVALID_SOCKET) - { - closesocket(Socket); - Socket=INVALID_SOCKET; - } - if(wsainit) - { - WSACleanup(); - wsainit=0; - } - /* Make sure blocking is returned to normal once network play is stopped. */ - NoWaiting&=~2; -} - -int FCEUD_NetworkConnect(void) -{ - WSADATA WSAData; - SOCKADDR_IN sockin; /* I want to play with fighting robots. */ - SOCKET TSocket; - - if(WSAStartup(MAKEWORD(1,1),&WSAData)) - { - FCEUD_PrintError("Error initializing Windows Sockets."); - return(0); - } - wsainit=1; - concommand=abortnetplay=0; - - if( (TSocket=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET) - { - WSE("Error creating socket."); - FCEUD_NetworkClose(); - return(0); - } - - memset(&sockin,0,sizeof(sockin)); - sockin.sin_family=AF_INET; - sockin.sin_port=htons(netplayport); - - if(!netplaytype) /* Act as a server. */ - { - - int sockin_len; - sockin.sin_addr.s_addr=INADDR_ANY; - - sockin_len=sizeof(sockin); - - if(bind(TSocket,(struct sockaddr *)&sockin,sizeof(sockin))==SOCKET_ERROR) - { - WSE("Error binding to socket."); - closesocket(TSocket); - FCEUD_NetworkClose(); - return(0); - } - - if(listen(TSocket,1)==SOCKET_ERROR) - { - WSE("Error listening on socket."); - closesocket(TSocket); - FCEUD_NetworkClose(); - return(0); - } - - CreateStatusDialog(); - if(!SetBlockingSock(TSocket)) - { - closesocket(TSocket); - FCEUD_NetworkClose(); - return(0); - } - - while( (Socket=accept(TSocket,(struct sockaddr *) &sockin,(int *)&sockin_len)) == - INVALID_SOCKET) - { - if(abortnetplay || WSAGetLastError()!=WSAEWOULDBLOCK) - { - if(!abortnetplay) - WSE("Error accepting connection."); - closesocket(TSocket); - FCEUD_NetworkClose(); - return(0); - } - else - BlockingCheck(); - } - - if(!SetBlockingSock(Socket)) - { - FCEUD_NetworkClose(); - return(0); - } - - } - else /* We're a client... */ - { - char phostentb[MAXGETHOSTSTRUCT]; - unsigned long hadr; - - hadr=inet_addr(netplayhost); - - CreateStatusDialog(); - - if(hadr!=INADDR_NONE) - sockin.sin_addr.s_addr=hadr; - else - { - if(!WSAAsyncGetHostByName(hwndns,WM_USER+1,(const char *)netplayhost,phostentb,MAXGETHOSTSTRUCT)) - { - ghosterr: - WSE("Error getting host network information."); - closesocket(TSocket); - FCEUD_NetworkClose(); - return(0); - } - while(concommand!=2) - { - BlockingCheck(); - if(concommand==1 || abortnetplay) - goto ghosterr; - } - memcpy((char *)&sockin.sin_addr,((PHOSTENT)phostentb)->h_addr,((PHOSTENT)phostentb)->h_length); - } - concommand=0; - - if(WSAAsyncSelect(TSocket,hwndns,WM_USER,FD_CONNECT|FD_CLOSE)==SOCKET_ERROR) - { - eventnoterr: - WSE("Error setting event notification on socket."); - closesocket(TSocket); - FCEUD_NetworkClose(); - return(0); - } - - if(!SetBlockingSock(TSocket)) - { - closesocket(TSocket); - FCEUD_NetworkClose(); - return(0); - } - - if(connect(TSocket,(PSOCKADDR)&sockin,sizeof(sockin))==SOCKET_ERROR) - { - if(WSAGetLastError()!=WSAEWOULDBLOCK) - { - cerrav: - WSE("Error connecting to remote host."); - - cerra: - closesocket(TSocket); - FCEUD_NetworkClose(); - return(0); - } - - while(concommand!=2) - { - BlockingCheck(); - if(abortnetplay) goto cerra; - if(concommand==1) goto cerrav; - } - } - if(WSAAsyncSelect(TSocket,hAppWnd,WM_USER,0)==SOCKET_ERROR) - goto eventnoterr; - Socket=TSocket; - - } - CloseNSDialog(); - return(1); -} - - -int FCEUD_NetworkSendData(uint8 *data, uint32 len) -{ - int erc; - - while((erc=send(Socket,data,len,0))) - { - if(erc!=SOCKET_ERROR) - { - len-=erc; - data+=erc; - if(!len) - return(1); /* All data sent. */ - - if(!BlockingCheck()) return(0); - } - else - { - if(WSAGetLastError()==WSAEWOULDBLOCK) - { - if(!BlockingCheck()) return(0); - continue; - } - return(0); - } - } - return(0); -} - -int FCEUD_NetworkRecvData(uint8 *data, uint32 len, int block) -{ - int erc; - - if(block) // TODO: Add code elsewhere to handle sound buffer underruns. - { - while((erc=recv(Socket,data,len,0))!=len) - { - if(!erc) - return(0); - if(WSAGetLastError()==WSAEWOULDBLOCK) - { - if(!BlockingCheck()) return(0); - continue; - } - return(0); - } - - { - char buf[24]; - if(recv(Socket,buf,24,MSG_PEEK)==SOCKET_ERROR) - { - if(WSAGetLastError()==WSAEWOULDBLOCK) - NoWaiting&=~2; - else - return(0); - } - else - NoWaiting|=2; /* We're the client and we're lagging behind. - disable blocking(particularly sound...) to *try* - to catch up. - */ - } - - return 1; - } - - else /* We're the server. See if there's any new data - from player 2. If not, then return(-1). - */ - { - erc=recv(Socket,data,len,0); - if(!erc) - return(0); - if(erc==SOCKET_ERROR) - { - if(WSAGetLastError()==WSAEWOULDBLOCK) - return(-1); - return(0); // Some other(bad) error occurred. - } - return(1); - } // end else to if(block) -} - -BOOL CALLBACK NetConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch(uMsg) { - case WM_INITDIALOG: - - CheckDlgButton(hwndDlg,100,netplayon?BST_CHECKED:BST_UNCHECKED); - CheckRadioButton(hwndDlg,101,102,101+netplaytype); - SetDlgItemInt(hwndDlg,107,netplayport,0); - - if(netplayhost[0]) - SetDlgItemText(hwndDlg,104,netplayhost); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 1: - gornk: - - netplayport=GetDlgItemInt(hwndDlg,107,0,0); - - if(IsDlgButtonChecked(hwndDlg,100)==BST_CHECKED) - netplayon=1; - else - netplayon=0; - - if(IsDlgButtonChecked(hwndDlg,101)==BST_CHECKED) - netplaytype=0; - else - netplaytype=1; - - GetDlgItemText(hwndDlg,104,netplayhost,255); - netplayhost[255]=0; - - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - - -static void ConfigNetplay(void) -{ - DialogBox(fceu_hInstance,"NETPLAYCONFIG",hAppWnd,NetConCallB); - - if(netplayon) - FCEUI_SetNetworkPlay(netplaytype+1); - else - FCEUI_SetNetworkPlay(0); -} - diff --git a/drivers/win/res.res b/drivers/win/res.res deleted file mode 100644 index e7e533dfab203b429a61068ef238289b0098dda8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 27108 zcmeHQYmimdmEH$L6j}oKAR|hy7)fJ99-{a_bDMVqO(PBXNYrlV2aWymb|YYno;G95 z6zXUbK{I0wQ)3d7ni7*t#Ht?4He(#k%Sqy^imAw$A5$rROeWUMey+XtT5GSp&(#=X3ZNtr!q?38=n0CCMViQBlPCKm)%aQf6+w|f zVqV9|pZsSL4`L9ivYCnn+=CJj3n+qOPy#ZIxCh0c1jLL*Pz*{y<^b+NF(?64yv zPy%8lMNnMsR{>QNP)q?(0rle^6oV2FZcsn&K?%q-;vN)(5)d0&1jV2PWDejS6oV3w z8Nxj%1|=YNstAffiR)kyEr>x0$P{n~ia`m8oiBo7Py#ZIxCh0c1VqLZK`|%+nFF{7 z#h?UahHwvxK?#UVEP`TC;uu;4Q)5s9GKEIek9$x8BD0I27?glaBkn;lC;@RGil7*j zfXo5hgJMtuGDElr#h?VlK`Vk{P~rx#h}!ut0hvOK`f&$JKpfm6C4yvPy)h3)Q@{m;smq^A&o%^$P|W9Kkh*Z2$@ko z?m-F2G~yl{42OT;Vmz@lfNUC zZxjFVKA;2ab<>%9HtoD+(9)ty2j}beDW`vXx~4f|%y`m}F=I(FTni=h0WU2x>&J|- zrF`Va6rjfo(BlQ@@dETX?uT#>`pA!IgdJ;y9czRgYlI!c{YQQb=FN~Pf@07|ehk?0 z(e;0m1D)-)wIj5w%U+$sB@tLY+bfGvxLv<=X3}(Z4GfeN!rxM<)YaKpZV&Dc9U2@w zv~OU5iAp7=E|iviQd(12D(we;c+i^eLr)A0?A<%iRj8X?J5WM3wSe~{`{6@k+7G{; z96o$#pmx)YmUIL8A|y!arQg?p7EehB(b?Yc|Wp6{T!~#JcB}#m$_G=xG23zLyuC;8vrXr_|c>&0Jv}Y%flFL8eBK(NW57F;! zz}O34H%niNTwSIW^|smc=S8dVy%}i>;5zxY!(3 z(9R}2Wje}&AHn5OgDsJxt50LIBHE0a$;s~W)BC{jRd~{Yc5+1{o|B~C)#kB_EcU|`26bZdRYNx{Fq6;=M#7{ml3nosG!L6A zfp52XRtNa&yO%8zGBv(U(CZfUUKrzSzZE9N^W%E|n&gdGAaUFH*`&|R8#-iW%( zINh}$C4LHWLD}oKed9;Jt#7}XYca~0$7G)DF@KTLU9<;zt*thN5qVKb=jM4!!q zeV|R@3=^BG`eVPDh!L-{bH~@K{W>YdgS?K{G&QNds~<$$DYBt*wjZrtjCw>*EVpxe zi*1o;1)r|YrlTH>(P~=eCiI1ESN-t>Cgwc!lrpu<)IzT<#f(@7$*eUi$pTyB>4KEd_VODwpx`snL;4W(uBc;opmiO<^PbOcJgc`J7&WG7<6bipPup-$-=+uO zcLJfuQ@|5?Yd)>7@#rmDf;KSK=vt9&!}-WnK<}yFX)#nn3n-KQ&bRBligd~u%JnYr zsQ^i44?FR#5~B>!e=fi(ag_UP+75VMY{xo0V>yzO zeksX1o?Bi2x@?UF$Tw@v_LltUaxJR?XL^CN|ICw5%iQ@EiuX%Svff^dI6Y%}aYX3# zQKs0Zv?NGNw%X_908?Iu6w+7rnjSbkcb44Y(lr|*90B%{ek!l=PS#IFo8JUZSx?(s zwVSGoX25prgN|rM%6?k{KSZBBjT$(o=zGPmMI7Uus4MMd`}*!r)i=C%Uk!dpUqoKo z&?8xY^w_?sAKz&@Cc9n&{#y+0aNz3*k}6$#}Gq31?Vu?Nzy4cz1URW9F#<0Hyd$hJOh##vqc z<59F>BK-I$`X{6$pFWHxmiDQiwcv-h_r>Tb%iEBz zsrG&tHdN6`b&R?~x_evquuoVGphr?C|urE7oRRH@dht&qK#~ijgfIZ`|H394;hpi1@|L(B5 z0QR24)&;Q1(e-vt*9WlEp(8jB>jT&vhg})KiVoWl!03mt%!UBg>adLgY`4QU1+cpv zwmE?Pjl-@AVBc}r)dB1W4!b6Rz2>lM1K67m`)mMv-(jB%U{fOD%XI;4k-5$C?1lig z+F^|W>^g@v1+X56Z3$psblBDaw$EYB0qmO&YYAZg=&;rR_M*eu0@xc4+ZMpyc367= zI~f>l)%5}F#7MC10c^Fo*Yf(t0CpX)2T*2509zbww)r{(SiQr#0@xOZbqBDOQLF7k zPXN0py4hkk1+Z%!RtjJ%qc7Qfy(#Qj#2+t)$!4r*rCk>-hxf%DlhMVD#-ry8%*^O^ zYxdLoPqNn1)frcevXeqDDijMCeeCiu@(&k3(iqd}h=8pt$M^C+EZ2>BPgndF&3^_s zum<@h9v8~L8vfdD_;id$(QlJgm97!)g0ImDKU>!0%aF#$>13ymp4}Yl1Jajeiz@v) zX_Lm;PcUbp&MVM+t~;dtbK&);J>xp?xd;EmXVfTTI=(*_l3Z;`P#-Z9x6> zu=6>`*!b&2M3$?flbwG)QY2{Rh^5lIt&Ev*tw9d7!4vMbYoCr>RK>^Qn$Z7Nq~f@#~ZWI$$l-QWj*%5HjYy6ry>^94h{25J4CgRY4NC! zMSOHZ^!;JwTh~h;!*~>j!5n;JWQ^-P&BxU?YxL_rnF9r^#VTk1 zOxs_^2`PP?Yb=KmONqiuZ#JS3hmaJ-vr>o_+h&c@pOY|O@Fy_|6-=I1%1vs(l`$l8jj z&}I*sMc^N8h4zFqSN5I8nzO84|2TNR5<5za{oU!xP#d`2++g*P?)m5EBa^Fb`i`ql z_Kkggx>v9DJ?ZLW3@%^agh=We&gQ1;n*h7FDyj!h*uM~;YB9%^Pud=_(c0$O<{|Sn z@Tk+4@j)aa%fq?m3D}LrsIRh5_nJp74|)E8vHg*F_;GU`#-a)-x#uO9w)M#ou({^z zs6U%8a(fHYvHq(;T#9~(mZ{jF!x)RtV++hTz|{#j_vEoN@amrKE3Sr>zh;!S@?7)V zAGbUo6@_y5Yv6zTXnaIlVSIn=6wVBGpsTiZD;Wx>g5dNxMo{Fg1eE3$Bb(Krw z_MX>(_guG*yQ zs|oyL)Lt%~^Pk6@-;6mgdq)m*b9axMyFbp%L7CSF9mf5je$7_SCv*3w0qmfg*Dq!; znXmU?zMfQ`ubW_<^b-8B%)IBxGWw}{Nt(OCCqL)cqQ|X}7ri9SL8S5eV*|#k4Ra}b zCTyy?&+0aQ~YlIfr7Lcx9(z}7$uGT+YwSc}7ck-?-d zwXmPQFC*!~M^XL>D1r8>0lf|B!e>U%g=wtDa>UEwgH{e@591G&!}~^%L*d&?nf|LB z3ifgU+vE85N&q|Puvasf@bn(=bYwY9^L#itd?v;3;pFg{)YxU^@U?N?mso>yxuf+Z zW}(&%=0)?a9ie;-=h*lXd(DwyeF?RX<6s~E8E1S&-qu@BpBkJlUzxydRR7&Id7oNVBOZNoFn6n{C8%%bOPUL6?_T?v)=Uk;eJ00cu zxf_&eQI?oUoPmq0SA%;&~{Bi8V&DdWWZvWx`n|(L|_TiZd`yg{|2DrpI^HyrV zNp*6w!`=;G3mx`$0IPS{I{|D4VhgPAcLA)~VgDV#7CP*|0$9Dn-V0ze%;#)qLWliN0IPQxU*(IPE!MN&{fK$-jJWur4e;w3|K!_na`|-YY&t!krs+h}8?)j# zKj-RjPOky;t#ZbN&xjw79@pUA1N@o>uHny)ei%%C-&ttU1? z_b|A|W`ve&!~7nCtmq}`%H05cOO9#jGZB~gco*I_kaam@&dkBHWn72vhL-UsgNbTX zME0;0lhrrhf@9QP(#Uycj+w7bq6^erx<2njeNvXBVx-_=5YM`?cZ`^`#q`)D&MxPr zxd*@~2ur7zDBc~{>&(ehv%7&ZZatc{xJ3Ec0`hUVy?|=$k?`F;azS=NTkHuojabZt z%(mDzUC4c6l*JKZ8@VII_yb$U{>(1>o@zTLn~UI8Ohk)07kI{-BeB!A|HE-88)uk| zIKy+8R}vTGIXtl*GZ7Qi)9LyyEPFtXa@4x5Oo%jajO1P00(KEQzzaDCO0LLCRHGYs zsn^9UX}wr4&q*`Z!EsV6swdJlrnL>_@$7CN%2qj%C<@2Zw}GeNMELo0%`eS8R{zL5rz+dWLgzdT4j)bDOn|@iBHrqewO`t& znOiZ6!@U)o-}?!@f55%y_2_LaJ~`Vd^L%%J?_y+k#&k}JzM~FcJW}OEv;k)%B}nv> z=tj;yo*vK$rC%pf?zykdvQ!4CQz#FTUgNh+BXPuP*HX?N#(w1t?QG=ghK%_1y*Ab; z`+h1HdPaK*Vs&?6PB1RjZ^zib`!^Zbg7Q3-y%g=M=sd}wc5t$}7ILNYYptDMtd$b& zqlRiFv?SS`)^@3#nFv1JiP2w#-PyD*2&1Yfw%*6(=i z^}!|Jjl5%$_1C2x;eLumRS9L0UkB-XjWW+0FxUOt*P-{%#=y6j4Bz5x+on8M*MmcH zGC)?fjOqI~&_{mrjQb&xUH?6VJ+1Wo=B%J~>#%k5V~kBV0THshFwbdwbZ_il=&pH4 z!Lw5G#(kyN6zbPR^y*6VOLP|3CbW3+e#)`XS^IGoCEX`V5B&|fq(9>f{iHLjjQIEI zW*=A~mTLbL?dHXbMU$ z+fJWmIXr{>S@(2p`S7`D%RR&Vd*`C7mx1@KXe~KFFSN29I$v+X z`{;a^T70CmEz-9^Mee(yn?DO*>aB?TEF4#QY&YO9{S=;GqxCMKG`?}Y(b^8(S5O{p z2anpoBk@=K$c{X2B89r{>p?wi$J?W7$0~3@`8x?GEo!4P-TZ9;S11=Z+cER& zowWCtpR3t*$vTWM^&ag6cTfw~Uh`ZX-`Cd_1b1a=d1$}Ya)!KIKQm_{H|JOjJPT?O z*~{etSx!6}KdW=)?Z6@O2xfwWBZ$^D3T-&ocsYtbr> ztdt;Qo}TNXotLC!QBDFGa7OraPILjR?3z*PS<#KEU#CUqg6o^j7i@nvgU9@35X!Dz zV#}vMhc1R6BfcotY`TgrKu0l#;eQuK&#A01jrhfe{23N0uN~!0!hV*Nw+&;QZP#6p zpW9IG?Y3R%-irh)4|H6nV6S2c>blLQPxFu5&96jRm+^!P^jT`~G|bQ|Rw>HM{O z!L?J$<2WDhH!{khrvap&zeburE2miiUv6F|mHK|qL9+e+XsQ%f*WUUEP9bf@divlD%6ZZmB5GRSy+AUYTFGpo&Sk|pMr zs5)X{n=um@AEeHaHNhWp>R$bwdC}yf{$|5O$k3+f(@u_f?u43+XJ#rb6*acBZjRM* z@=mvUZPW;%)>02=qjp)VCaYrAkBr|?2Xkd5?^;ScgPN76i|F6-m#X~P8|rH6B-$(b zNNkT<8}=f7rc?Y>Z~0iF?=N+;L}%F-(UfeLoYrM7>O8To@{GR&Bz`+%H1v!&*!ozf zKSQJ|M2Yx`#cTtQ#lkWjS7;iyN!KI1Ra?_q=1exyqwOXqye>_1bfL9Ova>Ah6l=h? zkf-D=Ei-i`Pk#H6=8ROXkjv?}4b=8a%#z$8xBW@~^eFIDwy%Ms8Loq~j=g4IL~~2& z`4N_0WFso+G>mo8Ix}v;v1C8kdU{9AmK(~|w8tW&nvcG*A3BB_h0X8EXY)`Z8R?br zW3Bl}V6~Md&wu(NtX%|tNqk;T&6nT4H;?Np> zl6W+IDE1(IZf-m3=dZ%~ch}YCeG_B(I8tlu!jEeqqrvKIsbUHBoKg{%ss(RwaP6b| zQ}yu4@HEaX+sL#o)RNR{iEa2UG(>G#Z?8ga^h$5BoMHr*I)w9)BTTETzM__*^?ny~ zbxFCL&9>i6tLN%QSH?}S@4CiWg52`f#d=#BSA*^LtXoIUM|&S_I~zH9-cQu-^Ag%l|H&e^7O}5HTL%;qIGqsQ}@7x|IA6*WULyNvMdHs$ z9hK?)I9`nymhO`*2M1{(8Lc^*HK7KT6{MurT@}%h>6neK8&npC%=gUSL*m&s?vZfR zMMrTzuEvf?lXl1P^ab-%#H*BN93if0xjtbGn7UB8Ed77Mya5ka)2~Gh!=!fO`3`<1 zguk)KeeHf%x6Y+^aCVFs_pTMwzMO=h*!j)im>iOnEx5>Y&>gb83f<=S~yHSIgD4#76Ud z+sE{8)@Yq;QQI|$AyK2N4$?YLh6Pwy*2$ym!wcrO_~pqe_d9L;ojSIRaXvZuO39Md zGxfEcbEUl!@3I%ZICoBI@nkI}t9#l%`WNzcnC?94n(!^0Xz;(asc|kDXdUP3NMwNL z5Okb9CNjXY4T@>m)ls@^i6XP)Q$P|gp9F0wapfDZI?yZa@7pM(DHQNyJCIubUkjpP Q^6RfBX7}>8))^128; - } - else - { - for(P=0;P=DSBufferSize) - if(playpos=(playpos+(soundbufsize<>=1; - if(stime>=5) - Sleep(stime); - k=1; - } - } - else if(soundsleep==2) - { - int stime; - stime=writepos-(playpos+(soundbufsize<>=1; - if(stime>=2) - Sleep(stime); - } - } - BlockingCheck(); - if(!soundo || NoWaiting) return; - goto ilicpo; - } - - if(netplaytype && netplayon) - { - if(writepos<=playpos+128) - writepos=playpos+(soundbufsize<>16)) - switch(wParam&0xFFFF) - { - case 1: - gornk: - soundoptions=0; - if(IsDlgButtonChecked(hwndDlg,122)==BST_CHECKED) - soundoptions|=SO_FORCE8BIT; - if(IsDlgButtonChecked(hwndDlg,123)==BST_CHECKED) - soundoptions|=SO_SECONDARY; - if(IsDlgButtonChecked(hwndDlg,124)==BST_CHECKED) - soundoptions|=SO_GFOCUS; - if(IsDlgButtonChecked(hwndDlg,126)==BST_CHECKED) - soundo=1; - else - soundo=0; - x=GetDlgItemInt(hwndDlg,200,0,0); - if(x<8192 || x>65535) - { - FCEUD_PrintError("Sample rate is out of range(8192-65535)."); - break; - } - else - soundrate=x; - - soundvolume=200-SendDlgItemMessage(hwndDlg,500,TBM_GETPOS,0,0); - FCEUI_SetSoundVolume(soundvolume); - soundsleep=SendDlgItemMessage(hwndDlg,129,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - - -void ConfigSound(void) -{ - int backo=soundo,sr=soundrate; - int so=soundoptions; - - DialogBox(fceu_hInstance,"SOUNDCONFIG",hAppWnd,SoundConCallB); - - if(((backo?1:0)!=(soundo?1:0))) - { - if(!soundo) - TrashSound(); - else - soundo=InitSound(); - } - else if(( soundoptions!=so || (sr!=soundrate)) && soundo) - { - TrashSound(); - soundo=InitSound(); - } - soundbufsize=(soundbuftime*soundrate/1000); -} - - -void StopSound(void) -{ - if(soundo) - IDirectSoundBuffer_Stop(ppbufw); -} - -#include "wave.c" diff --git a/drivers/win/throttle.c b/drivers/win/throttle.c deleted file mode 100644 index 1ccf271..0000000 --- a/drivers/win/throttle.c +++ /dev/null @@ -1,73 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -static uint64 tmethod,tfreq; -static uint64 desiredfps; - -static void RefreshThrottleFPS(void) -{ - desiredfps=FCEUI_GetDesiredFPS()>>8; -} - -static uint64 GetCurTime(void) -{ - if(tmethod) - { - uint64 tmp; - - /* Practically, LARGE_INTEGER and uint64 differ only by signness and name. */ - QueryPerformanceCounter((LARGE_INTEGER*)&tmp); - - return(tmp); - } - else - return((uint64)GetTickCount()); - -} - -static void InitSpeedThrottle(void) -{ - tmethod=0; - if(QueryPerformanceFrequency((LARGE_INTEGER*)&tfreq)) - { - tmethod=1; - } - else - tfreq=1000; - tfreq<<=16; /* Adjustment for fps returned from FCEUI_GetDesiredFPS(). */ -} - - -static void SpeedThrottle(void) -{ - static uint64 ttime,ltime; - - waiter: - - ttime=GetCurTime(); - - - if( (ttime-ltime) < (tfreq/desiredfps) ) - goto waiter; - if( (ttime-ltime) >= (tfreq*4/desiredfps)) - ltime=ttime; - else - ltime+=tfreq/desiredfps; -} diff --git a/drivers/win/video.c b/drivers/win/video.c deleted file mode 100644 index a0438a0..0000000 --- a/drivers/win/video.c +++ /dev/null @@ -1,1174 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -static int RecalcCustom(void); - -#define VF_DDSTRETCHED 1 - -#define VEF_LOSTSURFACE 1 -#define VEF____INTERNAL 2 - -#define VMDF_DXBLT 1 -#define VMDF_STRFS 2 - -typedef struct { - int x; - int y; - int bpp; - int flags; - int xscale; - int yscale; - RECT srect; - RECT drect; -} vmdef; - -// left, top, right, bottom -static vmdef vmodes[11]={ - {320,240,8,0,1,1}, //0 - {320,240,8,0,1,1}, //1 - {512,384,8,0,1,1}, //2 - {640,480,8,0,1,1}, //3 - {640,480,8,0,1,1}, //4 - {640,480,8,0,1,1}, //5 - {640,480,8,VMDF_DXBLT,2,2}, //6 - {1024,768,8,VMDF_DXBLT,4,3}, //7 - {1280,1024,8,VMDF_DXBLT,5,4}, //8 - {1600,1200,8,VMDF_DXBLT,6,5}, //9 - {800,600,8,VMDF_DXBLT|VMDF_STRFS,0,0} //10 - }; -static DDCAPS caps; -static int mustrestore=0; -static DWORD CBM[3]; - -static int bpp; -static int vflags; -static int veflags; - -int fssync=0; -int winsync=0; - -static uint32 *palettetranslate=0; - -PALETTEENTRY color_palette[256]; -static int PaletteChanged=0; - -LPDIRECTDRAWCLIPPER lpClipper=0; -LPDIRECTDRAW lpDD=0; -LPDIRECTDRAW4 lpDD4=0; -LPDIRECTDRAWPALETTE lpddpal; - -DDSURFACEDESC2 ddsd; - -DDSURFACEDESC2 ddsdback; -LPDIRECTDRAWSURFACE4 lpDDSPrimary=0; -LPDIRECTDRAWSURFACE4 lpDDSDBack=0; -LPDIRECTDRAWSURFACE4 lpDDSBack=0; - -static void ShowDDErr(char *s) -{ - char tempo[512]; - sprintf(tempo,"DirectDraw: %s",s); - FCEUD_PrintError(tempo); -} - -int RestoreDD(int w) -{ - if(w) - { - if(!lpDDSBack) return 0; - if(IDirectDrawSurface4_Restore(lpDDSBack)!=DD_OK) return 0; - } - else - { - if(!lpDDSPrimary) return 0; - if(IDirectDrawSurface4_Restore(lpDDSPrimary)!=DD_OK) return 0; - } - veflags|=1; - return 1; -} - -void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b) -{ - color_palette[index].peRed=r; - color_palette[index].peGreen=g; - color_palette[index].peBlue=b; - PaletteChanged=1; -} - -void FCEUD_GetPalette(unsigned char i, unsigned char *r, unsigned char *g, unsigned char *b) -{ - *r=color_palette[i].peRed; - *g=color_palette[i].peGreen; - *b=color_palette[i].peBlue; -} - -int InitializeDDraw(void) -{ - ddrval = DirectDrawCreate(NULL, &lpDD, NULL); - if (ddrval != DD_OK) - { - ShowDDErr("Error creating DirectDraw object."); - return 0; - } - - ddrval = IDirectDraw_QueryInterface(lpDD,&IID_IDirectDraw4,(LPVOID *)&lpDD4); - IDirectDraw_Release(lpDD); - - if (ddrval != DD_OK) - { - ShowDDErr("Error querying interface."); - return 0; - } - - caps.dwSize=sizeof(caps); - if(IDirectDraw4_GetCaps(lpDD4,&caps,0)!=DD_OK) - { - ShowDDErr("Error getting capabilities."); - return 0; - } - return 1; -} - -static int GetBPP(void) -{ - DDPIXELFORMAT ddpix; - - memset(&ddpix,0,sizeof(ddpix)); - ddpix.dwSize=sizeof(ddpix); - - ddrval=IDirectDrawSurface4_GetPixelFormat(lpDDSPrimary,&ddpix); - if (ddrval != DD_OK) - { - ShowDDErr("Error getting primary surface pixel format."); - return 0; - } - - if(ddpix.dwFlags&DDPF_RGB) - { - bpp=ddpix.DUMMYUNIONNAMEN(1).dwRGBBitCount; - CBM[0]=ddpix.DUMMYUNIONNAMEN(2).dwRBitMask; - CBM[1]=ddpix.DUMMYUNIONNAMEN(3).dwGBitMask; - CBM[2]=ddpix.DUMMYUNIONNAMEN(4).dwBBitMask; - } - else - { - ShowDDErr("RGB data not valid."); - return 0; - } - if(bpp==15) bpp=16; - - return 1; -} - -static int InitBPPStuff(void) -{ - if(bpp==16) - palettetranslate=malloc(65536*4); - else if(bpp>=24) - palettetranslate=malloc(256*4); - else if(bpp==8) - { - ddrval=IDirectDraw4_CreatePalette( lpDD4, DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_INITIALIZE,color_palette,&lpddpal,NULL); - if (ddrval != DD_OK) - { - ShowDDErr("Error creating palette object."); - return 0; - } - ddrval=IDirectDrawSurface4_SetPalette(lpDDSPrimary, lpddpal); - if (ddrval != DD_OK) - { - ShowDDErr("Error setting palette object."); - return 0; - } - } - return 1; -} - -int SetVideoMode(int fs) -{ - if(!lpDD4) // DirectDraw not initialized - return(1); - - if(fs) - if(!vmod) - if(!RecalcCustom()) - return(0); - - vflags=0; - veflags=1; - PaletteChanged=1; - - ResetVideo(); - - if(!fs) - { - ShowCursorAbs(1); - windowedfailed=1; - HideFWindow(0); - - ddrval = IDirectDraw4_SetCooperativeLevel ( lpDD4, hAppWnd, DDSCL_NORMAL); - if (ddrval != DD_OK) - { - ShowDDErr("Error setting cooperative level."); - return 1; - } - - /* Beginning */ - memset(&ddsd,0,sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - ddrval = IDirectDraw4_CreateSurface ( lpDD4, &ddsd, &lpDDSPrimary,(IUnknown FAR*)NULL); - if (ddrval != DD_OK) - { - ShowDDErr("Error creating primary surface."); - return 1; - } - - memset(&ddsdback,0,sizeof(ddsdback)); - ddsdback.dwSize=sizeof(ddsdback); - ddsdback.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; - ddsdback.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN; - - ddsdback.dwWidth=256; - ddsdback.dwHeight=240; - - /* If no blit hardware is present, make sure buffer is created - in system memory. - */ - if(!(caps.dwCaps&DDCAPS_BLT)) - ddsdback.ddsCaps.dwCaps|=DDSCAPS_SYSTEMMEMORY; - - ddrval = IDirectDraw4_CreateSurface ( lpDD4, &ddsdback, &lpDDSBack, (IUnknown FAR*)NULL); - if (ddrval != DD_OK) - { - ShowDDErr("Error creating secondary surface."); - return 0; - } - - if(!GetBPP()) - return 0; - - if(bpp!=16 && bpp!=24 && bpp!=32) - { - ShowDDErr("Current bit depth not supported!"); - return 0; - } - - if(!InitBPPStuff()) - return 0; - - ddrval=IDirectDraw4_CreateClipper(lpDD4,0,&lpClipper,0); - if (ddrval != DD_OK) - { - ShowDDErr("Error creating clipper."); - return 0; - } - - ddrval=IDirectDrawClipper_SetHWnd(lpClipper,0,hAppWnd); - if (ddrval != DD_OK) - { - ShowDDErr("Error setting clipper window."); - return 0; - } - ddrval=IDirectDrawSurface4_SetClipper(lpDDSPrimary,lpClipper); - if (ddrval != DD_OK) - { - ShowDDErr("Error attaching clipper to primary surface."); - return 0; - } - - windowedfailed=0; - SetMainWindowStuff(); - } - else - { - HideFWindow(1); - - ddrval = IDirectDraw4_SetCooperativeLevel ( lpDD4, hAppWnd,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT); - if (ddrval != DD_OK) - { - ShowDDErr("Error setting cooperative level."); - return 0; - } - - ddrval = IDirectDraw4_SetDisplayMode(lpDD4, vmodes[vmod].x, vmodes[vmod].y,vmodes[vmod].bpp,0,0); - if (ddrval != DD_OK) - { - ShowDDErr("Error setting display mode."); - return 0; - } - if(vmodes[vmod].flags&VMDF_DXBLT) - { - memset(&ddsdback,0,sizeof(ddsdback)); - ddsdback.dwSize=sizeof(ddsdback); - ddsdback.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; - ddsdback.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN; - - ddsdback.dwWidth=256; //vmodes[vmod].srect.right; - ddsdback.dwHeight=240; //vmodes[vmod].srect.bottom; - - if(!(caps.dwCaps&DDCAPS_BLT)) - ddsdback.ddsCaps.dwCaps|=DDSCAPS_SYSTEMMEMORY; - - ddrval = IDirectDraw4_CreateSurface ( lpDD4, &ddsdback, &lpDDSBack, (IUnknown FAR*)NULL); - if(ddrval!=DD_OK) - { - ShowDDErr("Error creating secondary surface."); - return 0; - } - } - - // create foreground surface - - memset(&ddsd,0,sizeof(ddsd)); - ddsd.dwSize = sizeof(ddsd); - - ddsd.dwFlags = DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - if(fssync==2) // Double buffering. - { - ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; - ddsd.dwBackBufferCount = 1; - ddsd.ddsCaps.dwCaps |= DDSCAPS_COMPLEX | DDSCAPS_FLIP; - } - - ddrval = IDirectDraw4_CreateSurface ( lpDD4, &ddsd, &lpDDSPrimary,(IUnknown FAR*)NULL); - if (ddrval != DD_OK) - { - ShowDDErr("Error creating primary surface."); - return 0; - } - - if(fssync==2) - { - DDSCAPS2 tmp; - - memset(&tmp,0,sizeof(tmp)); - tmp.dwCaps=DDSCAPS_BACKBUFFER; - - if(IDirectDrawSurface4_GetAttachedSurface(lpDDSPrimary,&tmp,&lpDDSDBack)!=DD_OK) - { - ShowDDErr("Error getting attached surface."); - return 0; - } - } - - if(!GetBPP()) - return 0; - if(!InitBPPStuff()) - return 0; - - mustrestore=1; - ShowCursorAbs(0); - } - - InputScreenChanged(fs); - fullscreen=fs; - return 1; -} - -static void BlitScreenWindow(uint8 *XBuf); -static void BlitScreenFull(uint8 *XBuf); - -void FCEUD_BlitScreen(uint8 *XBuf) -{ - doagain: - - UpdateFCEUWindow(); - - if(!(eoptions&EO_BGRUN)) - while(nofocus) - { - Sleep(50); - BlockingCheck(); - } - - - /* This complex statement deserves some explanation. - Make sure this special speed throttling hasn't been disabled by the user - first. Second, we don't want to throttle the speed if the fast-forward - button is pressed down(or during certain network play conditions). - - Now, if we're at this point, we'll throttle speed if sound is disabled. - Otherwise, it gets a bit more complicated. We'll throttle speed if focus - to FCE Ultra has been lost and we're writing to the primary sound buffer - because our sound code won't block. Blocking does seem to work when - writing to a secondary buffer, so we won't throttle when a secondary - buffer is used. - */ - - if(!(eoptions&EO_NOTHROTTLE)) - if(!NoWaiting) - if(!soundo || (soundo && nofocus && !(soundoptions&SO_SECONDARY)) ) - SpeedThrottle(); - - if(fullscreen) - { - if(fssync==1 && !NoWaiting) - IDirectDraw4_WaitForVerticalBlank(lpDD4,DDWAITVB_BLOCKBEGIN,0); - - BlitScreenFull(XBuf); - } - else - { - if(winsync && !NoWaiting) - IDirectDraw4_WaitForVerticalBlank(lpDD4,DDWAITVB_BLOCKBEGIN,0); - - if(!windowedfailed) - BlitScreenWindow(XBuf); - } - if(userpause) - { - StopSound(); - Sleep(50); - BlockingCheck(); - goto doagain; - } -} - -static INLINE void BlitVidHi(uint8 *src, uint8 *dest, /*int xr,*/ int yr, int pitch) -{ - int x,y; - int pinc; - - if(!(eoptions&EO_CLIPSIDES)) - switch(bpp) - { - case 32: - - pinc=pitch-(256<<2); - for(y=yr;y;y--) - { - for(x=256;x;x--) - { - *(uint32 *)dest=palettetranslate[(uint32)*src]; - dest+=4; - src++; - } - dest+=pinc; - src+=16; - } - break; - - case 24: - pinc=pitch-(256*3); - for(y=yr;y;y--) - { - for(x=256;x;x--) - { - uint32 tmp; - tmp=palettetranslate[(uint32)*src]; - *(uint16*)dest=(uint16)tmp; - *&dest[2]=(uint8)(tmp>>16); - dest+=3; - src++; - } - dest+=pinc; - src+=16; - } - break; - - case 16: - pinc=pitch-(256<<1); - for(y=yr;y;y--) - { - for(x=256>>1;x;x--) - { - *(unsigned long *)dest=palettetranslate[*(unsigned short *)src]; - dest+=4; - src+=2; - } - dest+=pinc; - src+=16; - } - break; - } - else - switch(bpp) - { - case 32: - - pinc=pitch-(240<<2); - for(y=yr;y;y--) - { - for(x=240;x;x--) - { - *(uint32 *)dest=palettetranslate[(uint32)*src]; - dest+=4; - src++; - } - dest+=pinc; - src+=32; - } - break; - - case 24: - pinc=pitch-(240*3); - for(y=yr;y;y--) - { - for(x=240;x;x--) - { - uint32 tmp; - tmp=palettetranslate[(uint32)*src]; - *(uint16*)dest=(uint16)tmp; - *&dest[2]=(uint8)(tmp>>16); - dest+=3; - src++; - } - dest+=pinc; - src+=32; - } - break; - case 16: - pinc=pitch-(240<<1); - for(y=yr;y;y--) - { - for(x=240>>1;x;x--) - { - *(unsigned long *)dest=palettetranslate[*(unsigned short *)src]; - dest+=4; - src+=2; - } - dest+=pinc; - src+=32; - } - break; - } -} - -static INLINE void FixPaletteHi(void) -{ - int x; - - switch(bpp) - { - case 16:{ - int cshiftr[3]; - int cshiftl[3]; - int a,x,z,y; - - cshiftl[0]=cshiftl[1]=cshiftl[2]=-1; - for(a=0;a<3;a++) - { - for(x=0,y=-1,z=0;x<16;x++) - { - if(CBM[a]&(1<>cshiftr[0])<>cshiftr[1])<>cshiftr[2])<>8].peRed>>cshiftr[0])<>8].peGreen>>cshiftr[1])<>8].peBlue>>cshiftr[2])<=16) - FixPaletteHi(); - else - for(x=0;x<=0x80;x+=0x80) - { - ddrval=IDirectDrawPalette_SetEntries(lpddpal,0,0x80^x,128,&color_palette[x]); - if(ddrval!=DD_OK) - { - if(ddrval==DDERR_SURFACELOST) RestoreDD(0); - return; - } - } - PaletteChanged=0; - } - - if(vmodes[vmod].flags&VMDF_DXBLT) - { - ddrval=IDirectDrawSurface4_Lock(lpDDSBack,NULL,&ddsdback, 0, NULL); - if(ddrval!=DD_OK) - { - if(ddrval==DDERR_SURFACELOST) RestoreDD(1); - return; - } - ScreenLoc=ddsdback.lpSurface; - pitch=ddsdback.DUMMYUNIONNAMEN(1).lPitch; - - srect.top=0; - srect.left=0; - srect.right=VNSWID; - srect.bottom=totallines; - if(vmodes[vmod].flags&VMDF_STRFS) - { - drect.top=0; - drect.left=0; - drect.right=vmodes[vmod].x; - drect.bottom=vmodes[vmod].y; - } - else - { - drect.top=(vmodes[vmod].y-(totallines*vmodes[vmod].yscale))>>1; - drect.bottom=drect.top+(totallines*vmodes[vmod].yscale); - drect.left=(vmodes[vmod].x-VNSWID*vmodes[vmod].xscale)>>1; - drect.right=drect.left+VNSWID*vmodes[vmod].xscale; - } - } - else - { - ddrval=IDirectDrawSurface4_Lock(lpDDSVPrimary,NULL,&ddsd, 0, NULL); - if(ddrval!=DD_OK) - { - if(ddrval==DDERR_SURFACELOST) RestoreDD(0); - return; - } - - ScreenLoc=ddsd.lpSurface; - pitch=ddsd.DUMMYUNIONNAMEN(1).lPitch; - } - - if(veflags&1) - { - if(vmodes[vmod].flags&VMDF_DXBLT) - { - veflags|=2; - memset((char *)ScreenLoc,0,pitch*srect.bottom); - } - else - { - memset((char *)ScreenLoc,0,pitch*vmodes[vmod].y); - } - PaletteChanged=1; - veflags&=~1; - } - - if(vmod==5) - { - if(eoptions&EO_CLIPSIDES) - { - asm volatile( - "xorl %%edx, %%edx\n\t" - "akoop1:\n\t" - "movb $120,%%al \n\t" - "akoop2:\n\t" - "movb 1(%%esi),%%dl\n\t" - "shl $16,%%edx\n\t" - "movb (%%esi),%%dl\n\t" - "xorl $0x00800080,%%edx\n\t" - "movl %%edx,(%%edi)\n\t" - "addl $2,%%esi\n\t" - "addl $4,%%edi\n\t" - "decb %%al\n\t" - "jne akoop2\n\t" - "addl $32,%%esi\n\t" - "addl %%ecx,%%edi\n\t" - "decb %%bl\n\t" - "jne akoop1\n\t" - : - : "S" (XBuf+srendline*272+VNSCLIP), "D" (ScreenLoc+((240-totallines)/2)*pitch+(640-(VNSWID<<1))/2),"b" (totallines), "c" ((pitch-VNSWID)<<1) - : "%al", "%edx", "%cc" ); - } - else - { - asm volatile( - "xorl %%edx, %%edx\n\t" - "koop1:\n\t" - "movb $128,%%al \n\t" - "koop2:\n\t" - "movb 1(%%esi),%%dl\n\t" - "shl $16,%%edx\n\t" - "movb (%%esi),%%dl\n\t" - "xorl $0x00800080,%%edx\n\t" - "movl %%edx,(%%edi)\n\t" - "addl $2,%%esi\n\t" - "addl $4,%%edi\n\t" - "decb %%al\n\t" - "jne koop2\n\t" - "addl $16,%%esi\n\t" - "addl %%ecx,%%edi\n\t" - "decb %%bl\n\t" - "jne koop1\n\t" - : - : "S" (XBuf+srendline*272), "D" (ScreenLoc+((240-totallines)/2)*pitch+(640-512)/2),"b" (totallines), "c" (pitch-512+pitch) - : "%al", "%edx", "%cc" ); - } - } - else if(vmod==4) - { - if(eoptions&EO_CLIPSIDES) - { - asm volatile( - "ayoop1:\n\t" - "movb $120,%%al \n\t" - "ayoop2:\n\t" - "movb 1(%%esi),%%dh\n\t" - "movb %%dh,%%dl\n\t" - "shl $16,%%edx\n\t" - "movb (%%esi),%%dl\n\t" - "movb %%dl,%%dh\n\t" // Ugh - "xorl $0x80808080,%%edx\n\t" - "movl %%edx,(%%edi)\n\t" - "addl $2,%%esi\n\t" - "addl $4,%%edi\n\t" - "decb %%al\n\t" - "jne ayoop2\n\t" - "addl $32,%%esi\n\t" - "addl %%ecx,%%edi\n\t" - "decb %%bl\n\t" - "jne ayoop1\n\t" - : - : "S" (XBuf+srendline*272+VNSCLIP), "D" (ScreenLoc+((240-totallines)/2)*pitch+(640-(VNSWID<<1))/2),"b" (totallines), "c" ((pitch-VNSWID)<<1) - : "%al", "%edx", "%cc" ); - } - else - { - asm volatile( - "yoop1:\n\t" - "movb $128,%%al \n\t" - "yoop2:\n\t" - "movb 1(%%esi),%%dh\n\t" - "movb %%dh,%%dl\n\t" - "shl $16,%%edx\n\t" - "movb (%%esi),%%dl\n\t" - "movb %%dl,%%dh\n\t" // Ugh - "xorl $0x80808080,%%edx\n\t" - "movl %%edx,(%%edi)\n\t" - "addl $2,%%esi\n\t" - "addl $4,%%edi\n\t" - "decb %%al\n\t" - "jne yoop2\n\t" - "addl $16,%%esi\n\t" - "addl %%ecx,%%edi\n\t" - "decb %%bl\n\t" - "jne yoop1\n\t" - : - : "S" (XBuf+srendline*272), "D" (ScreenLoc+((240-totallines)/2)*pitch+(640-512)/2),"b" (totallines), "c" (pitch-512+pitch) - : "%al", "%edx", "%cc" ); - } - } - else - { - if(!(vmodes[vmod].flags&VMDF_DXBLT)) - { - ScreenLoc+=((vmodes[vmod].x-VNSWID)>>1)*(bpp>>3)+(((vmodes[vmod].y-totallines)>>1))*pitch; - } - if(bpp>=16) - { - BlitVidHi(XBuf+srendline*272+VNSCLIP, ScreenLoc, /*VNSWID,*/ totallines, pitch); - } - else - { - XBuf+=srendline*272+VNSCLIP; - if(eoptions&EO_CLIPSIDES) - { - for(y=totallines;y;y--) - { - for(x=60;x;x--) - { - *(long *)ScreenLoc=(*(long *)XBuf)^0x80808080; - ScreenLoc+=4; - XBuf+=4; - } - ScreenLoc+=pitch-240; - XBuf+=32; - } - } - else - { - for(y=totallines;y;y--) - { - for(x=64;x;x--) - { - *(long *)ScreenLoc=(*(long *)XBuf)^0x80808080; - ScreenLoc+=4; - XBuf+=4; - } - ScreenLoc+=pitch-256; - XBuf+=16; - } - } - } - } - - if(vmodes[vmod].flags&VMDF_DXBLT) - { - IDirectDrawSurface4_Unlock(lpDDSBack, NULL); - - if(veflags&2) - { - if(IDirectDrawSurface4_Lock(lpDDSVPrimary,NULL,&ddsd, 0, NULL)==DD_OK) - { - memset(ddsd.lpSurface,0,ddsd.DUMMYUNIONNAMEN(1).lPitch*vmodes[vmod].y); - IDirectDrawSurface4_Unlock(lpDDSVPrimary, NULL); - veflags&=~2; - } - } - - - if(IDirectDrawSurface4_Blt(lpDDSVPrimary, &drect,lpDDSBack,&srect,DDBLT_ASYNC,0)!=DD_OK) - { - ddrval=IDirectDrawSurface4_Blt(lpDDSVPrimary, &drect,lpDDSBack,&srect,DDBLT_WAIT,0); - if(ddrval!=DD_OK) - { - if(ddrval==DDERR_SURFACELOST) - { - RestoreDD(0); - RestoreDD(1); - } - return; - } - - } - } - else - IDirectDrawSurface4_Unlock(lpDDSVPrimary, NULL); - if(fssync==2) - { - IDirectDrawSurface4_Flip(lpDDSPrimary,0,0); - - } -} - -void ResetVideo(void) -{ - ShowCursorAbs(1); - if(palettetranslate) {free(palettetranslate);palettetranslate=0;} - if(lpDD4) - if(mustrestore) - {IDirectDraw4_RestoreDisplayMode(lpDD4);mustrestore=0;} - if(lpDDSBack) {IDirectDrawSurface4_Release(lpDDSBack);lpDDSBack=0;} - if(lpDDSPrimary) {IDirectDrawSurface4_Release(lpDDSPrimary);lpDDSPrimary=0;} - if(lpClipper) {IDirectDrawClipper_Release(lpClipper);lpClipper=0;} -} - -static int RecalcCustom(void) -{ - vmodes[0].flags&=~VMDF_DXBLT; - - if(vmodes[0].flags&VMDF_STRFS) - { - vmodes[0].flags|=VMDF_DXBLT; - - vmodes[0].srect.top=srendline; - vmodes[0].srect.left=VNSCLIP; - vmodes[0].srect.right=256-VNSCLIP; - vmodes[0].srect.bottom=erendline+1; - - vmodes[0].drect.top=vmodes[0].drect.left=0; - vmodes[0].drect.right=vmodes[0].x; - vmodes[0].drect.bottom=vmodes[0].y; - } - else if(vmodes[0].xscale!=1 || vmodes[0].yscale!=1) - { - vmodes[0].flags|=VMDF_DXBLT; - if(VNSWID*vmodes[0].xscale>vmodes[0].x) - { - FCEUD_PrintError("Scaled width is out of range. Reverting to no horizontal scaling."); - vmodes[0].xscale=1; - } - if(totallines*vmodes[0].yscale>vmodes[0].y) - { - FCEUD_PrintError("Scaled height is out of range. Reverting to no vertical scaling."); - vmodes[0].yscale=1; - } - - vmodes[0].srect.left=VNSCLIP; - vmodes[0].srect.top=srendline; - vmodes[0].srect.right=256-VNSCLIP; - vmodes[0].srect.bottom=erendline+1; - - vmodes[0].drect.top=(vmodes[0].y-(totallines*vmodes[0].yscale))>>1; - vmodes[0].drect.bottom=vmodes[0].drect.top+totallines*vmodes[0].yscale; - - vmodes[0].drect.left=(vmodes[0].x-(VNSWID*vmodes[0].xscale))>>1; - vmodes[0].drect.right=vmodes[0].drect.left+VNSWID*vmodes[0].xscale; - } - - if(vmodes[0].x>3)-1,(LPARAM)(LPSTR)0); - - SetDlgItemInt(hwndDlg,200,vmodes[0].x,0); - SetDlgItemInt(hwndDlg,201,vmodes[0].y,0); - - SetDlgItemInt(hwndDlg,302,vmodes[0].xscale,0); - SetDlgItemInt(hwndDlg,303,vmodes[0].yscale,0); - CheckRadioButton(hwndDlg,300,301,(vmodes[0].flags&VMDF_STRFS)?301:300); - if(eoptions&EO_FSAFTERLOAD) - CheckDlgButton(hwndDlg,102,BST_CHECKED); - - if(eoptions&EO_CLIPSIDES) - CheckDlgButton(hwndDlg,106,BST_CHECKED); - - SetDlgItemInt(hwndDlg,500,srendlinen,0); - SetDlgItemInt(hwndDlg,501,erendlinen,0); - - SetDlgItemInt(hwndDlg,502,srendlinep,0); - SetDlgItemInt(hwndDlg,503,erendlinep,0); - - - SetDlgItemInt(hwndDlg,103,winsizemul,0); - - SendDlgItemMessage(hwndDlg,104,CB_ADDSTRING,0,(LPARAM)(LPSTR)""); - SendDlgItemMessage(hwndDlg,105,CB_ADDSTRING,0,(LPARAM)(LPSTR)""); - - SendDlgItemMessage(hwndDlg,104,CB_ADDSTRING,0,(LPARAM)(LPSTR)"Wait for VBlank"); - SendDlgItemMessage(hwndDlg,105,CB_ADDSTRING,0,(LPARAM)(LPSTR)"Wait for VBlank"); - - SendDlgItemMessage(hwndDlg,105,CB_ADDSTRING,0,(LPARAM)(LPSTR)"Double Buffering"); - - SendDlgItemMessage(hwndDlg,104,CB_SETCURSEL,winsync,(LPARAM)(LPSTR)0); - SendDlgItemMessage(hwndDlg,105,CB_SETCURSEL,fssync,(LPARAM)(LPSTR)0); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 1: - gornk: - - if(IsDlgButtonChecked(hwndDlg,106)==BST_CHECKED) - eoptions|=EO_CLIPSIDES; - else - eoptions&=~EO_CLIPSIDES; - - srendlinen=GetDlgItemInt(hwndDlg,500,0,0); - erendlinen=GetDlgItemInt(hwndDlg,501,0,0); - srendlinep=GetDlgItemInt(hwndDlg,502,0,0); - erendlinep=GetDlgItemInt(hwndDlg,503,0,0); - - - if(erendlinen>239) erendlinen=239; - if(srendlinen>erendlinen) srendlinen=erendlinen; - - if(erendlinep>239) erendlinep=239; - if(srendlinep>erendlinen) srendlinep=erendlinep; - - UpdateRendBounds(); - - if(IsDlgButtonChecked(hwndDlg,301)==BST_CHECKED) - vmodes[0].flags|=VMDF_STRFS; - else - vmodes[0].flags&=~VMDF_STRFS; - - vmod=SendDlgItemMessage(hwndDlg,100,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - vmodes[0].x=GetDlgItemInt(hwndDlg,200,0,0); - vmodes[0].y=GetDlgItemInt(hwndDlg,201,0,0); - vmodes[0].bpp=(SendDlgItemMessage(hwndDlg,202,CB_GETCURSEL,0,(LPARAM)(LPSTR)0)+1)<<3; - - vmodes[0].xscale=GetDlgItemInt(hwndDlg,302,0,0); - vmodes[0].yscale=GetDlgItemInt(hwndDlg,303,0,0); - - if(IsDlgButtonChecked(hwndDlg,101)==BST_CHECKED) - fullscreen=1; - else - fullscreen=0; - if(IsDlgButtonChecked(hwndDlg,102)==BST_CHECKED) - eoptions|=EO_FSAFTERLOAD; - else - eoptions&=~EO_FSAFTERLOAD; - - { - int t=GetDlgItemInt(hwndDlg,103,0,0); - if(t>0 && t<60) - winsizemul=t; - } - winsync=SendDlgItemMessage(hwndDlg,104,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - fssync=SendDlgItemMessage(hwndDlg,105,CB_GETCURSEL,0,(LPARAM)(LPSTR)0); - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - -static void SetFSVideoMode(void) -{ - changerecursive=1; - if(!SetVideoMode(1)) - SetVideoMode(0); - changerecursive=0; -} - - - -void ConfigVideo(void) -{ - DialogBox(fceu_hInstance,"VIDEOCONFIG",hAppWnd,VideoConCallB); - UpdateRendBounds(); - if(fullscreen) - SetFSVideoMode(); - else - SetMainWindowStuff(); -} - -void DoVideoConfigFix(void) -{ - UpdateRendBounds(); -} - - -#ifdef moo - if(!vmod) - { - if(vmodes[0].x>8)&0xFF,soundlog); - fputc((s>>16)&0xFF,soundlog); - fputc((s>>24)&0xFF,soundlog); - - fseek(soundlog,0x28,SEEK_SET); - s=wsize; - fputc(s&0xFF,soundlog); - fputc((s>>8)&0xFF,soundlog); - fputc((s>>16)&0xFF,soundlog); - fputc((s>>24)&0xFF,soundlog); - - fclose(soundlog); - soundlog=0; - return 1; -} -int WriteWaveHeader(FILE *fp) -{ - int r; - fputs("RIFF",fp); - fseek(fp,4,SEEK_CUR); // Skip size - fputs("WAVEfmt ",fp); - fputc(0x10,fp); - fputc(0,fp); - fputc(0,fp); - fputc(0,fp); - - fputc(1,fp); // PCM - fputc(0,fp); - fputc(1,fp); // Monophonic - fputc(0,fp); - - r=44100; - fputc(r&0xFF,fp); - fputc((r>>8)&0xFF,fp); - fputc((r>>16)&0xFF,fp); - fputc((r>>24)&0xFF,fp); - r<<=1; - fputc(r&0xFF,fp); - fputc((r>>8)&0xFF,fp); - fputc((r>>16)&0xFF,fp); - fputc((r>>24)&0xFF,fp); - fputc(2,fp); - fputc(0,fp); - fputc(16,fp); - fputc(0,fp); - - fputs("data",fp); - fseek(fp,4,SEEK_CUR); - - return 1; -} - -int StartSoundLog(char *str) -{ - wsize=0; - soundlog=fopen(str,"wb"); - if(soundlog) - return WriteWaveHeader(soundlog); - else - return 0; -} -int CreateSoundSave(void) -{ - const char filter[]="MS WAVE(*.wav)\0*.wav\0"; - char nameo[2048]; - OPENFILENAME ofn; - - if(soundlog) - { - CloseWave(); - return 0; - } - - memset(&ofn,0,sizeof(ofn)); - ofn.lStructSize=sizeof(ofn); - ofn.hInstance=fceu_hInstance; - ofn.lpstrTitle="Log Sound As..."; - ofn.lpstrFilter=filter; - nameo[0]=0; - ofn.lpstrFile=nameo; - ofn.nMaxFile=256; - ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; - if(GetSaveFileName(&ofn)) - return StartSoundLog(nameo); - return 0; -} diff --git a/drivers/win/window.c b/drivers/win/window.c deleted file mode 100644 index 6ccd4e0..0000000 --- a/drivers/win/window.c +++ /dev/null @@ -1,855 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * 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 - */ - -static void ConfigMisc(void); -static void ConfigPalette(void); -static void ConfigDirectories(void); - -static HMENU fceumenu=0; -static HMENU recentmenu; - -static int tog=0; - -void ShowCursorAbs(int w) -{ - static int stat=0; - if(w) - { - if(stat==-1) {stat++; ShowCursor(1);} - } - else - { - if(stat==0) {stat--; ShowCursor(0);} - } -} - - -RECT *CalcWindowSize(void) -{ - static RECT al; - al.left=0; - al.right=VNSWID*winsizemul; - al.top=0; - al.bottom=totallines*winsizemul; - - AdjustWindowRectEx(&al,GetWindowLong(hAppWnd,GWL_STYLE),GetMenu(hAppWnd)!=NULL,GetWindowLong(hAppWnd,GWL_EXSTYLE)); - - al.right-=al.left; - al.left=0; - al.bottom-=al.top; - al.top=0; - - return(&al); -} - -void UpdateMenu(void) -{ - static int *polo[2]={&genie,&palyo}; - static int polo2[2]={310,311}; - int x; - - for(x=0;x<2;x++) - CheckMenuItem(fceumenu,polo2[x],*polo[x]?MF_CHECKED:MF_UNCHECKED); - if(eoptions&EO_BGRUN) - CheckMenuItem(fceumenu,301,MF_CHECKED); - else - CheckMenuItem(fceumenu,301,MF_UNCHECKED); -} - -char *rfiles[10]={0,0,0,0,0,0,0,0,0,0}; - -void UpdateRMenu(void) -{ - MENUITEMINFO moo; - int x; - - moo.cbSize=sizeof(moo); - moo.fMask=MIIM_SUBMENU|MIIM_STATE; - - GetMenuItemInfo(GetSubMenu(fceumenu,0),102,FALSE,&moo); - moo.hSubMenu=recentmenu; - moo.fState=rfiles[0]?MFS_ENABLED:MFS_GRAYED; - - SetMenuItemInfo(GetSubMenu(fceumenu,0),102,FALSE,&moo); - - for(x=0;x<10;x++) - RemoveMenu(recentmenu,600+x,MF_BYCOMMAND); - for(x=9;x>=0;x--) - { - char tmp[128+5]; - if(!rfiles[x]) continue; - - moo.cbSize=sizeof(moo); - moo.fMask=MIIM_DATA|MIIM_ID|MIIM_TYPE; - - if(strlen(rfiles[x])<128) - { - sprintf(tmp,"&%d. %s",(x+1)%10,rfiles[x]); - } - else - sprintf(tmp,"&%d. %s",(x+1)%10,rfiles[x]+strlen(rfiles[x])-127); - - moo.cch=strlen(tmp); - moo.fType=0; - moo.wID=600+x; - moo.dwTypeData=tmp; - InsertMenuItem(recentmenu,0,1,&moo); - } - DrawMenuBar(hAppWnd); -} - -void AddRecent(char *fn) -{ - int x; - - for(x=0;x<10;x++) - if(rfiles[x]) - if(!strcmp(rfiles[x],fn)) // Item is already in list. - { - int y; - char *tmp; - - tmp=rfiles[x]; // Save pointer. - for(y=x;y;y--) - rfiles[y]=rfiles[y-1]; // Move items down. - - rfiles[0]=tmp; // Put item on top. - UpdateRMenu(); - return; - } - - if(rfiles[9]) free(rfiles[9]); - for(x=9;x;x--) rfiles[x]=rfiles[x-1]; - rfiles[0]=malloc(strlen(fn)+1); - strcpy(rfiles[0],fn); - UpdateRMenu(); -} - -void HideMenu(int h) -{ - if(h) - { - SetMenu(hAppWnd,0); - } - else - { - SetMenu(hAppWnd,fceumenu); - } -} - -static LONG WindowXC=1<<30,WindowYC; -void HideFWindow(int h) -{ - LONG desa; - - if(h) - { - RECT bo; - GetWindowRect(hAppWnd,&bo); - WindowXC=bo.left; - WindowYC=bo.top; - - SetMenu(hAppWnd,0); - desa=WS_POPUP|WS_CLIPSIBLINGS; - } - else - { - desa=WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS; - HideMenu(tog); - } - - SetWindowLong(hAppWnd,GWL_STYLE,desa|(GetWindowLong(hAppWnd,GWL_STYLE)&WS_VISIBLE)); - SetWindowPos(hAppWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_NOZORDER); -} - -void ToggleHideMenu(void) -{ - if(!fullscreen) - { - tog^=1; - HideMenu(tog); - SetMainWindowStuff(); - } -} - -static void ALoad(char *nameo) -{ - if((GI=FCEUI_LoadGame(nameo))) - { - FixFL(); - FixGIGO(); - SetMainWindowStuff(); - AddRecent(nameo); - RefreshThrottleFPS(); - if(eoptions&EO_FSAFTERLOAD) - SetFSVideoMode(); - } - else - StopSound(); -} - -void LoadNewGamey(HWND hParent) -{ - const char filter[]="All usable files(*.nes,*.nsf,*.fds,*.unf,*.zip,*.gz)\0*.nes;*.nsf;*.fds;*.unf;*.zip;*.gz\0All non-compressed usable files(*.nes,*.nsf,*.fds,*.unf)\0*.nes;*.nsf;*.fds;*.unf\0All files (*.*)\0*.*\0"; - char nameo[2048]; - OPENFILENAME ofn; - memset(&ofn,0,sizeof(ofn)); - ofn.lStructSize=sizeof(ofn); - ofn.hInstance=fceu_hInstance; - ofn.lpstrTitle="FCE Ultra Open File..."; - ofn.lpstrFilter=filter; - nameo[0]=0; - ofn.hwndOwner=hParent; - ofn.lpstrFile=nameo; - ofn.nMaxFile=256; - ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; //OFN_EXPLORER|OFN_ENABLETEMPLATE|OFN_ENABLEHOOK; - ofn.lpstrInitialDir=gfsdir; - if(GetOpenFileName(&ofn)) - { - if(gfsdir) free(gfsdir); - if((gfsdir=malloc(ofn.nFileOffset+1))) - { - strncpy(gfsdir,ofn.lpstrFile,ofn.nFileOffset); - gfsdir[ofn.nFileOffset]=0; - } - ALoad(nameo); - } -} - -static uint32 mousex,mousey,mouseb; -void GetMouseData(uint32 *x, uint32 *y, uint32 *b) -{ - *x=mousex; - *y=mousey; - if(!fullscreen) - { - if(eoptions&EO_USERFORCE) - { - RECT t; - GetClientRect(hAppWnd,&t); - - *x=*x*VNSWID/(t.right?t.right:1); - *y=*y*totallines/(t.bottom?t.bottom:1); - } - else - { - *x/=winsizemul; - *y/=winsizemul; - } - *x+=VNSCLIP; - } - - *y+=srendline; - *b=((mouseb==MK_LBUTTON)?1:0)|((mouseb==MK_RBUTTON)?2:0); -} - -static int sizchange=0; -static int vchanged=0; - -LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) -{ - switch(msg) { - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - mouseb=wParam; - goto proco; - case WM_MOUSEMOVE: - { - mousex=LOWORD(lParam); - mousey=HIWORD(lParam); - } - goto proco; - case WM_SIZING: - sizchange=1; - goto proco; - case WM_DISPLAYCHANGE: - if(!fullscreen && !changerecursive) - vchanged=1; - goto proco; - case WM_DROPFILES: - { - UINT len; - char *ftmp; - - len=DragQueryFile((HANDLE)wParam,0,0,0)+1; - if((ftmp=malloc(len))) - { - DragQueryFile((HANDLE)wParam,0,ftmp,len); - ALoad(ftmp); - free(ftmp); - } - } - break; - case WM_COMMAND: - if(!(wParam>>16)) - { - wParam&=0xFFFF; - if(wParam>=600 && wParam<=609) - { - if(rfiles[wParam-600]) ALoad(rfiles[wParam-600]); - } - switch(wParam) - { - case 300:ToggleHideMenu();break; - case 301:eoptions^=EO_BGRUN;UpdateMenu();break; - - case 310:genie^=1;FCEUI_SetGameGenie(genie);UpdateMenu();break; - case 311:palyo^=1; - FCEUI_SetVidSystem(palyo); - RefreshThrottleFPS(); - UpdateMenu(); - FixFL(); - SetMainWindowStuff(); - break; - - case 320:StopSound();ConfigDirectories();break; - case 321:StopSound();ConfigInput(hWnd);break; - case 322:ConfigMisc();break; - case 323:StopSound();ConfigNetplay();break; - case 324:StopSound();ConfigPalette();break; - case 325:StopSound();ConfigSound();break; - case 326:ConfigVideo();break; - - case 200:DriverInterface(DES_RESET,0);break; - case 201:DriverInterface(DES_POWER,0);break; - case 202:ConfigCheats(hWnd);break; - - case 100:StopSound(); - LoadNewGamey(hWnd); - break; - case 101:if(GI) - { - FCEUI_CloseGame(); - GI=0; - } - break; - case 110:FCEUI_SaveState();break; - case 111:FCEUI_LoadState();break; - - case 120: - { - MENUITEMINFO mi; - char *str; - - StopSound(); - if(CreateSoundSave()) - str="Stop Sound Logging"; - else - str="Log Sound As..."; - memset(&mi,0,sizeof(mi)); - mi.fMask=MIIM_DATA|MIIM_TYPE; - mi.cbSize=sizeof(mi); - GetMenuItemInfo(fceumenu,120,0,&mi); - mi.fMask=MIIM_DATA|MIIM_TYPE; - mi.cbSize=sizeof(mi); - mi.dwTypeData=str; - mi.cch=strlen(str); - SetMenuItemInfo(fceumenu,120,0,&mi); - } - break; - case 130:DoFCEUExit();break; - - case 400:StopSound();ShowAboutBox();break; - } - } - break; - - - case WM_SYSCOMMAND: - if(wParam==SC_KEYMENU) - if(GI && InputTypeFC==SIFC_FKB && cidisabled) - break; - goto proco; - case WM_SYSKEYDOWN: - if(GI && InputTypeFC==SIFC_FKB && cidisabled) - break; /* Hopefully this won't break DInput... */ - - if(fullscreen || tog) - { - if(wParam==VK_MENU) - break; - } - if(wParam==VK_F10) - { - if(!(lParam&0x40000000)) - DriverInterface(DES_RESET,0); - break; - } - goto proco; - - case WM_KEYDOWN: - if(GI) - { - /* Only disable command keys if a game is loaded(and the other - conditions are right, of course). */ - if(InputTypeFC==SIFC_FKB) - { - if(wParam==VK_SCROLL) - { - cidisabled^=1; - FCEUI_DispMessage("Family Keyboard %sabled.",cidisabled?"en":"dis"); - } - if(cidisabled) - break; /* Hopefully this won't break DInput... */ - } - if(GI->type==GIT_NSF) - switch(wParam) - { - case VK_UP:DriverInterface(DES_NSFINC,0);break; - case VK_DOWN:DriverInterface(DES_NSFDEC,0);break; - case VK_RETURN:DriverInterface(DES_NSFRES,0);break; - - case VK_LEFT:if(!(lParam&0x40000000)) - DriverInterface(DES_NSFDEC,0); break; - case VK_RIGHT:if(!(lParam&0x40000000)) - DriverInterface(DES_NSFINC,0); break; - } - - } - if(!(lParam&0x40000000)) - switch( wParam ) - { - case VK_F11:DriverInterface(DES_POWER,0);break; - case VK_F12:DoFCEUExit();break; - case VK_F2:userpause^=1;break; - case VK_F3:ToggleHideMenu();break; - case VK_F4: UpdateMenu(); - changerecursive=1; - if(!SetVideoMode(fullscreen^1)) - SetVideoMode(fullscreen); - changerecursive=0; - break; - } - goto proco; - - - case WM_NCRBUTTONDOWN: - case WM_NCMBUTTONDOWN:StopSound();goto proco; - case WM_NCLBUTTONDOWN:StopSound();goto proco; - - case WM_ENTERMENULOOP:StopSound();goto proco; - case WM_CLOSE: - case WM_DESTROY: - case WM_QUIT:DoFCEUExit();break; - case WM_ACTIVATEAPP: - if((BOOL)wParam) - { - nofocus=0; - } - else - { - nofocus=1; - } - default: - proco: - return DefWindowProc(hWnd,msg,wParam,lParam); - } - return 0; -} - -void UpdateFCEUWindow(void) -{ - int w,h; - RECT wrect; - - if(vchanged && !fullscreen && !changerecursive && !nofocus) - { - SetVideoMode(0); - vchanged=0; - } - - if(sizchange && !fullscreen && !(eoptions&EO_USERFORCE)) - { - GetWindowRect(hAppWnd,&wrect); - h=wrect.bottom-wrect.top; - w=wrect.right-wrect.left; - if(w!=winwidth) - winsizemul=(w-(winwidth-VNSWID*winsizemul)+(VNSWID>>1))>>8; - else - if(h!=winheight) - winsizemul=(h-(winheight-totallines*winsizemul)+(totallines>>1))>>8; - - if(winsizemul<1) - winsizemul=1; - SetMainWindowStuff(); - } - sizchange=0; - - BlockingCheck(); -} - -void ByebyeWindow(void) -{ - SetMenu(hAppWnd,0); - DestroyMenu(fceumenu); - DestroyWindow(hAppWnd); -} - -int CreateMainWindow(void) -{ - WNDCLASSEX winclass; - RECT tmp; - - memset(&winclass,0,sizeof(winclass)); - winclass.cbSize=sizeof(WNDCLASSEX); - winclass.style=CS_OWNDC|CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS; - winclass.lpfnWndProc=AppWndProc; - winclass.cbClsExtra=0; - winclass.cbWndExtra=0; - winclass.hInstance=fceu_hInstance; - winclass.hIcon=LoadIcon(fceu_hInstance, "ICON_1"); - winclass.hIconSm=LoadIcon(fceu_hInstance, "ICON_1"); - winclass.hCursor=LoadCursor(NULL, IDC_ARROW); - winclass.hbrBackground=GetStockObject(BLACK_BRUSH); - //winclass.lpszMenuName="FCEUMENU"; - winclass.lpszClassName="FCEULTRA"; - - if(!RegisterClassEx(&winclass)) - return FALSE; - - AdjustWindowRectEx(&tmp,WS_OVERLAPPEDWINDOW,1,0); - - fceumenu=LoadMenu(fceu_hInstance,"FCEUMENU"); - recentmenu=CreateMenu(); - UpdateRMenu(); - - hAppWnd = CreateWindowEx(0,"FCEULTRA","FCE Ultra", - WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS, /* Style */ - CW_USEDEFAULT,CW_USEDEFAULT,256,240, /* X,Y ; Width, Height */ - NULL,fceumenu,fceu_hInstance,NULL ); - DragAcceptFiles(hAppWnd, 1); - SetMainWindowStuff(); - return 1; -} - - -int SetMainWindowStuff(void) -{ - RECT *srect; - RECT tmp; - - GetWindowRect(hAppWnd,&tmp); - - if(WindowXC!=(1<<30)) - { - /* Subtracting and adding for if(eoptions&EO_USERFORCE) below. */ - tmp.bottom-=tmp.top; - tmp.bottom+=WindowYC; - - tmp.right-=tmp.left; - tmp.right+=WindowXC; - - - tmp.left=WindowXC; - tmp.top=WindowYC; - WindowXC=1<<30; - } - - if(eoptions&EO_USERFORCE) - { - SetWindowPos(hAppWnd,HWND_TOP,tmp.left,tmp.top,0,0,SWP_NOSIZE|SWP_SHOWWINDOW); - winwidth=tmp.right-tmp.left; - winheight=tmp.bottom-tmp.top; - } - else - { - srect=CalcWindowSize(); - SetWindowPos(hAppWnd,HWND_TOP,tmp.left,tmp.top,srect->right,srect->bottom,SWP_SHOWWINDOW); - winwidth=srect->right; - winheight=srect->bottom; - } - - - ShowWindow(hAppWnd, SW_SHOWNORMAL); - return 1; -} - -int GetClientAbsRect(LPRECT lpRect) -{ - POINT point; - point.x=point.y=0; - if(!ClientToScreen(hAppWnd,&point)) return 0; - - lpRect->top=point.y; - lpRect->left=point.x; - - if(eoptions&EO_USERFORCE) - { - RECT al; - - GetClientRect(hAppWnd,&al); - - lpRect->right=point.x+al.right; - lpRect->bottom=point.y+al.bottom; - } - else - { - lpRect->right=point.x+VNSWID*winsizemul; - lpRect->bottom=point.y+totallines*winsizemul; - } - return 1; -} - - -void LoadPaletteFile(void) -{ - FILE *fp; - const char filter[]="All usable files(*.pal)\0*.pal\0All files (*.*)\0*.*\0"; - char nameo[2048]; - OPENFILENAME ofn; - memset(&ofn,0,sizeof(ofn)); - ofn.lStructSize=sizeof(ofn); - ofn.hInstance=fceu_hInstance; - ofn.lpstrTitle="FCE Ultra Open Palette File..."; - ofn.lpstrFilter=filter; - nameo[0]=0; - ofn.lpstrFile=nameo; - ofn.nMaxFile=256; - ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; - ofn.lpstrInitialDir=0; - if(GetOpenFileName(&ofn)) - { - if((fp=fopen(nameo,"rb"))) - { - fread(cpalette,1,192,fp); - fclose(fp); - FCEUI_SetPaletteArray(cpalette); - eoptions|=EO_CPALETTE; - } - else - FCEUD_PrintError("Error opening palette file!"); - } -} - -BOOL CALLBACK PaletteConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch(uMsg) { - case WM_INITDIALOG: - if(ntsccol) - CheckDlgButton(hwndDlg,100,BST_CHECKED); - SendDlgItemMessage(hwndDlg,500,TBM_SETRANGE,1,MAKELONG(0,128)); - SendDlgItemMessage(hwndDlg,501,TBM_SETRANGE,1,MAKELONG(0,128)); - DriverInterface(DES_GETNTSCTINT,&ntsctint); - DriverInterface(DES_GETNTSCHUE,&ntschue); - SendDlgItemMessage(hwndDlg,500,TBM_SETPOS,1,ntsctint); - SendDlgItemMessage(hwndDlg,501,TBM_SETPOS,1,ntschue); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 100:ntsccol^=1;DriverInterface(DES_NTSCCOL,&ntsccol);break; - case 200: - LoadPaletteFile(); - break; - case 201:FCEUI_SetPaletteArray(0); - eoptions&=~EO_CPALETTE; - break; - case 1: - gornk: - ntsctint=SendDlgItemMessage(hwndDlg,500,TBM_GETPOS,0,(LPARAM)(LPSTR)0); - ntschue=SendDlgItemMessage(hwndDlg,501,TBM_GETPOS,0,(LPARAM)(LPSTR)0); - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - -static void ConfigPalette(void) -{ - DialogBox(fceu_hInstance,"PALCONFIG",hAppWnd,PaletteConCallB); - DriverInterface(DES_SETNTSCTINT,&ntsctint); - DriverInterface(DES_SETNTSCHUE,&ntschue); -} - - -static BOOL CALLBACK MiscConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch(uMsg) { - case WM_INITDIALOG: - if(eoptions&EO_NOSPRLIM) - CheckDlgButton(hwndDlg,100,BST_CHECKED); - if(eoptions&EO_FOAFTERSTART) - CheckDlgButton(hwndDlg,102,BST_CHECKED); - if(eoptions&EO_SNAPNAME) - CheckDlgButton(hwndDlg,103,BST_CHECKED); - if(eoptions&EO_NOTHROTTLE) - CheckDlgButton(hwndDlg,101,BST_CHECKED); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(!(wParam>>16)) - switch(wParam&0xFFFF) - { - case 1: - gornk: - if(IsDlgButtonChecked(hwndDlg,100)==BST_CHECKED) - eoptions|=EO_NOSPRLIM; - else - eoptions&=~EO_NOSPRLIM; - if(IsDlgButtonChecked(hwndDlg,102)==BST_CHECKED) - eoptions|=EO_FOAFTERSTART; - else - eoptions&=~EO_FOAFTERSTART; - if(IsDlgButtonChecked(hwndDlg,103)==BST_CHECKED) - eoptions|=EO_SNAPNAME; - else - eoptions&=~EO_SNAPNAME; - if(IsDlgButtonChecked(hwndDlg,101)==BST_CHECKED) - eoptions|=EO_NOTHROTTLE; - else - eoptions&=~EO_NOTHROTTLE; - EndDialog(hwndDlg,0); - break; - } - } - return 0; -} - -void DoMiscConfigFix(void) -{ - FCEUI_DisableSpriteLimitation(eoptions&EO_NOSPRLIM); - FCEUI_SetSnapName(eoptions&EO_SNAPNAME); -} - -static void ConfigMisc(void) -{ - DialogBox(fceu_hInstance,"MISCCONFIG",hAppWnd,MiscConCallB); - DoMiscConfigFix(); -} - -static int BrowseForFolder(HWND hParent, char *htext, char *buf) -{ - BROWSEINFO bi; - LPCITEMIDLIST pidl; - int ret=1; - - buf[0]=0; - - memset(&bi,0,sizeof(bi)); - - bi.hwndOwner=hParent; - bi.lpszTitle=htext; - bi.ulFlags=BIF_RETURNONLYFSDIRS; - - if(FAILED(CoInitialize(0))) - return(0); - - if(!(pidl=SHBrowseForFolder(&bi))) - { - ret=0; - goto end1; - } - - if(!SHGetPathFromIDList(pidl,buf)) - { - ret=0; - goto end2; - } - - end2: - /* This probably isn't the best way to free the memory... */ - CoTaskMemFree((PVOID)pidl); - - end1: - CoUninitialize(); - return(ret); -} - -static BOOL CALLBACK DirConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - int x; - - switch(uMsg){ - case WM_INITDIALOG: - for(x=0;x<6;x++) - SetDlgItemText(hwndDlg,100+x,DOvers[x]); - - if(eoptions&EO_BSAV) - CheckDlgButton(hwndDlg,300,BST_CHECKED); - break; - case WM_CLOSE: - case WM_QUIT: goto gornk; - case WM_COMMAND: - if(!(wParam>>16)) - { - if((wParam&0xFFFF)>=200 && (wParam&0xFFFF)<=205) - { - static char *helpert[6]={"Cheats","Miscellaneous","Nonvolatile Game Data","Save States","Screen Snapshots","Base Directory"}; - char name[MAX_PATH]; - - if(BrowseForFolder(hwndDlg,helpert[((wParam&0xFFFF)-200)],name)) - SetDlgItemText(hwndDlg,100+((wParam&0xFFFF)-200),name); - } - else switch(wParam&0xFFFF) - { - case 1: - gornk: - - RemoveDirs(); // Remove empty directories. - - for(x=0;x<6;x++) - { - LONG len; - len=SendDlgItemMessage(hwndDlg,100+x,WM_GETTEXTLENGTH,0,0); - if(len<=0) - { - if(DOvers[x]) free(DOvers[x]); - DOvers[x]=0; - continue; - } - len++; // Add 1 for null character. - if(!(DOvers[x]=malloc(len))) - continue; - if(!GetDlgItemText(hwndDlg,100+x,DOvers[x],len)) - { - free(DOvers[x]); - DOvers[x]=0; - continue; - } - - } - if(IsDlgButtonChecked(hwndDlg,300)==BST_CHECKED) - eoptions|=EO_BSAV; - else - eoptions&=~EO_BSAV; - - CreateDirs(); // Create needed directories. - SetDirs(); // Set the directories in the core. - EndDialog(hwndDlg,0); - break; - } - } - } - return 0; -} - - - -static void ConfigDirectories(void) -{ - DialogBox(fceu_hInstance,"DIRCONFIG",hAppWnd,DirConCallB); -} diff --git a/palettes/conv.c b/palettes/conv.c new file mode 100644 index 0000000..c0cd6b2 --- /dev/null +++ b/palettes/conv.c @@ -0,0 +1,74 @@ +/* Quick conversion stuff for MAME->FCE Ultra */ + +#include +#include "../types.h" +#include "../palette.h" +#include "palettes.h" + +/* check 0x08 */ +static uint8 rp2c04001_colortable[] = +{ + 0x35, 0x23, 0x16, 0x22, 0x1c, 0x09, 0xff, 0x15, /* 0x00 - 0x07 */ + 0x20, 0x00, 0x27, 0x05, 0x04, 0x27, 0x08, 0x30, /* 0x08 - 0x0f */ + 0x21, 0xff, 0xff, 0x29, 0x3c, 0x32, 0x36, 0x12, /* 0x10 - 0x17 */ + 0xff, 0x2b, 0x0f, 0xff, 0x20, 0x10, 0x24, 0x01, /* 0x18 - 0x1f */ + 0xff, 0x31, 0xff, 0x2a, 0x2c, 0x0c, 0xff, 0xff, /* 0x20 - 0x27 */ + 0xff, 0x07, 0x34, 0x06, 0x13, 0x02, 0x26, 0x0f, /* 0x28 - 0x2f */ + 0xff, 0x19, 0x10, 0x0a, 0x39, 0xff, 0x37, 0x17, /* 0x30 - 0x37 */ + 0xff, 0x11, 0x09, 0xff, 0x39, 0x25, 0x18, 0xff /* 0x38 - 0x3f */ +}; + +/* RP2C04-002 */ +static uint8 rp2c04002_colortable[] = +{ + 0x0f, 0x27, 0x18, 0xff, 0x3a, 0x25, 0xff, 0x31, /* 0x00 - 0x07 */ + 0x16, 0x13, 0x38, 0x34, 0x20, 0x23, 0xff, 0x0b, /* 0x08 - 0x0f */ + 0xff, 0x21, 0x06, 0xff, 0x1b, 0x29, 0xff, 0x22, /* 0x10 - 0x17 */ + 0xff, 0x24, 0xff, 0x2b, 0xff, 0x08, 0xff, 0x03, /* 0x18 - 0x1f */ + 0xff, 0x36, 0x26, 0x33, 0x11, 0xff, 0x10, 0x02, /* 0x20 - 0x27 */ + 0x14, 0xff, 0x00, 0x09, 0x12, 0x0f, 0x37, 0x30, /* 0x28 - 0x2f */ + 0xff, 0xff, 0x2a, 0x17, 0x0c, 0x01, 0x15, 0x19, /* 0x30 - 0x37 */ + 0xff, 0x2c, 0x07, 0x37, 0xff, 0x05, 0x0a, 0x00 /* 0x38 - 0x3f */ +}; + +/* RP2C04-003 */ +/* Check 0x00. Used in Dr Mario. */ +static uint8 rp2c04003_colortable[] = +{ + 0x03, 0xff, 0xff, 0x00, 0x1a, 0x30, 0x31, 0x09, /* 0x00 - 0x07 */ + 0x01, 0x0f, 0x36, 0x08, 0x15, 0xff, 0xff, 0x30, /* 0x08 - 0x0f */ + 0x22, 0x1c, 0xff, 0x12, 0x19, 0x18, 0x17, 0x1b, /* 0x10 - 0x17 */ + 0x00, 0xff, 0xff, 0x02, 0x16, 0x06, 0xff, 0x35, /* 0x18 - 0x1f */ + 0x23, 0xff, 0x0f, 0x37, 0xff, 0x27, 0x26, 0x30, /* 0x20 - 0x27 */ + 0x29, 0xff, 0x21, 0x24, 0x11, 0xff, 0x0f, 0xff, /* 0x28 - 0x2f */ + 0x2c, 0xff, 0xff, 0xff, 0x07, 0x2a, 0x28, 0xff, /* 0x30 - 0x37 */ + 0x0a, 0xff, 0x32, 0x37, 0x13, 0xff, 0xff, 0x0c /* 0x38 - 0x3f */ +}; + +/* RP2C05-004 */ +/* check 0x1d, 0x38 */ +static uint8 rp2c05004_colortable[] = +{ + 0x18, 0xff, 0x1c, 0x28, 0xff, 0xff, 0x01, 0x17, /* 0x00 - 0x07 */ + 0x10, 0x0f, 0x2a, 0x0f, 0x36, 0x37, 0x1a, 0xff, /* 0x08 - 0x0f */ + 0x25, 0xff, 0x12, 0xff, 0x0f, 0xff, 0xff, 0x26, /* 0x10 - 0x17 */ + 0xff, 0xff, 0x22, 0x19, 0xff, 0x0f, 0x3a, 0x21, /* 0x18 - 0x1f */ + 0x05, 0x0a, 0x07, 0x01, 0x13, 0xff, 0x00, 0x15, /* 0x20 - 0x27 */ + 0x0c, 0xff, 0x11, 0xff, 0xff, 0x38, 0xff, 0xff, /* 0x28 - 0x2f */ + 0xff, 0xff, 0x08, 0x16, 0xff, 0xff, 0x30, 0x3c, /* 0x30 - 0x37 */ + 0x0f, 0x27, 0xff, 0x31, 0x29, 0xff, 0x30, 0x09 /* 0x38 - 0x3f */ +}; + + +main() +{ + int x; + for(x=0;x<64;x++) + { + // if(x <= 0x20) +// if(rp2c04002_colortable[x] == 0xFF) rp2c04002_colortable[x]= 0x30; + printf("{0x%02x, 0x%02x, 0x%02x},\n",palette[rp2c04001_colortable[x]&0x3F].r, + palette[rp2c04001_colortable[x]&0x3F].g, + palette[rp2c04001_colortable[x]&0x3F].b); + } +} diff --git a/palettes/palettes.h b/palettes/palettes.h new file mode 100644 index 0000000..ed6c2db --- /dev/null +++ b/palettes/palettes.h @@ -0,0 +1,94 @@ +pal rp2c04001[64] = { + #include "rp2c04001.h" +}; + +pal rp2c04002[64] = { + #include "rp2c04002.h" +}; + +pal rp2c04003[64] = { + #include "rp2c04003.h" +}; +pal rp2c05004[64] = { + #include "rp2c05004.h" +}; + +pal unvpalette[7] = { +{ 0x00<<2,0x00<<2,0x00<<2}, // Black +{ 0x3F<<2,0x3F<<2,0x34<<2}, // White +{ 0x00<<2,0x00<<2,0x00<<2}, // Black +{ 0x1d<<2,0x1d<<2,0x24<<2}, // Greyish +{ 190,0,0 }, // Redish +{ 51,255,51}, // Bright green +{ 49,14,200}, +}; + + +/* Default palette */ +pal palette[64] = { + + { 0x1D<<2, 0x1D<<2, 0x1D<<2 }, /* Value 0 */ + { 0x09<<2, 0x06<<2, 0x23<<2 }, /* Value 1 */ + { 0x00<<2, 0x00<<2, 0x2A<<2 }, /* Value 2 */ + { 0x11<<2, 0x00<<2, 0x27<<2 }, /* Value 3 */ + { 0x23<<2, 0x00<<2, 0x1D<<2 }, /* Value 4 */ + { 0x2A<<2, 0x00<<2, 0x04<<2 }, /* Value 5 */ + { 0x29<<2, 0x00<<2, 0x00<<2 }, /* Value 6 */ + { 0x1F<<2, 0x02<<2, 0x00<<2 }, /* Value 7 */ + { 0x10<<2, 0x0B<<2, 0x00<<2 }, /* Value 8 */ + { 0x00<<2, 0x11<<2, 0x00<<2 }, /* Value 9 */ + { 0x00<<2, 0x14<<2, 0x00<<2 }, /* Value 10 */ + { 0x00<<2, 0x0F<<2, 0x05<<2 }, /* Value 11 */ + { 0x06<<2, 0x0F<<2, 0x17<<2 }, /* Value 12 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 13 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 14 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 15 */ + { 0x2F<<2, 0x2F<<2, 0x2F<<2 }, /* Value 16 */ + { 0x00<<2, 0x1C<<2, 0x3B<<2 }, /* Value 17 */ + { 0x08<<2, 0x0E<<2, 0x3B<<2 }, /* Value 18 */ + { 0x20<<2, 0x00<<2, 0x3C<<2 }, /* Value 19 */ + { 0x2F<<2, 0x00<<2, 0x2F<<2 }, /* Value 20 */ + { 0x39<<2, 0x00<<2, 0x16<<2 }, /* Value 21 */ + { 0x36<<2, 0x0A<<2, 0x00<<2 }, /* Value 22 */ + { 0x32<<2, 0x13<<2, 0x03<<2 }, /* Value 23 */ + { 0x22<<2, 0x1C<<2, 0x00<<2 }, /* Value 24 */ + { 0x00<<2, 0x25<<2, 0x00<<2 }, /* Value 25 */ + { 0x00<<2, 0x2A<<2, 0x00<<2 }, /* Value 26 */ + { 0x00<<2, 0x24<<2, 0x0E<<2 }, /* Value 27 */ + { 0x00<<2, 0x20<<2, 0x22<<2 }, /* Value 28 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 29 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 30 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 31 */ + { 0x3F<<2, 0x3F<<2, 0x3F<<2 }, /* Value 32 */ + { 0x0F<<2, 0x2F<<2, 0x3F<<2 }, /* Value 33 */ + { 0x17<<2, 0x25<<2, 0x3F<<2 }, /* Value 34 */ + { 0x10<<2, 0x22<<2, 0x3F<<2 }, /* Value 35 */ + { 0x3D<<2, 0x1E<<2, 0x3F<<2 }, /* Value 36 */ + { 0x3F<<2, 0x1D<<2, 0x2D<<2 }, /* Value 37 */ + { 0x3F<<2, 0x1D<<2, 0x18<<2 }, /* Value 38 */ + { 0x3F<<2, 0x26<<2, 0x0E<<2 }, /* Value 39 */ + { 0x3C<<2, 0x2F<<2, 0x0F<<2 }, /* Value 40 */ + { 0x20<<2, 0x34<<2, 0x04<<2 }, /* Value 41 */ + { 0x13<<2, 0x37<<2, 0x12<<2 }, /* Value 42 */ + { 0x16<<2, 0x3E<<2, 0x26<<2 }, /* Value 43 */ + { 0x00<<2, 0x3A<<2, 0x36<<2 }, /* Value 44 */ + { 0x1E<<2, 0x1E<<2, 0x1E<<2 }, /* Value 45 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 46 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 47 */ + { 0x3F<<2, 0x3F<<2, 0x3F<<2 }, /* Value 48 */ + { 0x2A<<2, 0x39<<2, 0x3F<<2 }, /* Value 49 */ + { 0x31<<2, 0x35<<2, 0x3F<<2 }, /* Value 50 */ + { 0x35<<2, 0x32<<2, 0x3F<<2 }, /* Value 51 */ + { 0x3F<<2, 0x31<<2, 0x3F<<2 }, /* Value 52 */ + { 0x3F<<2, 0x31<<2, 0x36<<2 }, /* Value 53 */ + { 0x3F<<2, 0x2F<<2, 0x2C<<2 }, /* Value 54 */ + { 0x3F<<2, 0x36<<2, 0x2A<<2 }, /* Value 55 */ + { 0x3F<<2, 0x39<<2, 0x28<<2 }, /* Value 56 */ + { 0x38<<2, 0x3F<<2, 0x28<<2 }, /* Value 57 */ + { 0x2A<<2, 0x3C<<2, 0x2F<<2 }, /* Value 58 */ + { 0x2C<<2, 0x3F<<2, 0x33<<2 }, /* Value 59 */ + { 0x27<<2, 0x3F<<2, 0x3C<<2 }, /* Value 60 */ + { 0x31<<2, 0x31<<2, 0x31<<2 }, /* Value 61 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 62 */ + { 0x00<<2, 0x00<<2, 0x00<<2 }, /* Value 63 */ +}; diff --git a/palettes/rp2c04001.old b/palettes/rp2c04001.old new file mode 100644 index 0000000..f2526b9 --- /dev/null +++ b/palettes/rp2c04001.old @@ -0,0 +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, }, diff --git a/palettes/rp2c04002.h b/palettes/rp2c04002.h new file mode 100644 index 0000000..d0f46b9 --- /dev/null +++ b/palettes/rp2c04002.h @@ -0,0 +1,64 @@ +{0x00, 0x00, 0x00}, +{0xfc, 0x98, 0x38}, +{0x88, 0x70, 0x00}, +{0x00, 0x00, 0x00}, +{0xa8, 0xf0, 0xbc}, +{0xfc, 0x74, 0xb4}, +{0x00, 0x00, 0x00}, +{0xa8, 0xe4, 0xfc}, +{0xd8, 0x28, 0x00}, +{0x80, 0x00, 0xf0}, +{0xfc, 0xe4, 0xa0}, +{0xfc, 0xc4, 0xfc}, +{0xfc, 0xfc, 0xfc}, +{0x40, 0x88, 0xfc}, +{0x00, 0x00, 0x00}, +{0x00, 0x3c, 0x14}, +{0x00, 0x00, 0x00}, +{0x3c, 0xbc, 0xfc}, +{0xa4, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x90, 0x38}, +{0x80, 0xd0, 0x10}, +{0x00, 0x00, 0x00}, +{0x5c, 0x94, 0xfc}, +{0x00, 0x00, 0x00}, +{0xf4, 0x78, 0xfc}, +{0x00, 0x00, 0x00}, +{0x58, 0xf8, 0x98}, +{0x00, 0x00, 0x00}, +{0x40, 0x2c, 0x00}, +{0x00, 0x00, 0x00}, +{0x44, 0x00, 0x9c}, +{0x00, 0x00, 0x00}, +{0xfc, 0xbc, 0xb0}, +{0xfc, 0x74, 0x60}, +{0xd4, 0xc8, 0xfc}, +{0x00, 0x70, 0xec}, +{0x00, 0x00, 0x00}, +{0xbc, 0xbc, 0xbc}, +{0x00, 0x00, 0xa8}, +{0xbc, 0x00, 0xbc}, +{0x00, 0x00, 0x00}, +{0x74, 0x74, 0x74}, +{0x00, 0x44, 0x00}, +{0x20, 0x38, 0xec}, +{0x00, 0x00, 0x00}, +{0xfc, 0xd8, 0xa8}, +{0xfc, 0xfc, 0xfc}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x4c, 0xdc, 0x48}, +{0xc8, 0x4c, 0x0c}, +{0x18, 0x3c, 0x5c}, +{0x24, 0x18, 0x8c}, +{0xe4, 0x00, 0x58}, +{0x00, 0x94, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0xe8, 0xd8}, +{0x7c, 0x08, 0x00}, +{0xfc, 0xd8, 0xa8}, +{0x00, 0x00, 0x00}, +{0xa8, 0x00, 0x10}, +{0x00, 0x50, 0x00}, +{0x74, 0x74, 0x74}, diff --git a/palettes/rp2c04003.h b/palettes/rp2c04003.h new file mode 100644 index 0000000..9a4717c --- /dev/null +++ b/palettes/rp2c04003.h @@ -0,0 +1,64 @@ +{0x44, 0x00, 0x9c}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x74, 0x74, 0x74}, +{0x00, 0xa8, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0xa8, 0xe4, 0xfc}, +{0x00, 0x44, 0x00}, +{0x24, 0x18, 0x8c}, +{0x00, 0x00, 0x00}, +{0xfc, 0xbc, 0xb0}, +{0x40, 0x2c, 0x00}, +{0xe4, 0x00, 0x58}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0x5c, 0x94, 0xfc}, +{0x00, 0x80, 0x88}, +{0x00, 0x00, 0x00}, +{0x20, 0x38, 0xec}, +{0x00, 0x94, 0x00}, +{0x88, 0x70, 0x00}, +{0xc8, 0x4c, 0x0c}, +{0x00, 0x90, 0x38}, +{0x74, 0x74, 0x74}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0xa8}, +{0xd8, 0x28, 0x00}, +{0xa4, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xc4, 0xd8}, +{0x40, 0x88, 0xfc}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xd8, 0xa8}, +{0x00, 0x00, 0x00}, +{0xfc, 0x98, 0x38}, +{0xfc, 0x74, 0x60}, +{0xfc, 0xfc, 0xfc}, +{0x80, 0xd0, 0x10}, +{0x00, 0x00, 0x00}, +{0x3c, 0xbc, 0xfc}, +{0xf4, 0x78, 0xfc}, +{0x00, 0x70, 0xec}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0xe8, 0xd8}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x7c, 0x08, 0x00}, +{0x4c, 0xdc, 0x48}, +{0xf0, 0xbc, 0x3c}, +{0x00, 0x00, 0x00}, +{0x00, 0x50, 0x00}, +{0x00, 0x00, 0x00}, +{0xc4, 0xd4, 0xfc}, +{0xfc, 0xd8, 0xa8}, +{0x80, 0x00, 0xf0}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x18, 0x3c, 0x5c}, diff --git a/palettes/rp2c05004.h b/palettes/rp2c05004.h new file mode 100644 index 0000000..dc0a90a --- /dev/null +++ b/palettes/rp2c05004.h @@ -0,0 +1,64 @@ +{0x88, 0x70, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x80, 0x88}, +{0xf0, 0xbc, 0x3c}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x24, 0x18, 0x8c}, +{0xc8, 0x4c, 0x0c}, +{0xbc, 0xbc, 0xbc}, +{0x00, 0x00, 0x00}, +{0x4c, 0xdc, 0x48}, +{0x00, 0x00, 0x00}, +{0xfc, 0xbc, 0xb0}, +{0xfc, 0xd8, 0xa8}, +{0x00, 0xa8, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0x74, 0xb4}, +{0x00, 0x00, 0x00}, +{0x20, 0x38, 0xec}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0x74, 0x60}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x5c, 0x94, 0xfc}, +{0x00, 0x94, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xa8, 0xf0, 0xbc}, +{0x3c, 0xbc, 0xfc}, +{0xa8, 0x00, 0x10}, +{0x00, 0x50, 0x00}, +{0x7c, 0x08, 0x00}, +{0x00, 0x00, 0xa8}, +{0x80, 0x00, 0xf0}, +{0x00, 0x00, 0x00}, +{0x74, 0x74, 0x74}, +{0xe4, 0x00, 0x58}, +{0x18, 0x3c, 0x5c}, +{0x00, 0x00, 0x00}, +{0x00, 0x70, 0xec}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xe4, 0xa0}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0x40, 0x2c, 0x00}, +{0xd8, 0x28, 0x00}, +{0x00, 0x00, 0x00}, +{0x00, 0x00, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0x9c, 0xfc, 0xf0}, +{0x00, 0x00, 0x00}, +{0xfc, 0x98, 0x38}, +{0x00, 0x00, 0x00}, +{0xa8, 0xe4, 0xfc}, +{0x80, 0xd0, 0x10}, +{0x00, 0x00, 0x00}, +{0xfc, 0xfc, 0xfc}, +{0x00, 0x44, 0x00}, diff --git a/ppu.c b/ppu.c new file mode 100644 index 0000000..0f2a47f --- /dev/null +++ b/ppu.c @@ -0,0 +1,803 @@ +/** + * For whatever reason, breaking this out of fce.c made sprites not corrupt + */ + + +#include +#include +#include + +#include "types.h" +#include "x6502.h" +#include "fce.h" +#include "sound.h" +#include "svga.h" +#include "netplay.h" +#include "general.h" +#include "endian.h" +#include "version.h" +#include "memory.h" + +#include "cart.h" +#include "nsf.h" +#include "fds.h" +#include "ines.h" +#include "unif.h" +#include "cheat.h" + +#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V)>>10][(V)] +//#define MMC5BGVRAMADR(V) &MMC5BGVPage[(V)>>10][(V)] +#define VRAMADR(V) &VPage[(V)>>10][(V)] + +#define V_FLIP 0x80 +#define H_FLIP 0x40 +#define SP_BACK 0x20 + +uint8 SPRAM[0x100]; +static uint8 SPRBUF[0x100]; + +static uint8 sprlinebuf[256+8]; +extern void BGRender(uint8 *target); +extern int tosprite; + + +static int maxsprites=8; + + +void FCEUI_DisableSpriteLimitation(int a) +{ + maxsprites=a?64:8; +} + + +//int printed=1; +typedef struct { + uint8 y,no,atr,x; +} SPR __attribute__((aligned(1))); + +typedef struct { + // uint8 ca[2],atr,x; + uint8 ca[2],atr,x; + // union { int z; } + + +} SPRB __attribute__((aligned(1))); + + + +static uint8 nosprites,SpriteBlurp; + +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; + } + } +} + +#ifdef FRAMESKIP +extern int FSkip; +#endif + +void 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; + } +} + + + + + +/* +void FetchSpriteData(void) +{ + uint8 ns,sb; + SPR *spr; + uint8 H; + int n; + int vofs; + uint8 P0=PPU[0]; + + + spr=(SPR *)SPRAM; + H=8; + + ns=sb=0; + + vofs=(unsigned int)(P0&0x8&(((P0&0x20)^0x20)>>2))<<9; + H+=(P0&0x20)>>2; + + if(!PPU_hook) + for(n=63;n>=0;n--,spr++) + { + if((unsigned int)(scanline-spr->y)>=H) continue; + //printf("%d, %u\n",scanline,(unsigned int)(scanline-spr->y)); + if(nsy); + + 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+=(P0&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[ns<<2]=*(uint32 *)&dst; + } + + ns++; + } + else + { + PPU_status|=0x20; + break; + } + } + else + for(n=63;n>=0;n--,spr++) + { + if((unsigned int)(scanline-spr->y)>=H) continue; + + if(nsy); + + 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+=(P0&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]; + if(ns<8) + { + PPU_hook(0x2000); + PPU_hook(vadr); + } + dst.ca[1]=C[8]; + dst.x=spr->x; + dst.atr=spr->atr; + + + *(uint32 *)&SPRBUF[ns<<2]=*(uint32 *)&dst; + } + + ns++; + } + else + { + PPU_status|=0x20; + break; + } + } + //if(ns>=7) + //printf("%d %d\n",scanline,ns); + if(ns>8) PPU_status|=0x20; // Handle case when >8 sprites per +// scanline option is enabled. + else if(PPU_hook) + { + for(n=0;n<(8-ns);n++) + { + PPU_hook(0x2000); + PPU_hook(vofs); + } + } + numsprites=ns; + SpriteBlurp=sb; +} + + + +void RefreshSprite(uint8 *target) +{ + + int n,sprindex; + SPRB *spr; + uint8 *P=target; + + //if (printed) { printf("SPRB: %d SPR: %d\n", sizeof(SPRB), sizeof(SPR)); printed=0; } + if(!numsprites) return; + + FCEU_dwmemset(sprlinebuf,0x80808080,256); + + numsprites--; + sprindex=numsprites; + spr = (SPRB*)SPRBUF; + + // for(n=nosprites;n>=0;n--,spr--) + for(n=numsprites;n>=0;n--,sprindex--) + { + uint8 J,atr,c1,c2; + int x=spr[sprindex].x; + uint8 *C; + uint8 *VB; + + P+=x; + + c1=((spr[sprindex].ca[0]>>1)&0x55)|(spr[sprindex].ca[1]&0xAA); + c2=(spr[sprindex].ca[0]&0x55)|((spr[sprindex].ca[1]<<1)&0xAA); + + J=spr[sprindex].ca[0]|spr[sprindex].ca[1]; + atr=spr[sprindex].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 + )) + // nothing wrong with this + 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; + } + + numsprites=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; + } +} + + +*/ diff --git a/ppu.h b/ppu.h new file mode 100644 index 0000000..b1b30ba --- /dev/null +++ b/ppu.h @@ -0,0 +1,5 @@ + +extern uint8 SPRAM[0x100]; +//extern uint8 SPRBUF[0x100]; +extern void FetchSpriteData(void); +extern void RefreshSprite(uint8 *target); -- 2.39.5