What's new

Emulator timing & debugging

Doomulation

?????????????????????????
Ok, so I have two more questions:
How do you usually emulate timing in an emulator? I mean, what's the general principle so I can understand how it's done. Usually, the documentations only says like "using processor type X running at Y Mhz" which isn't very much info if you don't know anything...

Oh and how to you usually debug emulators? How do you know what opcode is at error and how to you fix it usually? Do you guess until you find the right one? Do you guess the right produced value or something?
 

aprentice

Moderator
Doomulation said:
Ok, so I have two more questions:
How do you usually emulate timing in an emulator? I mean, what's the general principle so I can understand how it's done. Usually, the documentations only says like "using processor type X running at Y Mhz" which isn't very much info if you don't know anything...

Oh and how to you usually debug emulators? How do you know what opcode is at error and how to you fix it usually? Do you guess until you find the right one? Do you guess the right produced value or something?

1) Depends on the console, i know at least with the nes and gameboy the clockticks are included in the cpu document for each opcode.

2) You build a debugger that shows the content of each register (variable) and you trace the code. If for example LDA #40 doesnt load "40" into the accumulator variable, then that particular opcode is at error.
 

Cyberman

Moderator
Moderator
Doomulation said:
Ok, so I have two more questions:
How do you usually emulate timing in an emulator? I mean, what's the general principle so I can understand how it's done. Usually, the documentations only says like "using processor type X running at Y Mhz" which isn't very much info if you don't know anything...

Oh and how to you usually debug emulators? How do you know what opcode is at error and how to you fix it usually? Do you guess until you find the right one? Do you guess the right produced value or something?
Well I recomend taking this approach.

What do you have? In most cases you have a processor that has a fixed set of execution times for one instruction. The same goes with other components in the emulator. Most emulators sync to a base factor, for example SNES syncs to the vertical sync, and suspends activity until a vsync event ocures. In retro spect this is why sometimes ePSXe hangs the GPU recieves an instruction and never returns from executing it (had that happen a few times with Arc The Lad 1).

For debuging and fixing I recomend commenting EVERYTHING, what it does what the results should be etc. Then you step through watching if something is behaving unexpectedly and oft that's your problem see all the questions reguarding N64 emulation and graphics here.. notice a trend? Ask questions of yourself like 'what is it supposed to do here?'

As for guessing if you have to do that yes, but if you aren't sure what it is, maybe you need to do more research instead.

Cyb
 
OP
Doomulation

Doomulation

?????????????????????????
aprentice said:
1) Depends on the console, i know at least with the nes and gameboy the clockticks are included in the cpu document for each opcode.

2) You build a debugger that shows the content of each register (variable) and you trace the code. If for example LDA #40 doesnt load "40" into the accumulator variable, then that particular opcode is at error.
1) How is it possible to make sure I'm staying at the correct number of cycles? I mean, there's no possible way to determine the number of clock cycles the processor has done. As I was looking at a source of a wonderswan emulator, it was using some kindof strange emulating by using timeGetTime to check how many ms passed since last check...multiplying it by 755 and so on...I don't get HOW that works.

Well I recomend taking this approach.

What do you have? In most cases you have a processor that has a fixed set of execution times for one instruction. The same goes with other components in the emulator. Most emulators sync to a base factor, for example SNES syncs to the vertical sync, and suspends activity until a vsync event ocures. In retro spect this is why sometimes ePSXe hangs the GPU recieves an instruction and never returns from executing it (had that happen a few times with Arc The Lad 1).
I was looking at a wonderswan emulator with a processor running at approximetlty 3.something MHz. The documentation describes diffrent interrupts, among them vsync. However, afaik, no information (and according to the source) tells that it waits for interrupts.

For debuging and fixing I recomend commenting EVERYTHING, what it does what the results should be etc. Then you step through watching if something is behaving unexpectedly and oft that's your problem see all the questions reguarding N64 emulation and graphics here.. notice a trend? Ask questions of yourself like 'what is it supposed to do here?'

As for guessing if you have to do that yes, but if you aren't sure what it is, maybe you need to do more research instead.

Cyb
That sounds kinda hard, heh. Especially like math opcodes. But then I suppose that if a math opcode is wrong, then lots of information would be misplaced. Let me see what I can for that :)
 

Top