Welcome to Emulationworld

Forum Index | FAQ | New User | Login | Search

Make a New PostPrevious ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectAmiga 500 --> PC new Reply to this message
Posted byamilator
Posted on09/17/05 09:05 AM



Hi, I've just started coding what is ment to be an emulator of the Amiga 500 in C, advice needed.

The first thing I've wondered about is this: the mc 68000 reads/writes words/longwords "normal" as opposed to the x86 (in the PC I'm trying to code an emulator for) that swaps the cointained bytes (LO-to-HI).

what is the easiest way to deal with this ? I've got somwhat confused for the past ours to be honest.

note: I've never coded an emulator before, I've been programming on and off since I was 13 (29 now) but never finished anything serious, which however doesent mean I'd be terrified from the project I've decided to do :)




SubjectRe: Amiga 500 --> PC new Reply to this message
Posted byBart T.
Posted on09/18/05 01:46 PM



> Hi, I've just started coding what is ment to be an emulator of the Amiga 500 in
> C, advice needed.
>
> The first thing I've wondered about is this: the mc 68000 reads/writes
> words/longwords "normal" as opposed to the x86 (in the PC I'm trying to code an
> emulator for) that swaps the cointained bytes (LO-to-HI).
>
> what is the easiest way to deal with this ? I've got somwhat confused for the
> past ours to be honest.

There are a few ways to deal with this depending on which version of the 68K you have to emulate. If dealing with the 68000 or 68010, you can actually byteswap every 16-bit word in your emulated memory spaces and then use normal loads/stores on X86. This is platform-specific of course. To access bytes, you'll have to XOR the address with 1 to get at the right part.

For the 68020 and higher, this won't work because the processor can perform unaligned memory access and you have to either use a really tricky backwards memory scheme or simply byteswap everything after you've read it from memory.

This works for the 68000 and any processor: just shift the bytes around using standard C bit shift and logical AND/OR operators.



SubjectRe: Amiga 500 --> PC new Reply to this message
Posted bysmf
Posted on09/21/05 03:25 AM



The usual way for 68000 is as you say to store unsigned shorts in x86 format and xor the address with 1 when reading bytes.

For the 68020 the process is the same but store unsigned longs and xor address with 2 when reading words and with 3 when reading bytes.

Unaligned reads aren't that hard, there are only three cases. You just do two reads and shift each value, like the real chip does. In terms of emulating an Amiga, that is easy.

smf



SubjectRe: Amiga 500 --> PC new Reply to this message
Posted byamilator
Posted on09/22/05 08:22 AM



Thank you for the reply.

After playing some with type casting and the logical operation OR, below is what I'm doing right now.

I have this function 'UWORD GetOpcode(address)' that reads from mem_chip[] (or mem_slow[] or mem_rom[]) like this: 'word = (UWORD) (mem_chip[address] << 8) | (UWORD) mem_chip[address+1];

note: the memory arrays I'm using are supposed to always follow the 68000 way of storing words/longwords (thats: mem[0] = highest byte, mem[1] = second highest byte, etc..
So I'm reading from emulated amiga memory, converting words/longwords by switching the order of the bytes and store in a variable, do the necessary operations etc.., switch the order of the bytes place that into the amiga memory.

Now I have not run any tests of the cpu emulator yet as I am far from nearly finished, so it would be informative to know what you feel about my way of doing this.


> > Hi, I've just started coding what is ment to be an emulator of the Amiga 500
> in
> > C, advice needed.
> >
> > The first thing I've wondered about is this: the mc 68000 reads/writes
> > words/longwords "normal" as opposed to the x86 (in the PC I'm trying to code
> an
> > emulator for) that swaps the cointained bytes (LO-to-HI).
> >
> > what is the easiest way to deal with this ? I've got somwhat confused for the
> > past ours to be honest.
>
> There are a few ways to deal with this depending on which version of the 68K you
> have to emulate. If dealing with the 68000 or 68010, you can actually byteswap
> every 16-bit word in your emulated memory spaces and then use normal
> loads/stores on X86. This is platform-specific of course. To access bytes,
> you'll have to XOR the address with 1 to get at the right part.
>
> For the 68020 and higher, this won't work because the processor can perform
> unaligned memory access and you have to either use a really tricky backwards
> memory scheme or simply byteswap everything after you've read it from memory.
>
> This works for the 68000 and any processor: just shift the bytes around using
> standard C bit shift and logical AND/OR operators.
>





SubjectRe: Amiga 500 --> PC Reply to this message
Posted byamilator
Posted on09/22/05 08:27 AM



my next problem seem to be a way to handle signed operations directly with C operations or if I need to read up on arithmetics and handle them myself, you see this is the first time I'm doing this sort of lowlevel stuff in C.

> The usual way for 68000 is as you say to store unsigned shorts in x86 format and
> xor the address with 1 when reading bytes.
>
> For the 68020 the process is the same but store unsigned longs and xor address
> with 2 when reading words and with 3 when reading bytes.
>
> Unaligned reads aren't that hard, there are only three cases. You just do two
> reads and shift each value, like the real chip does. In terms of emulating an
> Amiga, that is easy.
>
> smf
>





SubjectRe: Amiga 500 --> PC new Reply to this message
Posted bynikoniko1975
Posted on11/07/05 06:49 PM



I'm trying to code an
> emulator for) that swaps the cointained bytes (LO-to-HI).
>
> what is the easiest way to deal with this ? I've got somwhat confused for the
> past ours to be honest.

If you use a little inline assembly, you could take advantage of the x86's BSWAP instruction. It changes the byte order of a 32-bit register from big endian to little endian and vice-versa.


Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode