synchronize with fellow cpu update.

- edge-case fixes for bcd ops
- tweak division by 0 exception a bit
- clean up includes
This commit is contained in:
Kelvin Sherlock 2016-05-16 13:45:32 -04:00
parent f79e74c510
commit 5976f91a89
16 changed files with 135 additions and 209 deletions

View File

@ -1,8 +1,6 @@
#ifndef CpuIntegration_H
#define CpuIntegration_H
#include <setjmp.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -16,6 +14,8 @@ typedef enum {
M68EC20 = 9
} cpu_integration_models;
extern void cpuIntegrationCalculateMultiplier(void);
extern void cpuIntegrationSetUpInterruptEventHandler(void);
extern void cpuIntegrationExecuteInstructionEventHandler68000Fast(void);
extern void cpuIntegrationExecuteInstructionEventHandler68000General(void);

View File

@ -24,8 +24,7 @@
#include "defs.h"
#include "CpuModule.h"
#include "fellow.h"
#include "fmem.h"
#include "CpuModule_Memory.h"
#include "CpuModule_Internal.h"
void cpuClearEverything(void)

View File

@ -18,7 +18,7 @@ extern void cpuSetFLineExceptionFunc(cpuLineExceptionFunc func);
typedef BOOLE (*cpuCheckPendingInterruptsFunc)(void);
extern void cpuSetCheckPendingInterruptsFunc(cpuCheckPendingInterruptsFunc func);
extern void cpuCheckPendingInterrupts(void);
void cpuSetUpInterrupt(ULO new_interrupt_level);
extern void cpuSetUpInterrupt(ULO new_interrupt_level);
extern void cpuInitializeFromNewPC(ULO new_pc);
@ -77,12 +77,9 @@ extern ULO cpuGetInitialSP(void);
extern ULO cpuGetInstructionTime(void);
extern BOOLE cpuSetIrqLevel(ULO new_interrupt_level);
extern BOOLE cpuSetIrqLevel(ULO irq_level);
extern ULO cpuGetIrqLevel(void);
extern void cpuSetIrqAddress(ULO irq_address);
extern ULO cpuGetIrqAddress(void);
extern ULO cpuExecuteInstruction(void);
extern ULO cpuDisOpcode(ULO disasm_pc, STR *saddress, STR *sdata, STR *sinstruction, STR *soperands);

View File

@ -5590,254 +5590,199 @@ static void DIVS_81C0(ULO*opc_data)
{
UWO src = cpuGetDRegWord(opc_data[0]);
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81D0(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA02(opc_data[0]));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81D8(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA03(opc_data[0],2));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81E0(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA04(opc_data[0],2));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81E8(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA05(opc_data[0]));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81F0(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA06(opc_data[0]));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81F8(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA70());
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81F9(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA71());
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81FA(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA72());
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81FB(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA73());
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVS_81FC(ULO*opc_data)
{
UWO src = cpuGetNextWord();
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivsW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivsW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVL_4C40(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = cpuGetDReg(opc_data[0]);
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C50(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA02(opc_data[0]));
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C58(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA03(opc_data[0],4));
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C60(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA04(opc_data[0],4));
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C68(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA05(opc_data[0]));
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C70(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA06(opc_data[0]));
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C78(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA70());
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C79(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA71());
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C7A(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA72());
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C7B(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = memoryReadLong(cpuEA73());
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVL_4C7C(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
ULO src = cpuGetNextLong();
cpuDivL(src, ext);
cpuSetInstructionTime(opc_data[2]);
cpuDivL(src, ext, opc_data[2]);
}
static void DIVU_80C0(ULO*opc_data)
{
UWO src = cpuGetDRegWord(opc_data[0]);
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80D0(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA02(opc_data[0]));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80D8(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA03(opc_data[0],2));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80E0(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA04(opc_data[0],2));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80E8(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA05(opc_data[0]));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80F0(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA06(opc_data[0]));
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80F8(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA70());
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80F9(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA71());
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80FA(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA72());
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80FB(ULO*opc_data)
{
UWO src = memoryReadWord(cpuEA73());
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void DIVU_80FC(ULO*opc_data)
{
UWO src = cpuGetNextWord();
ULO dst = cpuGetDReg(opc_data[1]);
ULO res = cpuDivuW(dst, src);
cpuSetDReg(opc_data[1], res);
cpuSetInstructionTime(opc_data[2]);
cpuDivuW(dst, src, opc_data[1], opc_data[2]);
}
static void MOVEM_48A0(ULO*opc_data)
{
@ -6483,42 +6428,42 @@ static void BFTST_E8FB(ULO*opc_data)
static void BFCHG_EAC0(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
cpuBfChgReg(opc_data[1], ext);
cpuBfChgReg(opc_data[0], ext);
}
static void BFCLR_ECC0(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
cpuBfClrReg(opc_data[1], ext);
cpuBfClrReg(opc_data[0], ext);
}
static void BFEXTS_EBC0(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
cpuBfExtsReg(opc_data[1], ext);
cpuBfExtsReg(opc_data[0], ext);
}
static void BFEXTU_E9C0(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
cpuBfExtuReg(opc_data[1], ext);
cpuBfExtuReg(opc_data[0], ext);
}
static void BFFFO_EDC0(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
cpuBfFfoReg(opc_data[1], ext);
cpuBfFfoReg(opc_data[0], ext);
}
static void BFINS_EFC0(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
cpuBfInsReg(opc_data[1], ext);
cpuBfInsReg(opc_data[0], ext);
}
static void BFSET_EEC0(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
cpuBfSetReg(opc_data[1], ext);
cpuBfSetReg(opc_data[0], ext);
}
static void BFTST_E8C0(ULO*opc_data)
{
UWO ext = cpuGetNextWord();
cpuBfTstReg(opc_data[1], ext);
cpuBfTstReg(opc_data[0], ext);
}
static void MULL_4C00(ULO*opc_data)
{
@ -7347,6 +7292,7 @@ static void TAS_4AC0(ULO*opc_data)
UBY dst = cpuGetDRegByte(opc_data[0]);
dst = cpuTas(dst);
cpuSetDRegByte(opc_data[0], dst);
cpuSetInstructionTime(4);
}
static void TAS_4AD0(ULO*opc_data)
{
@ -7354,6 +7300,7 @@ static void TAS_4AD0(ULO*opc_data)
UBY dst = memoryReadByte(dstea);
dst = cpuTas(dst);
memoryWriteByte(dst, dstea);
cpuSetInstructionTime(14);
}
static void TAS_4AD8(ULO*opc_data)
{
@ -7361,6 +7308,7 @@ static void TAS_4AD8(ULO*opc_data)
UBY dst = memoryReadByte(dstea);
dst = cpuTas(dst);
memoryWriteByte(dst, dstea);
cpuSetInstructionTime(14);
}
static void TAS_4AE0(ULO*opc_data)
{
@ -7368,6 +7316,7 @@ static void TAS_4AE0(ULO*opc_data)
UBY dst = memoryReadByte(dstea);
dst = cpuTas(dst);
memoryWriteByte(dst, dstea);
cpuSetInstructionTime(16);
}
static void TAS_4AE8(ULO*opc_data)
{
@ -7375,6 +7324,7 @@ static void TAS_4AE8(ULO*opc_data)
UBY dst = memoryReadByte(dstea);
dst = cpuTas(dst);
memoryWriteByte(dst, dstea);
cpuSetInstructionTime(18);
}
static void TAS_4AF0(ULO*opc_data)
{
@ -7382,6 +7332,7 @@ static void TAS_4AF0(ULO*opc_data)
UBY dst = memoryReadByte(dstea);
dst = cpuTas(dst);
memoryWriteByte(dst, dstea);
cpuSetInstructionTime(20);
}
static void TAS_4AF8(ULO*opc_data)
{
@ -7389,6 +7340,7 @@ static void TAS_4AF8(ULO*opc_data)
UBY dst = memoryReadByte(dstea);
dst = cpuTas(dst);
memoryWriteByte(dst, dstea);
cpuSetInstructionTime(18);
}
static void TAS_4AF9(ULO*opc_data)
{
@ -7396,6 +7348,7 @@ static void TAS_4AF9(ULO*opc_data)
UBY dst = memoryReadByte(dstea);
dst = cpuTas(dst);
memoryWriteByte(dst, dstea);
cpuSetInstructionTime(22);
}
static void TST_4A00(ULO*opc_data)
{
@ -7638,43 +7591,43 @@ static void PEA_4850(ULO*opc_data)
{
ULO dstea = cpuEA02(opc_data[0]);
cpuPeaL(dstea);
cpuSetInstructionTime(8);
cpuSetInstructionTime(12);
}
static void PEA_4868(ULO*opc_data)
{
ULO dstea = cpuEA05(opc_data[0]);
cpuPeaL(dstea);
cpuSetInstructionTime(10);
cpuSetInstructionTime(16);
}
static void PEA_4870(ULO*opc_data)
{
ULO dstea = cpuEA06(opc_data[0]);
cpuPeaL(dstea);
cpuSetInstructionTime(14);
cpuSetInstructionTime(20);
}
static void PEA_4878(ULO*opc_data)
{
ULO dstea = cpuEA70();
cpuPeaL(dstea);
cpuSetInstructionTime(10);
cpuSetInstructionTime(16);
}
static void PEA_4879(ULO*opc_data)
{
ULO dstea = cpuEA71();
cpuPeaL(dstea);
cpuSetInstructionTime(12);
cpuSetInstructionTime(20);
}
static void PEA_487A(ULO*opc_data)
{
ULO dstea = cpuEA72();
cpuPeaL(dstea);
cpuSetInstructionTime(10);
cpuSetInstructionTime(16);
}
static void PEA_487B(ULO*opc_data)
{
ULO dstea = cpuEA73();
cpuPeaL(dstea);
cpuSetInstructionTime(14);
cpuSetInstructionTime(20);
}
static void JMP_4ED0(ULO*opc_data)
{

View File

@ -23,7 +23,7 @@
/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*=========================================================================*/
#include "defs.h"
#include "fmem.h"
#include "CpuModule_Memory.h"
#include "CpuModule.h"
#include "CpuModule_DisassemblerFunc.h"

View File

@ -24,8 +24,7 @@
/*=========================================================================*/
#include "defs.h"
#include "fellow.h"
#include "fmem.h"
#include "CpuModule_Memory.h"
#include "CpuModule.h"
#include "CpuModule_Internal.h"

View File

@ -24,8 +24,7 @@
/*=========================================================================*/
#include "defs.h"
#include "fellow.h"
#include "fmem.h"
#include "CpuModule_Memory.h"
#include "CpuModule.h"
#include "CpuModule_Internal.h"
@ -194,10 +193,10 @@ void cpuThrowTrapVException(void)
cpuThrowException(0x1c, cpuGetPC(), FALSE);
}
void cpuThrowDivisionByZeroException(BOOLE executejmp)
void cpuThrowDivisionByZeroException()
{
// The saved pc points to the next instruction, which is now in pc
cpuThrowException(0x14, cpuGetPC(), executejmp);
cpuThrowException(0x14, cpuGetPC(), FALSE);
}
void cpuThrowTrapException(ULO vector_no)

View File

@ -22,7 +22,6 @@
/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*=========================================================================*/
#include "defs.h"
#include "fellow.h"
#include "CpuModule.h"
#include "CpuModule_Internal.h"
@ -195,7 +194,7 @@ void cpuSetFlags0100(void)
/// <summary>
/// Clear V and C.
/// </summary>
static void cpuClearFlagsVC(void)
void cpuClearFlagsVC(void)
{
cpu_sr = cpu_sr & 0xfffc;
}

View File

@ -24,16 +24,10 @@
/*=========================================================================*/
#include "defs.h"
#include "fellow.h"
#include "fmem.h"
#include "CpuModule_Memory.h"
#include "CpuModule.h"
#include "CpuModule_Internal.h"
#ifdef UAE_FILESYS
#include "uae2fell.h"
#include "autoconf.h"
#endif
static cpuLineExceptionFunc cpu_a_line_exception_func = NULL;
static cpuLineExceptionFunc cpu_f_line_exception_func = NULL;
@ -168,24 +162,21 @@ static void cpuIllegal(void)
}
else if ((opcode & 0xa000) == 0xa000)
{
/*
#ifdef UAE_FILESYS
#if 0
if ((cpuGetPC() & 0xff0000) == 0xf00000)
{
call_calltrap(opcode & 0xfff);
cpuInitializeFromNewPC(cpuGetPC());
cpuSetInstructionTime(512);
}
else
#endif
*/
#else
if (cpu_a_line_exception_func)
{
cpu_a_line_exception_func(opcode);
cpuInitializeFromNewPC(cpuGetPC());
cpuSetInstructionTime(512);
}
#endif
else
{
cpuThrowALineException();
@ -1162,17 +1153,16 @@ static ULO cpuMuluW(UWO src2, UWO src1, ULO eatime)
/// <summary>
/// Divsw, src1 / src2
/// </summary>
static ULO cpuDivsW(ULO dst, UWO src1)
static void cpuDivsW(ULO dst, UWO src1, ULO destination_reg, ULO instruction_time)
{
ULO result;
if (src1 == 0)
{
// Alcatraz odyssey assumes that PC in this exception points after the instruction.
cpuThrowDivisionByZeroException(TRUE);
result = dst;
cpuThrowDivisionByZeroException();
}
else
{
ULO result;
LON x = (LON) dst;
LON y = (LON)(WOR) src1;
LON res = x / y;
@ -1187,24 +1177,24 @@ static ULO cpuDivsW(ULO dst, UWO src1)
result = (rem << 16) | (res & 0xffff);
cpuSetFlagsNZVC(cpuIsZeroW((UWO) res), cpuMsbW((UWO) res), FALSE, FALSE);
}
cpuSetDReg(destination_reg, result);
cpuSetInstructionTime(instruction_time);
}
return result;
}
/// <summary>
/// Divuw, src1 / src2
/// </summary>
static ULO cpuDivuW(ULO dst, UWO src1)
static void cpuDivuW(ULO dst, UWO src1, ULO destination_reg, ULO instruction_time)
{
ULO result;
if (src1 == 0)
{
// Alcatraz odyssey assumes that PC in this exception points after the instruction.
cpuThrowDivisionByZeroException(TRUE);
result = dst;
cpuThrowDivisionByZeroException();
}
else
{
ULO result;
ULO x = dst;
ULO y = (ULO) src1;
ULO res = x / y;
@ -1219,11 +1209,12 @@ static ULO cpuDivuW(ULO dst, UWO src1)
result = (rem << 16) | (res & 0xffff);
cpuSetFlagsNZVC(cpuIsZeroW((UWO) res), cpuMsbW((UWO) res), FALSE, FALSE);
}
cpuSetDReg(destination_reg, result);
cpuSetInstructionTime(instruction_time);
}
return result;
}
static void cpuDivL(ULO divisor, ULO ext)
static void cpuDivL(ULO divisor, ULO ext, ULO instruction_time)
{
if (divisor != 0)
{
@ -1296,10 +1287,11 @@ static void cpuDivL(ULO divisor, ULO ext)
cpuSetFlagsNZ00NewL((ULO) result);
}
}
cpuSetInstructionTime(instruction_time);
}
else
{
cpuThrowDivisionByZeroException(FALSE);
cpuThrowDivisionByZeroException();
}
}
@ -2462,7 +2454,7 @@ static void cpuCmpML(ULO regx, ULO regy)
static void cpuChkW(UWO value, UWO ub)
{
cpuSetFlagZ(value == 0);
cpuSetFlagsVC(FALSE, FALSE);
cpuClearFlagsVC();
if (((WOR)value) < 0)
{
cpuSetFlagN(TRUE);
@ -2485,7 +2477,7 @@ static void cpuChkW(UWO value, UWO ub)
static void cpuChkL(ULO value, ULO ub)
{
cpuSetFlagZ(value == 0);
cpuSetFlagsVC(FALSE, FALSE);
cpuClearFlagsVC();
if (((LON)value) < 0)
{
cpuSetFlagN(TRUE);
@ -2567,39 +2559,35 @@ static ULO cpuSubXL(ULO dst, ULO src)
/// </summary>
static UBY cpuAbcdB(UBY dst, UBY src)
{
UBY xflag = (cpuGetFlagX()) ? 1:0;
UWO res = dst + src + xflag;
UWO res_unadjusted = res;
UBY res_bcd;
UBY low_nibble = (dst & 0xf) + (src & 0xf) + xflag;
UBY xflag = (cpuGetFlagX()) ? 1 : 0;
UWO low_nibble = (dst & 0xf) + (src & 0xf) + xflag;
UWO high_nibble = ((UWO)(dst & 0xf0)) + ((UWO)(src & 0xf0));
UWO result_unadjusted = low_nibble + high_nibble;
UWO result_bcd = result_unadjusted;
if (low_nibble > 9)
{
res += 6;
result_bcd += 6;
}
if (res > 0x99)
BOOLE xc_flags = (result_bcd & 0xfff0) > 0x90;
cpuSetFlagXC(xc_flags);
if (xc_flags)
{
res += 0x60;
cpuSetFlagXC(TRUE);
}
else
{
cpuSetFlagXC(FALSE);
result_bcd += 0x60;
}
res_bcd = (UBY) res;
if (res_bcd != 0)
if (result_bcd & 0xff)
{
cpuSetFlagZ(FALSE);
}
if (res_bcd & 0x80)
if (cpuGetModelMajor() < 4) // 040 apparently does not set these flags
{
cpuSetFlagN(TRUE);
cpuSetFlagN(result_bcd & 0x80);
cpuSetFlagV(((result_unadjusted & 0x80) == 0) && (result_bcd & 0x80));
}
cpuSetFlagV(((res_unadjusted & 0x80) == 0) && (res_bcd & 0x80));
return res_bcd;
return (UBY)result_bcd;
}
/// <summary>
@ -2612,36 +2600,38 @@ static UBY cpuAbcdB(UBY dst, UBY src)
/// </summary>
static UBY cpuSbcdB(UBY dst, UBY src)
{
UBY xflag = (cpuGetFlagX()) ? 1:0;
UWO res = dst - src - xflag;
UWO res_unadjusted = res;
UBY res_bcd;
UWO xflag = (cpuGetFlagX()) ? 1:0;
UWO result_plain_binary = (UWO)dst - (UWO)src - xflag;
UWO low_nibble = (UWO)(dst & 0xf) - (UWO)(src & 0xf) - xflag;
UWO high_nibble = ((UWO)(dst & 0xf0)) - ((UWO)(src & 0xf0));
UWO result_unadjusted = low_nibble + high_nibble;
UWO result_bcd = result_unadjusted;
if (((src & 0xf) + xflag) > (dst & 0xf))
if ((WOR)result_plain_binary < 0)
{
res -= 6;
result_bcd -= 0x60;
}
if (res & 0x80)
{
res -= 0x60;
cpuSetFlagXC(TRUE);
}
else
{
cpuSetFlagXC(FALSE);
}
res_bcd = (UBY) res;
if (res_bcd != 0)
if (((WOR)low_nibble) < 0)
{
result_bcd -= 6;
result_plain_binary -= 6;
}
BOOLE borrow = ((WOR)result_plain_binary < 0);
cpuSetFlagXC(borrow);
if (result_bcd & 0xff)
{
cpuSetFlagZ(FALSE);
}
if (res_bcd & 0x80)
if (cpuGetModelMajor() < 4)
{
cpuSetFlagN(TRUE);
cpuSetFlagN(result_bcd & 0x80);
cpuSetFlagV(((result_unadjusted & 0x80) == 0x80) && !(result_bcd & 0x80));
}
cpuSetFlagV(((res_unadjusted & 0x80) == 0x80) && !(res_bcd & 0x80));
return res_bcd;
return (UBY) result_bcd;
}
/// <summary>
@ -2743,9 +2733,9 @@ void cpuBfDecodeExtWordAndGetField(struct cpuBfData *bf_data, ULO ea_or_reg, boo
ULO shift = (8 - bf_data->normalized_offset - bf_data->width) & 7;
for (int i = bf_data->base_address_byte_count - 1; i >= 0; --i)
{
ULL value = (ULL) memoryReadByte(address);
field_memory |= (value << (8*i));
field |= ((value >> shift) << (8*i));
ULL value = ((ULL)memoryReadByte(address)) << (8 * i);
field_memory |= value;
field |= (value >> shift);
++address;
}
@ -3701,7 +3691,7 @@ static void cpuPtest040(ULO rw, ULO regno)
#include "CpuModule_Decl.h"
#include "CpuModule_Data.h"
//#include "CpuModule_Profile.h"
#include "CpuModule_Profile.h"
#include "CpuModule_Code.h"
cpuOpcodeData cpu_opcode_data_current[65536];

View File

@ -51,10 +51,6 @@ extern void cpuSetCaar(ULO caar);
extern ULO cpuGetCaar(void);
extern void cpuSetSR(ULO sr);
extern ULO cpuGetSR(void);
extern BOOLE cpuSetIrqLevel(ULO new_interrupt_level);
extern ULO cpuGetIrqLevel(void);
extern void cpuSetIrqAddress(ULO irq_address);
extern ULO cpuGetIrqAddress(void);
extern void cpuSetInstructionTime(ULO cycles);
extern ULO cpuGetInstructionTime(void);
extern void cpuSetOriginalPC(ULO pc);
@ -140,6 +136,7 @@ extern UWO cpuGetZFlagL(ULO res);
extern UWO cpuGetNFlagB(UBY res);
extern UWO cpuGetNFlagW(UWO res);
extern UWO cpuGetNFlagL(ULO res);
extern void cpuClearFlagsVC(void);
extern BOOLE cpuCalculateConditionCode0(void);
extern BOOLE cpuCalculateConditionCode1(void);
@ -180,7 +177,7 @@ extern void cpuThrowFLineException(void);
extern void cpuThrowALineException(void);
extern void cpuThrowTrapVException(void);
extern void cpuThrowTrapException(ULO vector_no);
extern void cpuThrowDivisionByZeroException(BOOLE executejmp);
extern void cpuThrowDivisionByZeroException();
extern void cpuThrowChkException(void);
extern void cpuThrowTraceException(void);
extern void cpuThrowResetException(void);

View File

@ -23,8 +23,7 @@
/*=========================================================================*/
#include "defs.h"
#include "CpuModule.h"
#include "fellow.h"
#include "fmem.h"
#include "CpuModule_Memory.h"
#include "CpuModule_Internal.h"
/* M68k registers */

View File

@ -22,9 +22,7 @@
/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*=========================================================================*/
#include "defs.h"
#include "fellow.h"
#include "fmem.h"
#include "CpuModule_Memory.h"
#include "CpuModule.h"
#include "CpuModule_Internal.h"

View File

@ -24,8 +24,6 @@
/*=========================================================================*/
#include "defs.h"
#include "fellow.h"
#include "CpuModule.h"
#ifdef CPU_INSTRUCTION_LOGGING

1
cpu/CpuModule_Memory.h Normal file
View File

@ -0,0 +1 @@
#include "fmem.h"

View File

@ -1,7 +1,6 @@
#ifndef CPUMODULE_PROFILE_H
#define CPUMODULE_PROFILE_H
#include "fileops.h"
void cpuProfileWrite(void)
{
}

View File

@ -22,9 +22,7 @@
/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*=========================================================================*/
#include "defs.h"
#include "fellow.h"
#include "fmem.h"
#include "CpuModule_Memory.h"
#include "CpuModule.h"
#include "CpuModule_Internal.h"