Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2015-11-02 17:12:22

LIJI
New member
Registered: 2014-09-09
Posts: 9

Weird instruction timing – what am I missing?

Hey,

I'm trying to fix some timing issues in an emulator I'm working on so it can pass Blargg's instruction timing test.

The timer is configured to increase TIMA every 16 ticks, i.e. it's increased by 1 after running 4 nops.

Considering this code from the test:

Code:

start_timer:
     push af
     
-    xor  a         ; 1
     sta  TIMA      ; 3
     lda  TIMA      ; 3
     or   a         ; 1
     jr   nz,-      ; 3
     
     pop  af
     ret

In the final loop, in my emulator, TIMA increases after executing the JR, but in BGB, which passes this test, it doesn't.

Now, what actually happens in BGB in the last iteration is this; after executing the XOR, TIMA is increased, which means TIMA, as a fraction is now X.00.

Then STA and LDA should increase the "fractional TIMA" to 0.75 and 1.5 respectively, and reading TIMA from the debugger confirms TIMA is 0 and 1 at these points. OR should increase TIMA to 1.75, and it is indeed still 1 in BGB after executing. So at this point the next instruction should increase TIMA to 2 – but that does not happen in BGB.

Generally, I often see delayed TIMA increases in BGB, specifically after executing relatively long instructions.

Can someone please explain what's going on? I'm really confused. sad

Offline

 

#2 2015-11-02 19:47:51

LIJI
New member
Registered: 2014-09-09
Posts: 9

Re: Weird instruction timing – what am I missing?

Ok I found the problem – seems like BGB's TIMA emulation isn't as accurate as I thought; while it generally "counts" precisely, sometimes the increments are lagging.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson