It is currently Mon Dec 11, 2017 8:32 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Nov 13, 2010 3:34 am 
Offline

Joined: Sat Nov 13, 2010 3:00 am
Posts: 1
Hi,

I'm not sure how the Gameboy CPU handles interrupts exactly yet. Two questions:

How many cycles are needed to handle an interrupt? What I mean is, when an interrupt occurs, how many cycles pass between completion of the last instruction and fetching of the interrupt handler's first opcode?

Some emulator code suggests that this happens immediately, but that seems highly unlikely. The CPU needs to at least push the return address on the stack, which is one memory access minimum.

The second question is more subtle: Some documentation says "interrupts are acknowledged during the opcode fetch phase". Does that mean that
  1. the CPU checks for interrupts before it would fetch the next opcode, and if an interrupt occurred, it injects the call to the interrupt instead, or
  2. the CPU already fetched the next instruction (i.e. has performed the read from memory) but discards the opcode, and injects the call to the interrupt?

I have seen emulators handling interrupts after emulating the last instruction. If done right, this should be functionally equivalent to a). It's also cleaner, so I tend to lean towards a), but emulators are seldom perfect (as seen above).

Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 13, 2010 12:31 pm 
Offline
User avatar

Joined: Wed Dec 06, 2006 8:18 pm
Posts: 2806
The source to Gambatte probably has it correct. I would guess that interrupts are handled before the next Opcode is fetched. Then as you say, some cycles are used to push the PC onto the stack and then fetch the vector from the interrupt table to load into the PC. But I can't tell you the exact timing. Gambatte's source should. It's supposed to be a GB emulator aimed at very high hardware accuracy. Ofcourse most software probably isn't going to rely on super precise timing. You have to have your timing EXTREMELY bad to cause problems with most games. I did this in my GB emulator at first where I didn't have CPU Cycles/Master Cycles/PPU Cycles figured out. So basically games had something like 1/3rd of expected CPU time and would crash and do all sorts of things that drove me crazy till I realized it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group