[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ARM and 6502



Rubywand <rubywand@swbell.net> wrote:

>     It sounds like you are saying 6502 code could be 'broadside loaded'
>so to speak. For example, a code sequence like A9 77 85 FF might arrive
>in a single 32-bit read. And, since you would want byte addressability,
>all memory reference commands would automatically parse out as
>references to one of four bytes in a 32-bit word.

>     If the above works, you would gain speed on the instruction and
>data load side of the simulation and lose speed on mem writes (since you
>would always have to do a mem read first).  Is this how the simulation
>would work? 

You do in fact broadside the memory in byte fetches, but invisibly. The ARM can
only address on 4 byte boundaries (what C calls long words) but it has a barrel
shifter that shifts any amount in a single instruction. So, an off boundary
read of a byte is really a read of a long word with the byte of interst shifted
into position automatically and 0's everywhere else. But really, I lie, I think
I recall there is a byte/word signal from the chip that can be used in memory
address decoding and chip select so it will really do bytes.

Simple interpreter: 

1) Assume that no 6502 instruction takes more than 16 ARM instructions to
emulate (more like 8 max, but I havn't tried everything yet).
2) Make a table of emulation routines for all the 65C02 instructions and start
each routine on a 16 word boundary.
3) Initialize a few pointers to the 6502 code and the emulation stack, etc.
Assign some of the 14 available ARM registers to be A, X, Y, S, R.
4) Fetch a 65C02 instruction and multiply it by 64 (shift left by 6). Add
result to base of table of routines and JSR. (Actually on the ARM you branch
with link) None of the routines will call other routines so the return address
is kept in the Link register (14) and to return you just mov link to PC.
5) The instruction emulation routines are short because ARM instructions can do
things like fetch a value offset by the contents of a register and shifted any
amount and auto-increment a pointer all in one instruction. So LDA (ZP),X is
something like get the two byte pointer from Zpage into a register and load the
A register offset by the X register, etc.

More later.

Charlie Springer