Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Conflicts:
	Emulator/Utilities/Types.h
  • Loading branch information
dirkwhoffmann committed Dec 29, 2023
2 parents 6d5f076 + 96b96ac commit e53fb61
Show file tree
Hide file tree
Showing 53 changed files with 5,200 additions and 396 deletions.
5 changes: 5 additions & 0 deletions Emulator/Base/CoreComponentTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ enum_long(OPT)
OPT_CPU_OVERCLOCKING,
OPT_CPU_RESET_VAL,

// FPU
OPT_FPU_REVISION,

// Real-time clock
OPT_RTC_MODEL,

Expand Down Expand Up @@ -187,6 +190,8 @@ struct OptionEnum : util::Reflection<OptionEnum, Option>
case OPT_CPU_RESET_VAL: return "CPU_RESET_VAL";
case OPT_CPU_DASM_SYNTAX: return "CPU_DASM_SYNTAX";

case OPT_FPU_REVISION: return "FPU_REVISION";

case OPT_RTC_MODEL: return "RTC_MODEL";

case OPT_CHIP_RAM: return "CHIP_RAM";
Expand Down
1 change: 1 addition & 0 deletions Emulator/Base/Defaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Defaults::Defaults()
setFallback(OPT_CPU_DASM_SYNTAX, DASM_SYNTAX_MOIRA);
setFallback(OPT_CPU_OVERCLOCKING, 0);
setFallback(OPT_CPU_RESET_VAL, 0);
setFallback(OPT_FPU_REVISION, FPU_INTERNAL);
setFallback(OPT_RTC_MODEL, RTC_OKI);
setFallback(OPT_CHIP_RAM, 512);
setFallback(OPT_SLOW_RAM, 512);
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Base/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Thread::execute<THREAD_ADAPTIVE>()
}

// Compute all missing frames
for (isize i = 0; i < missing; i++) execute();
for (isize i = 0; i < missing && isRunning(); i++) execute();

loadClock.stop();
}
Expand Down
10 changes: 8 additions & 2 deletions Emulator/Components/Amiga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ Amiga::getConfigItem(Option option) const
case OPT_CPU_DASM_SYNTAX:
case OPT_CPU_OVERCLOCKING:
case OPT_CPU_RESET_VAL:
case OPT_FPU_REVISION:

return cpu.getConfigItem(option);

Expand Down Expand Up @@ -562,7 +563,8 @@ Amiga::configure(Option option, i64 value)
case OPT_CPU_OVERCLOCKING:
case OPT_CPU_RESET_VAL:
case OPT_CPU_DASM_SYNTAX:

case OPT_FPU_REVISION:

cpu.setConfigItem(option, value);
break;

Expand Down Expand Up @@ -830,6 +832,7 @@ Amiga::configure(ConfigScheme scheme)
case CONFIG_A1000_OCS_1MB:

configure(OPT_CPU_REVISION, CPU_68000);
configure(OPT_FPU_REVISION, FPU_INTERNAL);
configure(OPT_AGNUS_REVISION, AGNUS_OCS_OLD);
configure(OPT_DENISE_REVISION, DENISE_OCS);
configure(OPT_VIDEO_FORMAT, PAL);
Expand All @@ -840,6 +843,7 @@ Amiga::configure(ConfigScheme scheme)
case CONFIG_A500_OCS_1MB:

configure(OPT_CPU_REVISION, CPU_68000);
configure(OPT_FPU_REVISION, FPU_INTERNAL);
configure(OPT_AGNUS_REVISION, AGNUS_OCS);
configure(OPT_DENISE_REVISION, DENISE_OCS);
configure(OPT_VIDEO_FORMAT, PAL);
Expand All @@ -850,6 +854,7 @@ Amiga::configure(ConfigScheme scheme)
case CONFIG_A500_ECS_1MB:

configure(OPT_CPU_REVISION, CPU_68000);
configure(OPT_FPU_REVISION, FPU_INTERNAL);
configure(OPT_AGNUS_REVISION, AGNUS_ECS_1MB);
configure(OPT_DENISE_REVISION, DENISE_OCS);
configure(OPT_VIDEO_FORMAT, PAL);
Expand All @@ -860,13 +865,14 @@ Amiga::configure(ConfigScheme scheme)
case CONFIG_A500_PLUS_1MB:

configure(OPT_CPU_REVISION, CPU_68000);
configure(OPT_FPU_REVISION, FPU_INTERNAL);
configure(OPT_AGNUS_REVISION, AGNUS_ECS_2MB);
configure(OPT_DENISE_REVISION, DENISE_ECS);
configure(OPT_VIDEO_FORMAT, PAL);
configure(OPT_CHIP_RAM, 512);
configure(OPT_SLOW_RAM, 512);
break;

default:
fatalError;
}
Expand Down
4 changes: 3 additions & 1 deletion Emulator/Components/Amiga.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ class Amiga : public Thread {
// Reverts to factory settings
void revertToFactorySettings();


// Returns whether experimental FPU support should be enabled
bool fpuSupport() { return FPU_SUPPORT; }

private:

// Overrides a config option if the corresponding debug option is enabled
Expand Down
1 change: 0 additions & 1 deletion Emulator/Components/AmigaTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ struct ConfigSchemeEnum : util::Reflection<ConfigSchemeEnum, ConfigScheme>
case CONFIG_A1000_OCS_1MB: return "A1000_OCS_1MB";
case CONFIG_A500_OCS_1MB: return "A500_OCS_1MB";
case CONFIG_A500_ECS_1MB: return "A500_ECS_1MB";
case CONFIG_A500_PLUS_1MB: return "A500_PLUS_1MB";
}
return "???";
}
Expand Down
95 changes: 77 additions & 18 deletions Emulator/Components/CPU/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
#include "IOUtils.h"
#include "Memory.h"
#include "MsgQueue.h"
#include "softfloat.h"

//
// Moira
//


namespace vamiga::moira {

void
Expand Down Expand Up @@ -141,7 +139,13 @@ Moira::willExecute(const char *func, Instr I, Mode M, Size S, u16 opcode)
break;

default:
{

char str[128];
disassemble(str, reg.pc0);
printf("%s\n", str);
break;
}
}
}

Expand Down Expand Up @@ -288,6 +292,8 @@ CPU::getConfigItem(Option option) const
case OPT_CPU_OVERCLOCKING: return (long)config.overclocking;
case OPT_CPU_RESET_VAL: return (long)config.regResetVal;

case OPT_FPU_REVISION: return (long)config.fpuRevision;

default:
fatalError;
}
Expand All @@ -297,6 +303,7 @@ void
CPU::setConfigItem(Option option, i64 value)
{
auto cpuModel = [&](CPURevision rev) { return moira::Model(rev); };
auto fpuModel = [&](FPURevision rev) { return moira::FPUModel(rev); };
auto dasmModel = [&](DasmRevision rev) { return moira::Model(rev); };
auto syntax = [&](DasmSyntax rev) { return moira::DasmSyntax(rev); };

Expand All @@ -314,6 +321,22 @@ CPU::setConfigItem(Option option, i64 value)
resume();
return;

case OPT_FPU_REVISION:

if (!amiga.fpuSupport()) {
throw VAError(ERROR_OPT_UNSUPPORTED);
}

if (!FPURevisionEnum::isValid(value)) {
throw VAError(ERROR_OPT_INVARG, FPURevisionEnum::keyList());
}

suspend();
config.fpuRevision = FPURevision(value);
cpu.setFpuModel(fpuModel(config.fpuRevision));
resume();
return;

case OPT_CPU_DASM_REVISION:

if (!DasmRevisionEnum::isValid(value)) {
Expand Down Expand Up @@ -365,8 +388,12 @@ CPU::resetConfig()
std::vector <Option> options = {

OPT_CPU_REVISION,
OPT_CPU_DASM_REVISION,
OPT_CPU_DASM_SYNTAX,
OPT_CPU_OVERCLOCKING,
OPT_CPU_RESET_VAL
OPT_CPU_RESET_VAL,

OPT_FPU_REVISION
};

for (auto &option : options) {
Expand Down Expand Up @@ -460,8 +487,13 @@ CPU::_dump(Category category, std::ostream& os) const

if (category == Category::Config) {

string fputxt =
config.fpuRevision == FPU_INTERNAL ? " (none)" : " (external coprocessor)";

os << util::tab("CPU revision");
os << CPURevisionEnum::key(config.revision) << std::endl;
os << util::tab("FPU revision");
os << FPURevisionEnum::key(config.fpuRevision) << fputxt << std::endl;
os << util::tab("DASM revision");
os << DasmRevisionEnum::key(config.dasmRevision) << std::endl;
os << util::tab("DASM syntax");
Expand Down Expand Up @@ -547,22 +579,39 @@ CPU::_dump(Category category, std::ostream& os) const
}

if (category == Category::Fpu) {

os << util::tab("FPIAR");
os << util::hex(fpu.fpiar) << std::endl;
os << util::tab("FPSR");
os << util::hex(fpu.fpsr) << std::endl;

os << util::tab("FPCR");
os << util::hex(fpu.fpcr) << std::endl;

/*
for (isize i = 0; i < 8; i++) {
auto value = softfloat::floatx80_to_float32(fpu.fpr[i].raw);
os << util::tab("FP" + std::to_string(i));
os << util::hex(u32(value)) << std::endl;
}
*/
os << util::tab("FPSR");
os << util::hex(fpu.fpsr) << std::endl;
os << util::tab("FPIAR");
os << util::hex(fpu.fpiar) << std::endl;
os << std::endl;

os << util::tab("Rounding mode");
switch (fpu.getRoundingMode()) {
case moira::FPU_RND_NEAREST: os << "NEAREST"; break;
case moira::FPU_RND_ZERO: os << "ZERO"; break;
case moira::FPU_RND_DOWNWARD: os << "DOWNWARD"; break;
case moira::FPU_RND_UPWARD: os << "UPDWARD"; break;
}
os << std::endl;
os << util::tab("Precision");
switch (fpu.getPrecision()) {
case moira::FPU_PREC_EXTENDED: os << "EXTENDED"; break;
case moira::FPU_PREC_SINGLE: os << "SINGLE"; break;
case moira::FPU_PREC_DOUBLE: os << "DOUBLE"; break;
case moira::FPU_PREC_UNDEFINED: os << "UNDEFINED"; break;
}
os << std::endl << std::endl;

for (isize i = 0; i < 8; i++) {

os << util::tab("FP" + std::to_string(i));
// os << fpu.fpr[i] << std::endl;
os << util::hex(fpu.fpr[i].val.raw.high) << ":";
os << util::hex(fpu.fpr[i].val.raw.low) << std::endl;
}
}

if (category == Category::Breakpoints) {
Expand Down Expand Up @@ -638,6 +687,7 @@ CPU::_trackOff()
debugger.disableLogging();
}

/*
isize
CPU::_load(const u8 *buffer)
{
Expand All @@ -653,10 +703,19 @@ CPU::_load(const u8 *buffer)
return isize(reader.ptr - buffer);
}
*/

isize
CPU::didLoadFromBuffer(const u8 *buffer)
{
auto cpuModel = (moira::Model)config.revision;
auto fpuModel = (moira::FPUModel)config.fpuRevision;
auto dasmModel = (moira::Model)config.dasmRevision;

// Rectify the CPU and FPU type
setModel(cpuModel, dasmModel);
fpu.setModel(fpuModel);

/* Because we don't save breakpoints and watchpoints in a snapshot, the
* CPU flags for checking breakpoints and watchpoints can be in a corrupt
* state after loading. These flags need to be updated according to the
Expand Down Expand Up @@ -741,7 +800,7 @@ CPU::disassembleWords(u32 addr, isize len)
{
static char result[64];

dump16(result, addr, len);
dump16(result, addr, (int)len);
return result;
}

Expand Down
26 changes: 24 additions & 2 deletions Emulator/Components/CPU/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CPU : public moira::Moira {
worker

<< config.revision
<< config.fpuRevision
<< config.dasmRevision
<< config.overclocking
<< config.regResetVal;
Expand Down Expand Up @@ -128,13 +129,34 @@ class CPU : public moira::Moira {
<< loopModeDelay
<< readBuffer
<< writeBuffer
<< flags;
<< flags

// << fpu.model
<< fpu.fpr[0].val.raw.high
<< fpu.fpr[0].val.raw.low
<< fpu.fpr[1].val.raw.high
<< fpu.fpr[1].val.raw.low
<< fpu.fpr[2].val.raw.high
<< fpu.fpr[2].val.raw.low
<< fpu.fpr[3].val.raw.high
<< fpu.fpr[3].val.raw.low
<< fpu.fpr[4].val.raw.high
<< fpu.fpr[4].val.raw.low
<< fpu.fpr[5].val.raw.high
<< fpu.fpr[5].val.raw.low
<< fpu.fpr[6].val.raw.high
<< fpu.fpr[6].val.raw.low
<< fpu.fpr[7].val.raw.high
<< fpu.fpr[7].val.raw.low
<< fpu.fpcr
<< fpu.fpsr
<< fpu.fpiar;
}
}

isize _size() override { COMPUTE_SNAPSHOT_SIZE }
u64 _checksum() override { COMPUTE_SNAPSHOT_CHECKSUM }
isize _load(const u8 *buffer) override;
isize _load(const u8 *buffer) override { LOAD_SNAPSHOT_ITEMS }
isize _save(u8 *buffer) override { SAVE_SNAPSHOT_ITEMS }
isize didLoadFromBuffer(const u8 *buffer) override;

Expand Down
30 changes: 30 additions & 0 deletions Emulator/Components/CPU/CPUTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ struct CPURevisionEnum : util::Reflection<CPURevisionEnum, CPURevision>
};
#endif

enum_long(FPU_REVISION)
{
FPU_INTERNAL,
FPU_68881,
FPU_68882
};
typedef FPU_REVISION FPURevision;

#ifdef __cplusplus
struct FPURevisionEnum : util::Reflection<FPURevisionEnum, FPURevision>
{
static constexpr long minVal = 0;
static constexpr long maxVal = FPU_68882;
static bool isValid(auto val) { return val >= minVal && val <= maxVal; }

static const char *prefix() { return "FPU"; }
static const char *key(CPURevision value)
{
switch (value) {

case FPU_INTERNAL: return "INTERNAL";
case FPU_68881: return "68881";
case FPU_68882: return "68882";
}
return "???";
}
};
#endif

enum_long(DASM_REVISION)
{
DASM_68000,
Expand Down Expand Up @@ -134,6 +163,7 @@ struct DasmSyntaxEnum : util::Reflection<DasmSyntaxEnum, DasmSyntax>
typedef struct
{
CPURevision revision;
FPURevision fpuRevision;
DasmRevision dasmRevision;
DasmSyntax dasmSyntax;
isize overclocking;
Expand Down
2 changes: 2 additions & 0 deletions Emulator/Components/CPU/Moira/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ target_include_directories(vAmigaCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_sources(vAmigaCore PRIVATE

Moira.cpp
MoiraFPU.cpp
MoiraDebugger.cpp
FpuFormats.cpp
)
Loading

0 comments on commit e53fb61

Please sign in to comment.