Skip to content

Commit

Permalink
68k: MOVEM - pre-decrement long-writes on an address register store l…
Browse files Browse the repository at this point in the history
…sw first and then msw
  • Loading branch information
Federico Berti committed May 20, 2019
1 parent 419a994 commit cd27310
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/m68k/cpu/instructions/MOVEM.java
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,9 @@ protected final int putMultipleLongPreDec(int reg, int reglist, int address)
{
start -= 4;
if (reg == 7-n) // if the EA register itself is also moved, use initial value
cpu.writeMemoryLong(start, oldreg);
writeMemoryLongSwapped(start, oldreg);
else
cpu.writeMemoryLong(start, cpu.getAddrRegisterLong(7 - n));
writeMemoryLongSwapped(start, cpu.getAddrRegisterLong(7 - n));
regcount++;
}
bit <<= 1;
Expand All @@ -679,7 +679,7 @@ protected final int putMultipleLongPreDec(int reg, int reglist, int address)
if((reglist & bit) != 0)
{
start -= 4;
cpu.writeMemoryLong(start, cpu.getDataRegisterLong(7 - n));
writeMemoryLongSwapped(start, cpu.getDataRegisterLong(7 - n));
regcount++;
}
bit <<= 1;
Expand All @@ -689,4 +689,9 @@ protected final int putMultipleLongPreDec(int reg, int reglist, int address)
return regcount;
}

private void writeMemoryLongSwapped(int address, int value) {
//swap word-write order, lsw first
cpu.writeMemoryWord(address + 2, value & 0xFFFF);
cpu.writeMemoryWord(address, (value >> 16) & 0xFFFF);
}
}
43 changes: 42 additions & 1 deletion test/m68k/cpu/instructions/AddressRegisterPreDecOperandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public void writeWord(int addr, int value) {
wordWrites.put(addr, value);
super.writeWord(addr, value);
}

@Override
public void writeLong(int addr, int value) {
wordWrites.put(addr, (value >> 16) & 0xFFFF);
wordWrites.put(addr + 2, value & 0xFFFF);
super.writeLong(addr, value);
}
};

cpu = new MC68000();
Expand All @@ -42,7 +49,7 @@ public void writeWord(int addr, int value) {
wordWrites.clear();
}

public void testLswWrittenFirst() {
public void testLswWrittenFirst_MOVE() {
int lsw = 0x2222;
int msw = 0x1111;
int value = msw << 16 | lsw;
Expand Down Expand Up @@ -73,6 +80,40 @@ public void testLswWrittenFirst() {
Map.Entry<Integer, Integer> second = i.next();
Assert.assertEquals(firstWordPos, second.getKey().intValue());
Assert.assertEquals(msw, second.getValue().intValue());
}

public void testLswWrittenFirst_MOVEM() {
int lsw = 0x2222;
int msw = 0x1111;
int value = msw << 16 | lsw;
int startPos = 0x104;
int endPos = startPos - 8; // 2 longs
int valuePos = startPos - 4;

bus.writeLong(4, 0x48e1_8100); //48e1 8100 movem.l d0/d7,-(a1)
cpu.setPC(4);
cpu.setDataRegisterLong(7, value);
cpu.setAddrRegisterLong(1, startPos);

wordWrites.clear();
cpu.execute();

Assert.assertEquals(cpu.getAddrRegisterLong(1), endPos);

long res = bus.readLong(valuePos);
Assert.assertEquals(res, value);

Assert.assertEquals(wordWrites.size(), 4);

int firstWordPos = startPos - 2;
Iterator<Map.Entry<Integer, Integer>> i = wordWrites.entrySet().iterator();
Map.Entry<Integer, Integer> first = i.next();
Assert.assertEquals(firstWordPos, first.getKey().intValue());
Assert.assertEquals(lsw, first.getValue().intValue());

int secondWordPos = firstWordPos - 2;
Map.Entry<Integer, Integer> second = i.next();
Assert.assertEquals(secondWordPos, second.getKey().intValue());
Assert.assertEquals(msw, second.getValue().intValue());
}
}

0 comments on commit cd27310

Please sign in to comment.