Skip to content

Commit 293e39e

Browse files
callsopejaquay
authored andcommitted
Fix EXG instruction exception
1 parent 6262a5e commit 293e39e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

mc6809.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void MC6809Init(void)
117117
xfreg16[3]=&U_REG;
118118
xfreg16[4]=&S_REG;
119119
xfreg16[5]=&PC_REG;
120+
xfreg16[6] = 0;
121+
xfreg16[7] = 0;
120122

121123
ureg8[0]=(unsigned char*)&A_REG;
122124
ureg8[1]=(unsigned char*)&B_REG;
@@ -490,9 +492,15 @@ void Do_Opcode(int CycleFor)
490492
}
491493
else // 16 bit EXG
492494
{
493-
temp16=(*xfreg16[((postbyte & 0x70) >> 4)]);
494-
(*xfreg16[((postbyte & 0x70) >> 4)])=(*xfreg16[postbyte & 0x07]);
495-
(*xfreg16[postbyte & 0x07])=temp16;
495+
uint16_t* src = xfreg16[((postbyte & 0x70) >> 4)];
496+
uint16_t* dest = xfreg16[postbyte & 0x07];
497+
// todo: find out which program triggers it
498+
assert(src);
499+
assert(dest);
500+
uint16_t srcValue = src ? *src : 0xFFFF;
501+
uint16_t destValue = dest ? *dest : 0xFFFF;
502+
if (src) *src = destValue;
503+
if (dest) *dest = srcValue;
496504
}
497505
}
498506
setcc(ccbits);

0 commit comments

Comments
 (0)