me again with and nmi question

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
me again with and nmi question
by on (#90572)
Im emulating instruction per instruction:

Wich are the opcodes that can affect a bad nmi timming?

Is there any way to get good nmi timming emulating the way i do?


I think is a big question, but please help!!

thx
Re: me again with and nmi question
by on (#90579)
Anes wrote:
I think is a big question, but please help!!

Too big, yes. Perhaps if you were having trouble with a particular test rom giving you a particular error?

by on (#90581)
yeah that's a bit of a vague question, but my answer would be all of them. since NMI/vblank timing is based on how many CPU ticks are in one frame, and you can run any opcodes you want during the course of that frame, any of 'em could be the problem. maybe your opcode timings are not the problem at all, but to check that out try blargg's instruction timing test ROMs.

http://blargg.parodius.com/nes-tests/instr_timing.zip

the only caveat of those tests is that they require an accurately working APU frame sequencer.
Re: me again with and nmi question
by on (#90582)
cpow wrote:
Anes wrote:
I think is a big question, but please help!!

Too big, yes. Perhaps if you were having trouble with a particular test rom giving you a particular error?


Im having problem with nmi_suppression test it trows me error #3,

anyway i think i coudn't solve it the way i emulating my ppu, my vblank rutine is as:

Code:
while ( Ppu.scanline >= 241 && Ppu.scanline <= 260 )
{
   while( Ppu.scanline_cycle < 341)
   {

   if (Ppu.scanline == 241 && Ppu.scanline_cycle == 0)
   {
   if (Ppu.cant_setvblank == 0)
   Ppu.on_vblank = 0x80;

   if (Ppu.on_vblank && Ppu.nmi_onvblank)
                SetNmiPending(1);
   }
      
   Ppu.scanline_cycle++;
   Ppu.ppu_timestamp += 1;

      if( Ppu.ppu_timestamp >= runto)
      return;
                }

   Ppu.scanline_cycle = 0;
   Ppu.scanline++;
                }

Ppu.cant_setvblank = 0;
Ppu.scanline = -1;
Ppu.ppu_timestamp -= 262 * 341;


This is the end of the frame on my runppu().
How i threah vblank and i think is a mess. No i don't think it. IT IS A MESS, but i cannot find a better way!.

Note: cant_setvblank is only for detecting error #8 on vblank basic test. Its set just when $2002 vblank is going to trigger.

by on (#90583)
miker00lz wrote:
yeah that's a bit of a vague question, but my answer would be all of them. since NMI/vblank timing is based on how many CPU ticks are in one frame, and you can run any opcodes you want during the course of that frame, any of 'em could be the problem. maybe your opcode timings are not the problem at all, but to check that out try blargg's instruction timing test ROMs.

http://blargg.parodius.com/nes-tests/instr_timing.zip

the only caveat of those tests is that they require an accurately working APU frame sequencer.


I have tested instr_timing version 3 and all giving a passing result

by on (#90589)
Quick answer: create a log of your CPU running the test ROM, including an indication of when $2002 is read and the VBlank flag is set by the PPU. This way, you will see exactly What's Going On. :)

Well, that's how I solved my problem.

by on (#90610)
I solved NMI SUPPRESSION, but it was a hack.
All test pass now exect NMI timming throwing me error #2. What a pain in the a*s!!

by on (#90612)
it gets worse from here. :)

by on (#90614)
miker00lz wrote:
it gets worse from here. :)


you don't say ... :cry:

by on (#90615)
so, does your emulator run any kind of games yet or have you not gotten to that yet? if something is preventing games from running feel free to upload all of the code, and maybe i can point out the issue to get you over this hurdle.

by on (#90616)
miker00lz wrote:
so, does your emulator run any kind of games yet or have you not gotten to that yet? if something is preventing games from running feel free to upload all of the code, and maybe i can point out the issue to get you over this hurdle.


Yes it run many.
It emulates mapper 0, UNROM, CNROM, MMC1, MMC3 and AOROM.

It runs and overall of 90% games (of course, the one that uses this mappers)

MMC3 emulation is crapy, but it works for most games.
Sprite emulation is not good too. i never understood wiki explication about sprites.

It emulates sound a little crapy too, but it sounds.

The code isn't commented at all, and it is disorganized.
If you HAVE THE WILL to review this code :oops: i'll preciate it.

by on (#90619)
my MMC3 emulation is crappy too, i've got something strange going on with my IRQ countdown stuff. it worked well in the original incarnation of my emulator. everything in my new one is 100x better than the old except that part.

if you've got your emu that far along there probably isn't all that much i can help with, but i definitely wouldn't mind having a look at all. i was assuming you weren't able to get games working. many of the other guys here are much sharper with the NES stuff than i am, but i am learning. i've been doing this for a year and a half, some nesdev guys have been doing this since the 90's.

feel free to peek at my code too, but just don't take it as gospel. it's not by any means perfect. it has very few comments by i tried hard to organize it well.

by on (#90620)
miker00lz wrote:
my MMC3 emulation is crappy too, i've got something strange going on with my IRQ countdown stuff. it worked well in the original incarnation of my emulator. everything in my new one is 100x better than the old except that part.

if you've got your emu that far along there probably isn't all that much i can help with, but i definitely wouldn't mind having a look at all. i was assuming you weren't able to get games working. many of the other guys here are much sharper with the NES stuff than i am, but i am learning. i've been doing this for a year and a half, some nesdev guys have been doing this since the 90's.

feel free to peek at my code too, but just don't take it as gospel. it's not by any means perfect. it has very few comments by i tried hard to organize it well.


Ok thanks for the link i'll take a look to it. Take a look at your PM.

by on (#90621)
Anes wrote:
miker00lz wrote:
my MMC3 emulation is crappy too, i've got something strange going on with my IRQ countdown stuff. it worked well in the original incarnation of my emulator. everything in my new one is 100x better than the old except that part.

if you've got your emu that far along there probably isn't all that much i can help with, but i definitely wouldn't mind having a look at all. i was assuming you weren't able to get games working. many of the other guys here are much sharper with the NES stuff than i am, but i am learning. i've been doing this for a year and a half, some nesdev guys have been doing this since the 90's.

feel free to peek at my code too, but just don't take it as gospel. it's not by any means perfect. it has very few comments by i tried hard to organize it well.


Ok thanks for the link i'll take a look to it. Take a look at your PM.


Anyway as you say there are a lot of people since the 90.
I started the emu when i registered. I discountiued it a couple of times.
But things have changed since i registered. There was not test roms, info changed and a lot of things.

Anyway i think is a project i can't handle to much. Im saying maybe im not too good at emulating!! :(

by on (#90663)
Anes wrote:
I solved NMI SUPPRESSION, but it was a hack.
All test pass now exect NMI timming throwing me error #2. What a pain in the a*s!!


I had to clock the PPU/APU *before* the CPU clock.

by on (#90664)
Zepper wrote:
Anes wrote:
I solved NMI SUPPRESSION, but it was a hack.
All test pass now exect NMI timming throwing me error #2. What a pain in the a*s!!


I had to clock the PPU/APU *before* the CPU clock.


But isn't supposed that you run a CPU clock and then run the PPU.
If i clock the ppu first, how many clocks am i going to clock.
Maybe having read the cpu opcode cycle first clock the PPU and then finish the instruction?

by on (#90667)
Anes wrote:
But isn't supposed that you run a CPU clock and then run the PPU.


That's what I though... but no, you clock the PPU/APU firstly.

Quote:
If i clock the ppu first, how many clocks am i going to clock.
Maybe having read the cpu opcode cycle first clock the PPU and then finish the instruction?


Uh... you clock the PPU, then fetch the opcode. Each memory fetch/write will clock the PPU firstly.

by on (#90670)
Zepper wrote:
Anes wrote:
But isn't supposed that you run a CPU clock and then run the PPU.


That's what I though... but no, you clock the PPU/APU firstly.

Quote:
If i clock the ppu first, how many clocks am i going to clock.
Maybe having read the cpu opcode cycle first clock the PPU and then finish the instruction?


Uh... you clock the PPU, then fetch the opcode. Each memory fetch/write will clock the PPU firstly.


Outstanding!! i didn't know and thats the way it goes.
It throws me cpu timming errors now, but i think its not too difficult to solve (altough they are unknown errors) i think i'll solve it.
I know you are from Brazil and you have the same GMT than me, but i haven't slept trying to solve this problem.
Now im going to sleep for some hours with a :D on my face.
This night and tomorrow will be a hard coding and debugging day.

Thanks Zepper!!