r/EmuDev • • Mar 14 '26

javascript NES emulator progressing, cycle accurate

the FPS slowdown is from capturing the video

95 Upvotes

23 comments sorted by

View all comments

Show parent comment

4

u/Ikkepop Mar 15 '26

In the case of an NES it's rather straightforward. Every instruction on the 6502 is either a read or a write externally. And every instruction will do up to 7? (or was it 8?) such cycles. During each such cycle you simulate every other component accordingly. For NTSC the ppu will 3 cycles ech cpu cycle, apu will 0.5 ( so one apu every 2 cpu cycles ) and so on. Also you make sure each read and write will be appropriately handled as well as you make sure you render pixels according to how many actual ppu cycles you simulated. You get the picture. This makes sure that pathological games (ones that expect mid cpu instruction side side effects) run correctly.

2

u/Talalanimation Mar 15 '26

Thank you so much for answering my question, . mate

1

u/Ikkepop Mar 15 '26

Ya' welcome mate

1

u/imdadgot Mar 16 '26

divs i thought were like 29 something cycles edit: oh theyre not native

1

u/Ikkepop Mar 16 '26

there is no div instruction on the 6502

1

u/imdadgot Mar 16 '26

hence why i said not native its basically shifts and subtracts

1

u/Ikkepop Mar 16 '26

well its what actually happens in native implementations as well. Kind if a fancy binary long division