Gameboy timer question

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
epsilon_j
Posts: 1
Joined: Tue Apr 07, 2020 4:24 pm

Gameboy timer question

Post by epsilon_j » Wed Apr 08, 2020 12:20 am

Hello all,

I am just getting into GB emulation and this is my first post here :-). I have a question regarding the way the TIMA timer (FF05) works.

I am debugging in bgb and have set the value of the TAC register to 0xFD (1111 1101), which means that:

- Bit 2 = 1, so timer started;
- Bits 1-0 = 01, so timer frequency = 262144 Hz.

Therefore I believe that TIMA should increment once every 4 machine cycles (machine clock runs at 1048576 Hz).

However, I am stepping through the BIOS code, and I have it sat in the VRAM-zeroing loop at the beginning:

0x0007 – LD (HL-), A
0x0008 – BIT 7, H
0x000A – JRNZ .+0xfb

My understanding is that the LD and BIT ops should each take 2 M cycles, whilst the JRNZ op should take 3 M cycles (since it is looping back to 0x0007). Is this correct?

I am observing that I can execute both the LD and BIT ops, but sometimes TIMA does not increment at all. I would expect it to always increment after one or the other, since 4 M cycles should definitely have elapsed? Or am I misunderstanding something?

Thanks in advance!

Post Reply