From ad2a5144adecaec68cabe3156be45320959857df Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Sun, 6 Sep 2009 21:56:17 +0000 Subject: [PATCH] > From: Gabriele Gorla [mailto:gorlik@penguintown.net] > Sent: Saturday, September 05, 2009 2:11 PM > To: submit@mamedev.org > Subject: I386: fix loop instructions when address_size is 16-bit > > Original code always assume address_size to be 32-bit > The patch will use the correct size based on the status of the > address_size flag. > --- src/emu/cpu/i386/i386op32.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/emu/cpu/i386/i386op32.c b/src/emu/cpu/i386/i386op32.c index e73c60c12d1..c8d06e4aa60 100644 --- a/src/emu/cpu/i386/i386op32.c +++ b/src/emu/cpu/i386/i386op32.c @@ -1021,8 +1021,8 @@ static void I386OP(lodsd)(i386_state *cpustate) // Opcode 0xad static void I386OP(loop32)(i386_state *cpustate) // Opcode 0xe2 { INT8 disp = FETCH(cpustate); - REG32(ECX)--; - if( REG32(ECX) != 0 ) { + INT32 reg = (cpustate->address_size)?--REG32(ECX):--REG16(CX); + if( reg != 0 ) { cpustate->eip += disp; CHANGE_PC(cpustate,cpustate->eip); } @@ -1032,8 +1032,8 @@ static void I386OP(loop32)(i386_state *cpustate) // Opcode 0xe2 static void I386OP(loopne32)(i386_state *cpustate) // Opcode 0xe0 { INT8 disp = FETCH(cpustate); - REG32(ECX)--; - if( REG32(ECX) != 0 && cpustate->ZF == 0 ) { + INT32 reg = (cpustate->address_size)?--REG32(ECX):--REG16(CX); + if( reg != 0 && cpustate->ZF == 0 ) { cpustate->eip += disp; CHANGE_PC(cpustate,cpustate->eip); } @@ -1043,8 +1043,8 @@ static void I386OP(loopne32)(i386_state *cpustate) // Opcode 0xe0 static void I386OP(loopz32)(i386_state *cpustate) // Opcode 0xe1 { INT8 disp = FETCH(cpustate); - REG32(ECX)--; - if( REG32(ECX) != 0 && cpustate->ZF != 0 ) { + INT32 reg = (cpustate->address_size)?--REG32(ECX):--REG16(CX); + if( reg != 0 && cpustate->ZF != 0 ) { cpustate->eip += disp; CHANGE_PC(cpustate,cpustate->eip); }