kstenerud / Musashi

Motorola 680x0 emulator written in C
412 stars 94 forks source link

Bitfield mask for 5th byte is wrong #5

Closed harbaum closed 8 years ago

harbaum commented 9 years ago

The instruction bfset mem{1:32}

writes 32 bits 0x7fffffff and then 8 bits of a fifth byte with 0xff while it should be writing 0x80 (only the last missing bit from the first 32 bit write).

The problem is in m68k_in.c at:

    mask_base = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
  ...
    if((width + offset) > 32)
    {
        mask_byte = MASK_OUT_ABOVE_8(mask_base);
   ...
        m68ki_write_8((mc68kcpu), ea+4, data_byte | mask_byte);
    }

The mask_byte imho needs to be generated like this: mask_byte = MASK_OUT_ABOVE_8(mask_base) << (8-offset);

This fix is not tested as i am actually not working on Musashi but instead tried to use Musashi to verify another core.

harbaum commented 8 years ago

Fixed in mess