xboxscene.org forums

Author Topic: Openxdk Nes Emulator  (Read 116 times)

openxdkman

  • Archived User
  • Hero Member
  • *
  • Posts: 550
Openxdk Nes Emulator
« on: March 12, 2007, 01:40:00 AM »

Nope, Joypad doesn't respond.
I will try to debug it a bit. Thanks for your efforts anyway.

I'm a HDTV user and I've noticed you are using a old openxdk version (doesn't auto detect well HDTV's).
I will recompile using last openxdk version.
Logged

openxdkman

  • Archived User
  • Hero Member
  • *
  • Posts: 550
Openxdk Nes Emulator
« Reply #1 on: March 12, 2007, 02:25:00 AM »

1)Resolution
In the source your provide you do :
screen=SDL_SetVideoMode(320,240,16,SDL_HWSURFACE|SDL_DOUBLEBUF);
screen=SDL_SetVideoMode(320,240,16,SDL_FULLSCREEN);

of course you should call it only once and I suggest you do this, instead:
screen=SDL_SetVideoMode(640,480,16,SDL_HWSURFACE|SDL_DOUBLEBUF);

Because 640x480 is the only resolution supported by all adapters (VGA_SOG,HDTV thru components cable, etc...)

2)Joypad

Your mistake is to read ucAnalogButtons[]. You should read usDigitalButtons for half of them:

while(!done)
{
   XInput_GetEvents();
   if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_Y]) { debugPrint("Y"); done=1; }
   if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_X]) debugPrint("X");
   if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_A]) debugPrint("A");
   if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_B]) debugPrint("B");
   if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_BLACK]) debugPrint("0");
   if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_WHITE]) debugPrint("1");
   if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_LEFT_TRIGGER]) debugPrint("LT");
   if (g_Pads[0].PressedButtons.ucAnalogButtons[XPAD_RIGHT_TRIGGER]) debugPrint("RT");
   if (g_Pads[0].PressedButtons.usDigitalButtons&XPAD_DPAD_UP) debugPrint("U");
   if (g_Pads[0].PressedButtons.usDigitalButtons&XPAD_DPAD_DOWN) debugPrint("D");
   if (g_Pads[0].PressedButtons.usDigitalButtons&XPAD_DPAD_RIGHT) debugPrint("R");
   if (g_Pads[0].PressedButtons.usDigitalButtons&XPAD_DPAD_LEFT) debugPrint("L");
   if (g_Pads[0].PressedButtons.usDigitalButtons&XPAD_LEFT_THUMB) debugPrint("LS");
   if (g_Pads[0].PressedButtons.usDigitalButtons&XPAD_RIGHT_THUMB) debugPrint("RS");
   if (g_Pads[0].PressedButtons.usDigitalButtons&XPAD_START) debugPrint("S");
   if (g_Pads[0].PressedButtons.usDigitalButtons&XPAD_BACK) debugPrint("B");

//if you fried your port 0, just add simultaneous detection of port 1 (it's free):
   if (g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_Y]) { debugPrint("Y"); done=1; }
   if (g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_X]) debugPrint("X");
   if (g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_A]) debugPrint("A");
   if (g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_B]) debugPrint("B");
   if (g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_BLACK]) debugPrint("0");
   if (g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_WHITE]) debugPrint("1");
   if (g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_LEFT_TRIGGER]) debugPrint("LT");
   if (g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_RIGHT_TRIGGER]) debugPrint("RT");
   if (g_Pads[1].PressedButtons.usDigitalButtons&XPAD_DPAD_UP) debugPrint("U");
   if (g_Pads[1].PressedButtons.usDigitalButtons&XPAD_DPAD_DOWN) debugPrint("D");
   if (g_Pads[1].PressedButtons.usDigitalButtons&XPAD_DPAD_RIGHT) debugPrint("R");
   if (g_Pads[1].PressedButtons.usDigitalButtons&XPAD_DPAD_LEFT) debugPrint("L");
   if (g_Pads[1].PressedButtons.usDigitalButtons&XPAD_LEFT_THUMB) debugPrint("LS");
   if (g_Pads[1].PressedButtons.usDigitalButtons&XPAD_RIGHT_THUMB) debugPrint("RS");
   if (g_Pads[1].PressedButtons.usDigitalButtons&XPAD_START) debugPrint("S");
   if (g_Pads[1].PressedButtons.usDigitalButtons&XPAD_BACK) debugPrint("B");

}

Logged

openxdkman

  • Archived User
  • Hero Member
  • *
  • Posts: 550
Openxdk Nes Emulator
« Reply #2 on: March 12, 2007, 02:52:00 AM »

You should also replace

   if(g_Pads[0].PressedButtons.usDigitalButtons&XPAD_START)
   {
    mp[0x823].uns = 0;                                                  
   }

with

   if(g_Pads[0].PressedButtons.usDigitalButtons&XPAD_START)
   {
     mp[0x823].uns = 1;
     SDL_Delay(10);                                                  
     mp[0x823].uns = 0;
   }

It helps detecting stuff! But it implies that nes engines runs in a parallel thread I guess... I let you continue the happy debugging...
Logged

openxdkman

  • Archived User
  • Hero Member
  • *
  • Posts: 550
Openxdk Nes Emulator
« Reply #3 on: March 12, 2007, 03:14:00 AM »

It helps detecting stuff! But it implies that nes engines runs in a parallel thread I guess... Which is not the case...

So use this for now, for testing :
   if(g_Pads[0].PressedButtons.usDigitalButtons&XPAD_START)
     mp[0x823].uns = 1;
   else
     ...some mechanism able to turn back value to 0 after some time...

Also it's a bit fishy how this function pad_proc() is not called at all for long moments in some nes roms... I guess you have work to do to debug that...

If the slow speed comes from graphics just poke pixels at XVideoGetFB() address directly.

You will obtain a 320x200 small image in the 640x480 frame buffer, then, much later if you want, you can use pbKit to do a texture mapping from 320x200 to 640x480 with optional antialiasing and double scaling (see q*bert demo).
Logged

Aman_oh_ya

  • Archived User
  • Newbie
  • *
  • Posts: 4
Openxdk Nes Emulator
« Reply #4 on: March 12, 2007, 02:08:00 PM »

Thanx openxdkman for the help. Currently I think ill make it simple and put something like this:

mp[0x820].uns =  g_Pads[1].PressedButtons.ucAnalogButtons[XPAD_A];
Logged

Aman_oh_ya

  • Archived User
  • Newbie
  • *
  • Posts: 4
Openxdk Nes Emulator
« Reply #5 on: March 12, 2007, 07:13:00 PM »

Just a quick question: You said I was using the old OpenXDK do you mean the ones before 0.07 or the newest CVS release? Because right now Im building the CVS relase right now. And BTW I cant believe I didnt notice how I set the video mode twice
Logged

openxdkman

  • Archived User
  • Hero Member
  • *
  • Posts: 550
Openxdk Nes Emulator
« Reply #6 on: March 13, 2007, 03:09:00 AM »

Maybe it's my version that is older than yours then

Anyway it's because asking 320x200 leads to unpredictable result for HDTV and VGA_SOG users
Logged

openxdkman

  • Archived User
  • Hero Member
  • *
  • Posts: 550
Openxdk Nes Emulator
« Reply #7 on: March 16, 2007, 05:17:00 AM »

You may consider this also
mp[0x820].uns = g_Pads[1].CurrentButtons.ucAnalogButtons[XPAD_A];

it's the only way to detect current state of button (rather than just the transition unpressed=>pressed)
Logged