mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df772f57e2 | ||
|
|
0d5817042e | ||
|
|
7bdad7703c | ||
|
|
087402290d | ||
|
|
9a0c340712 | ||
|
|
fd33c10712 | ||
|
|
9caaf0f538 | ||
|
|
476d893094 | ||
|
|
fff597075d | ||
|
|
793335d9b8 | ||
|
|
f609839894 | ||
|
|
f39188beb1 | ||
|
|
decb8342be | ||
|
|
609fb43726 | ||
|
|
c2991149fd | ||
|
|
99f5aba12e | ||
|
|
cbf4e266e1 |
No files matched your search
@@ -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
|
||||
+19
-17
@@ -148,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,9 +210,9 @@ enum CR_select : int32_t {
|
||||
CR1_field = (0xF << 24),
|
||||
};
|
||||
|
||||
enum CRx_bit : uint32_t {
|
||||
CR_SO = 28,
|
||||
CR_EQ = 29,
|
||||
enum CRx_bit : uint32_t {
|
||||
CR_SO = 28,
|
||||
CR_EQ = 29,
|
||||
CR_GT = 30,
|
||||
CR_LT = 31 };
|
||||
|
||||
@@ -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);
|
||||
|
||||
+278
-22
@@ -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;
|
||||
|
||||
@@ -847,7 +847,6 @@ 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;
|
||||
|
||||
@@ -71,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
|
||||
|
||||
+210
-393
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1397,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() {
|
||||
@@ -1616,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++;
|
||||
|
||||
@@ -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>
|
||||
@@ -499,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;
|
||||
|
||||
@@ -9,6 +9,7 @@ file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.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"
|
||||
|
||||
@@ -37,7 +37,6 @@ enum HWCompType : int {
|
||||
I2C_DEV = 61, /* I2C device */
|
||||
ADB_HOST = 70, /* ADB host */
|
||||
ADB_DEV = 71, /* ADB device */
|
||||
INT_CTRL = 80, /* interrupt controller */
|
||||
SND_SERVER = 100, /* host sound server */
|
||||
};
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ ViaCuda::ViaCuda() {
|
||||
this->via_regs[VIA_DIRB] = 0;
|
||||
this->via_regs[VIA_DIRA] = 0;
|
||||
this->via_regs[VIA_IER] = 0;
|
||||
this->via_regs[VIA_SR] = 0;
|
||||
this->via_regs[VIA_ACR] = 0;
|
||||
this->via_regs[VIA_PCR] = 0;
|
||||
this->via_regs[VIA_IFR] = 0;
|
||||
@@ -90,20 +89,6 @@ uint8_t ViaCuda::read(int reg) {
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A!");
|
||||
break;
|
||||
case VIA_T1CL:
|
||||
res = this->via_regs[VIA_T1CL];
|
||||
this->via_regs[VIA_IFR] &= ~IFR_T1;
|
||||
case VIA_T2CL:
|
||||
res = this->via_regs[VIA_T2CL];
|
||||
this->via_regs[VIA_IFR] &= ~IFR_T2;
|
||||
case VIA_SR:
|
||||
res = this->via_regs[VIA_SR];
|
||||
this->via_regs[VIA_IFR] &= ~IFR_SR;
|
||||
case VIA_IFR:
|
||||
res = this->via_regs[VIA_IFR];
|
||||
if (this->via_regs[VIA_IFR] & this->via_regs[VIA_IER])
|
||||
res |= 0x80;
|
||||
break;
|
||||
case VIA_IER:
|
||||
res |= 0x80; /* bit 7 always reads as "1" */
|
||||
}
|
||||
|
||||
@@ -72,20 +72,6 @@ enum {
|
||||
VIA_ANH = 0x0F, /* input/output register A, no handshake */
|
||||
};
|
||||
|
||||
/** IFR and IER register bits */
|
||||
enum {
|
||||
IER_SET = 0x80,
|
||||
IER_CLR = 0x00,
|
||||
|
||||
IFR_CA2 = 0x01,
|
||||
IFR_CA1 = 0x02,
|
||||
IFR_SR = 0x04,
|
||||
IFR_CB2 = 0x08,
|
||||
IFR_CB1 = 0x10,
|
||||
IFR_T2 = 0x20,
|
||||
IFR_T1 = 0x40,
|
||||
};
|
||||
|
||||
/** Cuda communication signals. */
|
||||
enum {
|
||||
CUDA_TIP = 0x20, /* transaction in progress: 0 - true, 1 - false */
|
||||
|
||||
@@ -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
|
||||
+54
-94
@@ -28,10 +28,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#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>
|
||||
@@ -50,107 +53,44 @@ 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) {
|
||||
if ((type == HWCompType::MMIO_DEV)
|
||||
|| (type == HWCompType::INT_CTRL)) {
|
||||
if (type == HWCompType::MMIO_DEV) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Interrupt Register
|
||||
void AMIC::process_interrupt(uint32_t cookie) {
|
||||
bool confirm_interrupt = false;
|
||||
uint32_t bit_field = 0;
|
||||
|
||||
if (this->int_ctrl_reg & 0x40) {
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
switch (cookie) {
|
||||
case DEV_ID::VIA_CUDA:
|
||||
if (this->viacuda->read(VIA_IFR)) {
|
||||
bit_field = (1 << VIA1_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
else if (via2_slot_int_enable || via2_int_enable) {
|
||||
bit_field = (1 << VIA2_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
break;
|
||||
case DEV_ID::SCC_B:
|
||||
case DEV_ID::SCC_A:
|
||||
bit_field = (1 << SCC_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
break;
|
||||
case DEV_ID::ETHERNET:
|
||||
bit_field = (1 << Eth_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
break;
|
||||
case DEV_ID::Swim3_DMA:
|
||||
case DEV_ID::ETHERNET_DMA_OUT:
|
||||
case DEV_ID::ETHERNET_DMA_IN:
|
||||
case DEV_ID::SCC_A_DMA_OUT:
|
||||
case DEV_ID::SCC_A_DMA_IN:
|
||||
case DEV_ID::SCC_B_DMA_OUT:
|
||||
case DEV_ID::SCC_B_DMA_IN:
|
||||
if (dma_int_reg0) {
|
||||
bit_field = (1 << DMA_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
break;
|
||||
case DEV_ID::SOUND_DMA_OUT:
|
||||
case DEV_ID::SOUND_DMA_IN:
|
||||
if (dma_int_reg1) {
|
||||
bit_field = (1 << DMA_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
}
|
||||
break;
|
||||
case DEV_ID::NMI:
|
||||
bit_field = (1 << NMI_Interrupt);
|
||||
confirm_interrupt = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (confirm_interrupt)
|
||||
ack_interrupt(bit_field);
|
||||
}
|
||||
|
||||
uint32_t AMIC::ack_interrupt(uint32_t device_bits) {
|
||||
bool confirm_interrupt = false;
|
||||
bool ack_bit = this->int_ctrl_reg & 0x80;
|
||||
|
||||
if (device_bits & this->int_ctrl_reg)
|
||||
confirm_interrupt = true;
|
||||
|
||||
if (confirm_interrupt && ack_bit)
|
||||
ack_cpu_interrupt();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
uint32_t phase_val;
|
||||
|
||||
// subdevices registers
|
||||
switch(offset >> 12) {
|
||||
case 0: // VIA1 registers
|
||||
case 1:
|
||||
process_interrupt(VIA_CUDA);
|
||||
return this->viacuda->read(offset >> 9);
|
||||
case 4: // SCC registers
|
||||
this->escc->read_compat((offset >> 1) & 0xF);
|
||||
this->process_interrupt(SCC_A);
|
||||
return 0;
|
||||
case 0xA: // MACE registers
|
||||
return this->mace->read((offset >> 4) & 0xF);
|
||||
@@ -177,18 +117,20 @@ uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
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::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;
|
||||
case AMICReg::Int_Ctrl:
|
||||
if (this->int_ctrl_reg & 0x80) {
|
||||
ack_cpu_interrupt();
|
||||
}
|
||||
return this->int_ctrl_reg;
|
||||
default:
|
||||
LOG_F(WARNING, "Unknown AMIC register read, offset=%x", offset);
|
||||
}
|
||||
@@ -228,7 +170,6 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
((this->imm_snd_regs[1] & 0xF) << 8) | this->imm_snd_regs[2]
|
||||
);
|
||||
}
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
return;
|
||||
case AMICReg::Snd_Buf_Size_Hi:
|
||||
case AMICReg::Snd_Buf_Size_Lo:
|
||||
@@ -237,7 +178,6 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
((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);
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
return;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
|
||||
@@ -261,31 +201,52 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
return;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
this->snd_out_dma->write_dma_out_ctrl(value);
|
||||
this->dma_int_reg1 |= 0x2;
|
||||
this->process_interrupt(DEV_ID::SOUND_DMA_OUT);
|
||||
return;
|
||||
}
|
||||
case 0x16: // SWIM3 registers
|
||||
case 0x17:
|
||||
this->swim3->write((offset >> 9) & 0xF, value);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::VIA2_Slot_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Slot Interrupt Enable Register updated, val=%x", value);
|
||||
via2_slot_int_enable = value;
|
||||
break;
|
||||
case AMICReg::VIA2_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Interrupt Enable Register updated, val=%x", value);
|
||||
via2_int_enable = 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);
|
||||
if (value & 0x80) {
|
||||
value &= 0xC0;
|
||||
ack_cpu_interrupt();
|
||||
}
|
||||
this->int_ctrl_reg = value;
|
||||
break;
|
||||
case AMICReg::DMA_Base_Addr_0:
|
||||
case AMICReg::DMA_Base_Addr_1:
|
||||
@@ -295,7 +256,6 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
this->dma_base = (this->dma_base & ~mask) |
|
||||
((value & 0xFF) << (8 * (3 - (offset & 3))));
|
||||
LOG_F(9, "AMIC: DMA base address set to 0x%X", this->dma_base);
|
||||
this->process_interrupt(DEV_ID::PERCH_DMA);
|
||||
break;
|
||||
case AMICReg::Enet_DMA_Xmt_Ctrl:
|
||||
LOG_F(INFO, "AMIC Ethernet Transmit DMA Ctrl updated, val=%x", value);
|
||||
|
||||
+25
-38
@@ -28,9 +28,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/scsi/ncr53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/ioctrl/interruptctrl.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>
|
||||
@@ -95,20 +97,20 @@ enum AMICReg : uint32_t {
|
||||
Snd_Out_DMA = 0x14018, // sound output DMA status/control register
|
||||
|
||||
// VIA2 registers
|
||||
VIA2_Slot_INT = 0x26002,
|
||||
VIA2_Slot_IER = 0x26012,
|
||||
VIA2_INT = 0x26003,
|
||||
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,
|
||||
|
||||
// Interrupt registers
|
||||
Video_Mode = 0x28000,
|
||||
Pixel_Depth = 0x28001,
|
||||
Monitor_Id = 0x28002,
|
||||
|
||||
Int_Ctrl = 0x2A000,
|
||||
DMA_Int_0 = 0x2A008,
|
||||
Bus_Error_Int_0 = 0x2A009,
|
||||
DMA_Int_1 = 0x2A00A,
|
||||
Bus_Error_Int_1 = 0x2A00B,
|
||||
|
||||
// Undocumented diagnostics register
|
||||
Diag_Reg = 0x2C000,
|
||||
@@ -128,30 +130,13 @@ enum AMICReg : uint32_t {
|
||||
SCC_DMA_Rcv_B_Ctrl = 0x320B8,
|
||||
};
|
||||
|
||||
enum AMICIntReg : uint32_t {
|
||||
VIA1_Interrupt = 0,
|
||||
VIA2_Interrupt = 1,
|
||||
SCC_Interrupt = 2,
|
||||
Eth_Interrupt = 3,
|
||||
DMA_Interrupt = 4,
|
||||
NMI_Interrupt = 5,
|
||||
INT_Mode = 6,
|
||||
ACK_Bit = 7,
|
||||
};
|
||||
|
||||
enum {
|
||||
FDC_PENDING = 0x40,
|
||||
};
|
||||
|
||||
/** Apple Memory-mapped I/O controller device. */
|
||||
class AMIC : public MMIODevice, public InterruptCtrl {
|
||||
/** Apple Memory-mapped I/O controller device. */
|
||||
class AMIC : public MMIODevice {
|
||||
public:
|
||||
AMIC();
|
||||
~AMIC() = default;
|
||||
|
||||
bool supports_type(HWCompType type);
|
||||
void process_interrupt(uint32_t cookie);
|
||||
uint32_t ack_interrupt(uint32_t device_bits);
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
@@ -163,16 +148,11 @@ protected:
|
||||
private:
|
||||
uint8_t imm_snd_regs[4]; // temporary storage for sound control registers
|
||||
|
||||
uint32_t dma_base = 0; // DMA physical base address
|
||||
uint16_t snd_buf_size = 0; // sound buffer size in bytes
|
||||
uint8_t snd_out_ctrl = 0;
|
||||
uint32_t dma_base = 0; // DMA physical base address
|
||||
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
|
||||
uint8_t int_ctrl_reg = 0;
|
||||
uint8_t dma_int_reg0 = 0;
|
||||
uint8_t dma_int_reg1 = 0;
|
||||
uint8_t via2_int_enable = 0;
|
||||
uint8_t via2_slot_int_enable = 0;
|
||||
uint8_t scsi_dma_cs = 0; // SCSI DMA control/status register value
|
||||
|
||||
// AMIC subdevices instances
|
||||
std::unique_ptr<Ncr53C94> scsi;
|
||||
@@ -182,6 +162,13 @@ private:
|
||||
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
|
||||
+34
-78
@@ -22,8 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#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/ioctrl/interruptctrl.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <endianswap.h>
|
||||
@@ -57,40 +57,11 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
||||
std::bind(&AwacsScreamer::dma_end, this->screamer.get())
|
||||
);
|
||||
|
||||
this->mesh = std::unique_ptr<MESHController> (new MESHController(HeathrowMESHID));
|
||||
this->escc = std::unique_ptr<EsccController>(new EsccController());
|
||||
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());
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::register_device(DEV_ID dev_id){
|
||||
return (1 << dev_id);
|
||||
};
|
||||
|
||||
void HeathrowIC::process_interrupt(uint32_t cookie) {
|
||||
bool confirm_interrupt = false;
|
||||
uint32_t bit_field = 0;
|
||||
|
||||
switch (cookie) {
|
||||
case DEV_ID::SOUND_DMA_OUT:
|
||||
bit_field = (1 << DEV_ID::SOUND_DMA_OUT);
|
||||
break;
|
||||
case DEV_ID::SCSI0:
|
||||
bit_field = (1 << DEV_ID::SCSI0);
|
||||
break;
|
||||
case DEV_ID::VIA_CUDA:
|
||||
bit_field = (1 << DEV_ID::VIA_CUDA);
|
||||
break;
|
||||
case DEV_ID::SWIM3:
|
||||
bit_field = (1 << DEV_ID::SWIM3);
|
||||
break;
|
||||
case DEV_ID::DAVBUS:
|
||||
bit_field = (1 << DEV_ID::DAVBUS);
|
||||
break;
|
||||
}
|
||||
|
||||
if (confirm_interrupt)
|
||||
ack_interrupt(bit_field);
|
||||
};
|
||||
|
||||
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
return this->pci_cfg_hdr[reg_offs & 0xFF];
|
||||
}
|
||||
@@ -124,7 +95,6 @@ uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
|
||||
switch (offset >> 8) {
|
||||
case 8:
|
||||
res = this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
this->ack_interrupt(DEV_ID::SOUND_DMA_OUT);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
|
||||
@@ -168,6 +138,8 @@ uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
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);
|
||||
@@ -197,7 +169,6 @@ void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int
|
||||
break;
|
||||
case 0x10:
|
||||
this->mesh->write((offset >> 4) & 0xF, value);
|
||||
this->process_interrupt(DEV_ID::SCSI0);
|
||||
break;
|
||||
case 0x12: // ESCC compatible
|
||||
this->escc->write_compat((offset >> 4) & 0xF, value);
|
||||
@@ -207,12 +178,13 @@ void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int
|
||||
break;
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
break;
|
||||
case 0x15:
|
||||
this->swim3->write(offset & 0xF, value);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
this->viacuda->write((offset - 0x16000) >> 9, value);
|
||||
this->process_interrupt(DEV_ID::VIA_CUDA);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
@@ -227,37 +199,29 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset & 0xFC) {
|
||||
case 0x10:
|
||||
LOG_F(0, "read from MIO:Int_Events2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::events2);
|
||||
break;
|
||||
case 0x14:
|
||||
LOG_F(0, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::mask2);
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->int_mask2;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(0, "read from MIO:Int_Clear2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::clear2);
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
res = this->int_clear2;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(0, "read from MIO:Int_Levels2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::levels2);
|
||||
break;
|
||||
case 0x20:
|
||||
LOG_F(0, "read from MIO:Int_Events1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::events1);
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
res = this->int_levels2;
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(0, "read from MIO:Int_Mask1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::mask1);
|
||||
LOG_F(9, "read from MIO:Int_Mask1 register \n");
|
||||
res = this->int_mask1;
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(0, "read from MIO:Int_Clear1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::clear1);
|
||||
LOG_F(9, "read from MIO:Int_Clear1 register \n");
|
||||
res = this->int_clear1;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(0, "read from MIO:Int_Levels1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::levels1);
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
res = this->int_levels1;
|
||||
break;
|
||||
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
||||
LOG_F(9, "read from MIO:ID register at Address %x \n", ppc_state.pc);
|
||||
@@ -277,37 +241,29 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset & 0xFC) {
|
||||
case 0x10:
|
||||
LOG_F(0, "write %x to MIO:Int_Events2 register \n", value);
|
||||
this->update_reg(REG_ID::events2, value);
|
||||
break;
|
||||
case 0x14:
|
||||
LOG_F(0, "write %x to MIO:Int_Mask2 register \n", value);
|
||||
this->update_reg(REG_ID::mask2, value);
|
||||
LOG_F(9, "write %x to MIO:Int_Mask2 register \n", value);
|
||||
this->int_mask2 = value;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(0, "write %x to MIO:Int_Clear2 register \n", value);
|
||||
this->update_reg(REG_ID::clear2, value);
|
||||
LOG_F(9, "write %x to MIO:Int_Clear2 register \n", value);
|
||||
this->int_clear2 = value;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(0, "write %x to MIO:Int_Levels2 register \n", value);
|
||||
this->update_reg(REG_ID::levels2, value);
|
||||
break;
|
||||
case 0x20:
|
||||
LOG_F(0, "write %x to MIO:Int_Events1 register \n", value);
|
||||
this->update_reg(REG_ID::events1, value);
|
||||
LOG_F(9, "write %x to MIO:Int_Levels2 register \n", value);
|
||||
this->int_levels2 = value;
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(0, "write %x to MIO:Int_Mask1 register \n", value);
|
||||
this->update_reg(REG_ID::mask1, value);
|
||||
LOG_F(9, "write %x to MIO:Int_Mask1 register \n", value);
|
||||
this->int_mask1 = value;
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(0, "write %x to MIO:Int_Clear1 register \n", value);
|
||||
this->update_reg(REG_ID::clear1, value);
|
||||
LOG_F(9, "write %x to MIO:Int_Clear1 register \n", value);
|
||||
this->int_clear1 = value;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(0, "write %x to MIO:Int_Levels1 register \n", value);
|
||||
this->update_reg(REG_ID::levels1, value);
|
||||
LOG_F(9, "write %x to MIO:Int_Levels1 register \n", value);
|
||||
this->int_levels1 = value;
|
||||
break;
|
||||
case 0x34:
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x \n", value, offset, ppc_state.pc);
|
||||
@@ -327,7 +283,7 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
|
||||
void HeathrowIC::feature_control(const uint32_t value)
|
||||
{
|
||||
LOG_F(0, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
|
||||
this->feat_ctrl = value;
|
||||
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
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 <cpu/ppc/ppcemu.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
InterruptCtrl::InterruptCtrl() {
|
||||
}
|
||||
|
||||
void InterruptCtrl::update_reg(REG_ID retrieve_reg, uint32_t bit_setting) {
|
||||
switch (retrieve_reg) {
|
||||
case mask1:
|
||||
int_mask1 = bit_setting;
|
||||
break;
|
||||
case clear1:
|
||||
int_clear1 = bit_setting;
|
||||
int_events1 &= ~int_clear1;
|
||||
break;
|
||||
case events1:
|
||||
int_events1 = bit_setting;
|
||||
break;
|
||||
case levels1:
|
||||
int_levels1 = bit_setting;
|
||||
break;
|
||||
case mask2:
|
||||
int_mask2 = bit_setting;
|
||||
break;
|
||||
case clear2:
|
||||
int_clear2 = bit_setting;
|
||||
int_events2 &= ~int_clear2;
|
||||
break;
|
||||
case events2:
|
||||
int_events2 = bit_setting;
|
||||
break;
|
||||
case levels2:
|
||||
int_levels2 = bit_setting;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t InterruptCtrl::retrieve_reg(REG_ID retrieve_reg) {
|
||||
switch (retrieve_reg) {
|
||||
case mask1:
|
||||
return int_mask1;
|
||||
break;
|
||||
case clear1:
|
||||
return int_clear1;
|
||||
break;
|
||||
case events1:
|
||||
return int_events1;
|
||||
break;
|
||||
case levels1:
|
||||
return int_levels1;
|
||||
break;
|
||||
case mask2:
|
||||
return int_mask2;
|
||||
break;
|
||||
case clear2:
|
||||
return int_clear2;
|
||||
break;
|
||||
case events2:
|
||||
return int_events2;
|
||||
break;
|
||||
case levels2:
|
||||
return int_levels2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t InterruptCtrl::ack_interrupt(uint32_t device_bits) {
|
||||
bool confirm_interrupt = false;
|
||||
|
||||
int_events1 |= device_bits;
|
||||
if (int_events1 & int_mask1)
|
||||
confirm_interrupt = true;
|
||||
|
||||
if (confirm_interrupt)
|
||||
ack_cpu_interrupt();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InterruptCtrl::ack_cpu_interrupt() {
|
||||
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0x0);
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
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 HWINTERRUPT_H
|
||||
#define HWINTERRUPT_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
enum DEV_ID {
|
||||
SCSI_DMA = 0,
|
||||
Swim3_DMA = 1,
|
||||
IDE0_DMA = 2,
|
||||
IDE1_DMA = 3,
|
||||
SCC_A_DMA_OUT = 4,
|
||||
SCC_A_DMA_IN = 5,
|
||||
SCC_B_DMA_OUT = 6,
|
||||
SCC_B_DMA_IN = 7,
|
||||
SOUND_DMA_OUT = 8,
|
||||
SOUND_DMA_IN = 9,
|
||||
VIDEO_OUT = 10,
|
||||
VIDEO_IN = 11,
|
||||
SCSI0 = 12,
|
||||
IDE0 = 13,
|
||||
IDE1 = 14,
|
||||
SCC_A = 15,
|
||||
SCC_B = 16,
|
||||
DAVBUS = 17,
|
||||
VIA_CUDA = 18,
|
||||
SWIM3 = 19,
|
||||
NMI = 20,
|
||||
PERCH_DMA = 21,
|
||||
PERCH = 22,
|
||||
ETHERNET_DMA_OUT = 23,
|
||||
ETHERNET_DMA_IN = 24,
|
||||
ETHERNET = 25,
|
||||
SCSI1 = 26,
|
||||
};
|
||||
|
||||
enum REG_ID {
|
||||
mask1 = 0,
|
||||
clear1 = 1,
|
||||
events1 = 2,
|
||||
levels1 = 3,
|
||||
mask2 = 4,
|
||||
clear2 = 5,
|
||||
events2 = 6,
|
||||
levels2 = 7,
|
||||
};
|
||||
|
||||
class InterruptCtrl {
|
||||
public:
|
||||
InterruptCtrl();
|
||||
~InterruptCtrl() = default;
|
||||
|
||||
uint32_t ack_interrupt(uint32_t device_bits);
|
||||
|
||||
virtual uint32_t register_device(DEV_ID dev_id){
|
||||
return 0;
|
||||
};
|
||||
|
||||
void update_reg(REG_ID retrieve_reg, uint32_t bit_setting);
|
||||
uint32_t retrieve_reg(REG_ID retrieve_reg);
|
||||
|
||||
void ack_cpu_interrupt();
|
||||
|
||||
protected:
|
||||
uint32_t int_events1 = 0;
|
||||
uint32_t int_mask1 = 0;
|
||||
uint32_t int_clear1 = 0;
|
||||
uint32_t int_levels1 = 0;
|
||||
uint32_t int_events2 = 0;
|
||||
uint32_t int_mask2 = 0;
|
||||
uint32_t int_clear2 = 0;
|
||||
uint32_t int_levels2 = 0;
|
||||
};
|
||||
|
||||
#endif /* HWINTERRUPT_H */
|
||||
+16
-14
@@ -59,7 +59,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
@@ -93,15 +93,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
VIA-CUDA register space: 0x00016000, size: 0x00002000
|
||||
*/
|
||||
|
||||
class HeathrowIC : public PCIDevice,
|
||||
public InterruptCtrl {
|
||||
|
||||
class HeathrowIC : public PCIDevice {
|
||||
public:
|
||||
HeathrowIC();
|
||||
~HeathrowIC() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return (type == HWCompType::MMIO_DEV) || (type == HWCompType::INT_CTRL);
|
||||
return type == HWCompType::MMIO_DEV;
|
||||
};
|
||||
|
||||
/* PCI device methods */
|
||||
@@ -116,9 +114,6 @@ 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);
|
||||
|
||||
uint32_t register_device(DEV_ID dev_id);
|
||||
void process_interrupt(uint32_t cookie);
|
||||
|
||||
protected:
|
||||
uint32_t dma_read(uint32_t offset, int size);
|
||||
void dma_write(uint32_t offset, uint32_t value, int size);
|
||||
@@ -148,17 +143,24 @@ private:
|
||||
0x00,
|
||||
0x00 // unknown defaults
|
||||
};
|
||||
|
||||
|
||||
uint32_t int_mask2 = 0;
|
||||
uint32_t int_clear2 = 0;
|
||||
uint32_t int_levels2 = 0;
|
||||
uint32_t int_mask1 = 0;
|
||||
uint32_t int_clear1 = 0;
|
||||
uint32_t int_levels1 = 0;
|
||||
uint32_t macio_id = 0xF0700008UL;
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
|
||||
/* device cells */
|
||||
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<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
|
||||
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -37,6 +37,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#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();
|
||||
@@ -48,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
|
||||
+72
-71
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
/* Mach64 post dividers. */
|
||||
static const int mach64_post_div[8] = {
|
||||
@@ -94,7 +95,7 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
|
||||
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 */
|
||||
@@ -116,20 +117,11 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
|
||||
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(Disp_Id_Kind::DDC2B);
|
||||
}
|
||||
|
||||
ATIRage::~ATIRage()
|
||||
{
|
||||
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) {
|
||||
@@ -144,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;
|
||||
}
|
||||
}
|
||||
@@ -173,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:
|
||||
@@ -240,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(
|
||||
@@ -265,16 +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)) {
|
||||
int32_t src_offset = (READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
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->block_io_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
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->fb_ptr = &this->vram_ptr[src_offset];
|
||||
this->update_screen();
|
||||
}
|
||||
}
|
||||
@@ -401,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 */
|
||||
@@ -433,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 */
|
||||
@@ -464,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);
|
||||
@@ -490,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]);
|
||||
@@ -521,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);
|
||||
@@ -548,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];
|
||||
|
||||
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/video/videoctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/* PCI related definitions. */
|
||||
enum {
|
||||
@@ -196,7 +197,7 @@ constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
|
||||
class ATIRage : public PCIDevice, public VideoCtrlBase {
|
||||
public:
|
||||
ATIRage(uint16_t dev_id, uint32_t vmem_size_mb);
|
||||
~ATIRage();
|
||||
~ATIRage() = default;
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
@@ -229,19 +230,19 @@ protected:
|
||||
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
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
|
||||
|
||||
/* 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;
|
||||
|
||||
int comp_index; /* color component index for DAC palette access */
|
||||
};
|
||||
|
||||
+75
-52
@@ -23,86 +23,109 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/video/displayid.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
DisplayID::DisplayID(Disp_Id_Kind id_kind)
|
||||
#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()
|
||||
{
|
||||
this->id_kind = id_kind;
|
||||
// assume a DDC monitor is connected by default
|
||||
this->id_kind = Disp_Id_Kind::DDC2B;
|
||||
|
||||
/* Initialize Apple monitor codes */
|
||||
this->std_sense_code = 6;
|
||||
this->ext_sense_code = 0x2B;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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: Monitor sense lines tristated!");
|
||||
}
|
||||
|
||||
switch(this->id_kind) {
|
||||
case Disp_Id_Kind::DDC2B:
|
||||
/* if GPIO pins are in the output mode, pick up their values
|
||||
/* 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);
|
||||
case Disp_Id_Kind::AppleSense:
|
||||
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;
|
||||
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)
|
||||
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;
|
||||
|
||||
|
||||
@@ -55,14 +55,14 @@ enum I2CState : uint8_t {
|
||||
|
||||
class DisplayID {
|
||||
public:
|
||||
DisplayID(Disp_Id_Kind id_kind);
|
||||
DisplayID();
|
||||
~DisplayID() = default;
|
||||
|
||||
uint16_t read_monitor_sense(uint16_t data, uint16_t dirs);
|
||||
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:
|
||||
Disp_Id_Kind id_kind;
|
||||
@@ -75,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
|
||||
@@ -28,17 +28,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
|
||||
VideoCtrlBase::VideoCtrlBase()
|
||||
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,
|
||||
640,
|
||||
480,
|
||||
this->active_width,
|
||||
this->active_height,
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
|
||||
@@ -98,9 +101,8 @@ void VideoCtrlBase::update_screen()
|
||||
|
||||
SDL_LockTexture(this->disp_texture, NULL, (void **)&dst_buf, &dst_pitch);
|
||||
|
||||
// call texture update method (hardcoded for now)
|
||||
// TODO: convert it to a callback
|
||||
this->convert_frame_8bpp(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);
|
||||
@@ -121,6 +123,11 @@ void VideoCtrlBase::update_screen()
|
||||
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;
|
||||
|
||||
@@ -27,15 +27,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <SDL.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
class VideoCtrlBase {
|
||||
public:
|
||||
VideoCtrlBase();
|
||||
VideoCtrlBase(int width = 640, int height = 480);
|
||||
~VideoCtrlBase();
|
||||
|
||||
void update_screen(void);
|
||||
|
||||
void convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch);
|
||||
// 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 */
|
||||
@@ -51,6 +54,8 @@ protected:
|
||||
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;
|
||||
|
||||
@@ -76,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 = {
|
||||
@@ -83,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 = {
|
||||
@@ -90,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 = {
|
||||
@@ -205,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;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#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>
|
||||
@@ -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;
|
||||
|
||||
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#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>
|
||||
@@ -86,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,61 +0,0 @@
|
||||
/*
|
||||
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 <machines/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;
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,12 @@ 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 <endianswap.h>
|
||||
#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
|
||||
@@ -37,8 +32,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define ILLEGAL_DEVICE_VALUE 0x168A523B
|
||||
|
||||
/** Property types. */
|
||||
enum PropType : int {
|
||||
PROP_TYPE_UNKNOWN = 0,
|
||||
@@ -66,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;
|
||||
}
|
||||
|
||||
@@ -88,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. */
|
||||
@@ -131,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;
|
||||
|
||||
@@ -28,7 +28,7 @@ as found in various PowerMacintosh models.
|
||||
|
||||
### Old World Macs
|
||||
|
||||
| ROM dump/Machine | BootROM codename | OF version | OF image offset |
|
||||
| ROM dump/Machine | BootROM codename | OF version | OF image offset |
|
||||
|:------------------------------------:|:----------------:|:-------------:|:---------------:|
|
||||
| Power Macintosh 7300/7600/8600/9600 | TNT | 1.0.5 | 0x330000 |
|
||||
| Bandai Pippin | Pip | 1.0.5 | 0x330000 |
|
||||
@@ -130,9 +130,9 @@ Apple's OpenFirmware contains a small kernel implemented in the native PowerPC c
|
||||
1. In response to power coming on, HWInit code in the Power Macintosh ROM performs initialization of the memory controller and the basic I/O facilities as well as some self-testing. After that, the startup chime is played.
|
||||
2. HWInit passes control to OpenFirmware kernel that prepares OF execution from RAM. OF builds the **device tree** - a platform-independent description of the attached HW.
|
||||
3. OF returns control to HWInit that initializes several low-level data structures required by the Nanokernel.
|
||||
4. HWInit passes control to the Nanokernel that initializes the low-level virtual machine and the 68k emulator.
|
||||
4. HWInit passes control to the Nanokernel that initializes the native execution enviroment and the 68k emulator.
|
||||
5. 68k emulator executes the start-up code in the Macintosh ROM that initializes various managers.
|
||||
6. The device tree generated by the OpenFirmware in step 2 is imported by the Expansion Bus Manager initialization and stored in the **NameRegistry**.
|
||||
6. The device tree generated by the OpenFirmware in step 2 is imported by the Expansion Bus Manager initialization code and stored in the **NameRegistry**.
|
||||
7. An operating system is located and loaded.
|
||||
|
||||
### New World Macs
|
||||
|
||||
Reference in new issue
Block a user