mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
49
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df772f57e2 | ||
|
|
0d5817042e | ||
|
|
7bdad7703c | ||
|
|
087402290d | ||
|
|
9a0c340712 | ||
|
|
fd33c10712 | ||
|
|
9caaf0f538 | ||
|
|
476d893094 | ||
|
|
fff597075d | ||
|
|
793335d9b8 | ||
|
|
f609839894 | ||
|
|
f39188beb1 | ||
|
|
decb8342be | ||
|
|
609fb43726 | ||
|
|
c2991149fd | ||
|
|
99f5aba12e | ||
|
|
cbf4e266e1 | ||
|
|
84ded9fc7a | ||
|
|
a01cd9c993 | ||
|
|
fc44cdcc83 | ||
|
|
958d3ee96a | ||
|
|
c2a63bab09 | ||
|
|
392fa87ba4 | ||
|
|
87b8e1759a | ||
|
|
cb946e41b5 | ||
|
|
3f20d0a700 | ||
|
|
767735251b | ||
|
|
6a756df5e3 | ||
|
|
281aaa1902 | ||
|
|
c7f21040ae | ||
|
|
a28ef677fd | ||
|
|
d70adac564 | ||
|
|
c0cd6eb38f | ||
|
|
9329d56d83 | ||
|
|
7919cd0590 | ||
|
|
7daf4aa317 | ||
|
|
f194887d34 | ||
|
|
46549d68a2 | ||
|
|
c7544d9c2f | ||
|
|
2f725fe3e4 | ||
|
|
e53296f7a9 | ||
|
|
7c47b9c1e7 | ||
|
|
e66979d30f | ||
|
|
9caef55c19 | ||
|
|
2a9d364b1b | ||
|
|
3eb2d3cba7 | ||
|
|
bde5b71167 | ||
|
|
89e79d05cb | ||
|
|
bb0ca2ac40 |
No files matched your search
+7
-6
@@ -21,9 +21,9 @@ endif()
|
||||
option(DPPC_BUILD_PPC_TESTS "Build PowerPC tests" OFF)
|
||||
option(DPPC_BUILD_BENCHMARKS "Build benchmarking programs" OFF)
|
||||
|
||||
option(ENABLE_68K_DEBUGGER "Enable 68k debugging" OFF)
|
||||
option(DPPC_68K_DEBUGGER "Enable 68k debugging" OFF)
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
# Build capstone as static library.
|
||||
set(CAPSTONE_BUILD_STATIC ON CACHE BOOL "")
|
||||
|
||||
@@ -79,7 +79,8 @@ add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
|
||||
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/devices"
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/devices"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc"
|
||||
"${PROJECT_SOURCE_DIR}/debugger"
|
||||
"${PROJECT_SOURCE_DIR}/utils"
|
||||
@@ -117,7 +118,7 @@ target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE
|
||||
target_include_directories(dingusppc PRIVATE ${CLI11_ROOT})
|
||||
endif()
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc capstone-static)
|
||||
endif()
|
||||
|
||||
@@ -141,7 +142,7 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(testppc capstone-static)
|
||||
endif()
|
||||
endif()
|
||||
@@ -159,7 +160,7 @@ if (DPPC_BUILD_BENCHMARKS)
|
||||
target_link_libraries(bench1 cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(bench1 capstone-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 <stdlib.h>
|
||||
#include <chrono>
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
|
||||
+10
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -42,7 +42,7 @@ inline void power_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
}
|
||||
}
|
||||
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
||||
uint32_t m2 = 0xFFFFFFFFUL << (31 - rot_me);
|
||||
@@ -154,9 +154,9 @@ void dppc_interpreter::power_lscbx() {
|
||||
ppc_result_d = 0xFFFFFFFF;
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
|
||||
switch (byte_offset) {
|
||||
|
||||
switch (byte_offset) {
|
||||
case 0:
|
||||
bitmask = 0x00FFFFFF;
|
||||
shift_amount = 24;
|
||||
@@ -174,7 +174,7 @@ void dppc_interpreter::power_lscbx() {
|
||||
shift_amount = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
// return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & bitmask) | (return_value << shift_amount);
|
||||
@@ -185,7 +185,7 @@ void dppc_interpreter::power_lscbx() {
|
||||
//Match has been found - Time to break out
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
byte_offset += 8;
|
||||
|
||||
if (byte_offset == 32) {
|
||||
@@ -211,10 +211,10 @@ void dppc_interpreter::power_maskg() {
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
insert_mask = power_rot_mask(mask_start, mask_end);
|
||||
}
|
||||
}
|
||||
else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
else {
|
||||
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
|
||||
}
|
||||
@@ -359,7 +359,7 @@ void dppc_interpreter::power_sllq() {
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
@@ -508,7 +508,7 @@ void dppc_interpreter::power_srlq() {
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 PPC_DEFS_H
|
||||
#define PPC_DEFS_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#define GET_rD_rA_OFFS(opcode) \
|
||||
uint32_t reg_d = ((opcode) >> 21) & 31; \
|
||||
uint32_t reg_a = ((opcode) >> 16) & 31; \
|
||||
int32_t offs = (int32_t)((int16_t)((opcode) & 0xFFFF));
|
||||
|
||||
#define GET_GPR(reg) ppc_state.gpr[(reg)]
|
||||
#define SET_GPR(reg, val) ppc_state.gpr[(reg)] = (val)
|
||||
|
||||
#define GET_rD_iA_iB(opcode) \
|
||||
uint32_t reg_d = ((opcode) >> 21) & 31; \
|
||||
uint32_t imm_a = ppc_state.gpr[((opcode) >> 16) & 31]; \
|
||||
uint32_t imm_b = ppc_state.gpr[((opcode) >> 11) & 31];
|
||||
|
||||
#define GET_rD_rA_iA_iB(opcode) \
|
||||
uint32_t reg_d = ((opcode) >> 21) & 31; \
|
||||
uint32_t reg_a = ((opcode) >> 16) & 31; \
|
||||
uint32_t imm_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t imm_b = ppc_state.gpr[((opcode) >> 11) & 31];
|
||||
|
||||
#define GET_rA_iS(opcode) \
|
||||
uint32_t reg_a = ((opcode) >> 16) & 31; \
|
||||
uint32_t imm_d = ppc_state.gpr[((opcode) >> 21) & 31];
|
||||
|
||||
#define GET_rS_rA_OFFS(opcode) \
|
||||
uint32_t reg_s = ((opcode) >> 21) & 31; \
|
||||
uint32_t reg_a = ((opcode) >> 16) & 31; \
|
||||
int32_t offs = (int32_t)((int16_t)((opcode) & 0xFFFF));
|
||||
|
||||
#define GET_rS_rA_iA_iB(opcode) \
|
||||
uint32_t reg_s = ((opcode) >> 21) & 31; \
|
||||
uint32_t reg_a = ((opcode) >> 16) & 31; \
|
||||
uint32_t imm_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t imm_b = ppc_state.gpr[((opcode) >> 11) & 31];
|
||||
|
||||
#endif // PPC_DEFS_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
+27
-25
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PPCEMU_H
|
||||
#define PPCEMU_H
|
||||
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "endianswap.h"
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <setjmp.h>
|
||||
@@ -147,8 +148,12 @@ SUPERVISOR MODEL
|
||||
536 - 543 are the Data BAT registers
|
||||
**/
|
||||
|
||||
extern uint32_t opcode_value; // used for interpreting opcodes
|
||||
extern uint64_t timebase_counter; // used for storing time base value
|
||||
extern uint32_t opcode_value; // used for interpreting opcodes
|
||||
|
||||
extern uint64_t timebase_counter;
|
||||
extern uint64_t tbr_wr_timestamp;
|
||||
extern uint64_t tbr_wr_value;
|
||||
extern uint64_t tbr_freq_hz;
|
||||
|
||||
// Additional steps to prevent overflow?
|
||||
extern int32_t add_result;
|
||||
@@ -206,14 +211,13 @@ enum CR_select : int32_t {
|
||||
};
|
||||
|
||||
enum CRx_bit : uint32_t {
|
||||
CR_SO = 0,
|
||||
CR_EQ,
|
||||
CR_GT,
|
||||
CR_LT
|
||||
};
|
||||
CR_SO = 28,
|
||||
CR_EQ = 29,
|
||||
CR_GT = 30,
|
||||
CR_LT = 31 };
|
||||
|
||||
enum CR1_bit : uint32_t {
|
||||
CR1_OX = 24,
|
||||
CR1_OX = 24,
|
||||
CR1_VX,
|
||||
CR1_FEX,
|
||||
CR1_FX,
|
||||
@@ -259,7 +263,7 @@ enum FPOP : int {
|
||||
SUB = 0x14,
|
||||
ADD = 0x15,
|
||||
MUL = 0x19,
|
||||
FMSUB = 0x1C,
|
||||
FMSUB = 0x1C,
|
||||
FMADD = 0x1D,
|
||||
FNMSUB = 0x1E,
|
||||
FNMADD = 0x1F,
|
||||
@@ -366,8 +370,8 @@ void ppc_fp_changecrf1();
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
|
||||
//typedef std::function<void()> CtxSyncCallback;
|
||||
extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
namespace dppc_interpreter {
|
||||
@@ -501,14 +505,16 @@ extern void ppc_bcl();
|
||||
extern void ppc_bcla();
|
||||
extern void ppc_cmpi();
|
||||
extern void ppc_cmpli();
|
||||
extern void ppc_lbz();
|
||||
extern void ppc_lbzu();
|
||||
extern void ppc_lha();
|
||||
extern void ppc_lhau();
|
||||
extern void ppc_lhz();
|
||||
extern void ppc_lhzu();
|
||||
extern void ppc_lwz();
|
||||
extern void ppc_lwzu();
|
||||
template <class T> void ppc_lz(void);
|
||||
template <class T> void ppc_lzu(void);
|
||||
template <class T> void ppc_lzux(void);
|
||||
template <class T> void ppc_lzx(void);
|
||||
template <class T> void ppc_st(void);
|
||||
template <class T> void ppc_stu(void);
|
||||
template <class T> void ppc_stux(void);
|
||||
template <class T> void ppc_stx(void);
|
||||
extern void ppc_lmw();
|
||||
extern void ppc_mulli();
|
||||
extern void ppc_ori();
|
||||
@@ -518,12 +524,6 @@ extern void ppc_rlwimi();
|
||||
extern void ppc_rlwinm();
|
||||
extern void ppc_rlwnm();
|
||||
extern void ppc_sc();
|
||||
extern void ppc_stb();
|
||||
extern void ppc_stbu();
|
||||
extern void ppc_sth();
|
||||
extern void ppc_sthu();
|
||||
extern void ppc_stw();
|
||||
extern void ppc_stwu();
|
||||
extern void ppc_stmw();
|
||||
extern void ppc_subfic();
|
||||
extern void ppc_twi();
|
||||
@@ -615,6 +615,8 @@ extern void power_srq();
|
||||
|
||||
// G5+ instructions
|
||||
|
||||
extern uint64_t get_virt_time_ns(void);
|
||||
|
||||
extern void ppc_main_opcode(void);
|
||||
extern void ppc_exec(void);
|
||||
extern void ppc_exec_single(void);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -110,6 +110,12 @@ jmp_buf exc_env; /* Global exception environment. */
|
||||
ppc_next_instruction_address |= 0xFFF00000;
|
||||
}
|
||||
|
||||
// perform context synchronization for recoverable exceptions
|
||||
if (exception_type != Except_Type::EXC_MACHINE_CHECK &&
|
||||
exception_type != Except_Type::EXC_SYSTEM_RESET) {
|
||||
do_ctx_sync();
|
||||
}
|
||||
|
||||
mmu_change_mode();
|
||||
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
|
||||
+279
-23
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -62,12 +62,19 @@ BB_end_kind bb_kind; /* basic block end */
|
||||
uint32_t glob_bb_start_la;
|
||||
|
||||
/* variables related to virtual time */
|
||||
uint64_t cycles_count; /* contains number of cycles executed so far */
|
||||
uint64_t old_cycles_count; /* previous value for cycles_count */
|
||||
uint64_t timebase_counter; /* internal timebase counter */
|
||||
uint32_t decr; /* current value of PPC DEC register */
|
||||
uint8_t old_decr_msb; /* MSB value for previous DEC value */
|
||||
uint8_t tbr_factor; /* cycles_count to TBR freq ratio in 2^x units */
|
||||
uint64_t g_icycles;
|
||||
int icnt_factor;
|
||||
|
||||
/* global variables related to the timebase facility */
|
||||
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR write
|
||||
uint64_t tbr_wr_value; // last value written to the TBR
|
||||
uint64_t tbr_freq_hz; // TBR driving frequency in Hz
|
||||
uint64_t cycles_count; // contains number of cycles executed so far */
|
||||
uint64_t old_cycles_count; // previous value for cycles_count */
|
||||
uint64_t timebase_counter; // internal timebase counter */
|
||||
uint32_t decr; // current value of PPC DEC register */
|
||||
uint8_t old_decr_msb; // MSB value for previous DEC value */
|
||||
uint8_t tbr_factor; // cycles_count to TBR freq ratio in 2^x units */
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
|
||||
@@ -129,9 +136,9 @@ static PPCOpcode OpcodeGrabber[] = {
|
||||
ppc_addic, ppc_addicdot, ppc_addi, ppc_addis, ppc_opcode16, ppc_sc,
|
||||
ppc_opcode18, ppc_opcode19, ppc_rlwimi, ppc_rlwinm, power_rlmi, ppc_rlwnm,
|
||||
ppc_ori, ppc_oris, ppc_xori, ppc_xoris, ppc_andidot, ppc_andisdot,
|
||||
ppc_illegalop, ppc_opcode31, ppc_lwz, ppc_lwzu, ppc_lbz, ppc_lbzu,
|
||||
ppc_stw, ppc_stwu, ppc_stb, ppc_stbu, ppc_lhz, ppc_lhzu,
|
||||
ppc_lha, ppc_lhau, ppc_sth, ppc_sthu, ppc_lmw, ppc_stmw,
|
||||
ppc_illegalop, ppc_opcode31, ppc_lz<uint32_t>, ppc_lzu<uint32_t>, ppc_lz<uint8_t>, ppc_lzu<uint8_t>,
|
||||
ppc_st<uint32_t>, ppc_stu<uint32_t>, ppc_st<uint8_t>, ppc_stu<uint8_t>, ppc_lz<uint16_t>, ppc_lzu<uint16_t>,
|
||||
ppc_lha, ppc_lhau, ppc_st<uint16_t>, ppc_stu<uint16_t>, ppc_lmw, ppc_stmw,
|
||||
ppc_lfs, ppc_lfsu, ppc_lfd, ppc_lfdu, ppc_stfs, ppc_stfsu,
|
||||
ppc_stfd, ppc_stfdu, ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode59,
|
||||
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode63};
|
||||
@@ -286,8 +293,20 @@ void ppc_main_opcode()
|
||||
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
|
||||
}
|
||||
|
||||
uint64_t get_virt_time_ns()
|
||||
{
|
||||
return g_icycles << icnt_factor;
|
||||
}
|
||||
|
||||
int process_events()
|
||||
{
|
||||
// dummy implementation that schedules execution
|
||||
// of another 10.000 instructions
|
||||
return g_icycles + 10000;
|
||||
}
|
||||
|
||||
/** Execute PPC code as long as power is on. */
|
||||
#if 0
|
||||
void ppc_exec()
|
||||
{
|
||||
uint32_t bb_start_la, page_start, delta;
|
||||
@@ -348,8 +367,78 @@ again:
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
// inner interpreter loop
|
||||
static void ppc_exec_inner()
|
||||
{
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
while (power_on) {
|
||||
// define boundaries of the next execution block
|
||||
// max execution block length = one memory page
|
||||
eb_start = ppc_state.pc;
|
||||
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
|
||||
//eb_last = false;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
|
||||
// interpret execution block
|
||||
while (ppc_state.pc < eb_end) {
|
||||
ppc_main_opcode();
|
||||
if (g_icycles++ >= max_cycles) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
|
||||
//if (eb_last) {
|
||||
if (bb_kind != BB_end_kind::BB_NONE) { // execution block ended ?
|
||||
if (!power_on)
|
||||
break;
|
||||
// check the reason for the block end
|
||||
//eb_last = false;
|
||||
// define next execution block
|
||||
eb_start = ppc_next_instruction_address;
|
||||
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
|
||||
if ((eb_start & PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// outer interpreter loop
|
||||
void ppc_exec()
|
||||
{
|
||||
if (setjmp(exc_env)) {
|
||||
// process low-level exceptions
|
||||
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
|
||||
ppc_state.pc = ppc_next_instruction_address;
|
||||
}
|
||||
|
||||
while (power_on) {
|
||||
ppc_exec_inner();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Execute one PPC instruction. */
|
||||
#if 0
|
||||
void ppc_exec_single()
|
||||
{
|
||||
uint32_t delta;
|
||||
@@ -383,8 +472,31 @@ void ppc_exec_single()
|
||||
timebase_counter++;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void ppc_exec_single()
|
||||
{
|
||||
if (setjmp(exc_env)) {
|
||||
// process low-level exceptions
|
||||
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
|
||||
ppc_state.pc = ppc_next_instruction_address;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
mmu_translate_imem(ppc_state.pc);
|
||||
ppc_main_opcode();
|
||||
if (bb_kind != BB_end_kind::BB_NONE) {
|
||||
ppc_state.pc = ppc_next_instruction_address;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
}
|
||||
g_icycles++;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Execute PPC code until goal_addr is reached. */
|
||||
#if 0
|
||||
void ppc_exec_until(volatile uint32_t goal_addr)
|
||||
{
|
||||
uint32_t bb_start_la, page_start, delta;
|
||||
@@ -411,7 +523,6 @@ void ppc_exec_until(volatile uint32_t goal_addr)
|
||||
}
|
||||
|
||||
/* initial MMU translation for the current code page. */
|
||||
//pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
|
||||
/* set current code page limits */
|
||||
@@ -444,8 +555,77 @@ again:
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
// inner interpreter loop
|
||||
static void ppc_exec_until_inner(const uint32_t goal_addr)
|
||||
{
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
while (ppc_state.pc != goal_addr) {
|
||||
// define boundaries of the next execution block
|
||||
// max execution block length = one memory page
|
||||
eb_start = ppc_state.pc;
|
||||
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
|
||||
//eb_last = false;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
|
||||
// interpret execution block
|
||||
while ((ppc_state.pc != goal_addr) && (ppc_state.pc < eb_end)) {
|
||||
ppc_main_opcode();
|
||||
if (g_icycles++ >= max_cycles) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
|
||||
//if (eb_last) {
|
||||
if (bb_kind != BB_end_kind::BB_NONE) { // execution block ended ?
|
||||
// check the reason for the block end
|
||||
//eb_last = false;
|
||||
// define next execution block
|
||||
eb_start = ppc_next_instruction_address;
|
||||
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
|
||||
if ((eb_start & PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_F(9, "PPC-EXEC: goal address reached, icycles=%llu", g_icycles);
|
||||
}
|
||||
|
||||
// outer interpreter loop
|
||||
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 = ppc_next_instruction_address;
|
||||
}
|
||||
|
||||
while (ppc_state.pc != goal_addr) {
|
||||
ppc_exec_until_inner(goal_addr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Execute PPC code until control is reached the specified region. */
|
||||
#if 0
|
||||
void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
|
||||
{
|
||||
uint32_t bb_start_la, page_start, delta;
|
||||
@@ -508,6 +688,75 @@ again:
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
// inner interpreter loop
|
||||
static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
|
||||
{
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
while (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size) {
|
||||
// define boundaries of the next execution block
|
||||
// max execution block length = one memory page
|
||||
eb_start = ppc_state.pc;
|
||||
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
|
||||
//eb_last = false;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
|
||||
// interpret execution block
|
||||
while ((ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)
|
||||
&& (ppc_state.pc < eb_end)) {
|
||||
ppc_main_opcode();
|
||||
if (g_icycles++ >= max_cycles) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
|
||||
//if (eb_last) {
|
||||
if (bb_kind != BB_end_kind::BB_NONE) { // execution block ended ?
|
||||
// check the reason for the block end
|
||||
//eb_last = false;
|
||||
// define next execution block
|
||||
eb_start = ppc_next_instruction_address;
|
||||
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
|
||||
if ((eb_start & PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_F(9, "PPC-EXEC: goal address reached, icycles=%llu", g_icycles);
|
||||
}
|
||||
|
||||
// outer interpreter loop
|
||||
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 = ppc_next_instruction_address;
|
||||
}
|
||||
|
||||
while (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size) {
|
||||
ppc_exec_dbg_inner(start_addr, size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
uint64_t instr_count, old_instr_count;
|
||||
@@ -569,12 +818,12 @@ void initialize_ppc_opcode_tables() {
|
||||
SubOpcode31Grabber[491] = SubOpcode31Grabber[1003] = ppc_divw;
|
||||
|
||||
SubOpcode31Grabber[20] = ppc_lwarx;
|
||||
SubOpcode31Grabber[23] = ppc_lwzx;
|
||||
SubOpcode31Grabber[55] = ppc_lwzux;
|
||||
SubOpcode31Grabber[87] = ppc_lbzx;
|
||||
SubOpcode31Grabber[119] = ppc_lbzux;
|
||||
SubOpcode31Grabber[279] = ppc_lhzx;
|
||||
SubOpcode31Grabber[311] = ppc_lhzux;
|
||||
SubOpcode31Grabber[23] = ppc_lzx<uint32_t>;
|
||||
SubOpcode31Grabber[55] = ppc_lzux<uint32_t>;
|
||||
SubOpcode31Grabber[87] = ppc_lzx<uint8_t>;
|
||||
SubOpcode31Grabber[119] = ppc_lzux<uint8_t>;
|
||||
SubOpcode31Grabber[279] = ppc_lzx<uint16_t>;
|
||||
SubOpcode31Grabber[311] = ppc_lzux<uint16_t>;
|
||||
SubOpcode31Grabber[343] = ppc_lhax;
|
||||
SubOpcode31Grabber[375] = ppc_lhaux;
|
||||
SubOpcode31Grabber[533] = ppc_lswx;
|
||||
@@ -587,12 +836,12 @@ void initialize_ppc_opcode_tables() {
|
||||
SubOpcode31Grabber[790] = ppc_lhbrx;
|
||||
|
||||
SubOpcode31Grabber[150] = ppc_stwcx;
|
||||
SubOpcode31Grabber[151] = ppc_stwx;
|
||||
SubOpcode31Grabber[183] = ppc_stwux;
|
||||
SubOpcode31Grabber[215] = ppc_stbx;
|
||||
SubOpcode31Grabber[247] = ppc_stbux;
|
||||
SubOpcode31Grabber[407] = ppc_sthx;
|
||||
SubOpcode31Grabber[439] = ppc_sthux;
|
||||
SubOpcode31Grabber[151] = ppc_stx<uint32_t>;
|
||||
SubOpcode31Grabber[183] = ppc_stux<uint32_t>;
|
||||
SubOpcode31Grabber[215] = ppc_stx<uint8_t>;
|
||||
SubOpcode31Grabber[247] = ppc_stux<uint8_t>;
|
||||
SubOpcode31Grabber[407] = ppc_stx<uint16_t>;
|
||||
SubOpcode31Grabber[439] = ppc_stux<uint16_t>;
|
||||
SubOpcode31Grabber[661] = ppc_stswx;
|
||||
SubOpcode31Grabber[662] = ppc_stwbrx;
|
||||
SubOpcode31Grabber[663] = ppc_stfsx;
|
||||
@@ -767,6 +1016,13 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version) {
|
||||
tbr_factor = 4;
|
||||
#endif
|
||||
|
||||
// initialize time base facility
|
||||
g_icycles = 0;
|
||||
icnt_factor = 4;
|
||||
tbr_wr_timestamp = 0;
|
||||
tbr_wr_value = 0;
|
||||
tbr_freq_hz = 16705000; // FIXME: this should be set properly during machine initialization
|
||||
|
||||
timebase_counter = 0;
|
||||
decr = 0;
|
||||
old_decr_msb = decr >> 31;
|
||||
|
||||
+132
-116
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The opcodes for the processor - ppcopcodes.cpp
|
||||
// The floating point opcodes for the processor - ppcfpopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
@@ -186,7 +186,7 @@ void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, b
|
||||
|
||||
switch (fpop) {
|
||||
case FPOP::DIV:
|
||||
if (isnan(input_a) && isnan(input_b)) {
|
||||
if (isinf(input_a) && isinf(input_b)) {
|
||||
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXIDI);
|
||||
} else if ((input_a == FP_ZERO) && (input_b == FP_ZERO)) {
|
||||
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXZDZ);
|
||||
@@ -217,7 +217,7 @@ void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, b
|
||||
case FPOP::FMSUB:
|
||||
case FPOP::FNMSUB:
|
||||
if (isnan(input_a) || isnan(input_b) || isnan(input_c)) {
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXSNAN);
|
||||
if (((input_a == FP_ZERO) && (input_c == FP_INFINITE)) ||
|
||||
((input_c == FP_ZERO) && (input_a == FP_INFINITE))) {
|
||||
ppc_state.fpscr |= FPSCR::VXIMZ;
|
||||
@@ -236,68 +236,79 @@ void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, b
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, const FPOP fpop>
|
||||
void fpresult_update(double set_result, bool confirm_arc) {
|
||||
bool confirm_ov = (bool)std::fetestexcept(FE_OVERFLOW);
|
||||
|
||||
if (ppc_state.fpscr & 0x3)
|
||||
ppc_state.cr |= 0x2;
|
||||
|
||||
if (set_result > 0.0) {
|
||||
ppc_state.fpscr |= FPSCR::FPCC_POS;
|
||||
ppc_state.fpscr |= FPCC_POS;
|
||||
} else if (set_result < 0.0) {
|
||||
ppc_state.fpscr |= FPSCR::FPCC_NEG;
|
||||
} else if (set_result == 0.0) {
|
||||
ppc_state.fpscr |= FPSCR::FPCC_ZERO;
|
||||
ppc_state.fpscr |= FPCC_NEG;
|
||||
} else {
|
||||
ppc_state.fpscr |= FPSCR::FPCC_FPRCD;
|
||||
ppc_state.fpscr |= FPCC_ZERO;
|
||||
}
|
||||
|
||||
if (confirm_ov) {
|
||||
ppc_state.fpscr |= (FPSCR::FX | (FPSCR::FPRF & FPSCR::FPCC_FUNAN));
|
||||
}
|
||||
|
||||
if (confirm_arc) {
|
||||
ppc_state.fpscr |= (FPSCR::FX | (FPSCR::FPRF & FPSCR::FPCC_FUNAN));
|
||||
//ppc_state.fpscr &= 0xFFFF0FFF;
|
||||
if (isnan(set_result) || isinf(set_result)) {
|
||||
ppc_state.fpscr |= FPCC_FPRCD;
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_changecrf1() {
|
||||
ppc_state.cr &= ~((uint32_t)CR_select::CR1_field);
|
||||
ppc_state.cr |= (ppc_state.fpscr & (uint32_t)CR_select::CR0_field) >> 4;
|
||||
void ppc_changecrf1(double set_result) {
|
||||
cmp_c = 0;
|
||||
|
||||
/*
|
||||
if (isnan(set_result)) {
|
||||
cmp_c |= (1 << CRx_bit::CR_SO);
|
||||
}
|
||||
|
||||
if (set_result > 0.0) {
|
||||
cmp_c |= (1 << CRx_bit::CR_GT);
|
||||
}
|
||||
|
||||
if (set_result < 0.0) {
|
||||
cmp_c |= (1 << CRx_bit::CR_LT);
|
||||
}
|
||||
|
||||
if (set_result == 0.0) {
|
||||
cmp_c |= (1 << CRx_bit::CR_EQ);
|
||||
}*/
|
||||
|
||||
ppc_state.cr = ((ppc_state.cr & ~(CR_select::CR1_field)) | ((cmp_c) >> crf_d));
|
||||
}
|
||||
|
||||
// Floating Point Arithmetic
|
||||
void dppc_interpreter::ppc_fadd() {
|
||||
ppc_grab_regsfpdab();
|
||||
|
||||
ppc_dblresult64_d = val_reg_a + val_reg_b;
|
||||
ppc_dblresult64_d = double(val_reg_a + val_reg_b);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
fpresult_update<double, ADD>(ppc_dblresult64_d, rc_flag);
|
||||
}
|
||||
else {
|
||||
ppc_confirm_inf_nan<double, ADD>(reg_a, reg_b, 0, rc_flag);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fsub() {
|
||||
ppc_grab_regsfpdab();
|
||||
|
||||
ppc_dblresult64_d = val_reg_a - val_reg_b;
|
||||
ppc_dblresult64_d = double(val_reg_a - val_reg_b);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<double, SUB>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<double, SUB>(reg_a, reg_b, 0, rc_flag);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fdiv() {
|
||||
@@ -305,15 +316,15 @@ void dppc_interpreter::ppc_fdiv() {
|
||||
|
||||
ppc_dblresult64_d = val_reg_a / val_reg_b;
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<double, DIV>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<double, DIV>(reg_a, reg_b, 0, rc_flag);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fmul() {
|
||||
@@ -321,15 +332,15 @@ void dppc_interpreter::ppc_fmul() {
|
||||
|
||||
ppc_dblresult64_d = val_reg_a * val_reg_c;
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<double, MUL>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<double, MUL>(reg_a, reg_b, 0, rc_flag);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fmadd() {
|
||||
@@ -337,15 +348,15 @@ void dppc_interpreter::ppc_fmadd() {
|
||||
|
||||
ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<double, FMADD>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<double, FMADD>(reg_a, reg_b, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fmsub() {
|
||||
@@ -354,15 +365,15 @@ void dppc_interpreter::ppc_fmsub() {
|
||||
ppc_dblresult64_d = (val_reg_a * val_reg_c);
|
||||
ppc_dblresult64_d -= val_reg_b;
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<double, FMSUB>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<double, FMSUB>(reg_a, reg_b, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fnmadd() {
|
||||
@@ -370,17 +381,18 @@ void dppc_interpreter::ppc_fnmadd() {
|
||||
|
||||
ppc_dblresult64_d = (val_reg_a * val_reg_c);
|
||||
ppc_dblresult64_d += val_reg_b;
|
||||
ppc_dblresult64_d = -(ppc_dblresult64_d);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<double, FNMADD>(ppc_dblresult64_d, rc_flag);
|
||||
}
|
||||
else {
|
||||
ppc_confirm_inf_nan<double, FNMADD>(reg_a, reg_b, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fnmsub() {
|
||||
@@ -388,85 +400,82 @@ void dppc_interpreter::ppc_fnmsub() {
|
||||
|
||||
ppc_dblresult64_d = (val_reg_a * val_reg_c);
|
||||
ppc_dblresult64_d -= val_reg_b;
|
||||
ppc_dblresult64_d = -ppc_dblresult64_d;
|
||||
ppc_dblresult64_d = -(ppc_dblresult64_d);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<double, FNMSUB>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<double, FNMSUB>(reg_a, reg_b, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fadds() {
|
||||
ppc_grab_regsfpdab();
|
||||
|
||||
float intermediate = (float)val_reg_a + (float)val_reg_b;
|
||||
ppc_dblresult64_d = static_cast<double>(intermediate);
|
||||
ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
fpresult_update<float, ADD>(ppc_dblresult64_d, rc_flag);
|
||||
}
|
||||
else {
|
||||
ppc_confirm_inf_nan<float, ADD>(reg_a, reg_b, 0);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fsubs() {
|
||||
ppc_grab_regsfpdab();
|
||||
|
||||
float intermediate = (float)val_reg_a - (float)val_reg_b;
|
||||
ppc_dblresult64_d = static_cast<double>(intermediate);
|
||||
ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<float, SUB>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<float, SUB>(reg_a, reg_b, 0);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fdivs() {
|
||||
ppc_grab_regsfpdab();
|
||||
|
||||
float intermediate = (float)val_reg_a / (float)val_reg_b;
|
||||
ppc_dblresult64_d = static_cast<double>(intermediate);
|
||||
ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<float, DIV>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<float, DIV>(reg_a, reg_b, 0);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fmuls() {
|
||||
ppc_grab_regsfpdac();
|
||||
|
||||
float intermediate = (float)val_reg_a * (float)val_reg_c;
|
||||
ppc_dblresult64_d = static_cast<double>(intermediate);
|
||||
ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<float, MUL>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<float, MUL>(reg_a, 0, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fmadds() {
|
||||
@@ -477,31 +486,31 @@ void dppc_interpreter::ppc_fmadds() {
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<float, FMADD>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<float, FMADD>(reg_a, reg_b, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fmsubs() {
|
||||
ppc_grab_regsfpdabc();
|
||||
|
||||
float intermediate = (float)val_reg_a * (float)val_reg_c;
|
||||
float intermediate = float(val_reg_a * val_reg_c);
|
||||
intermediate -= (float)val_reg_b;
|
||||
ppc_dblresult64_d = static_cast<double>(intermediate);
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<float, FMADD>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<float, FMSUB>(reg_a, reg_b, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fnmadds() {
|
||||
@@ -514,13 +523,13 @@ void dppc_interpreter::ppc_fnmadds() {
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<float, FNMADD>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<float, FNMADD>(reg_a, reg_b, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fnmsubs() {
|
||||
@@ -534,13 +543,13 @@ void dppc_interpreter::ppc_fnmsubs() {
|
||||
|
||||
if (!isnan(ppc_dblresult64_d)) {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
fpresult_update(ppc_dblresult64_d, rc_flag);
|
||||
fpresult_update<float, FNMSUB>(ppc_dblresult64_d, rc_flag);
|
||||
} else {
|
||||
ppc_confirm_inf_nan<float, FNMSUB>(reg_a, reg_b, reg_c);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fabs() {
|
||||
@@ -551,7 +560,7 @@ void dppc_interpreter::ppc_fabs() {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fnabs() {
|
||||
@@ -563,7 +572,7 @@ void dppc_interpreter::ppc_fnabs() {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fneg() {
|
||||
@@ -574,7 +583,7 @@ void dppc_interpreter::ppc_fneg() {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fsel() {
|
||||
@@ -585,7 +594,7 @@ void dppc_interpreter::ppc_fsel() {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fsqrt() {
|
||||
@@ -594,7 +603,7 @@ void dppc_interpreter::ppc_fsqrt() {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fsqrts() {
|
||||
@@ -607,7 +616,7 @@ void dppc_interpreter::ppc_fsqrts() {
|
||||
ppc_store_sfpresult_flt(reg_d);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_frsqrte() {
|
||||
@@ -621,7 +630,7 @@ void dppc_interpreter::ppc_frsqrte() {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_frsp() {
|
||||
@@ -630,7 +639,7 @@ void dppc_interpreter::ppc_frsp() {
|
||||
ppc_store_dfpresult_flt(reg_d);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fres() {
|
||||
@@ -653,7 +662,7 @@ void dppc_interpreter::ppc_fres() {
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fctiw() {
|
||||
@@ -693,7 +702,7 @@ void dppc_interpreter::ppc_fctiw() {
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fctiwz() {
|
||||
@@ -719,7 +728,7 @@ void dppc_interpreter::ppc_fctiwz() {
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf1();
|
||||
ppc_changecrf1(ppc_dblresult64_d);
|
||||
}
|
||||
|
||||
// Floating Point Store and Load
|
||||
@@ -981,26 +990,30 @@ void dppc_interpreter::ppc_fcmpo() {
|
||||
ppc_grab_regsfpsab();
|
||||
|
||||
ppc_state.fpscr &= 0xFFFF0FFF;
|
||||
cmp_c = 0;
|
||||
crf_d = 4;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= (1 << (uint32_t)CRx_bit::CR_SO);
|
||||
} else if (db_test_a < db_test_b) {
|
||||
cmp_c |= (1 << (uint32_t)CRx_bit::CR_LT);
|
||||
} else if (db_test_a > db_test_b) {
|
||||
cmp_c |= (1 << (uint32_t)CRx_bit::CR_GT);
|
||||
} else {
|
||||
cmp_c |= (1 << (uint32_t)CRx_bit::CR_EQ);
|
||||
cmp_c |= (1 << CRx_bit::CR_SO);
|
||||
}
|
||||
|
||||
if (db_test_a < db_test_b) {
|
||||
cmp_c |= (1 << CRx_bit::CR_LT);
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= (1 << CRx_bit::CR_GT);
|
||||
}
|
||||
else {
|
||||
cmp_c |= (1 << CRx_bit::CR_EQ);
|
||||
}
|
||||
|
||||
fpresult_update(db_test_a, true);
|
||||
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~(FPSCR::FPRF)) | (cmp_c << 12);
|
||||
ppc_state.cr =
|
||||
((ppc_state.cr & ~((uint32_t)CR_select::CR0_field >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
||||
ppc_state.fpscr &= ~(FPSCR::FPRF);
|
||||
ppc_state.fpscr |= (cmp_c << 12);
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | ((cmp_c) >> crf_d));
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
if (ppc_state.fpscr & 0x80) {
|
||||
ppc_state.fpscr |= FPSCR::FX | FPSCR::VXSNAN;
|
||||
if ((ppc_state.fpscr & FPSCR::VE) == 0) {
|
||||
ppc_state.fpscr |= FPSCR::VXVC;
|
||||
}
|
||||
} else if ((db_test_a == qnan) || (db_test_b == qnan)) {
|
||||
@@ -1011,25 +1024,28 @@ void dppc_interpreter::ppc_fcmpo() {
|
||||
void dppc_interpreter::ppc_fcmpu() {
|
||||
ppc_grab_regsfpsab();
|
||||
|
||||
ppc_state.fpscr &= 0xFFFF0FFF;
|
||||
cmp_c = 0;
|
||||
crf_d = 4;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= (1 << (uint32_t)CRx_bit::CR_SO);
|
||||
} else if (db_test_a < db_test_b) {
|
||||
cmp_c |= (1 << (uint32_t)CRx_bit::CR_LT);
|
||||
} else if (db_test_a > db_test_b) {
|
||||
cmp_c |= (1 << (uint32_t)CRx_bit::CR_GT);
|
||||
} else {
|
||||
cmp_c |= (1 << (uint32_t)CRx_bit::CR_EQ);
|
||||
cmp_c |= (1 << CRx_bit::CR_SO);
|
||||
}
|
||||
|
||||
if (db_test_a < db_test_b) {
|
||||
cmp_c |= (1 << CRx_bit::CR_LT);
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= (1 << CRx_bit::CR_GT);
|
||||
}
|
||||
else {
|
||||
cmp_c |= (1 << CRx_bit::CR_EQ);
|
||||
}
|
||||
|
||||
fpresult_update(db_test_a, true);
|
||||
ppc_state.fpscr &= ~(FPSCR::FPRF);
|
||||
ppc_state.fpscr |= (cmp_c << 12);
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | ((cmp_c) >> crf_d));
|
||||
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~(FPSCR::FPRF)) | (cmp_c << 12);
|
||||
ppc_state.cr =
|
||||
((ppc_state.cr & ~((uint32_t)CR_select::CR0_field >> crf_d)) | ((cmp_c + xercon) >> crf_d));
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
//if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
// ppc_state.fpscr |= FPSCR::VX | FPSCR::VXSNAN;
|
||||
//}
|
||||
}
|
||||
+312
-234
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,10 +21,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file PowerPC Memory Management Unit emulation. */
|
||||
|
||||
#include "ppcmmu.h"
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "memaccess.h"
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <memaccess.h>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
@@ -356,6 +357,9 @@ uint32_t tlb_size_mask = TLB_SIZE - 1;
|
||||
uint64_t UnmappedVal = -1ULL;
|
||||
TLBEntry UnmappedMem = {TLB_INVALID_TAG, TLBFlags::PAGE_NOPHYS, 0, 0};
|
||||
|
||||
// Dummy page for catching writes to physical read-only pages
|
||||
static std::array<uint8_t, 4096> dummy_page;
|
||||
|
||||
uint8_t CurITLBMode = {0xFF}; // current ITLB mode
|
||||
uint8_t CurDTLBMode = {0xFF}; // current DTLB mode
|
||||
|
||||
@@ -527,7 +531,7 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
tlb_entry = tlb2_target_entry<TLBType::ITLB>(tag);
|
||||
tlb_entry->tag = tag;
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
tlb_entry->host_va_offset = (int64_t)reg_desc->mem_ptr - guest_va +
|
||||
tlb_entry->host_va_offs_r = (int64_t)reg_desc->mem_ptr - guest_va +
|
||||
(phys_addr - reg_desc->start);
|
||||
} else {
|
||||
ABORT_F("Instruction fetch from unmapped memory at 0x%08X!\n", phys_addr);
|
||||
@@ -600,8 +604,14 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write)
|
||||
tlb_entry->reg_desc = reg_desc;
|
||||
} else { // memory region backed by host memory
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
tlb_entry->host_va_offset = (int64_t)reg_desc->mem_ptr - guest_va +
|
||||
(phys_addr - reg_desc->start);
|
||||
tlb_entry->host_va_offs_r = (int64_t)reg_desc->mem_ptr - guest_va +
|
||||
(phys_addr - reg_desc->start);
|
||||
if (reg_desc->type == RT_ROM) {
|
||||
// redirect writes to the dummy page for ROM regions
|
||||
tlb_entry->host_va_offs_w = (int64_t)&dummy_page - guest_va;
|
||||
} else {
|
||||
tlb_entry->host_va_offs_w = tlb_entry->host_va_offs_r;
|
||||
}
|
||||
}
|
||||
return tlb_entry;
|
||||
} else {
|
||||
@@ -670,7 +680,7 @@ uint8_t *mmu_translate_imem(uint32_t vaddr)
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_itlb_hits++;
|
||||
#endif
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offset + vaddr);
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
} else {
|
||||
// primary ITLB miss -> look up address in the secondary ITLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::ITLB>(vaddr, tag);
|
||||
@@ -690,8 +700,8 @@ uint8_t *mmu_translate_imem(uint32_t vaddr)
|
||||
// refill the primary ITLB
|
||||
tlb1_entry->tag = tag;
|
||||
tlb1_entry->flags = tlb2_entry->flags;
|
||||
tlb1_entry->host_va_offset = tlb2_entry->host_va_offset;
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offset + vaddr);
|
||||
tlb1_entry->host_va_offs_r = tlb2_entry->host_va_offs_r;
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
}
|
||||
|
||||
ppc_set_cur_instruction(host_va);
|
||||
@@ -699,6 +709,271 @@ uint8_t *mmu_translate_imem(uint32_t vaddr)
|
||||
return host_va;
|
||||
}
|
||||
|
||||
void tlb_flush_entry(uint32_t ea)
|
||||
{
|
||||
TLBEntry *tlb_entry, *tlb1, *tlb2;
|
||||
|
||||
const uint32_t tag = ea & ~0xFFFUL;
|
||||
|
||||
for (int m = 0; m < 6; m++) {
|
||||
switch (m) {
|
||||
case 0:
|
||||
tlb1 = &itlb1_mode1[0];
|
||||
tlb2 = &itlb2_mode1[0];
|
||||
break;
|
||||
case 1:
|
||||
tlb1 = &itlb1_mode2[0];
|
||||
tlb2 = &itlb2_mode2[0];
|
||||
break;
|
||||
case 2:
|
||||
tlb1 = &itlb1_mode3[0];
|
||||
tlb2 = &itlb2_mode3[0];
|
||||
break;
|
||||
case 3:
|
||||
tlb1 = &dtlb1_mode1[0];
|
||||
tlb2 = &dtlb2_mode1[0];
|
||||
break;
|
||||
case 4:
|
||||
tlb1 = &dtlb1_mode2[0];
|
||||
tlb2 = &dtlb2_mode2[0];
|
||||
break;
|
||||
case 5:
|
||||
tlb1 = &dtlb1_mode3[0];
|
||||
tlb2 = &dtlb2_mode3[0];
|
||||
break;
|
||||
}
|
||||
|
||||
// flush primary TLB
|
||||
tlb_entry = &tlb1[(ea >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb_entry->tag == tag) {
|
||||
tlb_entry->tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
|
||||
}
|
||||
|
||||
// flush secondary TLB
|
||||
tlb_entry = &tlb2[((ea >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
for (int i = 0; i < TLB2_WAYS; i++) {
|
||||
if (tlb_entry[i].tag == tag) {
|
||||
tlb_entry[i].tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", ea);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_entries(TLBFlags type)
|
||||
{
|
||||
TLBEntry *m1_tlb, *m2_tlb, *m3_tlb;
|
||||
int i;
|
||||
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
m1_tlb = &itlb1_mode1[0];
|
||||
m2_tlb = &itlb1_mode2[0];
|
||||
m3_tlb = &itlb1_mode3[0];
|
||||
} else {
|
||||
m1_tlb = &dtlb1_mode1[0];
|
||||
m2_tlb = &dtlb1_mode2[0];
|
||||
m3_tlb = &dtlb1_mode3[0];
|
||||
}
|
||||
|
||||
// Flush entries from the primary TLBs
|
||||
for (i = 0; i < TLB_SIZE; i++) {
|
||||
if (m1_tlb[i].flags & type) {
|
||||
m1_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (m2_tlb[i].flags & type) {
|
||||
m2_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (m3_tlb[i].flags & type) {
|
||||
m3_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
}
|
||||
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
m1_tlb = &itlb2_mode1[0];
|
||||
m2_tlb = &itlb2_mode2[0];
|
||||
m3_tlb = &itlb2_mode3[0];
|
||||
} else {
|
||||
m1_tlb = &dtlb2_mode1[0];
|
||||
m2_tlb = &dtlb2_mode2[0];
|
||||
m3_tlb = &dtlb2_mode3[0];
|
||||
}
|
||||
|
||||
// Flush entries from the secondary TLBs
|
||||
for (i = 0; i < TLB_SIZE * TLB2_WAYS; i++) {
|
||||
if (dtlb2_mode1[i].flags & type) {
|
||||
dtlb2_mode1[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (dtlb2_mode2[i].flags & type) {
|
||||
dtlb2_mode2[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (dtlb2_mode3[i].flags & type) {
|
||||
dtlb2_mode3[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool gTLBFlushBatEntries = false;
|
||||
bool gTLBFlushPatEntries = false;
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_bat_entries()
|
||||
{
|
||||
if (!gTLBFlushBatEntries)
|
||||
return;
|
||||
|
||||
tlb_flush_entries<tlb_type>(TLBE_FROM_BAT);
|
||||
|
||||
gTLBFlushBatEntries = false;
|
||||
}
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_pat_entries()
|
||||
{
|
||||
if (!gTLBFlushPatEntries)
|
||||
return;
|
||||
|
||||
tlb_flush_entries<tlb_type>(TLBE_FROM_PAT);
|
||||
|
||||
gTLBFlushPatEntries = false;
|
||||
}
|
||||
|
||||
static void mpc601_bat_update(uint32_t bat_reg)
|
||||
{
|
||||
PPC_BAT_entry *ibat_entry, *dbat_entry;
|
||||
uint32_t bsm, hi_mask;
|
||||
int upper_reg_num;
|
||||
|
||||
upper_reg_num = bat_reg & 0xFFFFFFFE;
|
||||
|
||||
ibat_entry = &ibat_array[(bat_reg - 528) >> 1];
|
||||
dbat_entry = &dbat_array[(bat_reg - 528) >> 1];
|
||||
|
||||
if (ppc_state.spr[bat_reg | 1] & 0x40) {
|
||||
bsm = ppc_state.spr[upper_reg_num + 1] & 0x3F;
|
||||
hi_mask = ~((bsm << 17) | 0x1FFFF);
|
||||
|
||||
ibat_entry->valid = true;
|
||||
ibat_entry->access = (ppc_state.spr[upper_reg_num] >> 2) & 3;
|
||||
ibat_entry->prot = ppc_state.spr[upper_reg_num] & 3;
|
||||
ibat_entry->hi_mask = hi_mask;
|
||||
ibat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
ibat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
// copy IBAT entry to DBAT entry
|
||||
*dbat_entry = *ibat_entry;
|
||||
} else {
|
||||
// disable the corresponding BAT paars
|
||||
ibat_entry->valid = false;
|
||||
dbat_entry->valid = false;
|
||||
}
|
||||
|
||||
// MPC601 has unified BATs so we're going to fush both ITLB and DTLB
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
|
||||
}
|
||||
}
|
||||
|
||||
static void ppc_ibat_update(uint32_t bat_reg)
|
||||
{
|
||||
int upper_reg_num;
|
||||
uint32_t bl, hi_mask;
|
||||
PPC_BAT_entry* bat_entry;
|
||||
|
||||
upper_reg_num = bat_reg & 0xFFFFFFFE;
|
||||
|
||||
if (ppc_state.spr[upper_reg_num] & 3) { // is that BAT pair valid?
|
||||
bat_entry = &ibat_array[(bat_reg - 528) >> 1];
|
||||
bl = (ppc_state.spr[upper_reg_num] >> 2) & 0x7FF;
|
||||
hi_mask = ~((bl << 17) | 0x1FFFF);
|
||||
|
||||
bat_entry->access = ppc_state.spr[upper_reg_num] & 3;
|
||||
bat_entry->prot = ppc_state.spr[upper_reg_num + 1] & 3;
|
||||
bat_entry->hi_mask = hi_mask;
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ppc_dbat_update(uint32_t bat_reg)
|
||||
{
|
||||
int upper_reg_num;
|
||||
uint32_t bl, hi_mask;
|
||||
PPC_BAT_entry* bat_entry;
|
||||
|
||||
upper_reg_num = bat_reg & 0xFFFFFFFE;
|
||||
|
||||
if (ppc_state.spr[upper_reg_num] & 3) { // is that BAT pair valid?
|
||||
bat_entry = &dbat_array[(bat_reg - 536) >> 1];
|
||||
bl = (ppc_state.spr[upper_reg_num] >> 2) & 0x7FF;
|
||||
hi_mask = ~((bl << 17) | 0x1FFFF);
|
||||
|
||||
bat_entry->access = ppc_state.spr[upper_reg_num] & 3;
|
||||
bat_entry->prot = ppc_state.spr[upper_reg_num + 1] & 3;
|
||||
bat_entry->hi_mask = hi_mask;
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mmu_pat_ctx_changed()
|
||||
{
|
||||
// Page address translation context changed so we need to flush
|
||||
// all PAT entries from both ITLB and DTLB
|
||||
if (!gTLBFlushPatEntries) {
|
||||
gTLBFlushPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_pat_entries<TLBType::ITLB>);
|
||||
add_ctx_sync_action(&tlb_flush_pat_entries<TLBType::DTLB>);
|
||||
}
|
||||
}
|
||||
|
||||
void mmu_print_regs()
|
||||
{
|
||||
LOG_SCOPE_FUNCTION(INFO);
|
||||
LOG_F(INFO, "MSR = 0x%X\n", ppc_state.msr);
|
||||
|
||||
LOG_F(INFO, "BAT registers:");
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
LOG_F(INFO, "IBAT%dU = 0x%X, IBAT%dL = 0x%X",
|
||||
i, ppc_state.spr[528+i*2],
|
||||
i, ppc_state.spr[529+i*2]);
|
||||
}
|
||||
|
||||
if (!is_601_MMU) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
LOG_F(INFO, "DBAT%dU = 0x%X, DBAT%dL = 0x%X",
|
||||
i, ppc_state.spr[536+i*2],
|
||||
i, ppc_state.spr[537+i*2]);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_F(INFO, "");
|
||||
LOG_F(INFO, "SDR1 = 0x%X\n", ppc_state.spr[SPR::SDR1]);
|
||||
LOG_F(INFO, "Segment registers:");
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
LOG_F(INFO, "SR%d = 0x%X", i, ppc_state.sr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Forward declarations.
|
||||
static uint32_t read_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t size);
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t value,
|
||||
@@ -718,7 +993,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
#ifdef TLB_PROFILING
|
||||
num_primary_dtlb_hits++;
|
||||
#endif
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offset + guest_va);
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + guest_va);
|
||||
} else {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
@@ -741,10 +1016,8 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
tlb1_entry->tag = tag;
|
||||
tlb1_entry->flags = tlb2_entry->flags;
|
||||
tlb1_entry->host_va_offset = tlb2_entry->host_va_offset;
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offset + guest_va);
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + guest_va);
|
||||
} else { // otherwise, it's an access to a memory-mapped device
|
||||
#ifdef MMU_PROFILING
|
||||
iomem_reads_total++;
|
||||
@@ -816,7 +1089,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
tlb2_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
}
|
||||
}
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offset + guest_va);
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_w + guest_va);
|
||||
} else {
|
||||
// primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = lookup_secondary_tlb<TLBType::DTLB>(guest_va, tag);
|
||||
@@ -852,10 +1125,8 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
|
||||
if (tlb2_entry->flags & TLBFlags::PAGE_MEM) { // is it a real memory region?
|
||||
// refill the primary TLB
|
||||
tlb1_entry->tag = tag;
|
||||
tlb1_entry->flags = tlb2_entry->flags;
|
||||
tlb1_entry->host_va_offset = tlb2_entry->host_va_offset;
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offset + guest_va);
|
||||
*tlb1_entry = *tlb2_entry;
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_w + guest_va);
|
||||
} else { // otherwise, it's an access to a memory-mapped device
|
||||
#ifdef MMU_PROFILING
|
||||
iomem_writes_total++;
|
||||
@@ -966,205 +1237,6 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t value,
|
||||
}
|
||||
}
|
||||
|
||||
void tlb_flush_entry(uint32_t ea)
|
||||
{
|
||||
TLBEntry *tlb_entry, *tlb1, *tlb2;
|
||||
|
||||
const uint32_t tag = ea & ~0xFFFUL;
|
||||
|
||||
for (int m = 0; m < 6; m++) {
|
||||
switch (m) {
|
||||
case 0:
|
||||
tlb1 = &itlb1_mode1[0];
|
||||
tlb2 = &itlb2_mode1[0];
|
||||
break;
|
||||
case 1:
|
||||
tlb1 = &itlb1_mode2[0];
|
||||
tlb2 = &itlb2_mode2[0];
|
||||
break;
|
||||
case 2:
|
||||
tlb1 = &itlb1_mode3[0];
|
||||
tlb2 = &itlb2_mode3[0];
|
||||
break;
|
||||
case 3:
|
||||
tlb1 = &dtlb1_mode1[0];
|
||||
tlb2 = &dtlb2_mode1[0];
|
||||
break;
|
||||
case 4:
|
||||
tlb1 = &dtlb1_mode2[0];
|
||||
tlb2 = &dtlb2_mode2[0];
|
||||
break;
|
||||
case 5:
|
||||
tlb1 = &dtlb1_mode3[0];
|
||||
tlb2 = &dtlb2_mode3[0];
|
||||
break;
|
||||
}
|
||||
|
||||
// flush primary TLB
|
||||
tlb_entry = &tlb1[(ea >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb_entry->tag == tag) {
|
||||
tlb_entry->tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
|
||||
}
|
||||
|
||||
// flush secondary TLB
|
||||
tlb_entry = &tlb2[((ea >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
for (int i = 0; i < TLB2_WAYS; i++) {
|
||||
if (tlb_entry[i].tag == tag) {
|
||||
tlb_entry[i].tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", ea);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tlb_flush_entries(TLBFlags type)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Flush BAT entries from the primary TLBs
|
||||
for (i = 0; i < TLB_SIZE; i++) {
|
||||
if (dtlb1_mode2[i].flags & type) {
|
||||
dtlb1_mode2[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (dtlb1_mode3[i].flags & type) {
|
||||
dtlb1_mode3[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
}
|
||||
|
||||
// Flush BAT entries from the secondary TLBs
|
||||
for (i = 0; i < TLB_SIZE * TLB2_WAYS; i++) {
|
||||
if (dtlb2_mode2[i].flags & type) {
|
||||
dtlb2_mode2[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (dtlb2_mode3[i].flags & type) {
|
||||
dtlb2_mode3[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool gTLBFlushBatEntries = false;
|
||||
bool gTLBFlushPatEntries = false;
|
||||
|
||||
void tlb_flush_bat_entries()
|
||||
{
|
||||
if (!gTLBFlushBatEntries)
|
||||
return;
|
||||
|
||||
tlb_flush_entries(TLBE_FROM_BAT);
|
||||
|
||||
gTLBFlushBatEntries = false;
|
||||
}
|
||||
|
||||
void tlb_flush_pat_entries()
|
||||
{
|
||||
if (!gTLBFlushPatEntries)
|
||||
return;
|
||||
|
||||
tlb_flush_entries(TLBE_FROM_PAT);
|
||||
|
||||
gTLBFlushPatEntries = false;
|
||||
}
|
||||
|
||||
static void mpc601_bat_update(uint32_t bat_reg)
|
||||
{
|
||||
PPC_BAT_entry *ibat_entry, *dbat_entry;
|
||||
uint32_t bsm, hi_mask;
|
||||
uint8_t key, pp, prot;
|
||||
int upper_reg_num;
|
||||
|
||||
upper_reg_num = bat_reg & 0xFFFFFFFE;
|
||||
|
||||
ibat_entry = &ibat_array[(bat_reg - 528) >> 1];
|
||||
dbat_entry = &dbat_array[(bat_reg - 528) >> 1];
|
||||
|
||||
if (ppc_state.spr[bat_reg | 1] & 0x40) {
|
||||
bsm = ppc_state.spr[upper_reg_num + 1] & 0x3F;
|
||||
hi_mask = ~((bsm << 17) | 0x1FFFF);
|
||||
|
||||
ibat_entry->valid = true;
|
||||
ibat_entry->access = (ppc_state.spr[upper_reg_num] >> 2) & 3;
|
||||
ibat_entry->prot = ppc_state.spr[upper_reg_num] & 3;
|
||||
ibat_entry->hi_mask = hi_mask;
|
||||
ibat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
ibat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
// copy IBAT entry to DBAT entry
|
||||
*dbat_entry = *ibat_entry;
|
||||
} else {
|
||||
// disable the corresponding BAT paars
|
||||
ibat_entry->valid = false;
|
||||
dbat_entry->valid = false;
|
||||
}
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries);
|
||||
}
|
||||
}
|
||||
|
||||
static void ppc_ibat_update(uint32_t bat_reg)
|
||||
{
|
||||
int upper_reg_num;
|
||||
uint32_t bl, hi_mask;
|
||||
PPC_BAT_entry* bat_entry;
|
||||
|
||||
upper_reg_num = bat_reg & 0xFFFFFFFE;
|
||||
|
||||
if (ppc_state.spr[upper_reg_num] & 3) { // is that BAT pair valid?
|
||||
bat_entry = &ibat_array[(bat_reg - 528) >> 1];
|
||||
bl = (ppc_state.spr[upper_reg_num] >> 2) & 0x7FF;
|
||||
hi_mask = ~((bl << 17) | 0x1FFFF);
|
||||
|
||||
bat_entry->access = ppc_state.spr[upper_reg_num] & 3;
|
||||
bat_entry->prot = ppc_state.spr[upper_reg_num + 1] & 3;
|
||||
bat_entry->hi_mask = hi_mask;
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ppc_dbat_update(uint32_t bat_reg)
|
||||
{
|
||||
int upper_reg_num;
|
||||
uint32_t bl, hi_mask;
|
||||
PPC_BAT_entry* bat_entry;
|
||||
|
||||
upper_reg_num = bat_reg & 0xFFFFFFFE;
|
||||
|
||||
if (ppc_state.spr[upper_reg_num] & 3) { // is that BAT pair valid?
|
||||
bat_entry = &dbat_array[(bat_reg - 536) >> 1];
|
||||
bl = (ppc_state.spr[upper_reg_num] >> 2) & 0x7FF;
|
||||
hi_mask = ~((bl << 17) | 0x1FFFF);
|
||||
|
||||
bat_entry->access = ppc_state.spr[upper_reg_num] & 3;
|
||||
bat_entry->prot = ppc_state.spr[upper_reg_num + 1] & 3;
|
||||
bat_entry->hi_mask = hi_mask;
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mmu_pat_ctx_changed()
|
||||
{
|
||||
if (!gTLBFlushPatEntries) {
|
||||
gTLBFlushPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_pat_entries);
|
||||
}
|
||||
}
|
||||
|
||||
/* MMU profiling. */
|
||||
#ifdef MMU_PROFILING
|
||||
|
||||
@@ -1504,7 +1576,7 @@ static inline uint64_t tlb_translate_addr(uint32_t guest_va)
|
||||
// look up address in the primary TLB
|
||||
tlb1_entry = &pCurDTLB1[(guest_va >> PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb1_entry->tag == tag) { // primary TLB hit -> fast path
|
||||
return tlb1_entry->host_va_offset + guest_va;
|
||||
return tlb1_entry->host_va_offs_r + guest_va;
|
||||
} else { // primary TLB miss -> look up address in the secondary TLB
|
||||
tlb2_entry = &pCurDTLB2[((guest_va >> PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
if (tlb2_entry->tag == tag) {
|
||||
@@ -1543,8 +1615,8 @@ static inline uint64_t tlb_translate_addr(uint32_t guest_va)
|
||||
// refill the primary TLB
|
||||
tlb1_entry->tag = tag;
|
||||
tlb1_entry->flags = tlb2_entry->flags;
|
||||
tlb1_entry->host_va_offset = tlb2_entry->host_va_offset;
|
||||
return tlb1_entry->host_va_offset + guest_va;
|
||||
tlb1_entry->host_va_offs_r = tlb2_entry->host_va_offs_r;
|
||||
return tlb1_entry->host_va_offs_r + guest_va;
|
||||
} else { // an attempt to access a memory-mapped device
|
||||
return guest_va - tlb2_entry->reg_desc->start;
|
||||
}
|
||||
@@ -1859,42 +1931,42 @@ void ppc_mmu_init(uint32_t cpu_version)
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb1_mode2) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb1_mode3) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb2_mode1) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb2_mode2) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : itlb2_mode3) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
}
|
||||
|
||||
// invalidate all DTLB entries
|
||||
@@ -1902,42 +1974,48 @@ void ppc_mmu_init(uint32_t cpu_version)
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb1_mode2) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb1_mode3) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb2_mode1) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb2_mode2) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
for (auto &tlb_el : dtlb2_mode3) {
|
||||
tlb_el.tag = TLB_INVALID_TAG;
|
||||
tlb_el.flags = 0;
|
||||
tlb_el.lru_bits = 0;
|
||||
tlb_el.host_va_offset = 0;
|
||||
tlb_el.host_va_offs_r = 0;
|
||||
tlb_el.host_va_offs_w = 0;
|
||||
}
|
||||
|
||||
mmu_change_mode();
|
||||
|
||||
+8
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,11 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PPCMMU_H
|
||||
#define PPCMMU_H
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include "devices/memctrlbase.h"
|
||||
|
||||
/* Uncomment this to exhaustive MMU integrity checks. */
|
||||
//#define MMU_INTEGRITY_CHECKS
|
||||
@@ -70,6 +71,8 @@ typedef struct PATResult {
|
||||
} PATResult;
|
||||
|
||||
#define PAGE_SIZE_BITS 12
|
||||
#define PAGE_SIZE (1 << PAGE_SIZE_BITS)
|
||||
#define PAGE_MASK ~(PAGE_SIZE - 1)
|
||||
#define TLB_SIZE 4096
|
||||
#define TLB2_WAYS 4
|
||||
#define TLB_INVALID_TAG 0xFFFFFFFF
|
||||
@@ -79,9 +82,11 @@ typedef struct TLBEntry {
|
||||
uint16_t flags;
|
||||
uint16_t lru_bits;
|
||||
union {
|
||||
int64_t host_va_offset;
|
||||
int64_t host_va_offs_r;
|
||||
AddressMapEntry* reg_desc;
|
||||
};
|
||||
int64_t host_va_offs_w;
|
||||
int64_t unused;
|
||||
} TLBEntry;
|
||||
|
||||
enum TLBFlags : uint16_t {
|
||||
|
||||
+214
-394
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// General opcodes for the processor - ppcopcodes.cpp
|
||||
|
||||
#include "ppcdefs.h"
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <array>
|
||||
@@ -240,16 +241,25 @@ void dppc_interpreter::ppc_addis() {
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_add() {
|
||||
/*
|
||||
ppc_grab_regsdab();
|
||||
ppc_result_d = ppc_result_a + ppc_result_b;
|
||||
if (oe_flag)
|
||||
ppc_setsoov(ppc_result_a, ~ppc_result_b, ppc_result_d);
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_regd();*/
|
||||
GET_rD_iA_iB(ppc_cur_instruction);
|
||||
uint32_t result = imm_a + imm_b;
|
||||
if (oe_flag)
|
||||
ppc_setsoov(imm_a, ~imm_b, result);
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(result);
|
||||
SET_GPR(reg_d, result);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_addc() {
|
||||
/*
|
||||
ppc_grab_regsdab();
|
||||
ppc_result_d = ppc_result_a + ppc_result_b;
|
||||
ppc_carry(ppc_result_a, ppc_result_d);
|
||||
@@ -259,7 +269,15 @@ void dppc_interpreter::ppc_addc() {
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_regd();*/
|
||||
GET_rD_iA_iB(ppc_cur_instruction);
|
||||
uint32_t result = imm_a + imm_b;
|
||||
ppc_carry(imm_a, result);
|
||||
if (oe_flag)
|
||||
ppc_setsoov(imm_a, ~imm_b, result);
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(result);
|
||||
SET_GPR(reg_d, result);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_adde() {
|
||||
@@ -746,6 +764,7 @@ void dppc_interpreter::ppc_rlwimi() {
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_rlwinm() {
|
||||
/*
|
||||
ppc_grab_regssa();
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
||||
@@ -756,7 +775,19 @@ void dppc_interpreter::ppc_rlwinm() {
|
||||
if ((ppc_cur_instruction & 0x01) == 1) {
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
}
|
||||
ppc_store_result_rega();
|
||||
ppc_store_result_rega();*/
|
||||
uint32_t opcode = ppc_cur_instruction;
|
||||
GET_rA_iS(opcode);
|
||||
unsigned rot_sh = (opcode >> 11) & 31;
|
||||
unsigned rot_mb = (opcode >> 6) & 31;
|
||||
unsigned rot_me = (opcode >> 1) & 31;
|
||||
uint32_t mask = rot_mask(rot_mb, rot_me);
|
||||
uint32_t r = ((imm_d << rot_sh) | (imm_d >> (32 - rot_sh)));
|
||||
r &= mask;
|
||||
SET_GPR(reg_a, r);
|
||||
if (ppc_cur_instruction & 1) {
|
||||
ppc_changecrf0(r);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_rlwnm() {
|
||||
@@ -858,6 +889,23 @@ void dppc_interpreter::ppc_mfspr() {
|
||||
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
|
||||
}
|
||||
|
||||
#define NS_PER_SEC 1E9
|
||||
|
||||
static inline uint64_t calc_tbr_value()
|
||||
{
|
||||
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
|
||||
uint64_t tbr_inc = diff * tbr_freq_hz / NS_PER_SEC;
|
||||
return (tbr_wr_value + tbr_inc);
|
||||
}
|
||||
|
||||
static void update_timebase(uint64_t mask, uint64_t new_val)
|
||||
{
|
||||
uint64_t tbr_value = calc_tbr_value();
|
||||
tbr_wr_value = (tbr_value & mask) | new_val;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
LOG_F(9, "New TBR value = 0x%llu", tbr_wr_value);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_mtspr() {
|
||||
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 31) << 5) | ((ppc_cur_instruction >> 16) & 31);
|
||||
reg_s = (ppc_cur_instruction >> 21) & 31;
|
||||
@@ -877,13 +925,11 @@ void dppc_interpreter::ppc_mtspr() {
|
||||
}
|
||||
|
||||
switch (ref_spr) {
|
||||
// Mirror the TBRs in the SPR range to the user-mode TBRs.
|
||||
case 284:
|
||||
timebase_counter = (timebase_counter & 0xFFFFFFFF00000000ULL) + ppc_state.gpr[reg_s];
|
||||
update_timebase(0xFFFFFFFF00000000ULL, ppc_state.gpr[reg_s]);
|
||||
break;
|
||||
case 285:
|
||||
timebase_counter = (timebase_counter & 0x00000000FFFFFFFFULL) +
|
||||
(((uint64_t)(ppc_state.gpr[reg_s])) << 32);
|
||||
update_timebase(0x00000000FFFFFFFFULL, (uint64_t)(ppc_state.gpr[reg_s]) << 32);
|
||||
break;
|
||||
case 528:
|
||||
case 529:
|
||||
@@ -910,15 +956,18 @@ void dppc_interpreter::ppc_mtspr() {
|
||||
void dppc_interpreter::ppc_mftb() {
|
||||
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 31) << 5) | ((ppc_cur_instruction >> 16) & 31);
|
||||
reg_d = (ppc_cur_instruction >> 21) & 31;
|
||||
|
||||
uint64_t tbr_value = calc_tbr_value();
|
||||
|
||||
switch (ref_spr) {
|
||||
case 268:
|
||||
ppc_state.gpr[reg_d] = timebase_counter & 0xFFFFFFFFUL;
|
||||
break;
|
||||
case 269:
|
||||
ppc_state.gpr[reg_d] = (timebase_counter >> 32) & 0xFFFFFFFFUL;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Invalid TBR access attempted !\n");
|
||||
case 268:
|
||||
ppc_state.gpr[reg_d] = tbr_value & 0xFFFFFFFFUL;
|
||||
break;
|
||||
case 269:
|
||||
ppc_state.gpr[reg_d] = (tbr_value >> 32) & 0xFFFFFFFFUL;
|
||||
break;
|
||||
default:
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1302,6 +1351,8 @@ void dppc_interpreter::ppc_rfi() {
|
||||
ppc_state.msr = (new_msr_val | new_srr1_val) & 0xFFFBFFFFUL;
|
||||
ppc_next_instruction_address = ppc_state.spr[SPR::SRR0] & 0xFFFFFFFCUL;
|
||||
|
||||
do_ctx_sync(); // RFI is context synchronizing
|
||||
|
||||
mmu_change_mode();
|
||||
|
||||
grab_return = true;
|
||||
@@ -1309,6 +1360,7 @@ void dppc_interpreter::ppc_rfi() {
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_sc() {
|
||||
do_ctx_sync(); // SC is context synchronizing!
|
||||
ppc_exception_handler(Except_Type::EXC_SYSCALL, 0x20000);
|
||||
}
|
||||
|
||||
@@ -1394,203 +1446,112 @@ void dppc_interpreter::ppc_dcbz() {
|
||||
|
||||
// Integer Load and Store Functions
|
||||
|
||||
void dppc_interpreter::ppc_stb() {
|
||||
template <class T>
|
||||
void dppc_interpreter::ppc_st() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssa();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += reg_a ? ppc_result_a : 0;
|
||||
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_byte(ppc_effective_address, ppc_result_d);
|
||||
GET_rS_rA_OFFS(ppc_cur_instruction);
|
||||
uint32_t ea = offs + (reg_a ? GET_GPR(reg_a) : 0);
|
||||
mmu_write_vmem<T>(ea, GET_GPR(reg_s));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stbx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_byte(ppc_effective_address, ppc_result_d);
|
||||
}
|
||||
// explicitely instantiate all required ppc_st variants
|
||||
template void dppc_interpreter::ppc_st<uint8_t>(void); // stb
|
||||
template void dppc_interpreter::ppc_st<uint16_t>(void); // sth
|
||||
template void dppc_interpreter::ppc_st<uint32_t>(void); // stw
|
||||
|
||||
void dppc_interpreter::ppc_stbu() {
|
||||
template <class T>
|
||||
void dppc_interpreter::ppc_stu() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssa();
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += ppc_result_a;
|
||||
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_byte(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
GET_rS_rA_OFFS(ppc_cur_instruction);
|
||||
if (!reg_a) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
uint32_t ea = offs + GET_GPR(reg_a);
|
||||
mmu_write_vmem<T>(ea, GET_GPR(reg_s));
|
||||
SET_GPR(reg_a, ea);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stbux() {
|
||||
// explicitely instantiate all required ppc_stu variants
|
||||
template void dppc_interpreter::ppc_stu<uint8_t>(void); // stbu
|
||||
template void dppc_interpreter::ppc_stu<uint16_t>(void); // sthu
|
||||
template void dppc_interpreter::ppc_stu<uint32_t>(void); // stwu
|
||||
|
||||
template <class T>
|
||||
void dppc_interpreter::ppc_stx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssab();
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_byte(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
GET_rS_rA_iA_iB(ppc_cur_instruction);
|
||||
uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
|
||||
mmu_write_vmem<T>(ea, GET_GPR(reg_s));
|
||||
}
|
||||
|
||||
// explicitely instantiate all required ppc_stx variants
|
||||
template void dppc_interpreter::ppc_stx<uint8_t>(void); // stbx
|
||||
template void dppc_interpreter::ppc_stx<uint16_t>(void); // sthx
|
||||
template void dppc_interpreter::ppc_stx<uint32_t>(void); // stwx
|
||||
|
||||
template <class T>
|
||||
void dppc_interpreter::ppc_stux() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
GET_rS_rA_iA_iB(ppc_cur_instruction);
|
||||
if (!reg_a) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
uint32_t ea = imm_a + imm_b;
|
||||
mmu_write_vmem<T>(ea, GET_GPR(reg_s));
|
||||
SET_GPR(reg_a, ea);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_sth() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssa();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
||||
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_word(ppc_effective_address, ppc_result_d);
|
||||
}
|
||||
// explicitely instantiate all required ppc_stux variants
|
||||
template void dppc_interpreter::ppc_stux<uint8_t>(void); // stbux
|
||||
template void dppc_interpreter::ppc_stux<uint16_t>(void); // sthux
|
||||
template void dppc_interpreter::ppc_stux<uint32_t>(void); // stwux
|
||||
|
||||
void dppc_interpreter::ppc_sthu() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssa();
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += ppc_result_a;
|
||||
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_word(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_sthux() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssab();
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_word(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_sthx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_word(ppc_effective_address, ppc_result_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_sthbrx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
||||
ppc_result_d = (uint32_t)(BYTESWAP_16((uint16_t)ppc_result_d));
|
||||
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_word(ppc_effective_address, ppc_result_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stw() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssa();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += reg_a ? ppc_result_a : 0;
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stwx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stwcx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
// PLACEHOLDER CODE FOR STWCX - We need to check for reserve memory
|
||||
if (rc_flag == 0) {
|
||||
ppc_illegalop();
|
||||
} else {
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
||||
if (ppc_state.reserve) {
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x30000000 : 0x20000000;
|
||||
ppc_state.reserve = false;
|
||||
} else {
|
||||
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x10000000 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stwu() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssa();
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += ppc_result_a;
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stwux() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssab();
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
GET_rS_rA_iA_iB(ppc_cur_instruction);
|
||||
uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
|
||||
mmu_write_vmem<uint16_t>(ea, BYTESWAP_16((uint16_t)(GET_GPR(reg_s))));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stwbrx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
ppc_result_d = BYTESWAP_32(ppc_result_d);
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
GET_rS_rA_iA_iB(ppc_cur_instruction);
|
||||
uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
|
||||
mmu_write_vmem<uint32_t>(ea, BYTESWAP_32(GET_GPR(reg_s)));
|
||||
}
|
||||
|
||||
|
||||
void dppc_interpreter::ppc_stwcx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
if (rc_flag == 0) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
} else {
|
||||
// TODO: We need to check for memory reservation
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
||||
if (ppc_state.reserve) {
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x30000000 : 0x20000000;
|
||||
ppc_state.reserve = false;
|
||||
} else {
|
||||
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x10000000 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stmw() {
|
||||
@@ -1613,277 +1574,136 @@ void dppc_interpreter::ppc_stmw() {
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lbz() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
||||
//ppc_result_d = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lbzu() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
if ((reg_a != reg_d) || reg_a != 0) {
|
||||
ppc_effective_address += ppc_result_a;
|
||||
//ppc_result_d = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lbzx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
//ppc_result_d = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lbzux() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
if ((reg_a != reg_d) || reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
//ppc_result_d = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dppc_interpreter::ppc_lhz() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += reg_a ? ppc_result_a : 0;
|
||||
//ppc_result_d = mem_grab_word(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lhzu() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda();
|
||||
if ((reg_a != reg_d) || reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += ppc_result_a;
|
||||
//ppc_result_d = mem_grab_word(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lhzx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
//ppc_result_d = mem_grab_word(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lhzux() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
if ((reg_a != reg_d) || reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
//ppc_result_d = mem_grab_word(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lha() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
||||
//uint16_t val = mem_grab_word(ppc_effective_address);
|
||||
uint16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
||||
if (val & 0x8000) {
|
||||
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
|
||||
} else {
|
||||
ppc_result_d = (uint32_t)val;
|
||||
}
|
||||
ppc_store_result_regd();
|
||||
GET_rD_rA_OFFS(ppc_cur_instruction);
|
||||
uint32_t ea = offs + ((reg_a) ? ppc_state.gpr[reg_a] : 0);
|
||||
SET_GPR(reg_d, (int32_t)((int16_t)mmu_read_vmem<uint16_t>(ea)));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lhau() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda();
|
||||
if ((reg_a != reg_d) || reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += ppc_result_a;
|
||||
//uint16_t val = mem_grab_word(ppc_effective_address);
|
||||
uint16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
||||
if (val & 0x8000) {
|
||||
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
|
||||
} else {
|
||||
ppc_result_d = (uint32_t)val;
|
||||
}
|
||||
ppc_store_result_regd();
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
GET_rD_rA_OFFS(ppc_cur_instruction);
|
||||
if ((reg_a == reg_d) || reg_a == 0) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
uint32_t ea = offs + ppc_state.gpr[reg_a];
|
||||
SET_GPR(reg_d, (int32_t)((int16_t)mmu_read_vmem<uint16_t>(ea)));
|
||||
SET_GPR(reg_a, ea);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lhaux() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
//uint16_t val = mem_grab_word(ppc_effective_address);
|
||||
uint16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
||||
if (val & 0x8000) {
|
||||
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
|
||||
} else {
|
||||
ppc_result_d = (uint32_t)val;
|
||||
GET_rD_rA_iA_iB(ppc_cur_instruction);
|
||||
if ((reg_a == reg_d) || reg_a == 0) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
ppc_store_result_regd();
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
uint32_t ea = imm_a + imm_b;
|
||||
SET_GPR(reg_d, (int32_t)((int16_t)mmu_read_vmem<uint16_t>(ea)));
|
||||
SET_GPR(reg_a, ea);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lhax() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
//uint16_t val = mem_grab_word(ppc_effective_address);
|
||||
uint16_t val = mmu_read_vmem<uint16_t>(ppc_effective_address);
|
||||
if (val & 0x8000) {
|
||||
ppc_result_d = 0xFFFF0000UL | (uint32_t)val;
|
||||
} else {
|
||||
ppc_result_d = (uint32_t)val;
|
||||
}
|
||||
ppc_store_result_regd();
|
||||
GET_rD_rA_iA_iB(ppc_cur_instruction);
|
||||
uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
|
||||
SET_GPR(reg_d, (int32_t)((int16_t)mmu_read_vmem<uint16_t>(ea)));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lhbrx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
//ppc_result_d = (uint32_t)(BYTESWAP_16(mem_grab_word(ppc_effective_address)));
|
||||
ppc_result_d = (uint32_t)(BYTESWAP_16(mmu_read_vmem<uint16_t>(ppc_effective_address)));
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lwz() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
||||
//ppc_result_d = mem_grab_dword(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
ppc_store_result_regd();
|
||||
GET_rD_rA_iA_iB(ppc_cur_instruction);
|
||||
uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
|
||||
SET_GPR(reg_d, BYTESWAP_16(mmu_read_vmem<uint16_t>(ea)));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lwbrx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
//ppc_result_d = BYTESWAP_32(mem_grab_dword(ppc_effective_address));
|
||||
ppc_result_d = BYTESWAP_32(mmu_read_vmem<uint32_t>(ppc_effective_address));
|
||||
ppc_store_result_regd();
|
||||
GET_rD_rA_iA_iB(ppc_cur_instruction);
|
||||
uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
|
||||
SET_GPR(reg_d, BYTESWAP_32(mmu_read_vmem<uint32_t>(ea)));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lwzu() {
|
||||
template <class T>
|
||||
void dppc_interpreter::ppc_lz() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsda();
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
if ((reg_a != reg_d) || reg_a != 0) {
|
||||
ppc_effective_address += ppc_result_a;
|
||||
//ppc_result_d = mem_grab_dword(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
ppc_store_result_regd();
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
GET_rD_rA_OFFS(ppc_cur_instruction);
|
||||
uint32_t ea = offs + ((reg_a) ? ppc_state.gpr[reg_a] : 0);
|
||||
SET_GPR(reg_d, mmu_read_vmem<T>(ea));
|
||||
}
|
||||
|
||||
// explicitely instantiate all required ppc_lz variants
|
||||
template void dppc_interpreter::ppc_lz<uint8_t>(void); // lbz
|
||||
template void dppc_interpreter::ppc_lz<uint16_t>(void); // lhz
|
||||
template void dppc_interpreter::ppc_lz<uint32_t>(void); // lwz
|
||||
|
||||
template <class T>
|
||||
void dppc_interpreter::ppc_lzu() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
GET_rD_rA_OFFS(ppc_cur_instruction);
|
||||
if ((reg_a == reg_d) || reg_a == 0) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
uint32_t ea = offs + ppc_state.gpr[reg_a];
|
||||
SET_GPR(reg_d, mmu_read_vmem<T>(ea));
|
||||
SET_GPR(reg_a, ea);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lwzx() {
|
||||
// explicitely instantiate all required ppc_lzu variants
|
||||
template void dppc_interpreter::ppc_lzu<uint8_t>(void); // lbzu
|
||||
template void dppc_interpreter::ppc_lzu<uint16_t>(void); // lhzu
|
||||
template void dppc_interpreter::ppc_lzu<uint32_t>(void); // lwzu
|
||||
|
||||
template <class T>
|
||||
void dppc_interpreter::ppc_lzx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
//ppc_result_d = mem_grab_dword(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
ppc_store_result_regd();
|
||||
GET_rD_rA_iA_iB(ppc_cur_instruction);
|
||||
uint32_t ea = imm_b + ((reg_a) ? imm_a : 0);
|
||||
SET_GPR(reg_d, mmu_read_vmem<T>(ea));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lwzux() {
|
||||
// explicitely instantiate all required ppc_lzx variants
|
||||
template void dppc_interpreter::ppc_lzx<uint8_t>(void); // lbzx
|
||||
template void dppc_interpreter::ppc_lzx<uint16_t>(void); // lhzx
|
||||
template void dppc_interpreter::ppc_lzx<uint32_t>(void); // lwzx
|
||||
|
||||
template <class T>
|
||||
void dppc_interpreter::ppc_lzux() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
#endif
|
||||
ppc_grab_regsdab();
|
||||
if ((reg_a != reg_d) || reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
} else {
|
||||
GET_rD_rA_iA_iB(ppc_cur_instruction);
|
||||
if ((reg_a == reg_d) || reg_a == 0) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
//ppc_result_d = mem_grab_dword(ppc_effective_address);
|
||||
ppc_result_d = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
uint32_t ea = imm_a + imm_b;
|
||||
SET_GPR(reg_d, mmu_read_vmem<T>(ea));
|
||||
SET_GPR(reg_a, ea);
|
||||
}
|
||||
|
||||
// explicitely instantiate all required ppc_lzux variants
|
||||
template void dppc_interpreter::ppc_lzux<uint8_t>(void); // lbzux
|
||||
template void dppc_interpreter::ppc_lzux<uint16_t>(void); // lhzux
|
||||
template void dppc_interpreter::ppc_lzux<uint32_t>(void); // lwzux
|
||||
|
||||
void dppc_interpreter::ppc_lwarx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_loads++;
|
||||
|
||||
+17
-13
@@ -112,9 +112,9 @@ def gen_ppc_opcode(opc_str, imm):
|
||||
elif opc_str == "FADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FCMPO":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0x20 << 1)
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11) + (0x20 << 1)
|
||||
elif opc_str == "FCMPU":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11)
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11)
|
||||
elif opc_str == "FCTIW":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1)
|
||||
elif opc_str == "FCTIW.":
|
||||
@@ -140,19 +140,21 @@ def gen_ppc_opcode(opc_str, imm):
|
||||
elif opc_str == "FMADDS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMUL":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x19 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMUL.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x19 << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FMULS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x19 << 1)
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x19 << 1) + 1
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FNABS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x88 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1)
|
||||
elif opc_str == "FNABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x88 << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1) + 1
|
||||
elif opc_str == "FNEG":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x28 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1)
|
||||
elif opc_str == "FNEG.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMSUB":
|
||||
@@ -179,14 +181,16 @@ def gen_ppc_opcode(opc_str, imm):
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUBS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FRES":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "FSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "MULHW":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x4B << 1)
|
||||
elif opc_str == "MULHW.":
|
||||
|
||||
@@ -2027,4 +2027,28 @@ FSUBS. (RTN) :: frD 0x7FF8000000000000 | frA -inf | frB -inf | FPSCR: 0xA0811
|
||||
FSUBS. (RTZ) :: frD 0x7FF8000000000000 | frA -inf | frB -inf | FPSCR: 0xA0811001 | CR: 0x4A000002
|
||||
FSUBS. (RTPI) :: frD 0x7FF8000000000000 | frA -inf | frB -inf | FPSCR: 0xA0811002 | CR: 0x4A000002
|
||||
FSUBS. (RTNI) :: frD 0x7FF8000000000000 | frA -inf | frB -inf | FPSCR: 0xA0811003 | CR: 0x4A000002
|
||||
FSUBS. (VE) :: frD 0x0000000000000000 | frA -inf | frB -inf | FPSCR: 0xE0800080 | CR: 0x0E000000
|
||||
FSUBS. (VE) :: frD 0x0000000000000000 | frA -inf | frB -inf | FPSCR: 0xE0800080 | CR: 0x0E000000
|
||||
FCMPO :: frA 0.000000e+00 | frB 0.000000e+00 | FPSCR: 0x00002000 | CR: 0x02000000
|
||||
FCMPO :: frA 0.000000e+00 | frB 1.000000e+00 | FPSCR: 0x00008000 | CR: 0x08000000
|
||||
FCMPO :: frA 1.000000e+00 | frB 0.000000e+00 | FPSCR: 0x00004000 | CR: 0x04000000
|
||||
FCMPO :: frA 5.000000e-01 | frB 5.000000e-01 | FPSCR: 0x00002000 | CR: 0x02000000
|
||||
FCMPO :: frA 0.000000e+00 | frB 5.000000e-01 | FPSCR: 0x00008000 | CR: 0x08000000
|
||||
FCMPO :: frA 5.000000e-01 | frB 0.000000e+00 | FPSCR: 0x00004000 | CR: 0x04000000
|
||||
FCMPO :: frA nan | frB nan | FPSCR: 0xA0081000 | CR: 0x01000000
|
||||
FCMPO :: frA nan | frB nan | FPSCR: 0xA1081000 | CR: 0x01000000
|
||||
FCMPO :: frA inf | frB inf | FPSCR: 0x00002000 | CR: 0x02000000
|
||||
FCMPO :: frA inf | frB -inf | FPSCR: 0x00004000 | CR: 0x04000000
|
||||
FCMPO :: frA -inf | frB inf | FPSCR: 0x00008000 | CR: 0x08000000
|
||||
FCMPO :: frA -inf | frB -inf | FPSCR: 0x00002000 | CR: 0x02000000
|
||||
FCMPU :: frA 0.000000e+00 | frB 0.000000e+00 | FPSCR: 0x00002000 | CR: 0x02000000
|
||||
FCMPU :: frA 0.000000e+00 | frB 1.000000e+00 | FPSCR: 0x00008000 | CR: 0x08000000
|
||||
FCMPU :: frA 1.000000e+00 | frB 0.000000e+00 | FPSCR: 0x00004000 | CR: 0x04000000
|
||||
FCMPU :: frA 5.000000e-01 | frB 5.000000e-01 | FPSCR: 0x00002000 | CR: 0x02000000
|
||||
FCMPU :: frA 0.000000e+00 | frB 5.000000e-01 | FPSCR: 0x00008000 | CR: 0x08000000
|
||||
FCMPU :: frA 5.000000e-01 | frB 0.000000e+00 | FPSCR: 0x00004000 | CR: 0x04000000
|
||||
FCMPU :: frA nan | frB nan | FPSCR: 0x00001000 | CR: 0x01000000
|
||||
FCMPU :: frA nan | frB nan | FPSCR: 0xA1001000 | CR: 0x01000000
|
||||
FCMPU :: frA inf | frB inf | FPSCR: 0x00002000 | CR: 0x02000000
|
||||
FCMPU :: frA inf | frB -inf | FPSCR: 0x00004000 | CR: 0x04000000
|
||||
FCMPU :: frA -inf | frB inf | FPSCR: 0x00008000 | CR: 0x08000000
|
||||
FCMPU :: frA -inf | frB -inf | FPSCR: 0x00002000 | CR: 0x02000000
|
||||
+664
-640
File diff suppressed because it is too large.
Load diff
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 "../ppcdisasm.h"
|
||||
#include "../ppcemu.h"
|
||||
#include <cmath>
|
||||
@@ -208,7 +229,7 @@ static void read_test_float_data() {
|
||||
dfp_src3 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("round=", 0) == 0) {
|
||||
rounding_mode = tokens[i].substr(6, 3);
|
||||
ppc_state.fpscr &= 0xFFFFFFFC;
|
||||
ppc_state.fpscr = 0;
|
||||
if (rounding_mode.compare("RTN") == 0) {
|
||||
ppc_state.fpscr = 0x0;
|
||||
} else if (rounding_mode.compare("RTZ") == 0) {
|
||||
@@ -242,7 +263,7 @@ static void read_test_float_data() {
|
||||
ppc_state.fpr[4].dbl64_r = dfp_src2;
|
||||
ppc_state.fpr[5].dbl64_r = dfp_src3;
|
||||
|
||||
ppc_state.cr = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
@@ -282,6 +303,9 @@ int main() {
|
||||
|
||||
read_test_data();
|
||||
|
||||
cout << endl << "Float IEEE suport: " << (bool)std::numeric_limits<float>::is_iec559 << endl;
|
||||
cout << endl << "Double IEEE suport: " << (bool)std::numeric_limits<double>::is_iec559 << endl;
|
||||
|
||||
cout << endl << "Testing floating point instructions:" << endl;
|
||||
|
||||
read_test_float_data();
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 "../ppcdisasm.h"
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
+17
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
@@ -117,13 +118,23 @@ static void disasm_68k(uint32_t count, uint32_t address) {
|
||||
code_size = sizeof(code);
|
||||
dis_addr = address;
|
||||
|
||||
// catch and handle F-Traps (Nanokernel calls) ourselves because
|
||||
// Capstone will likely return no meaningful assembly for them
|
||||
if ((code[0] & 0xF0) == 0xF0) {
|
||||
goto print_bin;
|
||||
}
|
||||
|
||||
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
|
||||
cout << uppercase << hex << insn->address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
|
||||
address = dis_addr;
|
||||
} else {
|
||||
cout << "DS.W " << hex << ((code[0] << 8) | code[1]) << endl;
|
||||
print_bin:
|
||||
cout << uppercase << hex << address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << "dc.w" << "$" << hex <<
|
||||
((code[0] << 8) | code[1]) << endl;
|
||||
address += 2;
|
||||
}
|
||||
}
|
||||
@@ -489,7 +500,11 @@ void enter_debugger() {
|
||||
exec_until_68k(addr);
|
||||
#endif
|
||||
} else {
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
ppc_exec_until(addr);
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
LOG_F(INFO, "Time elapsed: %lld ns", time_elapsed.count());
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 DEBUGGER_H_
|
||||
#define DEBUGGER_H_
|
||||
|
||||
|
||||
+14
-1
@@ -2,7 +2,20 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
file(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/i2c/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
)
|
||||
|
||||
add_library(devices OBJECT ${SOURCES})
|
||||
target_link_libraries(devices PRIVATE cubeb)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,7 +25,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "devices/adb.h"
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
@@ -37,8 +39,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <thirdparty/SDL2/include/SDL_stdinc.h>
|
||||
#endif
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ADB_Bus::ADB_Bus() {
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,10 +21,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Descriptor-based direct memory access emulation. */
|
||||
|
||||
#include "dmacore.h"
|
||||
#include "dbdma.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "endianswap.h"
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <loguru.hpp>
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,7 +29,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef DB_DMA_H
|
||||
#define DB_DMA_H
|
||||
|
||||
#include "dmacore.h"
|
||||
#include <devices/common/dmacore.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
File renamed without changes.
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_ID_H
|
||||
#define MACHINE_ID_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "mmiodevice.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/**
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,7 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MMIO_DEVICE_H
|
||||
#define MMIO_DEVICE_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,7 +19,8 @@ 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 "nvram.h"
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PCI_DEVICE_H
|
||||
#define PCI_DEVICE_H
|
||||
|
||||
#include "mmiodevice.h"
|
||||
#include "pcihost.h"
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 PCI_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance) = 0;
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj) = 0;
|
||||
};
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -21,7 +21,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file MESH (Macintosh Enhanced SCSI Hardware) controller emulation. */
|
||||
|
||||
#include "mesh.h"
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file NCR 53C94 SCSI controller emulation. */
|
||||
|
||||
#include "ncr53c94.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
uint8_t Ncr53C94::read(uint8_t reg_offset)
|
||||
{
|
||||
LOG_F(9, "NCR53C94: reading from register %d", reg_offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Ncr53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
LOG_F(INFO, "NCR53C94: writing 0x%X to %d register", value, reg_offset);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file NCR 53C94 SCSI controller definitions. */
|
||||
|
||||
/* NOTE: Power Macintosh computers don't have a real NCR 53C94 chip.
|
||||
The corresponding functionality is provided by the 53C94 compatible
|
||||
cell in the custom Curio IC (Am79C950).
|
||||
*/
|
||||
|
||||
#ifndef NCR53C94_H
|
||||
#define NCR53C94_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/** NCR 53C94 read registers */
|
||||
namespace Read {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Status = 4,
|
||||
Interrupt = 5,
|
||||
Seq_Step = 6,
|
||||
FIFO_Flags = 7,
|
||||
Config_1 = 8,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Curio extension?
|
||||
Xfer_Cnt_Hi = 0xE, // Curio extension?
|
||||
DMA = 0xF, // Curio extension?
|
||||
};
|
||||
};
|
||||
|
||||
/** NCR 53C94 write registers */
|
||||
namespace Write {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Dest_Bus_ID = 4,
|
||||
Sel_Timeout = 5,
|
||||
Synch_Period = 6,
|
||||
Synch_Offset = 7,
|
||||
Config_1 = 8,
|
||||
Clk_Conv_Fac = 9,
|
||||
Test_Mode = 0xA,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Curio extension?
|
||||
Chip_ID = 0xE, // Curio extension?
|
||||
DMA = 0xF, // Curio extension?
|
||||
};
|
||||
};
|
||||
|
||||
class Ncr53C94 {
|
||||
public:
|
||||
Ncr53C94() = default;
|
||||
~Ncr53C94() = default;
|
||||
|
||||
// NCR 53C94 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint8_t chip_id;
|
||||
};
|
||||
|
||||
#endif // NCR53C94_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,38 +24,46 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski 2019
|
||||
*/
|
||||
|
||||
#include "viacuda.h"
|
||||
#include "adb.h"
|
||||
#include <cinttypes>
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ViaCuda::ViaCuda() {
|
||||
this->name = "ViaCuda";
|
||||
|
||||
/* FIXME: is this the correct
|
||||
VIA initialization? */
|
||||
this->via_regs[VIA_A] = 0x80;
|
||||
this->via_regs[VIA_DIRB] = 0xFF;
|
||||
this->via_regs[VIA_DIRA] = 0xFF;
|
||||
// VIA reset clears all internal registers to logic 0
|
||||
// except timers/counters and the shift register
|
||||
// as stated in the 6522 datasheet
|
||||
this->via_regs[VIA_A] = 0;
|
||||
this->via_regs[VIA_B] = 0;
|
||||
this->via_regs[VIA_DIRB] = 0;
|
||||
this->via_regs[VIA_DIRA] = 0;
|
||||
this->via_regs[VIA_IER] = 0;
|
||||
this->via_regs[VIA_ACR] = 0;
|
||||
this->via_regs[VIA_PCR] = 0;
|
||||
this->via_regs[VIA_IFR] = 0;
|
||||
|
||||
// load maximum value into the timer registers for safety
|
||||
// (not prescribed in the 6522 datasheet)
|
||||
this->via_regs[VIA_T1LL] = 0xFF;
|
||||
this->via_regs[VIA_T1LH] = 0xFF;
|
||||
this->via_regs[VIA_IER] = 0x7F;
|
||||
this->via_regs[VIA_T2CL] = 0xFF;
|
||||
this->via_regs[VIA_T2CH] = 0xFF;
|
||||
|
||||
// PRAM Pre-Initialization
|
||||
this->pram_obj = new NVram("pram.bin", 256);
|
||||
// PRAM is part of Cuda
|
||||
this->pram_obj = std::unique_ptr<NVram> (new NVram("pram.bin", 256));
|
||||
|
||||
this->adb_obj = new ADB_Bus();
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
||||
ViaCuda::~ViaCuda() {
|
||||
if (this->pram_obj)
|
||||
delete (this->pram_obj);
|
||||
}
|
||||
|
||||
void ViaCuda::init() {
|
||||
this->old_tip = 0;
|
||||
this->old_byteack = 0;
|
||||
@@ -68,7 +76,7 @@ void ViaCuda::init() {
|
||||
uint8_t ViaCuda::read(int reg) {
|
||||
uint8_t res;
|
||||
|
||||
LOG_F(9, "Read VIA reg %x \n", (uint32_t)reg);
|
||||
LOG_F(9, "Read VIA reg %d", reg);
|
||||
|
||||
res = this->via_regs[reg & 0xF];
|
||||
|
||||
@@ -79,7 +87,7 @@ uint8_t ViaCuda::read(int reg) {
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A! \n");
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A!");
|
||||
break;
|
||||
case VIA_IER:
|
||||
res |= 0x80; /* bit 7 always reads as "1" */
|
||||
@@ -96,27 +104,27 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted write to VIA Port A! \n");
|
||||
LOG_F(WARNING, "Attempted write to VIA Port A!");
|
||||
break;
|
||||
case VIA_DIRB:
|
||||
LOG_F(9, "VIA_DIRB = %x \n", (uint32_t)value);
|
||||
LOG_F(9, "VIA_DIRB = 0x%X", value);
|
||||
this->via_regs[VIA_DIRB] = value;
|
||||
break;
|
||||
case VIA_DIRA:
|
||||
LOG_F(9, "VIA_DIRA = %x \n", (uint32_t)value);
|
||||
LOG_F(9, "VIA_DIRA = 0x%X", value);
|
||||
this->via_regs[VIA_DIRA] = value;
|
||||
break;
|
||||
case VIA_PCR:
|
||||
LOG_F(9, "VIA_PCR = %x \n", (uint32_t)value);
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
this->via_regs[VIA_PCR] = value;
|
||||
break;
|
||||
case VIA_ACR:
|
||||
LOG_F(9, "VIA_ACR = %x \n", (uint32_t)value);
|
||||
LOG_F(9, "VIA_ACR = 0x%X", value);
|
||||
this->via_regs[VIA_ACR] = value;
|
||||
break;
|
||||
case VIA_IER:
|
||||
this->via_regs[VIA_IER] = (value & 0x80) ? value & 0x7F : this->via_regs[VIA_IER] & ~value;
|
||||
LOG_F(INFO, "VIA_IER updated to %d \n", (uint32_t)this->via_regs[VIA_IER]);
|
||||
LOG_F(9, "VIA_IER updated to 0x%X", this->via_regs[VIA_IER]);
|
||||
print_enabled_ints();
|
||||
break;
|
||||
default:
|
||||
@@ -129,7 +137,7 @@ void ViaCuda::print_enabled_ints() {
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (this->via_regs[VIA_IER] & (1 << i))
|
||||
LOG_F(INFO, "VIA %s interrupt enabled \n", via_int_src[i]);
|
||||
LOG_F(INFO, "VIA %s interrupt enabled", via_int_src[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +151,7 @@ inline void ViaCuda::assert_sr_int() {
|
||||
|
||||
void ViaCuda::write(uint8_t new_state) {
|
||||
if (!ready()) {
|
||||
LOG_F(WARNING, "Cuda not ready! \n");
|
||||
LOG_F(WARNING, "Cuda not ready!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,7 +162,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
|
||||
return;
|
||||
|
||||
LOG_F(9, "Cuda state changed! \n");
|
||||
LOG_F(9, "Cuda state changed!");
|
||||
|
||||
this->old_tip = new_tip;
|
||||
this->old_byteack = new_byteack;
|
||||
@@ -174,7 +182,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
|
||||
this->in_count = 0;
|
||||
} else {
|
||||
LOG_F(9, "Cuda: enter sync state \n");
|
||||
LOG_F(9, "Cuda: enter sync state");
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; /* assert TREQ */
|
||||
this->treq = 0;
|
||||
this->in_count = 0;
|
||||
@@ -188,7 +196,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
assert_sr_int(); /* tell the system we've read the data */
|
||||
} else {
|
||||
LOG_F(WARNING, "Cuda input buffer exhausted! \n");
|
||||
LOG_F(WARNING, "Cuda input buffer too small. Truncating data!");
|
||||
}
|
||||
} else { /* data transfer: Cuda --> Host */
|
||||
(this->*out_handler)();
|
||||
@@ -197,11 +205,17 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
}
|
||||
}
|
||||
|
||||
/* sends zeros to host at infinitum */
|
||||
/* sends zeros to host ad infinitum */
|
||||
void ViaCuda::null_out_handler() {
|
||||
this->via_regs[VIA_SR] = 0;
|
||||
}
|
||||
|
||||
/* sends PRAM content to host ad infinitum */
|
||||
void ViaCuda::pram_out_handler()
|
||||
{
|
||||
this->via_regs[VIA_SR] = this->pram_obj->read_byte(this->cur_pram_addr++);
|
||||
}
|
||||
|
||||
/* sends data from out_buf until exhausted, then switches to next_out_handler */
|
||||
void ViaCuda::out_buf_handler() {
|
||||
if (this->out_pos < this->out_count) {
|
||||
@@ -245,7 +259,7 @@ void ViaCuda::error_response(uint32_t error) {
|
||||
|
||||
void ViaCuda::process_packet() {
|
||||
if (this->in_count < 2) {
|
||||
LOG_F(ERROR, "Cuda: invalid packet (too few data)!\n");
|
||||
LOG_F(ERROR, "Cuda: invalid packet (too few data)!");
|
||||
error_response(CUDA_ERR_BAD_SIZE);
|
||||
return;
|
||||
}
|
||||
@@ -256,16 +270,16 @@ void ViaCuda::process_packet() {
|
||||
process_adb_command(this->in_buf[1], this->in_count - 2);
|
||||
break;
|
||||
case CUDA_PKT_PSEUDO:
|
||||
LOG_F(9, "Cuda: pseudo command packet received \n");
|
||||
LOG_F(9, "Command: %x \n", (uint32_t)(this->in_buf[1]));
|
||||
LOG_F(9, "Data count: %d \n ", this->in_count);
|
||||
LOG_F(9, "Cuda: pseudo command packet received");
|
||||
LOG_F(9, "Command: 0x%X", this->in_buf[1]);
|
||||
LOG_F(9, "Data count: %d", this->in_count);
|
||||
for (int i = 0; i < this->in_count; i++) {
|
||||
LOG_F(9, "%x ,", (uint32_t)(this->in_buf[i]));
|
||||
LOG_F(9, "0x%X ,", this->in_buf[i]);
|
||||
}
|
||||
pseudo_command(this->in_buf[1], this->in_count - 2);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported packet type = %d \n", (uint32_t)(this->in_buf[0]));
|
||||
LOG_F(ERROR, "Cuda: unsupported packet type = %d", this->in_buf[0]);
|
||||
error_response(CUDA_ERR_BAD_PKT);
|
||||
}
|
||||
}
|
||||
@@ -275,13 +289,13 @@ void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
|
||||
int cmd = cmd_byte & 0xF;
|
||||
|
||||
if (!cmd) {
|
||||
LOG_F(9, "Cuda: ADB SendReset command requested\n");
|
||||
LOG_F(9, "Cuda: ADB SendReset command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else if (cmd == 1) {
|
||||
LOG_F(9, "Cuda: ADB Flush command requested\n");
|
||||
LOG_F(9, "Cuda: ADB Flush command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else if ((cmd & 0xC) == 8) {
|
||||
LOG_F(9, "Cuda: ADB Listen command requested\n");
|
||||
LOG_F(9, "Cuda: ADB Listen command requested");
|
||||
int adb_reg = cmd_byte & 0x3;
|
||||
if (adb_obj->listen(adb_dev, adb_reg)) {
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
@@ -292,7 +306,7 @@ void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
}
|
||||
} else if ((cmd & 0xC) == 0xC) {
|
||||
LOG_F(9, "Cuda: ADB Talk command requested\n");
|
||||
LOG_F(9, "Cuda: ADB Talk command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
int adb_reg = cmd_byte & 0x3;
|
||||
if (adb_obj->talk(adb_dev, adb_reg, this->in_buf[2])) {
|
||||
@@ -301,32 +315,105 @@ void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "Cuda: unsupported ADB command 0x%x \n", cmd);
|
||||
LOG_F(ERROR, "Cuda: unsupported ADB command 0x%X", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
uint16_t addr;
|
||||
int i;
|
||||
|
||||
switch (cmd) {
|
||||
case CUDA_START_STOP_AUTOPOLL:
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: autopoll started, rate: %dms", this->poll_rate);
|
||||
LOG_F(INFO, "Cuda: autopoll started, rate: %d ms", this->poll_rate);
|
||||
} else {
|
||||
LOG_F(INFO, "Cuda: autopoll stopped");
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_PRAM:
|
||||
case CUDA_READ_MCU_MEM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->pram_obj->read_byte(this->in_buf[2]);
|
||||
// if starting address is within PRAM region
|
||||
// prepare to transfer PRAM content, othwesise we will send zeroes
|
||||
if (addr >= CUDA_PRAM_START && addr <= CUDA_PRAM_END) {
|
||||
this->cur_pram_addr = addr - CUDA_PRAM_START;
|
||||
this->next_out_handler = &ViaCuda::pram_out_handler;
|
||||
} else if (addr >= CUDA_ROM_START) {
|
||||
// HACK: Cuda ROM dump requsted so let's partially fake it
|
||||
this->out_buf[3] = 0; // empty copyright string
|
||||
WRITE_WORD_BE_A(&this->out_buf[4], 0x0019U);
|
||||
WRITE_WORD_BE_A(&this->out_buf[6], CUDA_FW_VERSION_MAJOR);
|
||||
WRITE_WORD_BE_A(&this->out_buf[8], CUDA_FW_VERSION_MINOR);
|
||||
this->out_count += 7;
|
||||
}
|
||||
this->is_open_ended = true;
|
||||
break;
|
||||
case CUDA_GET_REAL_TIME:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = (uint8_t)((this->real_time >> 24) & 0xFF);
|
||||
this->out_buf[3] = (uint8_t)((this->real_time >> 16) & 0xFF);
|
||||
this->out_buf[4] = (uint8_t)((this->real_time >> 8) & 0xFF);
|
||||
this->out_buf[5] = (uint8_t)((this->real_time) & 0xFF);
|
||||
break;
|
||||
case CUDA_WRITE_MCU_MEM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
// if addr is inside PRAM, update PRAM with data from in_buf
|
||||
// otherwise, ignore data in in_buf
|
||||
if (addr >= CUDA_PRAM_START && addr <= CUDA_PRAM_END) {
|
||||
for (i = 0; i < this->in_count - 4; i++) {
|
||||
this->pram_obj->write_byte((addr - CUDA_PRAM_START + i) & 0xFF,
|
||||
this->in_buf[4+i]);
|
||||
}
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_PRAM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
if (addr <= 0xFF) {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
// this command is open-ended so set up the corresponding context
|
||||
this->cur_pram_addr = addr;
|
||||
this->next_out_handler = &ViaCuda::pram_out_handler;
|
||||
this->is_open_ended = true;
|
||||
} else {
|
||||
error_response(CUDA_ERR_BAD_PAR);
|
||||
}
|
||||
break;
|
||||
case CUDA_SET_REAL_TIME:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->real_time = ((uint32_t)in_buf[2]) >> 24;
|
||||
this->real_time += ((uint32_t)in_buf[3]) >> 16;
|
||||
this->real_time += ((uint32_t)in_buf[4]) >> 8;
|
||||
this->real_time += ((uint32_t)in_buf[5]);
|
||||
break;
|
||||
case CUDA_WRITE_PRAM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
if (addr <= 0xFF) {
|
||||
// transfer data from in_buf to PRAM
|
||||
for (i = 0; i < this->in_count - 4; i++) {
|
||||
this->pram_obj->write_byte((addr + i) & 0xFF, this->in_buf[4+i]);
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
} else {
|
||||
error_response(CUDA_ERR_BAD_PAR);
|
||||
}
|
||||
break;
|
||||
case CUDA_FILE_SERVER_FLAG:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->pram_obj->write_byte(this->in_buf[2], this->in_buf[3]);
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: File server flag on");
|
||||
this->file_server = true;
|
||||
} else {
|
||||
LOG_F(INFO, "Cuda: File server flag off");
|
||||
this->file_server = false;
|
||||
}
|
||||
break;
|
||||
case CUDA_SET_AUTOPOLL_RATE:
|
||||
this->poll_rate = this->in_buf[2];
|
||||
LOG_F(INFO, "Cuda: autopoll rate set to: %d", this->poll_rate);
|
||||
LOG_F(INFO, "Cuda: autopoll rate set to %d ms", this->poll_rate);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_GET_AUTOPOLL_RATE:
|
||||
@@ -334,6 +421,20 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
this->out_buf[3] = this->poll_rate;
|
||||
this->out_count++;
|
||||
break;
|
||||
case CUDA_SET_DEVICE_LIST:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->device_mask = ((uint16_t)in_buf[2]) >> 8;
|
||||
this->device_mask += ((uint16_t)in_buf[3]);
|
||||
break;
|
||||
case CUDA_GET_DEVICE_LIST:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = (uint8_t)((this->device_mask >> 8) & 0xFF);
|
||||
this->out_buf[3] = (uint8_t)((this->device_mask) & 0xFF);
|
||||
break;
|
||||
case CUDA_ONE_SECOND_MODE:
|
||||
LOG_F(INFO, "Cuda: One Second Interrupt - Byte Sent: %d", this->in_buf[2]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
|
||||
@@ -346,11 +447,19 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
}
|
||||
break;
|
||||
case CUDA_OUT_PB0: /* undocumented call! */
|
||||
LOG_F(INFO, "Cuda: send %d to PB0 \n", (int)(this->in_buf[2]));
|
||||
LOG_F(INFO, "Cuda: send %d to PB0", (int)(this->in_buf[2]));
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_POWER_DOWN:
|
||||
case CUDA_MONO_STABLE_RESET:
|
||||
case CUDA_RESTART_SYSTEM:
|
||||
/* really kludge temp code */
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x! \n", cmd);
|
||||
//exit(0);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported pseudo command 0x%x \n", cmd);
|
||||
LOG_F(ERROR, "Cuda: unsupported pseudo command 0x%X", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
@@ -366,7 +475,7 @@ void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, in
|
||||
dev_addr >>= 1; /* strip RD/WR bit */
|
||||
|
||||
if (!this->start_transaction(dev_addr)) {
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -375,7 +484,7 @@ void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, in
|
||||
or the target device doesn't acknowledge that indicates an error */
|
||||
for (int i = 0; i < in_bytes; i++) {
|
||||
if (!this->send_byte(dev_addr, in_buf[i])) {
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -394,7 +503,7 @@ void ViaCuda::i2c_comb_transaction(
|
||||
int op_type = dev_addr1 & 1; /* 0 - write to device, 1 - read from device */
|
||||
|
||||
if ((dev_addr & 0xFE) != (dev_addr1 & 0xFE)) {
|
||||
LOG_F(ERROR, "Combined I2C: dev_addr mismatch!\n");
|
||||
LOG_F(ERROR, "Combined I2C: dev_addr mismatch!");
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -402,13 +511,13 @@ void ViaCuda::i2c_comb_transaction(
|
||||
dev_addr >>= 1; /* strip RD/WR bit */
|
||||
|
||||
if (!this->start_transaction(dev_addr)) {
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->send_subaddress(dev_addr, sub_addr)) {
|
||||
LOG_F(WARNING, "NO_ACK while sending subaddress, device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "NO_ACK while sending subaddress, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -417,7 +526,7 @@ void ViaCuda::i2c_comb_transaction(
|
||||
or the target device doesn't acknowledge that indicates an error */
|
||||
for (int i = 0; i < in_bytes; i++) {
|
||||
if (!this->send_byte(dev_addr, in_buf[i])) {
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -45,10 +45,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include "adb.h"
|
||||
#include "hwcomponent.h"
|
||||
#include "i2c.h"
|
||||
#include "nvram.h"
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
/** VIA register offsets. */
|
||||
enum {
|
||||
@@ -88,11 +90,23 @@ enum {
|
||||
|
||||
/** Cuda pseudo commands. */
|
||||
enum {
|
||||
CUDA_WARM_START = 0x00, /* warm start */
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
|
||||
CUDA_READ_MCU_MEM = 0x02, /* read internal Cuda memory */
|
||||
CUDA_GET_REAL_TIME = 0x03, /* get real time */
|
||||
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
|
||||
CUDA_WRITE_MCU_MEM = 0x08, /* write internal Cuda memory */
|
||||
CUDA_SET_REAL_TIME = 0x09, /* set real time */
|
||||
CUDA_POWER_DOWN = 0x0A, /* power down system */
|
||||
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, /* mono stable reset */
|
||||
CUDA_RESTART_SYSTEM = 0x11, /* restart system */
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, /* set file server flag */
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, /* set auto-polling rate */
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
|
||||
CUDA_SET_DEVICE_LIST = 0x19, /* set device list */
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, /* get device list */
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, /* one second interrupt mode */
|
||||
CUDA_READ_WRITE_I2C = 0x22, /* read/write I2C device */
|
||||
CUDA_COMB_FMT_I2C = 0x25, /* combined format I2C transaction */
|
||||
CUDA_OUT_PB0 = 0x26, /* output one bit to Cuda's PB0 line */
|
||||
@@ -103,14 +117,23 @@ enum {
|
||||
CUDA_ERR_BAD_PKT = 1, /* invalid packet type */
|
||||
CUDA_ERR_BAD_CMD = 2, /* invalid pseudo command */
|
||||
CUDA_ERR_BAD_SIZE = 3, /* invalid packet size */
|
||||
CUDA_ERR_BAD_PAR = 4, /* invalid parameter */
|
||||
CUDA_ERR_I2C = 5 /* invalid I2C data or no acknowledge */
|
||||
};
|
||||
|
||||
/** PRAM addresses within Cuda's internal memory */
|
||||
#define CUDA_PRAM_START 0x100 // starting address of PRAM
|
||||
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
|
||||
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
|
||||
|
||||
/** Latest Cuda Firmware version. */
|
||||
#define CUDA_FW_VERSION_MAJOR 0x0002
|
||||
#define CUDA_FW_VERSION_MINOR 0x0029
|
||||
|
||||
class ViaCuda : public HWComponent, public I2CBus {
|
||||
public:
|
||||
ViaCuda();
|
||||
~ViaCuda();
|
||||
~ViaCuda() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return (type == HWCompType::ADB_HOST || type == HWCompType::I2C_HOST);
|
||||
@@ -132,14 +155,18 @@ private:
|
||||
int32_t out_count;
|
||||
int32_t out_pos;
|
||||
uint8_t poll_rate;
|
||||
int32_t real_time = 0;
|
||||
bool file_server;
|
||||
uint16_t device_mask = 0;
|
||||
|
||||
bool is_open_ended;
|
||||
uint8_t curr_i2c_addr;
|
||||
bool is_open_ended; // true if current transaction is open-ended
|
||||
uint8_t curr_i2c_addr; // current I2C address
|
||||
uint8_t cur_pram_addr; // current PRAM address, range 0...FF
|
||||
|
||||
void (ViaCuda::*out_handler)(void);
|
||||
void (ViaCuda::*next_out_handler)(void);
|
||||
|
||||
NVram* pram_obj;
|
||||
std::unique_ptr<NVram> pram_obj;
|
||||
ADB_Bus* adb_obj;
|
||||
|
||||
void print_enabled_ints(); /* print enabled VIA interrupts and their sources */
|
||||
@@ -149,13 +176,13 @@ private:
|
||||
void assert_sr_int();
|
||||
void write(uint8_t new_state);
|
||||
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
|
||||
// void cuda_response_packet();
|
||||
void error_response(uint32_t error);
|
||||
void process_packet();
|
||||
void process_adb_command(uint8_t cmd_byte, int data_count);
|
||||
void pseudo_command(int cmd, int data_count);
|
||||
|
||||
void null_out_handler(void);
|
||||
void pram_out_handler(void);
|
||||
void out_buf_handler(void);
|
||||
void i2c_handler(void);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Media Access Controller for Ethernet (MACE) emulation. */
|
||||
|
||||
#include "mace.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Interrupt:
|
||||
LOG_F(INFO, "MACE: all interrupt flags cleared");
|
||||
return 0;
|
||||
default:
|
||||
LOG_F(INFO, "Reading MACE register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
if (value & 1) {
|
||||
LOG_F(INFO, "MACE Reset issued");
|
||||
} else {
|
||||
LOG_F(INFO, "MACE BIU Config set to 0x%X", value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "Writing 0x%X to MACE register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Media Access Controller for Ethernet (MACE) definitions. */
|
||||
|
||||
#ifndef MACE_H
|
||||
#define MACE_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
// MACE Chip ID from AMD datasheet
|
||||
// TODO: compare with real HW
|
||||
#define MACE_ID 0x3940
|
||||
|
||||
// MACE registers offsets
|
||||
// Refer to the Am79C940 datasheet for details
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 0x0A,
|
||||
BIU_Config_Ctrl = 0x0B,
|
||||
FIFO_Config = 0x0C,
|
||||
MAC_Config_Ctrl = 0x0D,
|
||||
PLS_Config_Ctrl = 0x0E,
|
||||
PHY_Config_Ctrl = 0x0F,
|
||||
Chip_ID_Lo = 0x10,
|
||||
Chip_ID_Hi = 0x11,
|
||||
Addr_Config = 0x12,
|
||||
Log_Addr_Flt = 0x14,
|
||||
Phys_Addr = 0x15,
|
||||
Missed_Pkt_Cnt = 0x18,
|
||||
Runt_Pkt_Cnt = 0x1A, // not used in Macintosh?
|
||||
Rcv_Collis_Cnt = 0x1B, // not used in Macintosh?
|
||||
User_Test = 0x1D,
|
||||
Rsrvd_Test_1 = 0x1E, // not used in Macintosh?
|
||||
Rsrvd_Test_2 = 0x1F, // not used in Macintosh?
|
||||
};
|
||||
|
||||
class MaceController {
|
||||
public:
|
||||
MaceController(uint16_t id) { this->chip_id = id; };
|
||||
~MaceController() = default;
|
||||
|
||||
// MACE registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint16_t chip_id; // per-instance MACE Chip ID
|
||||
};
|
||||
|
||||
#endif // MACE_H
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Support for reading and writing of various floppy images. */
|
||||
|
||||
#include "floppyimg.h"
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static FlopImgType identify_image(FILE *img_file)
|
||||
{
|
||||
// WOZ images identification strings
|
||||
static uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
static uint8_t WOZ2_SIG[] = {0x57, 0x4F, 0x5A, 0x32, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
|
||||
uint8_t buf[8] = { 0 };
|
||||
|
||||
fseek(img_file, 0, SEEK_SET);
|
||||
fread(buf, sizeof(buf), 1, img_file);
|
||||
|
||||
// WOZ files are easily identified
|
||||
if (!std::memcmp(buf, WOZ1_SIG, sizeof(buf))) {
|
||||
return FlopImgType::WOZ1;
|
||||
} else if (!std::memcmp(buf, WOZ2_SIG, sizeof(buf))) {
|
||||
return FlopImgType::WOZ2;
|
||||
} else {
|
||||
for (int offset = 0; offset <=84; offset += 84) {
|
||||
// rewind to logical block 2
|
||||
fseek(img_file, 2*BLOCK_SIZE + offset, SEEK_SET);
|
||||
fread(buf, sizeof(buf), 1, img_file);
|
||||
|
||||
// check for HFS/MFS signature at the start of the logical block 2
|
||||
if ((buf[0] == 0x42 && buf[1] == 0x44) ||
|
||||
(buf[0] == 0xD2 && buf[1] == 0xD7)) {
|
||||
if (offset) {
|
||||
return FlopImgType::DC42;
|
||||
} else {
|
||||
return FlopImgType::RAW;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FlopImgType::UNKNOWN;
|
||||
}
|
||||
|
||||
static int64_t get_img_file_size(const char *fname)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
|
||||
memset(&stat_buf, 0, sizeof(stat_buf));
|
||||
|
||||
int res = stat(fname, &stat_buf);
|
||||
return res == 0 ? stat_buf.st_size : -1;
|
||||
}
|
||||
|
||||
static int64_t get_hfs_vol_size(const uint8_t *mdb_data)
|
||||
{
|
||||
uint16_t drNmAlBlks = READ_WORD_BE_A(&mdb_data[18]);
|
||||
uint32_t drAlBlkSiz = READ_DWORD_BE_A(&mdb_data[20]);
|
||||
|
||||
// calculate size of the volume bitmap
|
||||
uint32_t vol_bmp_size = (((drNmAlBlks + 8) >> 3) + 512) & 0xFFFFFE00UL;
|
||||
|
||||
return (drNmAlBlks * drAlBlkSiz + vol_bmp_size + 3*BLOCK_SIZE);
|
||||
}
|
||||
|
||||
//======================= RAW IMAGE CONVERTER ============================
|
||||
RawFloppyImg::RawFloppyImg(const char *file_path) : FloppyImgConverter()
|
||||
{
|
||||
this->img_path = file_path;
|
||||
}
|
||||
|
||||
/** For raw images, we're going to ensure that the data fits into
|
||||
one of the supported floppy disk sizes as well as image size
|
||||
matches the size of the embedded HFS/MFS volume.
|
||||
*/
|
||||
int RawFloppyImg::validate()
|
||||
{
|
||||
FILE *img_file = fopen(this->img_path, "rb");
|
||||
if (img_file == NULL) {
|
||||
LOG_F(ERROR, "RawFloppyImg: Could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// determine image size
|
||||
this->img_size = get_img_file_size(this->img_path);
|
||||
if (this->img_size < 5*BLOCK_SIZE) {
|
||||
LOG_F(ERROR, "RawFloppyImg: image too short!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this->img_size > MFM_HD_SIZE) {
|
||||
LOG_F(ERROR, "RawFloppyImg: image too big!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// read Master Directory Block from logical block 2
|
||||
uint8_t buf[512] = { 0 };
|
||||
|
||||
fseek(img_file, 2*BLOCK_SIZE, SEEK_SET);
|
||||
fread(buf, sizeof(buf), 1, img_file);
|
||||
fclose(img_file);
|
||||
|
||||
uint64_t vol_size = 0;
|
||||
|
||||
if (buf[0] == 0x42 && buf[1] == 0x44) {
|
||||
// check HFS volume size
|
||||
vol_size = get_hfs_vol_size(buf);
|
||||
} else if (buf[0] == 0xD2 && buf[1] == 0xD7) {
|
||||
// check MFS volume size
|
||||
} else {
|
||||
LOG_F(ERROR, "RawFloppyImg: unknown volume type!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vol_size > this->img_size) {
|
||||
LOG_F(INFO, "RawFloppyImg: volume size > image size!");
|
||||
LOG_F(INFO, "Volume size: %llu, Image size: %llu", vol_size, this->img_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Guess physical parameters of the target virtual disk based on image size. */
|
||||
int RawFloppyImg::get_phys_params()
|
||||
{
|
||||
// disk format: GCR vs MFM
|
||||
// single-sided vs double-sided
|
||||
// number of tracks
|
||||
// number of sectors
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Convert high-level image data to low-level disk data. */
|
||||
int RawFloppyImg::import_data()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Convert low-level disk data to high-level image data. */
|
||||
int RawFloppyImg::export_data()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_floppy_image(const char* img_path)
|
||||
{
|
||||
FloppyImgConverter *fconv;
|
||||
|
||||
FILE *img_file = fopen(img_path, "rb");
|
||||
if (img_file == NULL) {
|
||||
LOG_F(ERROR, "Could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FlopImgType itype = identify_image(img_file);
|
||||
|
||||
fclose(img_file);
|
||||
|
||||
switch(itype) {
|
||||
case FlopImgType::RAW:
|
||||
LOG_F(INFO, "Raw floppy image");
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
break;
|
||||
case FlopImgType::DC42:
|
||||
LOG_F(INFO, "Disk Copy 4.2 image");
|
||||
break;
|
||||
case FlopImgType::WOZ1:
|
||||
case FlopImgType::WOZ2:
|
||||
LOG_F(INFO, "WOZ v%s image\n", (itype == FlopImgType::WOZ2) ? "2" : "1");
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unknown/unsupported image format!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fconv->validate()) {
|
||||
LOG_F(ERROR, "Image validation failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Definitions for working with various floppy images. */
|
||||
|
||||
#ifndef FLOPPY_IMG_H
|
||||
#define FLOPPY_IMG_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <stdio.h>
|
||||
|
||||
#define BLOCK_SIZE 512 // size in bytes of a logical block
|
||||
|
||||
#define MFM_HD_SIZE (BLOCK_SIZE*2880) // maximal size of a high-density floppy
|
||||
|
||||
/** Floppy image types. */
|
||||
enum class FlopImgType {
|
||||
RAW, // raw image without metadata or low-level formatting
|
||||
DC42, // Disk Copy 4.2 image
|
||||
WOZ1, // WOZ v1 image with metadata and low-level data retained
|
||||
WOZ2, // WOZ v2 image with metadata and low-level data retained
|
||||
UNKNOWN, // invalid/unknown image format
|
||||
};
|
||||
|
||||
/** Interface for floppy image converters. */
|
||||
class FloppyImgConverter {
|
||||
public:
|
||||
FloppyImgConverter() = default;
|
||||
~FloppyImgConverter() = default;
|
||||
|
||||
virtual int validate(void) = 0;
|
||||
virtual int get_phys_params(void) = 0;
|
||||
virtual int import_data(void) = 0;
|
||||
virtual int export_data(void) = 0;
|
||||
};
|
||||
|
||||
/** Converter for raw floppy images. */
|
||||
class RawFloppyImg : public FloppyImgConverter {
|
||||
public:
|
||||
RawFloppyImg(const char *file_path);
|
||||
~RawFloppyImg() = default;
|
||||
|
||||
int validate(void);
|
||||
int get_phys_params(void);
|
||||
int import_data(void);
|
||||
int export_data(void);
|
||||
|
||||
private:
|
||||
const char *img_path;
|
||||
int64_t img_size;
|
||||
};
|
||||
|
||||
extern int open_floppy_image(const char* img_path);
|
||||
|
||||
#endif // FLOPPY_IMG_H
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Macintosh Superdrive emulation. */
|
||||
|
||||
#include "superdrive.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace MacSuperdrive;
|
||||
|
||||
MacSuperDrive::MacSuperDrive()
|
||||
{
|
||||
this->media_kind = MediaKind::high_density;
|
||||
}
|
||||
|
||||
void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
{
|
||||
LOG_F(9, "Superdrive: command addr=0x%X, value=%d", addr, value);
|
||||
|
||||
switch(addr) {
|
||||
case CommandAddr::Motor_On_Off:
|
||||
if (value) {
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor off");
|
||||
} else {
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor on");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Superdrive: unimplemented command, addr=0x%X", addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
{
|
||||
LOG_F(9, "Superdrive: status request, addr = 0x%X", addr);
|
||||
|
||||
switch(addr) {
|
||||
case StatusAddr::MFM_Support:
|
||||
return 1; // Superdrive does support MFM encoding scheme
|
||||
case StatusAddr::Double_Sided:
|
||||
return 1; // yes, Superdrive is double sided
|
||||
case StatusAddr::Drive_Exists:
|
||||
return 0; // tell the world I'm here
|
||||
case StatusAddr::Media_Kind:
|
||||
return this->media_kind;
|
||||
default:
|
||||
LOG_F(WARNING, "Superdrive: unimplemented status request, addr=0x%X", addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Macintosh Superdrive definitions. */
|
||||
|
||||
#ifndef MAC_SUPERDRIVE_H
|
||||
#define MAC_SUPERDRIVE_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
namespace MacSuperdrive {
|
||||
|
||||
/** Apple Drive status request addresses. */
|
||||
enum StatusAddr : uint8_t {
|
||||
MFM_Support = 5,
|
||||
Double_Sided = 6,
|
||||
Drive_Exists = 7,
|
||||
Media_Kind = 0xF
|
||||
};
|
||||
|
||||
/** Apple Drive command addresses. */
|
||||
enum CommandAddr : uint8_t {
|
||||
Motor_On_Off = 2,
|
||||
};
|
||||
|
||||
/** Type of media currently in the drive. */
|
||||
enum MediaKind : uint8_t {
|
||||
high_density = 0, // 1 or 2 MB disk
|
||||
low_density = 1
|
||||
};
|
||||
|
||||
class MacSuperDrive {
|
||||
public:
|
||||
MacSuperDrive();
|
||||
~MacSuperDrive() = default;
|
||||
|
||||
void command(uint8_t addr, uint8_t value);
|
||||
uint8_t status(uint8_t addr);
|
||||
|
||||
private:
|
||||
uint8_t media_kind;
|
||||
};
|
||||
|
||||
}; // namespace MacSuperdrive
|
||||
|
||||
#endif // MAC_SUPERDRIVE_H
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Sander-Wozniak Machine 3 (SWIM3) emulation. */
|
||||
|
||||
#include "superdrive.h"
|
||||
#include "swim3.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace Swim3;
|
||||
|
||||
Swim3Ctrl::Swim3Ctrl()
|
||||
{
|
||||
this->setup_reg = 0;
|
||||
this->mode_reg = 0;
|
||||
this->int_reg = 0;
|
||||
this->int_mask = 0;
|
||||
this->xfer_cnt = 0;
|
||||
this->first_sec = 0xFF;
|
||||
|
||||
// Attach virtual Superdrive to the internal drive connector
|
||||
// TODO: make SWIM3/drive wiring user selectable
|
||||
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
|
||||
(new MacSuperdrive::MacSuperDrive());
|
||||
}
|
||||
|
||||
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t status_addr;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Phase:
|
||||
return this->phase_lines;
|
||||
case Swim3Reg::Setup:
|
||||
return this->setup_reg;
|
||||
case Swim3Reg::Handshake_Mode1:
|
||||
if (this->mode_reg & 2) { // internal drive?
|
||||
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
|
||||
return ((this->int_drive->status(status_addr) & 1) << 2);
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
default:
|
||||
LOG_F(INFO, "SWIM3: reading from 0x%X register", reg_offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Param_Data:
|
||||
this->pram = value;
|
||||
break;
|
||||
case Swim3Reg::Phase:
|
||||
this->phase_lines = value & 0xF;
|
||||
if (value & 8) {
|
||||
if (this->mode_reg & 2) { // internal drive?
|
||||
this->int_drive->command(
|
||||
((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3),
|
||||
(value >> 2) & 1
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Swim3Reg::Setup:
|
||||
this->setup_reg = value;
|
||||
break;
|
||||
case Swim3Reg::Status_Mode0:
|
||||
// ones in value clear the corresponding bits in the mode register
|
||||
this->mode_reg &= ~value;
|
||||
break;
|
||||
case Swim3Reg::Handshake_Mode1:
|
||||
// ones in value set the corresponding bits in the mode register
|
||||
this->mode_reg |= value;
|
||||
break;
|
||||
case Swim3Reg::Interrupt_Mask:
|
||||
this->int_mask = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "SWIM3: writing 0x%X to register 0x%X", value, reg_offset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Sander-Wozniak Machine 3 (SWIM3) definitions. */
|
||||
|
||||
#ifndef SWIM3_H
|
||||
#define SWIM3_H
|
||||
|
||||
#include "superdrive.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** SWIM3 registers offsets. */
|
||||
namespace Swim3 {
|
||||
|
||||
enum Swim3Reg : uint8_t {
|
||||
Data = 0,
|
||||
Timer = 1,
|
||||
Error = 2,
|
||||
Param_Data = 3,
|
||||
Phase = 4,
|
||||
Setup = 5,
|
||||
Status_Mode0 = 6, // read: Status, write: zeroes to the mode register
|
||||
Handshake_Mode1 = 7, // read: Handshake, write: ones to the mode register
|
||||
Interrupt = 8,
|
||||
Step = 9,
|
||||
Current_Track = 10,
|
||||
Current_Sector = 11,
|
||||
Gap_Format = 12,
|
||||
First_Sector = 13,
|
||||
Sectors_To_Xfer = 14,
|
||||
Interrupt_Mask = 15
|
||||
};
|
||||
|
||||
class Swim3Ctrl {
|
||||
public:
|
||||
Swim3Ctrl();
|
||||
~Swim3Ctrl() = default;
|
||||
|
||||
// SWIM3 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
std::unique_ptr<MacSuperdrive::MacSuperDrive> int_drive;
|
||||
|
||||
uint8_t setup_reg;
|
||||
uint8_t mode_reg;
|
||||
uint8_t phase_lines;
|
||||
uint8_t int_reg;
|
||||
uint8_t int_mask;
|
||||
uint8_t pram; // parameter RAM: two nibbles = {late_time, early_time}
|
||||
uint8_t first_sec;
|
||||
uint8_t xfer_cnt;
|
||||
};
|
||||
|
||||
}; // namespace Swim3
|
||||
|
||||
#endif // SWIM3_H
|
||||
@@ -24,12 +24,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "amic.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "dmacore.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "viacuda.h"
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/scsi/ncr53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/ioctrl/amic.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/pdmonboard.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
@@ -47,11 +53,23 @@ AMIC::AMIC()
|
||||
LOG_F(ERROR, "Couldn't register AMIC registers!");
|
||||
}
|
||||
|
||||
// register I/O devices
|
||||
this->scsi = std::unique_ptr<Ncr53C94> (new Ncr53C94());
|
||||
this->escc = std::unique_ptr<EsccController> (new EsccController());
|
||||
this->mace = std::unique_ptr<MaceController> (new MaceController(MACE_ID));
|
||||
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
|
||||
|
||||
// initialize sound HW
|
||||
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
|
||||
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
|
||||
this->awacs->set_dma_out(this->snd_out_dma.get());
|
||||
|
||||
// initialize on-board video
|
||||
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
this->def_vid = std::unique_ptr<PdmOnboardVideo> (new PdmOnboardVideo());
|
||||
|
||||
// intialize floppy disk HW
|
||||
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
|
||||
}
|
||||
|
||||
bool AMIC::supports_type(HWCompType type) {
|
||||
@@ -66,29 +84,53 @@ uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
uint32_t phase_val;
|
||||
|
||||
if (offset < 0x2000) {
|
||||
// subdevices registers
|
||||
switch(offset >> 12) {
|
||||
case 0: // VIA1 registers
|
||||
case 1:
|
||||
return this->viacuda->read(offset >> 9);
|
||||
case 4: // SCC registers
|
||||
this->escc->read_compat((offset >> 1) & 0xF);
|
||||
return 0;
|
||||
case 0xA: // MACE registers
|
||||
return this->mace->read((offset >> 4) & 0xF);
|
||||
case 0x10: // SCSI registers
|
||||
return this->scsi->read((offset >> 4) & 0xF);
|
||||
case 0x14: // Sound registers
|
||||
switch (offset) {
|
||||
case AMICReg::Snd_Stat_0:
|
||||
case AMICReg::Snd_Stat_1:
|
||||
case AMICReg::Snd_Stat_2:
|
||||
return (this->awacs->read_stat() >> (offset & 3 * 8)) & 0xFF;
|
||||
case AMICReg::Snd_Phase0:
|
||||
case AMICReg::Snd_Phase1:
|
||||
case AMICReg::Snd_Phase2:
|
||||
// the sound phase register is organized as follows:
|
||||
// 000000oo oooooooo oopppppp where 'o' is the 12-bit offset
|
||||
// into the DMA buffer and 'p' is an undocumented prescale value
|
||||
// HWInit doesn't care about. Let's hope it will be sufficient
|
||||
// to return 0 for prescale.
|
||||
phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
|
||||
return (phase_val >> ((2 - (offset & 3)) * 8)) & 0xFF;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
return this->snd_out_ctrl;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
return this->snd_out_dma->read_stat();
|
||||
}
|
||||
case 0x16: // SWIM3 registers
|
||||
case 0x17:
|
||||
return this->swim3->read((offset >> 9) & 0xF);
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::Snd_Stat_0:
|
||||
case AMICReg::Snd_Stat_1:
|
||||
case AMICReg::Snd_Stat_2:
|
||||
return (this->awacs->read_stat() >> (offset & 3 * 8)) & 0xFF;
|
||||
case AMICReg::Snd_Phase0:
|
||||
case AMICReg::Snd_Phase1:
|
||||
case AMICReg::Snd_Phase2:
|
||||
// the sound phase register is organized as follows:
|
||||
// 000000oo oooooooo oopppppp where 'o' is the 12-bit offset
|
||||
// into the DMA buffer and 'p' is an undocumented prescale value
|
||||
// HWInit doesn't care about. Let's hope it will be sufficient
|
||||
// to return 0 for prescale.
|
||||
phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
|
||||
return (phase_val >> ((2 - (offset & 3)) * 8)) & 0xFF;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
return this->snd_out_ctrl;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
return this->snd_out_dma->read_stat();
|
||||
case AMICReg::Video_Mode:
|
||||
return this->def_vid->get_video_mode();
|
||||
case AMICReg::Monitor_Id:
|
||||
return this->mon_id;
|
||||
case AMICReg::Diag_Reg:
|
||||
return 0xFFU; // this value allows the machine to boot normally
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
return this->scsi_dma_cs;
|
||||
default:
|
||||
LOG_F(WARNING, "Unknown AMIC register read, offset=%x", offset);
|
||||
}
|
||||
@@ -99,64 +141,109 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
uint32_t mask;
|
||||
|
||||
if (offset < 0x2000) {
|
||||
// subdevices registers
|
||||
switch(offset >> 12) {
|
||||
case 0: // VIA1 registers
|
||||
case 1:
|
||||
this->viacuda->write(offset >> 9, value);
|
||||
return;
|
||||
case 4:
|
||||
this->escc->write_compat((offset >> 1) & 0xF, value);
|
||||
return;
|
||||
case 0xA: // MACE registers
|
||||
this->mace->write((offset >> 4) & 0xF, value);
|
||||
return;
|
||||
case 0x10:
|
||||
this->scsi->write((offset >> 4) & 0xF, value);
|
||||
return;
|
||||
case 0x14: // Sound registers
|
||||
switch(offset) {
|
||||
case AMICReg::Snd_Ctrl_0:
|
||||
case AMICReg::Snd_Ctrl_1:
|
||||
case AMICReg::Snd_Ctrl_2:
|
||||
// remember values of sound control registers
|
||||
this->imm_snd_regs[offset & 3] = value;
|
||||
// transfer control information to the sound codec when ready
|
||||
if ((this->imm_snd_regs[0] & 0xC0) == PDM_SND_CTRL_VALID) {
|
||||
this->awacs->write_ctrl(
|
||||
(this->imm_snd_regs[1] >> 4) | (this->imm_snd_regs[0] & 0x3F),
|
||||
((this->imm_snd_regs[1] & 0xF) << 8) | this->imm_snd_regs[2]
|
||||
);
|
||||
}
|
||||
return;
|
||||
case AMICReg::Snd_Buf_Size_Hi:
|
||||
case AMICReg::Snd_Buf_Size_Lo:
|
||||
mask = 0xFF00U >> (8 * (offset & 1));
|
||||
this->snd_buf_size = (this->snd_buf_size & ~mask) |
|
||||
((value & 0xFF) << (8 * ((offset & 1) ^1)));
|
||||
this->snd_buf_size &= ~3; // sound buffer size is always a multiple of 4
|
||||
LOG_F(9, "AMIC: Sound buffer size set to 0x%X", this->snd_buf_size);
|
||||
return;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
|
||||
if ((value & 1) != (this->snd_out_ctrl & 1)) {
|
||||
if (value & 1) {
|
||||
LOG_F(9, "AMIC Sound Out DMA enabled!");
|
||||
this->snd_out_dma->init(this->dma_base & ~0x3FFFF,
|
||||
this->snd_buf_size);
|
||||
this->snd_out_dma->enable();
|
||||
this->awacs->set_sample_rate((this->snd_out_ctrl >> 1) & 3);
|
||||
this->awacs->start_output_dma();
|
||||
} else {
|
||||
LOG_F(9, "AMIC Sound Out DMA disabled!");
|
||||
this->snd_out_dma->disable();
|
||||
}
|
||||
}
|
||||
this->snd_out_ctrl = value;
|
||||
return;
|
||||
case AMICReg::Snd_In_Ctrl:
|
||||
LOG_F(INFO, "AMIC Sound In Ctrl updated, val=%x", value);
|
||||
return;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
this->snd_out_dma->write_dma_out_ctrl(value);
|
||||
return;
|
||||
}
|
||||
case 0x16: // SWIM3 registers
|
||||
case 0x17:
|
||||
this->swim3->write((offset >> 9) & 0xF, value);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::Snd_Ctrl_0:
|
||||
case AMICReg::Snd_Ctrl_1:
|
||||
case AMICReg::Snd_Ctrl_2:
|
||||
// remember values of sound control registers
|
||||
this->imm_snd_regs[offset & 3] = value;
|
||||
// transfer control information to the sound codec when ready
|
||||
if ((this->imm_snd_regs[0] & 0xC0) == PDM_SND_CTRL_VALID) {
|
||||
this->awacs->write_ctrl(
|
||||
(this->imm_snd_regs[1] >> 4) | (this->imm_snd_regs[0] & 0x3F),
|
||||
((this->imm_snd_regs[1] & 0xF) << 8) | this->imm_snd_regs[2]
|
||||
);
|
||||
}
|
||||
break;
|
||||
case AMICReg::Snd_Buf_Size_Hi:
|
||||
case AMICReg::Snd_Buf_Size_Lo:
|
||||
mask = 0xFF00U >> (8 * (offset & 1));
|
||||
this->snd_buf_size = (this->snd_buf_size & ~mask) |
|
||||
((value & 0xFF) << (8 * ((offset & 1) ^1)));
|
||||
this->snd_buf_size &= ~3; // sound buffer size is always a multiple of 4
|
||||
LOG_F(9, "AMIC: Sound buffer size set to 0x%X", this->snd_buf_size);
|
||||
break;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
|
||||
if ((value & 1) != (this->snd_out_ctrl & 1)) {
|
||||
if (value & 1) {
|
||||
LOG_F(9, "AMIC Sound Out DMA enabled!");
|
||||
this->snd_out_dma->init(this->dma_base & ~0x3FFFF,
|
||||
this->snd_buf_size);
|
||||
this->snd_out_dma->enable();
|
||||
this->awacs->set_sample_rate((this->snd_out_ctrl >> 1) & 3);
|
||||
this->awacs->start_output_dma();
|
||||
} else {
|
||||
LOG_F(9, "AMIC Sound Out DMA disabled!");
|
||||
this->snd_out_dma->disable();
|
||||
}
|
||||
}
|
||||
this->snd_out_ctrl = value;
|
||||
break;
|
||||
case AMICReg::Snd_In_Ctrl:
|
||||
LOG_F(INFO, "AMIC Sound In Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
this->snd_out_dma->write_dma_out_ctrl(value);
|
||||
break;
|
||||
case AMICReg::VIA2_Slot_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Slot Interrupt Enable Register updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::VIA2_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Interrupt Enable Register updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::Video_Mode_Reg:
|
||||
LOG_F(INFO, "AMIC Video Mode Register set to %x", value);
|
||||
case AMICReg::Ariel_Clut_Index:
|
||||
this->def_vid->set_clut_index(value);
|
||||
break;
|
||||
case AMICReg::Ariel_Clut_Color:
|
||||
this->def_vid->set_clut_color(value);
|
||||
break;
|
||||
case AMICReg::Ariel_Config:
|
||||
this->def_vid->vdac_config(value);
|
||||
break;
|
||||
case AMICReg::Video_Mode:
|
||||
this->def_vid->set_video_mode(value);
|
||||
break;
|
||||
case AMICReg::Pixel_Depth:
|
||||
this->def_vid->set_pixel_depth(value);
|
||||
break;
|
||||
case AMICReg::Monitor_Id: {
|
||||
// extract and convert pin directions (0 - input, 1 - output)
|
||||
uint8_t dirs = ~value & 7;
|
||||
if (!dirs && !(value & 8)) {
|
||||
LOG_F(INFO, "AMIC: Monitor sense lines tristated");
|
||||
}
|
||||
// propagate bit 3 to all pins configured as output
|
||||
// set levels of all intput pins to "1"
|
||||
uint8_t levels = (7 ^ dirs) | (((value & 8) ? 7 : 0) & dirs);
|
||||
// read monitor sense lines and store the result in the bits 4-6
|
||||
this->mon_id = (this->mon_id & 0xF) |
|
||||
(this->disp_id->read_monitor_sense(levels, dirs) << 4);
|
||||
}
|
||||
break;
|
||||
case AMICReg::Int_Ctrl:
|
||||
LOG_F(INFO, "AMIC Interrupt Control Register set to %X", value);
|
||||
@@ -175,6 +262,7 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
break;
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCSI DMA Ctrl updated, val=%x", value);
|
||||
this->scsi_dma_cs = value;
|
||||
break;
|
||||
case AMICReg::Enet_DMA_Rcv_Ctrl:
|
||||
LOG_F(INFO, "AMIC Ethernet Receive DMA Ctrl updated, val=%x", value);
|
||||
@@ -24,10 +24,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef AMIC_H
|
||||
#define AMIC_H
|
||||
|
||||
#include "awacs.h"
|
||||
#include "dmacore.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "viacuda.h"
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/scsi/ncr53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/pdmonboard.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
@@ -94,11 +100,21 @@ enum AMICReg : uint32_t {
|
||||
VIA2_Slot_IER = 0x26012,
|
||||
VIA2_IER = 0x26013,
|
||||
|
||||
// Video DAC (Ariel II) control registers
|
||||
Ariel_Clut_Index = 0x24000,
|
||||
Ariel_Clut_Color = 0x24001,
|
||||
Ariel_Config = 0x24002,
|
||||
|
||||
// Video control registers
|
||||
Video_Mode_Reg = 0x28000,
|
||||
Video_Mode = 0x28000,
|
||||
Pixel_Depth = 0x28001,
|
||||
Monitor_Id = 0x28002,
|
||||
|
||||
Int_Ctrl = 0x2A000,
|
||||
|
||||
// Undocumented diagnostics register
|
||||
Diag_Reg = 0x2C000,
|
||||
|
||||
// DMA control registers
|
||||
DMA_Base_Addr_0 = 0x31000,
|
||||
DMA_Base_Addr_1 = 0x31001,
|
||||
@@ -136,10 +152,23 @@ private:
|
||||
uint16_t snd_buf_size = 0; // sound buffer size in bytes
|
||||
uint8_t snd_out_ctrl = 0;
|
||||
|
||||
uint8_t scsi_dma_cs = 0; // SCSI DMA control/status register value
|
||||
|
||||
// AMIC subdevices instances
|
||||
std::unique_ptr<Ncr53C94> scsi;
|
||||
std::unique_ptr<EsccController> escc;
|
||||
std::unique_ptr<MaceController> mace;
|
||||
std::unique_ptr<ViaCuda> viacuda;
|
||||
std::unique_ptr<AwacDevicePdm> awacs;
|
||||
|
||||
std::unique_ptr<AmicSndOutDma> snd_out_dma;
|
||||
|
||||
// on-board video
|
||||
std::unique_ptr<DisplayID> disp_id;
|
||||
std::unique_ptr<PdmOnboardVideo> def_vid;
|
||||
uint8_t mon_id;
|
||||
|
||||
std::unique_ptr<Swim3::Swim3Ctrl> swim3;
|
||||
};
|
||||
|
||||
#endif // AMIC_H
|
||||
@@ -19,16 +19,21 @@ 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 "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "macio.h"
|
||||
#include "viacuda.h"
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <memory>
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
@@ -38,35 +43,25 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
||||
this->nvram = new NVram();
|
||||
this->nvram = std::unique_ptr<NVram> (new NVram());
|
||||
|
||||
this->viacuda = new ViaCuda();
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
|
||||
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
|
||||
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
this->screamer = new AwacsScreamer();
|
||||
this->snd_out_dma = new DMAChannel();
|
||||
this->screamer->set_dma_out(this->snd_out_dma);
|
||||
this->screamer = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
|
||||
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->screamer->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_start, this->screamer),
|
||||
std::bind(&AwacsScreamer::dma_end, this->screamer)
|
||||
std::bind(&AwacsScreamer::dma_start, this->screamer.get()),
|
||||
std::bind(&AwacsScreamer::dma_end, this->screamer.get())
|
||||
);
|
||||
|
||||
this->mesh = new MESHController(HeathrowMESHID);
|
||||
this->mesh = std::unique_ptr<MESHController> (new MESHController(HeathrowMESHID));
|
||||
this->escc = std::unique_ptr<EsccController> (new EsccController());
|
||||
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
|
||||
}
|
||||
|
||||
HeathrowIC::~HeathrowIC() {
|
||||
if (this->nvram)
|
||||
delete (this->nvram);
|
||||
|
||||
if (this->viacuda)
|
||||
delete (this->viacuda);
|
||||
|
||||
if (this->mesh)
|
||||
delete (this->mesh);
|
||||
}
|
||||
|
||||
|
||||
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
return this->pci_cfg_hdr[reg_offs & 0xFF];
|
||||
}
|
||||
@@ -136,9 +131,15 @@ uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
case 0x10:
|
||||
res = this->mesh->read((offset >> 4) & 0xF);
|
||||
break;
|
||||
case 0x12: // ESCC compatible
|
||||
return this->escc->read_compat((offset >> 4) & 0xF);
|
||||
case 0x13: // ESCC MacRISC
|
||||
return this->escc->read((offset >> 4) & 0xF);
|
||||
case 0x14:
|
||||
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
||||
break;
|
||||
case 0x15: // SWIM3
|
||||
return this->swim3->read(offset & 0xF);
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
res = this->viacuda->read((offset - 0x16000) >> 9);
|
||||
@@ -169,9 +170,18 @@ void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int
|
||||
case 0x10:
|
||||
this->mesh->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x12: // ESCC compatible
|
||||
this->escc->write_compat((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x13: // ESCC MacRISC
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
break;
|
||||
case 0x15:
|
||||
this->swim3->write(offset & 0xF, value);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
this->viacuda->write((offset - 0x16000) >> 9, value);
|
||||
@@ -219,7 +229,7 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
||||
res = this->feat_ctrl;
|
||||
res = BYTESWAP_32(this->feat_ctrl);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x \n", offset);
|
||||
@@ -259,8 +269,7 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x \n", value, offset, ppc_state.pc);
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
this->feat_ctrl = value;
|
||||
this->feature_control(BYTESWAP_32(value));
|
||||
break;
|
||||
case 0x3C:
|
||||
LOG_F(9, "write %x to MIO:Aux_Ctrl register \n", value);
|
||||
@@ -271,3 +280,16 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::feature_control(const uint32_t value)
|
||||
{
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
|
||||
this->feat_ctrl = value;
|
||||
|
||||
if (!(this->feat_ctrl & 1)) {
|
||||
LOG_F(9, "Heathrow: Monitor sense enabled");
|
||||
} else {
|
||||
LOG_F(9, "Heathrow: Monitor sense disabled");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -51,17 +51,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACIO_H
|
||||
#define MACIO_H
|
||||
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mesh.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "nvram.h"
|
||||
#include "pcidevice.h"
|
||||
#include "pcihost.h"
|
||||
#include "viacuda.h"
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
Heathrow ASIC emulation
|
||||
@@ -76,7 +80,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
----------------------------------------------------------------
|
||||
mesh(SCSI) register space: 0x00010000, DMA space: 0x00008000
|
||||
bmac(ethernet) register space: 0x00011000, DMA space: 0x00008200, 0x00008300
|
||||
escc(serial) register space: 0x00013000, size: 0x00001000
|
||||
escc(compat) register space: 0x00012000, size: 0x00001000
|
||||
DMA space: 0x00008400, size: 0x00000400
|
||||
escc(MacRISC) register space: 0x00013000, size: 0x00001000
|
||||
DMA space: 0x00008400, size: 0x00000400
|
||||
escc:ch-a register space: 0x00013020, DMA space: 0x00008400, 0x00008500
|
||||
escc:ch-b register space: 0x00013000, DMA space: 0x00008600, 0x00008700
|
||||
@@ -90,7 +96,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class HeathrowIC : public PCIDevice {
|
||||
public:
|
||||
HeathrowIC();
|
||||
~HeathrowIC();
|
||||
~HeathrowIC() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::MMIO_DEV;
|
||||
@@ -115,6 +121,8 @@ protected:
|
||||
uint32_t mio_ctrl_read(uint32_t offset, int size);
|
||||
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void feature_control(const uint32_t value);
|
||||
|
||||
private:
|
||||
uint8_t pci_cfg_hdr[256] = {
|
||||
0x6B,
|
||||
@@ -147,12 +155,14 @@ private:
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
|
||||
/* device cells */
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
NVram* nvram; // NVRAM cell
|
||||
AwacsScreamer *screamer; // Screamer audio codec instance
|
||||
MESHController *mesh; // MESH SCSI cell instance
|
||||
std::unique_ptr<ViaCuda> viacuda; // VIA cell with Cuda MCU attached to it
|
||||
std::unique_ptr<NVram> nvram; // NVRAM cell
|
||||
std::unique_ptr<AwacsScreamer> screamer; // Screamer audio codec instance
|
||||
std::unique_ptr<MESHController> mesh; // MESH SCSI cell instance
|
||||
std::unique_ptr<EsccController> escc; // ESCC serial controller
|
||||
std::unique_ptr<Swim3::Swim3Ctrl> swim3; // floppy disk controller
|
||||
|
||||
DMAChannel* snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
#endif /* MACIO_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,7 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "hmc.h"
|
||||
#include <devices/memctrl/hmc.h>
|
||||
|
||||
HMC::HMC() : MemCtrlBase()
|
||||
{
|
||||
@@ -33,7 +33,7 @@ HMC::HMC() : MemCtrlBase()
|
||||
/* add memory mapped I/O region for the HMC control register */
|
||||
add_mmio_region(0x50F40000, 0x10000, this);
|
||||
|
||||
this->config_reg = 0ULL;
|
||||
this->ctrl_reg = 0ULL;
|
||||
this->bit_pos = 0;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ bool HMC::supports_type(HWCompType type) {
|
||||
uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
if (!offset)
|
||||
return !!(this->config_reg & (1ULL << this->bit_pos++));
|
||||
return !!(this->ctrl_reg & (1ULL << this->bit_pos++));
|
||||
else
|
||||
return 0; /* FIXME: what should be returned for invalid offsets? */
|
||||
}
|
||||
@@ -60,8 +60,8 @@ void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
switch(offset) {
|
||||
case 0:
|
||||
bit = 1ULL << this->bit_pos++;
|
||||
this->config_reg = (value & 1) ? this->config_reg | bit :
|
||||
this->config_reg & ~bit;
|
||||
this->ctrl_reg = (value & 1) ? this->ctrl_reg | bit :
|
||||
this->ctrl_reg & ~bit;
|
||||
break;
|
||||
case 8: /* writing to HMCBase + 8 resets internal bit position */
|
||||
this->bit_pos = 0;
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,11 +31,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef HMC_H
|
||||
#define HMC_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/** Bit in the HMC control register telling us where the frame bufffer
|
||||
for the on-board video is located. */
|
||||
#define HMC_VBASE_BIT 33
|
||||
|
||||
class HMC : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
HMC();
|
||||
@@ -47,9 +52,13 @@ public:
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
uint64_t get_control_reg(void) {
|
||||
return this->ctrl_reg;
|
||||
};
|
||||
|
||||
private:
|
||||
int bit_pos;
|
||||
uint64_t config_reg;
|
||||
uint64_t ctrl_reg;
|
||||
};
|
||||
|
||||
#endif // HMC_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,13 +19,13 @@ 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/memctrl/memctrlbase.h>
|
||||
|
||||
#include <algorithm> // to shut up MSVC errors (:
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "memctrlbase.h"
|
||||
|
||||
|
||||
MemCtrlBase::~MemCtrlBase() {
|
||||
for (auto& entry : address_map) {
|
||||
@@ -48,7 +48,7 @@ AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
||||
return entry;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,3 +146,14 @@ bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_rom_region()
|
||||
{
|
||||
for (auto& entry : address_map) {
|
||||
if (entry->type == RT_ROM) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,7 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MEMORY_CONTROLLER_BASE_H
|
||||
#define MEMORY_CONTROLLER_BASE_H
|
||||
|
||||
#include "mmiodevice.h"
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
||||
|
||||
AddressMapEntry* find_range(uint32_t addr);
|
||||
AddressMapEntry* find_rom_region();
|
||||
|
||||
protected:
|
||||
bool add_mem_region(
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,17 +24,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "memaccess.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "mpc106.h"
|
||||
|
||||
|
||||
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle PCI host bridge") {
|
||||
this->name = "Grackle";
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -35,11 +35,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MPC106_H_
|
||||
#define MPC106_H_
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "pcidevice.h"
|
||||
#include "pcihost.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,12 +47,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SPD_EEPROM_H
|
||||
#define SPD_EEPROM_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "i2c.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
enum RAMType : int { SDRAM = 4 };
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef PCI_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance) = 0;
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj) = 0;
|
||||
};
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Enhanced Serial Communications Controller (ESCC) emulation. */
|
||||
|
||||
#include "escc.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
EsccController::EsccController()
|
||||
{
|
||||
this->ch_a = std::unique_ptr<EsccChannel> (new EsccChannel("A"));
|
||||
this->ch_b = std::unique_ptr<EsccChannel> (new EsccChannel("B"));
|
||||
|
||||
this->reg_ptr = 0;
|
||||
}
|
||||
|
||||
uint8_t EsccController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case EsccReg::Port_B_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case EsccReg::Port_A_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: reading register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EsccController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case EsccReg::Port_B_Cmd:
|
||||
this->write_internal(this->ch_b.get(), value);
|
||||
break;
|
||||
case EsccReg::Port_A_Cmd:
|
||||
this->write_internal(this->ch_a.get(), value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: writing 0x%X to register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t EsccController::read_compat(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case Compat::EsccReg::Port_B_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case Compat::EsccReg::Port_A_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: reading register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EsccController::write_compat(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case Compat::EsccReg::Port_B_Cmd:
|
||||
this->write_internal(this->ch_b.get(), value);
|
||||
break;
|
||||
case Compat::EsccReg::Port_A_Cmd:
|
||||
this->write_internal(this->ch_a.get(), value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: writing 0x%X to register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void EsccController::write_internal(EsccChannel *ch, uint8_t value)
|
||||
{
|
||||
if (this->reg_ptr) {
|
||||
ch->write_reg(this->reg_ptr, value);
|
||||
this->reg_ptr = 0;
|
||||
} else {
|
||||
this->reg_ptr = value & 7;
|
||||
switch(value >> 3) {
|
||||
case WR0Cmd::Point_High:
|
||||
this->reg_ptr |= 8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
{
|
||||
this->write_regs[reg_num] = value;
|
||||
LOG_F(9, "ESCC: writing 0x%X to Channel %s WR%d", value, this->name.c_str(),
|
||||
reg_num);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Enhanced Serial Communications Controller (ESCC) definitions. */
|
||||
|
||||
#ifndef ESCC_H
|
||||
#define ESCC_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** ESCC compatible (aka Macintosh legacy) register addressing */
|
||||
namespace Compat {
|
||||
enum EsccReg : uint8_t {
|
||||
Port_B_Cmd = 0,
|
||||
Port_A_Cmd = 1,
|
||||
Port_B_Data = 2,
|
||||
Port_A_Data = 3,
|
||||
Enh_Reg_B = 4,
|
||||
Enh_Reg_A = 5,
|
||||
};
|
||||
};
|
||||
|
||||
/** ESCC MacRISC style register addressing */
|
||||
enum EsccReg : uint8_t {
|
||||
Port_B_Cmd = 0,
|
||||
Port_B_Data = 1,
|
||||
Port_A_Cmd = 2,
|
||||
Port_A_Data = 3,
|
||||
Enh_Reg_B = 4,
|
||||
Enh_Reg_A = 5,
|
||||
};
|
||||
|
||||
/** LocalTalk registers (same in both addressing schemes) */
|
||||
enum LocalTalkReg : uint8_t {
|
||||
Rec_Count = 8,
|
||||
Start_A = 9,
|
||||
Start_B = 0xA,
|
||||
Detect_AB = 0xB,
|
||||
};
|
||||
|
||||
enum WR0Cmd : uint8_t {
|
||||
Point_High = 1,
|
||||
};
|
||||
|
||||
/** ESCC Channel class. */
|
||||
class EsccChannel {
|
||||
public:
|
||||
EsccChannel(std::string name) { this->name = name; };
|
||||
~EsccChannel() = default;
|
||||
|
||||
void write_reg(int reg_num, uint8_t value);
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
uint8_t write_regs[16];
|
||||
};
|
||||
|
||||
/** ESCC Controller class. */
|
||||
class EsccController {
|
||||
public:
|
||||
EsccController();
|
||||
~EsccController() = default;
|
||||
|
||||
// ESCC MacRISC registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
// ESCC compatible registers access
|
||||
uint8_t read_compat(uint8_t reg_offset);
|
||||
void write_compat(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
void write_internal(EsccChannel* ch, uint8_t value);
|
||||
|
||||
std::unique_ptr<EsccChannel> ch_a;
|
||||
std::unique_ptr<EsccChannel> ch_b;
|
||||
|
||||
int reg_ptr; // register pointer for reading/writing (same for both channels)
|
||||
};
|
||||
|
||||
#endif // ESCC_H
|
||||
@@ -28,11 +28,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski 2019-21
|
||||
*/
|
||||
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "endianswap.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "soundserver.h"
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <endianswap.h>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <loguru.hpp>
|
||||
#include <memory>
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -28,10 +28,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef AWAC_H
|
||||
#define AWAC_H
|
||||
|
||||
#include "dmacore.h"
|
||||
#include "dbdma.h"
|
||||
#include "i2c.h"
|
||||
#include "soundserver.h"
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
@@ -148,7 +149,7 @@ private:
|
||||
class AwacsScreamer : public AwacsBase {
|
||||
public:
|
||||
AwacsScreamer();
|
||||
~AwacsScreamer();
|
||||
~AwacsScreamer() = default;
|
||||
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,9 +19,10 @@ 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 "dmacore.h"
|
||||
#include "endianswap.h"
|
||||
#include "soundserver.h"
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <loguru.hpp>
|
||||
#include <cubeb/cubeb.h>
|
||||
#ifdef _WIN32
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -34,8 +34,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SOUND_SERVER_H
|
||||
#define SOUND_SERVER_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include <cubeb/cubeb.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
enum {
|
||||
SND_SERVER_DOWN = 0,
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,15 +19,17 @@ 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 "displayid.h"
|
||||
#include "endianswap.h"
|
||||
#include "memaccess.h"
|
||||
#include "pcidevice.h"
|
||||
#include <atirage.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/video/atirage.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <loguru.hpp>
|
||||
#include <memory>
|
||||
|
||||
/* Mach64 post dividers. */
|
||||
static const int mach64_post_div[8] = {
|
||||
@@ -85,13 +87,15 @@ static const std::map<uint16_t, std::string> mach64_reg_names = {
|
||||
};
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id, uint32_t mem_amount) : PCIDevice("ati-rage") {
|
||||
ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
|
||||
: PCIDevice("ati-rage"), VideoCtrlBase()
|
||||
{
|
||||
uint8_t asic_id;
|
||||
|
||||
this->vram_size = mem_amount << 20;
|
||||
this->vram_size = vmem_size_mb << 20; // convert MBs to bytes
|
||||
|
||||
/* allocate video RAM */
|
||||
this->vram_ptr = new uint8_t[this->vram_size];
|
||||
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
|
||||
|
||||
/* ATI Rage driver needs to know ASIC ID (manufacturer's internal chip code)
|
||||
to operate properly */
|
||||
@@ -113,24 +117,11 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t mem_amount) : PCIDevice("ati-rage") {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[0x3C], 0x00080100);
|
||||
|
||||
/* stuff default values into chip registers */
|
||||
WRITE_DWORD_LE_A(&this->block_io_regs[ATI_CONFIG_CHIP_ID],
|
||||
WRITE_DWORD_LE_A(&this->mm_regs[ATI_CONFIG_CHIP_ID],
|
||||
(asic_id << 24) | dev_id);
|
||||
|
||||
/* initialize display identification */
|
||||
this->disp_id = new DisplayID();
|
||||
|
||||
//this->surface = new uint8_t[640 * 480];
|
||||
}
|
||||
|
||||
ATIRage::~ATIRage()
|
||||
{
|
||||
//delete (this->surface);
|
||||
|
||||
if (this->vram_ptr) {
|
||||
delete this->vram_ptr;
|
||||
}
|
||||
|
||||
delete (this->disp_id);
|
||||
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
}
|
||||
|
||||
const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
||||
@@ -145,24 +136,25 @@ const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
||||
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
uint32_t res;
|
||||
|
||||
// perform register-specific pre-read action
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
/* reading from internal PLL registers */
|
||||
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
|
||||
!(this->block_io_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
return this->plls[this->block_io_regs[ATI_CLOCK_CNTL+1] >> 2];
|
||||
!(this->mm_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
return this->plls[this->mm_regs[ATI_CLOCK_CNTL+1] >> 2];
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
if (offset == ATI_DAC_DATA) {
|
||||
this->block_io_regs[ATI_DAC_DATA] =
|
||||
this->palette[this->block_io_regs[ATI_DAC_R_INDEX]][this->comp_index];
|
||||
this->mm_regs[ATI_DAC_DATA] =
|
||||
this->palette[this->mm_regs[ATI_DAC_R_INDEX]][this->comp_index];
|
||||
this->comp_index++; /* move to next color component */
|
||||
if (this->comp_index >= 3) {
|
||||
/* autoincrement reading index - move to next palette entry */
|
||||
(this->block_io_regs[ATI_DAC_R_INDEX])++;
|
||||
(this->mm_regs[ATI_DAC_R_INDEX])++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
}
|
||||
@@ -174,63 +166,66 @@ uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
get_reg_name(offset),
|
||||
offset,
|
||||
size,
|
||||
read_mem(&this->block_io_regs[offset], size));
|
||||
read_mem(&this->mm_regs[offset], size));
|
||||
}
|
||||
|
||||
res = read_mem(&this->block_io_regs[offset], size);
|
||||
// reading internal registers with necessary endian conversion
|
||||
res = read_mem(&this->mm_regs[offset], size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
uint32_t gpio_val;
|
||||
uint16_t gpio_dir;
|
||||
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint8_t gpio_levels, gpio_dirs;
|
||||
|
||||
/* size-dependent endian conversion */
|
||||
write_mem(&this->block_io_regs[offset], value, size);
|
||||
// writing internal registers with necessary endian conversion
|
||||
write_mem(&this->mm_regs[offset], value, size);
|
||||
|
||||
// perform register-specific post-write action
|
||||
switch (offset & ~3) {
|
||||
case ATI_CRTC_OFF_PITCH:
|
||||
LOG_F(INFO, "ATI Rage: CRTC_OFF_PITCH=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH]));
|
||||
LOG_F(INFO, "ATI Rage: CRTC_OFF_PITCH=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]));
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
if (this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2) {
|
||||
if (this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2) {
|
||||
this->crtc_enable();
|
||||
} else {
|
||||
this->crtc_on = false;
|
||||
}
|
||||
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_ENABLE=%d", !!(this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2));
|
||||
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_DISPLAY_DIS=%d", !!(this->block_io_regs[ATI_CRTC_GEN_CNTL] & 0x40));
|
||||
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_ENABLE=%d", !!(this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2));
|
||||
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_DISPLAY_DIS=%d", !!(this->mm_regs[ATI_CRTC_GEN_CNTL] & 0x40));
|
||||
break;
|
||||
case ATI_CUR_OFFSET:
|
||||
LOG_F(INFO, "ATI Rage: CUR_OFFSET=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET]));
|
||||
LOG_F(INFO, "ATI Rage: CUR_OFFSET=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_OFFSET]));
|
||||
break;
|
||||
case ATI_CUR_HORZ_VERT_POSN:
|
||||
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_POSN=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_POSN]));
|
||||
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_POSN=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_POSN]));
|
||||
break;
|
||||
case ATI_CUR_HORZ_VERT_OFF:
|
||||
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_OFF=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]));
|
||||
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_OFF=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_OFF]));
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
if (offset < (ATI_GP_IO + 2)) {
|
||||
gpio_val = READ_DWORD_LE_A(&this->block_io_regs[ATI_GP_IO]);
|
||||
gpio_dir = (gpio_val >> 16) & 0x3FFF;
|
||||
WRITE_WORD_LE_A(
|
||||
&this->block_io_regs[ATI_GP_IO],
|
||||
this->disp_id->read_monitor_sense(gpio_val, gpio_dir));
|
||||
gpio_levels = this->mm_regs[ATI_GP_IO+1];
|
||||
gpio_levels = ((gpio_levels & 0x30) >> 3) | (gpio_levels & 1);
|
||||
gpio_dirs = this->mm_regs[ATI_GP_IO+3];
|
||||
gpio_dirs = ((gpio_dirs & 0x30) >> 3) | (gpio_dirs & 1);
|
||||
gpio_levels = this->disp_id->read_monitor_sense(gpio_levels, gpio_dirs);
|
||||
this->mm_regs[ATI_GP_IO+1] = ((gpio_levels & 6) << 3) | (gpio_levels & 1);
|
||||
}
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
/* writing to internal PLL registers */
|
||||
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
|
||||
(this->block_io_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
int pll_addr = this->block_io_regs[ATI_CLOCK_CNTL+1] >> 2;
|
||||
uint8_t pll_data = this->block_io_regs[ATI_CLOCK_CNTL+2];
|
||||
(this->mm_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
int pll_addr = this->mm_regs[ATI_CLOCK_CNTL+1] >> 2;
|
||||
uint8_t pll_data = this->mm_regs[ATI_CLOCK_CNTL+2];
|
||||
this->plls[pll_addr] = pll_data;
|
||||
LOG_F(INFO, "ATI Rage: PLL #%d set to 0x%02X", pll_addr, pll_data);
|
||||
} else if (offset == ATI_CLOCK_CNTL && size == 1) {
|
||||
LOG_F(INFO, "ATI Rage: CLOCK_SEL = 0x%02X",
|
||||
this->block_io_regs[ATI_CLOCK_CNTL] & 3);
|
||||
this->mm_regs[ATI_CLOCK_CNTL] & 3);
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
@@ -241,24 +236,24 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
this->comp_index = 0;
|
||||
break;
|
||||
case ATI_DAC_DATA:
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF;
|
||||
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF;
|
||||
this->comp_index++; /* move to next color component */
|
||||
if (this->comp_index >= 3) {
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI DAC palette entry #%d set to R=%X, G=%X, B=%X",
|
||||
this->block_io_regs[ATI_DAC_W_INDEX],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][0],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][1],
|
||||
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][2]);
|
||||
this->mm_regs[ATI_DAC_W_INDEX],
|
||||
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][0],
|
||||
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][1],
|
||||
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][2]);
|
||||
/* autoincrement writing index - move to next palette entry */
|
||||
(this->block_io_regs[ATI_DAC_W_INDEX])++;
|
||||
(this->mm_regs[ATI_DAC_W_INDEX])++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATI_GEN_TEST_CNTL:
|
||||
LOG_F(INFO, "HW cursor: %s", this->block_io_regs[ATI_GEN_TEST_CNTL] & 0x80 ? "on" : "off");
|
||||
LOG_F(INFO, "HW cursor: %s", this->mm_regs[ATI_GEN_TEST_CNTL] & 0x80 ? "on" : "off");
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
@@ -266,11 +261,16 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
"ATI Rage: %s register at 0x%X set to 0x%X",
|
||||
get_reg_name(offset),
|
||||
offset & ~3,
|
||||
READ_DWORD_LE_A(&this->block_io_regs[offset & ~3]));
|
||||
READ_DWORD_LE_A(&this->mm_regs[offset & ~3]));
|
||||
}
|
||||
|
||||
if ((this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2) &&
|
||||
!(this->block_io_regs[ATI_CRTC_GEN_CNTL] & 0x40)) {
|
||||
if ((this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2) &&
|
||||
!(this->mm_regs[ATI_CRTC_GEN_CNTL] & 0x40)) {
|
||||
int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
|
||||
this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
|
||||
this->fb_ptr = &this->vram_ptr[src_offset];
|
||||
this->update_screen();
|
||||
}
|
||||
}
|
||||
@@ -397,11 +397,11 @@ uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* read from little-endian VRAM region */
|
||||
return read_mem(this->vram_ptr + offset, size);
|
||||
return read_mem(&this->vram_ptr[offset], size);
|
||||
}
|
||||
else if (offset >= BE_FB_OFFSET) {
|
||||
/* read from big-endian VRAM region */
|
||||
return read_mem_rev(this->vram_ptr + (offset - BE_FB_OFFSET), size);
|
||||
return read_mem_rev(&this->vram_ptr[offset - BE_FB_OFFSET], size);
|
||||
}
|
||||
else if (offset >= MM_REGS_0_OFF) {
|
||||
/* read from memory-mapped registers, block 0 */
|
||||
@@ -429,11 +429,11 @@ void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int siz
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* write to little-endian VRAM region */
|
||||
write_mem(this->vram_ptr + offset, value, size);
|
||||
write_mem(&this->vram_ptr[offset], value, size);
|
||||
}
|
||||
else if (offset >= BE_FB_OFFSET) {
|
||||
/* write to big-endian VRAM region */
|
||||
write_mem_rev(this->vram_ptr + (offset - BE_FB_OFFSET), value, size);
|
||||
write_mem_rev(&this->vram_ptr[offset - BE_FB_OFFSET], value, size);
|
||||
}
|
||||
else if (offset >= MM_REGS_0_OFF) {
|
||||
/* write to memory-mapped registers, block 0 */
|
||||
@@ -460,13 +460,13 @@ void ATIRage::verbose_pixel_format(int crtc_index) {
|
||||
|
||||
const char* what = "Pixel format:";
|
||||
|
||||
switch (this->block_io_regs[ATI_CRTC_GEN_CNTL+1] & 7) {
|
||||
switch (this->mm_regs[ATI_CRTC_GEN_CNTL+1] & 7) {
|
||||
case 1:
|
||||
LOG_F(INFO, "%s 4 bpp with DAC palette", what);
|
||||
break;
|
||||
case 2:
|
||||
// check the undocumented DAC_DIRECT bit
|
||||
if (this->block_io_regs[ATI_DAC_CNTL+1] & 4) {
|
||||
if (this->mm_regs[ATI_DAC_CNTL+1] & 4) {
|
||||
LOG_F(INFO, "%s 8 bpp direct color (RGB322)", what);
|
||||
} else {
|
||||
LOG_F(INFO, "%s 8 bpp with DAC palette", what);
|
||||
@@ -486,21 +486,21 @@ void ATIRage::verbose_pixel_format(int crtc_index) {
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "ATI Rage: CRTC pixel format %d not supported",
|
||||
this->block_io_regs[ATI_CRTC_GEN_CNTL+2] & 7);
|
||||
this->mm_regs[ATI_CRTC_GEN_CNTL+2] & 7);
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::crtc_enable() {
|
||||
/* active (visible) width is specified in characters (8 px) - 1 */
|
||||
this->active_width = (this->block_io_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
|
||||
this->active_width = (this->mm_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
|
||||
|
||||
/* active (visible) height is specified in lines - 1 */
|
||||
this->active_height =
|
||||
(READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
|
||||
(READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
|
||||
|
||||
if ((this->plls[PLL_VCLK_CNTL] & 3) == 3) {
|
||||
/* look up which VPLL ouput is requested */
|
||||
int clock_sel = this->block_io_regs[ATI_CLOCK_CNTL] & 3;
|
||||
int clock_sel = this->mm_regs[ATI_CLOCK_CNTL] & 3;
|
||||
|
||||
/* calculate VPLL output frequency */
|
||||
float vpll_freq = calc_pll_freq(2, this->plls[VCLK0_FB_DIV + clock_sel]);
|
||||
@@ -517,17 +517,22 @@ void ATIRage::crtc_enable() {
|
||||
|
||||
/* calculate display refresh rate */
|
||||
int hori_total =
|
||||
((READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_H_TOTAL_DISP])
|
||||
((READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_H_TOTAL_DISP])
|
||||
& 0x1FFUL) + 1) * 8;
|
||||
|
||||
int vert_total =
|
||||
(READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
|
||||
(READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
|
||||
|
||||
this->refresh_rate = pixel_clock / hori_total / vert_total;
|
||||
|
||||
// specify framebuffer converter (hardcoded for now)
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->convert_frame_8bpp(dst_buf, dst_pitch);
|
||||
};
|
||||
|
||||
LOG_F(INFO, "ATI Rage: primary CRT controller enabled:");
|
||||
LOG_F(INFO, "Video mode: %s",
|
||||
(this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 1) ? "extended" : "VGA");
|
||||
(this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 1) ? "extended" : "VGA");
|
||||
LOG_F(INFO, "Video width: %d px", this->active_width);
|
||||
LOG_F(INFO, "Video height: %d px", this->active_height);
|
||||
verbose_pixel_format(0);
|
||||
@@ -544,15 +549,15 @@ void ATIRage::crtc_enable() {
|
||||
void ATIRage::draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {
|
||||
uint8_t *src_buf, *src_row, *dst_row, px4;
|
||||
|
||||
int horz_offset = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]) & 0x3F;
|
||||
int vert_offset = (READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]) >> 16) & 0x3F;
|
||||
int horz_offset = READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_OFF]) & 0x3F;
|
||||
int vert_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_OFF]) >> 16) & 0x3F;
|
||||
|
||||
src_buf = this->vram_ptr + (READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET]) * 8);
|
||||
src_buf = &this->vram_ptr[(READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_OFFSET]) * 8)];
|
||||
|
||||
int cur_height = 64 - vert_offset;
|
||||
|
||||
uint32_t color0 = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_CLR0]) | 0x000000FFUL;
|
||||
uint32_t color1 = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_CLR1]) | 0x000000FFUL;
|
||||
uint32_t color0 = READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_CLR0]) | 0x000000FFUL;
|
||||
uint32_t color1 = READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_CLR1]) | 0x000000FFUL;
|
||||
|
||||
for (int h = 0; h < cur_height; h++) {
|
||||
dst_row = &dst_buf[h * dst_pitch];
|
||||
@@ -578,46 +583,3 @@ void ATIRage::draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::update_screen() {
|
||||
uint8_t *src_buf, *dst_buf, *src_row, *dst_row, pix;
|
||||
int src_pitch, dst_pitch;
|
||||
|
||||
//auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
this->disp_id->get_disp_texture((void **)&dst_buf, &dst_pitch);
|
||||
|
||||
uint32_t src_offset = (READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
|
||||
src_pitch = ((READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
|
||||
src_buf = this->vram_ptr + src_offset;
|
||||
|
||||
for (int h = 0; h < this->active_height; h++) {
|
||||
src_row = &src_buf[h * src_pitch];
|
||||
dst_row = &dst_buf[h * dst_pitch];
|
||||
|
||||
for (int x = 0; x < this->active_width; x++) {
|
||||
pix = src_row[x];
|
||||
dst_row[0] = this->palette[pix][2]; // B
|
||||
dst_row[1] = this->palette[pix][1]; // G
|
||||
dst_row[2] = this->palette[pix][0]; // R
|
||||
dst_row[3] = 255; // A
|
||||
dst_row += 4;
|
||||
}
|
||||
}
|
||||
|
||||
// HW cursor data is stored at the beginning of the video memory
|
||||
// HACK: use src_offset to recognize cursor data being ready
|
||||
// Normally, we should check GEN_CUR_ENABLE bit in the GEN_TEST_CNTL register
|
||||
if (src_offset > 0x400 && READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET])) {
|
||||
this->draw_hw_cursor(dst_buf + dst_pitch * 20 + 120, dst_pitch);
|
||||
}
|
||||
|
||||
this->disp_id->update_screen();
|
||||
|
||||
//auto end_time = std::chrono::steady_clock::now();
|
||||
//auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
//LOG_F(INFO, "Display uodate took: %lld ns", time_elapsed.count());
|
||||
SDL_Delay(15);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,9 +22,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ATI_RAGE_H
|
||||
#define ATI_RAGE_H
|
||||
|
||||
#include "displayid.h"
|
||||
#include "pcidevice.h"
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/* PCI related definitions. */
|
||||
enum {
|
||||
@@ -191,10 +194,10 @@ constexpr auto BE_FB_OFFSET = 0x00800000UL; /* Offset to the big-endian frame b
|
||||
|
||||
constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
|
||||
|
||||
class ATIRage : public PCIDevice {
|
||||
class ATIRage : public PCIDevice, public VideoCtrlBase {
|
||||
public:
|
||||
ATIRage(uint16_t dev_id, uint32_t mem_amount);
|
||||
~ATIRage();
|
||||
ATIRage(uint16_t dev_id, uint32_t vmem_size_mb);
|
||||
~ATIRage() = default;
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
@@ -225,32 +228,22 @@ protected:
|
||||
void verbose_pixel_format(int crtc_index);
|
||||
void crtc_enable();
|
||||
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
|
||||
void update_screen();
|
||||
|
||||
private:
|
||||
uint8_t block_io_regs[2048] = {0};
|
||||
uint8_t mm_regs[2048] = {0}; // internal registers
|
||||
|
||||
uint8_t pci_cfg[256] = {0}; /* PCI configuration space */
|
||||
uint8_t pci_cfg[256] = {0}; // PCI configuration space
|
||||
|
||||
uint8_t plls[64] = {0}; // internal PLL registers
|
||||
|
||||
/* CRT controller parameters */
|
||||
bool crtc_on = false;
|
||||
int active_width; // width of the visible display area
|
||||
int active_height; // height of the visible display area
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
/* Video RAM variables */
|
||||
std::unique_ptr<uint8_t[]> vram_ptr;
|
||||
uint32_t vram_size;
|
||||
uint8_t* vram_ptr;
|
||||
|
||||
uint32_t aperture_base;
|
||||
|
||||
DisplayID* disp_id;
|
||||
std::unique_ptr<DisplayID> disp_id;
|
||||
|
||||
uint8_t palette[256][4]; /* internal DAC palette in RGBA format */
|
||||
int comp_index; /* color component index for DAC palette access */
|
||||
uint8_t *surface;
|
||||
};
|
||||
#endif /* ATI_RAGE_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,156 +19,113 @@ 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 "displayid.h"
|
||||
#include <loguru.hpp>
|
||||
#include "SDL.h"
|
||||
/** @file DisplayID class implementation. */
|
||||
|
||||
DisplayID::DisplayID() {
|
||||
/* Initialize Apple monitor codes */
|
||||
this->std_sense_code = 6;
|
||||
this->ext_sense_code = 0x2B;
|
||||
#include <devices/video/displayid.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/** Mapping between monitor IDs and their sense codes. */
|
||||
static const std::map<std::string, uint16_t> MonitorIdToCode = {
|
||||
{ "MacColor21in" , 0x00FF },
|
||||
{ "PortraitGS" , 0x01FF },
|
||||
{ "MacRGB12in" , 0x02FF },
|
||||
{ "TwoPageGS" , 0x03FF },
|
||||
{ "NTSC" , 0x04FF },
|
||||
{ "MacRGB15in" , 0x05FF },
|
||||
{ "HiRes12-14in" , 0x06FF },
|
||||
{ "Multiscan15in" , 0x0603 },
|
||||
{ "Multiscan17in" , 0x060B },
|
||||
{ "Multiscan20in" , 0x0623 },
|
||||
{ "AppleVision1710" , 0x062B }, // this code is assigned to several different monitors!
|
||||
{ "PALEncoder" , 0x0700 }, // no clue what it means
|
||||
{ "NTSCEncoder" , 0x0714 }, // no clue what it means
|
||||
{ "VGA-SVGA" , 0x0717 },
|
||||
{ "MacRGB16in" , 0x072D },
|
||||
{ "MacRGB19in" , 0x073A },
|
||||
{ "PAL" , 0x0730 },
|
||||
{ "NotConnected" , 0x07FF }
|
||||
};
|
||||
|
||||
DisplayID::DisplayID()
|
||||
{
|
||||
// assume a DDC monitor is connected by default
|
||||
this->id_kind = Disp_Id_Kind::DDC2B;
|
||||
|
||||
std::string mon_id = GET_STR_PROP("mon_id");
|
||||
if (!mon_id.empty()) {
|
||||
if (MonitorIdToCode.count(mon_id)) {
|
||||
auto sense_code = MonitorIdToCode.at(mon_id);
|
||||
this->std_sense_code = (sense_code >> 8) & 0xFFU;
|
||||
this->ext_sense_code = (sense_code >> 0) & 0xFFU;
|
||||
this->id_kind = Disp_Id_Kind::AppleSense;
|
||||
LOG_F(INFO, "DisplayID mode set to AppleSense");
|
||||
LOG_F(INFO, "Standard sense code: 0x%d", this->std_sense_code);
|
||||
LOG_F(INFO, "Extended sense code: 0x%X", this->ext_sense_code);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize DDC I2C bus */
|
||||
this->next_state = I2CState::STOP;
|
||||
this->prev_state = I2CState::STOP;
|
||||
this->last_sda = 1;
|
||||
this->last_scl = 1;
|
||||
this->data_out = 0x3000;
|
||||
this->data_ptr = 0;
|
||||
|
||||
/* DDC sense mode is on by default */
|
||||
this->i2c_on = true;
|
||||
|
||||
LOG_F(INFO, "Create display window...");
|
||||
|
||||
// Create display window
|
||||
this->display_wnd = SDL_CreateWindow(
|
||||
"DingusPPC Display",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
640,
|
||||
480,
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
|
||||
if (this->display_wnd == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateWindow failed with %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
this->renderer = SDL_CreateRenderer(this->display_wnd, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (this->renderer == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateRenderer failed with %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(this->renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
|
||||
// Stupidly poll for 10 events.
|
||||
// Otherwise no window will be shown on mac OS!
|
||||
SDL_Event e;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
SDL_PollEvent(&e);
|
||||
}
|
||||
|
||||
this->disp_texture = SDL_CreateTexture(
|
||||
this->renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
640, 480
|
||||
);
|
||||
|
||||
if (this->disp_texture == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateTexture failed with %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
DisplayID::~DisplayID() {
|
||||
if (this->disp_texture) {
|
||||
SDL_DestroyTexture(this->disp_texture);
|
||||
}
|
||||
|
||||
if (this->renderer) {
|
||||
SDL_DestroyRenderer(this->renderer);
|
||||
}
|
||||
|
||||
if (this->display_wnd) {
|
||||
SDL_DestroyWindow(this->display_wnd);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayID::get_disp_texture(void **pix_buf, int *pitch) {
|
||||
SDL_LockTexture(this->disp_texture, NULL, pix_buf, pitch);
|
||||
}
|
||||
|
||||
void DisplayID::update_screen() {
|
||||
SDL_UnlockTexture(this->disp_texture);
|
||||
//SDL_SetRenderDrawColor(this->renderer, 255, 255, 255, 255);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderCopy(this->renderer, this->disp_texture, NULL, NULL);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
}
|
||||
|
||||
uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl) {
|
||||
this->last_sda = sda;
|
||||
this->last_scl = scl;
|
||||
|
||||
if (scl) {
|
||||
this->data_out |= 0x1000;
|
||||
} else {
|
||||
this->data_out &= ~0x1000U;
|
||||
}
|
||||
|
||||
if (sda) {
|
||||
this->data_out |= 0x2000;
|
||||
} else {
|
||||
this->data_out &= ~0x2000U;
|
||||
}
|
||||
|
||||
return this->data_out;
|
||||
}
|
||||
|
||||
|
||||
uint16_t DisplayID::read_monitor_sense(uint16_t data, uint16_t dirs) {
|
||||
uint8_t DisplayID::read_monitor_sense(uint8_t levels, uint8_t dirs)
|
||||
{
|
||||
uint8_t scl, sda;
|
||||
uint16_t result;
|
||||
|
||||
if ((dirs & 0x3100) == 0 && (data & 0x3100) == 0x3100) {
|
||||
LOG_F(WARNING, "DisplayID: Hackish Monitor ID Switch activated!");
|
||||
this->i2c_on = false;
|
||||
}
|
||||
|
||||
if (this->i2c_on) {
|
||||
/* if GPIO pins are in the output mode, pick up their values
|
||||
switch(this->id_kind) {
|
||||
case Disp_Id_Kind::DDC2B:
|
||||
/* If GPIO pins are in the output mode, pick up their levels.
|
||||
In the input mode, GPIO pins will be read "high" */
|
||||
scl = (dirs & 0x1000) ? !!(data & 0x1000) : 1;
|
||||
sda = (dirs & 0x2000) ? !!(data & 0x2000) : 1;
|
||||
scl = (dirs & 2) ? !!(levels & 2) : 1;
|
||||
sda = (dirs & 4) ? !!(levels & 4) : 1;
|
||||
|
||||
return update_ddc_i2c(sda, scl);
|
||||
} else { /* Apple legacy monitor codes (see Technical Note HW30) */
|
||||
switch (dirs & 0x3100) {
|
||||
case 0:
|
||||
result = ((this->std_sense_code & 6) << 11) | ((this->std_sense_code & 1) << 8);
|
||||
break;
|
||||
case 0x2000: /* Sense line 2 is low */
|
||||
result = ((this->ext_sense_code & 0x20) << 7) | ((this->ext_sense_code & 0x10) << 4);
|
||||
break;
|
||||
case 0x1000: /* Sense line 1 is low */
|
||||
result = ((this->ext_sense_code & 8) << 10) | ((this->ext_sense_code & 4) << 6);
|
||||
break;
|
||||
case 0x100: /* Sense line 0 is low */
|
||||
result = ((this->ext_sense_code & 2) << 12) | ((this->ext_sense_code & 1) << 12);
|
||||
break;
|
||||
case Disp_Id_Kind::AppleSense:
|
||||
switch ((dirs << 3) | levels) {
|
||||
case 0x23: // Sense line 2 pulled low
|
||||
return ((this->ext_sense_code >> 4) & 3);
|
||||
case 0x15: // Sense line 1 pulled low
|
||||
return (((this->ext_sense_code & 8) >> 1) |
|
||||
((this->ext_sense_code & 4) >> 2));
|
||||
case 0xE: // Sense line 0 pulled low
|
||||
return ((this->ext_sense_code & 3) << 1);
|
||||
default:
|
||||
result = 0x3100U;
|
||||
return this->std_sense_code;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t DisplayID::set_result(uint8_t sda, uint8_t scl)
|
||||
{
|
||||
uint16_t data_out;
|
||||
|
||||
uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl) //(uint16_t data, uint16_t dirs)
|
||||
this->last_sda = sda;
|
||||
this->last_scl = scl;
|
||||
|
||||
data_out = 0;
|
||||
|
||||
if (scl) {
|
||||
data_out |= 2;
|
||||
}
|
||||
|
||||
if (sda) {
|
||||
data_out |= 4;
|
||||
}
|
||||
|
||||
return data_out;
|
||||
}
|
||||
|
||||
uint8_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)
|
||||
{
|
||||
bool clk_gone_high = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,16 +26,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
video cards.
|
||||
|
||||
DisplayID provides two methods for display identification:
|
||||
- Apple monitor sense codes as described in the Technical Note HW30
|
||||
- Apple monitor sense as described in the Technical Note HW30
|
||||
- Display Data Channel (DDC) standardized by VESA
|
||||
*/
|
||||
|
||||
#ifndef DISPLAY_ID_H
|
||||
#define DISPLAY_ID_H
|
||||
|
||||
#include "SDL.h"
|
||||
#include <cinttypes>
|
||||
|
||||
/* Supported diplay ID methods. */
|
||||
enum class Disp_Id_Kind {
|
||||
AppleSense,
|
||||
DDC2B,
|
||||
};
|
||||
|
||||
/** I2C bus states. */
|
||||
enum I2CState : uint8_t {
|
||||
STOP = 0, /* transaction started */
|
||||
@@ -51,22 +56,16 @@ enum I2CState : uint8_t {
|
||||
class DisplayID {
|
||||
public:
|
||||
DisplayID();
|
||||
~DisplayID();
|
||||
~DisplayID() = default;
|
||||
|
||||
uint16_t read_monitor_sense(uint16_t data, uint16_t dirs);
|
||||
void get_disp_texture(void **pix_buf, int *pitch);
|
||||
void update_screen(void);
|
||||
uint8_t read_monitor_sense(uint8_t levels, uint8_t dirs);
|
||||
|
||||
protected:
|
||||
uint16_t set_result(uint8_t sda, uint8_t scl);
|
||||
uint16_t update_ddc_i2c(uint8_t sda, uint8_t scl);
|
||||
uint8_t set_result(uint8_t sda, uint8_t scl);
|
||||
uint8_t update_ddc_i2c(uint8_t sda, uint8_t scl);
|
||||
|
||||
private:
|
||||
SDL_Window *display_wnd;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *disp_texture;
|
||||
|
||||
bool i2c_on;
|
||||
Disp_Id_Kind id_kind;
|
||||
|
||||
uint8_t std_sense_code;
|
||||
uint8_t ext_sense_code;
|
||||
@@ -76,7 +75,6 @@ private:
|
||||
uint8_t prev_state;
|
||||
uint8_t last_sda;
|
||||
uint8_t last_scl;
|
||||
uint16_t data_out;
|
||||
int bit_count; /* number of bits processed so far */
|
||||
uint8_t byte; /* byte value being currently transferred */
|
||||
uint8_t dev_addr; /* current device address */
|
||||
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file PDM on-board video emulation. */
|
||||
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/memctrl/hmc.h>
|
||||
#include <devices/video/pdmonboard.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
PdmOnboardVideo::PdmOnboardVideo()
|
||||
: VideoCtrlBase()
|
||||
{
|
||||
this->video_mode = PDM_VMODE_OFF;
|
||||
this->blanking = 0x80;
|
||||
this->crtc_on = false;
|
||||
this->vdac_mode = 8;
|
||||
|
||||
// get pointer to the Highspeed Memory controller
|
||||
this->hmc_obj = dynamic_cast<HMC*>(gMachineObj->get_comp_by_name("HMC"));
|
||||
}
|
||||
|
||||
void PdmOnboardVideo::set_video_mode(uint8_t new_mode)
|
||||
{
|
||||
switch(new_mode & 0x7F) {
|
||||
case PdmVideoMode::Portrait:
|
||||
case PdmVideoMode::Rgb12in:
|
||||
case PdmVideoMode::Rgb13in:
|
||||
case PdmVideoMode::Rgb16in:
|
||||
case PdmVideoMode::VGA:
|
||||
if (this->video_mode != (new_mode & 0x1F)) {
|
||||
this->video_mode = new_mode & 0x1F;
|
||||
LOG_F(INFO, "PDM-Video: video mode set to 0x%X", this->video_mode);
|
||||
}
|
||||
if (this->blanking != (new_mode & 0x80)) {
|
||||
this->blanking = new_mode & 0x80;
|
||||
if (this->blanking) {
|
||||
this->disable_video_internal();
|
||||
} else {
|
||||
this->enable_video_internal();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "PDM-Video: video disabled, new mode = 0x%X", new_mode & 0x1F);
|
||||
this->video_mode = new_mode & 0x1F;
|
||||
this->blanking = 0x80;
|
||||
this->crtc_on = false;
|
||||
}
|
||||
}
|
||||
|
||||
void PdmOnboardVideo::set_pixel_depth(uint8_t depth)
|
||||
{
|
||||
static uint8_t pix_depths[8] = {1, 2, 4, 8, 16, 0xFF, 0xFF, 0xFF};
|
||||
|
||||
this->pixel_depth = pix_depths[depth];
|
||||
if (this->pixel_depth == 0xFF) {
|
||||
ABORT_F("PDM-Video: invalid pixel depth code %d specified!", depth);
|
||||
}
|
||||
}
|
||||
|
||||
void PdmOnboardVideo::vdac_config(uint8_t mode)
|
||||
{
|
||||
if (mode != 8) {
|
||||
LOG_F(WARNING, "Unknown Ariel Config code 0x%X", mode);
|
||||
}
|
||||
this->vdac_mode = 8; // 1 bpp, master mode, no overlay
|
||||
}
|
||||
|
||||
void PdmOnboardVideo::set_clut_index(uint8_t index)
|
||||
{
|
||||
this->clut_index = index;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
|
||||
void PdmOnboardVideo::set_clut_color(uint8_t color)
|
||||
{
|
||||
this->clut_color[this->comp_index++] = color;
|
||||
if (this->comp_index >= 3) {
|
||||
LOG_F(INFO, "PDM-Video: received color for index %d", this->clut_index);
|
||||
// TODO: combine separate components into a single ARGB value
|
||||
this->palette[this->clut_index][0] = this->clut_color[0];
|
||||
this->palette[this->clut_index][1] = this->clut_color[1];
|
||||
this->palette[this->clut_index][2] = this->clut_color[2];
|
||||
this->palette[this->clut_index][3] = 255;
|
||||
this->clut_index++; // assume the HW works like that
|
||||
this->comp_index = 0; // assume the HW works like that
|
||||
}
|
||||
}
|
||||
|
||||
void PdmOnboardVideo::enable_video_internal()
|
||||
{
|
||||
int new_width, new_height;
|
||||
|
||||
// ensure all video parameters contain safe values
|
||||
switch(this->video_mode) {
|
||||
case PdmVideoMode::Portrait:
|
||||
case PdmVideoMode::Rgb16in:
|
||||
case PdmVideoMode::VGA:
|
||||
if (this->pixel_depth > 8) {
|
||||
ABORT_F("PDM-Video: no 16bpp support in mode %d!", this->video_mode);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// set video mode parameters
|
||||
switch(this->video_mode) {
|
||||
case PdmVideoMode::Portrait:
|
||||
new_width = 640;
|
||||
new_height = 870;
|
||||
this->pixel_clock = 57283200;
|
||||
break;
|
||||
case PdmVideoMode::Rgb12in:
|
||||
new_width = 512;
|
||||
new_height = 384;
|
||||
this->pixel_clock = 15667200;
|
||||
break;
|
||||
case PdmVideoMode::Rgb13in:
|
||||
new_width = 640;
|
||||
new_height = 480;
|
||||
this->pixel_clock = 31334400;
|
||||
break;
|
||||
case PdmVideoMode::Rgb16in:
|
||||
new_width = 832;
|
||||
new_height = 624;
|
||||
this->pixel_clock = 57283200;
|
||||
break;
|
||||
case PdmVideoMode::VGA:
|
||||
new_width = 640;
|
||||
new_height = 480;
|
||||
this->pixel_clock = 25175000;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("PDM-Video: invalid video mode %d", this->video_mode);
|
||||
}
|
||||
|
||||
if (new_width != this->active_width || new_height != this->active_height) {
|
||||
LOG_F(WARNING, "Display window resizing not implemented yet!");
|
||||
}
|
||||
|
||||
// figure out where our framebuffer is located
|
||||
uint64_t hmc_control = this->hmc_obj->get_control_reg();
|
||||
uint32_t fb_base_phys = ((hmc_control >> HMC_VBASE_BIT) & 1) ? 0 : 0x100000;
|
||||
LOG_F(INFO, "PDM-Video: framebuffer phys base addr = 0x%X", fb_base_phys);
|
||||
|
||||
// set framebuffer address and pitch
|
||||
this->fb_ptr = mmu_get_dma_mem(fb_base_phys, PDM_FB_SIZE_MAX);
|
||||
this->active_width = new_width;
|
||||
this->active_height = new_height;
|
||||
|
||||
switch(this->pixel_depth) {
|
||||
case 1:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->convert_frame_1bpp(dst_buf, dst_pitch);
|
||||
};
|
||||
this->fb_pitch = new_width >> 3; // one byte contains 8 pixels
|
||||
break;
|
||||
default:
|
||||
ABORT_F("PDM-Video: pixel depth %d not implemented yet!", this->pixel_depth);
|
||||
}
|
||||
|
||||
this->update_screen();
|
||||
|
||||
LOG_F(INFO, "PDM-Video: video enabled");
|
||||
this->crtc_on = true;
|
||||
}
|
||||
|
||||
void PdmOnboardVideo::disable_video_internal()
|
||||
{
|
||||
this->crtc_on = false;
|
||||
LOG_F(INFO, "PDM-Video: video disabled");
|
||||
}
|
||||
|
||||
/** Ariel II has a weird 1bpp mode where a white pixel is mapped to
|
||||
CLUT entry #127 (%01111111) and a black pixel to #255 (%11111111).
|
||||
It requres a non-standard conversion routine implementend below.
|
||||
*/
|
||||
void PdmOnboardVideo::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
{
|
||||
uint8_t *src_buf, *src_row, pix;
|
||||
uint32_t *dst_row;
|
||||
int src_pitch, width;
|
||||
uint32_t pixels[2];
|
||||
|
||||
// prepare cached ARGB values for white & black pixels
|
||||
pixels[0] = (0xFF << 24) | (this->palette[127][0] << 16) |
|
||||
(this->palette[127][1] << 8) | this->palette[127][2];
|
||||
pixels[1] = (0xFF << 24) | (this->palette[255][0] << 16) |
|
||||
(this->palette[255][1] << 8) | this->palette[255][2];
|
||||
|
||||
src_buf = this->fb_ptr;
|
||||
src_pitch = this->fb_pitch;
|
||||
width = this->active_width >> 3;
|
||||
|
||||
for (int h = 0; h < this->active_height; h++) {
|
||||
src_row = &src_buf[h * src_pitch];
|
||||
dst_row = (uint32_t *)(&dst_buf[h * dst_pitch]);
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
pix = src_row[x];
|
||||
|
||||
for (int i = 0; i < 8; i++, pix <<= 1, dst_row++) {
|
||||
*dst_row = pixels[(pix >> 7) & 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Definitions for the PDM on-board video. */
|
||||
|
||||
#ifndef PDM_ONBOARD_H
|
||||
#define PDM_ONBOARD_H
|
||||
|
||||
#include <devices/memctrl/hmc.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#define PDM_VMODE_OFF 0x1F
|
||||
|
||||
/** Max. size of our framebuffer in bytes (RGB 13-inch, 16 bpp) */
|
||||
#define PDM_FB_SIZE_MAX (640 * 480 * 2)
|
||||
|
||||
/** Fixed video modes supported by the PDM on-board video. */
|
||||
enum PdmVideoMode : uint8_t {
|
||||
Portrait = 1,
|
||||
Rgb12in = 2,
|
||||
Rgb13in = 6,
|
||||
Rgb16in = 9,
|
||||
VGA = 0xB
|
||||
};
|
||||
|
||||
class PdmOnboardVideo : public VideoCtrlBase {
|
||||
public:
|
||||
PdmOnboardVideo();
|
||||
~PdmOnboardVideo() = default;
|
||||
|
||||
uint8_t get_video_mode() {
|
||||
return ((this->video_mode & 0x1F) | this->blanking);
|
||||
};
|
||||
|
||||
void set_video_mode(uint8_t new_mode);
|
||||
void set_pixel_depth(uint8_t depth);
|
||||
void vdac_config(uint8_t config);
|
||||
void set_clut_index(uint8_t index);
|
||||
void set_clut_color(uint8_t color);
|
||||
|
||||
protected:
|
||||
void enable_video_internal();
|
||||
void disable_video_internal();
|
||||
void convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
private:
|
||||
uint8_t video_mode;
|
||||
uint8_t pixel_depth;
|
||||
uint8_t blanking;
|
||||
uint8_t vdac_mode;
|
||||
uint8_t clut_index;
|
||||
uint8_t comp_index;
|
||||
uint8_t clut_color[3];
|
||||
|
||||
HMC* hmc_obj;
|
||||
};
|
||||
|
||||
#endif // PDM_ONBOARD_H
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Video Conroller base class implementation. */
|
||||
|
||||
#include "videoctrl.h"
|
||||
#include <loguru.hpp>
|
||||
#include <SDL.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
|
||||
VideoCtrlBase::VideoCtrlBase(int width, int height)
|
||||
{
|
||||
LOG_F(INFO, "Create display window...");
|
||||
|
||||
this->active_width = width;
|
||||
this->active_height = height;
|
||||
|
||||
// Create display window
|
||||
this->display_wnd = SDL_CreateWindow(
|
||||
"DingusPPC Display",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
this->active_width,
|
||||
this->active_height,
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
|
||||
if (this->display_wnd == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateWindow failed with %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
this->renderer = SDL_CreateRenderer(this->display_wnd, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (this->renderer == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateRenderer failed with %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(this->renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
|
||||
// Stupidly poll for 10 events.
|
||||
// Otherwise no window will be shown on mac OS!
|
||||
SDL_Event e;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
SDL_PollEvent(&e);
|
||||
}
|
||||
|
||||
this->disp_texture = SDL_CreateTexture(
|
||||
this->renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
640, 480
|
||||
);
|
||||
|
||||
if (this->disp_texture == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateTexture failed with %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
VideoCtrlBase::~VideoCtrlBase()
|
||||
{
|
||||
if (this->disp_texture) {
|
||||
SDL_DestroyTexture(this->disp_texture);
|
||||
}
|
||||
|
||||
if (this->renderer) {
|
||||
SDL_DestroyRenderer(this->renderer);
|
||||
}
|
||||
|
||||
if (this->display_wnd) {
|
||||
SDL_DestroyWindow(this->display_wnd);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoCtrlBase::update_screen()
|
||||
{
|
||||
uint8_t* dst_buf;
|
||||
int dst_pitch;
|
||||
|
||||
//auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
SDL_LockTexture(this->disp_texture, NULL, (void **)&dst_buf, &dst_pitch);
|
||||
|
||||
// texture update callback to get ARGB data from guest framebuffer
|
||||
this->convert_fb_cb(dst_buf, dst_pitch);
|
||||
|
||||
SDL_UnlockTexture(this->disp_texture);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderCopy(this->renderer, this->disp_texture, NULL, NULL);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
|
||||
// HW cursor data is stored at the beginning of the video memory
|
||||
// HACK: use src_offset to recognize cursor data being ready
|
||||
// Normally, we should check GEN_CUR_ENABLE bit in the GEN_TEST_CNTL register
|
||||
//if (src_offset > 0x400 && READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET])) {
|
||||
// this->draw_hw_cursor(dst_buf + dst_pitch * 20 + 120, dst_pitch);
|
||||
//}
|
||||
|
||||
//auto end_time = std::chrono::steady_clock::now();
|
||||
//auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
//LOG_F(INFO, "Display uodate took: %lld ns", time_elapsed.count());
|
||||
|
||||
SDL_Delay(15);
|
||||
}
|
||||
|
||||
void VideoCtrlBase::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
{
|
||||
// TODO: implement me!
|
||||
}
|
||||
|
||||
void VideoCtrlBase::convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
{
|
||||
uint8_t *src_buf, *src_row, *dst_row, pix;
|
||||
int src_pitch;
|
||||
|
||||
src_buf = this->fb_ptr;
|
||||
src_pitch = this->fb_pitch;
|
||||
|
||||
for (int h = 0; h < this->active_height; h++) {
|
||||
src_row = &src_buf[h * src_pitch];
|
||||
dst_row = &dst_buf[h * dst_pitch];
|
||||
|
||||
for (int x = 0; x < this->active_width; x++) {
|
||||
pix = src_row[x];
|
||||
dst_row[0] = this->palette[pix][2]; // B
|
||||
dst_row[1] = this->palette[pix][1]; // G
|
||||
dst_row[2] = this->palette[pix][0]; // R
|
||||
dst_row[3] = 255; // Alpha
|
||||
dst_row += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Video Conroller base class definitions. */
|
||||
|
||||
#ifndef VIDEO_CTRL_H
|
||||
#define VIDEO_CTRL_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
class VideoCtrlBase {
|
||||
public:
|
||||
VideoCtrlBase(int width = 640, int height = 480);
|
||||
~VideoCtrlBase();
|
||||
|
||||
void update_screen(void);
|
||||
|
||||
// converters for various framebuffer pixel depths
|
||||
virtual void convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch);
|
||||
virtual void convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
protected:
|
||||
/* CRT controller parameters */
|
||||
bool crtc_on = false;
|
||||
int active_width; // width of the visible display area
|
||||
int active_height; // height of the visible display area
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
uint8_t palette[256][4]; /* internal DAC palette in RGBA format */
|
||||
|
||||
// Framebuffer parameters
|
||||
uint8_t* fb_ptr;
|
||||
int fb_pitch;
|
||||
|
||||
std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb;
|
||||
|
||||
private:
|
||||
SDL_Window *display_wnd;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *disp_texture;
|
||||
};
|
||||
|
||||
#endif // VIDEO_CTRL_H
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Macros for performing byte swapping for quick endian conversion.
|
||||
|
||||
It will try to use the fast built-in machine instructions first
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -20,4 +20,4 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void interpreter_update_counters();
|
||||
void interpreter_main_loop();
|
||||
void interpreter_main_loop();
|
||||
@@ -1,6 +1,7 @@
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/devices"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
#include "machinebase.h"
|
||||
#include "devices/hwcomponent.h"
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
std::unique_ptr<MachineBase> gMachineObj = 0;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,7 +27,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_BASE_H
|
||||
#define MACHINE_BASE_H
|
||||
|
||||
#include "devices/hwcomponent.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
+45
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,10 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "machinefactory.h"
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "memaccess.h"
|
||||
#include "machineproperties.h"
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
@@ -38,7 +40,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -75,6 +76,18 @@ static const PropMap GossamerSettings = {
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"gfxmem_size",
|
||||
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
|
||||
{"mon_id",
|
||||
new StrProperty("")},
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
/** Monitors supported by the PDM on-board video. */
|
||||
/* see displayid.cpp for the full list of supported monitor IDs. */
|
||||
static const vector<string> PDMBuiltinMonitorIDs = {
|
||||
"PortraitGS", "MacRGB12in", "MacRGB15in", "HiRes12-14in", "VGA-SVGA",
|
||||
"MacRGB16in", "Multiscan15in", "Multiscan17in", "Multiscan20in",
|
||||
"NotConnected"
|
||||
};
|
||||
|
||||
static const PropMap PDMSettings = {
|
||||
@@ -82,6 +95,10 @@ static const PropMap PDMSettings = {
|
||||
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
|
||||
{"mon_id",
|
||||
new StrProperty("HiRes12-14in", PDMBuiltinMonitorIDs)},
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const map<string, string> PropHelp = {
|
||||
@@ -89,6 +106,8 @@ static const map<string, string> PropHelp = {
|
||||
{"rambank2_size", "specifies RAM bank 2 size in MB"},
|
||||
{"rambank3_size", "specifies RAM bank 3 size in MB"},
|
||||
{"gfxmem_size", "specifies video memory size in MB"},
|
||||
{"fdd_img", "specifies path to floppy disk image"},
|
||||
{"mon_id", "specifies which monitor to emulate"},
|
||||
};
|
||||
|
||||
static const map<string, tuple<PropMap, function<int(string&)>, string>> machines = {
|
||||
@@ -204,10 +223,20 @@ void list_properties() {
|
||||
for (auto& p : get<0>(mach.second)) {
|
||||
cout << setw(13) << p.first << "\t\t" << PropHelp.at(p.first)
|
||||
<< endl;
|
||||
if (p.second->get_type() == PROP_TYPE_INTEGER) {
|
||||
cout << setw(13) << "\t\t\t" "Valid values: " <<
|
||||
dynamic_cast<IntProperty*>(p.second)->get_valid_values_as_str()
|
||||
|
||||
cout << setw(13) << "\t\t\t" "Valid values: ";
|
||||
|
||||
switch(p.second->get_type()) {
|
||||
case PROP_TYPE_INTEGER:
|
||||
cout << dynamic_cast<IntProperty*>(p.second)->get_valid_values_as_str()
|
||||
<< endl;
|
||||
break;
|
||||
case PROP_TYPE_STRING:
|
||||
cout << dynamic_cast<StrProperty*>(p.second)->get_valid_values_as_str()
|
||||
<< endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
@@ -235,6 +264,7 @@ int load_boot_rom(string& rom_filepath) {
|
||||
ifstream rom_file;
|
||||
size_t file_size;
|
||||
int result;
|
||||
AddressMapEntry *rom_reg;
|
||||
|
||||
rom_file.open(rom_filepath, ios::in | ios::binary);
|
||||
if (rom_file.fail()) {
|
||||
@@ -259,7 +289,12 @@ int load_boot_rom(string& rom_filepath) {
|
||||
MemCtrlBase* mem_ctrl = dynamic_cast<MemCtrlBase*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
mem_ctrl->set_data(0xFFC00000, sysrom_mem, file_size);
|
||||
if ((rom_reg = mem_ctrl->find_rom_region())) {
|
||||
mem_ctrl->set_data(rom_reg->start, sysrom_mem, file_size);
|
||||
} else {
|
||||
ABORT_F("Could not locate physical ROM region!");
|
||||
}
|
||||
|
||||
delete[] sysrom_mem;
|
||||
|
||||
result = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,7 +27,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_FACTORY_H
|
||||
#define MACHINE_FACTORY_H
|
||||
|
||||
#include "machinebase.h"
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,17 +24,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "devices/atirage.h"
|
||||
#include "devices/machineid.h"
|
||||
#include "devices/soundserver.h"
|
||||
#include "devices/macio.h"
|
||||
#include "devices/mpc106.h"
|
||||
#include "devices/spdram.h"
|
||||
#include "devices/viacuda.h"
|
||||
#include "machinebase.h"
|
||||
#include "machineproperties.h"
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <devices/memctrl/spdram.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <devices/video/atirage.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -89,9 +90,9 @@ int create_gossamer(std::string& id) {
|
||||
}
|
||||
|
||||
/* configure RAM slots */
|
||||
setup_ram_slot("RAM_DIMM_1", 0x57, GET_INT_PROP("rambank1_size"));
|
||||
setup_ram_slot("RAM_DIMM_2", 0x56, GET_INT_PROP("rambank2_size"));
|
||||
setup_ram_slot("RAM_DIMM_3", 0x55, GET_INT_PROP("rambank3_size"));
|
||||
setup_ram_slot("RAM_DIMM_1", 0x57, GET_INT_PROP("rambank1_size"));
|
||||
setup_ram_slot("RAM_DIMM_2", 0x56, GET_INT_PROP("rambank2_size"));
|
||||
setup_ram_slot("RAM_DIMM_3", 0x55, GET_INT_PROP("rambank3_size"));
|
||||
|
||||
/* register ATI 3D Rage Pro video card with the PCI host bridge */
|
||||
gMachineObj->add_component("ATIRage",
|
||||
@@ -102,6 +103,12 @@ int create_gossamer(std::string& id) {
|
||||
/* Init virtual CPU and request MPC750 CPU aka G3 */
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
|
||||
|
||||
/* check for a floppy image to be inserted into the virtual superdrive */
|
||||
std::string fdd_path = GET_STR_PROP("fdd_img");
|
||||
if (!fdd_path.empty()) {
|
||||
open_floppy_image(fdd_path.c_str());
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initialization complete.\n");
|
||||
|
||||
return 0;
|
||||
|
||||
+16
-8
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,14 +24,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "devices/amic.h"
|
||||
#include "devices/hmc.h"
|
||||
#include "devices/machineid.h"
|
||||
#include "devices/soundserver.h"
|
||||
#include "machinebase.h"
|
||||
#include "machineproperties.h"
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <devices/ioctrl/amic.h>
|
||||
#include <devices/memctrl/hmc.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
int create_pdm(std::string& id) {
|
||||
@@ -85,6 +87,12 @@ int create_pdm(std::string& id) {
|
||||
/* Init virtual CPU and request MPC601 */
|
||||
ppc_cpu_init(hmc_obj, PPC_VER::MPC601);
|
||||
|
||||
/* check for a floppy image to be inserted into the virtual superdrive */
|
||||
std::string fdd_path = GET_STR_PROP("fdd_img");
|
||||
if (!fdd_path.empty()) {
|
||||
open_floppy_image(fdd_path.c_str());
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initialization completed.\n");
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "machineproperties.h"
|
||||
#include <map>
|
||||
|
||||
static std::map<std::string, StrProperty> PowerMac6100_Properties = {
|
||||
{"machineid", StrProperty("PowerMacG3")},
|
||||
{"cputype", StrProperty("PPC_MPC750")},
|
||||
{"motherboard", StrProperty("Grackle")},
|
||||
{"ioboard", StrProperty("Heathrow")},
|
||||
{"rambank1", StrProperty("8")},
|
||||
{"minram", StrProperty("32")},
|
||||
{"maxram", StrProperty("256")},
|
||||
{"gfxcard", StrProperty("Nubus_Video")},
|
||||
{"gfxmem", StrProperty("2")}
|
||||
};
|
||||
|
||||
static std::map<std::string, StrProperty> PowerMacG3_Properties = {
|
||||
{"machineid", StrProperty("PowerMacG3")},
|
||||
{"cputype", StrProperty("PPC_MPC750")},
|
||||
{"motherboard", StrProperty("Grackle")},
|
||||
{"ioboard", StrProperty("Heathrow")},
|
||||
{"rambank1", StrProperty("64")},
|
||||
{"minram", StrProperty("32")},
|
||||
{"maxram", StrProperty("256")},
|
||||
{"gfxcard", StrProperty("ATI_Rage_Pro")},
|
||||
{"gfxmem", StrProperty("2")}
|
||||
};
|
||||
|
||||
static std::map<std::string, uint32_t> PPC_CPUs = {
|
||||
{"PPC_MPC601", 0x00010001},
|
||||
{"PPC_MPC603", 0x00030001},
|
||||
{"PPC_MPC604", 0x00040001},
|
||||
{"PPC_MPC603E", 0x00060101},
|
||||
{"PPC_MPC750", 0x00080200}
|
||||
};
|
||||
|
||||
static std::map<std::string, uint32_t> GFX_CARDs = {
|
||||
{"ATI_Rage_Pro", 0x10024750},
|
||||
{"ATI_Rage_128_Pro", 0x10025052}
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 "machineproperties.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
void StrProperty::set_string(std::string str)
|
||||
{
|
||||
if (!this->check_val(str)) {
|
||||
LOG_F(ERROR, "Invalid property value '%s'!", str.c_str());
|
||||
LOG_F(ERROR, "Valid values: %s!",
|
||||
this->get_valid_values_as_str().c_str());
|
||||
} else {
|
||||
this->val = str;
|
||||
}
|
||||
}
|
||||
|
||||
std::string StrProperty::get_valid_values_as_str()
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
switch (this->check_type) {
|
||||
case CHECK_TYPE_LIST: {
|
||||
bool first = true;
|
||||
for (auto it = begin(this->vec); it != end(this->vec); ++it) {
|
||||
if (!first)
|
||||
ss << ", ";
|
||||
ss << "'" << *it << "'";
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
return ss.str();
|
||||
default:
|
||||
return std::string("Any");
|
||||
}
|
||||
}
|
||||
|
||||
bool StrProperty::check_val(std::string str)
|
||||
{
|
||||
switch (this->check_type) {
|
||||
case CHECK_TYPE_LIST:
|
||||
if (find(this->vec.begin(), this->vec.end(), str) != this->vec.end())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t IntProperty::get_int()
|
||||
{
|
||||
try {
|
||||
uint32_t result = strtoul(this->get_string().c_str(), 0, 0);
|
||||
|
||||
/* perform value check */
|
||||
if (!this->check_val(result)) {
|
||||
LOG_F(ERROR, "Invalid property value %d!", result);
|
||||
LOG_F(ERROR, "Valid values: %s!",
|
||||
this->get_valid_values_as_str().c_str());
|
||||
this->set_string(to_string(this->int_val));
|
||||
} else {
|
||||
this->int_val = result;
|
||||
}
|
||||
} catch (string bad_string) {
|
||||
LOG_F(ERROR, "Could not convert string %s to an integer!",
|
||||
bad_string.c_str());
|
||||
}
|
||||
return this->int_val;
|
||||
}
|
||||
|
||||
string IntProperty::get_valid_values_as_str()
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
switch (this->check_type) {
|
||||
case CHECK_TYPE_RANGE:
|
||||
ss << "[" << this->min << "..." << this->max << "]";
|
||||
return ss.str();
|
||||
case CHECK_TYPE_LIST: {
|
||||
bool first = true;
|
||||
for (auto it = begin(this->vec); it != end(this->vec); ++it) {
|
||||
if (!first)
|
||||
ss << ", ";
|
||||
ss << *it;
|
||||
first = false;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
default:
|
||||
return std::string("Any");
|
||||
}
|
||||
}
|
||||
|
||||
bool IntProperty::check_val(uint32_t val)
|
||||
{
|
||||
switch (this->check_type) {
|
||||
case CHECK_TYPE_RANGE:
|
||||
if (val < this->min || val > this->max)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
case CHECK_TYPE_LIST:
|
||||
if (find(this->vec.begin(), this->vec.end(), val) != this->vec.end())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,30 @@
|
||||
#include "endianswap.h"
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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 <loguru.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifndef MACHINE_PROPERTIES_H
|
||||
@@ -15,8 +32,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define ILLEGAL_DEVICE_VALUE 0x168A523B
|
||||
|
||||
/** Property types. */
|
||||
enum PropType : int {
|
||||
PROP_TYPE_UNKNOWN = 0,
|
||||
@@ -44,15 +59,15 @@ public:
|
||||
/* Clone method for copying derived property objects. */
|
||||
virtual BasicProperty* clone() const = 0;
|
||||
|
||||
string get_string() {
|
||||
virtual string get_string() {
|
||||
return this->val;
|
||||
}
|
||||
|
||||
void set_string(string str) {
|
||||
virtual void set_string(string str) {
|
||||
this->val = str;
|
||||
}
|
||||
|
||||
PropType get_type() {
|
||||
virtual PropType get_type() {
|
||||
return this->type;
|
||||
}
|
||||
|
||||
@@ -66,9 +81,33 @@ protected:
|
||||
class StrProperty : public BasicProperty {
|
||||
public:
|
||||
StrProperty(string str)
|
||||
: BasicProperty(PROP_TYPE_STRING, str) {}
|
||||
: BasicProperty(PROP_TYPE_STRING, str)
|
||||
{
|
||||
this->check_type = CHECK_TYPE_NONE;
|
||||
this->vec.clear();
|
||||
}
|
||||
|
||||
/* construct a string property with a list of valid values. */
|
||||
StrProperty(string str, vector<string> vec)
|
||||
: BasicProperty(PROP_TYPE_STRING, str)
|
||||
{
|
||||
this->check_type = CHECK_TYPE_LIST;
|
||||
this->vec = vec;
|
||||
}
|
||||
|
||||
BasicProperty* clone() const { return new StrProperty(*this); }
|
||||
|
||||
/* override BasicProperty::set_string() and perform checks */
|
||||
void set_string(string str);
|
||||
|
||||
string get_valid_values_as_str();
|
||||
|
||||
protected:
|
||||
bool check_val(string str);
|
||||
|
||||
private:
|
||||
CheckType check_type;
|
||||
vector<string> vec;
|
||||
};
|
||||
|
||||
/** Property class that holds an integer value. */
|
||||
@@ -109,65 +148,12 @@ public:
|
||||
|
||||
BasicProperty* clone() const { return new IntProperty(*this); }
|
||||
|
||||
uint32_t get_int() {
|
||||
try {
|
||||
uint32_t result = strtoul(this->get_string().c_str(), 0, 0);
|
||||
uint32_t get_int();
|
||||
|
||||
/* perform value check */
|
||||
if (!this->check_val(result)) {
|
||||
LOG_F(ERROR, "Invalid property value %d!", result);
|
||||
LOG_F(ERROR, "Valid values: %s!",
|
||||
this->get_valid_values_as_str().c_str());
|
||||
this->set_string(to_string(this->int_val));
|
||||
} else {
|
||||
this->int_val = result;
|
||||
}
|
||||
} catch (string bad_string) {
|
||||
LOG_F(ERROR, "Could not convert string %s to an integer!",
|
||||
bad_string.c_str());
|
||||
}
|
||||
return this->int_val;
|
||||
}
|
||||
|
||||
string get_valid_values_as_str() {
|
||||
stringstream ss;
|
||||
|
||||
switch (this->check_type) {
|
||||
case CHECK_TYPE_RANGE:
|
||||
ss << "[" << this->min << "..." << this->max << "]";
|
||||
return ss.str();
|
||||
case CHECK_TYPE_LIST: {
|
||||
bool first = true;
|
||||
for (auto it = begin(this->vec); it != end(this->vec); ++it) {
|
||||
if (!first)
|
||||
ss << ", ";
|
||||
ss << *it;
|
||||
first = false;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
default:
|
||||
return string("None");
|
||||
}
|
||||
}
|
||||
string get_valid_values_as_str();
|
||||
|
||||
protected:
|
||||
bool check_val(uint32_t val) {
|
||||
switch (this->check_type) {
|
||||
case CHECK_TYPE_RANGE:
|
||||
if (val < this->min || val > this->max)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
case CHECK_TYPE_LIST:
|
||||
if (find(this->vec.begin(), this->vec.end(), val) != this->vec.end())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
bool check_val(uint32_t val);
|
||||
|
||||
private:
|
||||
uint32_t int_val;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
+21
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** @file Set of macros for accessing host memory in units of various sizes
|
||||
and endianness.
|
||||
*/
|
||||
|
||||
Vendored
+1
-1
Submodule thirdparty/cubeb updated: 524a9c99b4...d512bfa07a.
@@ -1,3 +0,0 @@
|
||||
build/
|
||||
build-win32/
|
||||
build-win64/
|
||||
Vendored
-78
@@ -1,78 +0,0 @@
|
||||
### Version 1.1.0 (2016-01-31)
|
||||
|
||||
* JACK: delete broken pause implementation. Previously, calling
|
||||
`soundio_outstream_pause` or `soundio_instream_pause` during the
|
||||
`write_callback` or `read_callback` would cause a deadlock. Now, attempting
|
||||
to pause always results in `SoundIoErrorBackendIncompatible`.
|
||||
* PulseAudio: improve latency handling code. It now passes the latency test
|
||||
along with all the other backends.
|
||||
* PulseAudio: fix incorrect outstream `software_latency`.
|
||||
* libsoundio source code is now pure C, no C++ mixed in.
|
||||
* ALSA: better device detection.
|
||||
- No longer suppress sysdefault.
|
||||
- If default and sysdefault are missing, use the first device as the default
|
||||
device.
|
||||
* Workaround for Raspberry Pi driver that incorrectly reports itself as Output
|
||||
when it is actually Input.
|
||||
* ALSA: let alsa lib choose period settings. Fixes behavior with many ALSA
|
||||
devices.
|
||||
* ALSA: fix potential cleanup deadlock.
|
||||
* ALSA: fix crash for devices with null description, thanks to Charles Lehner.
|
||||
* CoreAudio: drop support for MacOS 10.9. There was a bug for this system that
|
||||
was never resolved, so it didn't work in the first place.
|
||||
* Record example handles device not found and probe errors gracefully.
|
||||
* Fix typo in microphone example, thanks to James Dyson.
|
||||
* Improve documentation.
|
||||
* New functions available: `soundio_version_string`, `soundio_version_major`,
|
||||
`soundio_version_minor`, `soundio_version_patch`.
|
||||
* libsoundio source code now builds with MSVC, thanks to Raphaël Londeix.
|
||||
|
||||
### Version 1.0.3 (2015-10-20)
|
||||
|
||||
* Architecture independent header files.
|
||||
* Add --latency and --sample-rate to sine example.
|
||||
* ALSA: fix deadlock under some circumstances.
|
||||
* dummy: fix deadlock when pause called from `write_callback`.
|
||||
* Fix double clean-up corruption when opening stream fails.
|
||||
* Add --device and --raw to underflow test.
|
||||
* ALSA: use period size to calculate buffer size, fixes opening output stream
|
||||
sometimes resulting in an error.
|
||||
|
||||
### Version 1.0.2 (2015-09-24)
|
||||
|
||||
* build: fix GNUInstallDirs not working.
|
||||
* docs: fix incorrect docs for `soundio_instream_pause`.
|
||||
* PulseAudio: fix `soundio_outstream_pause` triggering assertion when called
|
||||
from within `write_callback`.
|
||||
* fix mirrored memory not working on Linux (fixes corrupted data in ring
|
||||
buffer).
|
||||
* os: fix crash when creating non high priority thread fails.
|
||||
* docs: fix typos and cleanup.
|
||||
* fix and add test for `soundio_device_nearest_sample_rate`.
|
||||
|
||||
### Version 1.0.1 (2015-09-11)
|
||||
|
||||
* libsoundio no longer depends on or links against libm.
|
||||
* ALSA: treat ALSA as unavailable when /dev/snd does not exist.
|
||||
* ALSA: remove duplicate assert.
|
||||
* ALSA: remove stray print statement.
|
||||
* ALSA: pausing returns error code when state is invalid instead of reaching
|
||||
assertion failure in pcm.c.
|
||||
* JACK: fix infinite loop when refreshing devices.
|
||||
* PulseAudio: better clear buffer implementation.
|
||||
* dummy backend: fix sometimes calling `write_callback` with
|
||||
`frame_count_max` equal to 0.
|
||||
* os: fix some variables accidentally not declared static.
|
||||
* macos: fix not cleaning up condition variables.
|
||||
* macos: avoid allocation when getting time.
|
||||
* docs: note that `read_callback` and `write_callback` must be real time safe.
|
||||
* docs: record example demonstrates proper real time safety by not calling
|
||||
fwrite in `read_callback`.
|
||||
* docs: add note to record example about shutting down.
|
||||
* docs: make microphone example latency a command line argument.
|
||||
* build: fix build on linux with clang.
|
||||
* build: static libs, examples, and tests are optional.
|
||||
|
||||
### Version 1.0.0 (2015-09-03)
|
||||
|
||||
* Initial public release.
|
||||
Vendored
-388
@@ -1,388 +0,0 @@
|
||||
cmake_minimum_required(VERSION 2.8.5)
|
||||
project(libsoundio C)
|
||||
set(CMAKE_MODULE_PATH ${libsoundio_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.0.0)
|
||||
set(CMAKE_INSTALL_LIBDIR "lib" CACHE PATH "library install dir (lib)")
|
||||
set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE PATH "header base install dir (include)")
|
||||
set(CMAKE_INSTALL_BINDIR "bin" CACHE PATH "user executables (bin)")
|
||||
else()
|
||||
cmake_policy(SET CMP0042 NEW)
|
||||
cmake_policy(SET CMP0046 NEW)
|
||||
include(GNUInstallDirs)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
|
||||
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
||||
endif()
|
||||
|
||||
set(LIBSOUNDIO_VERSION_MAJOR 2)
|
||||
set(LIBSOUNDIO_VERSION_MINOR 0)
|
||||
set(LIBSOUNDIO_VERSION_PATCH 0)
|
||||
set(LIBSOUNDIO_VERSION "${LIBSOUNDIO_VERSION_MAJOR}.${LIBSOUNDIO_VERSION_MINOR}.${LIBSOUNDIO_VERSION_PATCH}")
|
||||
message("Configuring libsoundio version ${LIBSOUNDIO_VERSION}")
|
||||
|
||||
if(NOT SOUNDIO_STATIC_LIBNAME)
|
||||
set(SOUNDIO_STATIC_LIBNAME soundio)
|
||||
endif()
|
||||
|
||||
option(BUILD_STATIC_LIBS "Build static libraries" ON)
|
||||
option(BUILD_DYNAMIC_LIBS "Build dynamic libraries" ON)
|
||||
option(BUILD_EXAMPLE_PROGRAMS "Build example programs" ON)
|
||||
option(BUILD_TESTS "Build tests" ON)
|
||||
option(ENABLE_JACK "Enable JACK backend" ON)
|
||||
option(ENABLE_PULSEAUDIO "Enable PulseAudio backend" ON)
|
||||
option(ENABLE_ALSA "Enable ALSA backend" ON)
|
||||
option(ENABLE_COREAUDIO "Enable CoreAudio backend" ON)
|
||||
option(ENABLE_WASAPI "Enable WASAPI backend" ON)
|
||||
|
||||
find_package(Threads)
|
||||
if(Threads_FOUND)
|
||||
set(STATUS_THREADS "OK")
|
||||
else(Threads_FOUND)
|
||||
set(STATUS_THREADS "not found")
|
||||
endif(Threads_FOUND)
|
||||
|
||||
if(ENABLE_JACK)
|
||||
find_package(JACK)
|
||||
if(JACK_FOUND)
|
||||
set(STATUS_JACK "OK")
|
||||
set(SOUNDIO_HAVE_JACK true)
|
||||
include_directories(${JACK_INCLUDE_DIR})
|
||||
else()
|
||||
set(STATUS_JACK "not found")
|
||||
set(SOUNDIO_HAVE_JACK false)
|
||||
set(JACK_LIBRARY "")
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_JACK "disabled")
|
||||
set(SOUNDIO_HAVE_JACK false)
|
||||
set(JACK_LIBRARY "")
|
||||
endif()
|
||||
|
||||
if(ENABLE_PULSEAUDIO)
|
||||
find_package(PulseAudio)
|
||||
if(PULSEAUDIO_FOUND)
|
||||
set(STATUS_PULSEAUDIO "OK")
|
||||
set(SOUNDIO_HAVE_PULSEAUDIO true)
|
||||
include_directories(${PULSEAUDIO_INCLUDE_DIR})
|
||||
else()
|
||||
set(STATUS_PULSEAUDIO "not found")
|
||||
set(SOUNDIO_HAVE_PULSEAUDIO false)
|
||||
set(PULSEAUDIO_LIBRARY "")
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_PULSEAUDIO "disabled")
|
||||
set(SOUNDIO_HAVE_PULSEAUDIO false)
|
||||
set(PULSEAUDIO_LIBRARY "")
|
||||
endif()
|
||||
|
||||
if(ENABLE_ALSA)
|
||||
find_package(ALSA)
|
||||
if(ALSA_FOUND)
|
||||
set(STATUS_ALSA "OK")
|
||||
set(SOUNDIO_HAVE_ALSA true)
|
||||
include_directories(${ALSA_INCLUDE_DIRS})
|
||||
else()
|
||||
set(STATUS_ALSA "not found")
|
||||
set(SOUNDIO_HAVE_ALSA false)
|
||||
set(ALSA_LIBRARIES "")
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_ALSA "disabled")
|
||||
set(SOUNDIO_HAVE_ALSA false)
|
||||
set(ALSA_LIBRARIES "")
|
||||
endif()
|
||||
|
||||
if(ENABLE_COREAUDIO)
|
||||
find_package(CoreAudio)
|
||||
if(COREAUDIO_FOUND)
|
||||
set(STATUS_COREAUDIO "OK")
|
||||
set(SOUNDIO_HAVE_COREAUDIO true)
|
||||
include_directories(${COREAUDIO_INCLUDE_DIR})
|
||||
|
||||
find_path(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
|
||||
find_library(COREFOUNDATION_LIBRARY NAMES CoreFoundation)
|
||||
include_directories(${COREFOUNDATION_INCLUDE_DIR})
|
||||
|
||||
find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit.h)
|
||||
find_library(AUDIOUNIT_LIBRARY NAMES AudioUnit)
|
||||
include_directories(${AUDIOUNIT_INCLUDE_DIR})
|
||||
else()
|
||||
set(STATUS_COREAUDIO "not found")
|
||||
set(SOUNDIO_HAVE_COREAUDIO false)
|
||||
set(COREAUDIO_LIBRARY "")
|
||||
set(COREFOUNDATION_LIBRARY "")
|
||||
set(AUDIOUNIT_LIBRARY "")
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_COREAUDIO "disabled")
|
||||
set(SOUNDIO_HAVE_COREAUDIO false)
|
||||
set(COREAUDIO_LIBRARY "")
|
||||
set(COREFOUNDATION_LIBRARY "")
|
||||
set(AUDIOUNIT_LIBRARY "")
|
||||
endif()
|
||||
|
||||
if(ENABLE_WASAPI)
|
||||
find_package(WASAPI)
|
||||
if(WASAPI_FOUND)
|
||||
set(STATUS_WASAPI "OK")
|
||||
set(SOUNDIO_HAVE_WASAPI true)
|
||||
else()
|
||||
set(STATUS_WASAPI "not found")
|
||||
set(SOUNDIO_HAVE_WASAPI false)
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_WASAPI "disabled")
|
||||
set(SOUNDIO_HAVE_WASAPI false)
|
||||
endif()
|
||||
|
||||
|
||||
set(LIBSOUNDIO_SOURCES
|
||||
"${libsoundio_SOURCE_DIR}/src/soundio.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/util.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/os.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/dummy.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/channel_layout.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/ring_buffer.c"
|
||||
)
|
||||
|
||||
set(CONFIGURE_OUT_FILE "${libsoundio_BINARY_DIR}/config.h")
|
||||
set(LIBSOUNDIO_HEADERS
|
||||
"${libsoundio_SOURCE_DIR}/soundio/soundio.h"
|
||||
"${libsoundio_SOURCE_DIR}/soundio/endian.h"
|
||||
)
|
||||
|
||||
if(SOUNDIO_HAVE_JACK)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/jack.c"
|
||||
)
|
||||
endif()
|
||||
if(SOUNDIO_HAVE_PULSEAUDIO)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/pulseaudio.c"
|
||||
)
|
||||
endif()
|
||||
if(SOUNDIO_HAVE_ALSA)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/alsa.c"
|
||||
)
|
||||
endif()
|
||||
if(SOUNDIO_HAVE_COREAUDIO)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/coreaudio.c"
|
||||
)
|
||||
endif()
|
||||
if(SOUNDIO_HAVE_WASAPI)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/wasapi.c"
|
||||
)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${libsoundio_SOURCE_DIR}
|
||||
${libsoundio_BINARY_DIR}
|
||||
"${libsoundio_SOURCE_DIR}/test"
|
||||
"${libsoundio_SOURCE_DIR}/src"
|
||||
)
|
||||
|
||||
set(LIBSOUNDIO_LIBS
|
||||
${JACK_LIBRARY}
|
||||
${PULSEAUDIO_LIBRARY}
|
||||
${ALSA_LIBRARIES}
|
||||
${COREAUDIO_LIBRARY}
|
||||
${COREFOUNDATION_LIBRARY}
|
||||
${AUDIOUNIT_LIBRARY}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Wall")
|
||||
set(LIB_CFLAGS "/TP /W4")
|
||||
set(EXAMPLE_CFLAGS "/W4")
|
||||
set(TEST_CFLAGS "${LIB_CFLAGS}")
|
||||
set(TEST_LDFLAGS " ")
|
||||
set(LIBM " ")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror -pedantic")
|
||||
set(LIB_CFLAGS "-std=c11 -fvisibility=hidden -Wall -Werror=strict-prototypes -Werror=old-style-definition -Werror=missing-prototypes -D_REENTRANT -D_POSIX_C_SOURCE=200809L -Wno-missing-braces")
|
||||
set(EXAMPLE_CFLAGS "-std=c99 -Wall")
|
||||
set(TEST_CFLAGS "${LIB_CFLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(TEST_LDFLAGS "-fprofile-arcs -ftest-coverage")
|
||||
set(LIBM "m")
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
"${libsoundio_SOURCE_DIR}/src/config.h.in"
|
||||
${CONFIGURE_OUT_FILE}
|
||||
)
|
||||
set(DOXYGEN_CONF_FILE "${libsoundio_BINARY_DIR}/doxygen.conf")
|
||||
configure_file(
|
||||
"${libsoundio_SOURCE_DIR}/doc/doxygen.conf.in"
|
||||
${DOXYGEN_CONF_FILE}
|
||||
)
|
||||
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
add_library(libsoundio_shared SHARED ${LIBSOUNDIO_SOURCES})
|
||||
set_target_properties(libsoundio_shared PROPERTIES
|
||||
OUTPUT_NAME soundio
|
||||
SOVERSION ${LIBSOUNDIO_VERSION_MAJOR}
|
||||
VERSION ${LIBSOUNDIO_VERSION}
|
||||
COMPILE_FLAGS ${LIB_CFLAGS}
|
||||
LINKER_LANGUAGE C
|
||||
)
|
||||
target_link_libraries(libsoundio_shared LINK_PUBLIC ${LIBSOUNDIO_LIBS})
|
||||
install(TARGETS libsoundio_shared DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
if(BUILD_STATIC_LIBS)
|
||||
add_library(libsoundio_static STATIC ${LIBSOUNDIO_SOURCES})
|
||||
set_target_properties(libsoundio_static PROPERTIES
|
||||
OUTPUT_NAME ${SOUNDIO_STATIC_LIBNAME}
|
||||
COMPILE_FLAGS ${LIB_CFLAGS}
|
||||
LINKER_LANGUAGE C
|
||||
)
|
||||
install(TARGETS libsoundio_static DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
install(FILES
|
||||
${LIBSOUNDIO_HEADERS}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/soundio")
|
||||
|
||||
# Example Programs
|
||||
|
||||
if(BUILD_EXAMPLE_PROGRAMS)
|
||||
add_executable(sio_sine example/sio_sine.c)
|
||||
set_target_properties(sio_sine PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(sio_sine libsoundio_shared ${LIBM})
|
||||
else()
|
||||
target_link_libraries(sio_sine libsoundio_static ${LIBSOUNDIO_LIBS} ${LIBM})
|
||||
endif()
|
||||
install(TARGETS sio_sine DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
add_executable(sio_list_devices example/sio_list_devices.c)
|
||||
set_target_properties(sio_list_devices PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(sio_list_devices libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(sio_list_devices libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
install(TARGETS sio_list_devices DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
add_executable(sio_microphone example/sio_microphone.c)
|
||||
set_target_properties(sio_microphone PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(sio_microphone libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(sio_microphone libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
install(TARGETS sio_microphone DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
add_executable(sio_record example/sio_record.c)
|
||||
set_target_properties(sio_record PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(sio_record libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(sio_record libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
install(TARGETS sio_record DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTS)
|
||||
add_executable(unit_tests "${libsoundio_SOURCE_DIR}/test/unit_tests.c" ${LIBSOUNDIO_SOURCES})
|
||||
target_link_libraries(unit_tests LINK_PUBLIC ${LIBSOUNDIO_LIBS})
|
||||
set_target_properties(unit_tests PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${TEST_CFLAGS}
|
||||
LINK_FLAGS ${TEST_LDFLAGS}
|
||||
)
|
||||
|
||||
add_executable(latency "${libsoundio_SOURCE_DIR}/test/latency.c" ${LIBSOUNDIO_SOURCES})
|
||||
target_link_libraries(latency LINK_PUBLIC ${LIBSOUNDIO_LIBS} ${LIBM})
|
||||
set_target_properties(latency PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${LIB_CFLAGS}
|
||||
)
|
||||
|
||||
add_executable(underflow test/underflow.c)
|
||||
set_target_properties(underflow PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(underflow libsoundio_shared ${LIBM})
|
||||
else()
|
||||
target_link_libraries(underflow libsoundio_static ${LIBSOUNDIO_LIBS} ${LIBM})
|
||||
endif()
|
||||
|
||||
add_executable(backend_disconnect_recover test/backend_disconnect_recover.c)
|
||||
set_target_properties(backend_disconnect_recover PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(backend_disconnect_recover libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(backend_disconnect_recover libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
|
||||
add_executable(overflow test/overflow.c)
|
||||
set_target_properties(overflow PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(overflow libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(overflow libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
add_custom_target(coverage
|
||||
DEPENDS unit_tests
|
||||
WORKING_DIRECTORY ${libsoundio_BINARY_DIR}
|
||||
COMMAND lcov --directory . --zerocounters --rc lcov_branch_coverage=1
|
||||
COMMAND ./unit_tests
|
||||
COMMAND lcov --directory . --capture --output-file coverage.info --rc lcov_branch_coverage=1
|
||||
COMMAND lcov --remove coverage.info '/usr/*' --output-file coverage.info.cleaned --rc lcov_branch_coverage=1
|
||||
COMMAND genhtml -o coverage coverage.info.cleaned --rc lcov_branch_coverage=1
|
||||
COMMAND rm coverage.info coverage.info.cleaned
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
add_custom_target(doc
|
||||
WORKING_DIRECTORY ${libsoundio_BINARY_DIR}
|
||||
COMMAND doxygen ${DOXYGEN_CONF_FILE}
|
||||
)
|
||||
|
||||
|
||||
|
||||
message("\n"
|
||||
"Installation Summary\n"
|
||||
"--------------------\n"
|
||||
"* Install Directory : ${CMAKE_INSTALL_PREFIX}\n"
|
||||
"* Build Type : ${CMAKE_BUILD_TYPE}\n"
|
||||
"* Build static libs : ${BUILD_STATIC_LIBS}\n"
|
||||
"* Build examples : ${BUILD_EXAMPLE_PROGRAMS}\n"
|
||||
"* Build tests : ${BUILD_TESTS}\n"
|
||||
)
|
||||
|
||||
message(
|
||||
"System Dependencies\n"
|
||||
"-------------------\n"
|
||||
"* threads : ${STATUS_THREADS}\n"
|
||||
"* JACK (optional) : ${STATUS_JACK}\n"
|
||||
"* PulseAudio (optional) : ${STATUS_PULSEAUDIO}\n"
|
||||
"* ALSA (optional) : ${STATUS_ALSA}\n"
|
||||
"* CoreAudio (optional) : ${STATUS_COREAUDIO}\n"
|
||||
"* WASAPI (optional) : ${STATUS_WASAPI}\n"
|
||||
)
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
The MIT License (Expat)
|
||||
|
||||
Copyright (c) 2015 Andrew Kelley
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
Vendored
-266
@@ -1,266 +0,0 @@
|
||||
# libsoundio
|
||||
|
||||
C library providing cross-platform audio input and output. The API is
|
||||
suitable for real-time software such as digital audio workstations as well
|
||||
as consumer software such as music players.
|
||||
|
||||
This library is an abstraction; however in the delicate balance between
|
||||
performance and power, and API convenience, the scale is tipped closer to
|
||||
the former. Features that only exist in some sound backends are exposed.
|
||||
|
||||
## Features and Limitations
|
||||
|
||||
* Supported operating systems:
|
||||
- Windows 7+
|
||||
- MacOS 10.10+
|
||||
- Linux 3.7+
|
||||
* Supported backends:
|
||||
- [JACK](http://jackaudio.org/)
|
||||
- [PulseAudio](http://www.freedesktop.org/wiki/Software/PulseAudio/)
|
||||
- [ALSA](http://www.alsa-project.org/)
|
||||
- [CoreAudio](https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/CoreAudioOverview/Introduction/Introduction.html)
|
||||
- [WASAPI](https://msdn.microsoft.com/en-us/library/windows/desktop/dd371455%28v=vs.85%29.aspx)
|
||||
- Dummy (silence)
|
||||
* Exposes both raw devices and shared devices. Raw devices give you the best
|
||||
performance but prevent other applications from using them. Shared devices
|
||||
are default and usually provide sample rate conversion and format
|
||||
conversion.
|
||||
* Exposes both device id and friendly name. id you could save in a config file
|
||||
because it persists between devices becoming plugged and unplugged, while
|
||||
friendly name is suitable for exposing to users.
|
||||
* Supports optimal usage of each supported backend. The same API does the
|
||||
right thing whether the backend has a fixed buffer size, such as on JACK and
|
||||
CoreAudio, or whether it allows directly managing the buffer, such as on
|
||||
ALSA, PulseAudio, and WASAPI.
|
||||
* C library. Depends only on the respective backend API libraries and libc.
|
||||
Does *not* depend on libstdc++, and does *not* have exceptions, run-time type
|
||||
information, or [setjmp](http://latentcontent.net/2007/12/05/libpng-worst-api-ever/).
|
||||
* Errors are communicated via return codes, not logging to stdio.
|
||||
* Supports channel layouts (also known as channel maps), important for
|
||||
surround sound applications.
|
||||
* Ability to monitor devices and get an event when available devices change.
|
||||
* Ability to get an event when the backend is disconnected, for example when
|
||||
the JACK server or PulseAudio server shuts down.
|
||||
* Detects which input device is default and which output device is default.
|
||||
* Ability to connect to multiple backends at once. For example you could have
|
||||
an ALSA device open and a JACK device open at the same time.
|
||||
* Meticulously checks all return codes and memory allocations and uses
|
||||
meaningful error codes.
|
||||
* Exposes extra API that is only available on some backends. For example you
|
||||
can provide application name and stream names which is used by JACK and
|
||||
PulseAudio.
|
||||
|
||||
## Synopsis
|
||||
|
||||
Complete program to emit a sine wave over the default device using the best
|
||||
backend:
|
||||
|
||||
```c
|
||||
#include <soundio/soundio.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
static const float PI = 3.1415926535f;
|
||||
static float seconds_offset = 0.0f;
|
||||
static void write_callback(struct SoundIoOutStream *outstream,
|
||||
int frame_count_min, int frame_count_max)
|
||||
{
|
||||
const struct SoundIoChannelLayout *layout = &outstream->layout;
|
||||
float float_sample_rate = outstream->sample_rate;
|
||||
float seconds_per_frame = 1.0f / float_sample_rate;
|
||||
struct SoundIoChannelArea *areas;
|
||||
int frames_left = frame_count_max;
|
||||
int err;
|
||||
|
||||
while (frames_left > 0) {
|
||||
int frame_count = frames_left;
|
||||
|
||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
|
||||
fprintf(stderr, "%s\n", soundio_strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!frame_count)
|
||||
break;
|
||||
|
||||
float pitch = 440.0f;
|
||||
float radians_per_second = pitch * 2.0f * PI;
|
||||
for (int frame = 0; frame < frame_count; frame += 1) {
|
||||
float sample = sinf((seconds_offset + frame * seconds_per_frame) * radians_per_second);
|
||||
for (int channel = 0; channel < layout->channel_count; channel += 1) {
|
||||
float *ptr = (float*)(areas[channel].ptr + areas[channel].step * frame);
|
||||
*ptr = sample;
|
||||
}
|
||||
}
|
||||
seconds_offset = fmodf(seconds_offset +
|
||||
seconds_per_frame * frame_count, 1.0f);
|
||||
|
||||
if ((err = soundio_outstream_end_write(outstream))) {
|
||||
fprintf(stderr, "%s\n", soundio_strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
frames_left -= frame_count;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int err;
|
||||
struct SoundIo *soundio = soundio_create();
|
||||
if (!soundio) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((err = soundio_connect(soundio))) {
|
||||
fprintf(stderr, "error connecting: %s", soundio_strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
soundio_flush_events(soundio);
|
||||
|
||||
int default_out_device_index = soundio_default_output_device_index(soundio);
|
||||
if (default_out_device_index < 0) {
|
||||
fprintf(stderr, "no output device found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct SoundIoDevice *device = soundio_get_output_device(soundio, default_out_device_index);
|
||||
if (!device) {
|
||||
fprintf(stderr, "out of memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Output device: %s\n", device->name);
|
||||
|
||||
struct SoundIoOutStream *outstream = soundio_outstream_create(device);
|
||||
outstream->format = SoundIoFormatFloat32NE;
|
||||
outstream->write_callback = write_callback;
|
||||
|
||||
if ((err = soundio_outstream_open(outstream))) {
|
||||
fprintf(stderr, "unable to open device: %s", soundio_strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (outstream->layout_error)
|
||||
fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error));
|
||||
|
||||
if ((err = soundio_outstream_start(outstream))) {
|
||||
fprintf(stderr, "unable to start device: %s", soundio_strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
soundio_wait_events(soundio);
|
||||
|
||||
soundio_outstream_destroy(outstream);
|
||||
soundio_device_unref(device);
|
||||
soundio_destroy(soundio);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Backend Priority
|
||||
|
||||
When you use `soundio_connect`, libsoundio tries these backends in order.
|
||||
If unable to connect to that backend, due to the backend not being installed,
|
||||
or the server not running, or the platform is wrong, the next backend is tried.
|
||||
|
||||
0. JACK
|
||||
0. PulseAudio
|
||||
0. ALSA (Linux)
|
||||
0. CoreAudio (OSX)
|
||||
0. WASAPI (Windows)
|
||||
0. Dummy
|
||||
|
||||
If you don't like this order, you can use `soundio_connect_backend` to
|
||||
explicitly choose a backend to connect to. You can use `soundio_backend_count`
|
||||
and `soundio_get_backend` to get the list of available backends.
|
||||
|
||||
[API Documentation](http://libsound.io/doc)
|
||||
|
||||
### Building
|
||||
|
||||
Install the dependencies:
|
||||
|
||||
* cmake
|
||||
* ALSA library (optional)
|
||||
* libjack2 (optional)
|
||||
* libpulseaudio (optional)
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
### Building for Windows
|
||||
|
||||
You can build libsoundio with [mxe](http://mxe.cc/). Follow the
|
||||
[requirements](http://mxe.cc/#requirements) section to install the
|
||||
packages necessary on your system. Then somewhere on your file system:
|
||||
|
||||
```
|
||||
git clone https://github.com/mxe/mxe
|
||||
cd mxe
|
||||
make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' gcc
|
||||
```
|
||||
|
||||
Then in the libsoundio source directory (replace "/path/to/mxe" with the
|
||||
appropriate path):
|
||||
|
||||
```
|
||||
mkdir build-win32
|
||||
cd build-win32
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake
|
||||
make
|
||||
```
|
||||
|
||||
```
|
||||
mkdir build-win64
|
||||
cd build-win64
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/x86_64-w64-mingw32.static/share/cmake/mxe-conf.cmake
|
||||
make
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
For each backend, do the following:
|
||||
|
||||
0. Run the unit tests: `./unit_tests`. To see test coverage, install lcov, run
|
||||
`make coverage`, and then view `coverage/index.html` in a browser.
|
||||
0. Run the example `./sio_list_devices` and make sure it does not crash, and
|
||||
the output looks good. If valgrind is available, use it.
|
||||
0. Run `./sio_list_devices --watch` and make sure it detects when you plug and
|
||||
unplug a USB microphone.
|
||||
0. Run `./sio_sine` and make sure you hear a sine wave. For backends with raw
|
||||
devices, run `./sio_sine --device id --raw` (where 'id' is a device id you
|
||||
got from `sio_list_devices` and make sure you hear a sine wave.
|
||||
- Use 'p' to test pausing, 'u' to test unpausing, 'q' to test cleanup.
|
||||
- 'c' for clear buffer. Clear buffer should not pause the stream and it
|
||||
should also not cause an underflow.
|
||||
- Use 'P' to test pausing from the callback, and then 'u' to unpause.
|
||||
0. Run `./underflow` and read the testing instructions that it prints.
|
||||
0. Run `./sio_microphone` and ensure that it is both recording and playing
|
||||
back correctly. If possible use the `--in-device` and `--out-device`
|
||||
parameters to test a USB microphone in raw mode.
|
||||
0. Run `./backend_disconnect_recover` and read the testing instructions that
|
||||
it prints.
|
||||
0. Run `./latency` and make sure the printed beeps line up with the beeps that
|
||||
you hear.
|
||||
|
||||
### Building the Documentation
|
||||
|
||||
Ensure that [doxygen](http://www.stack.nl/~dimitri/doxygen/) is installed,
|
||||
then:
|
||||
|
||||
```
|
||||
make doc
|
||||
```
|
||||
|
||||
Then look at `html/index.html` in a browser.
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# COREAUDIO_FOUND
|
||||
# COREAUDIO_INCLUDE_DIR
|
||||
# COREAUDIO_LIBRARY
|
||||
|
||||
find_path(COREAUDIO_INCLUDE_DIR NAMES CoreAudio/CoreAudio.h)
|
||||
|
||||
find_library(COREAUDIO_LIBRARY NAMES CoreAudio)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(COREAUDIO DEFAULT_MSG COREAUDIO_LIBRARY COREAUDIO_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(COREAUDIO_INCLUDE_DIR COREAUDIO_LIBRARY)
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# JACK_FOUND
|
||||
# JACK_INCLUDE_DIR
|
||||
# JACK_LIBRARY
|
||||
|
||||
find_path(JACK_INCLUDE_DIR NAMES jack/jack.h)
|
||||
|
||||
find_library(JACK_LIBRARY NAMES jack)
|
||||
|
||||
include(CheckLibraryExists)
|
||||
check_library_exists(jack "jack_set_port_rename_callback" "${JACK_LIBRARY}" HAVE_jack_set_port_rename_callback)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(JACK DEFAULT_MSG JACK_LIBRARY JACK_INCLUDE_DIR HAVE_jack_set_port_rename_callback)
|
||||
|
||||
mark_as_advanced(JACK_INCLUDE_DIR JACK_LIBRARY)
|
||||
@@ -1,16 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# PULSEAUDIO_FOUND
|
||||
# PULSEAUDIO_INCLUDE_DIR
|
||||
# PULSEAUDIO_LIBRARY
|
||||
|
||||
find_path(PULSEAUDIO_INCLUDE_DIR NAMES pulse/pulseaudio.h)
|
||||
|
||||
find_library(PULSEAUDIO_LIBRARY NAMES pulse)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(PULSEAUDIO DEFAULT_MSG PULSEAUDIO_LIBRARY PULSEAUDIO_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(PULSEAUDIO_INCLUDE_DIR PULSEAUDIO_LIBRARY)
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# WASAPI_FOUND
|
||||
# AUDIOCLIENT_H
|
||||
|
||||
if(WIN32)
|
||||
include(CheckIncludeFile)
|
||||
check_include_file(audioclient.h AUDIOCLIENT_H)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(WASAPI DEFAULT_MSG AUDIOCLIENT_H)
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# SOUNDIO_FOUND
|
||||
# SOUNDIO_INCLUDE_DIR
|
||||
# SOUNDIO_LIBRARY
|
||||
|
||||
find_path(SOUNDIO_INCLUDE_DIR NAMES soundio/soundio.h)
|
||||
|
||||
find_library(SOUNDIO_LIBRARY NAMES soundio)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(SOUNDIO DEFAULT_MSG SOUNDIO_LIBRARY SOUNDIO_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(SOUNDIO_INCLUDE_DIR SOUNDIO_LIBRARY)
|
||||
Loaded 100 of 140 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user