0xCB Instructions and Timer/Interruptions

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

0xCB Instructions and Timer/Interruptions

Post by zerowalker »

Hi,

I can't seem to find information regarding how 0xCB instructions are handled by the CPU when it comes to the Timer and Interruptions.
Meaning, is the 0xCB read as an instruction and then handles things etc, then it reads then ext instruction from the 0xCB table.

Or is 0xCB read and immediately afterwards the next byte is read, ignoring everything else until the entire instruction is complete?
AWJ
Posts: 433
Joined: Mon Nov 10, 2008 3:09 pm

Re: 0xCB Instructions and Timer/Interruptions

Post by AWJ »

zerowalker wrote:Hi,

I can't seem to find information regarding how 0xCB instructions are handled by the CPU when it comes to the Timer and Interruptions.
Meaning, is the 0xCB read as an instruction and then handles things etc, then it reads then ext instruction from the 0xCB table.

Or is 0xCB read and immediately afterwards the next byte is read, ignoring everything else until the entire instruction is complete?
Interrupts can't occur between the 0xCB prefix and the second byte. How would the CPU recover if they did? Think of the second byte as a special kind of operand, not as a separate instruction.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: 0xCB Instructions and Timer/Interruptions

Post by tepples »

AWJ wrote:Interrupts can't occur between the 0xCB prefix and the second byte. How would the CPU recover if they did?
By storing the "0xCB occurred" bit in the status flags, like the HuC6280 does with prefix 0xF4.
User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: 0xCB Instructions and Timer/Interruptions

Post by Myask »

zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

Re: 0xCB Instructions and Timer/Interruptions

Post by zerowalker »

A bit confused, don't really understand the relevant post (apparently a bit too low level for my understanding of these things i guess).

But as far as i know, there is no "0xCB" flag, at least not a visible one, which of course doesn't mean it doesn't exist at all.

So, is there a way to determine these things?

I assume in this case it's always read as a 2 byte instructions directly more ore less,
but as it was mentioned there is a case with a status flag, it means this isn't a rule for these kind of things.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: 0xCB Instructions and Timer/Interruptions

Post by tepples »

As far as I can tell:

0xCB on Z80 is atomic; there can be no interrupt between it and the instruction it modifies.
Prefixes on x86 are likewise atomic, and some instructions have enough prefixes to fill 15 bytes.
0xF4 on HuC6280, by contrast, is not atomic, instead setting an ephemeral status flag. I mentioned it as a contrast to the 8080-family way of doing prefixes.
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

Re: 0xCB Instructions and Timer/Interruptions

Post by zerowalker »

Ah, seen the word atomic used a alot and never been too clear on the meaning, except it seems to mean "close/directly by by the cpu" or something.

So that's basically what it is then, and atomic operation is completed by the CPU without any interference from whatever could interfere more or less?

And so there is basically no x86 non-atomic prefixes?
If so that's nice, makes things more simple:p
User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: 0xCB Instructions and Timer/Interruptions

Post by Myask »

and atomic operation is completed by the CPU without any interference from whatever could interfere more or less?
Yes.
close/directly by
No. Some etymology should help…
wiktionary wrote:atom
From Middle French athome, from Latin atomus (“smallest particle”), from Ancient Greek ἄτομος (átomos, “indivisible”), from ἀ- (a-, “not”) +‎ τέμνω (témnō, “I cut”).

atomic
Adjective
[…]
5. (computing) Of an operation: guaranteed to complete either fully or not at all while waiting in a pause, and running synchronously when called by multiple asynchronous threads.
Indivisible. Uninterruptible.
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

Re: 0xCB Instructions and Timer/Interruptions

Post by zerowalker »

Ah thanks that clear things up, appreciated:)
Post Reply