Date : Wed, 17 Mar 2004 16:24:22 +0000
From : Richard Gellman <splodge@...>
Subject: Re: Behaviour of 6502 opcode 9C
Richard_Talbot-Watkins@... wrote:
>Hi,
>
>Just wondered if anyone has ever checked the exact behaviour of opcode 9C
>on a real BBC B. It's one of the unspecified 6502 opcodes, but there seems
>to be division on what it actually does.
>
>Some Beeb-related docs describe it as STZ abs, meaning ?abs = 0, just like
>its 65C12 equivalent.
>
>Most other docs describe it as SAY abs,X, meaning ?(abs+X) = Y AND ((abs
>DIV 256) + 1), which is rather less useful.
>
>
In my quest to implement all undocumented opcodes in BeebEm, I happened
across opcode &9C. Prior to my fiddling, it was unemulated. There is now
source code comments around the instruction decode for &9C, saying that
it is invalid on the 6502, but valid on the 65C12, with the result being
the same in either, that is, STZ abs.
Almost every document I've come across detailing &9C concurs that it is
STZ abs, and experiments with a real beeb confirm this. The other 65C12
STZ instructions however, are not available likewies on the 6502 (there
are LDA-TXA style dual-instruction opcodes there instead).
It's quite likely that both are true, just to annoy us. If you consider
how permutations of Y AND ((abs DIV 256)+1) yield 0, then whats probable
is that the latter is being executed, but has the effect of the former.
Although this would require that X = 0, and Y = (((abs DIV 256)+1) EOR
255) AND n, where n is anything between 0 and 255.
CPUs are weird.
-- Richard Gellman