mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
116
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd6cc0f388 | ||
|
|
9291a093d5 | ||
|
|
3db6d07060 | ||
|
|
7fbbde0750 | ||
|
|
87054deb3d | ||
|
|
49a5951647 | ||
|
|
84ded9fc7a | ||
|
|
a01cd9c993 | ||
|
|
fc44cdcc83 | ||
|
|
958d3ee96a | ||
|
|
c2a63bab09 | ||
|
|
392fa87ba4 | ||
|
|
87b8e1759a | ||
|
|
cb946e41b5 | ||
|
|
3f20d0a700 | ||
|
|
767735251b | ||
|
|
6a756df5e3 | ||
|
|
281aaa1902 | ||
|
|
c7f21040ae | ||
|
|
a28ef677fd | ||
|
|
d70adac564 | ||
|
|
c0cd6eb38f | ||
|
|
9329d56d83 | ||
|
|
7919cd0590 | ||
|
|
fb277945c2 | ||
|
|
7daf4aa317 | ||
|
|
f194887d34 | ||
|
|
46549d68a2 | ||
|
|
331b93d4d6 | ||
|
|
3c7fc58ac0 | ||
|
|
c7544d9c2f | ||
|
|
00dd99d851 | ||
|
|
7d7a4b453f | ||
|
|
7ce94a6ab5 | ||
|
|
061b061813 | ||
|
|
9251745d6f | ||
|
|
2f725fe3e4 | ||
|
|
e53296f7a9 | ||
|
|
7c47b9c1e7 | ||
|
|
e66979d30f | ||
|
|
9caef55c19 | ||
|
|
2a9d364b1b | ||
|
|
3eb2d3cba7 | ||
|
|
bde5b71167 | ||
|
|
89e79d05cb | ||
|
|
bb0ca2ac40 | ||
|
|
5672a154cb | ||
|
|
2d65ed47fc | ||
|
|
e344b089b3 | ||
|
|
d5960ca70b | ||
|
|
2106c4ca47 | ||
|
|
ad6a2a9f17 | ||
|
|
1922a20cdd | ||
|
|
f605c484dd | ||
|
|
69c357b70f | ||
|
|
c313a9c8bb | ||
|
|
03e58dac35 | ||
|
|
983e278498 | ||
|
|
3ca7a78a37 | ||
|
|
0f55877137 | ||
|
|
b4d399ffa2 | ||
|
|
8c9f23daf4 | ||
|
|
22827642e4 | ||
|
|
e9fcc51b93 | ||
|
|
f104a634ea | ||
|
|
81ea96a058 | ||
|
|
e052eb4a87 | ||
|
|
d2cd43fcb1 | ||
|
|
4b16cb826e | ||
|
|
40d0aa70da | ||
|
|
212cd58f40 | ||
|
|
5b54cd69ef | ||
|
|
501f24f0d3 | ||
|
|
2a79c9a63c | ||
|
|
f0b03aa1a2 | ||
|
|
de8d6487f9 | ||
|
|
ed56d018b0 | ||
|
|
8c13c30162 | ||
|
|
84e111290f | ||
|
|
1c77057860 | ||
|
|
738e2d3bd1 | ||
|
|
ea5b0d9f52 | ||
|
|
16d9e6c681 | ||
|
|
9ce15be106 | ||
|
|
e3a4539b02 | ||
|
|
c5f45c6f9a | ||
|
|
a8f400287a | ||
|
|
089645e830 | ||
|
|
6d80ead5b1 | ||
|
|
29dcd11648 | ||
|
|
62070659f8 | ||
|
|
87ccfaed53 | ||
|
|
4f3dd797be | ||
|
|
22a15f4780 | ||
|
|
48a65279e1 | ||
|
|
6abe86589b | ||
|
|
07a4166eef | ||
|
|
094d9a9c2f | ||
|
|
4da95a66d7 | ||
|
|
592d32017e | ||
|
|
7d8f4d4e61 | ||
|
|
a5ddb51a3b | ||
|
|
05330bc942 | ||
|
|
6f9ee10de5 | ||
|
|
0c1c59ffa7 | ||
|
|
048b4f5f20 | ||
|
|
085877a8bf | ||
|
|
bc59bf7c43 | ||
|
|
ed6c316c82 | ||
|
|
31b5290ac9 | ||
|
|
0375b6a687 | ||
|
|
d545780071 | ||
|
|
0cc1ac5731 | ||
|
|
68b8da2182 | ||
|
|
18a19cd52f | ||
|
|
282940e580 |
No files matched your search
+17
-6
@@ -11,6 +11,8 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
if (NOT WIN32)
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
else()
|
||||
include_directories("${PROJECT_SOURCE_DIR}/thirdparty/SDL2/include/")
|
||||
if (UNIX AND NOT APPLE)
|
||||
find_package (Threads)
|
||||
endif()
|
||||
@@ -19,9 +21,9 @@ endif()
|
||||
option(DPPC_BUILD_PPC_TESTS "Build PowerPC tests" OFF)
|
||||
option(DPPC_BUILD_BENCHMARKS "Build benchmarking programs" OFF)
|
||||
|
||||
option(ENABLE_68K_DEBUGGER "Enable 68k debugging" OFF)
|
||||
option(DPPC_68K_DEBUGGER "Enable 68k debugging" OFF)
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
# Build capstone as static library.
|
||||
set(CAPSTONE_BUILD_STATIC ON CACHE BOOL "")
|
||||
|
||||
@@ -59,6 +61,7 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/debugger/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/devices/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/execution")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/machines/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/utils/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
#set(BUILD_EXAMPLE_PROGRAMS OFF CACHE BOOL "Build libsoundio example programs")
|
||||
@@ -76,10 +79,14 @@ add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
|
||||
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/devices"
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/devices"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc"
|
||||
"${PROJECT_SOURCE_DIR}/debugger"
|
||||
"${PROJECT_SOURCE_DIR}/utils"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/CLI11/"
|
||||
# ${SDL2_INCLUDE_DIRS})
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
|
||||
# "${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
|
||||
# ${LIBSOUNDIO_HEADERS})
|
||||
@@ -98,6 +105,7 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
@@ -110,7 +118,7 @@ target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE
|
||||
target_include_directories(dingusppc PRIVATE ${CLI11_ROOT})
|
||||
endif()
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc capstone-static)
|
||||
endif()
|
||||
|
||||
@@ -120,6 +128,7 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
@@ -133,7 +142,7 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(testppc capstone-static)
|
||||
endif()
|
||||
endif()
|
||||
@@ -145,12 +154,13 @@ if (DPPC_BUILD_BENCHMARKS)
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
target_link_libraries(bench1 cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(bench1 capstone-static)
|
||||
endif()
|
||||
endif()
|
||||
@@ -160,6 +170,7 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
TARGET testppc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcfloattests.csv"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
||||
endif()
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <chrono>
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
|
||||
+247
-206
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
// Affects the XER register's SO and OV Bits
|
||||
|
||||
@@ -42,12 +42,19 @@ inline void power_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
}
|
||||
}
|
||||
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
||||
uint32_t m2 = 0xFFFFFFFFUL << (31 - rot_me);
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_abs() {
|
||||
ppc_grab_regsda();
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (oe_flag)
|
||||
ppc_state.spr[SPR::XER] |= 0x40000000;
|
||||
ppc_state.spr[SPR::XER] |= 0xC0000000;
|
||||
|
||||
} else {
|
||||
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
|
||||
@@ -62,21 +69,16 @@ void dppc_interpreter::power_abs() {
|
||||
void dppc_interpreter::power_clcs() {
|
||||
ppc_grab_regsda();
|
||||
switch (reg_a) {
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
ppc_result_d = 65535;
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
case 14: //minimum line size
|
||||
case 15: //maximum line size
|
||||
ppc_result_d = 64;
|
||||
break;
|
||||
default:
|
||||
ppc_result_d = 0;
|
||||
}
|
||||
|
||||
if (rc_flag) {
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
printf("Does RC do anything here? (TODO) \n");
|
||||
}
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
@@ -111,84 +113,94 @@ void dppc_interpreter::power_doz() {
|
||||
if (((int32_t)ppc_result_a) > ((int32_t)ppc_result_b)) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = ~ppc_result_a + ppc_result_b + 1;
|
||||
ppc_result_d = ppc_result_b - ppc_result_a;
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (oe_flag)
|
||||
power_setsoov(ppc_result_a, ppc_result_b, ppc_result_d);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_dozi() {
|
||||
ppc_grab_regsdab();
|
||||
ppc_grab_regsdasimm();
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = ~ppc_result_a + simm + 1;
|
||||
ppc_result_d = simm - ppc_result_a;
|
||||
}
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab();
|
||||
uint32_t bytes_copied = 0;
|
||||
bool match_found = false;
|
||||
uint32_t shift_amount = 0;
|
||||
uint8_t return_value;
|
||||
uint8_t byte_compared = (uint8_t)((ppc_state.spr[SPR::XER] & 0xFF00) >> 8);
|
||||
if ((ppc_state.spr[SPR::XER] & 0x7f) == 0) {
|
||||
return;
|
||||
}
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7f) + 1;
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : ppc_result_a + ppc_result_b;
|
||||
do {
|
||||
ppc_effective_address++;
|
||||
bytes_to_load--;
|
||||
if (match_found == false) {
|
||||
switch (shift_amount) {
|
||||
case 0:
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & 0x00FFFFFF) | (return_value << 24);
|
||||
ppc_store_result_regd();
|
||||
break;
|
||||
case 1:
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & 0xFF00FFFF) | (return_value << 16);
|
||||
ppc_store_result_regd();
|
||||
break;
|
||||
case 2:
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & 0xFFFF00FF) | (return_value << 8);
|
||||
ppc_store_result_regd();
|
||||
break;
|
||||
case 3:
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & 0xFFFFFF00) | return_value;
|
||||
ppc_store_result_regd();
|
||||
break;
|
||||
}
|
||||
|
||||
bytes_copied++;
|
||||
uint8_t return_value = 0;
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7f);
|
||||
uint32_t bytes_copied = 0;
|
||||
uint8_t matching_byte = (uint8_t)((ppc_state.spr[SPR::XER] & 0xFF00) >> 8);
|
||||
uint32_t byte_offset = 0;
|
||||
|
||||
//for storing each byte
|
||||
uint32_t bitmask = 0;
|
||||
uint32_t shift_amount = 0;
|
||||
|
||||
while (bytes_to_load > 0) {
|
||||
if (byte_offset == 24) {
|
||||
reg_d = (reg_d + 1) % 32;
|
||||
ppc_result_d = 0xFFFFFFFF;
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
if (return_value == byte_compared) {
|
||||
|
||||
|
||||
switch (byte_offset) {
|
||||
case 0:
|
||||
bitmask = 0x00FFFFFF;
|
||||
shift_amount = 24;
|
||||
break;
|
||||
case 8:
|
||||
bitmask = 0xFF00FFFF;
|
||||
shift_amount = 16;
|
||||
break;
|
||||
case 16:
|
||||
bitmask = 0xFFFF00FF;
|
||||
shift_amount = 8;
|
||||
break;
|
||||
case 24:
|
||||
bitmask = 0xFFFFFF00;
|
||||
shift_amount = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shift_amount == 3) {
|
||||
shift_amount = 0;
|
||||
reg_d = (reg_d + 1) & 0x1F;
|
||||
} else {
|
||||
shift_amount++;
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
// return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & bitmask) | (return_value << shift_amount);
|
||||
ppc_store_result_regd();
|
||||
bytes_copied++;
|
||||
|
||||
if (return_value == matching_byte) {
|
||||
//Match has been found - Time to break out
|
||||
break;
|
||||
}
|
||||
} while (bytes_to_load > 0);
|
||||
|
||||
byte_offset += 8;
|
||||
|
||||
if (byte_offset == 32) {
|
||||
byte_offset = 0;
|
||||
}
|
||||
|
||||
ppc_effective_address++;
|
||||
bytes_to_load--;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & 0xFFFFFF80) | bytes_copied;
|
||||
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_maskg() {
|
||||
@@ -198,16 +210,13 @@ void dppc_interpreter::power_maskg() {
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
for (uint32_t i = mask_start; i < mask_end; i++) {
|
||||
insert_mask |= (0x80000000 >> i);
|
||||
}
|
||||
} else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = power_rot_mask(mask_start, mask_end);
|
||||
}
|
||||
else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
} else {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
for (uint32_t i = (mask_end + 1); i < (mask_start - 1); i++) {
|
||||
insert_mask &= (~(0x80000000 >> i));
|
||||
}
|
||||
}
|
||||
else {
|
||||
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
@@ -220,17 +229,7 @@ void dppc_interpreter::power_maskg() {
|
||||
|
||||
void dppc_interpreter::power_maskir() {
|
||||
ppc_grab_regssab();
|
||||
uint32_t mask_insert = ppc_result_a;
|
||||
uint32_t insert_rot = 0x80000000;
|
||||
do {
|
||||
if (ppc_result_b & insert_rot) {
|
||||
mask_insert &= ~insert_rot;
|
||||
mask_insert |= (ppc_result_d & insert_rot);
|
||||
}
|
||||
insert_rot = insert_rot >> 1;
|
||||
} while (insert_rot > 0);
|
||||
|
||||
ppc_result_a = (ppc_result_d & ppc_result_b);
|
||||
ppc_result_a = (ppc_result_d & ppc_result_b) | (~(ppc_result_b) & ppc_result_a);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -266,24 +265,16 @@ void dppc_interpreter::power_rlmi() {
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
||||
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
if (rot_mb < (rot_me + 1)) {
|
||||
for (uint32_t i = rot_mb; i < rot_me; i++) {
|
||||
insert_mask |= (0x80000000 >> i);
|
||||
}
|
||||
} else if (rot_mb == (rot_me + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
} else {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
for (uint32_t i = (rot_me + 1); i < (rot_mb - 1); i++) {
|
||||
insert_mask &= (~(0x80000000 >> i));
|
||||
}
|
||||
}
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(rot_mb, rot_me);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
uint32_t step2 = (ppc_result_d << rot_amt) | (ppc_result_d >> rot_amt);
|
||||
ppc_result_a = step2 & insert_mask;
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
@@ -291,9 +282,9 @@ void dppc_interpreter::power_rrib() {
|
||||
ppc_grab_regssab();
|
||||
|
||||
if (ppc_result_d & 0x80000000) {
|
||||
ppc_result_a |= (0x80000000 >> ppc_result_b);
|
||||
ppc_result_a |= ((ppc_result_d & 0x80000000) >> ppc_result_b);
|
||||
} else {
|
||||
ppc_result_a &= ~(0x80000000 >> ppc_result_b);
|
||||
ppc_result_a &= ~((ppc_result_d & 0x80000000) >> ppc_result_b);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
@@ -303,15 +294,13 @@ void dppc_interpreter::power_rrib() {
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_sle() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
for (uint32_t i = 31; i > rot_amt; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_final = ((ppc_result_d << rot_amt) | (ppc_result_d >> (32 - rot_amt)));
|
||||
ppc_state.spr[SPR::MQ] = insert_final & insert_mask;
|
||||
ppc_result_a = insert_final & insert_mask;
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
ppc_store_result_rega();
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -320,24 +309,13 @@ void dppc_interpreter::power_sle() {
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_sleq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
for (uint32_t i = 31; i > rot_amt; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d << rot_amt) | (ppc_result_d >> (rot_amt - 31)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -347,23 +325,10 @@ void dppc_interpreter::power_sleq() {
|
||||
|
||||
void dppc_interpreter::power_sliq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
for (uint32_t i = 31; i > rot_sh; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d << rot_sh) | (ppc_result_d >> (rot_sh - 31)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end & insert_mask;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -373,23 +338,12 @@ void dppc_interpreter::power_sliq() {
|
||||
|
||||
void dppc_interpreter::power_slliq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
for (uint32_t i = 31; i > rot_sh; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -398,59 +352,119 @@ void dppc_interpreter::power_slliq() {
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_sllq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sllq!!! \n");
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
}
|
||||
else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_slq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slq!!! \n");
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
} else {
|
||||
ppc_result_a = 0;
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_sraiq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sraiq!!! \n");
|
||||
ppc_grab_regssa();
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 0x1F;
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_sraq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sraq!!! \n");
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << ppc_result_b) | (ppc_result_d >> (ppc_result_b)));
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_sre() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
for (uint32_t i = 31; i > rot_amt; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_final = ((ppc_result_d >> rot_amt) | (ppc_result_d << (32 - rot_amt)));
|
||||
ppc_state.spr[SPR::MQ] = insert_final & insert_mask;
|
||||
ppc_result_a = insert_final;
|
||||
ppc_grab_regssab();
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_srea() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for srea!!! \n");
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & rot_sh)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_sreq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
for (uint32_t i = 31; i > rot_sh; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_result_a = ((rot_sh & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = rot_sh;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -460,23 +474,9 @@ void dppc_interpreter::power_sreq() {
|
||||
|
||||
void dppc_interpreter::power_sriq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
for (uint32_t i = 31; i > rot_sh; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (rot_sh)));
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -485,13 +485,54 @@ void dppc_interpreter::power_sriq() {
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_srliq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slriq!!! \n");
|
||||
ppc_grab_regssa();
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_srlq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slrq!!! \n");
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
}
|
||||
else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_srq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for srq!!! \n");
|
||||
}
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
+85
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,9 +22,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PPCEMU_H
|
||||
#define PPCEMU_H
|
||||
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "endianswap.h"
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <setjmp.h>
|
||||
#include <string>
|
||||
|
||||
@@ -40,6 +42,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// Uncomment this to use Visual Studio built-in functions.
|
||||
//#define USE_VS_BUILTINS 1
|
||||
|
||||
//#define CPU_PROFILING // enable CPU profiling
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
|
||||
typedef void (*PPCOpcode)(void);
|
||||
@@ -197,6 +201,70 @@ enum class BB_end_kind {
|
||||
BB_RFI /* the rfi instruction is encountered */
|
||||
};
|
||||
|
||||
enum CR_select : int32_t {
|
||||
CR0_field = (0xF << 28),
|
||||
CR1_field = (0xF << 24),
|
||||
};
|
||||
|
||||
enum CRx_bit : uint32_t {
|
||||
CR_SO = 28,
|
||||
CR_EQ = 29,
|
||||
CR_GT = 30,
|
||||
CR_LT = 31 };
|
||||
|
||||
enum CR1_bit : uint32_t {
|
||||
CR1_OX = 24,
|
||||
CR1_VX,
|
||||
CR1_FEX,
|
||||
CR1_FX,
|
||||
};
|
||||
|
||||
enum FPSCR : uint32_t {
|
||||
RN = 0x3,
|
||||
NI = 0x4,
|
||||
XE = 0x8,
|
||||
ZE = 0x10,
|
||||
UE = 0x20,
|
||||
OE = 0x40,
|
||||
VE = 0x80,
|
||||
VXCVI = 0x100,
|
||||
VXSQRT = 0x200,
|
||||
VXSOFT = 0x400,
|
||||
FPRF = 0x1F000,
|
||||
FPCC_FUNAN = 0x10000,
|
||||
FPCC_NEG = 0x8000,
|
||||
FPCC_POS = 0x4000,
|
||||
FPCC_ZERO = 0x2000,
|
||||
FPCC_FPRCD = 0x1000,
|
||||
FI = 0x20000,
|
||||
FR = 0x40000,
|
||||
VXVC = 0x80000,
|
||||
VXIMZ = 0x100000,
|
||||
VXZDZ = 0x200000,
|
||||
VXIDI = 0x400000,
|
||||
VXISI = 0x800000,
|
||||
VXSNAN = 0x1000000,
|
||||
XX = 0x2000000,
|
||||
ZX = 0x4000000,
|
||||
UX = 0x8000000,
|
||||
OX = 0x10000000,
|
||||
VX = 0x20000000,
|
||||
FEX = 0x40000000,
|
||||
FX = 0x80000000
|
||||
};
|
||||
|
||||
//for inf and nan checks
|
||||
enum FPOP : int {
|
||||
DIV = 0x12,
|
||||
SUB = 0x14,
|
||||
ADD = 0x15,
|
||||
MUL = 0x19,
|
||||
FMSUB = 0x1C,
|
||||
FMADD = 0x1D,
|
||||
FNMSUB = 0x1E,
|
||||
FNMADD = 0x1F,
|
||||
};
|
||||
|
||||
/** PowerPC exception types. */
|
||||
enum class Except_Type {
|
||||
EXC_SYSTEM_RESET = 1,
|
||||
@@ -243,13 +311,17 @@ extern uint32_t ppc_effective_address;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
// Profiling Stats
|
||||
extern uint32_t mmu_translations_num;
|
||||
extern uint32_t exceptions_performed;
|
||||
extern uint32_t supervisor_inst_num;
|
||||
#ifdef CPU_PROFILING
|
||||
extern uint64_t num_executed_instrs;
|
||||
extern uint64_t num_supervisor_instrs;
|
||||
extern uint64_t num_int_loads;
|
||||
extern uint64_t num_int_stores;
|
||||
extern uint64_t exceptions_processed;
|
||||
#endif
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version);
|
||||
extern void ppc_mmu_init();
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version);
|
||||
extern void ppc_mmu_init(uint32_t cpu_version);
|
||||
|
||||
[[noreturn]] void ppc_illegalop();
|
||||
[[noreturn]] void ppc_fpu_off();
|
||||
@@ -264,7 +336,6 @@ void ppc_opcode63();
|
||||
|
||||
void initialize_ppc_opcode_tables();
|
||||
|
||||
extern bool ppc_confirm_inf_nan(uint64_t input_a, uint64_t input_b, bool is_single, uint32_t op);
|
||||
extern double fp_return_double(uint32_t reg);
|
||||
extern uint64_t fp_return_uint64(uint32_t reg);
|
||||
|
||||
@@ -295,6 +366,9 @@ void ppc_fp_changecrf1();
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
|
||||
extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
namespace dppc_interpreter {
|
||||
extern void ppc_bcctr();
|
||||
@@ -329,6 +403,8 @@ extern void ppc_dcbtst();
|
||||
extern void ppc_dcbz();
|
||||
extern void ppc_divw();
|
||||
extern void ppc_divwu();
|
||||
extern void ppc_eciwx();
|
||||
extern void ppc_ecowx();
|
||||
extern void ppc_eieio();
|
||||
extern void ppc_eqv();
|
||||
extern void ppc_extsb();
|
||||
@@ -404,15 +480,10 @@ extern void ppc_mtspr();
|
||||
extern void ppc_mtfsb0();
|
||||
extern void ppc_mtfsb1();
|
||||
extern void ppc_mcrfs();
|
||||
extern void ppc_mtfsb0dot();
|
||||
extern void ppc_mtfsb1dot();
|
||||
extern void ppc_fmr();
|
||||
extern void ppc_mffs();
|
||||
extern void ppc_mffsdot();
|
||||
extern void ppc_mtfsf();
|
||||
extern void ppc_mtfsfdot();
|
||||
extern void ppc_mtfsfi();
|
||||
extern void ppc_mtfsfidot();
|
||||
|
||||
extern void ppc_addi();
|
||||
extern void ppc_addic();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file Handling of low-level PPC exceptions. */
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -30,8 +31,8 @@ jmp_buf exc_env; /* Global exception environment. */
|
||||
|
||||
[[noreturn]] void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
grab_exception = true;
|
||||
#ifdef PROFILER
|
||||
exceptions_performed++;
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
#endif
|
||||
bb_kind = BB_end_kind::BB_EXCEPTION;
|
||||
|
||||
@@ -109,6 +110,14 @@ jmp_buf exc_env; /* Global exception environment. */
|
||||
ppc_next_instruction_address |= 0xFFF00000;
|
||||
}
|
||||
|
||||
// perform context synchronization for recoverable exceptions
|
||||
if (exception_type != Except_Type::EXC_MACHINE_CHECK &&
|
||||
exception_type != Except_Type::EXC_SYSTEM_RESET) {
|
||||
do_ctx_sync();
|
||||
}
|
||||
|
||||
mmu_change_mode();
|
||||
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
|
||||
|
||||
+107
-27
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ppcemu.h"
|
||||
@@ -69,6 +69,57 @@ 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
|
||||
|
||||
/* global variables for lightweight CPU profiling */
|
||||
uint64_t num_executed_instrs;
|
||||
uint64_t num_supervisor_instrs;
|
||||
uint64_t num_int_loads;
|
||||
uint64_t num_int_stores;
|
||||
uint64_t exceptions_processed;
|
||||
|
||||
#include "utils/profiler.h"
|
||||
#include <memory>
|
||||
|
||||
class CPUProfile : public BaseProfile {
|
||||
public:
|
||||
CPUProfile() : BaseProfile("PPC_CPU") {};
|
||||
|
||||
void populate_variables(std::vector<ProfileVar>& vars) {
|
||||
vars.clear();
|
||||
|
||||
vars.push_back({.name = "Executed Instructions Total",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_executed_instrs});
|
||||
|
||||
vars.push_back({.name = "Executed Supervisor Instructions",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_supervisor_instrs});
|
||||
|
||||
vars.push_back({.name = "Integer Load Instructions",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_int_loads});
|
||||
|
||||
vars.push_back({.name = "Integer Store Instructions",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_int_stores});
|
||||
|
||||
vars.push_back({.name = "Exceptions processed",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = exceptions_processed});
|
||||
};
|
||||
|
||||
void reset() {
|
||||
num_executed_instrs = 0;
|
||||
num_supervisor_instrs = 0;
|
||||
num_int_loads = 0;
|
||||
num_int_stores = 0;
|
||||
exceptions_processed = 0;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/** Opcode lookup tables. */
|
||||
|
||||
/** Primary opcode (bits 0...5) lookup table. */
|
||||
@@ -202,8 +253,7 @@ void ppc_opcode31() {
|
||||
oe_flag = ppc_cur_instruction & 0x400;
|
||||
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 63 table subopcode entry \n", regrab);
|
||||
LOG_F(INFO, "Executing Opcode 31 table subopcode entry %n \n", (uint32_t)subop_grab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
|
||||
SubOpcode31Grabber[subop_grab]();
|
||||
@@ -213,8 +263,7 @@ void ppc_opcode59() {
|
||||
uint16_t subop_grab = (ppc_cur_instruction >> 1) & 0x1F;
|
||||
rc_flag = ppc_cur_instruction & 1;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 59 table subopcode entry \n", regrab);
|
||||
LOG_F(INFO, "Executing Opcode 59 table subopcode entry %n \n", (uint32_t)subop_grab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
SubOpcode59Grabber[subop_grab]();
|
||||
}
|
||||
@@ -223,8 +272,7 @@ void ppc_opcode63() {
|
||||
uint16_t subop_grab = (ppc_cur_instruction >> 1) & 0x3FF;
|
||||
rc_flag = ppc_cur_instruction & 1;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 63 table subopcode entry \n", regrab);
|
||||
LOG_F(INFO, "Executing Opcode 63 table subopcode entry %n \n", (uint32_t)subop_grab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
SubOpcode63Grabber[subop_grab]();
|
||||
}
|
||||
@@ -232,6 +280,9 @@ void ppc_opcode63() {
|
||||
/* Dispatch using main opcode */
|
||||
void ppc_main_opcode()
|
||||
{
|
||||
#ifdef CPU_PROFILING
|
||||
num_executed_instrs++;
|
||||
#endif
|
||||
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
|
||||
}
|
||||
|
||||
@@ -255,7 +306,8 @@ void ppc_exec()
|
||||
timebase_counter += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
|
||||
#endif
|
||||
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
//pc_real = mmu_translate_imem(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
ppc_state.pc = bb_start_la;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
@@ -263,7 +315,8 @@ void ppc_exec()
|
||||
}
|
||||
|
||||
/* initial MMU translation for the current code page. */
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
//pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
|
||||
/* set current code page limits */
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
@@ -281,7 +334,7 @@ again:
|
||||
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
|
||||
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
} else {
|
||||
pc_real += (int)bb_start_la - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
@@ -314,7 +367,8 @@ void ppc_exec_single()
|
||||
return;
|
||||
}
|
||||
|
||||
quickinstruction_translate(ppc_state.pc);
|
||||
//quickinstruction_translate(ppc_state.pc);
|
||||
mmu_translate_imem(ppc_state.pc);
|
||||
ppc_main_opcode();
|
||||
if (bb_kind != BB_end_kind::BB_NONE) {
|
||||
ppc_state.pc = ppc_next_instruction_address;
|
||||
@@ -349,7 +403,7 @@ void ppc_exec_until(volatile uint32_t goal_addr)
|
||||
timebase_counter += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
|
||||
#endif
|
||||
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
ppc_state.pc = bb_start_la;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
@@ -357,7 +411,8 @@ 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 = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
|
||||
/* set current code page limits */
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
@@ -375,7 +430,7 @@ again:
|
||||
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
|
||||
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
} else {
|
||||
pc_real += (int)bb_start_la - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
@@ -409,7 +464,8 @@ void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
|
||||
timebase_counter += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
|
||||
#endif
|
||||
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
//pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
ppc_state.pc = bb_start_la;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
@@ -418,7 +474,7 @@ void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
@@ -436,7 +492,8 @@ again:
|
||||
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
|
||||
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
//pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
} else {
|
||||
pc_real += (int)bb_start_la - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
@@ -546,6 +603,9 @@ void initialize_ppc_opcode_tables() {
|
||||
SubOpcode31Grabber[918] = ppc_sthbrx;
|
||||
SubOpcode31Grabber[983] = ppc_stfiwx;
|
||||
|
||||
SubOpcode31Grabber[310] = ppc_eciwx;
|
||||
SubOpcode31Grabber[438] = ppc_ecowx;
|
||||
|
||||
SubOpcode31Grabber[24] = ppc_slw;
|
||||
SubOpcode31Grabber[28] = ppc_and;
|
||||
SubOpcode31Grabber[60] = ppc_andc;
|
||||
@@ -624,11 +684,26 @@ void initialize_ppc_opcode_tables() {
|
||||
SubOpcode59Grabber[21] = ppc_fadds;
|
||||
SubOpcode59Grabber[22] = ppc_fsqrts;
|
||||
SubOpcode59Grabber[24] = ppc_fres;
|
||||
SubOpcode59Grabber[25] = ppc_fmuls;
|
||||
SubOpcode59Grabber[28] = ppc_fmsubs;
|
||||
SubOpcode59Grabber[29] = ppc_fmadds;
|
||||
SubOpcode59Grabber[30] = ppc_fnmsubs;
|
||||
SubOpcode59Grabber[31] = ppc_fnmadds;
|
||||
|
||||
for (int i = 25; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fmuls;
|
||||
}
|
||||
|
||||
for (int i = 28; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fmsubs;
|
||||
}
|
||||
|
||||
for (int i = 29; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fmadds;
|
||||
}
|
||||
|
||||
for (int i = 30; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fnmsubs;
|
||||
}
|
||||
|
||||
for (int i = 31; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fnmadds;
|
||||
}
|
||||
|
||||
SubOpcode63Grabber[0] = ppc_fcmpu;
|
||||
SubOpcode63Grabber[12] = ppc_frsp;
|
||||
@@ -676,7 +751,7 @@ void initialize_ppc_opcode_tables() {
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version) {
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version) {
|
||||
int i;
|
||||
|
||||
mem_ctrl_instance = mem_ctrl;
|
||||
@@ -727,9 +802,9 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version) {
|
||||
ppc_state.spr[i] = 0;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::PVR] = proc_version;
|
||||
ppc_state.spr[SPR::PVR] = cpu_version;
|
||||
|
||||
if ((proc_version & 0xFFFF0000) == 0x00010000) {
|
||||
if ((cpu_version & 0xFFFF0000) == 0x00010000) {
|
||||
/* MPC601 sets MSR[ME] bit during hard reset / Power-On */
|
||||
ppc_state.msr = 0x1040;
|
||||
} else {
|
||||
@@ -737,10 +812,15 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version) {
|
||||
ppc_state.spr[SPR::DEC] = 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
ppc_mmu_init();
|
||||
ppc_mmu_init(cpu_version);
|
||||
|
||||
/* redirect code execution to reset vector */
|
||||
ppc_state.pc = 0xFFF00100;
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
gProfilerObj->register_profile("PPC_CPU",
|
||||
std::unique_ptr<BaseProfile>(new CPUProfile()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void print_fprs() {
|
||||
|
||||
+367
-372
File diff suppressed because it is too large.
Load diff
+1634
-245
File diff suppressed because it is too large.
Load diff
+83
-13
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,13 +19,16 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The opcodes for the processor - ppcopcodes.cpp
|
||||
/** @file PowerPC Memory Management Unit definitions. */
|
||||
|
||||
#ifndef PPCMEMORY_H
|
||||
#define PPCMEMORY_H
|
||||
#ifndef PPCMMU_H
|
||||
#define PPCMMU_H
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
/* Uncomment this to exhaustive MMU integrity checks. */
|
||||
@@ -33,20 +36,87 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** generic PowerPC BAT descriptor (MMU internal state) */
|
||||
typedef struct PPC_BAT_entry {
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t lo_mask; /* mask for low-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
bool valid; /* BAT entry valid for MPC601 */
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t hi_mask; /* mask for high-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
} PPC_BAT_entry;
|
||||
|
||||
/** Block address translation types. */
|
||||
enum BATType : int {
|
||||
IBAT,
|
||||
DBAT
|
||||
};
|
||||
|
||||
extern void ibat_update(uint32_t bat_reg);
|
||||
extern void dbat_update(uint32_t bat_reg);
|
||||
/** TLB types. */
|
||||
enum TLBType : int {
|
||||
ITLB,
|
||||
DTLB
|
||||
};
|
||||
|
||||
/** Result of the block address translation. */
|
||||
typedef struct BATResult {
|
||||
bool hit;
|
||||
uint8_t prot;
|
||||
uint32_t phys;
|
||||
} BATResult;
|
||||
|
||||
/** Result of the page address translation. */
|
||||
typedef struct PATResult {
|
||||
uint32_t phys;
|
||||
uint8_t prot;
|
||||
uint8_t pte_c_status; // status of the C bit of the PTE
|
||||
} PATResult;
|
||||
|
||||
#define PAGE_SIZE_BITS 12
|
||||
#define TLB_SIZE 4096
|
||||
#define TLB2_WAYS 4
|
||||
#define TLB_INVALID_TAG 0xFFFFFFFF
|
||||
|
||||
typedef struct TLBEntry {
|
||||
uint32_t tag;
|
||||
uint16_t flags;
|
||||
uint16_t lru_bits;
|
||||
union {
|
||||
int64_t host_va_offs_r;
|
||||
AddressMapEntry* reg_desc;
|
||||
};
|
||||
int64_t host_va_offs_w;
|
||||
int64_t unused;
|
||||
} TLBEntry;
|
||||
|
||||
enum TLBFlags : uint16_t {
|
||||
PAGE_MEM = 1 << 0, // memory page backed by host memory
|
||||
PAGE_IO = 1 << 1, // memory mapped I/O page
|
||||
PAGE_NOPHYS = 1 << 2, // no physical storage for this page (unmapped)
|
||||
TLBE_FROM_BAT = 1 << 3, // TLB entry has been translated with BAT
|
||||
TLBE_FROM_PAT = 1 << 4, // TLB entry has been translated with PAT
|
||||
PAGE_WRITABLE = 1 << 5, // page is writable
|
||||
PTE_SET_C = 1 << 6, // tells if C bit of the PTE needs to be updated
|
||||
};
|
||||
|
||||
extern std::function<void(uint32_t bat_reg)> ibat_update;
|
||||
extern std::function<void(uint32_t bat_reg)> dbat_update;
|
||||
|
||||
extern uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size);
|
||||
|
||||
extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
extern void tlb_flush_entry(uint32_t ea);
|
||||
|
||||
extern void ppc_set_cur_instruction(const uint8_t* ptr);
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
uint8_t *mmu_translate_imem(uint32_t vaddr);
|
||||
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t guest_va);
|
||||
template <class T>
|
||||
extern void mmu_write_vmem(uint32_t guest_va, T value);
|
||||
|
||||
//====================== Deprecated calls =========================
|
||||
#if 0
|
||||
extern void mem_write_byte(uint32_t addr, uint8_t value);
|
||||
extern void mem_write_word(uint32_t addr, uint16_t value);
|
||||
extern void mem_write_dword(uint32_t addr, uint32_t value);
|
||||
@@ -55,7 +125,7 @@ extern uint8_t mem_grab_byte(uint32_t addr);
|
||||
extern uint16_t mem_grab_word(uint32_t addr);
|
||||
extern uint32_t mem_grab_dword(uint32_t addr);
|
||||
extern uint64_t mem_grab_qword(uint32_t addr);
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
extern uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
#endif
|
||||
|
||||
#endif // PPCMEMORY_H
|
||||
#endif // PPCMMU_H
|
||||
+370
-115
File diff suppressed because it is too large.
Load diff
+294
-44
@@ -99,6 +99,98 @@ def gen_ppc_opcode(opc_str, imm):
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (0x39A << 1)
|
||||
elif opc_str == "EXTSH.":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (0x39A << 1) + 1
|
||||
elif opc_str == "FABS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1)
|
||||
elif opc_str == "FABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x108 << 1) + 1
|
||||
elif opc_str == "FADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FCMPO":
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11) + (0x20 << 1)
|
||||
elif opc_str == "FCMPU":
|
||||
return (0x3F << 26)+ (4 << 21) + (3 << 16) + (4 << 11)
|
||||
elif opc_str == "FCTIW":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1)
|
||||
elif opc_str == "FCTIW.":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xE << 1) + 1
|
||||
elif opc_str == "FCTIWZ":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1)
|
||||
elif opc_str == "FCTIWZ.":
|
||||
return (0x3B << 26) + (3 << 16) + (4 << 11) + (0xF << 1) + 1
|
||||
elif opc_str == "FDIV":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIV.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FDIVS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIVS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMADDS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADDS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMUL":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMUL.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FMULS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (5 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FNABS":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1)
|
||||
elif opc_str == "FNABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x88 << 1) + 1
|
||||
elif opc_str == "FNEG":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1)
|
||||
elif opc_str == "FNEG.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 11) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 6) + (0x28 << 1) + 1
|
||||
elif opc_str == "FMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FMSUBS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUBS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMADDS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADDS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMSUBS":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FNMSUBS.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (5 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FRES":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "FSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "MULHW":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x4B << 1)
|
||||
elif opc_str == "MULHW.":
|
||||
@@ -262,51 +354,209 @@ def extract_rot_params(line):
|
||||
pos += 16
|
||||
return (sh, mb, me)
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("ppcinttest.txt", "r") as in_file:
|
||||
with open("ppcinttests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
|
||||
with open("ppcinttest.txt", "r") as in_file:
|
||||
with open("ppcinttests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode + ",")
|
||||
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode + ",")
|
||||
|
||||
if opcode.startswith("RLWI"):
|
||||
sh, mb, me = extract_rot_params(line)
|
||||
out_file.write("0x{:X}".format(gen_rot_opcode(opcode, sh, mb, me)))
|
||||
else:
|
||||
imm = extract_imm(line)
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, imm)))
|
||||
|
||||
pos = 12
|
||||
|
||||
while pos < len(line):
|
||||
reg_id = line[pos:pos+4]
|
||||
if reg_id.startswith("rD"):
|
||||
out_file.write(",rD=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rA"):
|
||||
out_file.write(",rA=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rB") or reg_id.startswith("rS"):
|
||||
out_file.write(",rB=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("XER:"):
|
||||
out_file.write(",XER=" + line[pos+5:pos+15])
|
||||
pos += 18
|
||||
elif reg_id.startswith("CR:"):
|
||||
out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
pos += 17
|
||||
elif reg_id.startswith("imm"):
|
||||
pos += 17 # ignore immediate operands
|
||||
elif reg_id.startswith("SH"):
|
||||
pos += 16
|
||||
elif reg_id.startswith("MB") or reg_id.startswith("ME"):
|
||||
pos += 16
|
||||
if opcode.startswith("RLWI"):
|
||||
sh, mb, me = extract_rot_params(line)
|
||||
out_file.write("0x{:X}".format(gen_rot_opcode(opcode, sh, mb, me)))
|
||||
else:
|
||||
out_file.write("Unknown reg ID" + reg_id)
|
||||
break
|
||||
imm = extract_imm(line)
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, imm)))
|
||||
|
||||
out_file.write("\n")
|
||||
pos = 12
|
||||
|
||||
while pos < len(line):
|
||||
reg_id = line[pos:pos+4]
|
||||
if reg_id.startswith("rD"):
|
||||
out_file.write(",rD=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rA"):
|
||||
out_file.write(",rA=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("rB") or reg_id.startswith("rS"):
|
||||
out_file.write(",rB=" + line[pos+3:pos+13])
|
||||
pos += 16
|
||||
elif reg_id.startswith("XER:"):
|
||||
out_file.write(",XER=" + line[pos+5:pos+15])
|
||||
pos += 18
|
||||
elif reg_id.startswith("CR:"):
|
||||
out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
pos += 17
|
||||
elif reg_id.startswith("imm"):
|
||||
pos += 17 # ignore immediate operands
|
||||
elif reg_id.startswith("SH"):
|
||||
pos += 16
|
||||
elif reg_id.startswith("MB") or reg_id.startswith("ME"):
|
||||
pos += 16
|
||||
else:
|
||||
out_file.write("Unknown reg ID" + reg_id)
|
||||
break
|
||||
|
||||
out_file.write("\n")
|
||||
|
||||
with open("ppcfloattest.txt", "r") as in_file:
|
||||
with open("ppcfloattests.csv", "w") as out_file:
|
||||
lineno = 0
|
||||
for line in in_file:
|
||||
lineno += 1
|
||||
|
||||
line = line.strip()
|
||||
opcode = (line[0:8]).rstrip().upper()
|
||||
out_file.write(opcode+ ",")
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, 0)))
|
||||
|
||||
pos = 10
|
||||
checkstring = ''
|
||||
|
||||
while pos < len(line):
|
||||
if (line[pos].isalnum()):
|
||||
checkstring += line[pos]
|
||||
|
||||
if ("RTN" in checkstring):
|
||||
if (line[pos+1:pos+2] == "I"):
|
||||
out_file.write(",round=RNI")
|
||||
checkstring = ''
|
||||
else:
|
||||
out_file.write(",round=RTN")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("RTZ" in checkstring):
|
||||
out_file.write(",round=RTZ")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("RTPI" in checkstring):
|
||||
out_file.write(",round=RPI")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("VE" in checkstring):
|
||||
out_file.write(",round=VEN")
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
elif ("frD" in checkstring):
|
||||
out_file.write(",frD=0x" + line[pos+4:pos+20])
|
||||
checkstring = ''
|
||||
elif ("frA" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frA=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frA=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frA=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frA=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frA=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("frB" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frB=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frB=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frB=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frB=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frB=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("frC" in checkstring): #sloppy temp code
|
||||
check2 = line[pos+1:pos+10]
|
||||
if ("-inf" in check2):
|
||||
out_file.write(",frC=-inf")
|
||||
elif ("inf" in check2):
|
||||
out_file.write(",frC=inf")
|
||||
pos += 1
|
||||
elif ("nan" in check2):
|
||||
out_file.write(",frC=nan")
|
||||
pos += 1
|
||||
elif ("-0." or "-2." or "-4." or \
|
||||
"-6." or "-8." or "-7." or\
|
||||
"-5." or "-3." or "-1." or \
|
||||
"-9." in check2):
|
||||
get_pos = line[pos+2:pos+16].strip("|")
|
||||
out_file.write(",frC=" + get_pos.strip())
|
||||
elif ("0." or "2." or "4." or \
|
||||
"6." or "8." or "7." or\
|
||||
"5." or "3." or "1." or \
|
||||
"9." in check2):
|
||||
get_pos = line[pos+2:pos+15]
|
||||
out_file.write(",frC=" + get_pos.strip())
|
||||
checkstring = ''
|
||||
elif ("FPSCR" in checkstring):
|
||||
out_file.write(",FPSCR=" + line[pos+3:pos+13])
|
||||
checkstring = ''
|
||||
elif ("CR" in checkstring):
|
||||
out_file.write(",CR=0x0" + line[pos+6:pos+14])
|
||||
checkstring = ''
|
||||
pos += 1
|
||||
|
||||
# reg_id = line[pos:pos+4]
|
||||
# if reg_id.startswith("frD"):
|
||||
# out_file.write(",frD=" + line[pos+4:pos+22])
|
||||
# pos += 24
|
||||
# elif reg_id.startswith("frA"):
|
||||
# out_file.write(",frA=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("frB"):
|
||||
# out_file.write(",frB=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("frC"):
|
||||
# out_file.write(",frC=" + line[pos+4:pos+14])
|
||||
# pos += 16
|
||||
# elif reg_id.startswith("FPSCR:"):
|
||||
# out_file.write(",FPSCR=" + line[pos+7:pos+17])
|
||||
# pos += 19
|
||||
# elif reg_id.startswith("CR:"):
|
||||
# out_file.write(",CR=" + line[pos+4:pos+14])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("VE)"):
|
||||
# out_file.write("round=VEN" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("TN)"):
|
||||
# out_file.write("round=RTN" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("TZ)"):
|
||||
# out_file.write("round=RTZ" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("NI)"):
|
||||
# out_file.write("round=RNI" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# elif reg_id.startswith("PI)"):
|
||||
# out_file.write("round=RPI" + line[pos+4:pos+20])
|
||||
# pos += 17
|
||||
# else:
|
||||
# out_file.write("Unknown reg ID" + reg_id)
|
||||
# break
|
||||
|
||||
out_file.write("\n")
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,27 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../ppcdisasm.h"
|
||||
#include "../ppcemu.h"
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
@@ -117,6 +139,7 @@ static void read_test_data() {
|
||||
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
@@ -141,6 +164,129 @@ static void read_test_data() {
|
||||
}
|
||||
}
|
||||
|
||||
static void read_test_float_data() {
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
|
||||
uint32_t opcode, dest, src1, src2, check_xer, check_cr, check_fpscr;
|
||||
uint64_t dest_64, src1_64, src2_64;
|
||||
//float sfp_dest, sfp_src1, sfp_src2, sfp_src3;
|
||||
double dfp_dest, dfp_src1, dfp_src2, dfp_src3;
|
||||
string rounding_mode;
|
||||
|
||||
ifstream tf2stream("ppcfloattests.csv");
|
||||
if (!tf2stream.is_open()) {
|
||||
cout << "Could not open tests CSV file. Exiting..." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
lineno = 0;
|
||||
|
||||
while (getline(tf2stream, line)) {
|
||||
lineno++;
|
||||
|
||||
if (line.empty() || !line.rfind("#", 0))
|
||||
continue; /* skip empty/comment lines */
|
||||
|
||||
istringstream lnstream(line);
|
||||
|
||||
vector<string> tokens;
|
||||
|
||||
while (getline(lnstream, token, ',')) {
|
||||
tokens.push_back(token);
|
||||
}
|
||||
|
||||
if (tokens.size() < 5) {
|
||||
cout << "Too few values in line " << lineno << ". Skipping..." << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
opcode = stoul(tokens[1], NULL, 16);
|
||||
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
check_xer = 0;
|
||||
check_cr = 0;
|
||||
check_fpscr = 0;
|
||||
//sfp_dest = 0.0;
|
||||
//sfp_src1 = 0.0;
|
||||
//sfp_src2 = 0.0;
|
||||
//sfp_src3 = 0.0;
|
||||
dfp_dest = 0.0;
|
||||
dfp_src1 = 0.0;
|
||||
dfp_src2 = 0.0;
|
||||
dfp_src3 = 0.0;
|
||||
dest_64 = 0;
|
||||
|
||||
for (i = 2; i < tokens.size(); i++) {
|
||||
if (tokens[i].rfind("frD=", 0) == 0) {
|
||||
dest_64 = stoull(tokens[i].substr(4), NULL, 16);
|
||||
} else if (tokens[i].rfind("frA=", 0) == 0) {
|
||||
dfp_src1 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("frB=", 0) == 0) {
|
||||
dfp_src2 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("frC=", 0) == 0) {
|
||||
dfp_src3 = stod(tokens[i].substr(4), NULL);
|
||||
} else if (tokens[i].rfind("round=", 0) == 0) {
|
||||
rounding_mode = tokens[i].substr(6, 3);
|
||||
ppc_state.fpscr = 0;
|
||||
if (rounding_mode.compare("RTN") == 0) {
|
||||
ppc_state.fpscr = 0x0;
|
||||
} else if (rounding_mode.compare("RTZ") == 0) {
|
||||
ppc_state.fpscr = 0x1;
|
||||
} else if (rounding_mode.compare("RPI") == 0) {
|
||||
ppc_state.fpscr = 0x2;
|
||||
} else if (rounding_mode.compare("RNI") == 0) {
|
||||
ppc_state.fpscr = 0x3;
|
||||
} else if (rounding_mode.compare("VEN") == 0) {
|
||||
ppc_state.fpscr = FPSCR::VE;
|
||||
} else {
|
||||
cout << "ILLEGAL ROUNDING METHOD: " << tokens[i] << " in line " << lineno
|
||||
<< ". Exiting..." << endl;
|
||||
exit(0);
|
||||
}
|
||||
} else if (tokens[i].rfind("FPSCR=", 0) == 0) {
|
||||
check_fpscr = stoul(tokens[i].substr(6), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
|
||||
ppc_state.fpr[3].dbl64_r = dfp_src1;
|
||||
ppc_state.fpr[4].dbl64_r = dfp_src2;
|
||||
ppc_state.fpr[5].dbl64_r = dfp_src3;
|
||||
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
|
||||
ntested++;
|
||||
|
||||
if ((tokens[0].rfind("FCMP") && (ppc_state.fpr[3].int64_r != dest_64)) ||
|
||||
(ppc_state.fpscr != check_fpscr) ||
|
||||
(ppc_state.cr != check_cr)) {
|
||||
cout << "Mismatch: instr=" << tokens[0] << ", src1=" << scientific << dfp_src1 << ", src2=" << scientific << dfp_src2 << ", src3=" << scientific << dfp_src3 << endl;
|
||||
cout << "expected: dest=0x" << hex << dest_64 << ", FPSCR=0x" << hex << check_fpscr
|
||||
<< ", CR=0x"
|
||||
<< hex << check_cr << endl;
|
||||
cout << "got: dest=0x" << hex << ppc_state.fpr[3].int64_r << ", FPSCR=0x" << hex
|
||||
<< ppc_state.fpscr << ", CR=0x" << hex << ppc_state.cr << endl;
|
||||
cout << "Test file line #: " << dec << lineno << endl << endl;
|
||||
|
||||
nfailed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
initialize_ppc_opcode_tables(); //kludge
|
||||
|
||||
@@ -157,6 +303,13 @@ int main() {
|
||||
|
||||
read_test_data();
|
||||
|
||||
cout << endl << "Float IEEE suport: " << (bool)std::numeric_limits<float>::is_iec559 << endl;
|
||||
cout << endl << "Double IEEE suport: " << (bool)std::numeric_limits<double>::is_iec559 << endl;
|
||||
|
||||
cout << endl << "Testing floating point instructions:" << endl;
|
||||
|
||||
read_test_float_data();
|
||||
|
||||
cout << "... completed." << endl;
|
||||
cout << "--> Tested instructions: " << dec << ntested << endl;
|
||||
cout << "--> Failed: " << dec << nfailed << endl << endl;
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../ppcdisasm.h"
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
+69
-44
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,14 +23,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include "memaccess.h"
|
||||
#include "utils/profiler.h"
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER // optionally defined in CMakeLists.txt
|
||||
#include <capstone/capstone.h>
|
||||
@@ -56,33 +58,37 @@ static uint32_t str2num(string& num_str) {
|
||||
|
||||
static void show_help() {
|
||||
cout << "Debugger commands:" << endl;
|
||||
cout << " step [N] -- execute single instruction" << endl;
|
||||
cout << " N is an optional step count" << endl;
|
||||
cout << " si [N] -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " regs -- dump content of the GRPs" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " step [N] -- execute single instruction" << endl;
|
||||
cout << " N is an optional step count" << endl;
|
||||
cout << " si [N] -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " regs -- dump content of the GRPs" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " profile C N -- run subcommand C on profile N" << endl;
|
||||
cout << " supported subcommands:" << endl;
|
||||
cout << " 'show' - show profile report" << endl;
|
||||
cout << " 'reset' - reset profile variables" << endl;
|
||||
#ifdef PROFILER
|
||||
cout << " profiler -- show stats related to the processor" << endl;
|
||||
cout << " profiler -- show stats related to the processor" << endl;
|
||||
#endif
|
||||
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
|
||||
cout << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
cout << " da N,X -- shortcut for disas" << endl;
|
||||
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
|
||||
cout << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
cout << " da N,X -- shortcut for disas" << endl;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
cout << " context X -- switch to the debugging context X." << endl;
|
||||
cout << " X can be either 'ppc' (default) or '68k'" << endl;
|
||||
cout << " Use 68k for debugging emulated 68k code only." << endl;
|
||||
cout << " context X -- switch to the debugging context X." << endl;
|
||||
cout << " X can be either 'ppc' (default) or '68k'" << endl;
|
||||
cout << " Use 68k for debugging emulated 68k code only." << endl;
|
||||
#endif
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << "Pressing ENTER will repeat last command." << endl;
|
||||
}
|
||||
|
||||
@@ -111,13 +117,23 @@ static void disasm_68k(uint32_t count, uint32_t address) {
|
||||
code_size = sizeof(code);
|
||||
dis_addr = address;
|
||||
|
||||
// catch and handle F-Traps (Nanokernel calls) ourselves because
|
||||
// Capstone will likely return no meaningful assembly for them
|
||||
if ((code[0] & 0xF0) == 0xF0) {
|
||||
goto print_bin;
|
||||
}
|
||||
|
||||
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
|
||||
cout << uppercase << hex << insn->address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
|
||||
address = dis_addr;
|
||||
} else {
|
||||
cout << "DS.W " << hex << ((code[0] << 8) | code[1]) << endl;
|
||||
print_bin:
|
||||
cout << uppercase << hex << address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << "dc.w" << "$" << hex <<
|
||||
((code[0] << 8) | code[1]) << endl;
|
||||
address += 2;
|
||||
}
|
||||
}
|
||||
@@ -146,7 +162,7 @@ void exec_single_68k()
|
||||
|
||||
/* calculate address of the current opcode table entry as follows:
|
||||
get_word(68k_PC) * entry_size + table_base */
|
||||
cur_instr_tab_entry = mem_grab_word(cur_68k_pc) * 8 + emu_table_virt;
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc) * 8 + emu_table_virt;
|
||||
|
||||
/* grab the PPC PC too */
|
||||
reg = "PC";
|
||||
@@ -325,7 +341,7 @@ static void disasm(uint32_t count, uint32_t address) {
|
||||
ctx.simplified = true;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = mem_read_dbg(ctx.instr_addr, 4);
|
||||
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
}
|
||||
@@ -365,7 +381,8 @@ static void print_gprs() {
|
||||
}
|
||||
|
||||
void enter_debugger() {
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str, inst_string, inst_num_str;
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
|
||||
inst_string, inst_num_str, profile_name, sub_cmd;
|
||||
uint32_t addr, inst_grab;
|
||||
std::stringstream ss;
|
||||
int log_level, context;
|
||||
@@ -396,14 +413,18 @@ void enter_debugger() {
|
||||
show_help();
|
||||
} else if (cmd == "quit") {
|
||||
break;
|
||||
} else if (cmd == "profile") {
|
||||
ss >> sub_cmd;
|
||||
ss >> profile_name;
|
||||
|
||||
if (sub_cmd == "show") {
|
||||
gProfilerObj->print_profile(profile_name);
|
||||
} else if (sub_cmd == "reset") {
|
||||
gProfilerObj->reset_profile(profile_name);
|
||||
} else {
|
||||
cout << "Unknown/empty subcommand " << sub_cmd << endl;
|
||||
}
|
||||
}
|
||||
#ifdef PROFILER
|
||||
else if (cmd == "profiler") {
|
||||
cout << "Number of Supervisor Instructions Executed:" << supervisor_inst_num << endl;
|
||||
cout << "Exception Handler Ran:" << exceptions_performed << endl;
|
||||
cout << "Number of MMU Translations:" << mmu_translations_num << endl;
|
||||
}
|
||||
#endif
|
||||
else if (cmd == "regs") {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
@@ -531,16 +552,20 @@ void enter_debugger() {
|
||||
}
|
||||
} else {
|
||||
/* disas without arguments defaults to disas 1,pc */
|
||||
if (context == 2) {
|
||||
try {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str);
|
||||
disasm_68k(1, addr - 2);
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str);
|
||||
disasm_68k(1, addr - 2);
|
||||
#endif
|
||||
} else {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
} else {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
}
|
||||
} else if (cmd == "dump") {
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DEBUGGER_H_
|
||||
#define DEBUGGER_H_
|
||||
|
||||
|
||||
+16
-2
@@ -1,6 +1,20 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
)
|
||||
|
||||
add_library(devices OBJECT ${SOURCES})
|
||||
target_link_libraries(devices PRIVATE cubeb)
|
||||
@@ -1,289 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 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/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019-20
|
||||
*/
|
||||
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "endianswap.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "soundserver.h"
|
||||
#include <algorithm>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
static int awac_freqs[8] = {44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350};
|
||||
|
||||
|
||||
AWACDevice::AWACDevice()
|
||||
{
|
||||
this->audio_proc = new AudioProcessor();
|
||||
|
||||
/* register audio processor chip with the I2C bus */
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(0x45, this->audio_proc);
|
||||
|
||||
this->snd_server = dynamic_cast<SoundServer *>
|
||||
(gMachineObj->get_comp_by_name("SoundServer"));
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
|
||||
AWACDevice::~AWACDevice()
|
||||
{
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
}
|
||||
|
||||
delete this->audio_proc;
|
||||
}
|
||||
|
||||
void AWACDevice::set_dma_out(DMAChannel* dma_out_ch) {
|
||||
this->dma_out_ch = dma_out_ch;
|
||||
}
|
||||
|
||||
uint32_t AWACDevice::snd_ctrl_read(uint32_t offset, int size) {
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
return this->snd_ctrl_reg;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
return this->is_busy;
|
||||
case AWAC_CODEC_STATUS_REG:
|
||||
return (AWAC_AVAILABLE << 8) | (AWAC_MAKER_CRYSTAL << 16) | (AWAC_REV_SCREAMER << 20);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AWAC: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AWACDevice::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
int subframe, reg_num;
|
||||
uint16_t data;
|
||||
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
this->snd_ctrl_reg = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "New sound control value = 0x%X", this->snd_ctrl_reg);
|
||||
break;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
subframe = (value >> 14) & 3;
|
||||
reg_num = (value >> 20) & 7;
|
||||
data = ((value >> 8) & 0xF00) | ((value >> 24) & 0xFF);
|
||||
LOG_F(INFO, "AWAC subframe = %d, reg = %d, data = %08X\n", subframe, reg_num, data);
|
||||
if (!subframe)
|
||||
this->control_regs[reg_num] = data;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AWAC: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void convert_data(const uint8_t *in, SoundIoChannelArea *out_buf, uint32_t frame_count)
|
||||
{
|
||||
uint16_t *p_in = (uint16_t *)in;
|
||||
|
||||
for (int i = 0; i < frame_count; i += 2, p_in += 4) {
|
||||
*(uint16_t *)(out_buf[0].ptr) = BYTESWAP_16(p_in[0]);
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
*(uint16_t *)(out_buf[0].ptr) = BYTESWAP_16(p_in[1]);
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
|
||||
*(uint16_t *)(out_buf[1].ptr) = BYTESWAP_16(p_in[2]);
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
*(uint16_t *)(out_buf[1].ptr) = BYTESWAP_16(p_in[3]);
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
}
|
||||
}
|
||||
|
||||
static void insert_silence(SoundIoChannelArea *out_buf, uint32_t frame_count)
|
||||
{
|
||||
for (int i = 0; i < frame_count; i += 2) {
|
||||
*(uint16_t *)(out_buf[0].ptr) = 0;
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
*(uint16_t *)(out_buf[0].ptr) = 0;
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
|
||||
*(uint16_t *)(out_buf[1].ptr) = 0;
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
*(uint16_t *)(out_buf[1].ptr) = 0;
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static void sound_out_callback(struct SoundIoOutStream *outstream,
|
||||
int frame_count_min, int frame_count_max)
|
||||
{
|
||||
int err, frame_count;
|
||||
uint8_t *p_in;
|
||||
uint32_t buf_len, rem_len, got_len;
|
||||
struct SoundIoChannelArea *areas;
|
||||
DMAChannel *dma_ch = (DMAChannel *)outstream->userdata; /* C API baby! */
|
||||
int n_channels = outstream->layout.channel_count;
|
||||
bool stop = false;
|
||||
|
||||
//if (!dma_ch->is_active()) {
|
||||
// soundio_outstream_clear_buffer(outstream);
|
||||
// soundio_outstream_pause(outstream, true);
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (frame_count_max > 512) {
|
||||
frame_count = 512;
|
||||
}
|
||||
else {
|
||||
frame_count = frame_count_max;
|
||||
}
|
||||
|
||||
buf_len = (frame_count * n_channels) << 1;
|
||||
//frame_count = frame_count_max;
|
||||
|
||||
//LOG_F(INFO, "frame_count_min=%d", frame_count_min);
|
||||
//LOG_F(INFO, "frame_count_max=%d", frame_count_max);
|
||||
//LOG_F(INFO, "channel count: %d", n_channels);
|
||||
//LOG_F(INFO, "buf_len: %d", buf_len);
|
||||
|
||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
|
||||
LOG_F(ERROR, "unrecoverable stream error: %s\n", soundio_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
for (rem_len = buf_len; rem_len > 0; rem_len -= got_len) {
|
||||
if (!dma_ch->get_data(rem_len, &got_len, &p_in)) {
|
||||
//LOG_F(INFO, "SndCallback: got_len = %d", got_len);
|
||||
convert_data(p_in, areas, got_len >> 2);
|
||||
//LOG_F(9, "Converted sound data, len = %d", got_len);
|
||||
} else { /* no more data */
|
||||
//memset(buf, 0, rem_len); /* fill the buffer with silence */
|
||||
//LOG_F(9, "Inserted silence, len = %d", rem_len);
|
||||
|
||||
/* fill the buffer with silence */
|
||||
//LOG_F(ERROR, "rem_len=%d", rem_len);
|
||||
insert_silence(areas, rem_len >> 2);
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = soundio_outstream_end_write(outstream))) {
|
||||
LOG_F(ERROR, "unrecoverable stream error: %s\n", soundio_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
LOG_F(INFO, "pausing result: %s",
|
||||
soundio_strerror(soundio_outstream_pause(outstream, true)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
long AWACDevice::sound_out_callback(cubeb_stream *stream, void *user_data,
|
||||
void const *input_buffer, void *output_buffer,
|
||||
long req_frames)
|
||||
{
|
||||
uint8_t *p_in;
|
||||
int16_t* in_buf, * out_buf;
|
||||
uint32_t got_len;
|
||||
long frames, out_frames;
|
||||
AWACDevice *this_ptr = static_cast<AWACDevice*>(user_data); /* C API baby! */
|
||||
|
||||
if (!this_ptr->dma_out_ch->is_active()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_buf = (int16_t*)output_buffer;
|
||||
|
||||
out_frames = 0;
|
||||
|
||||
while (req_frames > 0) {
|
||||
if (!this_ptr->dma_out_ch->get_data(req_frames << 2, &got_len, &p_in)) {
|
||||
frames = got_len >> 2;
|
||||
|
||||
in_buf = (int16_t*)p_in;
|
||||
|
||||
for (int i = frames; i > 0; i--) {
|
||||
out_buf[0] = BYTESWAP_16(in_buf[0]);
|
||||
out_buf[1] = BYTESWAP_16(in_buf[1]);
|
||||
in_buf += 2;
|
||||
out_buf += 2;
|
||||
}
|
||||
|
||||
req_frames -= frames;
|
||||
out_frames += frames;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out_frames;
|
||||
}
|
||||
|
||||
void status_callback(cubeb_stream *stream, void *user_data, cubeb_state state)
|
||||
{
|
||||
LOG_F(9, "Cubeb status callback fired, status = %d", state);
|
||||
}
|
||||
|
||||
void AWACDevice::open_stream(int sample_rate)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = this->snd_server->open_out_stream(sample_rate, sound_out_callback,
|
||||
status_callback, (void *)this))) {
|
||||
LOG_F(ERROR, "AWAC: unable to open sound output stream: %d", err);
|
||||
this->out_stream_ready = false;
|
||||
} else {
|
||||
this->out_sample_rate = sample_rate;
|
||||
this->out_stream_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AWACDevice::dma_start()
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
this->open_stream(awac_freqs[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else if (this->out_sample_rate != awac_freqs[(this->snd_ctrl_reg >> 8) & 7]) {
|
||||
snd_server->close_out_stream();
|
||||
this->open_stream(awac_freqs[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else {
|
||||
LOG_F(ERROR, "AWAC: unpausing attempted!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "Could not start sound output stream");
|
||||
}
|
||||
}
|
||||
|
||||
void AWACDevice::dma_end()
|
||||
{
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,7 +25,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "devices/adb.h"
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
@@ -37,8 +39,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <thirdparty/SDL2/include/SDL_stdinc.h>
|
||||
#endif
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ADB_Bus::ADB_Bus() {
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,12 +21,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Descriptor-based direct memory access emulation. */
|
||||
|
||||
#include "dbdma.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "endianswap.h"
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb)
|
||||
{
|
||||
this->start_cb = start_cb;
|
||||
this->stop_cb = stop_cb;
|
||||
}
|
||||
|
||||
void DMAChannel::get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd) {
|
||||
/* load DMACmd from physical memory */
|
||||
@@ -184,13 +192,14 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
int DMAChannel::get_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
|
||||
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
|
||||
{
|
||||
*avail_len = 0;
|
||||
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
/* dead or idle channel? -> no more data */
|
||||
LOG_F(WARNING, "Dead/idle channel -> no more data");
|
||||
return -1; /* dead or idle channel? -> no more data */
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
/* interpret DBDMA program until we get data or become idle */
|
||||
@@ -212,10 +221,10 @@ int DMAChannel::get_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data
|
||||
*avail_len = this->queue_len;
|
||||
this->queue_len = 0;
|
||||
}
|
||||
return 0; /* tell the caller there is more data */
|
||||
return DmaPullResult::MoreData; /* tell the caller there is more data */
|
||||
}
|
||||
|
||||
return -1; /* tell the caller there is no more data */
|
||||
return DmaPullResult::NoMoreData; /* tell the caller there is no more data */
|
||||
}
|
||||
|
||||
bool DMAChannel::is_active()
|
||||
@@ -239,7 +248,7 @@ void DMAChannel::start()
|
||||
|
||||
this->queue_len = 0;
|
||||
|
||||
this->dma_cb->dma_start();
|
||||
this->start_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::resume() {
|
||||
@@ -257,5 +266,5 @@ void DMAChannel::abort() {
|
||||
|
||||
void DMAChannel::pause() {
|
||||
LOG_F(INFO, "Pausing DMA channel");
|
||||
this->dma_cb->dma_end();
|
||||
this->stop_cb();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,7 +29,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef DB_DMA_H
|
||||
#define DB_DMA_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
/** DBDMA Channel registers offsets */
|
||||
enum DMAReg : uint32_t {
|
||||
@@ -59,26 +62,19 @@ typedef struct DMACmd {
|
||||
uint16_t xfer_stat;
|
||||
} DMACmd;
|
||||
|
||||
class DMACallback {
|
||||
public:
|
||||
virtual void dma_start(void) = 0;
|
||||
virtual void dma_end(void) = 0;
|
||||
//virtual void dma_push(uint8_t *buf, int size) = 0;
|
||||
//virtual void dma_pull(uint8_t *buf, int size) = 0;
|
||||
};
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel {
|
||||
class DMAChannel : public DmaOutChannel {
|
||||
public:
|
||||
DMAChannel(DMACallback* cb) {
|
||||
this->dma_cb = cb;
|
||||
};
|
||||
DMAChannel() = default;
|
||||
~DMAChannel() = default;
|
||||
|
||||
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
|
||||
uint32_t reg_read(uint32_t offset, int size);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
int get_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
bool is_active();
|
||||
bool is_active();
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
|
||||
protected:
|
||||
void get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
|
||||
@@ -90,7 +86,9 @@ protected:
|
||||
void pause(void);
|
||||
|
||||
private:
|
||||
DMACallback* dma_cb = 0;
|
||||
std::function<void(void)> start_cb; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb; // DMA channel stop callback
|
||||
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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 Core definitions for direct memory access (DMA) emulation. */
|
||||
|
||||
#ifndef DMA_CORE_H
|
||||
#define DMA_CORE_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
enum DmaPullResult : int {
|
||||
MoreData, // data source has more data to be pulled
|
||||
NoMoreData, // data source has no more data to be pulled
|
||||
};
|
||||
|
||||
class DmaOutChannel {
|
||||
public:
|
||||
virtual bool is_active() = 0;
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
};
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -37,6 +37,7 @@ 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 */
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** Base class for I2C devices */
|
||||
class I2CDevice {
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_ID_H
|
||||
#define MACHINE_ID_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "mmiodevice.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/**
|
||||
@@ -35,6 +36,39 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Register location and value meaning are board-dependent.
|
||||
*/
|
||||
|
||||
/**
|
||||
Machine ID register for Nubus Power Macs.
|
||||
It's located at physical address 0x5FFFFFFC and contains four bytes:
|
||||
+0 uint16_t signature = 0xA55A
|
||||
+1 uint8_t machine_type (3 - PowerMac)
|
||||
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
|
||||
*/
|
||||
class NubusMacID : public MMIODevice {
|
||||
public:
|
||||
NubusMacID(const uint16_t id) {
|
||||
this->name = "Nubus-Machine-id";
|
||||
this->id[0] = 0xA5;
|
||||
this->id[1] = 0x5A;
|
||||
this->id[2] = (id >> 8) & 0xFF;
|
||||
this->id[3] = id & 0xFF;
|
||||
};
|
||||
~NubusMacID() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::MMIO_DEV;
|
||||
};
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
return (offset < 4 ? this->id[offset] : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint8_t id[4];
|
||||
};
|
||||
|
||||
/**
|
||||
The machine ID for the Gossamer board is accesible at 0xFF000004 (phys).
|
||||
It contains a 16-bit value revealing machine's capabilities like bus speed,
|
||||
@@ -57,7 +91,8 @@ public:
|
||||
return ((!offset && size == 2) ? this->id : 0);
|
||||
};
|
||||
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size){}; /* not writable */
|
||||
/* not writable */
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint16_t id;
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,7 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MMIO_DEVICE_H
|
||||
#define MMIO_DEVICE_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,12 +19,13 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nvram.h"
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** @file Non-volatile RAM implementation.
|
||||
*/
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PCI_DEVICE_H
|
||||
#define PCI_DEVICE_H
|
||||
|
||||
#include "mmiodevice.h"
|
||||
#include "pcihost.h"
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PCI_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance) = 0;
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj) = 0;
|
||||
};
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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 MESH (Macintosh Enhanced SCSI Hardware) controller emulation. */
|
||||
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
|
||||
uint8_t MESHController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MeshReg::BusStatus0:
|
||||
LOG_F(9, "MESH: read from BusStatus0 register");
|
||||
return 0;
|
||||
case MeshReg::MeshID:
|
||||
LOG_F(INFO, "MESH: read from MeshID register");
|
||||
return this->chip_id; // tell them who we are
|
||||
default:
|
||||
LOG_F(WARNING, "MESH: read from unimplemented register at offset %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MESHController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MeshReg::Sequence:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to Sequence register", value);
|
||||
break;
|
||||
case MeshReg::BusStatus1:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to BusStatus1 register", value);
|
||||
break;
|
||||
case MeshReg::IntMask:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to IntMask register", value);
|
||||
break;
|
||||
case MeshReg::Interrupt:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to Interrupt register", value);
|
||||
break;
|
||||
case MeshReg::SourceID:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to SourceID register", value);
|
||||
break;
|
||||
case MeshReg::SyncParms:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to SyncParms register", value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "MESH: write to unimplemented register at offset %d", reg_offset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file MESH (Macintosh Enhanced SCSI Hardware) controller definitions. */
|
||||
|
||||
#ifndef MESH_H
|
||||
#define MESH_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
// Chip ID returned by the MESH cell inside the Heathrow ASIC
|
||||
#define HeathrowMESHID 4
|
||||
|
||||
// MESH registers offsets
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
FIFO = 2,
|
||||
Sequence = 3,
|
||||
BusStatus0 = 4,
|
||||
BusStatus1 = 5,
|
||||
FIFOCount = 6,
|
||||
Exception = 7,
|
||||
Error = 8,
|
||||
IntMask = 9,
|
||||
Interrupt = 0xA,
|
||||
SourceID = 0xB,
|
||||
DestID = 0xC,
|
||||
SyncParms = 0xD,
|
||||
MeshID = 0xE,
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
|
||||
class MESHController {
|
||||
public:
|
||||
MESHController(uint8_t mesh_id) { this->chip_id = mesh_id; };
|
||||
~MESHController() = default;
|
||||
|
||||
// MESH registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint8_t chip_id; // Chip ID for the MESH controller
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file NCR 53C94 SCSI controller emulation. */
|
||||
|
||||
#include "ncr53c94.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
uint8_t Ncr53C94::read(uint8_t reg_offset)
|
||||
{
|
||||
LOG_F(9, "NCR53C94: reading from register %d", reg_offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Ncr53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
LOG_F(INFO, "NCR53C94: writing 0x%X to %d register", value, reg_offset);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file NCR 53C94 SCSI controller definitions. */
|
||||
|
||||
/* NOTE: Power Macintosh computers don't have a real NCR 53C94 chip.
|
||||
The corresponding functionality is provided by the 53C94 compatible
|
||||
cell in the custom Curio IC (Am79C950).
|
||||
*/
|
||||
|
||||
#ifndef NCR53C94_H
|
||||
#define NCR53C94_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/** NCR 53C94 read registers */
|
||||
namespace Read {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Status = 4,
|
||||
Interrupt = 5,
|
||||
Seq_Step = 6,
|
||||
FIFO_Flags = 7,
|
||||
Config_1 = 8,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Curio extension?
|
||||
Xfer_Cnt_Hi = 0xE, // Curio extension?
|
||||
DMA = 0xF, // Curio extension?
|
||||
};
|
||||
};
|
||||
|
||||
/** NCR 53C94 write registers */
|
||||
namespace Write {
|
||||
enum Reg53C94 : uint8_t {
|
||||
Xfer_Cnt_LSB = 0,
|
||||
Xfer_Cnt_MSB = 1,
|
||||
FIFO = 2,
|
||||
Command = 3,
|
||||
Dest_Bus_ID = 4,
|
||||
Sel_Timeout = 5,
|
||||
Synch_Period = 6,
|
||||
Synch_Offset = 7,
|
||||
Config_1 = 8,
|
||||
Clk_Conv_Fac = 9,
|
||||
Test_Mode = 0xA,
|
||||
Config_2 = 0xB,
|
||||
Config_3 = 0xC,
|
||||
Config_4 = 0xD, // Curio extension?
|
||||
Chip_ID = 0xE, // Curio extension?
|
||||
DMA = 0xF, // Curio extension?
|
||||
};
|
||||
};
|
||||
|
||||
class Ncr53C94 {
|
||||
public:
|
||||
Ncr53C94() = default;
|
||||
~Ncr53C94() = default;
|
||||
|
||||
// NCR 53C94 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint8_t chip_id;
|
||||
};
|
||||
|
||||
#endif // NCR53C94_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,38 +24,47 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski 2019
|
||||
*/
|
||||
|
||||
#include "viacuda.h"
|
||||
#include "adb.h"
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ViaCuda::ViaCuda() {
|
||||
this->name = "ViaCuda";
|
||||
|
||||
/* FIXME: is this the correct
|
||||
VIA initialization? */
|
||||
this->via_regs[VIA_A] = 0x80;
|
||||
this->via_regs[VIA_DIRB] = 0xFF;
|
||||
this->via_regs[VIA_DIRA] = 0xFF;
|
||||
// VIA reset clears all internal registers to logic 0
|
||||
// except timers/counters and the shift register
|
||||
// as stated in the 6522 datasheet
|
||||
this->via_regs[VIA_A] = 0;
|
||||
this->via_regs[VIA_B] = 0;
|
||||
this->via_regs[VIA_DIRB] = 0;
|
||||
this->via_regs[VIA_DIRA] = 0;
|
||||
this->via_regs[VIA_IER] = 0;
|
||||
this->via_regs[VIA_SR] = 0;
|
||||
this->via_regs[VIA_ACR] = 0;
|
||||
this->via_regs[VIA_PCR] = 0;
|
||||
this->via_regs[VIA_IFR] = 0;
|
||||
|
||||
// load maximum value into the timer registers for safety
|
||||
// (not prescribed in the 6522 datasheet)
|
||||
this->via_regs[VIA_T1LL] = 0xFF;
|
||||
this->via_regs[VIA_T1LH] = 0xFF;
|
||||
this->via_regs[VIA_IER] = 0x7F;
|
||||
this->via_regs[VIA_T2CL] = 0xFF;
|
||||
this->via_regs[VIA_T2CH] = 0xFF;
|
||||
|
||||
// PRAM Pre-Initialization
|
||||
this->pram_obj = new NVram("pram.bin", 256);
|
||||
// PRAM is part of Cuda
|
||||
this->pram_obj = std::unique_ptr<NVram> (new NVram("pram.bin", 256));
|
||||
|
||||
this->adb_obj = new ADB_Bus();
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
||||
ViaCuda::~ViaCuda() {
|
||||
if (this->pram_obj)
|
||||
delete (this->pram_obj);
|
||||
}
|
||||
|
||||
void ViaCuda::init() {
|
||||
this->old_tip = 0;
|
||||
this->old_byteack = 0;
|
||||
@@ -68,7 +77,7 @@ void ViaCuda::init() {
|
||||
uint8_t ViaCuda::read(int reg) {
|
||||
uint8_t res;
|
||||
|
||||
LOG_F(9, "Read VIA reg %x \n", (uint32_t)reg);
|
||||
LOG_F(9, "Read VIA reg %d", reg);
|
||||
|
||||
res = this->via_regs[reg & 0xF];
|
||||
|
||||
@@ -79,7 +88,21 @@ uint8_t ViaCuda::read(int reg) {
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A! \n");
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A!");
|
||||
break;
|
||||
case VIA_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" */
|
||||
@@ -96,27 +119,27 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A! \n");
|
||||
LOG_F(WARNING, "Attempted write to VIA Port A!");
|
||||
break;
|
||||
case VIA_DIRB:
|
||||
LOG_F(9, "VIA_DIRB = %x \n", (uint32_t)value);
|
||||
LOG_F(9, "VIA_DIRB = 0x%X", value);
|
||||
this->via_regs[VIA_DIRB] = value;
|
||||
break;
|
||||
case VIA_DIRA:
|
||||
LOG_F(9, "VIA_DIRA = %x \n", (uint32_t)value);
|
||||
LOG_F(9, "VIA_DIRA = 0x%X", value);
|
||||
this->via_regs[VIA_DIRA] = value;
|
||||
break;
|
||||
case VIA_PCR:
|
||||
LOG_F(9, "VIA_PCR = %x \n", (uint32_t)value);
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
this->via_regs[VIA_PCR] = value;
|
||||
break;
|
||||
case VIA_ACR:
|
||||
LOG_F(9, "VIA_ACR = %x \n", (uint32_t)value);
|
||||
LOG_F(9, "VIA_ACR = 0x%X", value);
|
||||
this->via_regs[VIA_ACR] = value;
|
||||
break;
|
||||
case VIA_IER:
|
||||
this->via_regs[VIA_IER] = (value & 0x80) ? value & 0x7F : this->via_regs[VIA_IER] & ~value;
|
||||
LOG_F(INFO, "VIA_IER updated to %d \n", (uint32_t)this->via_regs[VIA_IER]);
|
||||
LOG_F(9, "VIA_IER updated to 0x%X", this->via_regs[VIA_IER]);
|
||||
print_enabled_ints();
|
||||
break;
|
||||
default:
|
||||
@@ -129,7 +152,7 @@ void ViaCuda::print_enabled_ints() {
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (this->via_regs[VIA_IER] & (1 << i))
|
||||
LOG_F(INFO, "VIA %s interrupt enabled \n", via_int_src[i]);
|
||||
LOG_F(INFO, "VIA %s interrupt enabled", via_int_src[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +166,7 @@ inline void ViaCuda::assert_sr_int() {
|
||||
|
||||
void ViaCuda::write(uint8_t new_state) {
|
||||
if (!ready()) {
|
||||
LOG_F(WARNING, "Cuda not ready! \n");
|
||||
LOG_F(WARNING, "Cuda not ready!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,7 +177,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
|
||||
return;
|
||||
|
||||
LOG_F(9, "Cuda state changed! \n");
|
||||
LOG_F(9, "Cuda state changed!");
|
||||
|
||||
this->old_tip = new_tip;
|
||||
this->old_byteack = new_byteack;
|
||||
@@ -174,7 +197,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
|
||||
this->in_count = 0;
|
||||
} else {
|
||||
LOG_F(9, "Cuda: enter sync state \n");
|
||||
LOG_F(9, "Cuda: enter sync state");
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; /* assert TREQ */
|
||||
this->treq = 0;
|
||||
this->in_count = 0;
|
||||
@@ -188,7 +211,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
assert_sr_int(); /* tell the system we've read the data */
|
||||
} else {
|
||||
LOG_F(WARNING, "Cuda input buffer exhausted! \n");
|
||||
LOG_F(WARNING, "Cuda input buffer too small. Truncating data!");
|
||||
}
|
||||
} else { /* data transfer: Cuda --> Host */
|
||||
(this->*out_handler)();
|
||||
@@ -197,11 +220,17 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
}
|
||||
}
|
||||
|
||||
/* sends zeros to host at infinitum */
|
||||
/* sends zeros to host ad infinitum */
|
||||
void ViaCuda::null_out_handler() {
|
||||
this->via_regs[VIA_SR] = 0;
|
||||
}
|
||||
|
||||
/* sends PRAM content to host ad infinitum */
|
||||
void ViaCuda::pram_out_handler()
|
||||
{
|
||||
this->via_regs[VIA_SR] = this->pram_obj->read_byte(this->cur_pram_addr++);
|
||||
}
|
||||
|
||||
/* sends data from out_buf until exhausted, then switches to next_out_handler */
|
||||
void ViaCuda::out_buf_handler() {
|
||||
if (this->out_pos < this->out_count) {
|
||||
@@ -245,7 +274,7 @@ void ViaCuda::error_response(uint32_t error) {
|
||||
|
||||
void ViaCuda::process_packet() {
|
||||
if (this->in_count < 2) {
|
||||
LOG_F(ERROR, "Cuda: invalid packet (too few data)!\n");
|
||||
LOG_F(ERROR, "Cuda: invalid packet (too few data)!");
|
||||
error_response(CUDA_ERR_BAD_SIZE);
|
||||
return;
|
||||
}
|
||||
@@ -256,16 +285,16 @@ void ViaCuda::process_packet() {
|
||||
process_adb_command(this->in_buf[1], this->in_count - 2);
|
||||
break;
|
||||
case CUDA_PKT_PSEUDO:
|
||||
LOG_F(9, "Cuda: pseudo command packet received \n");
|
||||
LOG_F(9, "Command: %x \n", (uint32_t)(this->in_buf[1]));
|
||||
LOG_F(9, "Data count: %d \n ", this->in_count);
|
||||
LOG_F(9, "Cuda: pseudo command packet received");
|
||||
LOG_F(9, "Command: 0x%X", this->in_buf[1]);
|
||||
LOG_F(9, "Data count: %d", this->in_count);
|
||||
for (int i = 0; i < this->in_count; i++) {
|
||||
LOG_F(9, "%x ,", (uint32_t)(this->in_buf[i]));
|
||||
LOG_F(9, "0x%X ,", this->in_buf[i]);
|
||||
}
|
||||
pseudo_command(this->in_buf[1], this->in_count - 2);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported packet type = %d \n", (uint32_t)(this->in_buf[0]));
|
||||
LOG_F(ERROR, "Cuda: unsupported packet type = %d", this->in_buf[0]);
|
||||
error_response(CUDA_ERR_BAD_PKT);
|
||||
}
|
||||
}
|
||||
@@ -275,13 +304,13 @@ void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
|
||||
int cmd = cmd_byte & 0xF;
|
||||
|
||||
if (!cmd) {
|
||||
LOG_F(9, "Cuda: ADB SendReset command requested\n");
|
||||
LOG_F(9, "Cuda: ADB SendReset command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else if (cmd == 1) {
|
||||
LOG_F(9, "Cuda: ADB Flush command requested\n");
|
||||
LOG_F(9, "Cuda: ADB Flush command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else if ((cmd & 0xC) == 8) {
|
||||
LOG_F(9, "Cuda: ADB Listen command requested\n");
|
||||
LOG_F(9, "Cuda: ADB Listen command requested");
|
||||
int adb_reg = cmd_byte & 0x3;
|
||||
if (adb_obj->listen(adb_dev, adb_reg)) {
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
@@ -292,7 +321,7 @@ void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
}
|
||||
} else if ((cmd & 0xC) == 0xC) {
|
||||
LOG_F(9, "Cuda: ADB Talk command requested\n");
|
||||
LOG_F(9, "Cuda: ADB Talk command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
int adb_reg = cmd_byte & 0x3;
|
||||
if (adb_obj->talk(adb_dev, adb_reg, this->in_buf[2])) {
|
||||
@@ -301,25 +330,41 @@ void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "Cuda: unsupported ADB command 0x%x \n", cmd);
|
||||
LOG_F(ERROR, "Cuda: unsupported ADB command 0x%X", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
uint16_t addr;
|
||||
int i;
|
||||
|
||||
switch (cmd) {
|
||||
case CUDA_START_STOP_AUTOPOLL:
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: autopoll started, rate: %dms", this->poll_rate);
|
||||
LOG_F(INFO, "Cuda: autopoll started, rate: %d ms", this->poll_rate);
|
||||
} else {
|
||||
LOG_F(INFO, "Cuda: autopoll stopped");
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_GET_6805_ADDRESS:
|
||||
case CUDA_READ_MCU_MEM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = (uint8_t)((this->m6805_address >> 8) & 0xFF);
|
||||
this->out_buf[3] = (uint8_t)((this->m6805_address) & 0xFF);
|
||||
// if starting address is within PRAM region
|
||||
// prepare to transfer PRAM content, othwesise we will send zeroes
|
||||
if (addr >= CUDA_PRAM_START && addr <= CUDA_PRAM_END) {
|
||||
this->cur_pram_addr = addr - CUDA_PRAM_START;
|
||||
this->next_out_handler = &ViaCuda::pram_out_handler;
|
||||
} else if (addr >= CUDA_ROM_START) {
|
||||
// HACK: Cuda ROM dump requsted so let's partially fake it
|
||||
this->out_buf[3] = 0; // empty copyright string
|
||||
WRITE_WORD_BE_A(&this->out_buf[4], 0x0019U);
|
||||
WRITE_WORD_BE_A(&this->out_buf[6], CUDA_FW_VERSION_MAJOR);
|
||||
WRITE_WORD_BE_A(&this->out_buf[8], CUDA_FW_VERSION_MINOR);
|
||||
this->out_count += 7;
|
||||
}
|
||||
this->is_open_ended = true;
|
||||
break;
|
||||
case CUDA_GET_REAL_TIME:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
@@ -328,41 +373,62 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
this->out_buf[4] = (uint8_t)((this->real_time >> 8) & 0xFF);
|
||||
this->out_buf[5] = (uint8_t)((this->real_time) & 0xFF);
|
||||
break;
|
||||
case CUDA_READ_PRAM:
|
||||
case CUDA_WRITE_MCU_MEM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
// if addr is inside PRAM, update PRAM with data from in_buf
|
||||
// otherwise, ignore data in in_buf
|
||||
if (addr >= CUDA_PRAM_START && addr <= CUDA_PRAM_END) {
|
||||
for (i = 0; i < this->in_count - 4; i++) {
|
||||
this->pram_obj->write_byte((addr - CUDA_PRAM_START + i) & 0xFF,
|
||||
this->in_buf[4+i]);
|
||||
}
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->pram_obj->read_byte(this->in_buf[2]);
|
||||
break;
|
||||
case CUDA_SET_6805_ADDRESS:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->m6805_address = ((uint16_t)in_buf[2]) >> 8;
|
||||
this->m6805_address += ((uint16_t)in_buf[3]);
|
||||
LOG_F(INFO, "6805 address set to: %x", this->m6805_address);
|
||||
case CUDA_READ_PRAM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
if (addr <= 0xFF) {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
// this command is open-ended so set up the corresponding context
|
||||
this->cur_pram_addr = addr;
|
||||
this->next_out_handler = &ViaCuda::pram_out_handler;
|
||||
this->is_open_ended = true;
|
||||
} else {
|
||||
error_response(CUDA_ERR_BAD_PAR);
|
||||
}
|
||||
break;
|
||||
case CUDA_SET_REAL_TIME:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->real_time = ((uint32_t)in_buf[2]) >> 24;
|
||||
this->real_time = ((uint32_t)in_buf[2]) >> 24;
|
||||
this->real_time += ((uint32_t)in_buf[3]) >> 16;
|
||||
this->real_time += ((uint32_t)in_buf[4]) >> 8;
|
||||
this->real_time += ((uint32_t)in_buf[5]);
|
||||
break;
|
||||
case CUDA_WRITE_PRAM:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->pram_obj->write_byte(this->in_buf[2], this->in_buf[3]);
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
if (addr <= 0xFF) {
|
||||
// transfer data from in_buf to PRAM
|
||||
for (i = 0; i < this->in_count - 4; i++) {
|
||||
this->pram_obj->write_byte((addr + i) & 0xFF, this->in_buf[4+i]);
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
} else {
|
||||
error_response(CUDA_ERR_BAD_PAR);
|
||||
}
|
||||
break;
|
||||
case CUDA_FILE_SERVER_FLAG:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: File server flag on");
|
||||
this->file_server = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
LOG_F(INFO, "Cuda: File server flag off");
|
||||
this->file_server = false;
|
||||
}
|
||||
break;
|
||||
case CUDA_SET_AUTOPOLL_RATE:
|
||||
this->poll_rate = this->in_buf[2];
|
||||
LOG_F(INFO, "Cuda: autopoll rate set to: %d", this->poll_rate);
|
||||
LOG_F(INFO, "Cuda: autopoll rate set to %d ms", this->poll_rate);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_GET_AUTOPOLL_RATE:
|
||||
@@ -380,6 +446,10 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
this->out_buf[2] = (uint8_t)((this->device_mask >> 8) & 0xFF);
|
||||
this->out_buf[3] = (uint8_t)((this->device_mask) & 0xFF);
|
||||
break;
|
||||
case CUDA_ONE_SECOND_MODE:
|
||||
LOG_F(INFO, "Cuda: One Second Interrupt - Byte Sent: %d", this->in_buf[2]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
|
||||
@@ -392,7 +462,7 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
}
|
||||
break;
|
||||
case CUDA_OUT_PB0: /* undocumented call! */
|
||||
LOG_F(INFO, "Cuda: send %d to PB0 \n", (int)(this->in_buf[2]));
|
||||
LOG_F(INFO, "Cuda: send %d to PB0", (int)(this->in_buf[2]));
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
@@ -401,10 +471,10 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
case CUDA_RESTART_SYSTEM:
|
||||
/* really kludge temp code */
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x! \n", cmd);
|
||||
exit(0);
|
||||
//exit(0);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported pseudo command 0x%x \n", cmd);
|
||||
LOG_F(ERROR, "Cuda: unsupported pseudo command 0x%X", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
@@ -420,7 +490,7 @@ void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, in
|
||||
dev_addr >>= 1; /* strip RD/WR bit */
|
||||
|
||||
if (!this->start_transaction(dev_addr)) {
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -429,7 +499,7 @@ void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, in
|
||||
or the target device doesn't acknowledge that indicates an error */
|
||||
for (int i = 0; i < in_bytes; i++) {
|
||||
if (!this->send_byte(dev_addr, in_buf[i])) {
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -448,7 +518,7 @@ void ViaCuda::i2c_comb_transaction(
|
||||
int op_type = dev_addr1 & 1; /* 0 - write to device, 1 - read from device */
|
||||
|
||||
if ((dev_addr & 0xFE) != (dev_addr1 & 0xFE)) {
|
||||
LOG_F(ERROR, "Combined I2C: dev_addr mismatch!\n");
|
||||
LOG_F(ERROR, "Combined I2C: dev_addr mismatch!");
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -456,13 +526,13 @@ void ViaCuda::i2c_comb_transaction(
|
||||
dev_addr >>= 1; /* strip RD/WR bit */
|
||||
|
||||
if (!this->start_transaction(dev_addr)) {
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "Unsupported I2C device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->send_subaddress(dev_addr, sub_addr)) {
|
||||
LOG_F(WARNING, "NO_ACK while sending subaddress, device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "NO_ACK while sending subaddress, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -471,7 +541,7 @@ void ViaCuda::i2c_comb_transaction(
|
||||
or the target device doesn't acknowledge that indicates an error */
|
||||
for (int i = 0; i < in_bytes; i++) {
|
||||
if (!this->send_byte(dev_addr, in_buf[i])) {
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X \n", (int)(dev_addr));
|
||||
LOG_F(WARNING, "NO_ACK during sending, device 0x%X", dev_addr);
|
||||
error_response(CUDA_ERR_I2C);
|
||||
return;
|
||||
}
|
||||
@@ -485,4 +555,4 @@ void ViaCuda::i2c_comb_transaction(
|
||||
this->next_out_handler = &ViaCuda::i2c_handler;
|
||||
this->is_open_ended = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -45,10 +45,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include "adb.h"
|
||||
#include "hwcomponent.h"
|
||||
#include "i2c.h"
|
||||
#include "nvram.h"
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
/** VIA register offsets. */
|
||||
enum {
|
||||
@@ -70,6 +72,20 @@ 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 */
|
||||
@@ -90,10 +106,10 @@ enum {
|
||||
enum {
|
||||
CUDA_WARM_START = 0x00, /* warm start */
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
|
||||
CUDA_GET_6805_ADDRESS = 0x02, /* get 6805 address */
|
||||
CUDA_READ_MCU_MEM = 0x02, /* read internal Cuda memory */
|
||||
CUDA_GET_REAL_TIME = 0x03, /* get real time */
|
||||
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
|
||||
CUDA_SET_6805_ADDRESS = 0x08, /* set 6805 address */
|
||||
CUDA_WRITE_MCU_MEM = 0x08, /* write internal Cuda memory */
|
||||
CUDA_SET_REAL_TIME = 0x09, /* set real time */
|
||||
CUDA_POWER_DOWN = 0x0A, /* power down system */
|
||||
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
|
||||
@@ -104,6 +120,7 @@ enum {
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
|
||||
CUDA_SET_DEVICE_LIST = 0x19, /* set device list */
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, /* get device list */
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, /* one second interrupt mode */
|
||||
CUDA_READ_WRITE_I2C = 0x22, /* read/write I2C device */
|
||||
CUDA_COMB_FMT_I2C = 0x25, /* combined format I2C transaction */
|
||||
CUDA_OUT_PB0 = 0x26, /* output one bit to Cuda's PB0 line */
|
||||
@@ -114,14 +131,23 @@ enum {
|
||||
CUDA_ERR_BAD_PKT = 1, /* invalid packet type */
|
||||
CUDA_ERR_BAD_CMD = 2, /* invalid pseudo command */
|
||||
CUDA_ERR_BAD_SIZE = 3, /* invalid packet size */
|
||||
CUDA_ERR_BAD_PAR = 4, /* invalid parameter */
|
||||
CUDA_ERR_I2C = 5 /* invalid I2C data or no acknowledge */
|
||||
};
|
||||
|
||||
/** PRAM addresses within Cuda's internal memory */
|
||||
#define CUDA_PRAM_START 0x100 // starting address of PRAM
|
||||
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
|
||||
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
|
||||
|
||||
/** Latest Cuda Firmware version. */
|
||||
#define CUDA_FW_VERSION_MAJOR 0x0002
|
||||
#define CUDA_FW_VERSION_MINOR 0x0029
|
||||
|
||||
class ViaCuda : public HWComponent, public I2CBus {
|
||||
public:
|
||||
ViaCuda();
|
||||
~ViaCuda();
|
||||
~ViaCuda() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return (type == HWCompType::ADB_HOST || type == HWCompType::I2C_HOST);
|
||||
@@ -145,16 +171,16 @@ private:
|
||||
uint8_t poll_rate;
|
||||
int32_t real_time = 0;
|
||||
bool file_server;
|
||||
uint16_t m6805_address = 0x1100;
|
||||
uint16_t device_mask = 0;
|
||||
uint16_t device_mask = 0;
|
||||
|
||||
bool is_open_ended;
|
||||
uint8_t curr_i2c_addr;
|
||||
bool is_open_ended; // true if current transaction is open-ended
|
||||
uint8_t curr_i2c_addr; // current I2C address
|
||||
uint8_t cur_pram_addr; // current PRAM address, range 0...FF
|
||||
|
||||
void (ViaCuda::*out_handler)(void);
|
||||
void (ViaCuda::*next_out_handler)(void);
|
||||
|
||||
NVram* pram_obj;
|
||||
std::unique_ptr<NVram> pram_obj;
|
||||
ADB_Bus* adb_obj;
|
||||
|
||||
void print_enabled_ints(); /* print enabled VIA interrupts and their sources */
|
||||
@@ -164,13 +190,13 @@ private:
|
||||
void assert_sr_int();
|
||||
void write(uint8_t new_state);
|
||||
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
|
||||
// void cuda_response_packet();
|
||||
void error_response(uint32_t error);
|
||||
void process_packet();
|
||||
void process_adb_command(uint8_t cmd_byte, int data_count);
|
||||
void pseudo_command(int cmd, int data_count);
|
||||
|
||||
void null_out_handler(void);
|
||||
void pram_out_handler(void);
|
||||
void out_buf_handler(void);
|
||||
void i2c_handler(void);
|
||||
|
||||
@@ -180,4 +206,4 @@ private:
|
||||
uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1, const uint8_t* in_buf, int in_bytes);
|
||||
};
|
||||
|
||||
#endif /* VIACUDA_H */
|
||||
#endif /* VIACUDA_H */
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Media Access Controller for Ethernet (MACE) emulation. */
|
||||
|
||||
#include "mace.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Interrupt:
|
||||
LOG_F(INFO, "MACE: all interrupt flags cleared");
|
||||
return 0;
|
||||
default:
|
||||
LOG_F(INFO, "Reading MACE register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
if (value & 1) {
|
||||
LOG_F(INFO, "MACE Reset issued");
|
||||
} else {
|
||||
LOG_F(INFO, "MACE BIU Config set to 0x%X", value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "Writing 0x%X to MACE register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Media Access Controller for Ethernet (MACE) definitions. */
|
||||
|
||||
#ifndef MACE_H
|
||||
#define MACE_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
// MACE Chip ID from AMD datasheet
|
||||
// TODO: compare with real HW
|
||||
#define MACE_ID 0x3940
|
||||
|
||||
// MACE registers offsets
|
||||
// Refer to the Am79C940 datasheet for details
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 0x0A,
|
||||
BIU_Config_Ctrl = 0x0B,
|
||||
FIFO_Config = 0x0C,
|
||||
MAC_Config_Ctrl = 0x0D,
|
||||
PLS_Config_Ctrl = 0x0E,
|
||||
PHY_Config_Ctrl = 0x0F,
|
||||
Chip_ID_Lo = 0x10,
|
||||
Chip_ID_Hi = 0x11,
|
||||
Addr_Config = 0x12,
|
||||
Log_Addr_Flt = 0x14,
|
||||
Phys_Addr = 0x15,
|
||||
Missed_Pkt_Cnt = 0x18,
|
||||
Runt_Pkt_Cnt = 0x1A, // not used in Macintosh?
|
||||
Rcv_Collis_Cnt = 0x1B, // not used in Macintosh?
|
||||
User_Test = 0x1D,
|
||||
Rsrvd_Test_1 = 0x1E, // not used in Macintosh?
|
||||
Rsrvd_Test_2 = 0x1F, // not used in Macintosh?
|
||||
};
|
||||
|
||||
class MaceController {
|
||||
public:
|
||||
MaceController(uint16_t id) { this->chip_id = id; };
|
||||
~MaceController() = default;
|
||||
|
||||
// MACE registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint16_t chip_id; // per-instance MACE Chip ID
|
||||
};
|
||||
|
||||
#endif // MACE_H
|
||||
@@ -0,0 +1,405 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/** Apple memory-mapped I/O controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/scsi/ncr53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/ioctrl/amic.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
#include <memory>
|
||||
|
||||
AMIC::AMIC()
|
||||
{
|
||||
this->name = "Apple Memory-mapped I/O Controller";
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
/* add memory mapped I/O region for the AMIC control registers */
|
||||
if (!mem_ctrl->add_mmio_region(0x50F00000, 0x00040000, this)) {
|
||||
LOG_F(ERROR, "Couldn't register AMIC registers!");
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
bool AMIC::supports_type(HWCompType type) {
|
||||
if ((type == HWCompType::MMIO_DEV)
|
||||
|| (type == HWCompType::INT_CTRL)) {
|
||||
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 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);
|
||||
case 0x10: // SCSI registers
|
||||
return this->scsi->read((offset >> 4) & 0xF);
|
||||
case 0x14: // Sound registers
|
||||
switch (offset) {
|
||||
case AMICReg::Snd_Stat_0:
|
||||
case AMICReg::Snd_Stat_1:
|
||||
case AMICReg::Snd_Stat_2:
|
||||
return (this->awacs->read_stat() >> (offset & 3 * 8)) & 0xFF;
|
||||
case AMICReg::Snd_Phase0:
|
||||
case AMICReg::Snd_Phase1:
|
||||
case AMICReg::Snd_Phase2:
|
||||
// the sound phase register is organized as follows:
|
||||
// 000000oo oooooooo oopppppp where 'o' is the 12-bit offset
|
||||
// into the DMA buffer and 'p' is an undocumented prescale value
|
||||
// HWInit doesn't care about. Let's hope it will be sufficient
|
||||
// to return 0 for prescale.
|
||||
phase_val = this->snd_out_dma->get_cur_buf_pos() << 6;
|
||||
return (phase_val >> ((2 - (offset & 3)) * 8)) & 0xFF;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
return this->snd_out_ctrl;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
return this->snd_out_dma->read_stat();
|
||||
}
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
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);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
uint32_t mask;
|
||||
|
||||
// subdevices registers
|
||||
switch(offset >> 12) {
|
||||
case 0: // VIA1 registers
|
||||
case 1:
|
||||
this->viacuda->write(offset >> 9, value);
|
||||
return;
|
||||
case 4:
|
||||
this->escc->write_compat((offset >> 1) & 0xF, value);
|
||||
return;
|
||||
case 0xA: // MACE registers
|
||||
this->mace->write((offset >> 4) & 0xF, value);
|
||||
return;
|
||||
case 0x10:
|
||||
this->scsi->write((offset >> 4) & 0xF, value);
|
||||
return;
|
||||
case 0x14: // Sound registers
|
||||
switch(offset) {
|
||||
case AMICReg::Snd_Ctrl_0:
|
||||
case AMICReg::Snd_Ctrl_1:
|
||||
case AMICReg::Snd_Ctrl_2:
|
||||
// remember values of sound control registers
|
||||
this->imm_snd_regs[offset & 3] = value;
|
||||
// transfer control information to the sound codec when ready
|
||||
if ((this->imm_snd_regs[0] & 0xC0) == PDM_SND_CTRL_VALID) {
|
||||
this->awacs->write_ctrl(
|
||||
(this->imm_snd_regs[1] >> 4) | (this->imm_snd_regs[0] & 0x3F),
|
||||
((this->imm_snd_regs[1] & 0xF) << 8) | this->imm_snd_regs[2]
|
||||
);
|
||||
}
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
return;
|
||||
case AMICReg::Snd_Buf_Size_Hi:
|
||||
case AMICReg::Snd_Buf_Size_Lo:
|
||||
mask = 0xFF00U >> (8 * (offset & 1));
|
||||
this->snd_buf_size = (this->snd_buf_size & ~mask) |
|
||||
((value & 0xFF) << (8 * ((offset & 1) ^1)));
|
||||
this->snd_buf_size &= ~3; // sound buffer size is always a multiple of 4
|
||||
LOG_F(9, "AMIC: Sound buffer size set to 0x%X", this->snd_buf_size);
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
return;
|
||||
case AMICReg::Snd_Out_Ctrl:
|
||||
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
|
||||
if ((value & 1) != (this->snd_out_ctrl & 1)) {
|
||||
if (value & 1) {
|
||||
LOG_F(9, "AMIC Sound Out DMA enabled!");
|
||||
this->snd_out_dma->init(this->dma_base & ~0x3FFFF,
|
||||
this->snd_buf_size);
|
||||
this->snd_out_dma->enable();
|
||||
this->awacs->set_sample_rate((this->snd_out_ctrl >> 1) & 3);
|
||||
this->awacs->start_output_dma();
|
||||
} else {
|
||||
LOG_F(9, "AMIC Sound Out DMA disabled!");
|
||||
this->snd_out_dma->disable();
|
||||
}
|
||||
}
|
||||
this->snd_out_ctrl = value;
|
||||
return;
|
||||
case AMICReg::Snd_In_Ctrl:
|
||||
LOG_F(INFO, "AMIC Sound In Ctrl updated, val=%x", value);
|
||||
return;
|
||||
case AMICReg::Snd_Out_DMA:
|
||||
this->snd_out_dma->write_dma_out_ctrl(value);
|
||||
this->dma_int_reg1 |= 0x2;
|
||||
this->process_interrupt(DEV_ID::SOUND_DMA_OUT);
|
||||
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);
|
||||
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:
|
||||
case AMICReg::DMA_Base_Addr_2:
|
||||
case AMICReg::DMA_Base_Addr_3:
|
||||
mask = 0xFF000000UL >> (8 * (offset & 3));
|
||||
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);
|
||||
break;
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCSI DMA Ctrl updated, val=%x", value);
|
||||
this->scsi_dma_cs = value;
|
||||
break;
|
||||
case AMICReg::Enet_DMA_Rcv_Ctrl:
|
||||
LOG_F(INFO, "AMIC Ethernet Receive DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SWIM3_DMA_Ctrl:
|
||||
LOG_F(INFO, "AMIC SWIM3 DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Xmt_A_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Transmit Ch A DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Rcv_A_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Receive Ch A DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Xmt_B_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Transmit Ch B DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCC_DMA_Rcv_B_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCC Receive Ch B DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unknown AMIC register write, offset=%x, val=%x",
|
||||
offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
// =========================== DMA related stuff =============================
|
||||
AmicSndOutDma::AmicSndOutDma()
|
||||
{
|
||||
this->dma_out_ctrl = 0;
|
||||
this->enabled = false;
|
||||
}
|
||||
|
||||
bool AmicSndOutDma::is_active()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AmicSndOutDma::init(uint32_t buf_base, uint32_t buf_samples)
|
||||
{
|
||||
this->out_buf0 = buf_base + AMIC_SND_BUF0_OFFS;
|
||||
this->out_buf1 = buf_base + AMIC_SND_BUF1_OFFS;
|
||||
|
||||
this->out_buf_len = buf_samples * 2 * 2;
|
||||
|
||||
this->snd_buf_num = 0;
|
||||
this->cur_buf_pos = 0;
|
||||
}
|
||||
|
||||
uint8_t AmicSndOutDma::read_stat()
|
||||
{
|
||||
return this->dma_out_ctrl;
|
||||
}
|
||||
|
||||
void AmicSndOutDma::write_dma_out_ctrl(uint8_t value)
|
||||
{
|
||||
// clear interrupt flags
|
||||
value &= ~PDM_DMA_INTS_MASK;
|
||||
this->dma_out_ctrl = value;
|
||||
LOG_F(9, "AMIC: Sound out DMA control set to 0x%X", value);
|
||||
}
|
||||
|
||||
DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data)
|
||||
{
|
||||
*avail_len = 0;
|
||||
|
||||
int rem_len = this->out_buf_len - this->cur_buf_pos;
|
||||
if (rem_len <= 0) {
|
||||
if (!this->snd_buf_num) {
|
||||
// signal buffer 0 drained
|
||||
this->dma_out_ctrl |= PDM_DMA_IF0;
|
||||
// TODO: generate IE0 interrupt if enabled
|
||||
} else {
|
||||
// signal buffer 1 drained
|
||||
this->dma_out_ctrl |= PDM_DMA_IF1;
|
||||
// TODO: generate IE1 interrupt if enabled
|
||||
}
|
||||
|
||||
// check DMA enable flag after buffer 1 was processed
|
||||
// if it's false stop delivering sound data
|
||||
// this will effectively stop audio playback
|
||||
if (this->snd_buf_num && !this->enabled) {
|
||||
this->cur_buf_pos = 0;
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
this->cur_buf_pos = 0; // reset buffer position
|
||||
this->snd_buf_num ^= 1; // toggle sound buffers
|
||||
rem_len = this->out_buf_len; // buffer size = full buffer
|
||||
}
|
||||
|
||||
uint32_t len = std::min((uint32_t)rem_len, req_len);
|
||||
|
||||
*p_data = mmu_get_dma_mem(
|
||||
(this->snd_buf_num ? this->out_buf1 : this->out_buf0) + this->cur_buf_pos,
|
||||
len);
|
||||
this->cur_buf_pos += len;
|
||||
*avail_len = len;
|
||||
return DmaPullResult::MoreData;
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
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 Apple memory-mapped I/O controller emulation. */
|
||||
|
||||
#ifndef AMIC_H
|
||||
#define AMIC_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/scsi/ncr53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** AMIC sound buffers are located at fixed offsets from DMA base. */
|
||||
#define AMIC_SND_BUF0_OFFS 0x10000
|
||||
#define AMIC_SND_BUF1_OFFS 0x12000
|
||||
|
||||
// PDM HWInit source defines two constants: kExpBit = 0x80 and kCmdBit = 0x40
|
||||
// I don't know what they means but it seems that their combination will
|
||||
// cause sound control parameters to be transferred to the sound chip.
|
||||
#define PDM_SND_CTRL_VALID 0xC0
|
||||
|
||||
#define PDM_DMA_IF1 0x80 // DMA interrupt flag => buffer 1 drained
|
||||
#define PDM_DMA_IF0 0x40 // DMA interrupt flag => buffer 0 drained
|
||||
#define PDM_DMA_INTS_MASK 0xF0 // mask for clearing all interrupt flags
|
||||
|
||||
/** AMIC-specific sound output DMA implementation. */
|
||||
class AmicSndOutDma : public DmaOutChannel {
|
||||
public:
|
||||
AmicSndOutDma();
|
||||
~AmicSndOutDma() = default;
|
||||
|
||||
bool is_active();
|
||||
void init(uint32_t buf_base, uint32_t buf_samples);
|
||||
void enable() { this->enabled = true; };
|
||||
void disable() { this->enabled = false; };
|
||||
uint8_t read_stat();
|
||||
void write_dma_out_ctrl(uint8_t value);
|
||||
uint32_t get_cur_buf_pos() { return this->cur_buf_pos; };
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data);
|
||||
|
||||
private:
|
||||
bool enabled;
|
||||
uint8_t dma_out_ctrl;
|
||||
|
||||
uint32_t out_buf0;
|
||||
uint32_t out_buf1;
|
||||
uint32_t out_buf_len;
|
||||
uint32_t snd_buf_num;
|
||||
uint32_t cur_buf_pos;
|
||||
};
|
||||
|
||||
/* AMIC registers offsets from AMIC base (0x50F00000). */
|
||||
enum AMICReg : uint32_t {
|
||||
// Sound control registers
|
||||
Snd_Ctrl_0 = 0x14000, // audio codec control register 0
|
||||
Snd_Ctrl_1 = 0x14001, // audio codec control register 1
|
||||
Snd_Ctrl_2 = 0x14002, // audio codec control register 2
|
||||
Snd_Stat_0 = 0x14004, // audio codec status register 0
|
||||
Snd_Stat_1 = 0x14005, // audio codec status register 1
|
||||
Snd_Stat_2 = 0x14006, // audio codec status register 2
|
||||
Snd_Buf_Size_Hi = 0x14008, // sound buffer size, high-order byte
|
||||
Snd_Buf_Size_Lo = 0x14009, // sound buffer size, low-order byte
|
||||
Snd_Phase0 = 0x1400C, // high-order byte of the sound phase register
|
||||
Snd_Phase1 = 0x1400D, // middle byte of the sound phase register
|
||||
Snd_Phase2 = 0x1400E, // low-order byte of the sound phase register
|
||||
Snd_Out_Ctrl = 0x14010, // audio codec output control register
|
||||
Snd_In_Ctrl = 0x14011, // audio codec input control register
|
||||
Snd_In_DMA = 0x14014, // sound input DMA status/control register
|
||||
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 control registers
|
||||
Video_Mode_Reg = 0x28000,
|
||||
|
||||
// Interrupt registers
|
||||
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,
|
||||
|
||||
// DMA control registers
|
||||
DMA_Base_Addr_0 = 0x31000,
|
||||
DMA_Base_Addr_1 = 0x31001,
|
||||
DMA_Base_Addr_2 = 0x31002,
|
||||
DMA_Base_Addr_3 = 0x31003,
|
||||
Enet_DMA_Xmt_Ctrl = 0x31C20,
|
||||
SCSI_DMA_Ctrl = 0x32008,
|
||||
Enet_DMA_Rcv_Ctrl = 0x32028,
|
||||
SWIM3_DMA_Ctrl = 0x32068,
|
||||
SCC_DMA_Xmt_A_Ctrl = 0x32088,
|
||||
SCC_DMA_Rcv_A_Ctrl = 0x32098,
|
||||
SCC_DMA_Xmt_B_Ctrl = 0x320A8,
|
||||
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 {
|
||||
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);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
protected:
|
||||
void dma_reg_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
// AMIC subdevices instances
|
||||
std::unique_ptr<Ncr53C94> scsi;
|
||||
std::unique_ptr<EsccController> escc;
|
||||
std::unique_ptr<MaceController> mace;
|
||||
std::unique_ptr<ViaCuda> viacuda;
|
||||
std::unique_ptr<AwacDevicePdm> awacs;
|
||||
|
||||
std::unique_ptr<AmicSndOutDma> snd_out_dma;
|
||||
};
|
||||
|
||||
#endif // AMIC_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,42 +19,77 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "macio.h"
|
||||
#include "viacuda.h"
|
||||
#include <cinttypes>
|
||||
#include <iostream>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
||||
this->nvram = new NVram();
|
||||
this->nvram = std::unique_ptr<NVram> (new NVram());
|
||||
|
||||
this->viacuda = new ViaCuda();
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
|
||||
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
|
||||
|
||||
this->screamer = new AWACDevice();
|
||||
this->snd_out_dma = new DMAChannel(this->screamer);
|
||||
this->screamer->set_dma_out(this->snd_out_dma);
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
this->screamer = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
|
||||
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->screamer->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_start, this->screamer.get()),
|
||||
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());
|
||||
}
|
||||
|
||||
HeathrowIC::~HeathrowIC() {
|
||||
if (this->nvram)
|
||||
delete (this->nvram);
|
||||
uint32_t HeathrowIC::register_device(DEV_ID dev_id){
|
||||
return (1 << dev_id);
|
||||
};
|
||||
|
||||
if (this->viacuda)
|
||||
delete (this->viacuda);
|
||||
}
|
||||
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];
|
||||
@@ -89,6 +124,7 @@ 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);
|
||||
@@ -122,6 +158,13 @@ uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
case 8:
|
||||
res = dma_read(offset - 0x8000, size);
|
||||
break;
|
||||
case 0x10:
|
||||
res = this->mesh->read((offset >> 4) & 0xF);
|
||||
break;
|
||||
case 0x12: // ESCC compatible
|
||||
return this->escc->read_compat((offset >> 4) & 0xF);
|
||||
case 0x13: // ESCC MacRISC
|
||||
return this->escc->read((offset >> 4) & 0xF);
|
||||
case 0x14:
|
||||
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
||||
break;
|
||||
@@ -152,12 +195,24 @@ void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int
|
||||
case 8:
|
||||
dma_write(offset - 0x8000, value, size);
|
||||
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);
|
||||
break;
|
||||
case 0x13: // ESCC MacRISC
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
this->process_interrupt(DEV_ID::DAVBUS);
|
||||
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) {
|
||||
@@ -172,29 +227,37 @@ 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(9, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->int_mask2;
|
||||
LOG_F(0, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::mask2);
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
res = this->int_clear2;
|
||||
LOG_F(0, "read from MIO:Int_Clear2 register \n");
|
||||
res = this->retrieve_reg(REG_ID::clear2);
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
res = this->int_levels2;
|
||||
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);
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(9, "read from MIO:Int_Mask1 register \n");
|
||||
res = this->int_mask1;
|
||||
LOG_F(0, "read from MIO:Int_Mask1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::mask1);
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(9, "read from MIO:Int_Clear1 register \n");
|
||||
res = this->int_clear1;
|
||||
LOG_F(0, "read from MIO:Int_Clear1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::clear1);
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
res = this->int_levels1;
|
||||
LOG_F(0, "read from MIO:Int_Levels1 register \n");
|
||||
res = this->retrieve_reg(REG_ID::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);
|
||||
@@ -202,7 +265,7 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
||||
res = this->feat_ctrl;
|
||||
res = BYTESWAP_32(this->feat_ctrl);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x \n", offset);
|
||||
@@ -214,36 +277,43 @@ 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(9, "write %x to MIO:Int_Mask2 register \n", value);
|
||||
this->int_mask2 = value;
|
||||
LOG_F(0, "write %x to MIO:Int_Mask2 register \n", value);
|
||||
this->update_reg(REG_ID::mask2, value);
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "write %x to MIO:Int_Clear2 register \n", value);
|
||||
this->int_clear2 = value;
|
||||
LOG_F(0, "write %x to MIO:Int_Clear2 register \n", value);
|
||||
this->update_reg(REG_ID::clear2, value);
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "write %x to MIO:Int_Levels2 register \n", value);
|
||||
this->int_levels2 = value;
|
||||
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);
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(9, "write %x to MIO:Int_Mask1 register \n", value);
|
||||
this->int_mask1 = value;
|
||||
LOG_F(0, "write %x to MIO:Int_Mask1 register \n", value);
|
||||
this->update_reg(REG_ID::mask1, value);
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(9, "write %x to MIO:Int_Clear1 register \n", value);
|
||||
this->int_clear1 = value;
|
||||
LOG_F(0, "write %x to MIO:Int_Clear1 register \n", value);
|
||||
this->update_reg(REG_ID::clear1, value);
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "write %x to MIO:Int_Levels1 register \n", value);
|
||||
this->int_levels1 = value;
|
||||
LOG_F(0, "write %x to MIO:Int_Levels1 register \n", value);
|
||||
this->update_reg(REG_ID::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);
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
this->feat_ctrl = value;
|
||||
this->feature_control(BYTESWAP_32(value));
|
||||
break;
|
||||
case 0x3C:
|
||||
LOG_F(9, "write %x to MIO:Aux_Ctrl register \n", value);
|
||||
@@ -254,3 +324,16 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::feature_control(const uint32_t value)
|
||||
{
|
||||
LOG_F(0, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
|
||||
this->feat_ctrl = value;
|
||||
|
||||
if (!(this->feat_ctrl & 1)) {
|
||||
LOG_F(9, "Heathrow: Monitor sense enabled");
|
||||
} else {
|
||||
LOG_F(9, "Heathrow: Monitor sense disabled");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
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 */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -51,16 +51,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACIO_H
|
||||
#define MACIO_H
|
||||
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "nvram.h"
|
||||
#include "pcidevice.h"
|
||||
#include "pcihost.h"
|
||||
#include "viacuda.h"
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ioctrl/interruptctrl.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
Heathrow ASIC emulation
|
||||
@@ -75,7 +80,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
----------------------------------------------------------------
|
||||
mesh(SCSI) register space: 0x00010000, DMA space: 0x00008000
|
||||
bmac(ethernet) register space: 0x00011000, DMA space: 0x00008200, 0x00008300
|
||||
escc(serial) register space: 0x00013000, size: 0x00001000
|
||||
escc(compat) register space: 0x00012000, size: 0x00001000
|
||||
DMA space: 0x00008400, size: 0x00000400
|
||||
escc(MacRISC) register space: 0x00013000, size: 0x00001000
|
||||
DMA space: 0x00008400, size: 0x00000400
|
||||
escc:ch-a register space: 0x00013020, DMA space: 0x00008400, 0x00008500
|
||||
escc:ch-b register space: 0x00013000, DMA space: 0x00008600, 0x00008700
|
||||
@@ -86,13 +93,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
VIA-CUDA register space: 0x00016000, size: 0x00002000
|
||||
*/
|
||||
|
||||
class HeathrowIC : public PCIDevice {
|
||||
class HeathrowIC : public PCIDevice,
|
||||
public InterruptCtrl {
|
||||
|
||||
public:
|
||||
HeathrowIC();
|
||||
~HeathrowIC();
|
||||
~HeathrowIC() = default;
|
||||
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::MMIO_DEV;
|
||||
return (type == HWCompType::MMIO_DEV) || (type == HWCompType::INT_CTRL);
|
||||
};
|
||||
|
||||
/* PCI device methods */
|
||||
@@ -107,6 +116,9 @@ 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);
|
||||
@@ -114,6 +126,8 @@ protected:
|
||||
uint32_t mio_ctrl_read(uint32_t offset, int size);
|
||||
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void feature_control(const uint32_t value);
|
||||
|
||||
private:
|
||||
uint8_t pci_cfg_hdr[256] = {
|
||||
0x6B,
|
||||
@@ -134,23 +148,19 @@ 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 */
|
||||
ViaCuda* viacuda; /* VIA cell with Cuda MCU attached to it */
|
||||
NVram* nvram; /* NVRAM cell */
|
||||
AWACDevice* screamer; /* Screamer audio codec instance */
|
||||
std::unique_ptr<ViaCuda> viacuda; // VIA cell with Cuda MCU attached to it
|
||||
std::unique_ptr<NVram> nvram; // NVRAM cell
|
||||
std::unique_ptr<AwacsScreamer> screamer; // Screamer audio codec instance
|
||||
std::unique_ptr<MESHController> mesh; // MESH SCSI cell instance
|
||||
std::unique_ptr<EsccController> escc; // ESCC serial controller
|
||||
|
||||
DMAChannel* snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
#endif /* MACIO_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/>.
|
||||
*/
|
||||
|
||||
/** Highspeed Memory Controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <devices/memctrl/hmc.h>
|
||||
|
||||
HMC::HMC() : MemCtrlBase()
|
||||
{
|
||||
this->name = "Highspeed Memory Controller";
|
||||
|
||||
/* add memory mapped I/O region for the HMC control register */
|
||||
add_mmio_region(0x50F40000, 0x10000, this);
|
||||
|
||||
this->config_reg = 0ULL;
|
||||
this->bit_pos = 0;
|
||||
}
|
||||
|
||||
bool HMC::supports_type(HWCompType type) {
|
||||
if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
if (!offset)
|
||||
return !!(this->config_reg & (1ULL << this->bit_pos++));
|
||||
else
|
||||
return 0; /* FIXME: what should be returned for invalid offsets? */
|
||||
}
|
||||
|
||||
void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
uint64_t bit;
|
||||
|
||||
switch(offset) {
|
||||
case 0:
|
||||
bit = 1ULL << this->bit_pos++;
|
||||
this->config_reg = (value & 1) ? this->config_reg | bit :
|
||||
this->config_reg & ~bit;
|
||||
break;
|
||||
case 8: /* writing to HMCBase + 8 resets internal bit position */
|
||||
this->bit_pos = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/** Highspeed Memory Controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Highspeed Memory Controller (HMC) is a custom memory
|
||||
and L2 cache controller designed especially for the
|
||||
first generation of the PowerMacintosh computer.
|
||||
*/
|
||||
|
||||
#ifndef HMC_H
|
||||
#define HMC_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class HMC : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
HMC();
|
||||
~HMC() = default;
|
||||
|
||||
bool supports_type(HWCompType type);
|
||||
|
||||
/* MMIODevice methods */
|
||||
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);
|
||||
|
||||
private:
|
||||
int bit_pos;
|
||||
uint64_t config_reg;
|
||||
};
|
||||
|
||||
#endif // HMC_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,15 +19,20 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <algorithm> // to shut up MSVC errors (:
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "memctrlbase.h"
|
||||
|
||||
|
||||
MemCtrlBase::~MemCtrlBase() {
|
||||
for (auto& entry : address_map) {
|
||||
if (entry)
|
||||
delete(entry);
|
||||
}
|
||||
|
||||
for (auto& reg : mem_regions) {
|
||||
if (reg)
|
||||
delete (reg);
|
||||
@@ -39,17 +44,17 @@ MemCtrlBase::~MemCtrlBase() {
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
||||
for (auto& entry : address_map) {
|
||||
if (addr >= entry.start && addr <= entry.end)
|
||||
return &entry;
|
||||
if (addr >= entry->start && addr <= entry->end)
|
||||
return entry;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mem_region(
|
||||
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val = 0) {
|
||||
AddressMapEntry entry;
|
||||
AddressMapEntry *entry;
|
||||
|
||||
/* error if a memory region for the given range already exists */
|
||||
if (find_range(start_addr) || find_range(start_addr + size))
|
||||
@@ -59,12 +64,14 @@ bool MemCtrlBase::add_mem_region(
|
||||
|
||||
this->mem_regions.push_back(reg_content);
|
||||
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + size - 1;
|
||||
entry.mirror = dest_addr;
|
||||
entry.type = type;
|
||||
entry.devobj = 0;
|
||||
entry.mem_ptr = reg_content;
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + size - 1;
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = type;
|
||||
entry->devobj = 0;
|
||||
entry->mem_ptr = reg_content;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -83,18 +90,20 @@ bool MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
AddressMapEntry entry, *ref_entry;
|
||||
AddressMapEntry *entry, *ref_entry;
|
||||
|
||||
ref_entry = find_range(dest_addr);
|
||||
if (!ref_entry)
|
||||
return false;
|
||||
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + (ref_entry->end - ref_entry->start) + 1;
|
||||
entry.mirror = dest_addr;
|
||||
entry.type = ref_entry->type | RT_MIRROR;
|
||||
entry.devobj = 0;
|
||||
entry.mem_ptr = ref_entry->mem_ptr;
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + (ref_entry->end - ref_entry->start);
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = ref_entry->type | RT_MIRROR;
|
||||
entry->devobj = 0;
|
||||
entry->mem_ptr = ref_entry->mem_ptr;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -118,20 +127,33 @@ bool MemCtrlBase::set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance) {
|
||||
AddressMapEntry entry;
|
||||
AddressMapEntry *entry;
|
||||
|
||||
/* error if another region for the given range already exists */
|
||||
if (find_range(start_addr) || find_range(start_addr + size))
|
||||
if (find_range(start_addr) || find_range(start_addr + size - 1))
|
||||
return false;
|
||||
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + size - 1;
|
||||
entry.mirror = 0;
|
||||
entry.type = RT_MMIO;
|
||||
entry.devobj = dev_instance;
|
||||
entry.mem_ptr = 0;
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + size - 1;
|
||||
entry->mirror = 0;
|
||||
entry->type = RT_MMIO;
|
||||
entry->devobj = dev_instance;
|
||||
entry->mem_ptr = 0;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_rom_region()
|
||||
{
|
||||
for (auto& entry : address_map) {
|
||||
if (entry->type == RT_ROM) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,7 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MEMORY_CONTROLLER_BASE_H
|
||||
#define MEMORY_CONTROLLER_BASE_H
|
||||
|
||||
#include "mmiodevice.h"
|
||||
#include <devices/common/mmiodevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
||||
|
||||
AddressMapEntry* find_range(uint32_t addr);
|
||||
AddressMapEntry* find_rom_region();
|
||||
|
||||
protected:
|
||||
bool add_mem_region(
|
||||
@@ -67,7 +69,7 @@ protected:
|
||||
|
||||
private:
|
||||
std::vector<uint8_t*> mem_regions;
|
||||
std::vector<AddressMapEntry> address_map;
|
||||
std::vector<AddressMapEntry*> address_map;
|
||||
};
|
||||
|
||||
#endif /* MEMORY_CONTROLLER_BASE_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,16 +24,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "memaccess.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "mpc106.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
|
||||
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle PCI host bridge") {
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -35,11 +35,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MPC106_H_
|
||||
#define MPC106_H_
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "pcidevice.h"
|
||||
#include "pcihost.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,12 +47,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SPD_EEPROM_H
|
||||
#define SPD_EEPROM_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "i2c.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
enum RAMType : int { SDRAM = 4 };
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef PCI_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance) = 0;
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj) = 0;
|
||||
};
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Enhanced Serial Communications Controller (ESCC) emulation. */
|
||||
|
||||
#include "escc.h"
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
EsccController::EsccController()
|
||||
{
|
||||
this->ch_a = std::unique_ptr<EsccChannel> (new EsccChannel("A"));
|
||||
this->ch_b = std::unique_ptr<EsccChannel> (new EsccChannel("B"));
|
||||
|
||||
this->reg_ptr = 0;
|
||||
}
|
||||
|
||||
uint8_t EsccController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case EsccReg::Port_B_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case EsccReg::Port_A_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: reading register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EsccController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case EsccReg::Port_B_Cmd:
|
||||
this->write_internal(this->ch_b.get(), value);
|
||||
break;
|
||||
case EsccReg::Port_A_Cmd:
|
||||
this->write_internal(this->ch_a.get(), value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: writing 0x%X to register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t EsccController::read_compat(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case Compat::EsccReg::Port_B_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case Compat::EsccReg::Port_A_Cmd:
|
||||
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: reading register %d", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EsccController::write_compat(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case Compat::EsccReg::Port_B_Cmd:
|
||||
this->write_internal(this->ch_b.get(), value);
|
||||
break;
|
||||
case Compat::EsccReg::Port_A_Cmd:
|
||||
this->write_internal(this->ch_a.get(), value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ESCC: writing 0x%X to register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void EsccController::write_internal(EsccChannel *ch, uint8_t value)
|
||||
{
|
||||
if (this->reg_ptr) {
|
||||
ch->write_reg(this->reg_ptr, value);
|
||||
this->reg_ptr = 0;
|
||||
} else {
|
||||
this->reg_ptr = value & 7;
|
||||
switch(value >> 3) {
|
||||
case WR0Cmd::Point_High:
|
||||
this->reg_ptr |= 8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
{
|
||||
this->write_regs[reg_num] = value;
|
||||
LOG_F(9, "ESCC: writing 0x%X to Channel %s WR%d", value, this->name.c_str(),
|
||||
reg_num);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Enhanced Serial Communications Controller (ESCC) definitions. */
|
||||
|
||||
#ifndef ESCC_H
|
||||
#define ESCC_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** ESCC compatible (aka Macintosh legacy) register addressing */
|
||||
namespace Compat {
|
||||
enum EsccReg : uint8_t {
|
||||
Port_B_Cmd = 0,
|
||||
Port_A_Cmd = 1,
|
||||
Port_B_Data = 2,
|
||||
Port_A_Data = 3,
|
||||
Enh_Reg_B = 4,
|
||||
Enh_Reg_A = 5,
|
||||
};
|
||||
};
|
||||
|
||||
/** ESCC MacRISC style register addressing */
|
||||
enum EsccReg : uint8_t {
|
||||
Port_B_Cmd = 0,
|
||||
Port_B_Data = 1,
|
||||
Port_A_Cmd = 2,
|
||||
Port_A_Data = 3,
|
||||
Enh_Reg_B = 4,
|
||||
Enh_Reg_A = 5,
|
||||
};
|
||||
|
||||
/** LocalTalk registers (same in both addressing schemes) */
|
||||
enum LocalTalkReg : uint8_t {
|
||||
Rec_Count = 8,
|
||||
Start_A = 9,
|
||||
Start_B = 0xA,
|
||||
Detect_AB = 0xB,
|
||||
};
|
||||
|
||||
enum WR0Cmd : uint8_t {
|
||||
Point_High = 1,
|
||||
};
|
||||
|
||||
/** ESCC Channel class. */
|
||||
class EsccChannel {
|
||||
public:
|
||||
EsccChannel(std::string name) { this->name = name; };
|
||||
~EsccChannel() = default;
|
||||
|
||||
void write_reg(int reg_num, uint8_t value);
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
uint8_t write_regs[16];
|
||||
};
|
||||
|
||||
/** ESCC Controller class. */
|
||||
class EsccController {
|
||||
public:
|
||||
EsccController();
|
||||
~EsccController() = default;
|
||||
|
||||
// ESCC MacRISC registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
// ESCC compatible registers access
|
||||
uint8_t read_compat(uint8_t reg_offset);
|
||||
void write_compat(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
void write_internal(EsccChannel* ch, uint8_t value);
|
||||
|
||||
std::unique_ptr<EsccChannel> ch_a;
|
||||
std::unique_ptr<EsccChannel> ch_b;
|
||||
|
||||
int reg_ptr; // register pointer for reading/writing (same for both channels)
|
||||
};
|
||||
|
||||
#endif // ESCC_H
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound device emulation.
|
||||
|
||||
Currently supported audio codecs:
|
||||
- PDM AWACs in Nubus Power Macintosh models
|
||||
- Screamer AWACs in Beige G3
|
||||
|
||||
Author: Max Poliakovski 2019-21
|
||||
*/
|
||||
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <endianswap.h>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <loguru.hpp>
|
||||
#include <memory>
|
||||
|
||||
AwacsBase::AwacsBase()
|
||||
{
|
||||
// connect to SoundServer
|
||||
this->snd_server = dynamic_cast<SoundServer *>
|
||||
(gMachineObj->get_comp_by_name("SoundServer"));
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
|
||||
AwacsBase::~AwacsBase()
|
||||
{
|
||||
// disconnect from SoundServer
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsBase::set_sample_rate(int sr_id)
|
||||
{
|
||||
if (sr_id > this->max_sr_id) {
|
||||
LOG_F(ERROR, "AWACs: invalid sample rate ID %d!", sr_id);
|
||||
} else {
|
||||
this->cur_sample_rate = this->sr_table[sr_id];
|
||||
}
|
||||
};
|
||||
|
||||
void AwacsBase::start_output_dma()
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = this->snd_server->open_out_stream(this->cur_sample_rate,
|
||||
(void *)this->dma_out_ch))) {
|
||||
LOG_F(ERROR, "AWACs: unable to open sound output stream: %d", err);
|
||||
this->out_stream_ready = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this->out_stream_ready = true;
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "AWACs: could not start sound output stream");
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsBase::stop_output_dma()
|
||||
{
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
}
|
||||
|
||||
//=========================== PDM-style AWACs =================================
|
||||
AwacDevicePdm::AwacDevicePdm() : AwacsBase()
|
||||
{
|
||||
static int pdm_awac_freqs[3] = {22050, 29400, 44100};
|
||||
|
||||
// PDM-style AWACs only supports three sample rates
|
||||
this->sr_table = pdm_awac_freqs;
|
||||
this->max_sr_id = 2;
|
||||
}
|
||||
|
||||
uint32_t AwacDevicePdm::read_stat()
|
||||
{
|
||||
LOG_F(INFO, "AWACs-PDM: status requested!");
|
||||
// TODO: return valid status including manufacturer & device IDs
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AwacDevicePdm::write_ctrl(uint32_t addr, uint16_t value)
|
||||
{
|
||||
LOG_F(9, "AWACs-PDM: control updated, addr=0x%X, val=0x%X", addr, value);
|
||||
|
||||
if (addr <= 4) {
|
||||
this->ctrl_regs[addr] = value;
|
||||
} else {
|
||||
LOG_F(ERROR, "AWACs-PDM: invalid control register address %d!", addr);
|
||||
}
|
||||
}
|
||||
|
||||
//============================= Screamer AWACs ================================
|
||||
AwacsScreamer::AwacsScreamer() : AwacsBase()
|
||||
{
|
||||
this->audio_proc = std::unique_ptr<AudioProcessor> (new AudioProcessor());
|
||||
|
||||
/* register audio processor chip with the I2C bus */
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(0x45, this->audio_proc.get());
|
||||
|
||||
static int screamer_freqs[8] = {
|
||||
44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
|
||||
};
|
||||
|
||||
this->sr_table = screamer_freqs;
|
||||
this->max_sr_id = 7;
|
||||
}
|
||||
|
||||
uint32_t AwacsScreamer::snd_ctrl_read(uint32_t offset, int size)
|
||||
{
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
return this->snd_ctrl_reg;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
return this->is_busy;
|
||||
case AWAC_CODEC_STATUS_REG:
|
||||
return (AWAC_AVAILABLE << 8) | (AWAC_MAKER_CRYSTAL << 16) | (AWAC_REV_SCREAMER << 20);
|
||||
default:
|
||||
LOG_F(ERROR, "Screamer: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AwacsScreamer::snd_ctrl_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int subframe, reg_num;
|
||||
uint16_t data;
|
||||
|
||||
switch (offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
this->snd_ctrl_reg = BYTESWAP_32(value);
|
||||
LOG_F(9, "Screamer: new sound control value = 0x%X", this->snd_ctrl_reg);
|
||||
break;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
subframe = (value >> 14) & 3;
|
||||
reg_num = (value >> 20) & 7;
|
||||
data = ((value >> 8) & 0xF00) | ((value >> 24) & 0xFF);
|
||||
LOG_F(9, "Screamer subframe = %d, reg = %d, data = %08X\n",
|
||||
subframe, reg_num, data);
|
||||
if (!subframe)
|
||||
this->control_regs[reg_num] = data;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Screamer: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsScreamer::open_stream(int sample_rate)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = this->snd_server->open_out_stream(sample_rate, (void *)this->dma_out_ch))) {
|
||||
LOG_F(ERROR, "Screamer: unable to open sound output stream: %d", err);
|
||||
this->out_stream_ready = false;
|
||||
} else {
|
||||
this->out_sample_rate = sample_rate;
|
||||
this->out_stream_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsScreamer::dma_start()
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
this->open_stream(this->sr_table[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else if (this->out_sample_rate != this->sr_table[(this->snd_ctrl_reg >> 8) & 7]) {
|
||||
snd_server->close_out_stream();
|
||||
this->open_stream(this->sr_table[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else {
|
||||
LOG_F(ERROR, "Screamer: unpausing attempted!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "Screamer: could not start sound output stream");
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsScreamer::dma_end()
|
||||
{
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,29 +21,72 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** AWAC sound devices family definitions.
|
||||
|
||||
Audio Waveform Aplifier and Converter (AWAC) is a family of custom audio
|
||||
Audio Waveform Aplifier and Converters (AWACs) is a family of custom audio
|
||||
chips used in Power Macintosh.
|
||||
*/
|
||||
|
||||
#ifndef AWAC_H
|
||||
#define AWAC_H
|
||||
|
||||
#include "dbdma.h"
|
||||
#include "i2c.h"
|
||||
#include "soundserver.h"
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
|
||||
/** AWAC registers offsets. */
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Base class for the AWACs codecs. */
|
||||
class AwacsBase {
|
||||
public:
|
||||
AwacsBase();
|
||||
~AwacsBase();
|
||||
|
||||
void set_dma_out(DmaOutChannel *dma_out_ch) {
|
||||
this->dma_out_ch = dma_out_ch;
|
||||
};
|
||||
|
||||
void set_sample_rate(int sr_id);
|
||||
void start_output_dma();
|
||||
void stop_output_dma();
|
||||
|
||||
protected:
|
||||
SoundServer *snd_server; // SoundServer instance pointer
|
||||
DmaOutChannel *dma_out_ch; // DMA output channel instance pointer
|
||||
|
||||
int *sr_table; // pointer to the table of supported sample rates
|
||||
int max_sr_id; // maximum value for sample rate ID
|
||||
|
||||
bool out_stream_ready;
|
||||
int cur_sample_rate;
|
||||
};
|
||||
|
||||
/** AWACs PDM-style sound codec. */
|
||||
class AwacDevicePdm : public AwacsBase {
|
||||
public:
|
||||
AwacDevicePdm();
|
||||
~AwacDevicePdm() = default;
|
||||
|
||||
uint32_t read_stat(void);
|
||||
void write_ctrl(uint32_t addr, uint16_t value);
|
||||
|
||||
void dma_out_start(uint8_t sample_rate_id);
|
||||
void dma_out_stop();
|
||||
|
||||
private:
|
||||
uint16_t ctrl_regs[5]; // 12-bit wide control registers
|
||||
};
|
||||
|
||||
/** AWACs Screamer registers offsets. */
|
||||
enum {
|
||||
AWAC_SOUND_CTRL_REG = 0x00,
|
||||
AWAC_CODEC_CTRL_REG = 0x10,
|
||||
AWAC_CODEC_STATUS_REG = 0x20,
|
||||
};
|
||||
|
||||
/** AWAC manufacturer and revision. */
|
||||
#define AWAC_MAKER_CRYSTAL 1
|
||||
#define AWAC_REV_SCREAMER 3
|
||||
/** AWACs Screamer manufacturer and revision. */
|
||||
#define AWAC_MAKER_CRYSTAL 1
|
||||
#define AWAC_REV_SCREAMER 3
|
||||
|
||||
/** Apple source calls this kValidData but doesn't explain
|
||||
what it actually means. It seems like it's used to check
|
||||
@@ -68,7 +111,8 @@ public:
|
||||
|
||||
this->sub_addr = sub_addr & 0xF;
|
||||
this->auto_inc = !!(sub_addr & 0x10);
|
||||
LOG_F(INFO, "TDA7433 subaddress = 0x%X, auto increment = %d", this->sub_addr, this->auto_inc);
|
||||
LOG_F(9, "TDA7433 subaddress = 0x%X, auto increment = %d",
|
||||
this->sub_addr, this->auto_inc);
|
||||
this->pos++;
|
||||
return true;
|
||||
};
|
||||
@@ -77,7 +121,7 @@ public:
|
||||
if (!this->pos) {
|
||||
return send_subaddress(data);
|
||||
} else if (this->sub_addr <= 6) {
|
||||
LOG_F(INFO, "TDA7433 byte 0x%X received", data);
|
||||
LOG_F(9, "TDA7433 byte 0x%X received", data);
|
||||
this->regs[this->sub_addr] = data;
|
||||
if (this->auto_inc) {
|
||||
this->sub_addr++;
|
||||
@@ -90,7 +134,7 @@ public:
|
||||
|
||||
bool receive_byte(uint8_t* p_data) {
|
||||
*p_data = this->regs[this->sub_addr];
|
||||
LOG_F(INFO, "TDA7433 byte 0x%X sent", *p_data);
|
||||
LOG_F(9, "TDA7433 byte 0x%X sent", *p_data);
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -101,18 +145,15 @@ private:
|
||||
int auto_inc;
|
||||
};
|
||||
|
||||
|
||||
class AWACDevice : public DMACallback {
|
||||
/** AWACs Screamer sound codec. */
|
||||
class AwacsScreamer : public AwacsBase {
|
||||
public:
|
||||
AWACDevice();
|
||||
~AWACDevice();
|
||||
AwacsScreamer();
|
||||
~AwacsScreamer() = default;
|
||||
|
||||
void set_dma_out(DMAChannel* dma_out_ch);
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* DMACallback methods */
|
||||
void dma_start();
|
||||
void dma_end();
|
||||
|
||||
@@ -120,22 +161,13 @@ protected:
|
||||
void open_stream(int sample_rate);
|
||||
|
||||
private:
|
||||
static long sound_out_callback(cubeb_stream* stream, void* user_data,
|
||||
void const* input_buffer, void* output_buffer,
|
||||
long req_frames);
|
||||
|
||||
uint32_t snd_ctrl_reg = {0};
|
||||
uint16_t control_regs[8] = {0}; /* control registers, each 12-bits wide */
|
||||
uint32_t snd_ctrl_reg = { 0 };
|
||||
uint16_t control_regs[8] = { 0 }; /* control registers, each 12-bits wide */
|
||||
uint8_t is_busy = 0;
|
||||
AudioProcessor* audio_proc;
|
||||
|
||||
SoundServer *snd_server;
|
||||
|
||||
bool out_stream_ready;
|
||||
int out_sample_rate;
|
||||
|
||||
DMAChannel *dma_out_ch;
|
||||
std::unique_ptr<AudioProcessor> audio_proc;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWAC_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,9 +19,11 @@ 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 "soundserver.h"
|
||||
//#include <thirdparty/libsoundio/soundio/soundio.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <loguru.hpp>
|
||||
#include <cubeb/cubeb.h>
|
||||
#ifdef _WIN32
|
||||
#include <objbase.h>
|
||||
@@ -124,9 +126,54 @@ void SoundServer::shutdown()
|
||||
LOG_F(INFO, "Sound Server shut down.");
|
||||
}
|
||||
|
||||
long sound_out_callback(cubeb_stream *stream, void *user_data,
|
||||
void const *input_buffer, void *output_buffer,
|
||||
long req_frames)
|
||||
{
|
||||
uint8_t *p_in;
|
||||
int16_t* in_buf, * out_buf;
|
||||
uint32_t got_len;
|
||||
long frames, out_frames;
|
||||
DmaOutChannel *dma_ch = static_cast<DmaOutChannel*>(user_data); /* C API baby! */
|
||||
|
||||
int SoundServer::open_out_stream(uint32_t sample_rate, cubeb_data_callback data_cb,
|
||||
cubeb_state_callback status_cb, void *user_data)
|
||||
if (!dma_ch->is_active()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_buf = (int16_t*)output_buffer;
|
||||
|
||||
out_frames = 0;
|
||||
|
||||
while (req_frames > 0) {
|
||||
if (!dma_ch->pull_data(req_frames << 2, &got_len, &p_in)) {
|
||||
frames = got_len >> 2;
|
||||
|
||||
in_buf = (int16_t*)p_in;
|
||||
|
||||
for (int i = frames; i > 0; i--) {
|
||||
out_buf[0] = BYTESWAP_16(in_buf[0]);
|
||||
out_buf[1] = BYTESWAP_16(in_buf[1]);
|
||||
in_buf += 2;
|
||||
out_buf += 2;
|
||||
}
|
||||
|
||||
req_frames -= frames;
|
||||
out_frames += frames;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out_frames;
|
||||
}
|
||||
|
||||
static void status_callback(cubeb_stream *stream, void *user_data, cubeb_state state)
|
||||
{
|
||||
LOG_F(9, "Cubeb status callback fired, status = %d", state);
|
||||
}
|
||||
|
||||
int SoundServer::open_out_stream(uint32_t sample_rate, void *user_data)
|
||||
{
|
||||
int res;
|
||||
uint32_t latency_frames;
|
||||
@@ -148,7 +195,7 @@ int SoundServer::open_out_stream(uint32_t sample_rate, cubeb_data_callback data_
|
||||
|
||||
res = cubeb_stream_init(this->cubeb_ctx, &this->out_stream, "SndOut stream",
|
||||
NULL, NULL, NULL, ¶ms, latency_frames,
|
||||
data_cb, status_cb, user_data);
|
||||
sound_out_callback, status_callback, user_data);
|
||||
if (res != CUBEB_OK) {
|
||||
LOG_F(ERROR, "Could not open sound output stream, error: %d", res);
|
||||
return -1;
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -34,9 +34,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SOUND_SERVER_H
|
||||
#define SOUND_SERVER_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
//#include <thirdparty/libsoundio/soundio/soundio.h>
|
||||
#include <cubeb/cubeb.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
enum {
|
||||
SND_SERVER_DOWN = 0,
|
||||
@@ -52,32 +51,19 @@ public:
|
||||
|
||||
int start();
|
||||
void shutdown();
|
||||
int open_out_stream(uint32_t sample_rate, cubeb_data_callback data_cb,
|
||||
cubeb_state_callback status_cb, void *user_data);
|
||||
int open_out_stream(uint32_t sample_rate, void *user_data);
|
||||
int start_out_stream();
|
||||
void close_out_stream();
|
||||
|
||||
bool supports_type(HWCompType type) { return type == HWCompType::SND_SERVER; };
|
||||
|
||||
#if 0
|
||||
SoundIoDevice *get_out_device() {
|
||||
if (this->status == SND_SERVER_UP) {
|
||||
return this->out_device;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
bool supports_type(HWCompType type) {
|
||||
return type == HWCompType::SND_SERVER;
|
||||
};
|
||||
#endif
|
||||
|
||||
private:
|
||||
int status; /* server status */
|
||||
cubeb *cubeb_ctx;
|
||||
|
||||
cubeb_stream *out_stream;
|
||||
//SoundIo *soundio;
|
||||
//int out_dev_index; /* current output device index */
|
||||
//SoundIoDevice *out_device; /* current output device instance */
|
||||
//SoundIoOutStream *outstream;
|
||||
};
|
||||
|
||||
#endif /* SOUND_SERVER_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,14 +19,16 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "displayid.h"
|
||||
#include "endianswap.h"
|
||||
#include "memaccess.h"
|
||||
#include "pcidevice.h"
|
||||
#include <atirage.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/video/atirage.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
/* Mach64 post dividers. */
|
||||
static const int mach64_post_div[8] = {
|
||||
@@ -75,13 +77,21 @@ static const std::map<uint16_t, std::string> mach64_reg_names = {
|
||||
{0x01FC, "SCALE_3D_CNTL"},
|
||||
{0x0310, "FIFO_STAT"},
|
||||
{0x0338, "GUI_STAT"},
|
||||
{0x04C0, "MPP_CONFIG"},
|
||||
{0x04C4, "MPP_STROBE_SEQ"},
|
||||
{0x04C8, "MPP_ADDR"},
|
||||
{0x04CC, "MPP_DATA"},
|
||||
{0x0500, "TVO_CNTL"},
|
||||
{0x0704, "SETUP_CNTL"},
|
||||
};
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id, uint32_t mem_amount) : PCIDevice("ati-rage") {
|
||||
ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
|
||||
: PCIDevice("ati-rage"), VideoCtrlBase()
|
||||
{
|
||||
uint8_t asic_id;
|
||||
|
||||
this->vram_size = mem_amount << 20;
|
||||
this->vram_size = vmem_size_mb << 20; // convert MBs to bytes
|
||||
|
||||
/* allocate video RAM */
|
||||
this->vram_ptr = new uint8_t[this->vram_size];
|
||||
@@ -89,6 +99,9 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t mem_amount) : PCIDevice("ati-rage") {
|
||||
/* ATI Rage driver needs to know ASIC ID (manufacturer's internal chip code)
|
||||
to operate properly */
|
||||
switch (dev_id) {
|
||||
case ATI_RAGE_GT_DEV_ID:
|
||||
asic_id = 0x9A; // GT-B2U3 fabricated by UMC
|
||||
break;
|
||||
case ATI_RAGE_PRO_DEV_ID:
|
||||
asic_id = 0x5C; // R3B/D/P-A4 fabricated by UMC
|
||||
break;
|
||||
@@ -107,7 +120,7 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t mem_amount) : PCIDevice("ati-rage") {
|
||||
(asic_id << 24) | dev_id);
|
||||
|
||||
/* initialize display identification */
|
||||
this->disp_id = new DisplayID();
|
||||
this->disp_id = new DisplayID(Disp_Id_Kind::DDC2B);
|
||||
}
|
||||
|
||||
ATIRage::~ATIRage()
|
||||
@@ -163,11 +176,6 @@ uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
read_mem(&this->block_io_regs[offset], size));
|
||||
}
|
||||
|
||||
if (offset > sizeof(this->block_io_regs)) {
|
||||
LOG_F(WARNING, "ATI Rage: register offset 0x%04X out of bounds!", offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = read_mem(&this->block_io_regs[offset], size);
|
||||
|
||||
return res;
|
||||
@@ -177,21 +185,30 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
uint32_t gpio_val;
|
||||
uint16_t gpio_dir;
|
||||
|
||||
if (offset > sizeof(this->block_io_regs)) {
|
||||
LOG_F(WARNING, "ATI Rage: register offset 0x%04X out of bounds!", offset);
|
||||
return;
|
||||
}
|
||||
|
||||
/* size-dependent endian conversion */
|
||||
write_mem(&this->block_io_regs[offset], value, size);
|
||||
|
||||
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]));
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
if (this->block_io_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));
|
||||
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]));
|
||||
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]));
|
||||
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]));
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
if (offset < (ATI_GP_IO + 2)) {
|
||||
@@ -239,6 +256,9 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATI_GEN_TEST_CNTL:
|
||||
LOG_F(INFO, "HW cursor: %s", this->block_io_regs[ATI_GEN_TEST_CNTL] & 0x80 ? "on" : "off");
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
INFO,
|
||||
@@ -247,6 +267,16 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
offset & ~3,
|
||||
READ_DWORD_LE_A(&this->block_io_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;
|
||||
|
||||
this->fb_pitch = ((READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
|
||||
this->fb_ptr = this->vram_ptr + src_offset;
|
||||
this->update_screen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -373,9 +403,17 @@ uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
/* read from little-endian VRAM region */
|
||||
return read_mem(this->vram_ptr + offset, size);
|
||||
}
|
||||
else if (offset >= MEMMAP_OFFSET) {
|
||||
/* read from memory-mapped registers */
|
||||
return this->read_reg(offset - MEMMAP_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);
|
||||
}
|
||||
else if (offset >= MM_REGS_0_OFF) {
|
||||
/* read from memory-mapped registers, block 0 */
|
||||
return this->read_reg(offset - MM_REGS_0_OFF, size);
|
||||
}
|
||||
else if (offset >= MM_REGS_1_OFF) {
|
||||
/* read from memory-mapped registers, block 1 */
|
||||
return this->read_reg(offset - MM_REGS_1_OFF + 0x400, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: read attempt from unmapped aperture region at 0x%08X", offset);
|
||||
@@ -396,9 +434,18 @@ 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);
|
||||
} else if (offset >= MEMMAP_OFFSET) {
|
||||
/* write to memory-mapped registers */
|
||||
this->write_reg(offset - MEMMAP_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);
|
||||
}
|
||||
else if (offset >= MM_REGS_0_OFF) {
|
||||
/* write to memory-mapped registers, block 0 */
|
||||
this->write_reg(offset - MM_REGS_0_OFF, value, size);
|
||||
}
|
||||
else if (offset >= MM_REGS_1_OFF) {
|
||||
/* write to memory-mapped registers, block 1 */
|
||||
this->write_reg(offset - MM_REGS_1_OFF + 0x400, value, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: write attempt to unmapped aperture region at 0x%08X", offset);
|
||||
@@ -497,3 +544,41 @@ void ATIRage::crtc_enable() {
|
||||
|
||||
this->crtc_on = true;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
src_buf = this->vram_ptr + (READ_DWORD_LE_A(&this->block_io_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;
|
||||
|
||||
for (int h = 0; h < cur_height; h++) {
|
||||
dst_row = &dst_buf[h * dst_pitch];
|
||||
src_row = &src_buf[h * 16];
|
||||
|
||||
for (int x = 0; x < 16; x++) {
|
||||
px4 = src_row[x];
|
||||
|
||||
for (int p = 0; p < 4; p++, px4 >>= 2, dst_row += 4) {
|
||||
switch(px4 & 3) {
|
||||
case 0: // cursor color 0
|
||||
WRITE_DWORD_BE_A(dst_row, color0);
|
||||
break;
|
||||
case 1: // cursor color 1
|
||||
WRITE_DWORD_BE_A(dst_row, color1);
|
||||
break;
|
||||
case 2: // transparent
|
||||
break;
|
||||
case 3: // 1's complement of display pixel
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ATI_RAGE_H
|
||||
#define ATI_RAGE_H
|
||||
|
||||
#include "displayid.h"
|
||||
#include "pcidevice.h"
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/* PCI related definitions. */
|
||||
@@ -169,6 +171,7 @@ enum {
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
ATI_SETUP_CNTL = 0x0704,
|
||||
};
|
||||
|
||||
/* Mach64 PLL register indices. */
|
||||
@@ -184,13 +187,15 @@ enum {
|
||||
};
|
||||
|
||||
constexpr auto APERTURE_SIZE = 0x01000000UL; /* Mach64 aperture size */
|
||||
constexpr auto MEMMAP_OFFSET = 0x007FFC00UL; /* offset to memory mapped registers */
|
||||
constexpr auto MM_REGS_0_OFF = 0x007FFC00UL; /* offset to memory mapped registers, block 0 */
|
||||
constexpr auto MM_REGS_1_OFF = 0x007FF800UL; /* offset to memory mapped registers, block 1 */
|
||||
constexpr auto BE_FB_OFFSET = 0x00800000UL; /* Offset to the big-endian frame buffer */
|
||||
|
||||
constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
|
||||
|
||||
class ATIRage : public PCIDevice {
|
||||
class ATIRage : public PCIDevice, public VideoCtrlBase {
|
||||
public:
|
||||
ATIRage(uint16_t dev_id, uint32_t mem_amount);
|
||||
ATIRage(uint16_t dev_id, uint32_t vmem_size_mb);
|
||||
~ATIRage();
|
||||
|
||||
/* MMIODevice methods */
|
||||
@@ -221,21 +226,15 @@ protected:
|
||||
float calc_pll_freq(int scale, int fb_div);
|
||||
void verbose_pixel_format(int crtc_index);
|
||||
void crtc_enable();
|
||||
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
private:
|
||||
uint8_t block_io_regs[512] = {0};
|
||||
uint8_t block_io_regs[2048] = {0};
|
||||
|
||||
uint8_t pci_cfg[256] = {0}; /* PCI configuration space */
|
||||
|
||||
uint8_t plls[64] = {0}; // internal PLL registers
|
||||
|
||||
/* CRT controller parameters */
|
||||
bool crtc_on = false;
|
||||
int active_width; // width of the visible display area
|
||||
int active_height; // height of the visible display area
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
/* Video RAM variables */
|
||||
uint32_t vram_size;
|
||||
uint8_t* vram_ptr;
|
||||
@@ -244,7 +243,6 @@ private:
|
||||
|
||||
DisplayID* disp_id;
|
||||
|
||||
uint8_t palette[256][4]; /* internal DAC palette in RGBA format */
|
||||
int comp_index; /* color component index for DAC palette access */
|
||||
};
|
||||
#endif /* ATI_RAGE_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,10 +19,15 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "displayid.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
/** @file DisplayID class implementation. */
|
||||
|
||||
#include <devices/video/displayid.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
DisplayID::DisplayID(Disp_Id_Kind id_kind)
|
||||
{
|
||||
this->id_kind = id_kind;
|
||||
|
||||
DisplayID::DisplayID() {
|
||||
/* Initialize Apple monitor codes */
|
||||
this->std_sense_code = 6;
|
||||
this->ext_sense_code = 0x2B;
|
||||
@@ -34,13 +39,11 @@ DisplayID::DisplayID() {
|
||||
this->last_scl = 1;
|
||||
this->data_out = 0x3000;
|
||||
this->data_ptr = 0;
|
||||
|
||||
/* DDC sense mode is on by default */
|
||||
this->i2c_on = true;
|
||||
}
|
||||
|
||||
|
||||
uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl) {
|
||||
uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl)
|
||||
{
|
||||
this->last_sda = sda;
|
||||
this->last_scl = scl;
|
||||
|
||||
@@ -60,23 +63,24 @@ uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl) {
|
||||
}
|
||||
|
||||
|
||||
uint16_t DisplayID::read_monitor_sense(uint16_t data, uint16_t dirs) {
|
||||
uint16_t DisplayID::read_monitor_sense(uint16_t data, uint16_t dirs)
|
||||
{
|
||||
uint8_t scl, sda;
|
||||
uint16_t result;
|
||||
|
||||
if ((dirs & 0x3100) == 0 && (data & 0x3100) == 0x3100) {
|
||||
LOG_F(WARNING, "DisplayID: Hackish Monitor ID Switch activated!");
|
||||
this->i2c_on = false;
|
||||
LOG_F(WARNING, "DisplayID: Monitor sense lines tristated!");
|
||||
}
|
||||
|
||||
if (this->i2c_on) {
|
||||
switch(this->id_kind) {
|
||||
case Disp_Id_Kind::DDC2B:
|
||||
/* if GPIO pins are in the output mode, pick up their values
|
||||
In the input mode, GPIO pins will be read "high" */
|
||||
scl = (dirs & 0x1000) ? !!(data & 0x1000) : 1;
|
||||
sda = (dirs & 0x2000) ? !!(data & 0x2000) : 1;
|
||||
|
||||
return update_ddc_i2c(sda, scl);
|
||||
} else { /* Apple legacy monitor codes (see Technical Note HW30) */
|
||||
case Disp_Id_Kind::AppleSense:
|
||||
switch (dirs & 0x3100) {
|
||||
case 0:
|
||||
result = ((this->std_sense_code & 6) << 11) | ((this->std_sense_code & 1) << 8);
|
||||
@@ -93,13 +97,12 @@ uint16_t DisplayID::read_monitor_sense(uint16_t data, uint16_t dirs) {
|
||||
default:
|
||||
result = 0x3100U;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl) //(uint16_t data, uint16_t dirs)
|
||||
uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)
|
||||
{
|
||||
bool clk_gone_high = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
video cards.
|
||||
|
||||
DisplayID provides two methods for display identification:
|
||||
- Apple monitor sense codes as described in the Technical Note HW30
|
||||
- Apple monitor sense as described in the Technical Note HW30
|
||||
- Display Data Channel (DDC) standardized by VESA
|
||||
*/
|
||||
|
||||
@@ -35,6 +35,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
/* Supported diplay ID methods. */
|
||||
enum class Disp_Id_Kind {
|
||||
AppleSense,
|
||||
DDC2B,
|
||||
};
|
||||
|
||||
/** I2C bus states. */
|
||||
enum I2CState : uint8_t {
|
||||
STOP = 0, /* transaction started */
|
||||
@@ -49,7 +55,7 @@ enum I2CState : uint8_t {
|
||||
|
||||
class DisplayID {
|
||||
public:
|
||||
DisplayID();
|
||||
DisplayID(Disp_Id_Kind id_kind);
|
||||
~DisplayID() = default;
|
||||
|
||||
uint16_t read_monitor_sense(uint16_t data, uint16_t dirs);
|
||||
@@ -59,7 +65,7 @@ protected:
|
||||
uint16_t update_ddc_i2c(uint8_t sda, uint8_t scl);
|
||||
|
||||
private:
|
||||
bool i2c_on;
|
||||
Disp_Id_Kind id_kind;
|
||||
|
||||
uint8_t std_sense_code;
|
||||
uint8_t ext_sense_code;
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Video Conroller base class implementation. */
|
||||
|
||||
#include "videoctrl.h"
|
||||
#include <loguru.hpp>
|
||||
#include <SDL.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
|
||||
VideoCtrlBase::VideoCtrlBase()
|
||||
{
|
||||
LOG_F(INFO, "Create display window...");
|
||||
|
||||
// Create display window
|
||||
this->display_wnd = SDL_CreateWindow(
|
||||
"DingusPPC Display",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
640,
|
||||
480,
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
|
||||
if (this->display_wnd == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateWindow failed with %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
this->renderer = SDL_CreateRenderer(this->display_wnd, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (this->renderer == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateRenderer failed with %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(this->renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
|
||||
// Stupidly poll for 10 events.
|
||||
// Otherwise no window will be shown on mac OS!
|
||||
SDL_Event e;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
SDL_PollEvent(&e);
|
||||
}
|
||||
|
||||
this->disp_texture = SDL_CreateTexture(
|
||||
this->renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
640, 480
|
||||
);
|
||||
|
||||
if (this->disp_texture == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateTexture failed with %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
VideoCtrlBase::~VideoCtrlBase()
|
||||
{
|
||||
if (this->disp_texture) {
|
||||
SDL_DestroyTexture(this->disp_texture);
|
||||
}
|
||||
|
||||
if (this->renderer) {
|
||||
SDL_DestroyRenderer(this->renderer);
|
||||
}
|
||||
|
||||
if (this->display_wnd) {
|
||||
SDL_DestroyWindow(this->display_wnd);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoCtrlBase::update_screen()
|
||||
{
|
||||
uint8_t* dst_buf;
|
||||
int dst_pitch;
|
||||
|
||||
//auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
SDL_LockTexture(this->disp_texture, NULL, (void **)&dst_buf, &dst_pitch);
|
||||
|
||||
// call texture update method (hardcoded for now)
|
||||
// TODO: convert it to a callback
|
||||
this->convert_frame_8bpp(dst_buf, dst_pitch);
|
||||
|
||||
SDL_UnlockTexture(this->disp_texture);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderCopy(this->renderer, this->disp_texture, NULL, NULL);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
|
||||
// HW cursor data is stored at the beginning of the video memory
|
||||
// HACK: use src_offset to recognize cursor data being ready
|
||||
// Normally, we should check GEN_CUR_ENABLE bit in the GEN_TEST_CNTL register
|
||||
//if (src_offset > 0x400 && READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET])) {
|
||||
// this->draw_hw_cursor(dst_buf + dst_pitch * 20 + 120, dst_pitch);
|
||||
//}
|
||||
|
||||
//auto end_time = std::chrono::steady_clock::now();
|
||||
//auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
//LOG_F(INFO, "Display uodate took: %lld ns", time_elapsed.count());
|
||||
|
||||
SDL_Delay(15);
|
||||
}
|
||||
|
||||
void VideoCtrlBase::convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
{
|
||||
uint8_t *src_buf, *src_row, *dst_row, pix;
|
||||
int src_pitch;
|
||||
|
||||
src_buf = this->fb_ptr;
|
||||
src_pitch = this->fb_pitch;
|
||||
|
||||
for (int h = 0; h < this->active_height; h++) {
|
||||
src_row = &src_buf[h * src_pitch];
|
||||
dst_row = &dst_buf[h * dst_pitch];
|
||||
|
||||
for (int x = 0; x < this->active_width; x++) {
|
||||
pix = src_row[x];
|
||||
dst_row[0] = this->palette[pix][2]; // B
|
||||
dst_row[1] = this->palette[pix][1]; // G
|
||||
dst_row[2] = this->palette[pix][0]; // R
|
||||
dst_row[3] = 255; // Alpha
|
||||
dst_row += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Video Conroller base class definitions. */
|
||||
|
||||
#ifndef VIDEO_CTRL_H
|
||||
#define VIDEO_CTRL_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class VideoCtrlBase {
|
||||
public:
|
||||
VideoCtrlBase();
|
||||
~VideoCtrlBase();
|
||||
|
||||
void update_screen(void);
|
||||
|
||||
void convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
protected:
|
||||
/* CRT controller parameters */
|
||||
bool crtc_on = false;
|
||||
int active_width; // width of the visible display area
|
||||
int active_height; // height of the visible display area
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
uint8_t palette[256][4]; /* internal DAC palette in RGBA format */
|
||||
|
||||
// Framebuffer parameters
|
||||
uint8_t* fb_ptr;
|
||||
int fb_pitch;
|
||||
|
||||
private:
|
||||
SDL_Window *display_wnd;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *disp_texture;
|
||||
};
|
||||
|
||||
#endif // VIDEO_CTRL_H
|
||||
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Macros for performing byte swapping for quick endian conversion.
|
||||
|
||||
It will try to use the fast built-in machine instructions first
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,7 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <interpreter_loop.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
|
||||
std::chrono::high_resolution_clock::time_point global; // global timer
|
||||
@@ -108,4 +108,4 @@ void interpreter_main_loop() {
|
||||
|
||||
interpreter_update_counters();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -20,4 +20,4 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void interpreter_update_counters();
|
||||
void interpreter_main_loop();
|
||||
void interpreter_main_loop();
|
||||
@@ -1,6 +1,8 @@
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/devices"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
#include "machinebase.h"
|
||||
#include "devices/hwcomponent.h"
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
std::unique_ptr<MachineBase> gMachineObj = 0;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,7 +27,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_BASE_H
|
||||
#define MACHINE_BASE_H
|
||||
|
||||
#include "devices/hwcomponent.h"
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
+26
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,10 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "machinefactory.h"
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "memaccess.h"
|
||||
#include "machineproperties.h"
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
@@ -36,8 +38,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -76,6 +78,13 @@ static const PropMap GossamerSettings = {
|
||||
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
|
||||
};
|
||||
|
||||
static const PropMap PDMSettings = {
|
||||
{"rambank1_size",
|
||||
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}))},
|
||||
};
|
||||
|
||||
static const map<string, string> PropHelp = {
|
||||
{"rambank1_size", "specifies RAM bank 1 size in MB"},
|
||||
{"rambank2_size", "specifies RAM bank 2 size in MB"},
|
||||
@@ -83,8 +92,9 @@ static const map<string, string> PropHelp = {
|
||||
{"gfxmem_size", "specifies video memory size in MB"},
|
||||
};
|
||||
|
||||
static const map<string, tuple<PropMap, function<int(void)>, string>> machines = {
|
||||
{"pmg3", {GossamerSettings, create_gossamer, "Power Macintosh G3 (Beige)"}},
|
||||
static const map<string, tuple<PropMap, function<int(string&)>, string>> machines = {
|
||||
{"pm6100", {PDMSettings, create_pdm, "PowerMacintosh 6100"}},
|
||||
{"pmg3", {GossamerSettings, create_gossamer, "Power Macintosh G3 (Beige)"}},
|
||||
};
|
||||
|
||||
string machine_name_from_rom(string& rom_filepath) {
|
||||
@@ -226,6 +236,7 @@ int load_boot_rom(string& rom_filepath) {
|
||||
ifstream rom_file;
|
||||
size_t file_size;
|
||||
int result;
|
||||
AddressMapEntry *rom_reg;
|
||||
|
||||
rom_file.open(rom_filepath, ios::in | ios::binary);
|
||||
if (rom_file.fail()) {
|
||||
@@ -250,7 +261,12 @@ int load_boot_rom(string& rom_filepath) {
|
||||
MemCtrlBase* mem_ctrl = dynamic_cast<MemCtrlBase*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
mem_ctrl->set_data(0xFFC00000, sysrom_mem, file_size);
|
||||
if ((rom_reg = mem_ctrl->find_rom_region())) {
|
||||
mem_ctrl->set_data(rom_reg->start, sysrom_mem, file_size);
|
||||
} else {
|
||||
ABORT_F("Could not locate physical ROM region!");
|
||||
}
|
||||
|
||||
delete[] sysrom_mem;
|
||||
|
||||
result = 0;
|
||||
@@ -267,7 +283,7 @@ int create_machine_for_id(string& id, string& rom_filepath) {
|
||||
auto machine = machines.at(id);
|
||||
|
||||
/* build machine and load boot ROM */
|
||||
if (get<1>(machine)() < 0 || load_boot_rom(rom_filepath) < 0) {
|
||||
if (get<1>(machine)(id) < 0 || load_boot_rom(rom_filepath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} catch(out_of_range ex) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,7 +27,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_FACTORY_H
|
||||
#define MACHINE_FACTORY_H
|
||||
|
||||
#include "machinebase.h"
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
@@ -42,6 +43,7 @@ void list_machines(void);
|
||||
void list_properties(void);
|
||||
|
||||
/* Machine-specific factory functions. */
|
||||
int create_gossamer(void);
|
||||
int create_gossamer(string& id);
|
||||
int create_pdm(string& id);
|
||||
|
||||
#endif /* MACHINE_FACTORY_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,17 +24,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "devices/atirage.h"
|
||||
#include "devices/machineid.h"
|
||||
#include "devices/soundserver.h"
|
||||
#include "devices/macio.h"
|
||||
#include "devices/mpc106.h"
|
||||
#include "devices/spdram.h"
|
||||
#include "devices/viacuda.h"
|
||||
#include "machinebase.h"
|
||||
#include "machineproperties.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <devices/memctrl/spdram.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <devices/video/atirage.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
||||
@@ -51,7 +52,7 @@ static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
||||
}
|
||||
|
||||
|
||||
int create_gossamer() {
|
||||
int create_gossamer(std::string& id) {
|
||||
if (gMachineObj) {
|
||||
LOG_F(ERROR, "Global machine object not empty!");
|
||||
return -1;
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
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 Construct a PDM-style PowerMacintosh machine.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/ioctrl/amic.h>
|
||||
#include <devices/memctrl/hmc.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
int create_pdm(std::string& id) {
|
||||
if (gMachineObj) {
|
||||
LOG_F(ERROR, "PDM Factory: global machine object not empty!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initializing the %s hardware...", id.c_str());
|
||||
|
||||
/* initialize the global machine object */
|
||||
gMachineObj.reset(new MachineBase("PDM"));
|
||||
|
||||
/* register HMC memory controller */
|
||||
gMachineObj->add_component("HMC", new HMC);
|
||||
|
||||
/* start the sound server. */
|
||||
gMachineObj->add_component("SoundServer", new SoundServer());
|
||||
|
||||
/* register AMIC I/O controller */
|
||||
gMachineObj->add_component("AMIC", new AMIC);
|
||||
|
||||
/* get raw pointer to HMC object */
|
||||
HMC* hmc_obj = dynamic_cast<HMC*>(gMachineObj->get_comp_by_name("HMC"));
|
||||
|
||||
/* allocate machine ID register and tell we're running PowerMac 6100 */
|
||||
// TODO: add a possibility to select another machine
|
||||
// to be used with the same ROM
|
||||
gMachineObj->add_component("MachineID", new NubusMacID(0x3010));
|
||||
hmc_obj->add_mmio_region(0x5FFFFFFC, 4,
|
||||
dynamic_cast<MMIODevice*>(gMachineObj->get_comp_by_name("MachineID")));
|
||||
|
||||
/* allocate ROM region */
|
||||
if (!hmc_obj->add_rom_region(0x40000000, 0x400000)) {
|
||||
LOG_F(ERROR, "Could not allocate ROM region!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* mirror ROM to 0xFFC00000 for a PowerPC CPU to start */
|
||||
if (!hmc_obj->add_mem_mirror(0xFFC00000, 0x40000000)) {
|
||||
LOG_F(ERROR, "Could not create ROM mirror!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* add 8MB of soldered on-board RAM */
|
||||
if (!hmc_obj->add_ram_region(0x00000000, 0x800000)) {
|
||||
LOG_F(ERROR, "Could not allocate built-in RAM region!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Init virtual CPU and request MPC601 */
|
||||
ppc_cpu_init(hmc_obj, PPC_VER::MPC601);
|
||||
|
||||
LOG_F(INFO, "Initialization completed.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +1,26 @@
|
||||
#include "machineproperties.h"
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
static std::map<std::string, StrProperty> PowerMac6100_Properties = {
|
||||
@@ -36,4 +58,4 @@ static std::map<std::string, uint32_t> PPC_CPUs = {
|
||||
static std::map<std::string, uint32_t> GFX_CARDs = {
|
||||
{"ATI_Rage_Pro", 0x10024750},
|
||||
{"ATI_Rage_128_Pro", 0x10025052}
|
||||
};
|
||||
};
|
||||
@@ -1,11 +1,33 @@
|
||||
#include "endianswap.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
/*
|
||||
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 <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,19 +26,38 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "execution/interpreter_loop.h"
|
||||
#include "machines/machinefactory.h"
|
||||
#include "machines/machineproperties.h"
|
||||
#include "utils/profiler.h"
|
||||
#include "ppcemu.h"
|
||||
#include <cinttypes>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <thirdparty/CLI11/CLI11.hpp>
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <CLI11.hpp>
|
||||
#include <SDL.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void sigint_handler(int signum) {
|
||||
enter_debugger();
|
||||
|
||||
LOG_F(INFO, "Shutting down...");
|
||||
|
||||
delete gMachineObj.release();
|
||||
SDL_Quit();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void sigabrt_handler(int signum) {
|
||||
LOG_F(INFO, "Shutting down...");
|
||||
|
||||
delete gMachineObj.release();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
static string appDescription = string(
|
||||
"\nDingusPPC - Prototype 5bf5 (8/23/2020) "
|
||||
"\nWritten by divingkatae and maximumspatium "
|
||||
@@ -64,7 +83,7 @@ int main(int argc, char** argv) {
|
||||
app.allow_windows_style_options(); /* we want Windows-style options */
|
||||
app.allow_extras();
|
||||
|
||||
bool realtime_enabled, debugger_enabled = false;
|
||||
bool realtime_enabled, debugger_enabled;
|
||||
string machine_str;
|
||||
string bootrom_path("bootrom.bin");
|
||||
|
||||
@@ -117,7 +136,7 @@ int main(int argc, char** argv) {
|
||||
loguru::init(argc, argv);
|
||||
loguru::add_file("dingusppc.log", loguru::Append, 0);
|
||||
} else {
|
||||
loguru::g_stderr_verbosity = 0;
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
|
||||
loguru::init(argc, argv);
|
||||
}
|
||||
|
||||
@@ -153,16 +172,30 @@ int main(int argc, char** argv) {
|
||||
cout << "BootROM path: " << bootrom_path << endl;
|
||||
cout << "Execution mode: " << execution_mode << endl;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO)) {
|
||||
LOG_F(ERROR, "SDL_Init error: %s", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// initialize global profiler object
|
||||
gProfilerObj.reset(new Profiler());
|
||||
|
||||
if (create_machine_for_id(machine_str, bootrom_path) < 0) {
|
||||
goto bail;
|
||||
}
|
||||
|
||||
#ifdef SDL
|
||||
if (SDL_Init(SDL_INIT_AUDIO)){
|
||||
LOG_F(ERROR, "SDL_Init error: %s", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
// graceful handling of fatal errors
|
||||
loguru::set_fatal_handler([](const loguru::Message& message) {
|
||||
enter_debugger();
|
||||
|
||||
abort();
|
||||
});
|
||||
|
||||
// redirect SIGINT to our own handler
|
||||
signal(SIGINT, sigint_handler);
|
||||
|
||||
// redirect SIGABRT to our own handler
|
||||
signal(SIGABRT, sigabrt_handler);
|
||||
|
||||
switch (execution_mode) {
|
||||
case 0:
|
||||
@@ -181,5 +214,7 @@ bail:
|
||||
|
||||
delete gMachineObj.release();
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+68
-31
@@ -1,4 +1,25 @@
|
||||
/** @file Set of macros for accessing host memory units of various sizes
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Set of macros for accessing host memory in units of various sizes
|
||||
and endianness.
|
||||
*/
|
||||
|
||||
@@ -7,7 +28,7 @@
|
||||
|
||||
#include "endianswap.h"
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/* read an aligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_A(addr) (BYTESWAP_16(*((uint16_t*)((addr)))))
|
||||
@@ -31,25 +52,28 @@
|
||||
#define READ_WORD_BE_U(addr) (((addr)[0] << 8) | (addr)[1])
|
||||
|
||||
/* read an unaligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_U(addr) (((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
|
||||
#define READ_DWORD_BE_U(addr) \
|
||||
(((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
|
||||
|
||||
/* read an unaligned big-endian QWORD (32bit) */
|
||||
#define READ_QWORD_BE_U(addr) \
|
||||
(((addr)[0] << 56) | ((addr)[1] << 48) | ((addr)[2] << 40) | ((addr)[3] << 32) | \
|
||||
((addr)[4] << 24) | ((addr)[5] << 16) | ((addr)[6] << 8) | (addr)[7])
|
||||
#define READ_QWORD_BE_U(addr) \
|
||||
((uint64_t((addr)[0]) << 56) | (uint64_t((addr)[1]) << 48) | \
|
||||
(uint64_t((addr)[2]) << 40) | (uint64_t((addr)[3]) << 32) | \
|
||||
((addr)[4] << 24) | ((addr)[5] << 16) | ((addr)[6] << 8) | (addr)[7])
|
||||
|
||||
/* read an unaligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_U(addr) (((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_U(addr) (((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
#define READ_DWORD_LE_U(addr) \
|
||||
(((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_QWORD_LE_U(addr) \
|
||||
(((addr)[7] << 56) | ((addr)[6] << 48) | ((addr)[5] << 40) | ((addr)[4] << 32) | \
|
||||
/* read an unaligned little-endian DWORD (64bit) */
|
||||
#define READ_QWORD_LE_U(addr) \
|
||||
((uint64_t((addr)[7]) << 56) | (uint64_t((addr)[6]) << 48) | \
|
||||
(uint64_t((addr)[5]) << 40) | (uint64_t((addr)[4]) << 32) | \
|
||||
((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
|
||||
/* write an aligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_A(addr, val) (*((uint16_t*)((addr))) = BYTESWAP_16(val))
|
||||
|
||||
@@ -60,19 +84,32 @@
|
||||
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)((addr))) = BYTESWAP_64(val))
|
||||
|
||||
/* write an unaligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[1] = (val)&0xFF; \
|
||||
#define WRITE_WORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[1] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[1] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[3] = (val)&0xFF; \
|
||||
#define WRITE_DWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[1] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[3] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned big-endian DWORD (64bit) */
|
||||
#define WRITE_QWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((uint64_t)(val) >> 56) & 0xFF; \
|
||||
(addr)[1] = ((uint64_t)(val) >> 48) & 0xFF; \
|
||||
(addr)[2] = ((uint64_t)(val) >> 40) & 0xFF; \
|
||||
(addr)[3] = ((uint64_t)(val) >> 32) & 0xFF; \
|
||||
(addr)[4] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[5] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[6] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[7] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an aligned little-endian WORD (16bit) */
|
||||
@@ -85,19 +122,19 @@
|
||||
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)((addr))) = (val))
|
||||
|
||||
/* write an unaligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
#define WRITE_WORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[3] = ((val) >> 24) & 0xFF; \
|
||||
#define WRITE_DWORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[3] = ((val) >> 24) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* read value of the specified size from memory starting at addr,
|
||||
|
||||
Vendored
+1
-1
Submodule thirdparty/cubeb updated: 524a9c99b4...d512bfa07a.
@@ -1,3 +0,0 @@
|
||||
build/
|
||||
build-win32/
|
||||
build-win64/
|
||||
Vendored
-78
@@ -1,78 +0,0 @@
|
||||
### Version 1.1.0 (2016-01-31)
|
||||
|
||||
* JACK: delete broken pause implementation. Previously, calling
|
||||
`soundio_outstream_pause` or `soundio_instream_pause` during the
|
||||
`write_callback` or `read_callback` would cause a deadlock. Now, attempting
|
||||
to pause always results in `SoundIoErrorBackendIncompatible`.
|
||||
* PulseAudio: improve latency handling code. It now passes the latency test
|
||||
along with all the other backends.
|
||||
* PulseAudio: fix incorrect outstream `software_latency`.
|
||||
* libsoundio source code is now pure C, no C++ mixed in.
|
||||
* ALSA: better device detection.
|
||||
- No longer suppress sysdefault.
|
||||
- If default and sysdefault are missing, use the first device as the default
|
||||
device.
|
||||
* Workaround for Raspberry Pi driver that incorrectly reports itself as Output
|
||||
when it is actually Input.
|
||||
* ALSA: let alsa lib choose period settings. Fixes behavior with many ALSA
|
||||
devices.
|
||||
* ALSA: fix potential cleanup deadlock.
|
||||
* ALSA: fix crash for devices with null description, thanks to Charles Lehner.
|
||||
* CoreAudio: drop support for MacOS 10.9. There was a bug for this system that
|
||||
was never resolved, so it didn't work in the first place.
|
||||
* Record example handles device not found and probe errors gracefully.
|
||||
* Fix typo in microphone example, thanks to James Dyson.
|
||||
* Improve documentation.
|
||||
* New functions available: `soundio_version_string`, `soundio_version_major`,
|
||||
`soundio_version_minor`, `soundio_version_patch`.
|
||||
* libsoundio source code now builds with MSVC, thanks to Raphaël Londeix.
|
||||
|
||||
### Version 1.0.3 (2015-10-20)
|
||||
|
||||
* Architecture independent header files.
|
||||
* Add --latency and --sample-rate to sine example.
|
||||
* ALSA: fix deadlock under some circumstances.
|
||||
* dummy: fix deadlock when pause called from `write_callback`.
|
||||
* Fix double clean-up corruption when opening stream fails.
|
||||
* Add --device and --raw to underflow test.
|
||||
* ALSA: use period size to calculate buffer size, fixes opening output stream
|
||||
sometimes resulting in an error.
|
||||
|
||||
### Version 1.0.2 (2015-09-24)
|
||||
|
||||
* build: fix GNUInstallDirs not working.
|
||||
* docs: fix incorrect docs for `soundio_instream_pause`.
|
||||
* PulseAudio: fix `soundio_outstream_pause` triggering assertion when called
|
||||
from within `write_callback`.
|
||||
* fix mirrored memory not working on Linux (fixes corrupted data in ring
|
||||
buffer).
|
||||
* os: fix crash when creating non high priority thread fails.
|
||||
* docs: fix typos and cleanup.
|
||||
* fix and add test for `soundio_device_nearest_sample_rate`.
|
||||
|
||||
### Version 1.0.1 (2015-09-11)
|
||||
|
||||
* libsoundio no longer depends on or links against libm.
|
||||
* ALSA: treat ALSA as unavailable when /dev/snd does not exist.
|
||||
* ALSA: remove duplicate assert.
|
||||
* ALSA: remove stray print statement.
|
||||
* ALSA: pausing returns error code when state is invalid instead of reaching
|
||||
assertion failure in pcm.c.
|
||||
* JACK: fix infinite loop when refreshing devices.
|
||||
* PulseAudio: better clear buffer implementation.
|
||||
* dummy backend: fix sometimes calling `write_callback` with
|
||||
`frame_count_max` equal to 0.
|
||||
* os: fix some variables accidentally not declared static.
|
||||
* macos: fix not cleaning up condition variables.
|
||||
* macos: avoid allocation when getting time.
|
||||
* docs: note that `read_callback` and `write_callback` must be real time safe.
|
||||
* docs: record example demonstrates proper real time safety by not calling
|
||||
fwrite in `read_callback`.
|
||||
* docs: add note to record example about shutting down.
|
||||
* docs: make microphone example latency a command line argument.
|
||||
* build: fix build on linux with clang.
|
||||
* build: static libs, examples, and tests are optional.
|
||||
|
||||
### Version 1.0.0 (2015-09-03)
|
||||
|
||||
* Initial public release.
|
||||
Vendored
-388
@@ -1,388 +0,0 @@
|
||||
cmake_minimum_required(VERSION 2.8.5)
|
||||
project(libsoundio C)
|
||||
set(CMAKE_MODULE_PATH ${libsoundio_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.0.0)
|
||||
set(CMAKE_INSTALL_LIBDIR "lib" CACHE PATH "library install dir (lib)")
|
||||
set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE PATH "header base install dir (include)")
|
||||
set(CMAKE_INSTALL_BINDIR "bin" CACHE PATH "user executables (bin)")
|
||||
else()
|
||||
cmake_policy(SET CMP0042 NEW)
|
||||
cmake_policy(SET CMP0046 NEW)
|
||||
include(GNUInstallDirs)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
|
||||
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
||||
endif()
|
||||
|
||||
set(LIBSOUNDIO_VERSION_MAJOR 2)
|
||||
set(LIBSOUNDIO_VERSION_MINOR 0)
|
||||
set(LIBSOUNDIO_VERSION_PATCH 0)
|
||||
set(LIBSOUNDIO_VERSION "${LIBSOUNDIO_VERSION_MAJOR}.${LIBSOUNDIO_VERSION_MINOR}.${LIBSOUNDIO_VERSION_PATCH}")
|
||||
message("Configuring libsoundio version ${LIBSOUNDIO_VERSION}")
|
||||
|
||||
if(NOT SOUNDIO_STATIC_LIBNAME)
|
||||
set(SOUNDIO_STATIC_LIBNAME soundio)
|
||||
endif()
|
||||
|
||||
option(BUILD_STATIC_LIBS "Build static libraries" ON)
|
||||
option(BUILD_DYNAMIC_LIBS "Build dynamic libraries" ON)
|
||||
option(BUILD_EXAMPLE_PROGRAMS "Build example programs" ON)
|
||||
option(BUILD_TESTS "Build tests" ON)
|
||||
option(ENABLE_JACK "Enable JACK backend" ON)
|
||||
option(ENABLE_PULSEAUDIO "Enable PulseAudio backend" ON)
|
||||
option(ENABLE_ALSA "Enable ALSA backend" ON)
|
||||
option(ENABLE_COREAUDIO "Enable CoreAudio backend" ON)
|
||||
option(ENABLE_WASAPI "Enable WASAPI backend" ON)
|
||||
|
||||
find_package(Threads)
|
||||
if(Threads_FOUND)
|
||||
set(STATUS_THREADS "OK")
|
||||
else(Threads_FOUND)
|
||||
set(STATUS_THREADS "not found")
|
||||
endif(Threads_FOUND)
|
||||
|
||||
if(ENABLE_JACK)
|
||||
find_package(JACK)
|
||||
if(JACK_FOUND)
|
||||
set(STATUS_JACK "OK")
|
||||
set(SOUNDIO_HAVE_JACK true)
|
||||
include_directories(${JACK_INCLUDE_DIR})
|
||||
else()
|
||||
set(STATUS_JACK "not found")
|
||||
set(SOUNDIO_HAVE_JACK false)
|
||||
set(JACK_LIBRARY "")
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_JACK "disabled")
|
||||
set(SOUNDIO_HAVE_JACK false)
|
||||
set(JACK_LIBRARY "")
|
||||
endif()
|
||||
|
||||
if(ENABLE_PULSEAUDIO)
|
||||
find_package(PulseAudio)
|
||||
if(PULSEAUDIO_FOUND)
|
||||
set(STATUS_PULSEAUDIO "OK")
|
||||
set(SOUNDIO_HAVE_PULSEAUDIO true)
|
||||
include_directories(${PULSEAUDIO_INCLUDE_DIR})
|
||||
else()
|
||||
set(STATUS_PULSEAUDIO "not found")
|
||||
set(SOUNDIO_HAVE_PULSEAUDIO false)
|
||||
set(PULSEAUDIO_LIBRARY "")
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_PULSEAUDIO "disabled")
|
||||
set(SOUNDIO_HAVE_PULSEAUDIO false)
|
||||
set(PULSEAUDIO_LIBRARY "")
|
||||
endif()
|
||||
|
||||
if(ENABLE_ALSA)
|
||||
find_package(ALSA)
|
||||
if(ALSA_FOUND)
|
||||
set(STATUS_ALSA "OK")
|
||||
set(SOUNDIO_HAVE_ALSA true)
|
||||
include_directories(${ALSA_INCLUDE_DIRS})
|
||||
else()
|
||||
set(STATUS_ALSA "not found")
|
||||
set(SOUNDIO_HAVE_ALSA false)
|
||||
set(ALSA_LIBRARIES "")
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_ALSA "disabled")
|
||||
set(SOUNDIO_HAVE_ALSA false)
|
||||
set(ALSA_LIBRARIES "")
|
||||
endif()
|
||||
|
||||
if(ENABLE_COREAUDIO)
|
||||
find_package(CoreAudio)
|
||||
if(COREAUDIO_FOUND)
|
||||
set(STATUS_COREAUDIO "OK")
|
||||
set(SOUNDIO_HAVE_COREAUDIO true)
|
||||
include_directories(${COREAUDIO_INCLUDE_DIR})
|
||||
|
||||
find_path(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
|
||||
find_library(COREFOUNDATION_LIBRARY NAMES CoreFoundation)
|
||||
include_directories(${COREFOUNDATION_INCLUDE_DIR})
|
||||
|
||||
find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit.h)
|
||||
find_library(AUDIOUNIT_LIBRARY NAMES AudioUnit)
|
||||
include_directories(${AUDIOUNIT_INCLUDE_DIR})
|
||||
else()
|
||||
set(STATUS_COREAUDIO "not found")
|
||||
set(SOUNDIO_HAVE_COREAUDIO false)
|
||||
set(COREAUDIO_LIBRARY "")
|
||||
set(COREFOUNDATION_LIBRARY "")
|
||||
set(AUDIOUNIT_LIBRARY "")
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_COREAUDIO "disabled")
|
||||
set(SOUNDIO_HAVE_COREAUDIO false)
|
||||
set(COREAUDIO_LIBRARY "")
|
||||
set(COREFOUNDATION_LIBRARY "")
|
||||
set(AUDIOUNIT_LIBRARY "")
|
||||
endif()
|
||||
|
||||
if(ENABLE_WASAPI)
|
||||
find_package(WASAPI)
|
||||
if(WASAPI_FOUND)
|
||||
set(STATUS_WASAPI "OK")
|
||||
set(SOUNDIO_HAVE_WASAPI true)
|
||||
else()
|
||||
set(STATUS_WASAPI "not found")
|
||||
set(SOUNDIO_HAVE_WASAPI false)
|
||||
endif()
|
||||
else()
|
||||
set(STATUS_WASAPI "disabled")
|
||||
set(SOUNDIO_HAVE_WASAPI false)
|
||||
endif()
|
||||
|
||||
|
||||
set(LIBSOUNDIO_SOURCES
|
||||
"${libsoundio_SOURCE_DIR}/src/soundio.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/util.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/os.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/dummy.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/channel_layout.c"
|
||||
"${libsoundio_SOURCE_DIR}/src/ring_buffer.c"
|
||||
)
|
||||
|
||||
set(CONFIGURE_OUT_FILE "${libsoundio_BINARY_DIR}/config.h")
|
||||
set(LIBSOUNDIO_HEADERS
|
||||
"${libsoundio_SOURCE_DIR}/soundio/soundio.h"
|
||||
"${libsoundio_SOURCE_DIR}/soundio/endian.h"
|
||||
)
|
||||
|
||||
if(SOUNDIO_HAVE_JACK)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/jack.c"
|
||||
)
|
||||
endif()
|
||||
if(SOUNDIO_HAVE_PULSEAUDIO)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/pulseaudio.c"
|
||||
)
|
||||
endif()
|
||||
if(SOUNDIO_HAVE_ALSA)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/alsa.c"
|
||||
)
|
||||
endif()
|
||||
if(SOUNDIO_HAVE_COREAUDIO)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/coreaudio.c"
|
||||
)
|
||||
endif()
|
||||
if(SOUNDIO_HAVE_WASAPI)
|
||||
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
|
||||
"${libsoundio_SOURCE_DIR}/src/wasapi.c"
|
||||
)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${libsoundio_SOURCE_DIR}
|
||||
${libsoundio_BINARY_DIR}
|
||||
"${libsoundio_SOURCE_DIR}/test"
|
||||
"${libsoundio_SOURCE_DIR}/src"
|
||||
)
|
||||
|
||||
set(LIBSOUNDIO_LIBS
|
||||
${JACK_LIBRARY}
|
||||
${PULSEAUDIO_LIBRARY}
|
||||
${ALSA_LIBRARIES}
|
||||
${COREAUDIO_LIBRARY}
|
||||
${COREFOUNDATION_LIBRARY}
|
||||
${AUDIOUNIT_LIBRARY}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Wall")
|
||||
set(LIB_CFLAGS "/TP /W4")
|
||||
set(EXAMPLE_CFLAGS "/W4")
|
||||
set(TEST_CFLAGS "${LIB_CFLAGS}")
|
||||
set(TEST_LDFLAGS " ")
|
||||
set(LIBM " ")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror -pedantic")
|
||||
set(LIB_CFLAGS "-std=c11 -fvisibility=hidden -Wall -Werror=strict-prototypes -Werror=old-style-definition -Werror=missing-prototypes -D_REENTRANT -D_POSIX_C_SOURCE=200809L -Wno-missing-braces")
|
||||
set(EXAMPLE_CFLAGS "-std=c99 -Wall")
|
||||
set(TEST_CFLAGS "${LIB_CFLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(TEST_LDFLAGS "-fprofile-arcs -ftest-coverage")
|
||||
set(LIBM "m")
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
"${libsoundio_SOURCE_DIR}/src/config.h.in"
|
||||
${CONFIGURE_OUT_FILE}
|
||||
)
|
||||
set(DOXYGEN_CONF_FILE "${libsoundio_BINARY_DIR}/doxygen.conf")
|
||||
configure_file(
|
||||
"${libsoundio_SOURCE_DIR}/doc/doxygen.conf.in"
|
||||
${DOXYGEN_CONF_FILE}
|
||||
)
|
||||
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
add_library(libsoundio_shared SHARED ${LIBSOUNDIO_SOURCES})
|
||||
set_target_properties(libsoundio_shared PROPERTIES
|
||||
OUTPUT_NAME soundio
|
||||
SOVERSION ${LIBSOUNDIO_VERSION_MAJOR}
|
||||
VERSION ${LIBSOUNDIO_VERSION}
|
||||
COMPILE_FLAGS ${LIB_CFLAGS}
|
||||
LINKER_LANGUAGE C
|
||||
)
|
||||
target_link_libraries(libsoundio_shared LINK_PUBLIC ${LIBSOUNDIO_LIBS})
|
||||
install(TARGETS libsoundio_shared DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
if(BUILD_STATIC_LIBS)
|
||||
add_library(libsoundio_static STATIC ${LIBSOUNDIO_SOURCES})
|
||||
set_target_properties(libsoundio_static PROPERTIES
|
||||
OUTPUT_NAME ${SOUNDIO_STATIC_LIBNAME}
|
||||
COMPILE_FLAGS ${LIB_CFLAGS}
|
||||
LINKER_LANGUAGE C
|
||||
)
|
||||
install(TARGETS libsoundio_static DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
install(FILES
|
||||
${LIBSOUNDIO_HEADERS}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/soundio")
|
||||
|
||||
# Example Programs
|
||||
|
||||
if(BUILD_EXAMPLE_PROGRAMS)
|
||||
add_executable(sio_sine example/sio_sine.c)
|
||||
set_target_properties(sio_sine PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(sio_sine libsoundio_shared ${LIBM})
|
||||
else()
|
||||
target_link_libraries(sio_sine libsoundio_static ${LIBSOUNDIO_LIBS} ${LIBM})
|
||||
endif()
|
||||
install(TARGETS sio_sine DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
add_executable(sio_list_devices example/sio_list_devices.c)
|
||||
set_target_properties(sio_list_devices PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(sio_list_devices libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(sio_list_devices libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
install(TARGETS sio_list_devices DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
add_executable(sio_microphone example/sio_microphone.c)
|
||||
set_target_properties(sio_microphone PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(sio_microphone libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(sio_microphone libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
install(TARGETS sio_microphone DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
add_executable(sio_record example/sio_record.c)
|
||||
set_target_properties(sio_record PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(sio_record libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(sio_record libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
install(TARGETS sio_record DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTS)
|
||||
add_executable(unit_tests "${libsoundio_SOURCE_DIR}/test/unit_tests.c" ${LIBSOUNDIO_SOURCES})
|
||||
target_link_libraries(unit_tests LINK_PUBLIC ${LIBSOUNDIO_LIBS})
|
||||
set_target_properties(unit_tests PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${TEST_CFLAGS}
|
||||
LINK_FLAGS ${TEST_LDFLAGS}
|
||||
)
|
||||
|
||||
add_executable(latency "${libsoundio_SOURCE_DIR}/test/latency.c" ${LIBSOUNDIO_SOURCES})
|
||||
target_link_libraries(latency LINK_PUBLIC ${LIBSOUNDIO_LIBS} ${LIBM})
|
||||
set_target_properties(latency PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${LIB_CFLAGS}
|
||||
)
|
||||
|
||||
add_executable(underflow test/underflow.c)
|
||||
set_target_properties(underflow PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(underflow libsoundio_shared ${LIBM})
|
||||
else()
|
||||
target_link_libraries(underflow libsoundio_static ${LIBSOUNDIO_LIBS} ${LIBM})
|
||||
endif()
|
||||
|
||||
add_executable(backend_disconnect_recover test/backend_disconnect_recover.c)
|
||||
set_target_properties(backend_disconnect_recover PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(backend_disconnect_recover libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(backend_disconnect_recover libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
|
||||
add_executable(overflow test/overflow.c)
|
||||
set_target_properties(overflow PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
COMPILE_FLAGS ${EXAMPLE_CFLAGS})
|
||||
if(BUILD_DYNAMIC_LIBS)
|
||||
target_link_libraries(overflow libsoundio_shared)
|
||||
else()
|
||||
target_link_libraries(overflow libsoundio_static ${LIBSOUNDIO_LIBS})
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
add_custom_target(coverage
|
||||
DEPENDS unit_tests
|
||||
WORKING_DIRECTORY ${libsoundio_BINARY_DIR}
|
||||
COMMAND lcov --directory . --zerocounters --rc lcov_branch_coverage=1
|
||||
COMMAND ./unit_tests
|
||||
COMMAND lcov --directory . --capture --output-file coverage.info --rc lcov_branch_coverage=1
|
||||
COMMAND lcov --remove coverage.info '/usr/*' --output-file coverage.info.cleaned --rc lcov_branch_coverage=1
|
||||
COMMAND genhtml -o coverage coverage.info.cleaned --rc lcov_branch_coverage=1
|
||||
COMMAND rm coverage.info coverage.info.cleaned
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
add_custom_target(doc
|
||||
WORKING_DIRECTORY ${libsoundio_BINARY_DIR}
|
||||
COMMAND doxygen ${DOXYGEN_CONF_FILE}
|
||||
)
|
||||
|
||||
|
||||
|
||||
message("\n"
|
||||
"Installation Summary\n"
|
||||
"--------------------\n"
|
||||
"* Install Directory : ${CMAKE_INSTALL_PREFIX}\n"
|
||||
"* Build Type : ${CMAKE_BUILD_TYPE}\n"
|
||||
"* Build static libs : ${BUILD_STATIC_LIBS}\n"
|
||||
"* Build examples : ${BUILD_EXAMPLE_PROGRAMS}\n"
|
||||
"* Build tests : ${BUILD_TESTS}\n"
|
||||
)
|
||||
|
||||
message(
|
||||
"System Dependencies\n"
|
||||
"-------------------\n"
|
||||
"* threads : ${STATUS_THREADS}\n"
|
||||
"* JACK (optional) : ${STATUS_JACK}\n"
|
||||
"* PulseAudio (optional) : ${STATUS_PULSEAUDIO}\n"
|
||||
"* ALSA (optional) : ${STATUS_ALSA}\n"
|
||||
"* CoreAudio (optional) : ${STATUS_COREAUDIO}\n"
|
||||
"* WASAPI (optional) : ${STATUS_WASAPI}\n"
|
||||
)
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
The MIT License (Expat)
|
||||
|
||||
Copyright (c) 2015 Andrew Kelley
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
Vendored
-266
@@ -1,266 +0,0 @@
|
||||
# libsoundio
|
||||
|
||||
C library providing cross-platform audio input and output. The API is
|
||||
suitable for real-time software such as digital audio workstations as well
|
||||
as consumer software such as music players.
|
||||
|
||||
This library is an abstraction; however in the delicate balance between
|
||||
performance and power, and API convenience, the scale is tipped closer to
|
||||
the former. Features that only exist in some sound backends are exposed.
|
||||
|
||||
## Features and Limitations
|
||||
|
||||
* Supported operating systems:
|
||||
- Windows 7+
|
||||
- MacOS 10.10+
|
||||
- Linux 3.7+
|
||||
* Supported backends:
|
||||
- [JACK](http://jackaudio.org/)
|
||||
- [PulseAudio](http://www.freedesktop.org/wiki/Software/PulseAudio/)
|
||||
- [ALSA](http://www.alsa-project.org/)
|
||||
- [CoreAudio](https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/CoreAudioOverview/Introduction/Introduction.html)
|
||||
- [WASAPI](https://msdn.microsoft.com/en-us/library/windows/desktop/dd371455%28v=vs.85%29.aspx)
|
||||
- Dummy (silence)
|
||||
* Exposes both raw devices and shared devices. Raw devices give you the best
|
||||
performance but prevent other applications from using them. Shared devices
|
||||
are default and usually provide sample rate conversion and format
|
||||
conversion.
|
||||
* Exposes both device id and friendly name. id you could save in a config file
|
||||
because it persists between devices becoming plugged and unplugged, while
|
||||
friendly name is suitable for exposing to users.
|
||||
* Supports optimal usage of each supported backend. The same API does the
|
||||
right thing whether the backend has a fixed buffer size, such as on JACK and
|
||||
CoreAudio, or whether it allows directly managing the buffer, such as on
|
||||
ALSA, PulseAudio, and WASAPI.
|
||||
* C library. Depends only on the respective backend API libraries and libc.
|
||||
Does *not* depend on libstdc++, and does *not* have exceptions, run-time type
|
||||
information, or [setjmp](http://latentcontent.net/2007/12/05/libpng-worst-api-ever/).
|
||||
* Errors are communicated via return codes, not logging to stdio.
|
||||
* Supports channel layouts (also known as channel maps), important for
|
||||
surround sound applications.
|
||||
* Ability to monitor devices and get an event when available devices change.
|
||||
* Ability to get an event when the backend is disconnected, for example when
|
||||
the JACK server or PulseAudio server shuts down.
|
||||
* Detects which input device is default and which output device is default.
|
||||
* Ability to connect to multiple backends at once. For example you could have
|
||||
an ALSA device open and a JACK device open at the same time.
|
||||
* Meticulously checks all return codes and memory allocations and uses
|
||||
meaningful error codes.
|
||||
* Exposes extra API that is only available on some backends. For example you
|
||||
can provide application name and stream names which is used by JACK and
|
||||
PulseAudio.
|
||||
|
||||
## Synopsis
|
||||
|
||||
Complete program to emit a sine wave over the default device using the best
|
||||
backend:
|
||||
|
||||
```c
|
||||
#include <soundio/soundio.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
static const float PI = 3.1415926535f;
|
||||
static float seconds_offset = 0.0f;
|
||||
static void write_callback(struct SoundIoOutStream *outstream,
|
||||
int frame_count_min, int frame_count_max)
|
||||
{
|
||||
const struct SoundIoChannelLayout *layout = &outstream->layout;
|
||||
float float_sample_rate = outstream->sample_rate;
|
||||
float seconds_per_frame = 1.0f / float_sample_rate;
|
||||
struct SoundIoChannelArea *areas;
|
||||
int frames_left = frame_count_max;
|
||||
int err;
|
||||
|
||||
while (frames_left > 0) {
|
||||
int frame_count = frames_left;
|
||||
|
||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
|
||||
fprintf(stderr, "%s\n", soundio_strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!frame_count)
|
||||
break;
|
||||
|
||||
float pitch = 440.0f;
|
||||
float radians_per_second = pitch * 2.0f * PI;
|
||||
for (int frame = 0; frame < frame_count; frame += 1) {
|
||||
float sample = sinf((seconds_offset + frame * seconds_per_frame) * radians_per_second);
|
||||
for (int channel = 0; channel < layout->channel_count; channel += 1) {
|
||||
float *ptr = (float*)(areas[channel].ptr + areas[channel].step * frame);
|
||||
*ptr = sample;
|
||||
}
|
||||
}
|
||||
seconds_offset = fmodf(seconds_offset +
|
||||
seconds_per_frame * frame_count, 1.0f);
|
||||
|
||||
if ((err = soundio_outstream_end_write(outstream))) {
|
||||
fprintf(stderr, "%s\n", soundio_strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
frames_left -= frame_count;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int err;
|
||||
struct SoundIo *soundio = soundio_create();
|
||||
if (!soundio) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((err = soundio_connect(soundio))) {
|
||||
fprintf(stderr, "error connecting: %s", soundio_strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
soundio_flush_events(soundio);
|
||||
|
||||
int default_out_device_index = soundio_default_output_device_index(soundio);
|
||||
if (default_out_device_index < 0) {
|
||||
fprintf(stderr, "no output device found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct SoundIoDevice *device = soundio_get_output_device(soundio, default_out_device_index);
|
||||
if (!device) {
|
||||
fprintf(stderr, "out of memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Output device: %s\n", device->name);
|
||||
|
||||
struct SoundIoOutStream *outstream = soundio_outstream_create(device);
|
||||
outstream->format = SoundIoFormatFloat32NE;
|
||||
outstream->write_callback = write_callback;
|
||||
|
||||
if ((err = soundio_outstream_open(outstream))) {
|
||||
fprintf(stderr, "unable to open device: %s", soundio_strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (outstream->layout_error)
|
||||
fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error));
|
||||
|
||||
if ((err = soundio_outstream_start(outstream))) {
|
||||
fprintf(stderr, "unable to start device: %s", soundio_strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
soundio_wait_events(soundio);
|
||||
|
||||
soundio_outstream_destroy(outstream);
|
||||
soundio_device_unref(device);
|
||||
soundio_destroy(soundio);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Backend Priority
|
||||
|
||||
When you use `soundio_connect`, libsoundio tries these backends in order.
|
||||
If unable to connect to that backend, due to the backend not being installed,
|
||||
or the server not running, or the platform is wrong, the next backend is tried.
|
||||
|
||||
0. JACK
|
||||
0. PulseAudio
|
||||
0. ALSA (Linux)
|
||||
0. CoreAudio (OSX)
|
||||
0. WASAPI (Windows)
|
||||
0. Dummy
|
||||
|
||||
If you don't like this order, you can use `soundio_connect_backend` to
|
||||
explicitly choose a backend to connect to. You can use `soundio_backend_count`
|
||||
and `soundio_get_backend` to get the list of available backends.
|
||||
|
||||
[API Documentation](http://libsound.io/doc)
|
||||
|
||||
### Building
|
||||
|
||||
Install the dependencies:
|
||||
|
||||
* cmake
|
||||
* ALSA library (optional)
|
||||
* libjack2 (optional)
|
||||
* libpulseaudio (optional)
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
### Building for Windows
|
||||
|
||||
You can build libsoundio with [mxe](http://mxe.cc/). Follow the
|
||||
[requirements](http://mxe.cc/#requirements) section to install the
|
||||
packages necessary on your system. Then somewhere on your file system:
|
||||
|
||||
```
|
||||
git clone https://github.com/mxe/mxe
|
||||
cd mxe
|
||||
make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' gcc
|
||||
```
|
||||
|
||||
Then in the libsoundio source directory (replace "/path/to/mxe" with the
|
||||
appropriate path):
|
||||
|
||||
```
|
||||
mkdir build-win32
|
||||
cd build-win32
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake
|
||||
make
|
||||
```
|
||||
|
||||
```
|
||||
mkdir build-win64
|
||||
cd build-win64
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/x86_64-w64-mingw32.static/share/cmake/mxe-conf.cmake
|
||||
make
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
For each backend, do the following:
|
||||
|
||||
0. Run the unit tests: `./unit_tests`. To see test coverage, install lcov, run
|
||||
`make coverage`, and then view `coverage/index.html` in a browser.
|
||||
0. Run the example `./sio_list_devices` and make sure it does not crash, and
|
||||
the output looks good. If valgrind is available, use it.
|
||||
0. Run `./sio_list_devices --watch` and make sure it detects when you plug and
|
||||
unplug a USB microphone.
|
||||
0. Run `./sio_sine` and make sure you hear a sine wave. For backends with raw
|
||||
devices, run `./sio_sine --device id --raw` (where 'id' is a device id you
|
||||
got from `sio_list_devices` and make sure you hear a sine wave.
|
||||
- Use 'p' to test pausing, 'u' to test unpausing, 'q' to test cleanup.
|
||||
- 'c' for clear buffer. Clear buffer should not pause the stream and it
|
||||
should also not cause an underflow.
|
||||
- Use 'P' to test pausing from the callback, and then 'u' to unpause.
|
||||
0. Run `./underflow` and read the testing instructions that it prints.
|
||||
0. Run `./sio_microphone` and ensure that it is both recording and playing
|
||||
back correctly. If possible use the `--in-device` and `--out-device`
|
||||
parameters to test a USB microphone in raw mode.
|
||||
0. Run `./backend_disconnect_recover` and read the testing instructions that
|
||||
it prints.
|
||||
0. Run `./latency` and make sure the printed beeps line up with the beeps that
|
||||
you hear.
|
||||
|
||||
### Building the Documentation
|
||||
|
||||
Ensure that [doxygen](http://www.stack.nl/~dimitri/doxygen/) is installed,
|
||||
then:
|
||||
|
||||
```
|
||||
make doc
|
||||
```
|
||||
|
||||
Then look at `html/index.html` in a browser.
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# COREAUDIO_FOUND
|
||||
# COREAUDIO_INCLUDE_DIR
|
||||
# COREAUDIO_LIBRARY
|
||||
|
||||
find_path(COREAUDIO_INCLUDE_DIR NAMES CoreAudio/CoreAudio.h)
|
||||
|
||||
find_library(COREAUDIO_LIBRARY NAMES CoreAudio)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(COREAUDIO DEFAULT_MSG COREAUDIO_LIBRARY COREAUDIO_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(COREAUDIO_INCLUDE_DIR COREAUDIO_LIBRARY)
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# JACK_FOUND
|
||||
# JACK_INCLUDE_DIR
|
||||
# JACK_LIBRARY
|
||||
|
||||
find_path(JACK_INCLUDE_DIR NAMES jack/jack.h)
|
||||
|
||||
find_library(JACK_LIBRARY NAMES jack)
|
||||
|
||||
include(CheckLibraryExists)
|
||||
check_library_exists(jack "jack_set_port_rename_callback" "${JACK_LIBRARY}" HAVE_jack_set_port_rename_callback)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(JACK DEFAULT_MSG JACK_LIBRARY JACK_INCLUDE_DIR HAVE_jack_set_port_rename_callback)
|
||||
|
||||
mark_as_advanced(JACK_INCLUDE_DIR JACK_LIBRARY)
|
||||
@@ -1,16 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# PULSEAUDIO_FOUND
|
||||
# PULSEAUDIO_INCLUDE_DIR
|
||||
# PULSEAUDIO_LIBRARY
|
||||
|
||||
find_path(PULSEAUDIO_INCLUDE_DIR NAMES pulse/pulseaudio.h)
|
||||
|
||||
find_library(PULSEAUDIO_LIBRARY NAMES pulse)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(PULSEAUDIO DEFAULT_MSG PULSEAUDIO_LIBRARY PULSEAUDIO_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(PULSEAUDIO_INCLUDE_DIR PULSEAUDIO_LIBRARY)
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# WASAPI_FOUND
|
||||
# AUDIOCLIENT_H
|
||||
|
||||
if(WIN32)
|
||||
include(CheckIncludeFile)
|
||||
check_include_file(audioclient.h AUDIOCLIENT_H)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(WASAPI DEFAULT_MSG AUDIOCLIENT_H)
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
# Copyright (c) 2015 Andrew Kelley
|
||||
# This file is MIT licensed.
|
||||
# See http://opensource.org/licenses/MIT
|
||||
|
||||
# SOUNDIO_FOUND
|
||||
# SOUNDIO_INCLUDE_DIR
|
||||
# SOUNDIO_LIBRARY
|
||||
|
||||
find_path(SOUNDIO_INCLUDE_DIR NAMES soundio/soundio.h)
|
||||
|
||||
find_library(SOUNDIO_LIBRARY NAMES soundio)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(SOUNDIO DEFAULT_MSG SOUNDIO_LIBRARY SOUNDIO_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(SOUNDIO_INCLUDE_DIR SOUNDIO_LIBRARY)
|
||||
-2036
File diff suppressed because it is too large.
Load diff
-2
@@ -1,2 +0,0 @@
|
||||
</body>
|
||||
</html>
|
||||
-181
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Andrew Kelley
|
||||
*
|
||||
* This file is part of libsoundio, which is MIT licensed.
|
||||
* See http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <soundio/soundio.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// list or keep a watch on audio devices
|
||||
|
||||
static int usage(char *exe) {
|
||||
fprintf(stderr, "Usage: %s [options]\n"
|
||||
"Options:\n"
|
||||
" [--watch]\n"
|
||||
" [--backend dummy|alsa|pulseaudio|jack|coreaudio|wasapi]\n"
|
||||
" [--short]\n", exe);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void print_channel_layout(const struct SoundIoChannelLayout *layout) {
|
||||
if (layout->name) {
|
||||
fprintf(stderr, "%s", layout->name);
|
||||
} else {
|
||||
fprintf(stderr, "%s", soundio_get_channel_name(layout->channels[0]));
|
||||
for (int i = 1; i < layout->channel_count; i += 1) {
|
||||
fprintf(stderr, ", %s", soundio_get_channel_name(layout->channels[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool short_output = false;
|
||||
|
||||
static void print_device(struct SoundIoDevice *device, bool is_default) {
|
||||
const char *default_str = is_default ? " (default)" : "";
|
||||
const char *raw_str = device->is_raw ? " (raw)" : "";
|
||||
fprintf(stderr, "%s%s%s\n", device->name, default_str, raw_str);
|
||||
if (short_output)
|
||||
return;
|
||||
fprintf(stderr, " id: %s\n", device->id);
|
||||
|
||||
if (device->probe_error) {
|
||||
fprintf(stderr, " probe error: %s\n", soundio_strerror(device->probe_error));
|
||||
} else {
|
||||
fprintf(stderr, " channel layouts:\n");
|
||||
for (int i = 0; i < device->layout_count; i += 1) {
|
||||
fprintf(stderr, " ");
|
||||
print_channel_layout(&device->layouts[i]);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (device->current_layout.channel_count > 0) {
|
||||
fprintf(stderr, " current layout: ");
|
||||
print_channel_layout(&device->current_layout);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
fprintf(stderr, " sample rates:\n");
|
||||
for (int i = 0; i < device->sample_rate_count; i += 1) {
|
||||
struct SoundIoSampleRateRange *range = &device->sample_rates[i];
|
||||
fprintf(stderr, " %d - %d\n", range->min, range->max);
|
||||
|
||||
}
|
||||
if (device->sample_rate_current)
|
||||
fprintf(stderr, " current sample rate: %d\n", device->sample_rate_current);
|
||||
fprintf(stderr, " formats: ");
|
||||
for (int i = 0; i < device->format_count; i += 1) {
|
||||
const char *comma = (i == device->format_count - 1) ? "" : ", ";
|
||||
fprintf(stderr, "%s%s", soundio_format_string(device->formats[i]), comma);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
if (device->current_format != SoundIoFormatInvalid)
|
||||
fprintf(stderr, " current format: %s\n", soundio_format_string(device->current_format));
|
||||
|
||||
fprintf(stderr, " min software latency: %0.8f sec\n", device->software_latency_min);
|
||||
fprintf(stderr, " max software latency: %0.8f sec\n", device->software_latency_max);
|
||||
if (device->software_latency_current != 0.0)
|
||||
fprintf(stderr, " current software latency: %0.8f sec\n", device->software_latency_current);
|
||||
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
static int list_devices(struct SoundIo *soundio) {
|
||||
int output_count = soundio_output_device_count(soundio);
|
||||
int input_count = soundio_input_device_count(soundio);
|
||||
|
||||
int default_output = soundio_default_output_device_index(soundio);
|
||||
int default_input = soundio_default_input_device_index(soundio);
|
||||
|
||||
fprintf(stderr, "--------Input Devices--------\n\n");
|
||||
for (int i = 0; i < input_count; i += 1) {
|
||||
struct SoundIoDevice *device = soundio_get_input_device(soundio, i);
|
||||
print_device(device, default_input == i);
|
||||
soundio_device_unref(device);
|
||||
}
|
||||
fprintf(stderr, "\n--------Output Devices--------\n\n");
|
||||
for (int i = 0; i < output_count; i += 1) {
|
||||
struct SoundIoDevice *device = soundio_get_output_device(soundio, i);
|
||||
print_device(device, default_output == i);
|
||||
soundio_device_unref(device);
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n%d devices found\n", input_count + output_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void on_devices_change(struct SoundIo *soundio) {
|
||||
fprintf(stderr, "devices changed\n");
|
||||
list_devices(soundio);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *exe = argv[0];
|
||||
bool watch = false;
|
||||
enum SoundIoBackend backend = SoundIoBackendNone;
|
||||
|
||||
for (int i = 1; i < argc; i += 1) {
|
||||
char *arg = argv[i];
|
||||
if (strcmp("--watch", arg) == 0) {
|
||||
watch = true;
|
||||
} else if (strcmp("--short", arg) == 0) {
|
||||
short_output = true;
|
||||
} else if (arg[0] == '-' && arg[1] == '-') {
|
||||
i += 1;
|
||||
if (i >= argc) {
|
||||
return usage(exe);
|
||||
} else if (strcmp(arg, "--backend") == 0) {
|
||||
if (strcmp("dummy", argv[i]) == 0) {
|
||||
backend = SoundIoBackendDummy;
|
||||
} else if (strcmp("alsa", argv[i]) == 0) {
|
||||
backend = SoundIoBackendAlsa;
|
||||
} else if (strcmp("pulseaudio", argv[i]) == 0) {
|
||||
backend = SoundIoBackendPulseAudio;
|
||||
} else if (strcmp("jack", argv[i]) == 0) {
|
||||
backend = SoundIoBackendJack;
|
||||
} else if (strcmp("coreaudio", argv[i]) == 0) {
|
||||
backend = SoundIoBackendCoreAudio;
|
||||
} else if (strcmp("wasapi", argv[i]) == 0) {
|
||||
backend = SoundIoBackendWasapi;
|
||||
} else {
|
||||
fprintf(stderr, "Invalid backend: %s\n", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return usage(exe);
|
||||
}
|
||||
} else {
|
||||
return usage(exe);
|
||||
}
|
||||
}
|
||||
|
||||
struct SoundIo *soundio = soundio_create();
|
||||
if (!soundio) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int err = (backend == SoundIoBackendNone) ?
|
||||
soundio_connect(soundio) : soundio_connect_backend(soundio, backend);
|
||||
|
||||
if (err) {
|
||||
fprintf(stderr, "%s\n", soundio_strerror(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
if (watch) {
|
||||
soundio->on_devices_change = on_devices_change;
|
||||
for (;;) {
|
||||
soundio_wait_events(soundio);
|
||||
}
|
||||
} else {
|
||||
soundio_flush_events(soundio);
|
||||
int err = list_devices(soundio);
|
||||
soundio_destroy(soundio);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
-390
@@ -1,390 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Andrew Kelley
|
||||
*
|
||||
* This file is part of libsoundio, which is MIT licensed.
|
||||
* See http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <soundio/soundio.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
struct SoundIoRingBuffer *ring_buffer = NULL;
|
||||
|
||||
static enum SoundIoFormat prioritized_formats[] = {
|
||||
SoundIoFormatFloat32NE,
|
||||
SoundIoFormatFloat32FE,
|
||||
SoundIoFormatS32NE,
|
||||
SoundIoFormatS32FE,
|
||||
SoundIoFormatS24NE,
|
||||
SoundIoFormatS24FE,
|
||||
SoundIoFormatS16NE,
|
||||
SoundIoFormatS16FE,
|
||||
SoundIoFormatFloat64NE,
|
||||
SoundIoFormatFloat64FE,
|
||||
SoundIoFormatU32NE,
|
||||
SoundIoFormatU32FE,
|
||||
SoundIoFormatU24NE,
|
||||
SoundIoFormatU24FE,
|
||||
SoundIoFormatU16NE,
|
||||
SoundIoFormatU16FE,
|
||||
SoundIoFormatS8,
|
||||
SoundIoFormatU8,
|
||||
SoundIoFormatInvalid,
|
||||
};
|
||||
|
||||
static int prioritized_sample_rates[] = {
|
||||
48000,
|
||||
44100,
|
||||
96000,
|
||||
24000,
|
||||
0,
|
||||
};
|
||||
|
||||
|
||||
__attribute__ ((cold))
|
||||
__attribute__ ((noreturn))
|
||||
__attribute__ ((format (printf, 1, 2)))
|
||||
static void panic(const char *format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vfprintf(stderr, format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
abort();
|
||||
}
|
||||
|
||||
static int min_int(int a, int b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
static void read_callback(struct SoundIoInStream *instream, int frame_count_min, int frame_count_max) {
|
||||
struct SoundIoChannelArea *areas;
|
||||
int err;
|
||||
char *write_ptr = soundio_ring_buffer_write_ptr(ring_buffer);
|
||||
int free_bytes = soundio_ring_buffer_free_count(ring_buffer);
|
||||
int free_count = free_bytes / instream->bytes_per_frame;
|
||||
|
||||
if (frame_count_min > free_count)
|
||||
panic("ring buffer overflow");
|
||||
|
||||
int write_frames = min_int(free_count, frame_count_max);
|
||||
int frames_left = write_frames;
|
||||
|
||||
for (;;) {
|
||||
int frame_count = frames_left;
|
||||
|
||||
if ((err = soundio_instream_begin_read(instream, &areas, &frame_count)))
|
||||
panic("begin read error: %s", soundio_strerror(err));
|
||||
|
||||
if (!frame_count)
|
||||
break;
|
||||
|
||||
if (!areas) {
|
||||
// Due to an overflow there is a hole. Fill the ring buffer with
|
||||
// silence for the size of the hole.
|
||||
memset(write_ptr, 0, frame_count * instream->bytes_per_frame);
|
||||
fprintf(stderr, "Dropped %d frames due to internal overflow\n", frame_count);
|
||||
} else {
|
||||
for (int frame = 0; frame < frame_count; frame += 1) {
|
||||
for (int ch = 0; ch < instream->layout.channel_count; ch += 1) {
|
||||
memcpy(write_ptr, areas[ch].ptr, instream->bytes_per_sample);
|
||||
areas[ch].ptr += areas[ch].step;
|
||||
write_ptr += instream->bytes_per_sample;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = soundio_instream_end_read(instream)))
|
||||
panic("end read error: %s", soundio_strerror(err));
|
||||
|
||||
frames_left -= frame_count;
|
||||
if (frames_left <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
int advance_bytes = write_frames * instream->bytes_per_frame;
|
||||
soundio_ring_buffer_advance_write_ptr(ring_buffer, advance_bytes);
|
||||
}
|
||||
|
||||
static void write_callback(struct SoundIoOutStream *outstream, int frame_count_min, int frame_count_max) {
|
||||
struct SoundIoChannelArea *areas;
|
||||
int frames_left;
|
||||
int frame_count;
|
||||
int err;
|
||||
|
||||
char *read_ptr = soundio_ring_buffer_read_ptr(ring_buffer);
|
||||
int fill_bytes = soundio_ring_buffer_fill_count(ring_buffer);
|
||||
int fill_count = fill_bytes / outstream->bytes_per_frame;
|
||||
|
||||
if (frame_count_min > fill_count) {
|
||||
// Ring buffer does not have enough data, fill with zeroes.
|
||||
frames_left = frame_count_min;
|
||||
for (;;) {
|
||||
frame_count = frames_left;
|
||||
if (frame_count <= 0)
|
||||
return;
|
||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count)))
|
||||
panic("begin write error: %s", soundio_strerror(err));
|
||||
if (frame_count <= 0)
|
||||
return;
|
||||
for (int frame = 0; frame < frame_count; frame += 1) {
|
||||
for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) {
|
||||
memset(areas[ch].ptr, 0, outstream->bytes_per_sample);
|
||||
areas[ch].ptr += areas[ch].step;
|
||||
}
|
||||
}
|
||||
if ((err = soundio_outstream_end_write(outstream)))
|
||||
panic("end write error: %s", soundio_strerror(err));
|
||||
frames_left -= frame_count;
|
||||
}
|
||||
}
|
||||
|
||||
int read_count = min_int(frame_count_max, fill_count);
|
||||
frames_left = read_count;
|
||||
|
||||
while (frames_left > 0) {
|
||||
int frame_count = frames_left;
|
||||
|
||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count)))
|
||||
panic("begin write error: %s", soundio_strerror(err));
|
||||
|
||||
if (frame_count <= 0)
|
||||
break;
|
||||
|
||||
for (int frame = 0; frame < frame_count; frame += 1) {
|
||||
for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) {
|
||||
memcpy(areas[ch].ptr, read_ptr, outstream->bytes_per_sample);
|
||||
areas[ch].ptr += areas[ch].step;
|
||||
read_ptr += outstream->bytes_per_sample;
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = soundio_outstream_end_write(outstream)))
|
||||
panic("end write error: %s", soundio_strerror(err));
|
||||
|
||||
frames_left -= frame_count;
|
||||
}
|
||||
|
||||
soundio_ring_buffer_advance_read_ptr(ring_buffer, read_count * outstream->bytes_per_frame);
|
||||
}
|
||||
|
||||
static void underflow_callback(struct SoundIoOutStream *outstream) {
|
||||
static int count = 0;
|
||||
fprintf(stderr, "underflow %d\n", ++count);
|
||||
}
|
||||
|
||||
static int usage(char *exe) {
|
||||
fprintf(stderr, "Usage: %s [options]\n"
|
||||
"Options:\n"
|
||||
" [--backend dummy|alsa|pulseaudio|jack|coreaudio|wasapi]\n"
|
||||
" [--in-device id]\n"
|
||||
" [--in-raw]\n"
|
||||
" [--out-device id]\n"
|
||||
" [--out-raw]\n"
|
||||
" [--latency seconds]\n"
|
||||
, exe);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *exe = argv[0];
|
||||
enum SoundIoBackend backend = SoundIoBackendNone;
|
||||
char *in_device_id = NULL;
|
||||
char *out_device_id = NULL;
|
||||
bool in_raw = false;
|
||||
bool out_raw = false;
|
||||
|
||||
double microphone_latency = 0.2; // seconds
|
||||
|
||||
for (int i = 1; i < argc; i += 1) {
|
||||
char *arg = argv[i];
|
||||
if (arg[0] == '-' && arg[1] == '-') {
|
||||
if (strcmp(arg, "--in-raw") == 0) {
|
||||
in_raw = true;
|
||||
} else if (strcmp(arg, "--out-raw") == 0) {
|
||||
out_raw = true;
|
||||
} else if (++i >= argc) {
|
||||
return usage(exe);
|
||||
} else if (strcmp(arg, "--backend") == 0) {
|
||||
if (strcmp("dummy", argv[i]) == 0) {
|
||||
backend = SoundIoBackendDummy;
|
||||
} else if (strcmp("alsa", argv[i]) == 0) {
|
||||
backend = SoundIoBackendAlsa;
|
||||
} else if (strcmp("pulseaudio", argv[i]) == 0) {
|
||||
backend = SoundIoBackendPulseAudio;
|
||||
} else if (strcmp("jack", argv[i]) == 0) {
|
||||
backend = SoundIoBackendJack;
|
||||
} else if (strcmp("coreaudio", argv[i]) == 0) {
|
||||
backend = SoundIoBackendCoreAudio;
|
||||
} else if (strcmp("wasapi", argv[i]) == 0) {
|
||||
backend = SoundIoBackendWasapi;
|
||||
} else {
|
||||
fprintf(stderr, "Invalid backend: %s\n", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
} else if (strcmp(arg, "--in-device") == 0) {
|
||||
in_device_id = argv[i];
|
||||
} else if (strcmp(arg, "--out-device") == 0) {
|
||||
out_device_id = argv[i];
|
||||
} else if (strcmp(arg, "--latency") == 0) {
|
||||
microphone_latency = atof(argv[i]);
|
||||
} else {
|
||||
return usage(exe);
|
||||
}
|
||||
} else {
|
||||
return usage(exe);
|
||||
}
|
||||
}
|
||||
struct SoundIo *soundio = soundio_create();
|
||||
if (!soundio)
|
||||
panic("out of memory");
|
||||
|
||||
int err = (backend == SoundIoBackendNone) ?
|
||||
soundio_connect(soundio) : soundio_connect_backend(soundio, backend);
|
||||
if (err)
|
||||
panic("error connecting: %s", soundio_strerror(err));
|
||||
|
||||
soundio_flush_events(soundio);
|
||||
|
||||
int default_out_device_index = soundio_default_output_device_index(soundio);
|
||||
if (default_out_device_index < 0)
|
||||
panic("no output device found");
|
||||
|
||||
int default_in_device_index = soundio_default_input_device_index(soundio);
|
||||
if (default_in_device_index < 0)
|
||||
panic("no input device found");
|
||||
|
||||
int in_device_index = default_in_device_index;
|
||||
if (in_device_id) {
|
||||
bool found = false;
|
||||
for (int i = 0; i < soundio_input_device_count(soundio); i += 1) {
|
||||
struct SoundIoDevice *device = soundio_get_input_device(soundio, i);
|
||||
if (device->is_raw == in_raw && strcmp(device->id, in_device_id) == 0) {
|
||||
in_device_index = i;
|
||||
found = true;
|
||||
soundio_device_unref(device);
|
||||
break;
|
||||
}
|
||||
soundio_device_unref(device);
|
||||
}
|
||||
if (!found)
|
||||
panic("invalid input device id: %s", in_device_id);
|
||||
}
|
||||
|
||||
int out_device_index = default_out_device_index;
|
||||
if (out_device_id) {
|
||||
bool found = false;
|
||||
for (int i = 0; i < soundio_output_device_count(soundio); i += 1) {
|
||||
struct SoundIoDevice *device = soundio_get_output_device(soundio, i);
|
||||
if (device->is_raw == out_raw && strcmp(device->id, out_device_id) == 0) {
|
||||
out_device_index = i;
|
||||
found = true;
|
||||
soundio_device_unref(device);
|
||||
break;
|
||||
}
|
||||
soundio_device_unref(device);
|
||||
}
|
||||
if (!found)
|
||||
panic("invalid output device id: %s", out_device_id);
|
||||
}
|
||||
|
||||
struct SoundIoDevice *out_device = soundio_get_output_device(soundio, out_device_index);
|
||||
if (!out_device)
|
||||
panic("could not get output device: out of memory");
|
||||
|
||||
struct SoundIoDevice *in_device = soundio_get_input_device(soundio, in_device_index);
|
||||
if (!in_device)
|
||||
panic("could not get input device: out of memory");
|
||||
|
||||
fprintf(stderr, "Input device: %s\n", in_device->name);
|
||||
fprintf(stderr, "Output device: %s\n", out_device->name);
|
||||
|
||||
soundio_device_sort_channel_layouts(out_device);
|
||||
const struct SoundIoChannelLayout *layout = soundio_best_matching_channel_layout(
|
||||
out_device->layouts, out_device->layout_count,
|
||||
in_device->layouts, in_device->layout_count);
|
||||
|
||||
if (!layout)
|
||||
panic("channel layouts not compatible");
|
||||
|
||||
int *sample_rate;
|
||||
for (sample_rate = prioritized_sample_rates; *sample_rate; sample_rate += 1) {
|
||||
if (soundio_device_supports_sample_rate(in_device, *sample_rate) &&
|
||||
soundio_device_supports_sample_rate(out_device, *sample_rate))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!*sample_rate)
|
||||
panic("incompatible sample rates");
|
||||
|
||||
enum SoundIoFormat *fmt;
|
||||
for (fmt = prioritized_formats; *fmt != SoundIoFormatInvalid; fmt += 1) {
|
||||
if (soundio_device_supports_format(in_device, *fmt) &&
|
||||
soundio_device_supports_format(out_device, *fmt))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*fmt == SoundIoFormatInvalid)
|
||||
panic("incompatible sample formats");
|
||||
|
||||
struct SoundIoInStream *instream = soundio_instream_create(in_device);
|
||||
if (!instream)
|
||||
panic("out of memory");
|
||||
instream->format = *fmt;
|
||||
instream->sample_rate = *sample_rate;
|
||||
instream->layout = *layout;
|
||||
instream->software_latency = microphone_latency;
|
||||
instream->read_callback = read_callback;
|
||||
|
||||
if ((err = soundio_instream_open(instream))) {
|
||||
fprintf(stderr, "unable to open input stream: %s", soundio_strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct SoundIoOutStream *outstream = soundio_outstream_create(out_device);
|
||||
if (!outstream)
|
||||
panic("out of memory");
|
||||
outstream->format = *fmt;
|
||||
outstream->sample_rate = *sample_rate;
|
||||
outstream->layout = *layout;
|
||||
outstream->software_latency = microphone_latency;
|
||||
outstream->write_callback = write_callback;
|
||||
outstream->underflow_callback = underflow_callback;
|
||||
|
||||
if ((err = soundio_outstream_open(outstream))) {
|
||||
fprintf(stderr, "unable to open output stream: %s", soundio_strerror(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int capacity = microphone_latency * 2 * instream->sample_rate * instream->bytes_per_frame;
|
||||
ring_buffer = soundio_ring_buffer_create(soundio, capacity);
|
||||
if (!ring_buffer)
|
||||
panic("unable to create ring buffer: out of memory");
|
||||
char *buf = soundio_ring_buffer_write_ptr(ring_buffer);
|
||||
int fill_count = microphone_latency * outstream->sample_rate * outstream->bytes_per_frame;
|
||||
memset(buf, 0, fill_count);
|
||||
soundio_ring_buffer_advance_write_ptr(ring_buffer, fill_count);
|
||||
|
||||
if ((err = soundio_instream_start(instream)))
|
||||
panic("unable to start input device: %s", soundio_strerror(err));
|
||||
|
||||
if ((err = soundio_outstream_start(outstream)))
|
||||
panic("unable to start output device: %s", soundio_strerror(err));
|
||||
|
||||
for (;;)
|
||||
soundio_wait_events(soundio);
|
||||
|
||||
soundio_outstream_destroy(outstream);
|
||||
soundio_instream_destroy(instream);
|
||||
soundio_device_unref(in_device);
|
||||
soundio_device_unref(out_device);
|
||||
soundio_destroy(soundio);
|
||||
return 0;
|
||||
}
|
||||
Loaded 100 of 142 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user