Date : Fri, 05 Jun 2009 23:57:33 +0200
From : rick@... (Rick Murray)
Subject: 65C02 instructions
I have a few questions about the 65C02 for helping with my FileStore
emulator.
1. Zero Page Relative addressing
"This new CMOS addressing mode tests the zero page
location specified for bit set/clear and then takes the
relative branch accordingly."
Is it correct to assume the second byte of the instruction is the page
zero location, and the third byte is the branch offset? I guess this
because it'll want to check PZ before worrying about the branch.
2. Would the code for the TRB instruction look like this:
CPU.A = (CPU.A Xor &HFF) And CPU.Temp
Memory_Write CPU.A, CPU.Addr
CPU.PS.Z = ((CPU.A And CPU.Addr) = 0)
[just tell yourself it's a sort-of BASIC <g>]
3. Likewise, TSB:
CPU.A = CPU.A Or CPU.Temp
Memory_Write CPU.A, CPU.Addr
CPU.PS.Z = (CPU.A = 0)
I pretty much guessed TRB and TSB from the rather rudimentary Rockwell
datasheet and playing around with a 6502 simulator.
I guess I ought to point out - execution of an instruction works in two
parts. The first part, after the instruction has been read, is called
the "PreFetch" (because it fetches data before the instruction is
actually executed). Here, the addressing mode is sorted out, any
relevant address in loaded into CPU.Addr and if there is data to be
read, it is read into CPU.Temp.
Then the instruction is executed. Using this method, we can do all of
the ADCs and all of the EORs and so on using the same code.
There are, of course, a number of 'kludges' to disable this behaviour in
undesired circumstances. For example, without kludge, WRITING to the
FileStore's misc functions latch to turn on the MODE LED would cause a
'hidden' READ of that memory location. Which, in turn, would fire off
the EPROM/RAM selection latch and, well...
Anyway, all the sources are at
http://www.heyrick.co.uk/econet/fs/emulator.html should you fancy a
peek. I'd REALLY appreciate somebody more au fait with the inner
workings of the 6502 to give it a look, make sure I've not done anything
truly stupid. :-)
Best wishes,
Rick.