<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Mon, 18 Jul 1994 17:43:44 +0100
From   : jfid@... (James Fidell)
Subject: Re: Steve's emulators.

Chris Rae wrote:

> > I don't know if anyone is following some of the things I have been
> > writing, but I am working on 2 emulators and am starting a third.
> > Why?  Because they have completely different design architectures,
> > and I particularly like my 2nd emulator's internal design, which
> > holds my secret [now to be reveal] of *not* storing the Status
> > Register anywhere!
> 
> Quite a nice trick - could be some hefty code though! I still prefer my 
> method (which unfortunately you C-programmers can't do! ;-) of using PC 
> flags for bits C and Z of the status register... that's really the only 
> reason mine is faster (by about 20% or something) than SQs. Is there any 
> chance of James testing his on a 386-40 so we can compare notes?

The idea of implementing the 6502 CPU as (what is pretty much just a)
finite state machine is mind-numbing when you take it to it's logical
conclusion.

Imagine having an FSM with states for every possible combination of
register values (let's ignore for the moment the values of the PC, SP
and memory).  This would give a huge number of possible states.  Even
optimising some of these would result in a massive, but potentially
pretty quick, piece of software.

Which James do you mean ?  If it's me, I'm afraid I can't help at the
moment, because I don't know anyone with such a machine.  I'm cleaning
the code up at the moment so that it's suitable for a pre-alpha release.
Maybe someone will be able to test it then.

> I have a bit of a problem which I think I could really speed up - how
> I can do relative branches?

If you treat the distance value as an unsigned char, you should be
able to just add it to the current value of the PC.  My read-byte-from-
memory routines all read unsigned values, so I've got a bit of code
that reads :


    unsigned int        old;
    union {
        unsigned char   u;
        signed char     s;
    } offset;

    /*
     * First the branch is read as it's unsigned value, then
     * converted to it's signed bitwise equivalent for adding
     * to the PC.
     *
     */

    old = ProgramCounter & 0xff00;
    offset.u = ReadByteAtPC();
    ProgramCounter += offset.s;

    /*
     * Now the odd clock cycles...
     */

    AddClockCycles ( 1 + ( old == ( ProgramCounter & 0xff00 )) ? 0 : 2 );


This probably isn't the most efficient solution, but it does avoid
any nasty sign-extension problems when trying to cast an unsigned char
to a signed one.

I'll do a little research to see what ANSI says about sign extension
when casting between unsigned and signed versions of the same types
when I'm back in the UK.

James.

-- 
 "Yield to temptation --             |
  it may not pass your way again"    |     jfid@...        
                                     |
        - Lazarus Long               |              James Fidell
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>