Compare commits

..
18 Commits
Author SHA1 Message Date
dingusdev 49a97bd487 Added ability to set up keyboard 2025-01-31 17:06:15 -07:00
joevt 2f30395d00 Break long lines.
Make them 130 characters or less.
2025-01-30 06:30:51 -07:00
dingusdev 8de2c9dafc Start i18n 2025-01-29 21:14:36 -07:00
dingusdevandjoevt 66f2c79605 Avoid MSVC compiler bug.
Use define instead of template for pm7500_settings<>

Co-Authored-By: joevt <[email protected]>
2025-01-27 20:53:27 -07:00
dingusdev 1a7ccce774 Merge pull request #136 from mihaip/upstream-nofpu-perf
Mitigate performance impact of respecting FP bit
2025-01-26 05:42:11 -07:00
Mihai Parparita 134339ae9d Mitigate performance impact of respecting FP bit
In #135 we switched from a static OpcodeGrabber table to a
curOpcodeGrabber pointer in ppc_main_opcode. This results in an extra
indirection (as far as generated assembly having an additional load),
which reduces execution speed.

Switch to making the opcode grabber into a parameter to
ppc_main_opcode, and make ppc_exec_inner keep it up to date (via an
EXEF_OPCODE exception flag).

Also fixes FPU instructions in ppctests - we now need to set the FP
MSR bit when initializing the CPU.
2025-01-25 17:58:31 -08:00
dingusdev 7df166a99e Merge pull request #135 from mihaip/upstream-nofpu
Respect FP bit in MSR when running floating point instructions
2025-01-21 06:53:14 -07:00
Mihai Parparita acc6e77ec5 Respect FP bit in MSR when running floating point instructions
Rather than running them normally, they should trigger a "no FPU"
exception. This appears to be required to allow correct graphical
rendering under Mac OS X - the FP bit cleared via mtmsr and rfi
instructions and something else appears to be relying on the exception
to be thrown.

Implemented by maintaining a parallel version of the OpcodeGrabber
table (OpcodeGrabberNoFPU) which contains alternate implementations
for all the floating point instructions. We switch the table whenever
the MSR value changes. This should minimize the overhead of doing
these checks.
2025-01-20 23:19:37 -08:00
joevt 38c4f1e4cc memaccess: Fix comments for some 64 bit macros. 2025-01-14 19:06:28 -07:00
dingusdev a6483fa895 Merge pull request #133 from mihaip/upstream-max-scsi-size
scsi: Check for maximum transfer size
2025-01-08 07:35:07 -07:00
Mihai Parparita 40617692b8 scsi: Check for maximum transfer size
Better to fail immediately than to have a buffer overflow.
2025-01-07 22:52:00 -08:00
Maxim Poliakovski a5ba986666 debugger: set maximal 68k instruction length to 12. 2025-01-06 14:30:13 +01:00
Maxim Poliakovski 497ab52ff0 nubusutils.cpp: break long lines. 2025-01-04 23:00:11 +01:00
joevt 24baf77dba nubusutils: rom_size fixes.
Support 64-bit file size.
Abort if file size > 16 MiB.
Calculate lane expanded memory size using integer arithmetic only.
Allocated memory is rounded to 4096 bytes. This can be adjusted. The lowest rounding of 4 would be "+ 3) / 4 * 4" instead of "+ 4095) / 4096 * 4096".
Abort if ROM size after lane expansion is > 16 MiB.
Expand lanes starting with the last byte instead of the first since the last byte must align with the last used lane of the memory range.
Include ROM image name in exceptions.
2025-01-04 12:27:46 -07:00
Maxim Poliakovski ce245f8885 Move SAA7187 emulator to devices/video 2025-01-03 18:11:57 +01:00
Maxim Poliakovski e508031c98 Move Athens emulator to devices/common/clockgen 2025-01-03 17:47:04 +01:00
Maxim Poliakovski 4ed13cdd04 control: break long lines. 2025-01-02 23:27:23 +01:00
Maxim Poliakovski f31f13f77b Add nubusutils for handling DeclROMs for Nubus/PDS/VDS cards. 2024-12-30 13:04:47 +01:00
45 changed files with 845 additions and 724 deletions

No files matched your search

+13 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -73,6 +73,17 @@ public:
uint16_t keys_state;
};
enum KeyboardLocale : uint32_t {
Eng_USA = 0,
Eng_GBR = 1,
Fra_FRA = 10,
Deu_DEU = 20,
Ita_ITA = 30,
Spa_ESP = 40,
Jpn_JPN = 80,
};
/* AppleJack bits 3-7 are supported but unused */
enum GamepadButton : uint8_t {
Red = 14,
@@ -112,7 +123,7 @@ public:
return event_manager;
};
void poll_events();
void poll_events(uint32_t kbd_locale);
template <typename T>
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
+14 -14
View File
@@ -28,11 +28,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
EventManager* EventManager::event_manager;
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event);
static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_locale);
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
void EventManager::poll_events()
{
void EventManager::poll_events(uint32_t kbd_locale) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -45,7 +44,7 @@ void EventManager::poll_events()
break;
case SDL_WINDOWEVENT: {
WindowEvent we;
WindowEvent we{};
we.sub_type = event.window.event;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
@@ -65,16 +64,16 @@ void EventManager::poll_events()
// Control-S: scale quality
if (event.key.keysym.sym == SDLK_s && SDL_GetModState() & KMOD_LCTRL) {
if (event.type == SDL_KEYUP) {
WindowEvent we;
WindowEvent we{};
we.sub_type = WINDOW_SCALE_QUALITY_TOGGLE;
we.window_id = event.window.windowID;
this->_window_signal.emit(we);
}
return;
}
int key_code = get_sdl_event_key_code(event.key);
int key_code = get_sdl_event_key_code(event.key, kbd_locale);
if (key_code != -1) {
KeyboardEvent ke;
KeyboardEvent ke{};
ke.key = key_code;
if (event.type == SDL_KEYDOWN) {
ke.flags = KEYBOARD_EVENT_DOWN;
@@ -96,7 +95,7 @@ void EventManager::poll_events()
break;
case SDL_MOUSEMOTION: {
MouseEvent me;
MouseEvent me{};
me.xrel = event.motion.xrel;
me.yrel = event.motion.yrel;
me.xabs = event.motion.x;
@@ -107,7 +106,7 @@ void EventManager::poll_events()
break;
case SDL_MOUSEBUTTONDOWN: {
MouseEvent me;
MouseEvent me{};
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -124,7 +123,7 @@ void EventManager::poll_events()
break;
case SDL_MOUSEBUTTONUP: {
MouseEvent me;
MouseEvent me{};
Uint8 adb_button;
switch (event.button.button) {
case SDL_BUTTON_LEFT : adb_button = 0; break;
@@ -141,7 +140,7 @@ void EventManager::poll_events()
break;
case SDL_CONTROLLERBUTTONDOWN: {
GamepadEvent ge;
GamepadEvent ge{};
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
@@ -164,7 +163,7 @@ void EventManager::poll_events()
break;
case SDL_CONTROLLERBUTTONUP: {
GamepadEvent ge;
GamepadEvent ge{};
switch (event.cbutton.button) {
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
@@ -196,7 +195,7 @@ void EventManager::poll_events()
}
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
{
switch (event.keysym.sym) {
case SDLK_a: return AdbKey_A;
@@ -331,7 +330,8 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
//Japanese keyboard
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
return AdbKey_JIS_Yen;
if (kbd_locale == Jpn_JPN)
return AdbKey_JIS_Yen;
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
return AdbKey_JIS_Underscore;
case 0XBC:
+4 -2
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-23 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -146,7 +146,9 @@ private:
std::function<void()> notify_timer_changes;
std::atomic<uint32_t> id{0};
bool cb_active = false; // true if a timer callback is executing // FIXME: Do we need this? It gets written in main thread and read in audio thread.
// FIXME: Do we need this? It gets written in main thread and read in audio thread.
bool cb_active = false; // true if a timer callback is executing
};
#endif // TIMER_MANAGER_H
-28
View File
@@ -52,7 +52,6 @@ void dppc_interpreter::power_abs(uint32_t opcode) {
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template void dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode);
@@ -84,7 +83,6 @@ void dppc_interpreter::power_clcs(uint32_t opcode) {
}
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template <field_rc rec, field_ov ov>
@@ -125,7 +123,6 @@ void dppc_interpreter::power_div(uint32_t opcode) {
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
ppc_next_instruction();
}
template void dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode);
@@ -160,7 +157,6 @@ void dppc_interpreter::power_divs(uint32_t opcode) {
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_state.spr[SPR::MQ] = remainder;
ppc_next_instruction();
}
template void dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode);
@@ -185,7 +181,6 @@ void dppc_interpreter::power_doz(uint32_t opcode) {
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template void dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode);
@@ -202,7 +197,6 @@ void dppc_interpreter::power_dozi(uint32_t opcode) {
ppc_result_d = simm - ppc_result_a;
}
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template <field_rc rec>
@@ -254,7 +248,6 @@ void dppc_interpreter::power_lscbx(uint32_t opcode) {
(is_match ? CRx_bit::CR_EQ : 0) |
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
}
ppc_next_instruction();
}
template void dppc_interpreter::power_lscbx<RC0>(uint32_t opcode);
@@ -283,7 +276,6 @@ void dppc_interpreter::power_maskg(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_maskg<RC0>(uint32_t opcode);
@@ -298,7 +290,6 @@ void dppc_interpreter::power_maskir(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_maskir<RC0>(uint32_t opcode);
@@ -321,7 +312,6 @@ void dppc_interpreter::power_mul(uint32_t opcode) {
if (rec)
ppc_changecrf0(uint32_t(product));
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template void dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode);
@@ -340,7 +330,6 @@ void dppc_interpreter::power_nabs(uint32_t opcode) {
ppc_changecrf0(ppc_result_d);
ppc_store_iresult_reg(reg_d, ppc_result_d);
ppc_next_instruction();
}
template void dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode);
@@ -363,7 +352,6 @@ void dppc_interpreter::power_rlmi(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template <field_rc rec>
@@ -381,7 +369,6 @@ void dppc_interpreter::power_rrib(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_rrib<RC0>(uint32_t opcode);
@@ -401,7 +388,6 @@ void dppc_interpreter::power_sle(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sle<RC0>(uint32_t opcode);
@@ -421,7 +407,6 @@ void dppc_interpreter::power_sleq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sleq<RC0>(uint32_t opcode);
@@ -438,7 +423,6 @@ void dppc_interpreter::power_sliq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sliq<RC0>(uint32_t opcode);
@@ -457,7 +441,6 @@ void dppc_interpreter::power_slliq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_slliq<RC0>(uint32_t opcode);
@@ -478,7 +461,6 @@ void dppc_interpreter::power_sllq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sllq<RC0>(uint32_t opcode);
@@ -500,7 +482,6 @@ void dppc_interpreter::power_slq(uint32_t opcode) {
ppc_state.spr[SPR::MQ] = rot_sh ? ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh))) : ppc_result_d;
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_slq<RC0>(uint32_t opcode);
@@ -523,7 +504,6 @@ void dppc_interpreter::power_sraiq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sraiq<RC0>(uint32_t opcode);
@@ -549,7 +529,6 @@ void dppc_interpreter::power_sraq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sraq<RC0>(uint32_t opcode);
@@ -568,7 +547,6 @@ void dppc_interpreter::power_sre(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sre<RC0>(uint32_t opcode);
@@ -593,7 +571,6 @@ void dppc_interpreter::power_srea(uint32_t opcode) {
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_state.spr[SPR::MQ] = r;
ppc_next_instruction();
}
template void dppc_interpreter::power_srea<RC0>(uint32_t opcode);
@@ -612,7 +589,6 @@ void dppc_interpreter::power_sreq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sreq<RC0>(uint32_t opcode);
@@ -628,7 +604,6 @@ void dppc_interpreter::power_sriq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_sriq<RC0>(uint32_t opcode);
@@ -647,7 +622,6 @@ void dppc_interpreter::power_srliq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_srliq<RC0>(uint32_t opcode);
@@ -670,7 +644,6 @@ void dppc_interpreter::power_srlq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_srlq<RC0>(uint32_t opcode);
@@ -693,7 +666,6 @@ void dppc_interpreter::power_srq(uint32_t opcode) {
ppc_changecrf0(ppc_result_a);
ppc_store_iresult_reg(reg_a, ppc_result_a);
ppc_next_instruction();
}
template void dppc_interpreter::power_srq<RC0>(uint32_t opcode);
+12 -13
View File
@@ -182,9 +182,10 @@ extern uint32_t rtc_lo, rtc_hi;
/* Flags for controlling interpreter execution. */
enum {
EXEF_BRANCH = 1 << 0,
EXEF_EXCEPTION = 1 << 1,
EXEF_RFI = 1 << 2,
EXEF_BRANCH = 1 << 0, // Branch taken, target PC is is in ppc_next_instruction_address
EXEF_EXCEPTION = 1 << 1, // Exception handler invoked
EXEF_RFI = 1 << 2, // RFI instruction executed
EXEF_OPC_DECODER = 1 << 3, // Opcode decoder has changed
};
enum CR_select : int32_t {
@@ -326,21 +327,16 @@ extern bool int_pin;
extern bool dec_exception_pending;
extern bool is_601; // For PowerPC 601 Emulation
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras (matches Mac OS 9 environment which can emulate MPC 601 instructions)
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras
// (matches Mac OS 9 environment which can emulate MPC 601 instructions)
extern bool is_altivec; // For Altivec Emulation
extern bool is_64bit; // For PowerPC G5 Emulation
// Make execution deterministic (ignore external input, used a fixed date, etc.)
extern bool is_deterministic;
//Instruction Handling
inline void ppc_next_instruction() {
ppc_state.pc += 4;
}
inline void ppc_set_instruction(uint32_t new_pc) {
ppc_state.pc = new_pc;
}
// Important Addressing Integers
extern uint32_t ppc_next_instruction_address;
inline uint32_t ppc_read_instruction(const uint8_t* ptr) {
return READ_DWORD_BE_A(ptr);
@@ -646,12 +642,15 @@ template <field_rc rec> extern void power_srq(uint32_t opcode);
extern uint64_t get_virt_time_ns(void);
extern void ppc_main_opcode(uint32_t opcode);
extern void ppc_main_opcode(PPCOpcode* ppc_opcode_grabber, uint32_t opcode);
extern void ppc_exec(void);
extern void ppc_exec_single(void);
extern void ppc_exec_until(uint32_t goal_addr);
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
extern PPCOpcode *ppc_opcode_grabber();
extern void ppc_msr_did_change(uint32_t old_msr_val, bool set_next_instruction_address = true);
/* debugging support API */
void print_fprs(void); /* print content of the floating-point registers */
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
+7 -6
View File
@@ -36,7 +36,6 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
#ifdef CPU_PROFILING
exceptions_processed++;
#endif
uint32_t ppc_next_instruction_address;
switch (exception_type) {
case Except_Type::EXC_SYSTEM_RESET:
@@ -58,8 +57,8 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_ISI:
if (exec_flags) {
ppc_state.spr[SPR::SRR0] = ppc_state.pc + 4;
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
}
@@ -67,7 +66,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_EXT_INT:
if (exec_flags) {
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -91,7 +90,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_DECR:
if (exec_flags) {
if (exec_flags & ~EXEF_OPC_DECODER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
@@ -115,16 +114,18 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
}
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
uint32_t old_msr_val = ppc_state.msr;
ppc_state.msr &= 0xFFFB1041;
/* copy MSR[ILE] to MSR[LE] */
ppc_state.msr = (ppc_state.msr & ~MSR::LE) | !!(ppc_state.msr & MSR::ILE);
// Don't clobber the ppc_next_instruction_address value
ppc_msr_did_change(old_msr_val, false);
if (ppc_state.msr & MSR::IP) {
ppc_next_instruction_address |= 0xFFF00000;
}
exec_flags = EXEF_EXCEPTION;
ppc_set_instruction(ppc_next_instruction_address);
// perform context synchronization for recoverable exceptions
if (exception_type != Except_Type::EXC_MACHINE_CHECK &&
+123 -52
View File
@@ -65,6 +65,8 @@ Po_Cause power_off_reason = po_enter_debugger;
SetPRS ppc_state;
uint32_t ppc_next_instruction_address; // Used for branching, setting up the NIA
unsigned exec_flags; // execution control flags
// FIXME: exec_timer is read by main thread ppc_main_opcode;
// written by audio dbdma DMAChannel::update_irq .. add_immediate_timer
@@ -151,9 +153,12 @@ public:
op_name_counts.emplace_back(op_name, pair.second);
}
size_t top_ops_size = std::min(op_name_counts.size(), size_t(20));
std::partial_sort(op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(), [](const auto& a, const auto& b) {
return b.second < a.second;
});
std::partial_sort(
op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(),
[](const auto& a, const auto& b) {
return b.second < a.second;
}
);
op_name_counts.resize(top_ops_size);
for (const auto& pair : op_name_counts) {
vars.push_back({.name = "Instruction " + pair.first,
@@ -182,12 +187,38 @@ public:
primary opcode (bits 0...5) and modifier (bits 21...31). */
static PPCOpcode OpcodeGrabber[64 * 2048];
/** Alternate lookup table when floating point instructions are disabled.
Floating point instructions are mapped to ppc_fpu_off,
everything else is the same.*/
static PPCOpcode OpcodeGrabberNoFPU[64 * 2048];
void ppc_msr_did_change(uint32_t old_msr_val, bool set_next_instruction_address) {
bool old_fp = old_msr_val & MSR::FP;
bool new_fp = ppc_state.msr & MSR::FP;
if (old_fp != new_fp) {
exec_flags |= EXEF_OPC_DECODER;
if (set_next_instruction_address) {
// Even though we're setting an exception flag, we want normal
// instruction execution to continue.
ppc_next_instruction_address = ppc_state.pc + 4;
}
}
}
PPCOpcode* ppc_opcode_grabber() {
return ppc_state.msr & MSR::FP ? OpcodeGrabber : OpcodeGrabberNoFPU;
}
/** Exception helpers. */
void ppc_illegalop(uint32_t opcode) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
void ppc_fpu_off(uint32_t opcode) {
ppc_exception_handler(Except_Type::EXC_NO_FPU, Exc_Cause::FPU_OFF);
}
void ppc_assert_int() {
int_pin = true;
if (ppc_state.msr & MSR::EE) {
@@ -205,7 +236,7 @@ void ppc_release_int() {
/** Opcode decoding functions. */
/* Dispatch using primary and modifier opcode */
void ppc_main_opcode(uint32_t opcode)
void ppc_main_opcode(PPCOpcode *opcodeGrabber, uint32_t opcode)
{
#ifdef CPU_PROFILING
num_executed_instrs++;
@@ -213,7 +244,7 @@ void ppc_main_opcode(uint32_t opcode)
num_opcodes[opcode]++;
#endif
#endif
OpcodeGrabber[(opcode >> 15 & 0x1F800) | (opcode & 0x7FF)](opcode);
opcodeGrabber[(opcode >> 15 & 0x1F800) | (opcode & 0x7FF)](opcode);
}
static long long cpu_now_ns() {
@@ -265,7 +296,7 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
uint64_t max_cycles = 0;
uint32_t page_start, eb_start, eb_end = 0;
uint32_t opcode;
uint32_t pc_old;
PPCOpcode* opcode_grabber = ppc_opcode_grabber();
uint8_t* pc_real;
while (power_on) {
@@ -283,17 +314,19 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
pc_real = mmu_translate_imem(eb_start);
}
pc_old = ppc_state.pc;
opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(opcode);
if (g_icycles++ >= max_cycles || exec_timer)
ppc_main_opcode(opcode_grabber, opcode);
if (g_icycles++ >= max_cycles || exec_timer) [[unlikely]]
max_cycles = process_events();
if (exec_flags) {
if (exec_flags & EXEF_OPC_DECODER) [[unlikely]] {
opcode_grabber = ppc_opcode_grabber();
}
// define next execution block
eb_start = ppc_state.pc;
eb_start = ppc_next_instruction_address;
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)pc_old;
pc_real += (int)eb_start - (int)ppc_state.pc;
} else {
page_start = eb_start & PPC_PAGE_MASK;
eb_end = page_start + PPC_PAGE_SIZE - 1;
@@ -301,9 +334,8 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
}
ppc_state.pc = eb_start;
exec_flags = 0;
}
else {
[[likely]]
} else { [[likely]]
ppc_state.pc += 4;
pc_real += 4;
}
@@ -324,7 +356,7 @@ void ppc_exec()
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc += 4;
ppc_state.pc = ppc_next_instruction_address;
}
while (power_on) {
@@ -338,19 +370,22 @@ void ppc_exec_single()
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc += 4;
ppc_state.pc = ppc_next_instruction_address;
exec_flags = 0;
return;
}
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
uint32_t opcode = ppc_read_instruction(pc_real);
ppc_main_opcode(opcode);
ppc_main_opcode(ppc_opcode_grabber(), opcode);
g_icycles++;
process_events();
if (exec_flags) {
ppc_state.pc = ppc_next_instruction_address;
exec_flags = 0;
} else {
ppc_state.pc += 4;
}
}
@@ -365,7 +400,7 @@ void ppc_exec_until(volatile uint32_t goal_addr)
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc += 4;
ppc_state.pc = ppc_next_instruction_address;
}
while (power_on) {
@@ -386,7 +421,7 @@ void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc += 4;
ppc_state.pc = ppc_next_instruction_address;
}
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)) {
@@ -412,17 +447,39 @@ for (uint32_t mod = 0; mod < 2048; mod++) { \
} \
} while (0)
#define OP_fp(opcode, fn) \
do { \
for (uint32_t mod = 0; mod < 2048; mod++) { \
OpcodeGrabber[((opcode) << 11) | mod] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | mod] = ppc_fpu_off; \
} \
} while (0)
#define OPX(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
} while (0)
#define OPX_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1)] = fn; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1)] = ppc_fpu_off; \
} while (0)
#define OPXd(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
} while (0)
#define OPXd_fp(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<RC1>; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x000] = ppc_fpu_off; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x001] = ppc_fpu_off; \
} while (0)
#define OPXod(opcode, subopcode, fn) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<RC0, OV0>; \
@@ -437,6 +494,14 @@ do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
} while (0)
#define OPXdc_fp(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0>; \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x001] = fn<carry, RC1>; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x000] = ppc_fpu_off; \
OpcodeGrabberNoFPU[((opcode) << 11) | ((subopcode)<<1) | 0x001] = ppc_fpu_off; \
} while (0)
#define OPXcod(opcode, subopcode, fn, carry) \
do { \
OpcodeGrabber[((opcode) << 11) | ((subopcode)<<1) | 0x000] = fn<carry, RC0, OV0>; \
@@ -458,36 +523,33 @@ do { \
} while (0)
#define OP31(subopcode, fn) OPX(31, subopcode, fn)
#define OP31_fp(subopcode, fn) OPX_fp(31, subopcode, fn)
#define OP31d(subopcode, fn) OPXd(31, subopcode, fn)
#define OP31od(subopcode, fn) OPXod(31, subopcode, fn)
#define OP31dc(subopcode, fn, carry) OPXdc(31, subopcode, fn, carry)
#define OP31cod(subopcode, fn, carry) OPXcod(31, subopcode, fn, carry)
#define OP63(subopcode, fn) OPX(63, subopcode, fn)
#define OP63d(subopcode, fn) OPXd(63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc(63, subopcode, fn, carry)
#define OP63(subopcode, fn) OPX_fp(63, subopcode, fn)
#define OP63d(subopcode, fn) OPXd_fp(63, subopcode, fn)
#define OP63dc(subopcode, fn, carry) OPXdc_fp(63, subopcode, fn, carry)
#define OP59d(subopcode, fn) \
do { \
OPXd(59, (subopcode), fn); \
OPXd_fp(59, (subopcode), fn); \
} while (0)
#define OP59cd(subopcode, fn) \
do { \
for (uint32_t ccccc = 0; ccccc < 32; ccccc++) { \
OPXd(59, (ccccc << 5) | (subopcode), fn); \
} \
} while (0)
#define OP4_ccccc10xxxx(subopcode, fn) \
do { \
for (uint32_t ccccc = 0; ccccc < 32; ccccc++) { \
OPr(4, (ccccc << 6) | (subopcode), fn); \
OPXd_fp(59, (ccccc << 5) | (subopcode), fn); \
} \
} while (0)
void initialize_ppc_opcode_table() {
std::fill_n(OpcodeGrabber, 64 * 2048, ppc_illegalop);
auto opcodeGrabberSize = sizeof(OpcodeGrabber) / sizeof(OpcodeGrabber[0]);
std::fill_n(OpcodeGrabber, opcodeGrabberSize, ppc_illegalop);
std::fill_n(OpcodeGrabberNoFPU, opcodeGrabberSize, ppc_illegalop);
OP(3, ppc_twi);
//OP(4, ppc_opcode4); - Altivec instructions not emulated yet. Uncomment once they're implemented.
OP(7, ppc_mulli);
@@ -526,14 +588,14 @@ void initialize_ppc_opcode_table() {
OP(45, ppc_stu<uint16_t>);
OP(46, ppc_lmw);
OP(47, ppc_stmw);
OP(48, ppc_lfs);
OP(49, ppc_lfsu);
OP(50, ppc_lfd);
OP(51, ppc_lfdu);
OP(52, ppc_stfs);
OP(53, ppc_stfsu);
OP(54, ppc_stfd);
OP(55, ppc_stfdu);
OP_fp(48, ppc_lfs);
OP_fp(49, ppc_lfsu);
OP_fp(50, ppc_lfd);
OP_fp(51, ppc_lfdu);
OP_fp(52, ppc_stfs);
OP_fp(53, ppc_stfsu);
OP_fp(54, ppc_stfd);
OP_fp(55, ppc_stfdu);
OPla(16, 0x0, (dppc_interpreter::ppc_bc<LK0, AA0>)); // bc
OPla(16, 0x1, (dppc_interpreter::ppc_bc<LK1, AA0>)); // bcl
@@ -595,11 +657,11 @@ void initialize_ppc_opcode_table() {
OP31(375, ppc_lhaux);
OP31(533, ppc_lswx);
OP31(534, ppc_lwbrx);
OP31(535, ppc_lfsx);
OP31(567, ppc_lfsux);
OP31_fp(535, ppc_lfsx);
OP31_fp(567, ppc_lfsux);
OP31(597, ppc_lswi);
OP31(599, ppc_lfdx);
OP31(631, ppc_lfdux);
OP31_fp(599, ppc_lfdx);
OP31_fp(631, ppc_lfdux);
OP31(790, ppc_lhbrx);
OPr(31, (150<<1) | 1, ppc_stwcx); // No Rc=0 variant.
@@ -611,13 +673,13 @@ void initialize_ppc_opcode_table() {
OP31(439, ppc_stux<uint16_t>);
OP31(661, ppc_stswx);
OP31(662, ppc_stwbrx);
OP31(663, ppc_stfsx);
OP31(695, ppc_stfsux);
OP31_fp(663, ppc_stfsx);
OP31_fp(695, ppc_stfsux);
OP31(725, ppc_stswi);
OP31(727, ppc_stfdx);
OP31(759, ppc_stfdux);
OP31_fp(727, ppc_stfdx);
OP31_fp(759, ppc_stfdux);
OP31(918, ppc_sthbrx);
if (!is_601) OP31(983, ppc_stfiwx);
if (!is_601) OP31_fp(983, ppc_stfiwx);
OP31(310, ppc_eciwx);
OP31(438, ppc_ecowx);
@@ -737,6 +799,12 @@ void initialize_ppc_opcode_table() {
OP63d(i + 30, ppc_fnmsub);
OP63d(i + 31, ppc_fnmadd);
}
for (auto i = 0; i < opcodeGrabberSize; i++) {
if (OpcodeGrabberNoFPU[i] != ppc_fpu_off) {
OpcodeGrabberNoFPU[i] = OpcodeGrabber[i];
}
}
}
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_601, uint64_t tb_freq)
@@ -747,8 +815,8 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
set_host_rounding_mode(0);
ppc_state.spr[SPR::PVR] = cpu_version;
is_601 = (cpu_version >> 16) == 1;
include_601 = !is_601 && do_include_601;
is_601 = (cpu_version >> 16) == 1;
include_601 = !is_601 & do_include_601;
initialize_ppc_opcode_table();
@@ -843,8 +911,11 @@ static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
return ppc_state.pc;
}
if (reg_name_u == "MSR") {
if (is_write)
if (is_write) {
uint32_t old_msr_val = ppc_state.msr;
ppc_state.msr = (uint32_t)val;
ppc_msr_did_change(old_msr_val);
}
return ppc_state.msr;
}
if (reg_name_u == "CR") {
+103 -187
View File
@@ -24,24 +24,24 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "ppcemu.h"
#include "ppcmacros.h"
#include "ppcmmu.h"
#include <stdlib.h>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <cmath>
#include <stdlib.h>
#include <cfloat>
inline static void ppc_update_cr1() {
// copy FPSCR[FX|FEX|VX|OX] to CR1
ppc_state.cr = (ppc_state.cr & ~CR_select::CR1_field) |
((ppc_state.fpscr >> 4) & CR_select::CR1_field);
((ppc_state.fpscr >> 4) & CR_select::CR1_field);
}
static int32_t round_to_nearest(double f) {
return static_cast<int32_t>(static_cast<int64_t>(std::floor(f + 0.5)));
return static_cast<int32_t>(static_cast<int64_t> (std::floor(f + 0.5)));
}
void set_host_rounding_mode(uint8_t mode) {
switch (mode & FPSCR::RN_MASK) {
switch(mode & FPSCR::RN_MASK) {
case 0:
std::fesetround(FE_TONEAREST);
break;
@@ -78,9 +78,9 @@ static int32_t round_to_neg_inf(double f) {
inline static bool check_snan(int check_reg) {
uint64_t check_int = FPR_INT(check_reg);
return (
((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
((check_int & ~(0xFFFULL << 52)) != 0ULL) && ((check_int & (0x1ULL << 51)) == 0ULL));
return (((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
((check_int & ~(0xFFFULL << 52)) != 0ULL) &&
((check_int & (0x1ULL << 51)) == 0ULL));
}
inline static bool snan_single_check(int reg_a) {
@@ -107,8 +107,7 @@ inline static void max_double_check(double value_a, double value_b) {
inline static bool check_qnan(int check_reg) {
uint64_t check_int = FPR_INT(check_reg);
return (
((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
return (((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
((check_int & (0x1ULL << 51)) == (0x1ULL << 51)));
}
@@ -155,7 +154,8 @@ static void ppc_update_vx() {
}
static void ppc_update_fex() {
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) & ((ppc_state.fpscr >> 3) & 0x1F));
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) &
((ppc_state.fpscr >> 3) & 0x1F));
if (fpscr_check)
ppc_state.fpscr |= VX;
@@ -173,7 +173,8 @@ void dppc_interpreter::ppc_fadd(uint32_t opcode) {
double ppc_dblresult64_d = val_reg_a + val_reg_b;
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
if (((val_reg_a == inf) && (val_reg_b == -inf)) || \
((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
@@ -183,7 +184,8 @@ void dppc_interpreter::ppc_fadd(uint32_t opcode) {
if (snan_double_check(reg_a, reg_b)) {
uint64_t qnan = 0x7FFC000000000000;
ppc_store_fpresult_int(reg_d, qnan);
} else {
}
else {
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
}
@@ -191,8 +193,6 @@ void dppc_interpreter::ppc_fadd(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fadd<RC0>(uint32_t opcode);
@@ -223,8 +223,6 @@ void dppc_interpreter::ppc_fsub(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsub<RC0>(uint32_t opcode);
@@ -263,7 +261,8 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if (snan_double_check(reg_a, reg_b)) {
uint64_t qnan = 0x7FFC000000000000;
ppc_store_fpresult_int(reg_d, qnan);
} else {
}
else {
ppc_store_fpresult_flt(reg_d, ppc_dblresult64_d);
}
@@ -271,8 +270,6 @@ void dppc_interpreter::ppc_fdiv(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fdiv<RC0>(uint32_t opcode);
@@ -307,8 +304,6 @@ void dppc_interpreter::ppc_fmul(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmul<RC0>(uint32_t opcode);
@@ -321,7 +316,8 @@ void dppc_interpreter::ppc_fmadd(uint32_t opcode) {
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == -inf)) || ((val_reg_a == -inf) && (val_reg_b == inf))) {
if (((val_reg_a == inf) && (val_reg_b == -inf)) || \
((val_reg_a == -inf) && (val_reg_b == inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
@@ -347,8 +343,6 @@ void dppc_interpreter::ppc_fmadd(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmadd<RC0>(uint32_t opcode);
@@ -391,8 +385,6 @@ void dppc_interpreter::ppc_fmsub(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmsub<RC0>(uint32_t opcode);
@@ -436,8 +428,6 @@ void dppc_interpreter::ppc_fnmadd(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnmadd<RC0>(uint32_t opcode);
@@ -476,8 +466,6 @@ void dppc_interpreter::ppc_fnmsub(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnmsub<RC0>(uint32_t opcode);
@@ -510,8 +498,6 @@ void dppc_interpreter::ppc_fadds(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fadds<RC0>(uint32_t opcode);
@@ -524,7 +510,8 @@ void dppc_interpreter::ppc_fsubs(uint32_t opcode) {
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
double inf = std::numeric_limits<double>::infinity();
if (((val_reg_a == inf) && (val_reg_b == inf)) || ((val_reg_a == -inf) && (val_reg_b == -inf))) {
if (((val_reg_a == inf) && (val_reg_b == inf)) ||
((val_reg_a == -inf) && (val_reg_b == -inf))) {
ppc_state.fpscr |= VXISI;
if (std::isnan(ppc_dblresult64_d)) {
ppc_dblresult64_d = set_endresult_nan(ppc_dblresult64_d);
@@ -542,8 +529,6 @@ void dppc_interpreter::ppc_fsubs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsubs<RC0>(uint32_t opcode);
@@ -585,8 +570,6 @@ void dppc_interpreter::ppc_fdivs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fdivs<RC0>(uint32_t opcode);
@@ -621,8 +604,6 @@ void dppc_interpreter::ppc_fmuls(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmuls<RC0>(uint32_t opcode);
@@ -658,8 +639,6 @@ void dppc_interpreter::ppc_fmadds(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmadds<RC0>(uint32_t opcode);
@@ -694,8 +673,6 @@ void dppc_interpreter::ppc_fmsubs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmsubs<RC0>(uint32_t opcode);
@@ -733,8 +710,6 @@ void dppc_interpreter::ppc_fnmadds(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnmadds<RC0>(uint32_t opcode);
@@ -776,8 +751,6 @@ void dppc_interpreter::ppc_fnmsubs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnmsubs<RC0>(uint32_t opcode);
@@ -795,8 +768,6 @@ void dppc_interpreter::ppc_fabs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fabs<RC0>(uint32_t opcode);
@@ -814,8 +785,6 @@ void dppc_interpreter::ppc_fnabs(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fnabs<RC0>(uint32_t opcode);
@@ -833,8 +802,6 @@ void dppc_interpreter::ppc_fneg(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fneg<RC0>(uint32_t opcode);
@@ -850,8 +817,6 @@ void dppc_interpreter::ppc_fsel(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsel<RC0>(uint32_t opcode);
@@ -861,7 +826,7 @@ template <field_rc rec>
void dppc_interpreter::ppc_fsqrt(uint32_t opcode) {
ppc_grab_regsfpdb(opcode);
double testd2 = (double)(GET_FPR(reg_b));
double testd2 = (double)(GET_FPR(reg_b));
double ppc_dblresult64_d = std::sqrt(testd2);
if (snan_single_check(reg_b)) {
@@ -873,8 +838,6 @@ void dppc_interpreter::ppc_fsqrt(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsqrt<RC0>(uint32_t opcode);
@@ -896,8 +859,6 @@ void dppc_interpreter::ppc_fsqrts(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fsqrts<RC0>(uint32_t opcode);
@@ -919,8 +880,6 @@ void dppc_interpreter::ppc_frsqrte(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_frsqrte<RC0>(uint32_t opcode);
@@ -941,8 +900,6 @@ void dppc_interpreter::ppc_frsp(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_frsp<RC0>(uint32_t opcode);
@@ -952,14 +909,16 @@ template <field_rc rec>
void dppc_interpreter::ppc_fres(uint32_t opcode) {
ppc_grab_regsfpdb(opcode);
double start_num = GET_FPR(reg_b);
double start_num = GET_FPR(reg_b);
double ppc_dblresult64_d = (float)(1.0 / start_num);
if (start_num == 0.0) {
ppc_state.fpscr |= FPSCR::ZX;
} else if (std::isnan(start_num)) {
}
else if (std::isnan(start_num)) {
ppc_state.fpscr |= FPSCR::VXSNAN;
} else if (std::isinf(start_num)) {
}
else if (std::isinf(start_num)){
ppc_state.fpscr &= 0xFFF9FFFF;
ppc_state.fpscr |= FPSCR::VXSNAN;
}
@@ -973,8 +932,6 @@ void dppc_interpreter::ppc_fres(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fres<RC0>(uint32_t opcode);
@@ -988,21 +945,22 @@ static void round_to_int(uint32_t opcode, const uint8_t mode, field_rc rec) {
ppc_state.fpscr &= ~(FPSCR::FR | FPSCR::FI);
ppc_state.fpscr |= (FPSCR::VXCVI | FPSCR::VX);
if (check_snan(reg_b)) // issnan
if (check_snan(reg_b)) // issnan
ppc_state.fpscr |= FPSCR::VXSNAN;
if (ppc_state.fpscr & FPSCR::VE) {
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
ppc_floating_point_exception(opcode);
} else {
ppc_store_fpresult_int(reg_d, 0xFFF8000080000000ULL);
}
} else if (val_reg_b > static_cast<double>(0x7fffffff) || val_reg_b < -static_cast<double>(0x80000000)) {
} else if (val_reg_b > static_cast<double>(0x7fffffff) ||
val_reg_b < -static_cast<double>(0x80000000)) {
ppc_state.fpscr &= ~(FPSCR::FR | FPSCR::FI);
ppc_state.fpscr |= (FPSCR::VXCVI | FPSCR::VX);
if (ppc_state.fpscr & FPSCR::VE) {
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
ppc_floating_point_exception(opcode);
} else {
if (val_reg_b >= 0.0f)
@@ -1039,7 +997,6 @@ static void round_to_int(uint32_t opcode, const uint8_t mode, field_rc rec) {
template <field_rc rec>
void dppc_interpreter::ppc_fctiw(uint32_t opcode) {
round_to_int(opcode, ppc_state.fpscr & 0x3, rec);
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fctiw<RC0>(uint32_t opcode);
@@ -1048,7 +1005,6 @@ template void dppc_interpreter::ppc_fctiw<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::ppc_fctiwz(uint32_t opcode) {
round_to_int(opcode, 1, rec);
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fctiwz<RC0>(uint32_t opcode);
@@ -1062,7 +1018,6 @@ void dppc_interpreter::ppc_lfs(uint32_t opcode) {
ea += (reg_a) ? val_reg_a : 0;
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfsu(uint32_t opcode) {
@@ -1074,34 +1029,32 @@ void dppc_interpreter::ppc_lfsu(uint32_t opcode) {
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_store_iresult_reg(reg_a, ea);
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_lfsx(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfsux(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode);
if (reg_a != 0) {
uint32_t ea = val_reg_a + val_reg_b;
uint32_t ea = val_reg_a + val_reg_b;
uint32_t result = mmu_read_vmem<uint32_t>(opcode, ea);
ppc_store_fpresult_flt(reg_d, *(float*)(&result));
ppc_store_iresult_reg(reg_a, ea);
} else {
}
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfd(uint32_t opcode) {
@@ -1110,7 +1063,6 @@ void dppc_interpreter::ppc_lfd(uint32_t opcode) {
ea += (reg_a) ? val_reg_a : 0;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d);
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfdu(uint32_t opcode) {
@@ -1122,35 +1074,31 @@ void dppc_interpreter::ppc_lfdu(uint32_t opcode) {
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d);
ppc_store_iresult_reg(reg_a, ea);
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_lfdx(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d);
ppc_next_instruction();
}
void dppc_interpreter::ppc_lfdux(uint32_t opcode) {
ppc_grab_regsfpdiab(opcode);
if (reg_a != 0) {
uint32_t ea = val_reg_a + val_reg_b;
uint32_t ea = val_reg_a + val_reg_b;
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(opcode, ea);
ppc_store_fpresult_int(reg_d, ppc_result64_d);
ppc_store_iresult_reg(reg_a, ea);
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_stfs(uint32_t opcode) {
@@ -1159,7 +1107,6 @@ void dppc_interpreter::ppc_stfs(uint32_t opcode) {
ea += (reg_a) ? val_reg_a : 0;
float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfsu(uint32_t opcode) {
@@ -1171,36 +1118,31 @@ void dppc_interpreter::ppc_stfsu(uint32_t opcode) {
float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
ppc_store_iresult_reg(reg_a, ea);
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_stfsx(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfsux(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode);
if (reg_a != 0) {
uint32_t ea = val_reg_a + val_reg_b;
uint32_t ea = val_reg_a + val_reg_b;
float result = float(GET_FPR(reg_s));
mmu_write_vmem<uint32_t>(opcode, ea, *(uint32_t*)(&result));
ppc_store_iresult_reg(reg_a, ea);
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_stfd(uint32_t opcode) {
@@ -1208,7 +1150,6 @@ void dppc_interpreter::ppc_stfd(uint32_t opcode) {
uint32_t ea = int32_t(int16_t(opcode));
ea += reg_a ? val_reg_a : 0;
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfdu(uint32_t opcode) {
@@ -1219,19 +1160,16 @@ void dppc_interpreter::ppc_stfdu(uint32_t opcode) {
ea += val_reg_a;
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
ppc_store_iresult_reg(reg_a, ea);
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_stfdx(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
ppc_next_instruction();
}
void dppc_interpreter::ppc_stfdux(uint32_t opcode) {
@@ -1241,19 +1179,16 @@ void dppc_interpreter::ppc_stfdux(uint32_t opcode) {
uint32_t ea = val_reg_a + val_reg_b;
mmu_write_vmem<uint64_t>(opcode, ea, FPR_INT(reg_s));
ppc_store_iresult_reg(reg_a, ea);
} else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
return;
}
ppc_next_instruction();
else {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
}
void dppc_interpreter::ppc_stfiwx(uint32_t opcode) {
ppc_grab_regsfpsiab(opcode);
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
mmu_write_vmem<uint32_t>(opcode, ea, uint32_t(FPR_INT(reg_s)));
ppc_next_instruction();
}
// Floating Point Register Transfer
@@ -1265,8 +1200,6 @@ void dppc_interpreter::ppc_fmr(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_fmr<RC0>(uint32_t opcode);
@@ -1276,13 +1209,10 @@ template <field_601 for601, field_rc rec>
void dppc_interpreter::ppc_mffs(uint32_t opcode) {
int reg_d = (opcode >> 21) & 31;
ppc_store_fpresult_int(
reg_d, uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL));
ppc_store_fpresult_int(reg_d, uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL));
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mffs<NOT601, RC0>(uint32_t opcode);
@@ -1297,25 +1227,17 @@ void dppc_interpreter::ppc_mtfsf(uint32_t opcode) {
uint32_t cr_mask = 0;
if (fm == 0xFFU) // the fast case
if (fm == 0xFFU) // the fast case
cr_mask = 0xFFFFFFFFUL;
else { // the slow case
if (fm & 0x80)
cr_mask |= 0xF0000000UL;
if (fm & 0x40)
cr_mask |= 0x0F000000UL;
if (fm & 0x20)
cr_mask |= 0x00F00000UL;
if (fm & 0x10)
cr_mask |= 0x000F0000UL;
if (fm & 0x08)
cr_mask |= 0x0000F000UL;
if (fm & 0x04)
cr_mask |= 0x00000F00UL;
if (fm & 0x02)
cr_mask |= 0x000000F0UL;
if (fm & 0x01)
cr_mask |= 0x0000000FUL;
else { // the slow case
if (fm & 0x80) cr_mask |= 0xF0000000UL;
if (fm & 0x40) cr_mask |= 0x0F000000UL;
if (fm & 0x20) cr_mask |= 0x00F00000UL;
if (fm & 0x10) cr_mask |= 0x000F0000UL;
if (fm & 0x08) cr_mask |= 0x0000F000UL;
if (fm & 0x04) cr_mask |= 0x00000F00UL;
if (fm & 0x02) cr_mask |= 0x000000F0UL;
if (fm & 0x01) cr_mask |= 0x0000000FUL;
}
// ensure neither FEX nor VX will be changed
@@ -1326,8 +1248,6 @@ void dppc_interpreter::ppc_mtfsf(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mtfsf<RC0>(uint32_t opcode);
@@ -1350,8 +1270,6 @@ void dppc_interpreter::ppc_mtfsfi(uint32_t opcode) {
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mtfsfi<RC0>(uint32_t opcode);
@@ -1360,14 +1278,12 @@ template void dppc_interpreter::ppc_mtfsfi<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::ppc_mtfsb0(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1F;
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
}
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mtfsb0<RC0>(uint32_t opcode);
@@ -1376,14 +1292,12 @@ template void dppc_interpreter::ppc_mtfsb0<RC1>(uint32_t opcode);
template <field_rc rec>
void dppc_interpreter::ppc_mtfsb1(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1F;
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
ppc_state.fpscr |= (0x80000000UL >> crf_d);
}
if (rec)
ppc_update_cr1();
ppc_next_instruction();
}
template void dppc_interpreter::ppc_mtfsb1<RC0>(uint32_t opcode);
@@ -1392,18 +1306,18 @@ template void dppc_interpreter::ppc_mtfsb1<RC1>(uint32_t opcode);
void dppc_interpreter::ppc_mcrfs(uint32_t opcode) {
int crf_d = (opcode >> 21) & 0x1C;
int crf_s = (opcode >> 16) & 0x1C;
ppc_state.cr =
((ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d));
ppc_state.fpscr &= ~(
(0xF0000000UL >> crf_s) &
(
// keep only the FPSCR bits that can be explicitly cleared
FPSCR::FX | FPSCR::OX | FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ | FPSCR::VXVC |
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI));
ppc_next_instruction();
ppc_state.cr = (
(ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d)
);
ppc_state.fpscr &= ~((0xF0000000UL >> crf_s) & (
// keep only the FPSCR bits that can be explicitly cleared
FPSCR::FX | FPSCR::OX |
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
FPSCR::VXVC |
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
));
}
// Floating Point Comparisons
@@ -1422,19 +1336,20 @@ void dppc_interpreter::ppc_fcmpo(uint32_t opcode) {
if (!(ppc_state.fpscr & FEX) || check_qnan(reg_a) || check_qnan(reg_b)) {
ppc_state.fpscr |= VXVC;
}
} else if (db_test_a < db_test_b) {
}
else if (db_test_a < db_test_b) {
cmp_c |= CRx_bit::CR_LT;
} else if (db_test_a > db_test_b) {
}
else if (db_test_a > db_test_b) {
cmp_c |= CRx_bit::CR_GT;
} else {
}
else {
cmp_c |= CRx_bit::CR_EQ;
}
ppc_state.fpscr &= ~VE; // kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
ppc_next_instruction();
ppc_state.fpscr &= ~VE; //kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
}
void dppc_interpreter::ppc_fcmpu(uint32_t opcode) {
@@ -1447,17 +1362,18 @@ void dppc_interpreter::ppc_fcmpu(uint32_t opcode) {
if (check_snan(reg_a) || check_snan(reg_b)) {
ppc_state.fpscr |= FX | VX | VXSNAN;
}
} else if (db_test_a < db_test_b) {
}
else if (db_test_a < db_test_b) {
cmp_c |= CRx_bit::CR_LT;
} else if (db_test_a > db_test_b) {
}
else if (db_test_a > db_test_b) {
cmp_c |= CRx_bit::CR_GT;
} else {
}
else {
cmp_c |= CRx_bit::CR_EQ;
}
ppc_state.fpscr &= ~VE; // kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.fpscr &= ~VE; //kludge to pass tests
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
ppc_next_instruction();
}
+177 -289
View File
File diff suppressed because it is too large. Load diff
+9 -5
View File
@@ -46,7 +46,7 @@ void xer_ov_test(string mnem, uint32_t opcode) {
ppc_state.gpr[3] = 2;
ppc_state.gpr[4] = 2;
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
ppc_main_opcode(opcode);
ppc_main_opcode(ppc_opcode_grabber(), opcode);
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
nfailed++;
@@ -150,7 +150,7 @@ static void read_test_data() {
ppc_state.spr[SPR::XER] = 0;
ppc_state.cr = 0;
ppc_main_opcode(opcode);
ppc_main_opcode(ppc_opcode_grabber(), opcode);
ntested++;
@@ -292,7 +292,7 @@ static void read_test_float_data() {
ppc_state.cr = 0;
ppc_main_opcode(opcode);
ppc_main_opcode(ppc_opcode_grabber(), opcode);
ntested++;
@@ -302,10 +302,11 @@ static void read_test_float_data() {
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
(ppc_state.fpscr != check_fpscr) ||
(ppc_state.cr != check_cr)) {
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 << ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1
<< ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr
<< ", CR=0x"
<< hex << check_cr << endl;
<< hex << check_cr << endl;
cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex
<< ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl;
cout << "Test file line #: " << dec << lineno << endl << endl;
@@ -318,6 +319,9 @@ static void read_test_float_data() {
int main() {
is_601 = true;
initialize_ppc_opcode_table(); //kludge
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
// Also set MSR[FP] bit so we can test FPU instructions.
ppc_state.msr = (MSR::ME | MSR::IP | MSR::FP);
cout << "Running DingusPPC emulator tests..." << endl << endl;
+2 -2
View File
@@ -111,7 +111,7 @@ static void show_help() {
static uint32_t disasm_68k(uint32_t count, uint32_t address) {
csh cs_handle;
uint8_t code[10];
uint8_t code[12];
size_t code_size;
uint64_t dis_addr;
@@ -123,7 +123,7 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
cs_insn* insn = cs_malloc(cs_handle);
for (; power_on && count > 0; count--) {
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
// prefetch opcode bytes (a 68k instruction can occupy 2...12 bytes)
for (int i = 0; i < sizeof(code); i++) {
code[i] = mem_read_dbg(address + i, 1);
}
+2
View File
@@ -8,8 +8,10 @@ include_directories("${PROJECT_SOURCE_DIR}"
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
+3 -1
View File
@@ -29,7 +29,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <loguru.hpp>
AdbMouse::AdbMouse(
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution) : AdbDevice(name), device_class(device_class), num_buttons(num_buttons), num_bits(num_bits), resolution(resolution) {
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution
) : AdbDevice(name), device_class(device_class), num_buttons(num_buttons), num_bits(num_bits), resolution(resolution)
{
EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
this->reset();
+4 -2
View File
@@ -241,7 +241,8 @@ void AtapiCdrom::perform_packet_command() {
else {
disk_image_byte_count = (this->r_byte_count / bytes_per_block) * this->block_size; // whole blocks
if ((this->r_byte_count % bytes_per_block) > bytes_prolog) { // partial block
int disk_image_byte_count_partial_block = (this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
int disk_image_byte_count_partial_block =
(this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
if (disk_image_byte_count_partial_block > this->block_size) { // partial block includes some epilog?
disk_image_byte_count_partial_block = this->block_size; // // remove epilog from partial block
}
@@ -252,7 +253,8 @@ void AtapiCdrom::perform_packet_command() {
int disk_image_bytes_received = this->read_begin(xfer_len, disk_image_byte_count);
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog + (disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog +
(disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
if (bytes_received > this->r_byte_count) { // if partial epilog or partial prolog
bytes_received = this->r_byte_count; // confine to r_byte_count
}
@@ -31,7 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
This is helpful especially for calculating video parameters.
*/
#include <devices/common/i2c/athens.h>
#include <devices/common/clockgen/athens.h>
#include <loguru.hpp>
#include <algorithm>
File renamed without changes.
+6 -4
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -27,11 +27,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef I2C_H
#define I2C_H
#include <stdexcept>
#include <cstring>
#include <string>
#include <loguru.hpp>
#include <cinttypes>
#include <cstring>
#include <stdexcept>
#include <string>
/** Base class for I2C devices */
class I2CDevice {
public:
+156
View File
@@ -0,0 +1,156 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <devices/common/hwcomponent.h>
#include <devices/common/nubus/nubusutils.h>
#include <devices/memctrl/memctrlbase.h>
#include <machines/machinebase.h>
#include <loguru.hpp>
#include <memaccess.h>
#include <cinttypes>
#include <fstream>
#include <sstream>
uint32_t calculate_rom_crc(uint8_t *data_ptr, int length)
{
uint32_t sum = 0;
for (int i = 0; i < length; i++) {
// rotate sum left by one bit
if (sum & 0x80000000UL)
sum = (sum << 1) | 1;
else
sum = (sum << 1) | 0;
sum += data_ptr[i];
}
return sum;
}
int load_declaration_rom(const std::string rom_path, int slot_num)
{
std::ifstream rom_file;
int result = 0;
try {
rom_file.open(rom_path, std::ios::in | std::ios::binary);
if (rom_file.fail())
throw std::runtime_error("could not open declaration ROM image " + rom_path);
// determine image size
rom_file.seekg(0, std::ios::end);
uint64_t rom_size = rom_file.tellg();
if (rom_size > 16 * 1024 * 1024)
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
std::to_string(rom_size) + " is too large");
// load it
auto rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[rom_size]);
rom_file.seekg(0, std::ios::beg);
rom_file.read((char *)rom_data.get(), rom_size);
// verify image data
uint8_t byte_lane = rom_data[rom_size - 1];
if ((byte_lane & 0xF) != ((byte_lane >> 4) ^ 0xF))
throw std::runtime_error("declaration ROM image " + rom_path +
" has invalid byte lane value");
if (READ_DWORD_BE_A(&rom_data[rom_size - 6]) != 0x5A932BC7UL)
throw std::runtime_error("declaration ROM image " + rom_path +
" has invalid test pattern");
if (rom_data[rom_size - 7] != 1)
throw std::runtime_error("declaration ROM image " + rom_path +
" has unsupported format");
uint32_t crc = READ_DWORD_BE_A(&rom_data[rom_size - 12]);
int hdr_length = READ_DWORD_BE_A(&rom_data[rom_size - 16]);
// patch the CRC field of the format header to 0
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], 0);
uint32_t test_crc = calculate_rom_crc(rom_data.get(), hdr_length);
// restore the CRC field value
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], crc);
if (test_crc != crc) {
std::stringstream err;
err << "declaration ROM image " + rom_path + " has invalid CRC, expected = 0x"
<< std::hex << crc << ", got = 0x" << std::hex << test_crc;
throw std::runtime_error(err.str());
}
int lanes_used = 0;
// count meaningful lanes in a data quad
for (int i = 0; i < 4; i++) {
if (byte_lane & (1 << i))
lanes_used++;
}
// padded_len is the size in bytes of all pages needed to contain all the bytes of the ROM
uint32_t padded_len =
uint32_t(((rom_size * 4 + lanes_used - 1) / lanes_used + 4095) / 4096 * 4096);
if (padded_len > 16 * 1024 * 1024)
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
std::to_string(rom_size) + " is too large");
// calculate starting physical address of the ROM
uint32_t rom_phys_start = (0xF0FFFFFFUL | ((slot_num & 0xF) << 24)) - padded_len + 1;
auto mem_crtl = dynamic_cast<MemCtrlBase*>(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
if (!mem_crtl->add_rom_region(rom_phys_start, padded_len))
throw std::runtime_error("could not allocate ROM space for declaration ROM image " +
rom_path);
int data_pos = int(rom_size) - 1;
auto new_data = std::unique_ptr<uint8_t[]> (new uint8_t[padded_len]);
// prepare new ROM data by copying over used lanes
// and padding unused lanes with 0xFF
// NOTE: speed uncritical - don't optimize!
for (int i = padded_len - 1; i >= 0; ) {
for (int b = 8; i>= 0 && b != 0; b >>= 1) {
if (data_pos >= 0 && (byte_lane & b))
new_data[i--] = rom_data[data_pos--];
else
new_data[i--] = 0xFF;
}
}
// move padded ROM data to the memory region
mem_crtl->set_data(rom_phys_start, new_data.get(), padded_len);
}
catch (const std::exception& exc) {
LOG_F(ERROR, "load_declaration_rom failed: %s", exc.what());
result = -1;
}
rom_file.close();
return result;
}
+30
View File
@@ -0,0 +1,30 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef NUBUS_UTILS_H
#define NUBUS_UTILS_H
#include <cinttypes>
#include <string>
int load_declaration_rom(const std::string rom_path, int slot_num);
#endif // NUBUS_UTILS_H
+4 -2
View File
@@ -191,7 +191,8 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Io_32_Bit:
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
if (value != 0xFFFFFFFFUL && (value & ~3) != (value & bar_cfg & ~3)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)", this->get_name().c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~3), (value & bar_cfg & ~3));
}
break;
@@ -200,7 +201,8 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
case PCIBarType::Mem_64_Bit_Lo:
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
if (value != 0xFFFFFFFFUL && (value & ~0xF) != (value & bar_cfg & ~0xF)) {
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)", this->get_name().c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
this->get_name().c_str(), bar_num, (value & ~0xF), (value & bar_cfg & ~0xF));
}
break;
+3 -1
View File
@@ -47,7 +47,9 @@ enum {
PCI_CFG_BAR0 = 0x10, // base address register 0 (type 0, 1, and 2)
PCI_CFG_BAR1 = 0x14, // base address register 1 (type 0 and 1)
PCI_CFG_DWORD_13 = 0x34, // capabilities pointer (type 0 and 1)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0); Bridge Control (Type 1 and 2); Int_Pin and Int_Line registers (type 0, 1, and 2)
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0)
// Bridge Control (Type 1 and 2)
// Int_Pin and Int_Line registers (type 0, 1, and 2)
};
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
+2 -1
View File
@@ -81,7 +81,8 @@ void PCIHost::pci_unregister_device(int dev_fun_num)
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
LOG_F(
// FIXME: need destructors to remove memory regions and downstream devices.
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs a working destructor to unregister memory and downstream devices etc.)",
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs "
"a working destructor to unregister memory and downstream devices etc.)",
hwc ? hwc->get_name().c_str() : "PCIHost", dev_instance->get_name().c_str()
);
+17 -7
View File
@@ -223,7 +223,8 @@ void ScsiHardDisk::inquiry() {
int lun;
if (this->last_selection_has_atention) {
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(), alloc_len, this->last_selection_message);
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7",
this->name.c_str(), alloc_len, this->last_selection_message);
lun = this->last_selection_message & 7;
}
else {
@@ -455,14 +456,18 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
return;
uint32_t transfer_size = transfer_len;
std::memset(this->data_buf, 0, sizeof(this->data_buf));
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
size_t data_buf_size = sizeof(this->data_buf);
if (transfer_size > data_buf_size) {
ABORT_F("%s: cannot read %d bytes (%d sectors * %d bytes/sector), maximum size is %lu bytes",
this->name.c_str(), transfer_size, transfer_len, this->sector_size, data_buf_size);
}
std::memset(this->data_buf, 0, data_buf_size);
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->disk_img.read(this->data_buf, device_offset, transfer_size);
@@ -474,12 +479,17 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
uint32_t transfer_size = transfer_len;
if (cmd_len == 6 && transfer_len == 0) {
transfer_size = 256;
}
transfer_size *= this->sector_size;
size_t data_buf_size = sizeof(this->data_buf);
if (transfer_size > data_buf_size) {
ABORT_F("%s: cannot write %d bytes (%d sectors * %d bytes/sector), maximum size is %lu bytes",
this->name.c_str(), transfer_size, transfer_len, this->sector_size, data_buf_size);
}
uint64_t device_offset = (uint64_t)lba * this->sector_size;
this->incoming_size = transfer_size;
+2 -1
View File
@@ -67,7 +67,8 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
if (this->cur_track < 0)
this->cur_track = 0;
else if (this->cur_track >= this->num_tracks) {
LOG_F(ERROR, "%s: track:%d is greater than max track:%d", this->get_name().c_str(), this->cur_track, this->num_tracks - 1);
LOG_F(ERROR, "%s: track:%d is greater than max track:%d",
this->get_name().c_str(), this->cur_track, this->num_tracks - 1);
this->cur_track = this->num_tracks - 1;
}
this->track_zero = this->cur_track == 0;
+4 -1
View File
@@ -252,7 +252,10 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
case MIO_GC_DMA_AUDIO_OUT:
return this->snd_out_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_AUDIO_IN:
//LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN read @%02x.%c", this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
#if 0
LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN read @%02x.%c",
this->name.c_str(), offset & 0xFF, SIZE_ARG(size));
#endif
return 0; // this->snd_in_dma->reg_read(offset & 0xFF, size);
case MIO_GC_DMA_SCSI_MESH:
if (this->mesh_dma) {
+8 -4
View File
@@ -390,8 +390,10 @@ void HeathrowIC::feature_control(const uint32_t value)
}
}
#define FIRST_INT1_BIT 12 // The first ten are DMA, the next 2 appear to be unused. We'll map 1:1 the INT1 bits 31..12 (0x1F..0x0C) as IRQ_ID bits.
#define FIRST_INT2_BIT 2 // Skip the first two which are Ethernet DMA. We'll map INT2 bits 13..2 (interrupts 45..34 or 0x2D..0x22) as IRQ_ID bits 11..0.
#define FIRST_INT1_BIT 12 // The first ten are DMA, the next 2 appear to be unused.
// We'll map 1:1 the INT1 bits 31..12 (0x1F..0x0C) as IRQ_ID bits.
#define FIRST_INT2_BIT 2 // Skip the first two which are Ethernet DMA.
// We'll map INT2 bits 13..2 (interrupts 45..34 or 0x2D..0x22) as IRQ_ID bits 11..0.
#define FIRST_INT1_IRQ_ID_BIT 12 // Same as INT1_BIT so there won't be any shifting required.
#define FIRST_INT2_IRQ_ID_BIT 0
@@ -481,7 +483,8 @@ void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
IRQ_ID_TO_INT2_MASK(irq_id);
#if 0
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change2:%08x state:%d",
this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0, this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state
this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0,
this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state
);
#endif
// native mode: set IRQ bits in int_events2 on a 0-to-1 transition
@@ -504,7 +507,8 @@ void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
// emulated mode: set IRQ bits in int_events1 on all transitions
#if 0
LOG_F(INFO, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change1:%08x state:%d",
this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0, this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state);
this->name.c_str(), this->int_events1 + 0, this->int_events2 + 0,
this->int_levels1 + 0, this->int_levels2 + 0, irq_id, irq_line_state);
#endif
if ((this->int_mask1 & MACIO_INT_MODE) ||
(irq_line_state && !(this->int_levels1 & irq_id))) {
+4 -1
View File
@@ -394,7 +394,10 @@ bool CharIoSocket::rcv_char_available_now()
int received = (int)recv(this->sockfd, &c, 1, 0);
if (received == -1) {
if (this->acceptfd == -1) {
//LOG_F(INFO, "socket sock read (not accepted yet) err: %s", strerror(errno)); // this happens once before accept
#if 0
LOG_F(INFO, "socket sock read (not accepted yet) err: %s",
strerror(errno)); // this happens once before accept
#endif
}
else {
LOG_F(INFO, "socket sock read err: %s", strerror(errno)); // should never happen
+3 -1
View File
@@ -275,7 +275,9 @@ void EsccChannel::write_reg(int reg_num, uint8_t value)
this->read_regs[RR0] |= RR0_SYNC_HUNT;
}
}
this->write_regs[WR3] = (this->write_regs[WR3] & (WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE)) | (value & ~(WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE));
this->write_regs[WR3] =
(this->write_regs[WR3] & (WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE)) |
(value & ~(WR3_RX_ENABLE | WR3_ENTER_HUNT_MODE));
return;
case WR7:
if (this->write_regs[WR15] & WR15_SDLC_HDLC_ENHANCEMENT_ENABLE) {
+11 -6
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-24 divingkatae and maximum
Copyright (C) 2018-25 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -215,7 +215,8 @@ enum
WR3_SYNC_CHARACTER_LOAD_INHIBIT = 1 << 1,
WR3_RX_ENABLE = 1 << 0,
// WR4 - Transmit/Receiver Miscellaneous Parameters and Modes // Transmit/Receive miscellaneous parameters and codes, clock rate, number of sync characters, stop bits, parity
// WR4 - Transmit/Receiver Miscellaneous Parameters and Modes
// Transmit/Receive miscellaneous parameters and codes, clock rate, number of sync characters, stop bits, parity
WR4_CLOCK_RATE = 3 << 6,
WR4_X1_CLOCK_MODE = 0 << 6,
@@ -257,7 +258,8 @@ enum
// WR8 - Transmit buffer
// WR9 - Master Interrupt Control // Master interrupt control and reset (accessed through either channel), reset bits, control interrupt daisy chain
// WR9 - Master Interrupt Control
// Master interrupt control and reset (accessed through either channel), reset bits, control interrupt daisy chain
WR9_RESET_COMMAND_BITS = 3 << 6,
WR9_NO_RESET = 0 << 6,
@@ -272,7 +274,8 @@ enum
WR9_NO_VECTOR = 1 << 1,
WR9_VECTOR_INCLUDES_STATUS = 1 << 0,
// WR10 - Miscellaneous Transmitter/Receiver Control Bits // Miscellaneous transmitter/receiver control bits, NRZI, NRZ, FM encoding, CRC reset
// WR10 - Miscellaneous Transmitter/Receiver Control Bits
// Miscellaneous transmitter/receiver control bits, NRZI, NRZ, FM encoding, CRC reset
WR10_CRC_PRESET = 1 << 7,
WR10_DATA_ENCODING = 3 << 5,
@@ -318,7 +321,8 @@ enum
// WR13 - Upper Byte of Baud Rate Generator Time Constant
// WR14 - Miscellaneous Control Bits // Miscellaneous control bits: baud rate generator, Phase-Locked Loop control, auto echo, local loopback
// WR14 - Miscellaneous Control Bits
// Miscellaneous control bits: baud rate generator, Phase-Locked Loop control, auto echo, local loopback
WR14_DPLL_COMMAND_BITS = 7 << 5,
WR14_DPLL_NULL_COMMAND = 0 << 5,
@@ -335,7 +339,8 @@ enum
WR14_BR_GENERATOR_SOURCE = 1 << 1,
WR14_BR_GENERATOR_ENABLE = 1 << 0,
// WR15 - External/Status Interrupt Control // External/Status interrupt control information-control external conditions causing interrupts
// WR15 - External/Status Interrupt Control
// External/Status interrupt control information-control external conditions causing interrupts
WR15_SDLC_HDLC_ENHANCEMENT_ENABLE = 1 << 0,
WR15_ZERO_COUNT_IE = 1 << 1,
+2 -1
View File
@@ -223,7 +223,8 @@ int SoundServer::start_out_stream()
{
if (is_deterministic) {
LOG_F(9, "Starting sound output deterministic polling.");
impl->deterministic_poll_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(10), impl->deterministic_poll_cb);
impl->deterministic_poll_timer =
TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(10), impl->deterministic_poll_cb);
return 0;
}
return cubeb_stream_start(impl->out_stream);
+3 -1
View File
@@ -70,7 +70,9 @@ enum RamdacRegs : uint8_t {
CURSOR_POS_HI = 0x10, // cursor position, high-order byte
CURSOR_POS_LO = 0x11, // cursor position, low-order byte
MISC_CTRL = 0x20, // miscellaneus control bits ; Dacula: read ; when 1MB VRAM then write (mode&15) else write (mode)
DBL_BUF_CTRL = 0x21, // double buffer control bits ; Dacula: write 4; Radical: set to 0 if using optional bank (bankb) in Open Firmware or for 2nd page in ndrv
DBL_BUF_CTRL = 0x21, // double buffer control bits ;
// - Dacula: write 4;
// - Radical: set to 0 if using optional bank (bankb) in Open Firmware or for 2nd page in ndrv
TEST_CTRL = 0x22, // enable/disable DAC tests ; Dacula: write 0
// multipurpose section registers (DACula only)
+2 -1
View File
@@ -398,7 +398,8 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
if (bit_changed(old_value, new_value, ATI_CRTC_ENABLE)
|| extract_bits(old_value, ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size) != extract_bits(new_value, ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size)
|| extract_bits(old_value, ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size) !=
extract_bits(new_value, ATI_CRTC_PIX_WIDTH, ATI_CRTC_PIX_WIDTH_size)
) {
draw_fb = true;
if (bit_set(new_value, ATI_CRTC_ENABLE) &&
+20 -11
View File
@@ -36,7 +36,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Kudos to joevt#3510 for his precious technical help and HW hacking.
*/
#include <devices/common/i2c/athens.h>
#include <devices/common/i2c/i2c.h>
#include <devices/deviceregistry.h>
#include <devices/ioctrl/macio.h>
@@ -322,7 +321,8 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
break;
case ControlRegs::MON_SENSE:
value = (this->cur_mon_id << 6) | this->mon_sense;
LOG_F(CONTROL, "%s: read MON_SENSE %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(CONTROL, "%s: read MON_SENSE %03x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
break;
case ControlRegs::MISC_ENABLES:
value = this->enables;
@@ -349,7 +349,8 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
details.offset = offset & 3;
uint32_t result = pci_conv_rd_data(value, value, details);
if ((offset & 3) || (size != 4)) {
LOG_F(WARNING, "%s: read %s %03x.%c = %08x -> %0*x", this->name.c_str(), get_name_controlreg(offset), offset, SIZE_ARG(size), value, size * 2, result);
LOG_F(WARNING, "%s: read %s %03x.%c = %08x -> %0*x", this->name.c_str(),
get_name_controlreg(offset), offset, SIZE_ARG(size), value, size * 2, result);
}
return result;
@@ -430,9 +431,11 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
case ControlRegs::PIPE_DELAY:
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0x3FF;
if (value & ~0x3FF)
LOG_F(ERROR, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(ERROR, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
else
LOG_F(CONTROL, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(CONTROL, "%s: write PIPE_DELAY %03x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
if (this->display_enabled) {
this->enable_display();
}
@@ -440,9 +443,11 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
case ControlRegs::HEQ:
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0xFFU;
if (value & ~0xFFU)
LOG_F(ERROR, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(ERROR, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
else
LOG_F(CONTROL, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(CONTROL, "%s: write HEQ %03x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
if (this->display_enabled) {
this->enable_display();
}
@@ -463,9 +468,11 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
case ControlRegs::HSERR:
this->swatch_params[(offset >> 4) - ControlRegs::VFPEQ] = value & 0xFFF;
if (value & ~0xFFF)
LOG_F(ERROR, "%s: write %s %03x.%c = %0*x", this->name.c_str(), get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
LOG_F(ERROR, "%s: write %s %03x.%c = %0*x", this->name.c_str(),
get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
else
LOG_F(CONTROL, "%s: write %s %03x.%c = %0*x", this->name.c_str(), get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
LOG_F(CONTROL, "%s: write %s %03x.%c = %0*x", this->name.c_str(),
get_name_controlreg(offset), offset, SIZE_ARG(size), size * 2, value);
if (this->display_enabled) {
this->enable_display();
}
@@ -511,9 +518,11 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
break;
case ControlRegs::MON_SENSE: {
if (value & ~0x3F)
LOG_F(ERROR, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(ERROR, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
else
LOG_F(CONTROL, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(), offset, SIZE_ARG(size), size * 2, value);
LOG_F(CONTROL, "%s: write MON_SENSE %03x.%c = %0*x", this->name.c_str(),
offset, SIZE_ARG(size), size * 2, value);
uint8_t dirs = ((value >> 3) & 7) ^ 7;
uint8_t levels = ((value & 7) & dirs) | (dirs ^ 7);
this->mon_sense = value & 0x3F;
+1 -1
View File
@@ -24,7 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef CONTROL_VIDEO_H
#define CONTROL_VIDEO_H
#include <devices/common/i2c/athens.h>
#include <devices/common/clockgen/athens.h>
#include <devices/common/pci/pcidevice.h>
#include <devices/video/appleramdac.h>
#include <devices/video/displayid.h>
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file SAA7187 Digital video encoder emulation. */
#include <devices/common/i2c/saa7187.h>
#include <devices/video/saa7187.h>
#include <loguru.hpp>
Saa7187VideoEncoder::Saa7187VideoEncoder(uint8_t dev_addr)
File renamed without changes.
+13 -8
View File
@@ -21,11 +21,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file TNT on-board NTSC/PAL video output emulation. */
#include <devices/video/sixty6.h>
#include <devices/video/control.h>
#include <devices/common/i2c/saa7187.h>
#include <devices/common/machineid.h>
#include <devices/deviceregistry.h>
#include <devices/video/control.h>
#include <devices/video/sixty6.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
namespace loguru {
@@ -93,22 +93,26 @@ uint16_t Sixty6Video::iodev_read(uint32_t address)
last_control_1_count++;
} else {
if (last_control_1_count) {
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_1 = %02x x %d", address, last_control_1_value, last_control_1_count);
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_1 = %02x x %d",
address, last_control_1_value, last_control_1_count);
}
last_control_1_value = value;
last_control_1_count = 0;
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_1 = %02x x %d", address, last_control_1_value, last_control_1_count);
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_1 = %02x x %d",
address, last_control_1_value, last_control_1_count);
}
break;
default:
value = 0;
LOG_F(ERROR, "Sixty6: read %d:CONTROL_DATA 0x%02x = %02x", address, this->control_addr, value);
LOG_F(ERROR, "Sixty6: read %d:CONTROL_DATA 0x%02x = %02x",
address, this->control_addr, value);
}
break;
case Sixty6BaseReg::CONTROL_ADDR:
value = this->control_addr;
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_ADDR = %02x", address, value);
LOG_F(SIXTY6_INTERRUPT, "Sixty6: read %d:CONTROL_ADDR = %02x",
address, value);
break;
}
return value;
@@ -412,7 +416,8 @@ int Sixty6Video::device_postinit()
this->control_1 |= 0x80;
else
this->control_1 &= ~0x80;
LOG_F(SIXTY6_INTERRUPT, "Sixty6: interrupt state:%d doit:%d", irq_line_state, ((this->control_1 & 0x40) && this->crtc_on));
LOG_F(SIXTY6_INTERRUPT, "Sixty6: interrupt state:%d doit:%d",
irq_line_state, ((this->control_1 & 0x40) && this->crtc_on));
if (this->interrupt_enabled && this->crtc_on) {
//this->pci_interrupt(irq_line_state);
+1
View File
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define SIXTY6_VIDEO_H
#include <devices/ioctrl/macio.h>
#include <devices/video/saa7187.h>
#include <devices/video/videoctrl.h>
#include <cinttypes>
-1
View File
@@ -22,7 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Taos video controller emulation. */
#include <core/bitops.h>
#include <devices/common/i2c/athens.h>
#include <devices/deviceregistry.h>
#include <devices/memctrl/memctrlbase.h>
#include <devices/video/taos.h>
+1
View File
@@ -28,6 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef TAOS_VIDEO_H
#define TAOS_VIDEO_H
#include <devices/common/clockgen/athens.h>
#include <devices/common/i2c/i2c.h>
#include <devices/common/mmiodevice.h>
#include <devices/video/videoctrl.h>
+10 -6
View File
@@ -60,7 +60,7 @@ typedef struct {
uint32_t ow_expected_checksum;
uint32_t nw_product_id;
uint32_t nw_subconfig_expected_checksum; // checksum of the system config section but without the firmware version and date
const char *id_str; // Bootstrap string located at offset 0x30D064 (PCI Macs) or 0x30C064 (Nubus Macs) to machine name and description.
const char *id_str; // Bootstrap string located at offset 0x30D064 (PCI Macs) or 0x30C064 (Nubus Macs)
const char *nw_firmware_updater_name;
const char *nw_openfirmware_name;
const char *dppc_machine;
@@ -788,10 +788,13 @@ string MachineFactory::machine_name_from_rom(char *rom_data, size_t rom_size) {
(info->nw_product_id && info->nw_product_id == nw_product_id )
) {
int match_count = 1
+ (info->ow_expected_checksum && info->ow_expected_checksum == ow_checksum_stored )
+ (info->ow_expected_checksum && info->ow_expected_checksum == ow_checksum_calculated )
+ (info->nw_subconfig_expected_checksum && info->nw_subconfig_expected_checksum == nw_subconfig_checksum_calculated )
+ (info->id_str && strcmp(rom_id_str, info->id_str) == 0)
+ (info->ow_expected_checksum
&& info->ow_expected_checksum == ow_checksum_stored)
+ (info->ow_expected_checksum
&& info->ow_expected_checksum == ow_checksum_calculated)
+ (info->nw_subconfig_expected_checksum
&& info->nw_subconfig_expected_checksum == nw_subconfig_checksum_calculated)
+ (info->id_str && strcmp(rom_id_str, info->id_str) == 0)
;
if (!match_pass) {
@@ -870,7 +873,8 @@ string MachineFactory::machine_name_from_rom(char *rom_data, size_t rom_size) {
if (firmware_version < 0xffff)
LOG_F(INFO, " ROM Version: %x.%03x", (firmware_version >> 12) & 15, firmware_version & 0xfff);
else
LOG_F(INFO, " ROM Version: %x.%x.%03x", firmware_version >> 16, (firmware_version >> 12) & 15, firmware_version & 0xfff);
LOG_F(INFO, " ROM Version: %x.%x.%03x",
firmware_version >> 16, (firmware_version >> 12) & 15, firmware_version & 0xfff);
if (has_nw_config) {
LOG_F(INFO, " Product ID: 0x%04x.%02x 0x%08x = %s%d,%d",
nw_product_id >> 8, nw_product_id & 0xff,
+1 -1
View File
@@ -25,9 +25,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cpu/ppc/ppcemu.h>
#include <devices/common/clockgen/athens.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/i2c/i2c.h>
#include <devices/common/i2c/athens.h>
#include <devices/common/i2c/i2cprom.h>
#include <devices/common/machineid.h>
#include <devices/common/scsi/scsihd.h>
+29 -45
View File
@@ -150,46 +150,30 @@ int initialize_tnt(std::string& id)
return 0;
}
template <uint32_t cpu>
static const PropMap pm7500_settings = {
{"rambank0_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank1_size",
new IntProperty(16, std::vector<uint32_t>({ 4, 8, 16, 32, 64, 128}))},
{"rambank2_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank3_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank4_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank5_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank6_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank7_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank8_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank9_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank10_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank11_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"rambank12_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
{"emmo",
new BinProperty(0)},
{"cpu",
new StrProperty(
cpu == PPC_VER::MPC601 ? "601" :
cpu == PPC_VER::MPC604 ? "604" :
cpu == PPC_VER::MPC604E ? "604e" :
"604e", std::vector<std::string>({"601", "604", "604e", "750"})
)
},
// If this is templated, it hits a compiler bug in MSVC, so use #define instead.
#define static_const_pm7500_settings(cpu) \
static const PropMap pm7500_settings_ ## cpu = { \
{"rambank0_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank1_size" , new IntProperty(16, std::vector<uint32_t>({ 4, 8, 16, 32, 64, 128}))}, \
{"rambank2_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank3_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank4_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank5_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank6_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank7_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank8_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank9_size" , new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank10_size", new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank11_size", new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"rambank12_size", new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))}, \
{"emmo", new BinProperty(0)}, \
{"cpu", new StrProperty(# cpu, std::vector<std::string>({"601", "604", "604e", "750"}))}, \
};
static_const_pm7500_settings(601)
static_const_pm7500_settings(604)
static_const_pm7500_settings(604e)
static std::vector<std::string> pm7500_devices = {
"Hammerhead", "Bandit1", "Chaos", "ScsiMesh", "MeshTnt", "GrandCentral",
"ControlVideo"
@@ -208,7 +192,7 @@ static const MachineDescription pm7300_descriptor = {
.name = "pm7300",
.description = "Power Macintosh 7300",
.devices = pm7500_devices,
.settings = pm7500_settings<PPC_VER::MPC604E>,
.settings = pm7500_settings_604e,
.init_func = &initialize_tnt
};
@@ -216,7 +200,7 @@ static const MachineDescription pm7500_descriptor = {
.name = "pm7500",
.description = "Power Macintosh 7500",
.devices = pm7500_devices,
.settings = pm7500_settings<PPC_VER::MPC601>,
.settings = pm7500_settings_601,
.init_func = &initialize_tnt
};
@@ -224,7 +208,7 @@ static const MachineDescription pm8500_descriptor = {
.name = "pm8500",
.description = "Power Macintosh 8500",
.devices = pm8500_devices,
.settings = pm7500_settings<PPC_VER::MPC604>,
.settings = pm7500_settings_604,
.init_func = &initialize_tnt
};
@@ -232,7 +216,7 @@ static const MachineDescription pm9500_descriptor = {
.name = "pm9500",
.description = "Power Macintosh 9500",
.devices = pm9500_devices,
.settings = pm7500_settings<PPC_VER::MPC604>,
.settings = pm7500_settings_604,
.init_func = &initialize_tnt
};
@@ -240,7 +224,7 @@ static const MachineDescription pm7600_descriptor = {
.name = "pm7600",
.description = "Power Macintosh 7600",
.devices = pm7500_devices,
.settings = pm7500_settings<PPC_VER::MPC604E>,
.settings = pm7500_settings_604e,
.init_func = &initialize_tnt
};
@@ -248,7 +232,7 @@ static const MachineDescription pm8600_descriptor = {
.name = "pm8600",
.description = "Power Macintosh 8600",
.devices = pm8500_devices,
.settings = pm7500_settings<PPC_VER::MPC604E>,
.settings = pm7500_settings_604e,
.init_func = &initialize_tnt
};
@@ -256,7 +240,7 @@ static const MachineDescription pm9600_descriptor = {
.name = "pm9600",
.description = "Power Macintosh 9600",
.devices = pm9500_devices,
.settings = pm7500_settings<PPC_VER::MPC604E>,
.settings = pm7500_settings_604e,
.init_func = &initialize_tnt
};
+33 -10
View File
@@ -37,6 +37,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <csignal>
#include <cstring>
#include <iostream>
#include <optional>
#include <CLI11.hpp>
#include <loguru.hpp>
@@ -60,7 +61,7 @@ static void sigabrt_handler(int signum) {
}
static string appDescription = string(
"\nDingusPPC - Alpha 1.01 (10/31/2024) "
"\nDingusPPC - Alpha 1.02 (5/10/2025) "
"\nWritten by divingkatae, maximumspatium, "
"\njoevt, mihaip, kkaisershot, et. al. "
"\n(c) 2018-2024 The DingusPPC Dev Team. "
@@ -69,6 +70,8 @@ static string appDescription = string(
"\n"
);
uint32_t keyboard_id = 0;
/// Check for an existing directory (returns error message if check fails)
class WorkingDirectoryValidator : public CLI::detail::ExistingDirectoryValidator {
public:
@@ -89,7 +92,10 @@ public:
const WorkingDirectoryValidator WorkingDirectory;
void run_machine(std::string machine_str, char *rom_data, size_t rom_size, uint32_t execution_mode, uint32_t profiling_interval_ms);
void run_machine(
std::string machine_str, char *rom_data, size_t rom_size, uint32_t execution_mode
,uint32_t profiling_interval_ms
);
int main(int argc, char** argv) {
@@ -99,8 +105,15 @@ int main(int argc, char** argv) {
app.allow_windows_style_options(); /* we want Windows-style options */
app.allow_extras();
bool realtime_enabled = false;
bool debugger_enabled = false;
bool realtime_enabled = false;
bool debugger_enabled = false;
string keyboard_string = "Eng_USA";
const std::map<std::string, int> kbd_map{
{"Eng_USA", 0}, {"Eng_GBR", 1}, {"Fra_FRA", 10}, {"Deu_DEU", 20},
{"Ita_ITA", 30},{"Spa_ESP", 40}, {"Jpn_JPN", 80},
};
string bootrom_path("bootrom.bin");
string working_directory_path(".");
@@ -110,6 +123,7 @@ int main(int argc, char** argv) {
"Run the emulator in real-time");
execution_mode_group->add_flag("-d,--debugger", debugger_enabled,
"Enter the built-in debugger");
app.add_option("-k,--keyboard", keyboard_string, "Specify keyboard ID");
app.add_option("-w,--workingdir", working_directory_path, "Specifies working directory")
->check(WorkingDirectory);
app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
@@ -179,7 +193,7 @@ int main(int argc, char** argv) {
}
auto rom_data = std::unique_ptr<char[]>(new char[4 * 1024 * 1024]);
memset(&rom_data[0], 0, 4 * 1024 * 1024);
memset(&rom_data[0], 0, static_cast<size_t>(4 * 1024 * 1024));
size_t rom_size = MachineFactory::read_boot_rom(bootrom_path, &rom_data[0]);
if (!rom_size) {
return 1;
@@ -258,8 +272,15 @@ int main(int argc, char** argv) {
// redirect SIGABRT to our own handler
signal(SIGABRT, sigabrt_handler);
keyboard_id = kbd_map.at(keyboard_string);
while (true) {
run_machine(machine_str, &rom_data[0], rom_size, execution_mode, profiling_interval_ms);
run_machine(
machine_str,
&rom_data[0],
rom_size,
execution_mode,
profiling_interval_ms);
if (power_off_reason == po_restarting) {
LOG_F(INFO, "Restarting...");
power_on = true;
@@ -282,10 +303,12 @@ int main(int argc, char** argv) {
return 0;
}
void run_machine(std::string machine_str, char *rom_data, size_t rom_size, uint32_t execution_mode,
void run_machine(std::string machine_str, char* rom_data,
size_t rom_size,
uint32_t execution_mode,
uint32_t
#ifdef CPU_PROFILING
profiling_interval_ms
profiling_interval_ms
#endif
) {
if (MachineFactory::create_machine_for_id(machine_str, rom_data, rom_size) < 0) {
@@ -309,8 +332,8 @@ void run_machine(std::string machine_str, char *rom_data, size_t rom_size, uint3
// set up system wide event polling using
// default Macintosh polling rate of 11 ms
uint32_t event_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(11), [] {
EventManager::get_instance()->poll_events();
uint32_t event_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(11), [] {
EventManager::get_instance()->poll_events(keyboard_id);
});
#ifdef CPU_PROFILING
+4 -4
View File
@@ -56,7 +56,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
((((uint8_t*)(addr))[0] << 24) | (((uint8_t*)(addr))[1] << 16) | \
(((uint8_t*)(addr))[2] << 8) | ((uint8_t*)(addr))[3] )
/* read an unaligned big-endian QWORD (32bit) */
/* read an unaligned big-endian QWORD (64bit) */
#define READ_QWORD_BE_U(addr) \
((uint64_t(((uint8_t*)(addr))[0]) << 56) | (uint64_t(((uint8_t*)(addr))[1]) << 48) | \
(uint64_t(((uint8_t*)(addr))[2]) << 40) | (uint64_t(((uint8_t*)(addr))[3]) << 32) | \
@@ -71,7 +71,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
((((uint8_t*)(addr))[3] << 24) | (((uint8_t*)(addr))[2] << 16) | \
(((uint8_t*)(addr))[1] << 8) | ((uint8_t*)(addr))[0] )
/* read an unaligned little-endian DWORD (64bit) */
/* read an unaligned little-endian QWORD (64bit) */
#define READ_QWORD_LE_U(addr) \
((uint64_t(((uint8_t*)(addr))[7]) << 56) | (uint64_t(((uint8_t*)(addr))[6]) << 48) | \
(uint64_t(((uint8_t*)(addr))[5]) << 40) | (uint64_t(((uint8_t*)(addr))[4]) << 32) | \
@@ -103,7 +103,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
((uint8_t*)(addr))[3] = (uint8_t)(val); \
} while (0)
/* write an unaligned big-endian DWORD (64bit) */
/* write an unaligned big-endian QWORD (64bit) */
#define WRITE_QWORD_BE_U(addr, val) \
do { \
((uint8_t*)(addr))[0] = ((uint64_t)(val) >> 56); \
@@ -141,7 +141,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
((uint8_t*)(addr))[3] = ((val) >> 24); \
} while (0)
/* write an unaligned little-endian DWORD (64bit) */
/* write an unaligned little-endian QWORD (64bit) */
#define WRITE_QWORD_LE_U(addr, val) \
do { \
((uint8_t*)(addr))[0] = (uint8_t)(val) ; \