Emulation speed vs actual NES speed (solved)

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

wendelscardua
Posts: 7
Joined: Tue Jun 09, 2020 5:55 pm

Re: Emulation speed vs actual NES speed

Post by wendelscardua » Sun Jun 28, 2020 1:07 pm

Controllerhead wrote:
Sat Jun 27, 2020 2:53 pm
Hmm i see. It does indeed hang at that Minesweeper part. It doesn't look like JSNES has any debug functions that i can tell or know about; but, since its in Javascript, it is possible to run the Chrome step through debugger and see how the emulator is executing step by step. I'm not sure how far you've looked into this, but i would set a button trigger in your NES ASM code to trigger the minesweeper game start instead of a timer, trigger it in JSNES and a diffrent emulator while each is paused, and compare step by step how each instruction is being interpreted in CPU.js against how the successful emulator is doing it, if you haven't tried that already.
Last time I tried to debug this issue, I got the Program Counter register from the browser console, which led me to a vblank waiting loop:

Code: Select all

vblankwait:
  BIT PPUSTATUS
  BPL vblankwait
Which was used in minesweeper mine finder at the point where tiles are written to PPU. I know it's not the best way to do it - in fact I changed it to

Code: Select all

vblankwait:
  LDA nmis
  CMP old_nmis
  BEQ vblankwait
just now and it worked. What I couldn't figure out was why the bad loop works everywhere, except on JSNES. As it isn't that much of a problem I left it as an open issue on jsnes github; maybe I'll try more later...

User avatar
Controllerhead
Posts: 172
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Emulation speed vs actual NES speed

Post by Controllerhead » Sun Jun 28, 2020 2:37 pm

wendelscardua wrote:
Sun Jun 28, 2020 1:07 pm
Last time I tried to debug this issue, I got the Program Counter register from the browser console
Yeah i was playing with JSNES yesterday out of curiousity, i got it to build with Yarn and a bunch of NPM / Node JS dependencies. I did realise there are some console trace functions like NES.getFPS() in JS prototype form and you can reference the variables where the registers are held, but i only found this after combing through the source code for a while. JSNES has no GUI, sparse comments in the source code, and there is zero documentation in the github repo, or anywhere for that matter that i know of. It's kind of built to just embed in a webpage and play some American NTSC games, from what i can tell.

Code: Select all

  BIT PPUSTATUS
  BPL vblankwait
Hmm... i suppose if you had a zero in bit 7 of the accumulator before running this sometimes, it could cause your code to spin forever intermittently. Or, if reading PPUSTATUS $2002 was somehow syncronized within the first 2 cycles after the VBlank trigger every frame causing the PPUSTATUS to return 0 in bit 7 and also clear every frame, that could spin forever too. Perhaps JSNES doesn't quite handle the VBlank trigger or NMI correcty. I don't know... i don't know your codepath, i dont know if JSNES has some "tricks" to handle certain games that don't exactly replicate NTSC NES behavior, and i'm just throwing out some guesses here. I don't know whats exactly going on behind the scenes of JSNES or how accurate it is to the hardware, but it seems to run ok with most American NTSC games i have thrown at it, even fancier MMC3 ones with scrolling tricks...

Anyway, i'm done rambling, and i'm glad you got it working!
Image

Post Reply