mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
127
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daca3a27d6 | ||
|
|
26374366c7 | ||
|
|
22798fe14e | ||
|
|
44478b6937 | ||
|
|
57ea3c2e66 | ||
|
|
03595c3940 | ||
|
|
ed48766e5f | ||
|
|
a7f4d418fc | ||
|
|
4093c6e83c | ||
|
|
cf0d361918 | ||
|
|
09da0c6109 | ||
|
|
2f562e7761 | ||
|
|
b07b700b36 | ||
|
|
616d0728fd | ||
|
|
74a49d1568 | ||
|
|
3e545bdef9 | ||
|
|
f1c898b17e | ||
|
|
49f47c5f3f | ||
|
|
888d919ae7 | ||
|
|
e01fea87a9 | ||
|
|
f181e721b0 | ||
|
|
c188d0251a | ||
|
|
d76433f112 | ||
|
|
422639411d | ||
|
|
5d7450df90 | ||
|
|
3234f21cab | ||
|
|
2fb23e210e | ||
|
|
fdf0ebbf6c | ||
|
|
597c077b19 | ||
|
|
71b2e6c1fa | ||
|
|
196154bb7b | ||
|
|
92c558f44b | ||
|
|
ad2fc290ec | ||
|
|
299f0d3a9f | ||
|
|
9fcf5ba51a | ||
|
|
094b3b5312 | ||
|
|
7e5451a97d | ||
|
|
8231ecd466 | ||
|
|
1d33ea2beb | ||
|
|
bee24b166d | ||
|
|
f61854a0ae | ||
|
|
99eb93f9e1 | ||
|
|
be45a6a020 | ||
|
|
b472123746 | ||
|
|
fd2e6c5b09 | ||
|
|
f7280c316b | ||
|
|
cc17035e67 | ||
|
|
654ff0219c | ||
|
|
8862a73ef1 | ||
|
|
5e61b473f0 | ||
|
|
2a64f547cc | ||
|
|
fba2ff4231 | ||
|
|
e64aab1577 | ||
|
|
36dee46e9b | ||
|
|
99e92a5679 | ||
|
|
ec97a671d8 | ||
|
|
31db015105 | ||
|
|
289ddf10b7 | ||
|
|
699b62373a | ||
|
|
4100a80f96 | ||
|
|
136aeca8f2 | ||
|
|
8d01440558 | ||
|
|
e510c11be2 | ||
|
|
19adb54cd8 | ||
|
|
f2db6bd066 | ||
|
|
1b221bc0bd | ||
|
|
85d0900d7d | ||
|
|
5294a8b71c | ||
|
|
46bc8567e9 | ||
|
|
64fec88436 | ||
|
|
bd5a88f02f | ||
|
|
b61a7c4aea | ||
|
|
2f08a0b327 | ||
|
|
52fa30b71d | ||
|
|
911acb4bc2 | ||
|
|
0bd9d0e973 | ||
|
|
5aaae40d94 | ||
|
|
190718fbee | ||
|
|
37c352955c | ||
|
|
fb56a6b536 | ||
|
|
74b457819a | ||
|
|
0118b347f3 | ||
|
|
101a8d33b0 | ||
|
|
eb3f978c7b | ||
|
|
9ea4a465f4 | ||
|
|
41a34ffab6 | ||
|
|
8002737124 | ||
|
|
7ba8921649 | ||
|
|
a1d9fcfa9d | ||
|
|
648dfcd47b | ||
|
|
f6e208267e | ||
|
|
24ccdabedc | ||
|
|
78528a1a16 | ||
|
|
df02f5053b | ||
|
|
14bcb6c08a | ||
|
|
09d374f626 | ||
|
|
072d5ae330 | ||
|
|
3b0e2c677d | ||
|
|
4f05d3dae6 | ||
|
|
d96351763f | ||
|
|
a0dd1884b3 | ||
|
|
a4ff58e9ee | ||
|
|
447941abe0 | ||
|
|
9835b96e87 | ||
|
|
9f4c248e4c | ||
|
|
98ccef732f | ||
|
|
dac50fe0fb | ||
|
|
76e0fab33a | ||
|
|
585c5fd4ca | ||
|
|
de082626ab | ||
|
|
9f1d613a2d | ||
|
|
f27dd94945 | ||
|
|
6f0d3b48ba | ||
|
|
b665f2cb4e | ||
|
|
ed424ad544 | ||
|
|
50dbd5eccd | ||
|
|
01d7d6bac3 | ||
|
|
ce925f5e56 | ||
|
|
a7403195ba | ||
|
|
3a5c61797c | ||
|
|
467e4df7dc | ||
|
|
24ecdbe75b | ||
|
|
b654424465 | ||
|
|
d91e14abc6 | ||
|
|
a08e70781a | ||
|
|
a24840803c | ||
|
|
7e7522d4b7 |
No files matched your search
+10
@@ -7,8 +7,14 @@ out/
|
||||
*.o
|
||||
*.d
|
||||
|
||||
# Ignore CMake system files
|
||||
CMakeFiles
|
||||
cmake_install.cmake
|
||||
|
||||
# Ignore Visual Studio configuration files
|
||||
CMakeSettings.json
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
|
||||
# Ignore generated executables
|
||||
dingusppc
|
||||
@@ -21,4 +27,8 @@ Thumb.db
|
||||
# IDE ignores
|
||||
build
|
||||
build-*
|
||||
*.dir
|
||||
*.user
|
||||
DerivedData
|
||||
*.xcodeproj/project.xcworkspace
|
||||
*.xcodeproj/xcuserdata
|
||||
+41
-42
@@ -4,18 +4,40 @@ project(dingusppc)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
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()
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
if (UNIX AND NOT APPLE)
|
||||
find_package (Threads)
|
||||
endif()
|
||||
|
||||
else() # Windows build relies on vcpkg
|
||||
# pick up system wide vcpkg if exists
|
||||
if (DEFINED ENV{VCPKG_ROOT} AND EXISTS $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
message(STATUS "Using system vcpkg at $ENV{VCPKG_ROOT}")
|
||||
set(vcpkg_toolchain_file $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
|
||||
# check Github Actions vcpkg installation
|
||||
elseif (DEFINED ENV{VCPKG_INSTALLATION_ROOT} AND EXISTS $ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
message(STATUS "Using system vcpkg at $ENV{VCPKG_INSTALLATION_ROOT}")
|
||||
set(vcpkg_toolchain_file $ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||
|
||||
# otherwise, fetch vcpkg from Github
|
||||
else()
|
||||
message(STATUS "Fetching latest vcpkg from Github...")
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(vcpkg GIT_REPOSITORY https://github.com/microsoft/vcpkg.git)
|
||||
FetchContent_MakeAvailable(vcpkg)
|
||||
set(vcpkg_toolchain_file ${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake)
|
||||
endif()
|
||||
|
||||
set(CMAKE_TOOLCHAIN_FILE ${vcpkg_toolchain_file})
|
||||
find_package(SDL2 CONFIG REQUIRED)
|
||||
add_compile_definitions(SDL_MAIN_HANDLED)
|
||||
endif()
|
||||
|
||||
option(DPPC_BUILD_PPC_TESTS "Build PowerPC tests" OFF)
|
||||
@@ -24,9 +46,6 @@ option(DPPC_BUILD_BENCHMARKS "Build benchmarking programs" OFF)
|
||||
option(DPPC_68K_DEBUGGER "Enable 68k debugging" OFF)
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
# Build capstone as static library.
|
||||
set(CAPSTONE_BUILD_STATIC ON CACHE BOOL "")
|
||||
|
||||
# Turn off anything unnecessary.
|
||||
set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "")
|
||||
@@ -64,13 +83,6 @@ 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")
|
||||
#set(BUILD_TESTS OFF CACHE BOOL "Build libsoundio tests")
|
||||
#set(BUILD_DYNAMIC_LIBS ON CACHE BOOL "Build libsoundio dynamic libs")
|
||||
#set(BUILD_STATIC_LIBS ON CACHE BOOL "Build libsoundio static libs")
|
||||
|
||||
#add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/libsoundio")
|
||||
|
||||
set(BUILD_TESTS OFF CACHE BOOL "Build Cubeb tests")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
|
||||
@@ -87,18 +99,13 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${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})
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
|
||||
|
||||
file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/*.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.h")
|
||||
|
||||
#get_directory_property(LIBSOUNDIO_LIBS DIRECTORY thirdparty/libsoundio DEFINITION LIBSOUNDIO_LIBS)
|
||||
|
||||
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
|
||||
|
||||
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
|
||||
@@ -110,18 +117,14 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(dingusppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
ws2_32
|
||||
cubeb)
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
|
||||
else()
|
||||
#target_link_libraries(dingusppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(dingusppc PRIVATE ${CLI11_ROOT})
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc capstone-static)
|
||||
target_link_libraries(dingusppc PRIVATE capstone)
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
@@ -134,18 +137,14 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
cubeb)
|
||||
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb)
|
||||
else()
|
||||
#target_link_libraries(testppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(testppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(testppc capstone-static)
|
||||
target_link_libraries(testppc PRIVATE capstone)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -159,11 +158,11 @@ if (DPPC_BUILD_BENCHMARKS)
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
target_link_libraries(bench1 cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
|
||||
target_link_libraries(bench1 PRIVATE cubeb SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(bench1 capstone-static)
|
||||
target_link_libraries(bench1 PRIVATE capstone)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <chrono>
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "devices/mpc106.h"
|
||||
#include "devices/memctrl/mpc106.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
uint32_t cs_code[] = {
|
||||
@@ -59,17 +59,19 @@ int main(int argc, char** argv) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
|
||||
constexpr uint64_t tbr_freq = 16705000;
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, tbr_freq);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code); i++) {
|
||||
mem_write_dword(i*4, cs_code[i]);
|
||||
mmu_write_vmem<uint32_t>(i*4, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
|
||||
for (i = 0; i < 32768; i++) {
|
||||
mem_write_byte(0x1000+i, rand() % 256);
|
||||
mmu_write_vmem<uint8_t>(0x1000+i, rand() % 256);
|
||||
}
|
||||
|
||||
/* prepare benchmark code execution */
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(core OBJECT ${SOURCES})
|
||||
target_link_libraries(core)
|
||||
target_link_libraries(core PRIVATE SDL2::SDL2)
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** Non-standard low-level bitwise operations. */
|
||||
|
||||
#ifndef BIT_OPS_H
|
||||
#define BIT_OPS_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#if defined(__GNUG__) && !defined(__clang__) // GCC, mybe ICC but not Clang
|
||||
|
||||
# include <x86intrin.h>
|
||||
|
||||
# define ROTL_32(x, n) (_rotl((x), (n)))
|
||||
# define ROTR_32(x, n) (_rotr((x), (n)))
|
||||
|
||||
#elif defined(_MSC_VER) // MSVC
|
||||
|
||||
# include <intrin.h>
|
||||
|
||||
# define ROTL_32(x, n) (_rotl((x), (n)))
|
||||
# define ROTR_32(x, n) (_rotr((x), (n)))
|
||||
|
||||
#else
|
||||
|
||||
// cyclic rotation idioms that modern compilers will
|
||||
// recognize and generate very compact code for
|
||||
// evolving specific machine instructions
|
||||
|
||||
inline unsigned ROTL_32(unsigned x, unsigned n) {
|
||||
n &= 0x1F;
|
||||
return (x << n) | (x >> (32 - n));
|
||||
}
|
||||
|
||||
inline unsigned ROTR_32(unsigned x, unsigned n) {
|
||||
n &= 0x1F;
|
||||
return (x >> n) | (x << (32 - n));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline T extract_bits(T val, int pos, int len) {
|
||||
return (val >> pos) & (((T)1 << len) - 1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void insert_bits(T &old_val, T new_val, int pos, int len) {
|
||||
T mask = (((T)1 << len) - 1) << pos;
|
||||
old_val = (old_val & ~mask) | ((new_val << pos) & mask);
|
||||
}
|
||||
|
||||
/* Return true if the specified bit is different in the given numbers. */
|
||||
static inline bool bit_changed(uint64_t old_val, uint64_t new_val, int bit_num) {
|
||||
return (old_val ^ new_val) & (1ULL << bit_num);
|
||||
}
|
||||
|
||||
static inline bool bit_set(const uint64_t val, const int bit_num) {
|
||||
return !!(val & (1ULL << bit_num));
|
||||
}
|
||||
|
||||
#endif // BIT_OPS_H
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 <core/hostevents.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <loguru.hpp>
|
||||
#include <SDL.h>
|
||||
|
||||
EventManager* EventManager::event_manager;
|
||||
|
||||
void EventManager::poll_events()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
events_captured++;
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
power_on = false;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
WindowEvent we;
|
||||
we.sub_type = event.window.event;
|
||||
we.window_id = event.window.windowID;
|
||||
this->post_event(we);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
key_downs++;
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
key_ups++;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
mouse_motions++;
|
||||
break;
|
||||
|
||||
default:
|
||||
unhandled_events++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 EVENT_MANAGER_H
|
||||
#define EVENT_MANAGER_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
enum EventType : uint16_t {
|
||||
EVENT_UNKNOWN = 0,
|
||||
EVENT_WINDOW = 100,
|
||||
EVENT_KEYBOARD = 200,
|
||||
EVENT_MOUSE = 300,
|
||||
};
|
||||
|
||||
class BaseEvent {
|
||||
public:
|
||||
BaseEvent(EventType type) { this->type = type; };
|
||||
EventType type;
|
||||
};
|
||||
|
||||
class WindowEvent : public BaseEvent {
|
||||
public:
|
||||
WindowEvent() : BaseEvent(EventType::EVENT_WINDOW) {};
|
||||
|
||||
uint16_t sub_type;
|
||||
uint32_t window_id;
|
||||
};
|
||||
|
||||
class EventManager {
|
||||
public:
|
||||
static EventManager* get_instance() {
|
||||
if (!event_manager) {
|
||||
event_manager = new EventManager();
|
||||
}
|
||||
return event_manager;
|
||||
};
|
||||
|
||||
using EventHandler = std::function<void(const BaseEvent&)>;
|
||||
|
||||
void poll_events();
|
||||
|
||||
void register_handler(const EventType event_type, EventHandler&& eh) {
|
||||
this->_handlers[event_type].emplace_back(std::move(eh));
|
||||
};
|
||||
|
||||
void post_event(const BaseEvent& event) {
|
||||
auto type = event.type;
|
||||
|
||||
if( _handlers.find(type) == _handlers.end() )
|
||||
return;
|
||||
|
||||
auto&& handlers = _handlers.at(type);
|
||||
|
||||
for(auto&& handler : handlers)
|
||||
handler(event);
|
||||
}
|
||||
|
||||
private:
|
||||
static EventManager* event_manager;
|
||||
EventManager() {}; // private constructor to implement a singleton
|
||||
|
||||
std::map<EventType, std::list<EventHandler>> _handlers;
|
||||
|
||||
uint64_t events_captured = 0;
|
||||
uint64_t unhandled_events = 0;
|
||||
uint64_t key_downs = 0;
|
||||
uint64_t key_ups = 0;
|
||||
uint64_t mouse_motions = 0;
|
||||
};
|
||||
|
||||
#endif // EVENT_MANAGER_H
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 MATH_UTILS_H
|
||||
#define MATH_UTILS_H
|
||||
|
||||
inline void _u32xu64(uint32_t a, uint64_t b, uint32_t &hi, uint64_t &lo)
|
||||
{
|
||||
uint64_t p0 = (b & 0xffffffff) * a;
|
||||
uint64_t p1 = (b >> 32) * a;
|
||||
lo = p0 + (p1 << 32);
|
||||
hi = (p1 >> 32) + (lo < p0);
|
||||
}
|
||||
|
||||
inline void _u32xu64(uint32_t a, uint64_t b, uint64_t &hi, uint32_t &lo)
|
||||
{
|
||||
uint64_t p0 = (b & 0xffffffff) * a;
|
||||
uint64_t p1 = (b >> 32) * a;
|
||||
lo = (uint32_t)p0;
|
||||
hi = (p0 >> 32) + p1;
|
||||
}
|
||||
|
||||
inline void _u64xu64(uint64_t a, uint64_t b, uint64_t &hi, uint64_t &lo)
|
||||
{
|
||||
uint32_t p0h; uint64_t p0l; _u32xu64((uint32_t)b, a, p0h, p0l);
|
||||
uint64_t p1h; uint32_t p1l; _u32xu64(b >> 32, a, p1h, p1l);
|
||||
lo = p0l + ((uint64_t)p1l << 32);
|
||||
hi = p0h + p1h + (lo < p0l);
|
||||
}
|
||||
|
||||
#endif // MATH_UTILS_H
|
||||
@@ -32,7 +32,7 @@ TimerManager* TimerManager::timer_manager;
|
||||
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
{
|
||||
if (!timeout || timeout <= MIN_TIMEOUT_NS) {
|
||||
LOG_F(WARNING, "One-shot timer too short, timeout=%llu ns", timeout);
|
||||
LOG_F(WARNING, "One-shot timer too short, timeout=%llu ns", (long long unsigned)timeout);
|
||||
}
|
||||
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
@@ -58,7 +58,7 @@ uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb)
|
||||
{
|
||||
if (!interval || interval <= MIN_TIMEOUT_NS) {
|
||||
LOG_F(WARNING, "Cyclic timer interval too short, timeout=%llu ns", interval);
|
||||
LOG_F(WARNING, "Cyclic timer interval too short, timeout=%llu ns", (long long unsigned)interval);
|
||||
}
|
||||
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
+5
-1
@@ -34,9 +34,13 @@ using namespace std;
|
||||
#define MIN_TIMEOUT_NS 200
|
||||
|
||||
#define NS_PER_SEC 1E9
|
||||
#define USEC_PER_SEC 1E6
|
||||
#define NS_PER_USEC 1000UL
|
||||
#define NS_PER_MSEC 1E6
|
||||
#define ONE_BILLION_NS 0x3B9ACA00UL
|
||||
|
||||
#define USECS_TO_NSECS(us) (us) * 1000
|
||||
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
|
||||
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
|
||||
|
||||
typedef function<void()> timer_cb;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ inline void power_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
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);
|
||||
uint32_t m2 = (uint32_t)(0xFFFFFFFFUL << (31 - rot_me));
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
|
||||
+11
-7
@@ -94,7 +94,7 @@ enum SPR : int {
|
||||
DAR = 19,
|
||||
RTCU_S = 20, // supervisor RTCU
|
||||
RTCL_S = 21, // supervisor RTCL
|
||||
DEC = 22,
|
||||
DEC = 22, // decrementer
|
||||
SDR1 = 25,
|
||||
SRR0 = 26,
|
||||
SRR1 = 27,
|
||||
@@ -109,11 +109,12 @@ enum SPR : int {
|
||||
|
||||
/** symbolic names for common PPC processors */
|
||||
enum PPC_VER : uint32_t {
|
||||
MPC601 = 0x00010001,
|
||||
MPC603 = 0x00030001,
|
||||
MPC604 = 0x00040001,
|
||||
MPC603E = 0x00060101,
|
||||
MPC750 = 0x00080200
|
||||
MPC601 = 0x00010001,
|
||||
MPC603 = 0x00030001,
|
||||
MPC604 = 0x00040001,
|
||||
MPC603E = 0x00060101,
|
||||
MPC603EV = 0x00070101,
|
||||
MPC750 = 0x00080200
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -159,8 +160,11 @@ extern uint32_t opcode_value; // used for interpreting opcodes
|
||||
|
||||
extern uint64_t timebase_counter;
|
||||
extern uint64_t tbr_wr_timestamp;
|
||||
extern uint64_t dec_wr_timestamp;
|
||||
extern uint64_t rtc_timestamp;
|
||||
extern uint64_t tbr_wr_value;
|
||||
extern uint64_t tbr_freq_hz;
|
||||
extern uint32_t dec_wr_value;
|
||||
extern uint32_t tbr_freq_ghz;
|
||||
extern uint32_t rtc_lo, rtc_hi;
|
||||
|
||||
// Additional steps to prevent overflow?
|
||||
|
||||
@@ -100,7 +100,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
default:
|
||||
ABORT_F("Unknown exception occured: %X\n", exception_type);
|
||||
ABORT_F("Unknown exception occured: %X\n", (unsigned)exception_type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+20
-17
@@ -66,11 +66,13 @@ uint64_t g_icycles;
|
||||
int icnt_factor;
|
||||
|
||||
/* global variables related to the timebase facility */
|
||||
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR/RTC write
|
||||
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR write
|
||||
uint64_t rtc_timestamp; // stores vCPU virtual time of the last RTC write
|
||||
uint64_t tbr_wr_value; // last value written to the TBR
|
||||
uint64_t tbr_freq_hz; // TBR/RTC driving frequency in Hz
|
||||
uint32_t tbr_freq_ghz; // TBR/RTC driving frequency in GHz expressed as a 32 bit fraction less than 1.0.
|
||||
uint64_t timebase_counter; // internal timebase counter
|
||||
uint32_t decr; // current value of PPC DEC register
|
||||
uint64_t dec_wr_timestamp; // stores vCPU virtual time of the last DEC write
|
||||
uint32_t dec_wr_value; // last value written to the DEC register
|
||||
uint32_t rtc_lo; // MPC601 RTC lower, counts nanoseconds
|
||||
uint32_t rtc_hi; // MPC601 RTC upper, counts seconds
|
||||
|
||||
@@ -763,13 +765,14 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq)
|
||||
g_icycles = 0;
|
||||
icnt_factor = 4;
|
||||
tbr_wr_timestamp = 0;
|
||||
rtc_timestamp = 0;
|
||||
tbr_wr_value = 0;
|
||||
tbr_freq_hz = tb_freq;
|
||||
tbr_freq_ghz = (tb_freq << 32) / NS_PER_SEC;
|
||||
|
||||
exec_flags = 0;
|
||||
|
||||
timebase_counter = 0;
|
||||
decr = 0;
|
||||
dec_wr_value = 0;
|
||||
|
||||
/* zero all GPRs as prescribed for MPC601 */
|
||||
/* For later PPC CPUs, GPR content is undefined */
|
||||
@@ -847,38 +850,38 @@ uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
|
||||
try {
|
||||
if (reg_name_u == "PC") {
|
||||
if (is_write)
|
||||
ppc_state.pc = val;
|
||||
ppc_state.pc = (uint32_t)val;
|
||||
return ppc_state.pc;
|
||||
}
|
||||
if (reg_name_u == "MSR") {
|
||||
if (is_write)
|
||||
ppc_state.msr = val;
|
||||
ppc_state.msr = (uint32_t)val;
|
||||
return ppc_state.msr;
|
||||
}
|
||||
if (reg_name_u == "CR") {
|
||||
if (is_write)
|
||||
ppc_state.cr = val;
|
||||
ppc_state.cr = (uint32_t)val;
|
||||
return ppc_state.cr;
|
||||
}
|
||||
if (reg_name_u == "FPSCR") {
|
||||
if (is_write)
|
||||
ppc_state.fpscr = val;
|
||||
ppc_state.fpscr = (uint32_t)val;
|
||||
return ppc_state.fpscr;
|
||||
}
|
||||
|
||||
if (reg_name_u.substr(0, 1) == "R") {
|
||||
reg_num_str = reg_name_u.substr(1);
|
||||
reg_num = stoul(reg_num_str, NULL, 0);
|
||||
reg_num = (unsigned)stoul(reg_num_str, NULL, 0);
|
||||
if (reg_num < 32) {
|
||||
if (is_write)
|
||||
ppc_state.gpr[reg_num] = val;
|
||||
ppc_state.gpr[reg_num] = (uint32_t)val;
|
||||
return ppc_state.gpr[reg_num];
|
||||
}
|
||||
}
|
||||
|
||||
if (reg_name_u.substr(0, 1) == "FR") {
|
||||
reg_num_str = reg_name_u.substr(2);
|
||||
reg_num = stoul(reg_num_str, NULL, 0);
|
||||
reg_num = (unsigned)stoul(reg_num_str, NULL, 0);
|
||||
if (reg_num < 32) {
|
||||
if (is_write)
|
||||
ppc_state.fpr[reg_num].int64_r = val;
|
||||
@@ -888,20 +891,20 @@ uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
|
||||
|
||||
if (reg_name_u.substr(0, 3) == "SPR") {
|
||||
reg_num_str = reg_name_u.substr(3);
|
||||
reg_num = stoul(reg_num_str, NULL, 0);
|
||||
reg_num = (unsigned)stoul(reg_num_str, NULL, 0);
|
||||
if (reg_num < 1024) {
|
||||
if (is_write)
|
||||
ppc_state.spr[reg_num] = val;
|
||||
ppc_state.spr[reg_num] = (uint32_t)val;
|
||||
return ppc_state.spr[reg_num];
|
||||
}
|
||||
}
|
||||
|
||||
if (reg_name_u.substr(0, 2) == "SR") {
|
||||
reg_num_str = reg_name_u.substr(2);
|
||||
reg_num = stoul(reg_num_str, NULL, 0);
|
||||
reg_num = (unsigned)stoul(reg_num_str, NULL, 0);
|
||||
if (reg_num < 16) {
|
||||
if (is_write)
|
||||
ppc_state.sr[reg_num] = val;
|
||||
ppc_state.sr[reg_num] = (uint32_t)val;
|
||||
return ppc_state.sr[reg_num];
|
||||
}
|
||||
}
|
||||
@@ -909,7 +912,7 @@ uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
|
||||
spr = SPRName2Num.find(reg_name_u);
|
||||
if (spr != SPRName2Num.end()) {
|
||||
if (is_write)
|
||||
ppc_state.spr[spr->second] = val;
|
||||
ppc_state.spr[spr->second] = (uint32_t)val;
|
||||
return ppc_state.spr[spr->second];
|
||||
}
|
||||
} catch (...) {
|
||||
|
||||
+45
-42
@@ -125,11 +125,11 @@ static BATResult mpc601_block_address_translation(uint32_t la)
|
||||
|
||||
// logical to physical translation
|
||||
pa = bat_entry->phys_hi | (la & ~bat_entry->hi_mask);
|
||||
break;
|
||||
return BATResult{bat_hit, prot, pa};
|
||||
}
|
||||
}
|
||||
|
||||
return BATResult{bat_hit, prot, pa};
|
||||
return BATResult{bat_hit, 0, 0};
|
||||
}
|
||||
|
||||
/** PowerPC-style block address translation. */
|
||||
@@ -309,9 +309,11 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
|
||||
};
|
||||
}
|
||||
|
||||
uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size)
|
||||
uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size, bool* is_writable)
|
||||
{
|
||||
if (addr >= last_dma_area.start && (addr + size) <= last_dma_area.end) {
|
||||
if (is_writable)
|
||||
*is_writable = last_dma_area.type & RT_RAM;
|
||||
return last_dma_area.mem_ptr + (addr - last_dma_area.start);
|
||||
} else {
|
||||
AddressMapEntry* entry = mem_ctrl_instance->find_range(addr);
|
||||
@@ -319,6 +321,9 @@ uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size)
|
||||
last_dma_area.start = entry->start;
|
||||
last_dma_area.end = entry->end;
|
||||
last_dma_area.mem_ptr = entry->mem_ptr;
|
||||
last_dma_area.type = entry->type;
|
||||
if (is_writable)
|
||||
*is_writable = entry->type & RT_RAM;
|
||||
return last_dma_area.mem_ptr + (addr - last_dma_area.start);
|
||||
} else {
|
||||
ABORT_F("SOS: DMA access to unmapped memory %08X!\n", addr);
|
||||
@@ -373,16 +378,16 @@ void mmu_change_mode()
|
||||
if (CurITLBMode != mmu_mode) {
|
||||
switch(mmu_mode) {
|
||||
case 0: // real address mode
|
||||
pCurITLB1 = &dtlb1_mode1[0];
|
||||
pCurITLB2 = &dtlb2_mode1[0];
|
||||
pCurITLB1 = &itlb1_mode1[0];
|
||||
pCurITLB2 = &itlb2_mode1[0];
|
||||
break;
|
||||
case 2: // supervisor mode with instruction translation enabled
|
||||
pCurITLB1 = &dtlb1_mode2[0];
|
||||
pCurITLB2 = &dtlb2_mode2[0];
|
||||
pCurITLB1 = &itlb1_mode2[0];
|
||||
pCurITLB2 = &itlb2_mode2[0];
|
||||
break;
|
||||
case 3: // user mode with instruction translation enabled
|
||||
pCurITLB1 = &dtlb1_mode3[0];
|
||||
pCurITLB2 = &dtlb2_mode3[0];
|
||||
pCurITLB1 = &itlb1_mode3[0];
|
||||
pCurITLB2 = &itlb2_mode3[0];
|
||||
break;
|
||||
}
|
||||
CurITLBMode = mmu_mode;
|
||||
@@ -737,6 +742,7 @@ void tlb_flush_entry(uint32_t ea)
|
||||
tlb1 = &dtlb1_mode2[0];
|
||||
tlb2 = &dtlb2_mode2[0];
|
||||
break;
|
||||
default:
|
||||
case 5:
|
||||
tlb1 = &dtlb1_mode3[0];
|
||||
tlb2 = &dtlb2_mode3[0];
|
||||
@@ -873,7 +879,7 @@ static void mpc601_bat_update(uint32_t bat_reg)
|
||||
dbat_entry->valid = false;
|
||||
}
|
||||
|
||||
// MPC601 has unified BATs so we're going to fush both ITLB and DTLB
|
||||
// MPC601 has unified BATs so we're going to flush both ITLB and DTLB
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
@@ -889,21 +895,19 @@ static void ppc_ibat_update(uint32_t bat_reg)
|
||||
|
||||
upper_reg_num = bat_reg & 0xFFFFFFFE;
|
||||
|
||||
if (ppc_state.spr[upper_reg_num] & 3) { // is that BAT pair valid?
|
||||
bat_entry = &ibat_array[(bat_reg - 528) >> 1];
|
||||
bl = (ppc_state.spr[upper_reg_num] >> 2) & 0x7FF;
|
||||
hi_mask = ~((bl << 17) | 0x1FFFF);
|
||||
bat_entry = &ibat_array[(bat_reg - 528) >> 1];
|
||||
bl = (ppc_state.spr[upper_reg_num] >> 2) & 0x7FF;
|
||||
hi_mask = ~((bl << 17) | 0x1FFFF);
|
||||
|
||||
bat_entry->access = ppc_state.spr[upper_reg_num] & 3;
|
||||
bat_entry->prot = ppc_state.spr[upper_reg_num + 1] & 3;
|
||||
bat_entry->hi_mask = hi_mask;
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
bat_entry->access = ppc_state.spr[upper_reg_num] & 3;
|
||||
bat_entry->prot = ppc_state.spr[upper_reg_num + 1] & 3;
|
||||
bat_entry->hi_mask = hi_mask;
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
}
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,22 +919,21 @@ static void ppc_dbat_update(uint32_t bat_reg)
|
||||
|
||||
upper_reg_num = bat_reg & 0xFFFFFFFE;
|
||||
|
||||
if (ppc_state.spr[upper_reg_num] & 3) { // is that BAT pair valid?
|
||||
bat_entry = &dbat_array[(bat_reg - 536) >> 1];
|
||||
bl = (ppc_state.spr[upper_reg_num] >> 2) & 0x7FF;
|
||||
hi_mask = ~((bl << 17) | 0x1FFFF);
|
||||
bat_entry = &dbat_array[(bat_reg - 536) >> 1];
|
||||
bl = (ppc_state.spr[upper_reg_num] >> 2) & 0x7FF;
|
||||
hi_mask = ~((bl << 17) | 0x1FFFF);
|
||||
|
||||
bat_entry->access = ppc_state.spr[upper_reg_num] & 3;
|
||||
bat_entry->prot = ppc_state.spr[upper_reg_num + 1] & 3;
|
||||
bat_entry->hi_mask = hi_mask;
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
bat_entry->access = ppc_state.spr[upper_reg_num] & 3;
|
||||
bat_entry->prot = ppc_state.spr[upper_reg_num + 1] & 3;
|
||||
bat_entry->hi_mask = hi_mask;
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
|
||||
}
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void mmu_pat_ctx_changed()
|
||||
@@ -965,7 +968,7 @@ void mmu_print_regs()
|
||||
}
|
||||
}
|
||||
|
||||
LOG_F(INFO, "");
|
||||
LOG_F(INFO, "%s", "");
|
||||
LOG_F(INFO, "SDR1 = 0x%X", ppc_state.spr[SPR::SDR1]);
|
||||
LOG_F(INFO, "Segment registers:");
|
||||
|
||||
@@ -1005,7 +1008,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
// perform full address translation and refill the secondary TLB
|
||||
tlb2_entry = dtlb2_refill(guest_va, 0);
|
||||
if (tlb2_entry->flags & PAGE_NOPHYS) {
|
||||
return UnmappedVal;
|
||||
return (T)UnmappedVal;
|
||||
}
|
||||
}
|
||||
#ifdef TLB_PROFILING
|
||||
@@ -1079,8 +1082,8 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
}
|
||||
if (!(tlb1_entry->flags & TLBFlags::PTE_SET_C)) {
|
||||
// perform full page address translation to update PTE.C bit
|
||||
PATResult pat_res = page_address_translation(guest_va, false,
|
||||
!!(ppc_state.msr & 0x4000), true);
|
||||
page_address_translation(guest_va, false,
|
||||
!!(ppc_state.msr & 0x4000), true);
|
||||
tlb1_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
|
||||
// don't forget to update the secondary TLB as well
|
||||
@@ -1118,8 +1121,8 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
|
||||
if (!(tlb2_entry->flags & TLBFlags::PTE_SET_C)) {
|
||||
// perform full page address translation to update PTE.C bit
|
||||
PATResult pat_res = page_address_translation(guest_va, false,
|
||||
!!(ppc_state.msr & 0x4000), true);
|
||||
page_address_translation(guest_va, false,
|
||||
!!(ppc_state.msr & 0x4000), true);
|
||||
tlb2_entry->flags |= TLBFlags::PTE_SET_C;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ enum TLBFlags : uint16_t {
|
||||
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 uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size, bool* is_writable);
|
||||
|
||||
extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
|
||||
+51
-27
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// General opcodes for the processor - ppcopcodes.cpp
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <core/mathutils.h>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <array>
|
||||
@@ -728,7 +729,7 @@ void dppc_interpreter::ppc_srawi() {
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
static inline uint32_t rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
||||
uint32_t m2 = 0xFFFFFFFFUL << (31 - rot_me);
|
||||
uint32_t m2 = (uint32_t)(0xFFFFFFFFUL << (31 - rot_me));
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
@@ -855,18 +856,47 @@ void dppc_interpreter::ppc_mtmsr() {
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint64_t calc_rtcl_value()
|
||||
static inline void calc_rtcl_value()
|
||||
{
|
||||
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
|
||||
uint64_t rtc_inc = diff * tbr_freq_hz / NS_PER_SEC;
|
||||
uint64_t rtc_l = rtc_lo + (rtc_inc << 7);
|
||||
uint64_t new_ts = get_virt_time_ns();
|
||||
uint64_t rtc_l = new_ts - rtc_timestamp + rtc_lo;
|
||||
if (rtc_l >= ONE_BILLION_NS) { // check RTCL overflow
|
||||
rtc_hi += rtc_l / ONE_BILLION_NS;
|
||||
rtc_hi += (uint32_t)(rtc_l / ONE_BILLION_NS);
|
||||
rtc_lo = rtc_l % ONE_BILLION_NS;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
rtc_l = rtc_lo;
|
||||
}
|
||||
return rtc_l & 0x3FFFFF80UL;
|
||||
else {
|
||||
rtc_lo = (uint32_t)rtc_l;
|
||||
}
|
||||
rtc_timestamp = new_ts;
|
||||
}
|
||||
|
||||
static inline uint64_t calc_tbr_value()
|
||||
{
|
||||
uint64_t tbr_inc;
|
||||
uint32_t tbr_inc_lo;
|
||||
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
|
||||
_u32xu64(tbr_freq_ghz, diff, tbr_inc, tbr_inc_lo);
|
||||
return (tbr_wr_value + tbr_inc);
|
||||
}
|
||||
|
||||
static inline uint32_t calc_dec_value() {
|
||||
uint64_t dec_adj;
|
||||
uint32_t dec_adj_lo;
|
||||
uint64_t diff = get_virt_time_ns() - dec_wr_timestamp;
|
||||
_u32xu64(tbr_freq_ghz, diff, dec_adj, dec_adj_lo);
|
||||
return (dec_wr_value - dec_adj);
|
||||
}
|
||||
|
||||
static void update_timebase(uint64_t mask, uint64_t new_val)
|
||||
{
|
||||
uint64_t tbr_value = calc_tbr_value();
|
||||
tbr_wr_value = (tbr_value & mask) | new_val;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
}
|
||||
|
||||
static void update_decrementer(uint32_t val) {
|
||||
dec_wr_value = val;
|
||||
dec_wr_timestamp = get_virt_time_ns();
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_mfspr() {
|
||||
@@ -880,30 +910,21 @@ void dppc_interpreter::ppc_mfspr() {
|
||||
|
||||
switch (ref_spr) {
|
||||
case SPR::RTCL_U:
|
||||
ppc_state.spr[SPR::RTCL_U] = calc_rtcl_value();
|
||||
calc_rtcl_value();
|
||||
ppc_state.spr[SPR::RTCL_U] = rtc_lo & 0x3FFFFF80UL;
|
||||
break;
|
||||
case SPR::RTCU_U:
|
||||
ppc_state.spr[SPR::RTCL_U] = rtc_hi;
|
||||
calc_rtcl_value();
|
||||
ppc_state.spr[SPR::RTCU_U] = rtc_hi;
|
||||
break;
|
||||
case SPR::DEC:
|
||||
ppc_state.spr[SPR::DEC] = calc_dec_value();
|
||||
break;
|
||||
}
|
||||
|
||||
ppc_state.gpr[(ppc_cur_instruction >> 21) & 31] = ppc_state.spr[ref_spr];
|
||||
}
|
||||
|
||||
static inline uint64_t calc_tbr_value()
|
||||
{
|
||||
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
|
||||
uint64_t tbr_inc = diff * tbr_freq_hz / NS_PER_SEC;
|
||||
return (tbr_wr_value + tbr_inc);
|
||||
}
|
||||
|
||||
static void update_timebase(uint64_t mask, uint64_t new_val)
|
||||
{
|
||||
uint64_t tbr_value = calc_tbr_value();
|
||||
tbr_wr_value = (tbr_value & mask) | new_val;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_mtspr() {
|
||||
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 31) << 5) | ((ppc_cur_instruction >> 16) & 31);
|
||||
reg_s = (ppc_cur_instruction >> 21) & 31;
|
||||
@@ -926,12 +947,15 @@ void dppc_interpreter::ppc_mtspr() {
|
||||
|
||||
switch (ref_spr) {
|
||||
case SPR::RTCL_S:
|
||||
calc_rtcl_value();
|
||||
rtc_lo = val & 0x3FFFFF80UL;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
break;
|
||||
case SPR::RTCU_S:
|
||||
calc_rtcl_value();
|
||||
rtc_hi = val;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
break;
|
||||
case SPR::DEC:
|
||||
update_decrementer(val);
|
||||
break;
|
||||
case SPR::TBL_S:
|
||||
update_timebase(0xFFFFFFFF00000000ULL, val);
|
||||
|
||||
@@ -52,7 +52,7 @@ using namespace std;
|
||||
|
||||
static uint32_t str2addr(string& addr_str) {
|
||||
try {
|
||||
return stoul(addr_str, NULL, 0);
|
||||
return (uint32_t)stoul(addr_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + addr_str);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ static uint32_t str2addr(string& addr_str) {
|
||||
|
||||
static uint32_t str2num(string& num_str) {
|
||||
try {
|
||||
return stol(num_str, NULL, 0);
|
||||
return (uint32_t)stol(num_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + num_str);
|
||||
}
|
||||
@@ -410,7 +410,7 @@ void enter_debugger() {
|
||||
int log_level, context;
|
||||
size_t separator_pos;
|
||||
|
||||
unique_ptr<OfNvramUtils> ofnvram = unique_ptr<OfNvramUtils>(new OfNvramUtils);
|
||||
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
|
||||
|
||||
context = 1; /* start with the PowerPC context */
|
||||
|
||||
@@ -512,7 +512,7 @@ void enter_debugger() {
|
||||
}
|
||||
} else if (cmd == "next" || cmd == "ni") {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str) + 4;
|
||||
addr = (uint32_t)get_reg(addr_str) + 4;
|
||||
ppc_exec_until(addr);
|
||||
} else if (cmd == "until") {
|
||||
ss >> addr_str;
|
||||
@@ -588,7 +588,7 @@ void enter_debugger() {
|
||||
#endif
|
||||
} else {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
addr = (uint32_t)get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
|
||||
)
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
|
||||
@@ -19,4 +19,4 @@ file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
)
|
||||
|
||||
add_library(devices OBJECT ${SOURCES})
|
||||
target_link_libraries(devices PRIVATE cubeb)
|
||||
target_link_libraries(devices PRIVATE cubeb SDL2::SDL2)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -52,66 +52,64 @@ int AtaHardDisk::perform_command()
|
||||
{
|
||||
LOG_F(INFO, "%s: command 0x%x requested", this->name.c_str(), this->r_command);
|
||||
this->r_status |= BSY;
|
||||
this->r_status &= ~(DRDY);
|
||||
this->r_status &= ~DRDY;
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case RESET_ATAPI: {
|
||||
device_reset();
|
||||
break;
|
||||
}
|
||||
case RECALIBRATE:
|
||||
hdd_img.seekg(0, std::ios::beg);
|
||||
this->r_error = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
break;
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * 512;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.read(buffer, sec_count * 512);
|
||||
this->r_status &= ~(DRQ);
|
||||
break;
|
||||
}
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * 512;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.write(buffer, sec_count * 512);
|
||||
this->r_status &= ~(DRQ);
|
||||
break;
|
||||
}
|
||||
case INIT_DEV_PARAM:
|
||||
break;
|
||||
case DIAGNOSTICS: {
|
||||
this->r_status |= DRQ;
|
||||
int ret_code = this->r_error;
|
||||
this->r_status &= ~(DRQ);
|
||||
return ret_code;
|
||||
break;
|
||||
}
|
||||
case IDENTIFY_DEVICE: {
|
||||
this->r_status |= DRQ;
|
||||
std::memcpy(buffer, ide_hd_id, 512);
|
||||
this->r_status &= ~(DRQ);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_F(INFO, "Unknown ATA command 0x%x", this->r_command);
|
||||
this->r_status &= ~(BSY);
|
||||
this->r_status |= ERR;
|
||||
return -1;
|
||||
case NOP:
|
||||
break;
|
||||
case RESET_ATAPI:
|
||||
device_reset();
|
||||
break;
|
||||
case RECALIBRATE:
|
||||
hdd_img.seekg(0, std::ios::beg);
|
||||
this->r_error = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
break;
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * ATA_HD_SEC_SIZE;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.read(buffer, sec_count * ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
}
|
||||
this->r_status &= ~(BSY);
|
||||
break;
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * ATA_HD_SEC_SIZE;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.write(buffer, sec_count * ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
}
|
||||
break;
|
||||
case INIT_DEV_PARAM:
|
||||
break;
|
||||
case DIAGNOSTICS: {
|
||||
this->r_status |= DRQ;
|
||||
int ret_code = this->r_error;
|
||||
this->r_status &= ~DRQ;
|
||||
return ret_code;
|
||||
}
|
||||
break;
|
||||
case IDENTIFY_DEVICE:
|
||||
this->r_status |= DRQ;
|
||||
std::memcpy(buffer, this->hd_id_data, ATA_HD_SEC_SIZE);
|
||||
this->r_status &= ~DRQ;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unknown ATA command 0x%x", this->name.c_str(), this->r_command);
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= ERR;
|
||||
return -1;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= DRDY;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file TA hard disk definitions. */
|
||||
/** @file ATA hard disk definitions. */
|
||||
|
||||
#ifndef ATA_HARD_DISK_H
|
||||
#define ATA_HARD_DISK_H
|
||||
@@ -28,6 +28,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#define ATA_HD_SEC_SIZE 512
|
||||
|
||||
class AtaHardDisk : public AtaBaseDevice
|
||||
{
|
||||
public:
|
||||
@@ -42,9 +44,7 @@ private:
|
||||
uint64_t img_size;
|
||||
char * buffer = new char[1 <<17];
|
||||
|
||||
char* ide_hd_id = {
|
||||
0x0
|
||||
};
|
||||
uint8_t hd_id_data[ATA_HD_SEC_SIZE] = {};
|
||||
};
|
||||
|
||||
#endif // ATA_HARD_DISK_H
|
||||
+168
-80
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,104 +25,152 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <endianswap.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <loguru.hpp>
|
||||
|
||||
void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb)
|
||||
{
|
||||
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 */
|
||||
memcpy((uint8_t*)p_cmd, mmu_get_dma_mem(cmd_addr, 16), 16);
|
||||
/* Load DMACmd from physical memory. */
|
||||
void DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd) {
|
||||
memcpy((uint8_t*)p_cmd, mmu_get_dma_mem(cmd_addr, 16, nullptr), 16);
|
||||
}
|
||||
|
||||
uint8_t DMAChannel::interpret_cmd() {
|
||||
DMACmd cmd_struct;
|
||||
bool is_writable, branch_taken = false;
|
||||
|
||||
get_next_cmd(this->cmd_ptr, &cmd_struct);
|
||||
if (this->cmd_in_progress) {
|
||||
// return current command if there is data to transfer
|
||||
if (this->queue_len)
|
||||
return this->cur_cmd;
|
||||
|
||||
this->ch_stat &= ~CH_STAT_WAKE; /* clear wake bit (DMA spec, 5.5.3.4) */
|
||||
// obtain real pointer to the descriptor of the completed command
|
||||
uint8_t *cmd_desc = mmu_get_dma_mem(this->cmd_ptr, 16, &is_writable);
|
||||
|
||||
switch (cmd_struct.cmd_key >> 4) {
|
||||
case 0:
|
||||
LOG_F(9, "Executing DMA Command OUTPUT_MORE");
|
||||
// get command code
|
||||
this->cur_cmd = cmd_desc[3] >> 4;
|
||||
|
||||
// all commands except STOP update cmd.xferStatus and
|
||||
// perform actions under control of "i", "b" and "w" bits
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
if (is_writable)
|
||||
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
|
||||
|
||||
if (cmd_desc[2] & 3) {
|
||||
ABORT_F("DBDMA: cmd.w bit not implemented");
|
||||
}
|
||||
|
||||
// react to cmd.b bit
|
||||
if (cmd_desc[2] & 0xC) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0xC) != 0xC) {
|
||||
uint16_t br_mask = this->branch_select >> 16;
|
||||
cond = (this->ch_stat & br_mask) == (this->branch_select & br_mask);
|
||||
if ((cmd_desc[2] & 0xC) == 0x8) { // branch if cond cleared?
|
||||
cond = !cond;
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
|
||||
branch_taken = true;
|
||||
}
|
||||
}
|
||||
|
||||
this->update_irq();
|
||||
}
|
||||
|
||||
// all INPUT and OUTPUT commands update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::STORE_QUAD && is_writable) {
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len & 0xFFFFUL);
|
||||
}
|
||||
|
||||
if (!branch_taken)
|
||||
this->cmd_ptr += 16;
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
}
|
||||
|
||||
fetch_cmd(this->cmd_ptr, &cmd_struct);
|
||||
|
||||
this->ch_stat &= ~CH_STAT_WAKE; // clear wake bit (DMA spec, 5.5.3.4)
|
||||
|
||||
this->cur_cmd = cmd_struct.cmd_key >> 4;
|
||||
|
||||
switch (this->cur_cmd) {
|
||||
case DBDMA_Cmd::OUTPUT_MORE:
|
||||
case DBDMA_Cmd::OUTPUT_LAST:
|
||||
case DBDMA_Cmd::INPUT_MORE:
|
||||
case DBDMA_Cmd::INPUT_LAST:
|
||||
if (cmd_struct.cmd_key & 7) {
|
||||
LOG_F(ERROR, "Key > 0 not implemented");
|
||||
break;
|
||||
}
|
||||
if (cmd_struct.cmd_bits & 0x3F) {
|
||||
LOG_F(ERROR, "non-zero i/b/w not implemented");
|
||||
break;
|
||||
}
|
||||
// this->dma_cb->dma_push(
|
||||
// mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count),
|
||||
// cmd_struct.req_count);
|
||||
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count);
|
||||
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count, &is_writable);
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->cmd_ptr += 16;
|
||||
this->cmd_in_progress = true;
|
||||
break;
|
||||
case 1:
|
||||
LOG_F(9, "Executing DMA Command OUTPUT_LAST");
|
||||
if (cmd_struct.cmd_key & 7) {
|
||||
LOG_F(ERROR, "Key > 0 not implemented");
|
||||
break;
|
||||
}
|
||||
if (cmd_struct.cmd_bits & 0x3F) {
|
||||
LOG_F(ERROR, "non-zero i/b/w not implemented");
|
||||
break;
|
||||
}
|
||||
// this->dma_cb->dma_push(
|
||||
// mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count),
|
||||
// cmd_struct.req_count);
|
||||
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count);
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->cmd_ptr += 16;
|
||||
break;
|
||||
case 2:
|
||||
LOG_F(ERROR, "Unsupported DMA Command INPUT_MORE");
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(ERROR, "Unsupported DMA Command INPUT_LAST");
|
||||
break;
|
||||
case 4:
|
||||
case DBDMA_Cmd::STORE_QUAD:
|
||||
LOG_F(ERROR, "Unsupported DMA Command STORE_QUAD");
|
||||
break;
|
||||
case 5:
|
||||
case DBDMA_Cmd::LOAD_QUAD:
|
||||
LOG_F(ERROR, "Unsupported DMA Command LOAD_QUAD");
|
||||
break;
|
||||
case 6:
|
||||
LOG_F(INFO, "Unsupported DMA Command NOP");
|
||||
case DBDMA_Cmd::NOP:
|
||||
LOG_F(ERROR, "Unsupported DMA Command NOP");
|
||||
break;
|
||||
case 7:
|
||||
LOG_F(INFO, "DMA Command: 7 (STOP)");
|
||||
case DBDMA_Cmd::STOP:
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
this->cmd_in_progress = false;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unsupported DMA command 0x%X", cmd_struct.cmd_key >> 4);
|
||||
LOG_F(ERROR, "Unsupported DMA command 0x%X", this->cur_cmd);
|
||||
this->ch_stat |= CH_STAT_DEAD;
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
}
|
||||
|
||||
return (cmd_struct.cmd_key >> 4);
|
||||
return this->cur_cmd;
|
||||
}
|
||||
|
||||
void DMAChannel::update_irq() {
|
||||
bool is_writable;
|
||||
|
||||
// obtain real pointer to the descriptor of the completed command
|
||||
uint8_t *cmd_desc = mmu_get_dma_mem(this->cmd_ptr, 16, &is_writable);
|
||||
|
||||
// STOP doesn't generate interrupts
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
if (cmd_desc[2] & 0x30) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0x30) != 0x30) {
|
||||
uint16_t int_mask = this->int_select >> 16;
|
||||
cond = (this->ch_stat & int_mask) == (this->int_select & int_mask);
|
||||
if ((cmd_desc[2] & 0x30) == 0x20) { // branch if cond cleared?
|
||||
cond = !cond;
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "Unsupported non-DWORD read from DMA channel");
|
||||
return 0;
|
||||
ABORT_F("DBDMA: non-DWORD read from a DMA channel not supported");
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
res = 0; /* ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74) */
|
||||
res = 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
res = BYTESWAP_32(this->ch_stat);
|
||||
@@ -138,8 +186,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
uint16_t mask, old_stat, new_stat;
|
||||
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "Unsupported non-DWORD write to DMA channel");
|
||||
return;
|
||||
ABORT_F("DBDMA: non-DWORD writes to a DMA channel not supported");
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
@@ -149,7 +196,22 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
case DMAReg::CH_CTRL:
|
||||
mask = value >> 16;
|
||||
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~mask);
|
||||
LOG_F(INFO, "New ChannelStatus value = 0x%X", new_stat);
|
||||
LOG_F(9, "New ChannelStatus value = 0x%X", new_stat);
|
||||
|
||||
// update ch_stat.s0...s7 if requested (needed for interrupt generation)
|
||||
if ((new_stat & 0xFF) != (old_stat & 0xFF)) {
|
||||
this->ch_stat |= new_stat & 0xFF;
|
||||
}
|
||||
|
||||
// flush bit can be set at the same time the run bit is cleared.
|
||||
// That means we need to update memory before channel operation
|
||||
// is aborted to prevent data loss.
|
||||
if (new_stat & CH_STAT_FLUSH) {
|
||||
// NOTE: because this implementation doesn't currently support
|
||||
// partial memory updates no special action is taken here
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
this->ch_stat = new_stat;
|
||||
}
|
||||
|
||||
if ((new_stat & CH_STAT_RUN) != (old_stat & CH_STAT_RUN)) {
|
||||
if (new_stat & CH_STAT_RUN) {
|
||||
@@ -157,10 +219,12 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->ch_stat = new_stat;
|
||||
this->start();
|
||||
} else {
|
||||
this->abort();
|
||||
this->update_irq();
|
||||
new_stat &= ~CH_STAT_ACTIVE;
|
||||
new_stat &= ~CH_STAT_DEAD;
|
||||
this->cmd_in_progress = false;
|
||||
this->ch_stat = new_stat;
|
||||
this->abort();
|
||||
}
|
||||
} else if ((new_stat & CH_STAT_WAKE) != (old_stat & CH_STAT_WAKE)) {
|
||||
new_stat |= CH_STAT_ACTIVE;
|
||||
@@ -173,20 +237,18 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->pause();
|
||||
}
|
||||
}
|
||||
if (new_stat & CH_STAT_FLUSH) {
|
||||
LOG_F(WARNING, "DMA flush not implemented!");
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
this->ch_stat = new_stat;
|
||||
}
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
break; /* ingore writes to ChannelStatus */
|
||||
break; // ingore writes to ChannelStatus
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
if (!(this->ch_stat & CH_STAT_RUN) && !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
this->cmd_ptr = value;
|
||||
LOG_F(INFO, "CommandPtrLo set to 0x%X", this->cmd_ptr);
|
||||
LOG_F(9, "CommandPtrLo set to 0x%X", this->cmd_ptr);
|
||||
}
|
||||
break;
|
||||
case DMAReg::BRANCH_SELECT:
|
||||
this->branch_select = value & 0xFF00FFUL;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
|
||||
}
|
||||
@@ -197,17 +259,17 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
*avail_len = 0;
|
||||
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
/* dead or idle channel? -> no more data */
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "Dead/idle channel -> no more data");
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
/* interpret DBDMA program until we get data or become idle */
|
||||
// interpret DBDMA program until we get data or become idle
|
||||
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
/* dequeue data if any */
|
||||
// dequeue data if any
|
||||
if (this->queue_len) {
|
||||
if (this->queue_len >= req_len) {
|
||||
LOG_F(9, "Return req_len = %d data", req_len);
|
||||
@@ -215,20 +277,45 @@ DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8
|
||||
*avail_len = req_len;
|
||||
this->queue_len -= req_len;
|
||||
this->queue_data += req_len;
|
||||
} else { /* return less data than req_len */
|
||||
} else { // return less data than req_len
|
||||
LOG_F(9, "Return queue_len = %d data", this->queue_len);
|
||||
*p_data = this->queue_data;
|
||||
*avail_len = this->queue_len;
|
||||
this->queue_len = 0;
|
||||
}
|
||||
return DmaPullResult::MoreData; /* tell the caller there is more data */
|
||||
return DmaPullResult::MoreData; // tell the caller there is more data
|
||||
}
|
||||
|
||||
return DmaPullResult::NoMoreData; /* tell the caller there is no more data */
|
||||
return DmaPullResult::NoMoreData; // tell the caller there is no more data
|
||||
}
|
||||
|
||||
bool DMAChannel::is_active()
|
||||
{
|
||||
int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
LOG_F(WARNING, "DBDMA: attempt to push data to dead/idle channel");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// interpret DBDMA program until we get buffer to fill in or become idle
|
||||
while ((this->ch_stat & CH_STAT_ACTIVE) && !this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
len = std::min((int)this->queue_len, len);
|
||||
std::memcpy(this->queue_data, src_ptr, len);
|
||||
this->queue_data += len;
|
||||
this->queue_len -= len;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program if the buffer became exhausted
|
||||
if (!this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DMAChannel::is_active() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
}
|
||||
@@ -237,18 +324,16 @@ bool DMAChannel::is_active()
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::start()
|
||||
{
|
||||
void DMAChannel::start() {
|
||||
if (this->ch_stat & CH_STAT_PAUSE) {
|
||||
LOG_F(WARNING, "Cannot start DMA channel, PAUSE bit is set");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Starting DMA channel, stat = 0x%X", this->ch_stat);
|
||||
|
||||
this->queue_len = 0;
|
||||
|
||||
this->start_cb();
|
||||
if (this->start_cb)
|
||||
this->start_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::resume() {
|
||||
@@ -261,10 +346,13 @@ void DMAChannel::resume() {
|
||||
}
|
||||
|
||||
void DMAChannel::abort() {
|
||||
LOG_F(INFO, "Aborting DMA channel");
|
||||
LOG_F(9, "Aborting DMA channel");
|
||||
if (this->stop_cb)
|
||||
this->stop_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::pause() {
|
||||
LOG_F(INFO, "Pausing DMA channel");
|
||||
this->stop_cb();
|
||||
if (this->stop_cb)
|
||||
this->stop_cb();
|
||||
}
|
||||
+51
-20
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -30,19 +30,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define DB_DMA_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
/** DBDMA Channel registers offsets */
|
||||
enum DMAReg : uint32_t {
|
||||
CH_CTRL = 0,
|
||||
CH_STAT = 4,
|
||||
CMD_PTR_LO = 12,
|
||||
CH_CTRL = 0,
|
||||
CH_STAT = 4,
|
||||
CMD_PTR_LO = 12,
|
||||
INT_SELECT = 16,
|
||||
BRANCH_SELECT = 20,
|
||||
};
|
||||
|
||||
/** Channel Status bits (DBDMA spec, 5.5.3) */
|
||||
enum {
|
||||
enum : uint16_t {
|
||||
CH_STAT_ACTIVE = 0x400,
|
||||
CH_STAT_DEAD = 0x800,
|
||||
CH_STAT_WAKE = 0x1000,
|
||||
@@ -53,18 +56,31 @@ enum {
|
||||
|
||||
/** DBDMA command (DBDMA spec, 5.6.1) - all fields are little-endian! */
|
||||
typedef struct DMACmd {
|
||||
uint16_t req_count;
|
||||
uint8_t cmd_bits;
|
||||
uint8_t cmd_key;
|
||||
uint32_t address;
|
||||
uint32_t cmd_arg;
|
||||
uint16_t res_count;
|
||||
uint16_t xfer_stat;
|
||||
uint16_t req_count;
|
||||
uint8_t cmd_bits;
|
||||
uint8_t cmd_key;
|
||||
uint32_t address;
|
||||
uint32_t cmd_arg;
|
||||
uint16_t res_count;
|
||||
uint16_t xfer_stat;
|
||||
} DMACmd;
|
||||
|
||||
namespace DBDMA_Cmd {
|
||||
enum : uint8_t {
|
||||
OUTPUT_MORE = 0,
|
||||
OUTPUT_LAST = 1,
|
||||
INPUT_MORE = 2,
|
||||
INPUT_LAST = 3,
|
||||
STORE_QUAD = 4,
|
||||
LOAD_QUAD = 5,
|
||||
NOP = 6,
|
||||
STOP = 7
|
||||
};
|
||||
};
|
||||
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel : public DmaOutChannel {
|
||||
class DMAChannel : public DmaBidirChannel {
|
||||
public:
|
||||
DMAChannel() = default;
|
||||
~DMAChannel() = default;
|
||||
@@ -75,10 +91,17 @@ public:
|
||||
|
||||
bool is_active();
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
int push_data(const char* src_ptr, int len);
|
||||
|
||||
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint32_t irq_id) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
this->irq_id = irq_id;
|
||||
};
|
||||
|
||||
protected:
|
||||
void get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
|
||||
void fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
|
||||
uint8_t interpret_cmd(void);
|
||||
void update_irq();
|
||||
|
||||
void start(void);
|
||||
void resume(void);
|
||||
@@ -86,14 +109,22 @@ protected:
|
||||
void pause(void);
|
||||
|
||||
private:
|
||||
std::function<void(void)> start_cb; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb; // DMA channel stop callback
|
||||
std::function<void(void)> start_cb = nullptr; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb = nullptr; // DMA channel stop callback
|
||||
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
uint32_t queue_len = 0;
|
||||
uint8_t* queue_data = 0;
|
||||
uint32_t int_select = 0;
|
||||
uint32_t branch_select = 0;
|
||||
|
||||
uint32_t queue_len;
|
||||
uint8_t* queue_data;
|
||||
bool cmd_in_progress = false;
|
||||
uint8_t cur_cmd;
|
||||
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif /* DB_DMA_H */
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -38,13 +38,13 @@ public:
|
||||
uint8_t **p_data) = 0;
|
||||
};
|
||||
|
||||
// Base class for bidirectional DMA channels.
|
||||
class DmaBidirChannel {
|
||||
class DmaInChannel {
|
||||
public:
|
||||
virtual bool is_active() { return true; };
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
};
|
||||
|
||||
// Base class for bidirectional DMA channels.
|
||||
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
|
||||
};
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -45,6 +45,7 @@ enum HWCompType {
|
||||
SCSI_DEV = 1ULL << 22, /* SCSI device */
|
||||
IDE_BUS = 1ULL << 23, /* IDE bus */
|
||||
IDE_DEV = 1ULL << 25, /* IDE device */
|
||||
SND_CODEC = 1ULL << 30, /* Sound codec */
|
||||
SND_SERVER = 1ULL << 31, /* host sound server */
|
||||
FLOPPY_CTRL = 1ULL << 32, /* floppy disk controller */
|
||||
FLOPPY_DRV = 1ULL << 33, /* floppy disk drive */
|
||||
|
||||
@@ -75,13 +75,14 @@ private:
|
||||
class GossamerID : public MMIODevice {
|
||||
public:
|
||||
GossamerID(const uint16_t id) {
|
||||
this->id = id, this->name = "Machine-id";
|
||||
this->id = id;
|
||||
this->name = "Machine-id";
|
||||
supports_types(HWCompType::MMIO_DEV);
|
||||
};
|
||||
~GossamerID() = default;
|
||||
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return ((!offset && size == 2) ? this->id : 0);
|
||||
return ((offset == 4 && size == 2) ? this->id : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -46,15 +46,14 @@ NVram::NVram(std::string file_name, uint32_t ram_size)
|
||||
this->file_name = file_name;
|
||||
this->ram_size = ram_size;
|
||||
|
||||
this->storage = new uint8_t[ram_size];
|
||||
// allocate memory storage and fill it with zeroes
|
||||
this->storage = std::unique_ptr<uint8_t[]>(new uint8_t[ram_size] ());
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
||||
NVram::~NVram() {
|
||||
this->save();
|
||||
if (this->storage)
|
||||
delete this->storage;
|
||||
}
|
||||
|
||||
uint8_t NVram::read_byte(uint32_t offset) {
|
||||
@@ -74,9 +73,8 @@ void NVram::init() {
|
||||
if (f.fail() || !f.read(sig, sizeof(NVRAM_FILE_ID)) ||
|
||||
!f.read((char*)&data_size, sizeof(data_size)) ||
|
||||
memcmp(sig, NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID)) || data_size != this->ram_size ||
|
||||
!f.read((char*)this->storage, this->ram_size)) {
|
||||
!f.read((char*)this->storage.get(), this->ram_size)) {
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file.");
|
||||
memset(this->storage, 0, this->ram_size);
|
||||
}
|
||||
|
||||
f.close();
|
||||
@@ -90,7 +88,7 @@ void NVram::save() {
|
||||
f.write((char*)&this->ram_size, sizeof(this->ram_size));
|
||||
|
||||
/* write NVRAM content */
|
||||
f.write((char*)this->storage, this->ram_size);
|
||||
f.write((char*)this->storage.get(), this->ram_size);
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
private:
|
||||
std::string file_name; // file name for the backing file
|
||||
uint16_t ram_size; // NVRAM size
|
||||
uint8_t* storage;
|
||||
std::unique_ptr<uint8_t[]> storage;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
|
||||
+336
-74
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Utilities for working with the Apple Open Firmware NVRAM partition. */
|
||||
/** Utilities for working with Apple Open Firmware and CHRP NVRAM partitions. */
|
||||
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include <endianswap.h>
|
||||
@@ -32,14 +32,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static std::string hex2str(uint32_t n)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << setw(8) << setfill('0') << hex << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static uint32_t str2env(string& num_str) {
|
||||
try {
|
||||
return stoul(num_str, NULL, 0);
|
||||
return (uint32_t)stoul(num_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
string num_str2 = string("0x") + num_str;
|
||||
@@ -50,22 +58,15 @@ static uint32_t str2env(string& num_str) {
|
||||
}
|
||||
}
|
||||
|
||||
int OfNvramUtils::init()
|
||||
{
|
||||
this->nvram_obj = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
return this->nvram_obj == nullptr;
|
||||
}
|
||||
|
||||
bool OfNvramUtils::validate()
|
||||
{
|
||||
int i;
|
||||
OfNvramHdr hdr;
|
||||
bool OfConfigAppl::validate() {
|
||||
int i;
|
||||
OfConfigHdrAppl hdr;
|
||||
|
||||
if (this->nvram_obj == nullptr)
|
||||
return false;
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfNvramHdr); i++) {
|
||||
for (i = 0; i < sizeof(OfConfigHdrAppl); i++) {
|
||||
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ bool OfNvramUtils::validate()
|
||||
|
||||
this->size = hdr.num_pages * 256;
|
||||
|
||||
if (this->size != 0x800)
|
||||
if (this->size != OF_CFG_SIZE)
|
||||
return false;
|
||||
|
||||
// read the entire partition into the local buffer
|
||||
@@ -88,10 +89,9 @@ bool OfNvramUtils::validate()
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
uint16_t OfNvramUtils::checksum_partition()
|
||||
{
|
||||
uint16_t OfConfigAppl::checksum_partition() {
|
||||
uint32_t acc = 0;
|
||||
|
||||
for (int i = 0; i < this->size; i += 2) {
|
||||
@@ -101,25 +101,6 @@ uint16_t OfNvramUtils::checksum_partition()
|
||||
return acc + (acc >> 16);
|
||||
}
|
||||
|
||||
void OfNvramUtils::update_partition()
|
||||
{
|
||||
// set checksum in the header to zero
|
||||
this->buf[4] = 0;
|
||||
this->buf[5] = 0;
|
||||
|
||||
// calculate new checksum
|
||||
uint16_t checksum = this->checksum_partition();
|
||||
checksum = checksum ? ~checksum : 0xFFFFU;
|
||||
|
||||
// stuff it into the header
|
||||
WRITE_WORD_BE_A(&this->buf[4], checksum);
|
||||
|
||||
// write the entire partition back to NVRAM
|
||||
for (int i = 0; i < this->size; i++) {
|
||||
this->nvram_obj->write_byte(OF_NVRAM_OFFSET + i, this->buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static const string flag_names[8] = {
|
||||
"little-endian?",
|
||||
"real-mode?",
|
||||
@@ -154,58 +135,74 @@ static const map<string, std::tuple<int, uint16_t>> of_vars = {
|
||||
{"boot-command", {OF_VAR_TYPE_STR, 0x58}},
|
||||
};
|
||||
|
||||
void OfNvramUtils::printenv()
|
||||
{
|
||||
int i;
|
||||
const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
|
||||
this->_config_vars.clear();
|
||||
|
||||
if (!this->validate()) {
|
||||
cout << "Invalid Open Firmware partition content!" << endl;
|
||||
return;
|
||||
}
|
||||
if (!this->validate())
|
||||
return _config_vars;
|
||||
|
||||
uint8_t of_flags = this->buf[12];
|
||||
|
||||
cout << endl;
|
||||
|
||||
// print flags
|
||||
for (i = 0; i < 8; i++) {
|
||||
cout << setw(20) << left << flag_names[i] <<
|
||||
(((of_flags << i) & 0x80) ? "true" : "false") << endl;
|
||||
// populate flags
|
||||
for (int i = 0; i < 8; i++) {
|
||||
_config_vars.push_back(std::make_pair(flag_names[i],
|
||||
((of_flags << i) & 0x80) ? "true" : "false"));
|
||||
}
|
||||
|
||||
// print the remaining variables
|
||||
// populate the remaining variables
|
||||
for (auto& var : of_vars) {
|
||||
auto name = var.first;
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
|
||||
cout << setw(20) << left << var.first;
|
||||
|
||||
switch (type) {
|
||||
case OF_VAR_TYPE_INT:
|
||||
cout << hex << READ_DWORD_BE_A(&this->buf[offset]) << endl;
|
||||
_config_vars.push_back(std::make_pair(name,
|
||||
hex2str(READ_DWORD_BE_A(&this->buf[offset]))));
|
||||
break;
|
||||
case OF_VAR_TYPE_STR:
|
||||
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - OF_NVRAM_OFFSET;
|
||||
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
|
||||
for (i = 0; i < str_len; i++) {
|
||||
char ch = *(char *)&(this->buf[str_offset + i]);
|
||||
if (ch == '\x0D') cout << endl; else cout << ch;
|
||||
|
||||
if ((str_offset + str_len) > OF_CFG_SIZE) {
|
||||
cout << "string property too long - skip it" << endl;
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
char prop_val[OF_CFG_SIZE] = "";
|
||||
memcpy(prop_val, &this->buf[str_offset], str_len);
|
||||
prop_val[str_len] = '\0';
|
||||
|
||||
_config_vars.push_back(std::make_pair(name, prop_val));
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
return _config_vars;
|
||||
};
|
||||
|
||||
void OfConfigAppl::update_partition() {
|
||||
// set checksum in the header to zero
|
||||
this->buf[4] = 0;
|
||||
this->buf[5] = 0;
|
||||
|
||||
// calculate new checksum
|
||||
uint16_t checksum = this->checksum_partition();
|
||||
checksum = checksum ? ~checksum : 0xFFFFU;
|
||||
|
||||
// stuff checksum into the header
|
||||
WRITE_WORD_BE_A(&this->buf[4], checksum);
|
||||
|
||||
// write the entire partition back to NVRAM
|
||||
for (int i = 0; i < this->size; i++) {
|
||||
this->nvram_obj->write_byte(OF_NVRAM_OFFSET + i, this->buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void OfNvramUtils::setenv(string var_name, string value)
|
||||
{
|
||||
bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
|
||||
int i, flag;
|
||||
|
||||
if (!this->validate()) {
|
||||
cout << "Invalid Open Firmware partition content!" << endl;
|
||||
return;
|
||||
}
|
||||
if (!this->validate())
|
||||
return false;
|
||||
|
||||
// check if the user tries to change a flag
|
||||
for (i = 0; i < 8; i++) {
|
||||
@@ -216,7 +213,7 @@ void OfNvramUtils::setenv(string var_name, string value)
|
||||
flag = 0;
|
||||
else {
|
||||
cout << "Invalid property value: " << value << endl;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
uint8_t flag_bit = 0x80U >> i;
|
||||
uint8_t of_flags = this->buf[12];
|
||||
@@ -228,15 +225,14 @@ void OfNvramUtils::setenv(string var_name, string value)
|
||||
|
||||
this->buf[12] = of_flags;
|
||||
this->update_partition();
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// see if one of the standard properties should be changed
|
||||
if (of_vars.find(var_name) == of_vars.end()) {
|
||||
cout << "Attempt to change unknown variable " << var_name << endl;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto type = std::get<0>(of_vars.at(var_name));
|
||||
@@ -248,7 +244,7 @@ void OfNvramUtils::setenv(string var_name, string value)
|
||||
num = str2env(value);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
WRITE_DWORD_BE_A(&this->buf[offset], num);
|
||||
this->update_partition();
|
||||
@@ -257,7 +253,7 @@ void OfNvramUtils::setenv(string var_name, string value)
|
||||
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]);
|
||||
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
|
||||
|
||||
OfNvramHdr *hdr = (OfNvramHdr *)&this->buf[0];
|
||||
OfConfigHdrAppl *hdr = (OfConfigHdrAppl *)&this->buf[0];
|
||||
uint16_t here = READ_WORD_BE_A(&hdr->here);
|
||||
uint16_t top = READ_WORD_BE_A(&hdr->top);
|
||||
|
||||
@@ -266,11 +262,13 @@ void OfNvramUtils::setenv(string var_name, string value)
|
||||
uint16_t new_top = top + str_len - value.length();
|
||||
if (new_top < here) {
|
||||
cout << "No room in the heap!" << endl;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove the old string
|
||||
std::memmove(&this->buf[top + str_len - OF_NVRAM_OFFSET], &this->buf[top - OF_NVRAM_OFFSET], str_offset - top);
|
||||
std::memmove(&this->buf[top + str_len - OF_NVRAM_OFFSET],
|
||||
&this->buf[top - OF_NVRAM_OFFSET], str_offset - top);
|
||||
|
||||
for (auto& var : of_vars) {
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
@@ -299,7 +297,271 @@ void OfNvramUtils::setenv(string var_name, string value)
|
||||
|
||||
// update physical NVRAM
|
||||
this->update_partition();
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
uint8_t OfConfigChrp::checksum_hdr(const uint8_t* data)
|
||||
{
|
||||
uint16_t sum = data[0];
|
||||
|
||||
for (int i = 2; i < 16; i++) {
|
||||
sum += data[i];
|
||||
if (sum >= 256)
|
||||
sum = (sum + 1) & 0xFFU;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
bool OfConfigChrp::validate()
|
||||
{
|
||||
int i, pos, len;
|
||||
uint8_t sig;
|
||||
bool wip = true;
|
||||
bool of_part_found = false;
|
||||
|
||||
// search the entire 8KB NVRAM for CHRP OF config partition.
|
||||
// Bail out if an unknown partition or free space is encountered.
|
||||
// Skip over known partitions.
|
||||
for (pos = 0; wip && pos < 8192;) {
|
||||
sig = this->nvram_obj->read_byte(pos);
|
||||
switch (sig) {
|
||||
case NVRAM_SIG_OF_ENV:
|
||||
of_part_found = true;
|
||||
// fall-through
|
||||
case NVRAM_SIG_FREE:
|
||||
wip = false;
|
||||
break;
|
||||
case NVRAM_SIG_VPD:
|
||||
case NVRAM_SIG_DIAG:
|
||||
case NVRAM_SIG_OF_CFG:
|
||||
case NVRAM_SIG_MAC_OS:
|
||||
case NVRAM_SIG_ERR_LOG:
|
||||
// skip valid partitions we're not interested in
|
||||
len = (this->nvram_obj->read_byte(pos + 2) << 8) |
|
||||
this->nvram_obj->read_byte(pos + 3);
|
||||
if (!len || (len * 16) >= 8192)
|
||||
break;
|
||||
pos += len * 16;
|
||||
break;
|
||||
default:
|
||||
wip = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!of_part_found)
|
||||
return false;
|
||||
|
||||
OfConfigHdrChrp hdr;
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfConfigHdrChrp); i++) {
|
||||
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(pos + i);
|
||||
}
|
||||
|
||||
len = BYTESWAP_16(hdr.length) * 16;
|
||||
|
||||
// sanity checks
|
||||
if (hdr.sig != NVRAM_SIG_OF_ENV || len < 16 || len > (4096 + sizeof(OfConfigHdrChrp)))
|
||||
return false;
|
||||
|
||||
// calculate partition header checksum
|
||||
uint8_t chk_sum = this->checksum_hdr((uint8_t*)&hdr);
|
||||
|
||||
if (chk_sum != hdr.checksum)
|
||||
return false;
|
||||
|
||||
len -= sizeof(OfConfigHdrChrp);
|
||||
pos += sizeof(OfConfigHdrChrp);
|
||||
|
||||
this->data_offset = pos;
|
||||
|
||||
// read the entire partition into the local buffer
|
||||
for (i = 0; i < len; i++) {
|
||||
this->buf[i] = this->nvram_obj->read_byte(pos + i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const OfConfigImpl::config_dict& OfConfigChrp::get_config_vars() {
|
||||
int len;
|
||||
|
||||
this->_config_vars.clear();
|
||||
|
||||
if (!this->validate())
|
||||
return _config_vars;
|
||||
|
||||
for (int pos = 0; pos < 4096;) {
|
||||
char *pname = (char *)&this->buf[pos];
|
||||
|
||||
// scan property name until '=' is encountered
|
||||
// or max length is reached
|
||||
for (len = 0; len < 32; pos++, len++) {
|
||||
if (pname[len] == '=' || pname[len] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
// empty property name -> free space reached
|
||||
if (!len) {
|
||||
this->data_length = pos;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pname[len] != '=') {
|
||||
cout << "no = sign found or name > 31 chars" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
char prop_name[32];
|
||||
memcpy(prop_name, pname, len);
|
||||
prop_name[len] = '\0';
|
||||
|
||||
pos++; // skip past '='
|
||||
char *pval = (char *)&this->buf[pos];
|
||||
|
||||
// determine property value length
|
||||
for (len = 0; pos < 4096; pos++, len++) {
|
||||
if (pval[len] == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
// ensure each property value is null-terminated
|
||||
if (pos >= 4096) {
|
||||
cout << "ran off partition end" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
this->_config_vars.push_back(std::make_pair(prop_name, pval));
|
||||
pos++; // skip past null terminator
|
||||
}
|
||||
|
||||
return this->_config_vars;
|
||||
}
|
||||
|
||||
bool OfConfigChrp::update_partition() {
|
||||
unsigned pos = 0;
|
||||
|
||||
memset(this->buf, 0, 4096);
|
||||
|
||||
for (auto& var : this->_config_vars) {
|
||||
if ((var.first.length() + var.second.length() + 2) >= 4096) {
|
||||
cout << "No room in the partition!" << endl;
|
||||
return false;
|
||||
}
|
||||
memcpy(&this->buf[pos], var.first.c_str(), var.first.length());
|
||||
pos += var.first.length();
|
||||
this->buf[pos++] = '=';
|
||||
memcpy(&this->buf[pos], var.second.c_str(), var.second.length());
|
||||
pos += var.second.length();
|
||||
this->buf[pos++] = '\0';
|
||||
}
|
||||
|
||||
// write the entire partition back to NVRAM
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
this->nvram_obj->write_byte(this->data_offset + i, this->buf[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfConfigChrp::set_var(std::string& var_name, std::string& value) {
|
||||
if (!this->validate())
|
||||
return false;
|
||||
|
||||
bool found = false;
|
||||
|
||||
// see if the user tries to change an existing property
|
||||
for (auto& var : this->_config_vars) {
|
||||
if (var.first == var_name) {
|
||||
found = true;
|
||||
|
||||
// see if we're about to change a flag
|
||||
if (var_name.back() == '?') {
|
||||
if (value != "true" && value != "false") {
|
||||
cout << "Flag value can be 'true' or 'false'" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (value.length() > var.second.length()) {
|
||||
unsigned free_space = 4096 - this->data_length;
|
||||
if ((value.length() - var.second.length()) >= free_space) {
|
||||
cout << "No room for new data!" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var.second = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
cout << "Attempt to change unknown variable " << var_name << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->update_partition();
|
||||
};
|
||||
|
||||
int OfConfigUtils::init()
|
||||
{
|
||||
this->nvram_obj = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
return this->nvram_obj == nullptr;
|
||||
}
|
||||
|
||||
bool OfConfigUtils::open_container() {
|
||||
OfConfigImpl* cfg_obj;
|
||||
|
||||
if (this->cfg_impl == nullptr) {
|
||||
cfg_obj = new OfConfigAppl(this->nvram_obj);
|
||||
if (cfg_obj->validate()) {
|
||||
this->cfg_impl = std::unique_ptr<OfConfigImpl>(cfg_obj);
|
||||
return true;
|
||||
} else {
|
||||
delete(cfg_obj);
|
||||
|
||||
cfg_obj = new OfConfigChrp(this->nvram_obj);
|
||||
if (cfg_obj->validate()) {
|
||||
this->cfg_impl = std::unique_ptr<OfConfigImpl>(cfg_obj);
|
||||
return true;
|
||||
} else {
|
||||
delete(cfg_obj);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return this->cfg_impl->validate();
|
||||
}
|
||||
|
||||
cout << "No valid Open Firmware partition found!" << endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OfConfigUtils::printenv() {
|
||||
OfConfigImpl::config_dict vars;
|
||||
|
||||
if (!this->open_container())
|
||||
return;
|
||||
|
||||
vars = this->cfg_impl->get_config_vars();
|
||||
|
||||
for (auto& var : vars) {
|
||||
cout << setw(34) << left << var.first << var.second << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void OfConfigUtils::setenv(string var_name, string value)
|
||||
{
|
||||
if (!this->open_container())
|
||||
return;
|
||||
|
||||
if (!this->cfg_impl->set_var(var_name, value)) {
|
||||
cout << " Please try again" << endl;
|
||||
} else {
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
}
|
||||
}
|
||||
+95
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,20 +19,30 @@ 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/CHRP Open Firmware NVRAM partition definitions. */
|
||||
|
||||
#ifndef OF_NVRAM_H
|
||||
#define OF_NVRAM_H
|
||||
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
/** @file Utilities for working with the Apple Open Firmware NVRAM partition. */
|
||||
#include <cinttypes>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
|
||||
#define OF_NVRAM_OFFSET 0x1800
|
||||
#define OF_NVRAM_SIG 0x1275
|
||||
#define OF_CFG_SIZE 0x800
|
||||
|
||||
// OF Variable types
|
||||
enum {
|
||||
OF_VAR_TYPE_INT = 1,
|
||||
OF_VAR_TYPE_STR = 2,
|
||||
OF_VAR_TYPE_INT = 1, // integer
|
||||
OF_VAR_TYPE_STR = 2, // string
|
||||
OF_VAR_TYPE_FLG = 3, // boolean flag
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@@ -42,26 +52,97 @@ typedef struct {
|
||||
uint16_t checksum; // >nv.checksum partition checksum
|
||||
uint16_t here; // >nv.here offset to the next free byte (offset of after last string length; = 0x185c)
|
||||
uint16_t top; // >nv.top offset to the last free byte (offset of string with lowest offset; < 0x2000)
|
||||
} OfNvramHdr;
|
||||
} OfConfigHdrAppl;
|
||||
|
||||
class OfNvramUtils {
|
||||
/** ================== CHRP NVRAM partition definitions. ================== */
|
||||
|
||||
/** CHRP NVRAM partition signatures. */
|
||||
enum {
|
||||
NVRAM_SIG_OF_CFG = 0x50, // of-config (unused in Power Macintosh)
|
||||
NVRAM_SIG_VPD = 0x52, // of-vpd (unused in Power Macintosh)
|
||||
NVRAM_SIG_DIAG = 0x5F, // diagnostics partition
|
||||
NVRAM_SIG_OF_ENV = 0x70, // common partition with OF environment vars
|
||||
NVRAM_SIG_ERR_LOG = 0x72, // post-err-log
|
||||
NVRAM_SIG_FREE = 0x7F, // free space
|
||||
NVRAM_SIG_MAC_OS = 0xA0, // APL,MacOS75
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t sig; // partition signature, must be 0x70
|
||||
uint8_t checksum; // partition header checksum (sig, length & name)
|
||||
uint16_t length; // partition length in 16-byte blocks
|
||||
char name[12]; // null-terminated partition name
|
||||
} OfConfigHdrChrp;
|
||||
|
||||
// - interface
|
||||
class OfConfigImpl {
|
||||
public:
|
||||
OfNvramUtils() = default;
|
||||
~OfNvramUtils() = default;
|
||||
using config_dict = std::vector<std::pair<std::string, std::string>>;
|
||||
|
||||
virtual ~OfConfigImpl() = default;
|
||||
virtual bool validate() = 0;
|
||||
virtual const config_dict& get_config_vars() = 0;
|
||||
virtual bool set_var(std::string& name, std::string& val) = 0;
|
||||
};
|
||||
|
||||
// Old World implementation
|
||||
class OfConfigAppl : public OfConfigImpl {
|
||||
public:
|
||||
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
|
||||
~OfConfigAppl() = default;
|
||||
|
||||
bool validate();
|
||||
const config_dict& get_config_vars();
|
||||
bool set_var(std::string& var_name, std::string& value);
|
||||
|
||||
protected:
|
||||
uint16_t checksum_partition();
|
||||
void update_partition();
|
||||
|
||||
private:
|
||||
NVram* nvram_obj = nullptr;
|
||||
uint8_t buf[OF_CFG_SIZE];
|
||||
int size = 0;
|
||||
config_dict _config_vars;
|
||||
};
|
||||
|
||||
// New World implementation
|
||||
class OfConfigChrp : public OfConfigImpl {
|
||||
public:
|
||||
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
|
||||
~OfConfigChrp() = default;
|
||||
|
||||
bool validate();
|
||||
const config_dict& get_config_vars();
|
||||
bool set_var(std::string& var_name, std::string& value);
|
||||
|
||||
protected:
|
||||
uint8_t checksum_hdr(const uint8_t* data);
|
||||
bool update_partition();
|
||||
|
||||
private:
|
||||
NVram* nvram_obj = nullptr;
|
||||
uint8_t buf[4096];
|
||||
unsigned data_offset = 0; // offset to the OF config data
|
||||
unsigned data_length = 0; // length of the OF config data
|
||||
config_dict _config_vars;
|
||||
};
|
||||
|
||||
class OfConfigUtils {
|
||||
public:
|
||||
OfConfigUtils() = default;
|
||||
~OfConfigUtils() = default;
|
||||
|
||||
int init();
|
||||
void printenv();
|
||||
void setenv(std::string var_name, std::string value);
|
||||
|
||||
protected:
|
||||
bool validate();
|
||||
uint16_t checksum_partition();
|
||||
void update_partition();
|
||||
bool open_container();
|
||||
|
||||
private:
|
||||
NVram* nvram_obj = nullptr;
|
||||
int size = 0;
|
||||
uint8_t buf[0x800];
|
||||
std::unique_ptr<OfConfigImpl> cfg_impl = nullptr;
|
||||
NVram* nvram_obj = nullptr;
|
||||
};
|
||||
|
||||
#endif // OF_NVRAM_H
|
||||
+185
-279
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Bandit ARBus-to-PCI Bridge emulation. */
|
||||
/** Bandit/Chaos ARBus-to-PCI Bridge emulation. */
|
||||
|
||||
#include <devices/common/pci/bandit.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
@@ -40,27 +40,15 @@ const int MultiplyDeBruijnBitPosition2[] =
|
||||
/** finds the position of the bit that is set */
|
||||
#define WHAT_BIT_SET(val) (MultiplyDeBruijnBitPosition2[(uint32_t)(val * 0x077CB531U) >> 27])
|
||||
|
||||
Bandit::Bandit(int bridge_num, std::string name) : PCIHost(), PCIDevice(name)
|
||||
BanditPciDevice::BanditPciDevice(int bridge_num, std::string name, int dev_id, int rev)
|
||||
: PCIDevice(name)
|
||||
{
|
||||
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
|
||||
this->base_addr = 0xF0000000 + ((bridge_num & 3) << 25);
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Bandit control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x000000 --> I/O space
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
// base_addr + 0x1000000 --> pass-through memory space (not included below)
|
||||
mem_ctrl->add_mmio_region(base_addr, 0x01000000, this);
|
||||
supports_types(HWCompType::PCI_DEV);
|
||||
|
||||
// prepare the PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0001;
|
||||
this->class_rev = 0x06000003;
|
||||
this->device_id = dev_id;
|
||||
this->class_rev = 0x06000000 | (rev & 0xFFU);
|
||||
this->cache_ln_sz = 8;
|
||||
this->command = 0x16;
|
||||
|
||||
@@ -73,182 +61,63 @@ Bandit::Bandit(int bridge_num, std::string name) : PCIHost(), PCIDevice(name)
|
||||
// This initialization is implied by the device functionality.
|
||||
this->addr_mask = 3 << ((bridge_num & 3) * 2);
|
||||
|
||||
this->name = name;
|
||||
// initial PCI number + chip mode: big endian, interrupts & VGA space disabled
|
||||
this->mode_ctrl = ((bridge_num & 3) << 2) | 3;
|
||||
|
||||
this->rd_hold_off_cnt = 8;
|
||||
}
|
||||
|
||||
uint32_t Bandit::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
uint32_t BanditPciDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, size);
|
||||
return PCIDevice::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case BANDIT_ADDR_MASK:
|
||||
return BYTESWAP_32(this->addr_mask);
|
||||
return this->addr_mask;
|
||||
case BANDIT_MODE_SELECT:
|
||||
return this->mode_ctrl;
|
||||
case BANDIT_ARBUS_RD_HOLD_OFF:
|
||||
return this->rd_hold_off_cnt;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: reading from unimplemented config register at 0x%X",
|
||||
this->pci_name.c_str(), reg_offs);
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Bandit::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
void BanditPciDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, size);
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, details);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case BANDIT_ADDR_MASK:
|
||||
this->addr_mask = BYTESWAP_32(value);
|
||||
this->addr_mask = value;
|
||||
this->verbose_address_space();
|
||||
break;
|
||||
return;
|
||||
case BANDIT_MODE_SELECT:
|
||||
this->mode_ctrl = value;
|
||||
return;
|
||||
case BANDIT_ARBUS_RD_HOLD_OFF:
|
||||
this->rd_hold_off_cnt = value & 0x1F;
|
||||
return;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: writing to unimplemented config register at 0x%X",
|
||||
this->pci_name.c_str(), reg_offs);
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Bandit::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t result, idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
bus_num = (this->config_addr >> 16) & 255;
|
||||
dev_num = (this->config_addr >> 11) & 31;
|
||||
LOG_F(
|
||||
WARNING, "%s: read config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(
|
||||
ERROR, "%s: read invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c",
|
||||
this->name.c_str(), idsel, this->config_addr,
|
||||
fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
if (idsel == BANDIT_ID_SEL) { // access to myself
|
||||
result = this->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
if (this->dev_map.count(idsel)) {
|
||||
result = this->dev_map[idsel]->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
dev_num = WHAT_BIT_SET(idsel) + 11;
|
||||
LOG_F(
|
||||
ERROR, "%s err: read attempt from non-existing PCI device ??:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = this->config_addr;
|
||||
}
|
||||
} else { // I/O space access
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_read(offset, size, &result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "%s: attempt to read from unmapped PCI I/O space, offset=0x%X",
|
||||
this->name.c_str(), offset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
bus_num = (this->config_addr >> 16) & 255;
|
||||
dev_num = (this->config_addr >> 11) & 31;
|
||||
LOG_F(
|
||||
WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(
|
||||
ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x",
|
||||
this->name.c_str(), idsel, this->config_addr,
|
||||
fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (idsel == BANDIT_ID_SEL) { // access to myself
|
||||
this->pci_cfg_write(reg_offs, value, size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->dev_map.count(idsel)) {
|
||||
this->dev_map[idsel]->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
dev_num = WHAT_BIT_SET(idsel) + 11;
|
||||
LOG_F(
|
||||
ERROR, "%s err: write attempt to non-existing PCI device ??:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
}
|
||||
} else { // I/O space access
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_write(offset, value, size)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "%s: attempt to write to unmapped PCI I/O space, offset=0x%X",
|
||||
this->name.c_str(), offset);
|
||||
}
|
||||
}
|
||||
|
||||
void Bandit::verbose_address_space()
|
||||
void BanditPciDevice::verbose_address_space()
|
||||
{
|
||||
uint32_t mask;
|
||||
int bit_pos;
|
||||
|
||||
if (!this->addr_mask) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s address spaces:", this->pci_name.c_str());
|
||||
|
||||
// verbose coarse aka 256MB memory regions
|
||||
@@ -268,8 +137,142 @@ void Bandit::verbose_address_space()
|
||||
}
|
||||
}
|
||||
|
||||
Chaos::Chaos(std::string name) : PCIHost()
|
||||
uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
switch (offset >> 22) {
|
||||
case 3: // CONFIG_DATA
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIDevice *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_READ;
|
||||
if (device) {
|
||||
return pci_conv_rd_data(device->pci_cfg_read(reg_offs, details), details);
|
||||
}
|
||||
LOG_READ_NON_EXISTENT_PCI_DEVICE();
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
return BYTESWAP_32(this->config_addr);
|
||||
|
||||
default: // I/O space
|
||||
return pci_io_read_broadcast(offset, size);
|
||||
}
|
||||
}
|
||||
|
||||
void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset >> 22) {
|
||||
case 3: // CONFIG_DATA
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIDevice *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_WRITE;
|
||||
if (device) {
|
||||
if (size == 4 && !details.offset) { // aligned DWORD writes -> fast path
|
||||
device->pci_cfg_write(reg_offs, BYTESWAP_32(value), details);
|
||||
return;
|
||||
}
|
||||
// otherwise perform necessary data transformations -> slow path
|
||||
uint32_t old_val = details.size == 4 ? 0 : device->pci_cfg_read(reg_offs, details);
|
||||
uint32_t new_val = pci_conv_wr_data(old_val, value, details);
|
||||
device->pci_cfg_write(reg_offs, new_val, details);
|
||||
return;
|
||||
}
|
||||
LOG_WRITE_NON_EXISTENT_PCI_DEVICE();
|
||||
break;
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
break;
|
||||
|
||||
default: // I/O space
|
||||
pci_io_write_broadcast(offset, size, value);
|
||||
}
|
||||
}
|
||||
|
||||
inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
|
||||
int &dev_num, int &fun_num, uint8_t ®_offs,
|
||||
AccessDetails &details, PCIDevice *&device)
|
||||
{
|
||||
device = NULL;
|
||||
details.size = size;
|
||||
details.offset = offset & 3;
|
||||
fun_num = FUN_NUM();
|
||||
reg_offs = REG_NUM();
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) { // type 1 configuration command
|
||||
details.flags = PCI_CONFIG_TYPE_1;
|
||||
bus_num = BUS_NUM();
|
||||
dev_num = DEV_NUM();
|
||||
device = pci_find_device(bus_num, dev_num, fun_num);
|
||||
return;
|
||||
}
|
||||
details.flags = PCI_CONFIG_TYPE_0;
|
||||
bus_num = 0; // use dummy value for bus number
|
||||
uint32_t idsel = this->config_addr & 0xFFFFF800U;
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
|
||||
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
|
||||
this->name.c_str(), (uint32_t)this->config_addr);
|
||||
return;
|
||||
}
|
||||
dev_num = WHAT_BIT_SET(idsel);
|
||||
if (this->dev_map.count(DEV_FUN(dev_num, fun_num))) {
|
||||
device = this->dev_map[DEV_FUN(dev_num, fun_num)];
|
||||
}
|
||||
}
|
||||
|
||||
int BanditHost::device_postinit()
|
||||
{
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots = {
|
||||
{"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}
|
||||
};
|
||||
|
||||
for (auto& slot : pci_slots) {
|
||||
pci_dev_name = GET_STR_PROP(slot.first);
|
||||
if (!pci_dev_name.empty()) {
|
||||
this->attach_pci_device(pci_dev_name, slot.second);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
|
||||
: BanditHost()
|
||||
{
|
||||
this->name = name;
|
||||
|
||||
supports_types(HWCompType::PCI_HOST);
|
||||
|
||||
this->base_addr = 0xF0000000 + ((bridge_num & 3) << 25);
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Bandit control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x000000 --> I/O space
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
// base_addr + 0x1000000 --> pass-through memory space (not included below)
|
||||
mem_ctrl->add_mmio_region(base_addr, 0x01000000, this);
|
||||
|
||||
// connnect Bandit PCI device
|
||||
this->my_pci_device = unique_ptr<BanditPciDevice>(
|
||||
new BanditPciDevice(bridge_num, name, dev_id, rev)
|
||||
);
|
||||
this->pci_register_device(DEV_FUN(BANDIT_DEV,0), this->my_pci_device.get());
|
||||
}
|
||||
|
||||
Chaos::Chaos(std::string name) : BanditHost()
|
||||
{
|
||||
this->name = name;
|
||||
|
||||
supports_types(HWCompType::PCI_HOST);
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
@@ -280,121 +283,23 @@ Chaos::Chaos(std::string name) : PCIHost()
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
mem_ctrl->add_mmio_region(0xF0000000UL, 0x01000000, this);
|
||||
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
uint32_t Chaos::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t result, idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
bus_num = (this->config_addr >> 16) & 255;
|
||||
dev_num = (this->config_addr >> 11) & 31;
|
||||
LOG_F(
|
||||
WARNING, "%s: read config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(
|
||||
ERROR, "%s: read invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c",
|
||||
this->name.c_str(), idsel, this->config_addr,
|
||||
fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
if (this->dev_map.count(idsel)) {
|
||||
result = this->dev_map[idsel]->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
dev_num = WHAT_BIT_SET(idsel) + 11;
|
||||
LOG_F(
|
||||
ERROR, "%s err: read attempt from non-existing VCI device ??:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
} else {
|
||||
result = this->config_addr;
|
||||
}
|
||||
} else { // I/O space access
|
||||
LOG_F(ERROR, "%s: I/O space not supported", this->name.c_str());
|
||||
return 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
bus_num = (this->config_addr >> 16) & 255;
|
||||
dev_num = (this->config_addr >> 11) & 31;
|
||||
LOG_F(
|
||||
WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(
|
||||
ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x",
|
||||
this->name.c_str(), idsel, this->config_addr,
|
||||
fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->dev_map.count(idsel)) {
|
||||
this->dev_map[idsel]->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
dev_num = WHAT_BIT_SET(idsel) + 11;
|
||||
LOG_F(
|
||||
ERROR, "%s err: write attempt to non-existing VCI device ??:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
}
|
||||
} else { // I/O space access
|
||||
LOG_F(ERROR, "%s: I/O space not supported", this->name.c_str());
|
||||
}
|
||||
}
|
||||
static const PropMap Bandit_Properties = {
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
{"pci_B1",
|
||||
new StrProperty("")},
|
||||
{"pci_C1",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit1_Descriptor = {
|
||||
Bandit::create_first, {}, {}
|
||||
Bandit::create_first, {}, Bandit_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription PsxPci1_Descriptor = {
|
||||
Bandit::create_psx_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Chaos_Descriptor = {
|
||||
@@ -402,4 +307,5 @@ static const DeviceDescription Chaos_Descriptor = {
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
+77
-35
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,10 +19,19 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Bandit ARBus-to-PCI bridge definitions.
|
||||
/** Bandit/Chaos ARBus-to-PCI bridge definitions.
|
||||
|
||||
The Bandit ASIC is a custom ARBus-to-PCI bridge used in the second
|
||||
generation of the Power Macintosh computer equipped with the PCI bus.
|
||||
Bandit is a custom ARBus-to-PCI bridge used in the second generation
|
||||
of the Power Macintosh computer equipped with the PCI bus.
|
||||
|
||||
Chaos is a custom ARBus-to-PCI bridge that provides a specialized
|
||||
PCI-like bus for video called VCI. This 64-bit bus runs at the same
|
||||
frequency as the CPU bus (40-50 MHz) and connects video input/output
|
||||
devices with the CPU bus.
|
||||
|
||||
Chaos seems to be a Bandit variant without PCI configuration space.
|
||||
It's assumed to be present in some PCI Power Macintosh models of the
|
||||
first generation.
|
||||
*/
|
||||
|
||||
#ifndef BANDIT_PCI_H
|
||||
@@ -36,51 +45,92 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#define BANDIT_ID_SEL (1 << 0) // Bandit's own IDSEL
|
||||
#define BANDIT_DEV (11) // Bandit's own device number
|
||||
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
|
||||
#define BANDIT_CONFIG_SPACE 0x00800000 // Bandit Config Space bit
|
||||
|
||||
/* Convenient macros for parsing CONFIG_ADDR fields. */
|
||||
#define BUS_NUM() ((this->config_addr >> 16) & 0xFFU)
|
||||
#define DEV_NUM() ((this->config_addr >> 11) & 0x1FU)
|
||||
#define FUN_NUM() ((this->config_addr >> 8) & 0x07U)
|
||||
#define REG_NUM() ((this->config_addr ) & 0xFCU)
|
||||
|
||||
/** Bandit specific configuration registers. */
|
||||
enum {
|
||||
BANDIT_ADDR_MASK = 0x48,
|
||||
BANDIT_ADDR_MASK = 0x48,
|
||||
BANDIT_MODE_SELECT = 0x50,
|
||||
BANDIT_ARBUS_RD_HOLD_OFF = 0x58,
|
||||
};
|
||||
|
||||
/** checks if one bit is set at time, return 0 if not */
|
||||
#define SINGLE_BIT_SET(val) ((val) && !((val) & ((val)-1)))
|
||||
|
||||
class Bandit : public PCIHost, public PCIDevice {
|
||||
/*
|
||||
Common functionality for Bandit/Chaos PCI host bridge.
|
||||
*/
|
||||
class BanditHost : public PCIHost, public MMIODevice {
|
||||
public:
|
||||
Bandit(int bridge_num, std::string name);
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
int device_postinit();
|
||||
|
||||
protected:
|
||||
uint32_t config_addr;
|
||||
|
||||
private:
|
||||
void cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
|
||||
int &fun_num, uint8_t ®_offs, AccessDetails &details,
|
||||
PCIDevice *&device);
|
||||
};
|
||||
|
||||
/*
|
||||
PCI device for Bandit (but not for Chaos).
|
||||
*/
|
||||
class BanditPciDevice : public PCIDevice {
|
||||
public:
|
||||
BanditPciDevice(int bridge_num, std::string name, int dev_id, int rev);
|
||||
~BanditPciDevice() = default;
|
||||
|
||||
// PCIDevice methods
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
protected:
|
||||
void verbose_address_space();
|
||||
|
||||
private:
|
||||
uint32_t addr_mask;
|
||||
uint32_t mode_ctrl; // controls various chip modes/features
|
||||
uint32_t rd_hold_off_cnt;
|
||||
};
|
||||
|
||||
/*
|
||||
Bandit HLE emulation class.
|
||||
*/
|
||||
class Bandit : public BanditHost {
|
||||
public:
|
||||
Bandit(int bridge_num, std::string name, int dev_id=1, int rev=3);
|
||||
~Bandit() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
|
||||
};
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
protected:
|
||||
void verbose_address_space();
|
||||
static std::unique_ptr<HWComponent> create_psx_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t base_addr;
|
||||
uint32_t config_addr;
|
||||
uint32_t addr_mask;
|
||||
uint32_t base_addr;
|
||||
unique_ptr<BanditPciDevice> my_pci_device;
|
||||
};
|
||||
|
||||
/** Chaos is a custom ARBus-to-PCI bridge that provides a specialized
|
||||
PCI-like bus for video called VCI. This 64-bit bus runs at the same
|
||||
frequency as the CPU bus (40-50 MHz) and provides an interface
|
||||
between video input/output devices and the CPU bus.
|
||||
/**
|
||||
Chaos HLE emulation class.
|
||||
*/
|
||||
class Chaos : public PCIHost, public MMIODevice {
|
||||
class Chaos : public BanditHost {
|
||||
public:
|
||||
Chaos(std::string name);
|
||||
~Chaos() = default;
|
||||
@@ -88,14 +138,6 @@ public:
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<Chaos>(new Chaos("VCI0"));
|
||||
};
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
uint32_t config_addr;
|
||||
};
|
||||
|
||||
#endif // BANDIT_PCI_H
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** DEC 21154 PCI-to-PCI bridge emulation. */
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/dec21154.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
DecPciBridge::DecPciBridge(std::string name) : PCIBridge(name)
|
||||
{
|
||||
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
|
||||
// initialize PCI config header
|
||||
this->vendor_id = PCI_VENDOR_DEC;
|
||||
this->device_id = 0x0026;
|
||||
this->class_rev = 0x06040002;
|
||||
this->cache_ln_sz = 0;
|
||||
this->command = 0;
|
||||
this->status = 0x2B0;
|
||||
}
|
||||
|
||||
uint32_t DecPciBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
return PCIBridge::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case CHIP_CTRL:
|
||||
return (this->arb_ctrl << 16) | (this-> diag_ctrl << 8) | this->chip_ctrl;
|
||||
case PSERR_EVENT_DIS:
|
||||
return (this->gpio_out_en << 16) | this->pserr_event_dis;
|
||||
case SEC_CLK_CTRL:
|
||||
return this->sec_clock_ctrl;
|
||||
default:
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DecPciBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
PCIBridge::pci_cfg_write(reg_offs, value, details);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case CHIP_CTRL:
|
||||
this->chip_ctrl = value & 0xFFU;
|
||||
this->diag_ctrl = (value >> 8) & 0xFFU;
|
||||
this->arb_ctrl = value >> 16;
|
||||
break;
|
||||
case PSERR_EVENT_DIS:
|
||||
this->pserr_event_dis = value & 0xFFU;
|
||||
this->gpio_out_en = (value >> 16) & 0xFFU;
|
||||
break;
|
||||
case SEC_CLK_CTRL:
|
||||
this->sec_clock_ctrl = value & 0xFFFFU;
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Dec21154_Descriptor = {
|
||||
DecPciBridge::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** DEC 21154 PCI-to-PCI bridge definitions. */
|
||||
|
||||
#ifndef DEC_P2P_H
|
||||
#define DEC_P2P_H
|
||||
|
||||
#include <devices/common/pci/pcibridge.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
enum {
|
||||
CHIP_CTRL = 0x40,
|
||||
PSERR_EVENT_DIS = 0x64,
|
||||
SEC_CLK_CTRL = 0x68,
|
||||
};
|
||||
|
||||
class DecPciBridge : public PCIBridge {
|
||||
public:
|
||||
DecPciBridge(std::string name);
|
||||
~DecPciBridge() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154"));
|
||||
}
|
||||
|
||||
// PCIDevice methods
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
private:
|
||||
uint8_t chip_ctrl = 0;
|
||||
uint8_t diag_ctrl = 0;
|
||||
uint16_t arb_ctrl = 0x0200;
|
||||
uint8_t pserr_event_dis = 0;
|
||||
uint8_t gpio_out_data = 0;
|
||||
uint8_t gpio_out_en = 0;
|
||||
uint8_t gpio_in_data = 0;
|
||||
uint16_t sec_clock_ctrl = 0;
|
||||
};
|
||||
|
||||
#endif // DEC_P2P_H
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/pci/pcibridge.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
PCIBridge::PCIBridge(std::string name) : PCIDevice(name)
|
||||
{
|
||||
this->num_bars = 2;
|
||||
this->hdr_type = 1;
|
||||
|
||||
this->pci_rd_primary_bus = [this]() { return this->primary_bus; };
|
||||
this->pci_rd_secondary_bus = [this]() { return this->secondary_bus; };
|
||||
this->pci_rd_subordinate_bus = [this]() { return this->subordinate_bus; };
|
||||
this->pci_rd_sec_latency_timer = [this]() { return this->sec_latency_timer; };
|
||||
this->pci_rd_sec_status = [this]() { return this->sec_status; };
|
||||
this->pci_rd_memory_base = [this]() { return this->memory_base; };
|
||||
this->pci_rd_memory_limit = [this]() { return this->memory_limit; };
|
||||
this->pci_rd_io_base = [this]() { return this->io_base; };
|
||||
this->pci_rd_io_limit = [this]() { return this->io_limit; };
|
||||
this->pci_rd_pref_mem_base = [this]() { return this->pref_mem_base; };
|
||||
this->pci_rd_pref_mem_limit = [this]() { return this->pref_mem_limit; };
|
||||
this->pci_rd_io_base_upper16 = [this]() { return this->io_base_upper16; };
|
||||
this->pci_rd_io_limit_upper16 = [this]() { return this->io_limit_upper16; };
|
||||
this->pci_rd_pref_base_upper32 = [this]() { return this->pref_base_upper32; };
|
||||
this->pci_rd_pref_limit_upper32 = [this]() { return this->pref_limit_upper32; };
|
||||
this->pci_rd_bridge_control = [this]() { return this->bridge_control; };
|
||||
|
||||
this->pci_wr_primary_bus = [this](uint8_t val) { this->primary_bus = val; };
|
||||
this->pci_wr_secondary_bus = [this](uint8_t val) { this->secondary_bus = val; };
|
||||
this->pci_wr_subordinate_bus = [this](uint8_t val) { this->subordinate_bus = val; };
|
||||
|
||||
this->pci_wr_sec_latency_timer = [this](uint8_t val) {
|
||||
this->sec_latency_timer = (this->sec_latency_timer & ~this->sec_latency_timer_cfg) |
|
||||
(val & this->sec_latency_timer_cfg);
|
||||
};
|
||||
|
||||
this->pci_wr_sec_status = [this](uint16_t val) {};
|
||||
|
||||
this->pci_wr_memory_base = [this](uint16_t val) {
|
||||
this->memory_base = (val & this->memory_cfg) | (this->memory_cfg & 15);
|
||||
this->memory_base_32 = ((this->memory_base & 0xfff0) << 16);
|
||||
};
|
||||
|
||||
this->pci_wr_memory_limit = [this](uint16_t val) {
|
||||
this->memory_limit = (val & this->memory_cfg) | (this->memory_cfg & 15);
|
||||
this->memory_limit_32 = ((this->memory_limit & 0xfff0) << 16) + 0x100000;
|
||||
};
|
||||
|
||||
this->pci_wr_io_base = [this](uint8_t val) {
|
||||
this->io_base = (val & this->io_cfg) | (this->io_cfg & 15);
|
||||
this->io_base_32 = ((uint32_t)this->io_base_upper16 << 16) | ((this->io_base & 0xf0) << 8);
|
||||
};
|
||||
|
||||
this->pci_wr_io_limit = [this](uint8_t val) {
|
||||
this->io_limit = (val & this->io_cfg) | (this->io_cfg & 15);
|
||||
this->io_limit_32 = (((uint32_t)this->io_limit_upper16 << 16) |
|
||||
((this->io_limit & 0xf0) << 8)) + 0x1000;
|
||||
};
|
||||
|
||||
this->pci_wr_pref_mem_base = [this](uint16_t val) {
|
||||
this->pref_mem_base = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
|
||||
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
|
||||
((this->pref_mem_base & 0xfff0) << 16);
|
||||
};
|
||||
this->pci_wr_pref_mem_limit = [this](uint16_t val) {
|
||||
this->pref_mem_limit = (val & this->pref_mem_cfg) | (this->pref_mem_cfg & 15);
|
||||
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
|
||||
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
|
||||
};
|
||||
this->pci_wr_io_base_upper16 = [this](uint16_t val) {
|
||||
if ((this->io_base & 15) == 1)
|
||||
this->io_base_upper16 = val;
|
||||
this->io_base_32 = ((uint32_t)this->io_base_upper16 << 16) |
|
||||
((this->io_base & 0xf0) << 8);
|
||||
};
|
||||
this->pci_wr_io_limit_upper16 = [this](uint16_t val) {
|
||||
if ((this->io_limit & 15) == 1)
|
||||
this->io_limit_upper16 = val;
|
||||
this->io_limit_32 = (((uint32_t)this->io_limit_upper16 << 16) |
|
||||
((this->io_limit & 0xf0) << 8)) + 0x1000;
|
||||
};
|
||||
|
||||
this->pci_wr_pref_base_upper32 = [this](uint32_t val) {
|
||||
if ((this->pref_mem_cfg & 15) == 1)
|
||||
this->pref_base_upper32 = val;
|
||||
this->pref_mem_base_64 = ((uint64_t)this->pref_base_upper32 << 32) |
|
||||
((this->pref_mem_base & 0xfff0) << 16);
|
||||
};
|
||||
|
||||
this->pci_wr_pref_limit_upper32 = [this](uint32_t val) {
|
||||
if ((this->pref_mem_cfg & 15) == 1)
|
||||
this->pref_limit_upper32 = val;
|
||||
this->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) |
|
||||
((this->pref_mem_limit & 0xfff0) << 16)) + 0x100000;
|
||||
};
|
||||
|
||||
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
|
||||
};
|
||||
|
||||
bool PCIBridge::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
// FIXME: constrain region to memory range
|
||||
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
return this->host_instance->pci_unregister_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 0x18) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_PRIMARY_BUS:
|
||||
return (this->pci_rd_sec_latency_timer() << 24) |
|
||||
(this->pci_rd_subordinate_bus() << 16) |
|
||||
(this->pci_rd_secondary_bus() << 8) |
|
||||
(this->pci_rd_primary_bus());
|
||||
case PCI_CFG_IO_BASE:
|
||||
return (this->pci_rd_sec_status() << 16) |
|
||||
(this->pci_rd_io_limit() << 8) | (this->pci_rd_io_base());
|
||||
case PCI_CFG_MEMORY_BASE:
|
||||
return (this->pci_rd_memory_limit() << 16) | (this->pci_rd_memory_base());
|
||||
case PCI_CFG_PREF_MEM_BASE:
|
||||
return (this->pci_rd_pref_mem_limit() << 16) | (this->pci_rd_pref_mem_base());
|
||||
case PCI_CFG_PREF_BASE_UPPER32:
|
||||
return this->pci_rd_pref_base_upper32();
|
||||
case PCI_CFG_PREF_LIMIT_UPPER32:
|
||||
return this->pci_rd_pref_limit_upper32();
|
||||
case PCI_CFG_IO_BASE_UPPER16:
|
||||
return (this->pci_rd_io_limit_upper16() << 16) | (this->pci_rd_io_base_upper16());
|
||||
case PCI_CFG_CAP_PTR:
|
||||
return cap_ptr;
|
||||
case PCI_CFG_BRIDGE_ROM_ADDRESS:
|
||||
return exp_rom_bar;
|
||||
case PCI_CFG_INTERRUPT_LINE:
|
||||
return (this->pci_rd_bridge_control() << 16) | (irq_pin << 8) | irq_line;
|
||||
}
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 0x18) {
|
||||
return PCIDevice::pci_cfg_write(reg_offs, value, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_PRIMARY_BUS:
|
||||
this->pci_wr_sec_latency_timer(value >> 24);
|
||||
this->pci_wr_subordinate_bus(value >> 16);
|
||||
this->pci_wr_secondary_bus(value >> 8);
|
||||
this->pci_wr_primary_bus(value & 0xFFU);
|
||||
break;
|
||||
case PCI_CFG_IO_BASE:
|
||||
this->pci_wr_sec_status(value >> 16);
|
||||
this->pci_wr_io_limit(value >> 8);
|
||||
this->pci_wr_io_base(value & 0xFFU);
|
||||
break;
|
||||
case PCI_CFG_MEMORY_BASE:
|
||||
this->pci_wr_memory_limit(value >> 16);
|
||||
this->pci_wr_memory_base(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_PREF_MEM_BASE:
|
||||
this->pci_wr_pref_mem_limit(value >> 16);
|
||||
this->pci_wr_pref_mem_base(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_PREF_BASE_UPPER32:
|
||||
this->pci_wr_pref_base_upper32(value);
|
||||
break;
|
||||
case PCI_CFG_PREF_LIMIT_UPPER32:
|
||||
this->pci_wr_pref_limit_upper32(value);
|
||||
break;
|
||||
case PCI_CFG_IO_BASE_UPPER16:
|
||||
this->pci_wr_io_limit_upper16(value >> 16);
|
||||
this->pci_wr_io_base_upper16(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_BRIDGE_ROM_ADDRESS:
|
||||
this->pci_wr_exp_rom_bar(value);
|
||||
break;
|
||||
case PCI_CFG_INTERRUPT_LINE:
|
||||
this->irq_line = value >> 24;
|
||||
this->pci_wr_bridge_control(value >> 16);
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
return this->pci_io_read_loop(offset, size, *res);
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
return this->pci_io_read_loop(offset, size, value);
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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_BRIDGE_H
|
||||
#define PCI_BRIDGE_H
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
PCI_CFG_PRIMARY_BUS = 0x18, // PRIMARY_BUS, SECONDARY_BUS, SUBORDINATE_BUS, SEC_LATENCY_TIMER
|
||||
PCI_CFG_IO_BASE = 0x1C, // IO_BASE.b, IO_LIMIT.b, SEC_STATUS.w
|
||||
PCI_CFG_MEMORY_BASE = 0x20, // MEMORY_BASE.w, MEMORY_LIMIT.w
|
||||
PCI_CFG_PREF_MEM_BASE = 0x24, // PREF_MEMORY_BASE.w, PREF_MEMORY_LIMIT.w
|
||||
PCI_CFG_PREF_BASE_UPPER32 = 0x28, // PREF_BASE_UPPER32
|
||||
PCI_CFG_PREF_LIMIT_UPPER32 = 0x2c, // PREF_LIMIT_UPPER32
|
||||
PCI_CFG_IO_BASE_UPPER16 = 0x30, // IO_BASE_UPPER16.w, IO_LIMIT_UPPER16.w
|
||||
// PCI_CFG_CAP_PTR
|
||||
PCI_CFG_BRIDGE_ROM_ADDRESS = 0x38, // BRIDGE_ROM_ADDRESS
|
||||
PCI_CFG_INTERRUPT_LINE = 0x3C, // INTERRUPT_LINE.b, INTERRUPT_PIN.b, BRIDGE_CONTROL.w
|
||||
};
|
||||
|
||||
class PCIBridge : public PCIHost, public PCIDevice {
|
||||
friend class PCIHost;
|
||||
public:
|
||||
PCIBridge(std::string name);
|
||||
~PCIBridge() = default;
|
||||
|
||||
// PCIHost methods
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
// PCIDevice methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
// MMIODevice methods
|
||||
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return 0;
|
||||
};
|
||||
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) { };
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_primary_bus;
|
||||
std::function<uint8_t()> pci_rd_secondary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_secondary_bus;
|
||||
std::function<uint8_t()> pci_rd_subordinate_bus;
|
||||
std::function<void(uint8_t)> pci_wr_subordinate_bus;
|
||||
std::function<uint8_t()> pci_rd_sec_latency_timer;
|
||||
std::function<void(uint8_t)> pci_wr_sec_latency_timer;
|
||||
std::function<uint16_t()> pci_rd_sec_status;
|
||||
std::function<void(uint16_t)> pci_wr_sec_status;
|
||||
std::function<uint8_t()> pci_rd_io_base;
|
||||
std::function<void(uint8_t)> pci_wr_io_base;
|
||||
std::function<uint8_t()> pci_rd_io_limit;
|
||||
std::function<void(uint8_t)> pci_wr_io_limit;
|
||||
std::function<uint16_t()> pci_rd_memory_base;
|
||||
std::function<void(uint16_t)> pci_wr_memory_base;
|
||||
std::function<uint16_t()> pci_rd_memory_limit;
|
||||
std::function<void(uint16_t)> pci_wr_memory_limit;
|
||||
std::function<uint16_t()> pci_rd_pref_mem_base;
|
||||
std::function<void(uint16_t)> pci_wr_pref_mem_base;
|
||||
std::function<uint16_t()> pci_rd_pref_mem_limit;
|
||||
std::function<void(uint16_t)> pci_wr_pref_mem_limit;
|
||||
std::function<uint32_t()> pci_rd_pref_base_upper32;
|
||||
std::function<void(uint32_t)> pci_wr_pref_base_upper32;
|
||||
std::function<uint32_t()> pci_rd_pref_limit_upper32;
|
||||
std::function<void(uint32_t)> pci_wr_pref_limit_upper32;
|
||||
std::function<uint16_t()> pci_rd_io_base_upper16;
|
||||
std::function<void(uint16_t)> pci_wr_io_base_upper16;
|
||||
std::function<uint16_t()> pci_rd_io_limit_upper16;
|
||||
std::function<void(uint16_t)> pci_wr_io_limit_upper16;
|
||||
std::function<uint16_t()> pci_rd_bridge_control;
|
||||
std::function<void(uint16_t)> pci_wr_bridge_control;
|
||||
|
||||
protected:
|
||||
// PCI configuration space state
|
||||
uint8_t primary_bus = 0;
|
||||
uint8_t secondary_bus = 0;
|
||||
uint8_t subordinate_bus = 0;
|
||||
uint8_t sec_latency_timer = 0; // if supportss r/w then must reset to 0
|
||||
uint16_t sec_status = 0;
|
||||
uint8_t io_base = 0;
|
||||
uint8_t io_limit = 0;
|
||||
uint16_t memory_base = 0;
|
||||
uint16_t memory_limit = 0;
|
||||
uint16_t pref_mem_base = 0;
|
||||
uint16_t pref_mem_limit = 0;
|
||||
uint32_t pref_base_upper32 = 0;
|
||||
uint32_t pref_limit_upper32 = 0;
|
||||
uint16_t io_base_upper16 = 0;
|
||||
uint16_t io_limit_upper16 = 0;
|
||||
uint16_t bridge_control = 0;
|
||||
|
||||
// 0 = not writable, 0xf8 = limits the granularity to eight PCI clocks
|
||||
uint8_t sec_latency_timer_cfg = 0;
|
||||
|
||||
// 0 = not writable, 0xf0 = supports 16 bit io range, 0xf1 = supports 32 bit I/O range
|
||||
uint8_t io_cfg = 0xf0;
|
||||
|
||||
// 0 = not writable, 0xfff0 = supports 32 bit memory range
|
||||
uint16_t memory_cfg = 0xfff0;
|
||||
|
||||
// 0 = not writable, 0xfff0 = supports 32 bit prefetchable memory range,
|
||||
// 0xfff1 = supports 64 bit prefetchable memory range
|
||||
uint16_t pref_mem_cfg = 0xfff0;
|
||||
|
||||
uint32_t io_base_32 = 0;
|
||||
uint32_t io_limit_32 = 0;
|
||||
uint64_t memory_base_32 = 0;
|
||||
uint64_t memory_limit_32 = 0;
|
||||
uint64_t pref_mem_base_64 = 0;
|
||||
uint64_t pref_mem_limit_64 = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* PCI_BRIDGE_H */
|
||||
+162
-110
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -20,17 +20,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
PCIDevice::PCIDevice(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
this->pci_name = name;
|
||||
|
||||
this->pci_rd_stat = [this]() { return this->status; };
|
||||
@@ -48,23 +49,49 @@ PCIDevice::PCIDevice(std::string name)
|
||||
this->pci_notify_bar_change = [](int bar_num) {};
|
||||
};
|
||||
|
||||
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_DEV_ID:
|
||||
result = (this->device_id << 16) | (this->vendor_id);
|
||||
break;
|
||||
return (this->device_id << 16) | (this->vendor_id);
|
||||
case PCI_CFG_STAT_CMD:
|
||||
result = (this->pci_rd_stat() << 16) | (this->pci_rd_cmd());
|
||||
break;
|
||||
return (this->pci_rd_stat() << 16) | (this->pci_rd_cmd());
|
||||
case PCI_CFG_CLASS_REV:
|
||||
result = this->class_rev;
|
||||
return this->class_rev;
|
||||
case PCI_CFG_DWORD_3:
|
||||
return (pci_rd_bist() << 24) | (this->hdr_type << 16) |
|
||||
(pci_rd_lat_timer() << 8) | pci_rd_cache_lnsz();
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
case PCI_CFG_BAR3:
|
||||
case PCI_CFG_BAR4:
|
||||
case PCI_CFG_BAR5:
|
||||
return this->bars[(reg_offs - 0x10) >> 2];
|
||||
case PCI_CFG_SUBSYS_ID:
|
||||
return (this->subsys_id << 16) | (this->subsys_vndr);
|
||||
case PCI_CFG_ROM_BAR:
|
||||
return this->exp_rom_bar;
|
||||
case PCI_CFG_DWORD_15:
|
||||
return (max_lat << 24) | (min_gnt << 16) | (irq_pin << 8) | irq_line;
|
||||
case PCI_CFG_CAP_PTR:
|
||||
return cap_ptr;
|
||||
}
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_STAT_CMD:
|
||||
this->pci_wr_stat(value >> 16);
|
||||
this->pci_wr_cmd(value & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
result = (pci_rd_bist() << 24) | (this->hdr_type << 16) |
|
||||
(pci_rd_lat_timer() << 8) | pci_rd_cache_lnsz();
|
||||
this->pci_wr_bist(value >> 24);
|
||||
this->pci_wr_lat_timer((value >> 8) & 0xFF);
|
||||
this->pci_wr_cache_lnsz(value & 0xFF);
|
||||
break;
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
@@ -72,93 +99,29 @@ uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
case PCI_CFG_BAR3:
|
||||
case PCI_CFG_BAR4:
|
||||
case PCI_CFG_BAR5:
|
||||
result = this->bars[(reg_offs - 0x10) >> 2];
|
||||
break;
|
||||
case PCI_CFG_SUBSYS_ID:
|
||||
result = (this->subsys_id << 16) | (this->subsys_vndr);
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, value);
|
||||
break;
|
||||
case PCI_CFG_ROM_BAR:
|
||||
result = this->exp_rom_bar;
|
||||
this->pci_wr_exp_rom_bar(value);
|
||||
break;
|
||||
case PCI_CFG_DWORD_15:
|
||||
result = (max_lat << 24) | (min_gnt << 16) | (irq_pin << 8) | irq_line;
|
||||
break;
|
||||
case PCI_CFG_CAP_PTR:
|
||||
result = cap_ptr;
|
||||
this->irq_line = value >> 24;
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
WARNING, "%s: attempt to read from reserved/unimplemented register @%02x.%c",
|
||||
this->pci_name.c_str(), reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size == 4) {
|
||||
return BYTESWAP_32(result);
|
||||
} else {
|
||||
return read_mem_rev(((uint8_t *)&result) + (reg_offs & 3), size);
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
void PCIDevice::setup_bars(std::vector<BarConfig> cfg_data)
|
||||
{
|
||||
uint32_t data;
|
||||
|
||||
if (size == 4) {
|
||||
data = BYTESWAP_32(value);
|
||||
} else {
|
||||
// get current register content as DWORD and update it partially
|
||||
data = BYTESWAP_32(this->pci_cfg_read(reg_offs, 4));
|
||||
write_mem_rev(((uint8_t *)&data) + (reg_offs & 3), value, size);
|
||||
for (auto cfg_entry : cfg_data) {
|
||||
if (cfg_entry.bar_num > 5) {
|
||||
ABORT_F("BAR number %d out of range", cfg_entry.bar_num);
|
||||
}
|
||||
this->bars_cfg[cfg_entry.bar_num] = cfg_entry.bar_cfg;
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_STAT_CMD:
|
||||
this->pci_wr_stat(data >> 16);
|
||||
this->pci_wr_cmd(data & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
this->pci_wr_bist(data >> 24);
|
||||
this->pci_wr_lat_timer((data >> 8) & 0xFF);
|
||||
this->pci_wr_cache_lnsz(data & 0xFF);
|
||||
break;
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
case PCI_CFG_BAR3:
|
||||
case PCI_CFG_BAR4:
|
||||
case PCI_CFG_BAR5:
|
||||
if (data == 0xFFFFFFFFUL) {
|
||||
this->do_bar_sizing((reg_offs - 0x10) >> 2);
|
||||
} else {
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, data);
|
||||
}
|
||||
break;
|
||||
case PCI_CFG_ROM_BAR:
|
||||
if (data == 0xFFFFF800UL) {
|
||||
this->exp_rom_bar = this->exp_bar_cfg;
|
||||
} else {
|
||||
this->exp_rom_bar = (data & 0xFFFFF801UL);
|
||||
if (this->exp_rom_bar & 1) {
|
||||
this->map_exp_rom_mem();
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unmapping of expansion ROM not implemented yet",
|
||||
this->pci_name.c_str());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PCI_CFG_DWORD_15:
|
||||
this->irq_line = data >> 24;
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
WARNING, "%s: attempt to write to reserved/unimplemented register @%02x.%c = %0*x",
|
||||
this->pci_name.c_str(), reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
}
|
||||
this->finish_config_bars();
|
||||
}
|
||||
|
||||
int PCIDevice::attach_exp_rom_image(const std::string img_path)
|
||||
@@ -187,10 +150,13 @@ int PCIDevice::attach_exp_rom_image(const std::string img_path)
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, std::ios::end);
|
||||
uint32_t exp_rom_image_size = img_file.tellg();
|
||||
size_t exp_rom_image_size = img_file.tellg();
|
||||
if (exp_rom_image_size > 4*1024*1024) {
|
||||
throw std::runtime_error("expansion ROM file too large");
|
||||
}
|
||||
|
||||
// verify PCI struct offset
|
||||
uint32_t pci_struct_offset = 0;
|
||||
uint16_t pci_struct_offset = 0;
|
||||
img_file.seekg(0x18, std::ios::beg);
|
||||
img_file.read((char *)&pci_struct_offset, sizeof(pci_struct_offset));
|
||||
|
||||
@@ -216,10 +182,12 @@ int PCIDevice::attach_exp_rom_image(const std::string img_path)
|
||||
memset(&this->exp_rom_data[exp_rom_image_size], 0xff, this->exp_rom_size - exp_rom_image_size);
|
||||
|
||||
if (exp_rom_image_size == this->exp_rom_size) {
|
||||
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).", this->pci_name.c_str(), this->exp_rom_size);
|
||||
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).",
|
||||
this->pci_name.c_str(), this->exp_rom_size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).", this->pci_name.c_str(), exp_rom_image_size, this->exp_rom_size);
|
||||
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
|
||||
this->pci_name.c_str(), (int)exp_rom_image_size, this->exp_rom_size);
|
||||
}
|
||||
|
||||
this->exp_bar_cfg = ~(this->exp_rom_size - 1);
|
||||
@@ -234,34 +202,118 @@ int PCIDevice::attach_exp_rom_image(const std::string img_path)
|
||||
return result;
|
||||
}
|
||||
|
||||
void PCIDevice::do_bar_sizing(int bar_num)
|
||||
{
|
||||
this->bars[bar_num] = this->bars_cfg[bar_num];
|
||||
}
|
||||
|
||||
void PCIDevice::set_bar_value(int bar_num, uint32_t value)
|
||||
{
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
if (bar_cfg & 1) {
|
||||
this->bars[bar_num] = (value & 0xFFFFFFFCUL) | 1;
|
||||
} else {
|
||||
if (bar_cfg & 6) {
|
||||
ABORT_F("Invalid or unsupported PCI space type: %d", (bar_cfg >> 1) & 3);
|
||||
}
|
||||
this->bars[bar_num] = (value & 0xFFFFFFF0UL) | (bar_cfg & 0xF);
|
||||
switch (bars_typ[bar_num]) {
|
||||
case PCIBarType::Unused:
|
||||
return;
|
||||
|
||||
case PCIBarType::Io_16_Bit:
|
||||
case PCIBarType::Io_32_Bit:
|
||||
this->bars[bar_num] = (value & bar_cfg & ~3) | (bar_cfg & 3);
|
||||
break;
|
||||
|
||||
case PCIBarType::Mem_20_Bit:
|
||||
case PCIBarType::Mem_32_Bit:
|
||||
case PCIBarType::Mem_64_Bit_Lo:
|
||||
this->bars[bar_num] = (value & bar_cfg & ~0xF) | (bar_cfg & 0xF);
|
||||
break;
|
||||
|
||||
case PCIBarType::Mem_64_Bit_Hi:
|
||||
this->bars[bar_num] = value & bar_cfg;
|
||||
break;
|
||||
}
|
||||
this->pci_notify_bar_change(bar_num);
|
||||
|
||||
if (value != 0xFFFFFFFFUL) // don't notify the device during BAR sizing
|
||||
this->pci_notify_bar_change(bar_num);
|
||||
}
|
||||
|
||||
void PCIDevice::finish_config_bars()
|
||||
{
|
||||
for (int bar_num = 0; bar_num < this->num_bars; bar_num++) {
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
|
||||
if (!bar_cfg) // skip unimplemented BARs
|
||||
continue;
|
||||
|
||||
if (bar_cfg & 1) {
|
||||
bars_typ[bar_num] = (bar_cfg & 0xffff0000) ? PCIBarType::Io_32_Bit :
|
||||
PCIBarType::Io_16_Bit;
|
||||
has_io_space = true;
|
||||
}
|
||||
else {
|
||||
int pci_space_type = (bar_cfg >> 1) & 3;
|
||||
switch (pci_space_type) {
|
||||
case 0:
|
||||
bars_typ[bar_num] = PCIBarType::Mem_32_Bit;
|
||||
break;
|
||||
case 1:
|
||||
bars_typ[bar_num] = PCIBarType::Mem_20_Bit;
|
||||
break;
|
||||
case 2:
|
||||
if (bar_num >= num_bars - 1) {
|
||||
ABORT_F("%s: BAR %d cannot be 64-bit",
|
||||
this->pci_name.c_str(), bar_num);
|
||||
}
|
||||
else if (this->bars_cfg[bar_num+1] == 0) {
|
||||
ABORT_F("%s: 64-bit BAR %d has zero for upper 32 bits",
|
||||
this->pci_name.c_str(), bar_num);
|
||||
}
|
||||
else {
|
||||
bars_typ[bar_num++] = PCIBarType::Mem_64_Bit_Lo;
|
||||
bars_typ[bar_num ] = PCIBarType::Mem_64_Bit_Hi;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: invalid or unsupported PCI space type %d for BAR %d",
|
||||
this->pci_name.c_str(), pci_space_type, bar_num);
|
||||
} // switch pci_space_type
|
||||
}
|
||||
} // for bar_num
|
||||
}
|
||||
|
||||
void PCIDevice::map_exp_rom_mem()
|
||||
{
|
||||
uint32_t rom_addr, rom_size;
|
||||
|
||||
rom_addr = this->exp_rom_bar & 0xFFFFF800UL;
|
||||
rom_size = ~this->exp_bar_cfg + 1;
|
||||
|
||||
if (!this->exp_rom_addr || this->exp_rom_addr != rom_addr) {
|
||||
uint32_t rom_addr = this->exp_rom_bar & this->exp_bar_cfg;
|
||||
if (rom_addr) {
|
||||
if (this->exp_rom_addr != rom_addr) {
|
||||
this->unmap_exp_rom_mem();
|
||||
uint32_t rom_size = ~this->exp_bar_cfg + 1;
|
||||
this->host_instance->pci_register_mmio_region(rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = rom_addr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this->unmap_exp_rom_mem();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::unmap_exp_rom_mem()
|
||||
{
|
||||
if (this->exp_rom_addr) {
|
||||
uint32_t rom_size = ~this->exp_bar_cfg + 1;
|
||||
this->host_instance->pci_unregister_mmio_region(exp_rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::pci_wr_exp_rom_bar(uint32_t data)
|
||||
{
|
||||
if (!this->exp_bar_cfg) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((data & this->exp_bar_cfg) == this->exp_bar_cfg) {
|
||||
// doing sizing
|
||||
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
|
||||
} else {
|
||||
this->exp_rom_bar = (data & (this->exp_bar_cfg | 1));
|
||||
if (this->exp_rom_bar & 1) {
|
||||
this->map_exp_rom_mem();
|
||||
}
|
||||
else {
|
||||
this->unmap_exp_rom_mem();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
@@ -53,10 +54,27 @@ enum {
|
||||
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
|
||||
enum {
|
||||
PCI_VENDOR_ATI = 0x1002,
|
||||
PCI_VENDOR_DEC = 0x1011,
|
||||
PCI_VENDOR_MOTOROLA = 0x1057,
|
||||
PCI_VENDOR_APPLE = 0x106B,
|
||||
PCI_VENDOR_NVIDIA = 0x10DE,
|
||||
};
|
||||
|
||||
/** PCI BAR types */
|
||||
enum PCIBarType : uint32_t {
|
||||
Unused = 0,
|
||||
Io_16_Bit,
|
||||
Io_32_Bit,
|
||||
Mem_20_Bit, // legacy type for < 1MB memory
|
||||
Mem_32_Bit,
|
||||
Mem_64_Bit_Lo,
|
||||
Mem_64_Bit_Hi
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t bar_num;
|
||||
uint32_t bar_cfg;
|
||||
} BarConfig;
|
||||
|
||||
class PCIDevice : public MMIODevice {
|
||||
public:
|
||||
@@ -64,7 +82,7 @@ public:
|
||||
virtual ~PCIDevice() = default;
|
||||
|
||||
virtual bool supports_io_space() {
|
||||
return false;
|
||||
return has_io_space;
|
||||
};
|
||||
|
||||
/* I/O space access methods */
|
||||
@@ -77,8 +95,8 @@ public:
|
||||
};
|
||||
|
||||
// configuration space access methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint16_t()> pci_rd_stat;
|
||||
@@ -100,10 +118,24 @@ public:
|
||||
this->host_instance = host_instance;
|
||||
};
|
||||
|
||||
virtual void set_multi_function(bool is_multi_function) {
|
||||
this->hdr_type = is_multi_function ? (this->hdr_type | 0x80) : (this->hdr_type & 0x7f);
|
||||
}
|
||||
virtual void set_irq_pin(uint8_t irq_pin) {
|
||||
this->irq_pin = irq_pin;
|
||||
}
|
||||
|
||||
// MMIODevice methods
|
||||
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) { return 0; }
|
||||
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) { }
|
||||
|
||||
protected:
|
||||
void do_bar_sizing(int bar_num);
|
||||
void set_bar_value(int bar_num, uint32_t value);
|
||||
void setup_bars(std::vector<BarConfig> cfg_data);
|
||||
void finish_config_bars();
|
||||
void pci_wr_exp_rom_bar(uint32_t data);
|
||||
void map_exp_rom_mem();
|
||||
void unmap_exp_rom_mem();
|
||||
|
||||
std::string pci_name; // human-readable device name
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
@@ -111,12 +143,12 @@ protected:
|
||||
// PCI configuration space state
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint32_t class_rev; // class code and revision id
|
||||
uint32_t class_rev; // class code and revision id
|
||||
uint16_t status = 0;
|
||||
uint16_t command = 0;
|
||||
uint8_t hdr_type = 0; // header type
|
||||
uint8_t lat_timer = 0; // latency timer
|
||||
uint8_t cache_ln_sz = 0; // cache line size
|
||||
uint8_t hdr_type = 0; // header type, single function
|
||||
uint8_t lat_timer = 0; // latency timer
|
||||
uint8_t cache_ln_sz = 0; // cache line size
|
||||
uint16_t subsys_id = 0;
|
||||
uint16_t subsys_vndr = 0;
|
||||
uint8_t cap_ptr = 0;
|
||||
@@ -125,8 +157,11 @@ protected:
|
||||
uint8_t irq_pin = 0;
|
||||
uint8_t irq_line = 0;
|
||||
|
||||
bool has_io_space = false;
|
||||
int num_bars = 6;
|
||||
uint32_t bars[6] = { 0 }; // base address registers
|
||||
uint32_t bars_cfg[6] = { 0 }; // configuration values for base address registers
|
||||
PCIBarType bars_typ[6] = { PCIBarType::Unused }; // types for base address registers
|
||||
|
||||
uint32_t exp_bar_cfg = 0; // expansion ROM configuration
|
||||
uint32_t exp_rom_bar = 0; // expansion ROM base address register
|
||||
@@ -136,4 +171,78 @@ protected:
|
||||
std::unique_ptr<uint8_t[]> exp_rom_data;
|
||||
};
|
||||
|
||||
inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
||||
switch (details.size << 2 | details.offset) {
|
||||
case 0x04: return (uint8_t) value;
|
||||
case 0x05: return (uint8_t)(value >> 8);
|
||||
case 0x06: return (uint8_t)(value >> 16);
|
||||
case 0x07: return (uint8_t)(value >> 24);
|
||||
|
||||
case 0x08: return (uint16_t) value;
|
||||
case 0x09: return (uint16_t) (value >> 8);
|
||||
case 0x0a: return (uint16_t) (value >> 16);
|
||||
case 0x0b: return (uint16_t)((value >> 24) | (value << 8));
|
||||
|
||||
case 0x10: return value;
|
||||
case 0x11: return (value >> 8) | (value << 24);
|
||||
case 0x12: return (value >> 16) | (value << 16);
|
||||
case 0x13: return (value >> 24) | (value << 8);
|
||||
|
||||
default: return 0xffffffff;
|
||||
}
|
||||
}
|
||||
|
||||
#define SIZE_ARGS details.size == 4 ? 'l' : details.size == 2 ? 'w' : \
|
||||
details.size == 1 ? 'b' : '0' + details.size
|
||||
|
||||
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER() \
|
||||
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
||||
VLOG_F( \
|
||||
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
||||
"%s: read unimplemented config register @%02x.%c", \
|
||||
this->name.c_str(), reg_offs + details.offset, \
|
||||
SIZE_ARGS \
|
||||
); \
|
||||
} } while(0)
|
||||
|
||||
#define LOG_NAMED_CONFIG_REGISTER(reg_verb, reg_name) \
|
||||
VLOG_F( \
|
||||
(~-details.size & details.offset) ? loguru::Verbosity_ERROR : loguru::Verbosity_WARNING, \
|
||||
"%s: %s %s register @%02x.%c = %0*x", \
|
||||
this->name.c_str(), reg_verb, reg_name, reg_offs + details.offset, \
|
||||
SIZE_ARGS, \
|
||||
details.size * 2, pci_cfg_log(value, details) \
|
||||
)
|
||||
|
||||
#define LOG_READ_NAMED_CONFIG_REGISTER(reg_name) \
|
||||
do { if ((details.flags & PCI_CONFIG_DIRECTION) == PCI_CONFIG_READ) { \
|
||||
LOG_NAMED_CONFIG_REGISTER("read ", reg_name); \
|
||||
} } while(0)
|
||||
|
||||
#define LOG_WRITE_NAMED_CONFIG_REGISTER(reg_name) \
|
||||
LOG_NAMED_CONFIG_REGISTER("write", reg_name)
|
||||
|
||||
#define LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER_WITH_VALUE() \
|
||||
LOG_READ_NAMED_CONFIG_REGISTER("unimplemented config")
|
||||
|
||||
#define LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER() \
|
||||
LOG_WRITE_NAMED_CONFIG_REGISTER("unimplemented config")
|
||||
|
||||
#define LOG_READ_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARGS \
|
||||
)
|
||||
|
||||
#define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARGS, \
|
||||
details.size * 2, BYTESWAP_SIZED(value, details.size) \
|
||||
)
|
||||
|
||||
#endif /* PCI_DEVICE_H */
|
||||
+131
-13
@@ -20,28 +20,50 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcibridge.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
bool PCIHost::pci_register_device(int dev_num, PCIDevice* dev_instance)
|
||||
bool PCIHost::pci_register_device(int dev_fun_num, PCIDevice* dev_instance)
|
||||
{
|
||||
// return false if dev_num already registered
|
||||
if (this->dev_map.count(dev_num))
|
||||
// return false if dev_fun_num already registered
|
||||
if (this->dev_map.count(dev_fun_num))
|
||||
return false;
|
||||
|
||||
this->dev_map[dev_num] = dev_instance;
|
||||
int fun_num = dev_fun_num & 7;
|
||||
int dev_num = (dev_fun_num >> 3) & 0x1f;
|
||||
bool is_multi_function = fun_num != 0;
|
||||
|
||||
for (int other_fun_num = 0; other_fun_num < 8; other_fun_num++) {
|
||||
if (this->dev_map.count(DEV_FUN(dev_num, other_fun_num))) {
|
||||
is_multi_function = true;
|
||||
if (is_multi_function && other_fun_num == 0) {
|
||||
this->dev_map[DEV_FUN(dev_num, other_fun_num)]->set_multi_function(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->dev_map[dev_fun_num] = dev_instance;
|
||||
|
||||
dev_instance->set_host(this);
|
||||
if (is_multi_function && fun_num == 0) {
|
||||
dev_instance->set_multi_function(true);
|
||||
}
|
||||
|
||||
if (dev_instance->supports_io_space()) {
|
||||
this->io_space_devs.push_back(dev_instance);
|
||||
}
|
||||
|
||||
PCIBridge *bridge = dynamic_cast<PCIBridge*>(dev_instance);
|
||||
if (bridge) {
|
||||
this->bridge_devs.push_back(bridge);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,25 +75,121 @@ bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDe
|
||||
return mem_ctrl->add_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
void PCIHost::attach_pci_device(std::string& dev_name, int slot_id)
|
||||
bool PCIHost::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
// FIXME: add sanity checks!
|
||||
return mem_ctrl->remove_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
void PCIHost::attach_pci_device(const std::string& dev_name, int slot_id)
|
||||
{
|
||||
this->attach_pci_device(dev_name, slot_id, "");
|
||||
}
|
||||
|
||||
PCIDevice *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, const std::string& dev_suffix)
|
||||
{
|
||||
if (!DeviceRegistry::device_registered(dev_name)) {
|
||||
LOG_F(WARNING, "PCIHost: specified PCI device %s doesn't exist", dev_name.c_str());
|
||||
return;
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
WARNING, "%s: specified PCI device %s doesn't exist",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", dev_name.c_str()
|
||||
);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// attempt to create device object
|
||||
auto dev_obj = DeviceRegistry::get_descriptor(dev_name).m_create_func();
|
||||
|
||||
if (!dev_obj->supports_type(HWCompType::PCI_DEV)) {
|
||||
LOG_F(WARNING, "PCIHost: cannot attach non-PCI device %s", dev_name.c_str());
|
||||
return;
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
WARNING, "%s: cannot attach non-PCI device %s",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", dev_name.c_str()
|
||||
);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// add device to the machine object
|
||||
gMachineObj->add_device(dev_name, std::move(dev_obj));
|
||||
gMachineObj->add_device(dev_name + dev_suffix, std::move(dev_obj));
|
||||
|
||||
PCIDevice *dev = dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(dev_name + dev_suffix));
|
||||
|
||||
// register device with the PCI host
|
||||
this->pci_register_device(
|
||||
slot_id, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(dev_name)));
|
||||
this->pci_register_device(slot_id, dev);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_io_read_loop(uint32_t offset, int size, uint32_t &res)
|
||||
{
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_read(offset, size, &res)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_io_write_loop(uint32_t offset, int size, uint32_t value)
|
||||
{
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_write(offset, value, size)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res;
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_read_loop (offset, size, res)) {
|
||||
return res;
|
||||
}
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to read from unmapped PCI I/O space @%08x.%c",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
// FIXME: add machine check exception (DEFAULT CATCH!, code=FFF00200)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIHost::pci_io_write_broadcast(uint32_t offset, int size, uint32_t value)
|
||||
{
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_write_loop(offset, size, value)) {
|
||||
return;
|
||||
}
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to write to unmapped PCI I/O space @%08x.%c = %0*x",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size,
|
||||
size * 2, BYTESWAP_SIZED(value, size)
|
||||
);
|
||||
}
|
||||
|
||||
PCIDevice *PCIHost::pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num)
|
||||
{
|
||||
for (auto& bridge : this->bridge_devs) {
|
||||
if (bridge->secondary_bus <= bus_num) {
|
||||
if (bridge->secondary_bus == bus_num) {
|
||||
if (bridge->dev_map.count(DEV_FUN(dev_num, fun_num))) {
|
||||
return bridge->dev_map[DEV_FUN(dev_num, fun_num)];
|
||||
}
|
||||
}
|
||||
else if (bridge->subordinate_bus >= bus_num) {
|
||||
return bridge->pci_find_device(bus_num, dev_num, fun_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -22,14 +22,37 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PCI_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
enum {
|
||||
PCI_CONFIG_DIRECTION = 1,
|
||||
PCI_CONFIG_READ = 0,
|
||||
PCI_CONFIG_WRITE = 1,
|
||||
|
||||
PCI_CONFIG_TYPE = 4,
|
||||
PCI_CONFIG_TYPE_0 = 0,
|
||||
PCI_CONFIG_TYPE_1 = 4,
|
||||
};
|
||||
|
||||
/** PCI config space access details */
|
||||
typedef struct AccessDetails {
|
||||
uint8_t size;
|
||||
uint8_t offset;
|
||||
uint8_t flags;
|
||||
} AccessDetails;
|
||||
|
||||
#define DEV_FUN(dev_num,fun_num) (((dev_num) << 3) | (fun_num))
|
||||
|
||||
class PCIDevice;
|
||||
class PCIBridge;
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
@@ -39,15 +62,122 @@ public:
|
||||
};
|
||||
~PCIHost() = default;
|
||||
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance);
|
||||
virtual bool pci_register_device(int dev_fun_num, PCIDevice* dev_instance);
|
||||
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
virtual void attach_pci_device(std::string& dev_name, int slot_id);
|
||||
virtual void attach_pci_device(const std::string& dev_name, int slot_id);
|
||||
PCIDevice *attach_pci_device(const std::string& dev_name, int slot_id,
|
||||
const std::string& dev_suffix);
|
||||
|
||||
virtual bool pci_io_read_loop (uint32_t offset, int size, uint32_t &res);
|
||||
virtual bool pci_io_write_loop(uint32_t offset, int size, uint32_t value);
|
||||
|
||||
virtual uint32_t pci_io_read_broadcast (uint32_t offset, int size);
|
||||
virtual void pci_io_write_broadcast(uint32_t offset, int size, uint32_t value);
|
||||
|
||||
virtual PCIDevice *pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num);
|
||||
|
||||
virtual uint32_t pci_t1_read(uint8_t dev, uint32_t fun, uint32_t reg, AccessDetails &details) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
virtual void pci_t1_write(uint8_t dev, uint32_t fun, uint32_t reg, uint32_t value,
|
||||
AccessDetails &details) {};
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, PCIDevice*> dev_map;
|
||||
std::vector<PCIDevice*> io_space_devs;
|
||||
std::vector<PCIBridge*> bridge_devs;
|
||||
};
|
||||
|
||||
// Helpers for data conversion in the PCI Configuration space.
|
||||
|
||||
/**
|
||||
Perform size dependent endian swapping for value that is dword from PCI config.
|
||||
|
||||
Unaligned data is handled properly by wrapping around if needed.
|
||||
*/
|
||||
inline uint32_t pci_conv_rd_data(uint32_t value, AccessDetails &details) {
|
||||
switch (details.size << 2 | details.offset) {
|
||||
// Bytes
|
||||
case 0x04:
|
||||
return value & 0xFF; // 0
|
||||
case 0x05:
|
||||
return (value >> 8) & 0xFF; // 1
|
||||
case 0x06:
|
||||
return (value >> 16) & 0xFF; // 2
|
||||
case 0x07:
|
||||
return (value >> 24) & 0xFF; // 3
|
||||
|
||||
// Words
|
||||
case 0x08:
|
||||
return BYTESWAP_16(value); // 0 1
|
||||
case 0x09:
|
||||
return BYTESWAP_16((value >> 8) & 0xFFFFU); // 1 2
|
||||
case 0x0A:
|
||||
return BYTESWAP_16((value >> 16) & 0xFFFFU); // 2 3
|
||||
case 0x0B:
|
||||
return ((value >> 16) & 0xFF00) | (value & 0xFF); // 3 0
|
||||
|
||||
// Dwords
|
||||
case 0x10:
|
||||
return BYTESWAP_32(value); // 0 1 2 3
|
||||
case 0x11:
|
||||
return ROTL_32(BYTESWAP_32(value), 8); // 1 2 3 0
|
||||
case 0x12:
|
||||
return ROTL_32(BYTESWAP_32(value), 16); // 2 3 0 1
|
||||
case 0x13:
|
||||
return ROTR_32(BYTESWAP_32(value), 8); // 3 0 1 2
|
||||
default:
|
||||
return 0xFFFFFFFFUL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Perform size dependent endian swapping for v2, then merge v2 with v1 under
|
||||
control of a mask generated according with the size parameter.
|
||||
|
||||
Unaligned data is handled properly by wrapping around if needed.
|
||||
*/
|
||||
inline uint32_t pci_conv_wr_data(uint32_t v1, uint32_t v2, AccessDetails &details)
|
||||
{
|
||||
switch (details.size << 2 | details.offset) {
|
||||
// Bytes
|
||||
case 0x04:
|
||||
return (v1 & ~0xFF) | (v2 & 0xFF); // 3 2 1 d0
|
||||
case 0x05:
|
||||
return (v1 & ~0xFF00) | ((v2 & 0xFF) << 8); // 3 2 d0 0
|
||||
case 0x06:
|
||||
return (v1 & ~0xFF0000) | ((v2 & 0xFF) << 16); // 3 d0 1 0
|
||||
case 0x07:
|
||||
return (v1 & 0x00FFFFFF) | ((v2 & 0xFF) << 24); // d0 2 1 0
|
||||
|
||||
// Words
|
||||
case 0x08:
|
||||
return (v1 & ~0xFFFF) | BYTESWAP_16(v2); // 3 2 d1 d0
|
||||
case 0x09:
|
||||
return (v1 & ~0xFFFF00) | (BYTESWAP_16(v2) << 8); // 3 d1 d0 0
|
||||
case 0x0a:
|
||||
return (v1 & 0x0000FFFF) | (BYTESWAP_16(v2) << 16); // d1 d0 1 0
|
||||
case 0x0b:
|
||||
return (v1 & 0x00FFFF00) | ((v2 & 0xFF00) << 16) |
|
||||
(v2 & 0xFF); // d0 2 1 d1
|
||||
|
||||
// Dwords
|
||||
case 0x10:
|
||||
return BYTESWAP_32(v2); // d3 d2 d1 d0
|
||||
case 0x11:
|
||||
return ROTL_32(BYTESWAP_32(v2), 8); // d2 d1 d0 d3
|
||||
case 0x12:
|
||||
return ROTL_32(BYTESWAP_32(v2), 16); // d1 d0 d3 d2
|
||||
case 0x13:
|
||||
return ROTR_32(BYTESWAP_32(v2), 8); // d0 d3 d2 d1
|
||||
|
||||
default:
|
||||
return 0xFFFFFFFFUL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
@@ -229,8 +229,6 @@ protected:
|
||||
void change_bus_phase(int initiator_id);
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
|
||||
// SCSI devices registered with this bus
|
||||
std::array<ScsiDevice*, SCSI_MAX_DEVS> devices;
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ int ViaCuda::device_postinit()
|
||||
}
|
||||
|
||||
void ViaCuda::cuda_init() {
|
||||
this->old_tip = 0;
|
||||
this->old_byteack = 0;
|
||||
this->old_tip = 1;
|
||||
this->old_byteack = 1;
|
||||
this->treq = 1;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
@@ -260,10 +260,6 @@ void ViaCuda::update_irq()
|
||||
}
|
||||
}
|
||||
|
||||
inline bool ViaCuda::ready() {
|
||||
return ((this->via_regs[VIA_DIRB] & 0x38) == 0x30);
|
||||
}
|
||||
|
||||
void ViaCuda::assert_sr_int() {
|
||||
this->sr_timer_on = false;
|
||||
this->_via_ifr |= VIA_IF_SR;
|
||||
@@ -322,11 +318,6 @@ void ViaCuda::schedule_sr_int(uint64_t timeout_ns) {
|
||||
}
|
||||
|
||||
void ViaCuda::write(uint8_t new_state) {
|
||||
if (!ready()) {
|
||||
LOG_F(WARNING, "Cuda not ready!");
|
||||
return;
|
||||
}
|
||||
|
||||
int new_tip = !!(new_state & CUDA_TIP);
|
||||
int new_byteack = !!(new_state & CUDA_BYTEACK);
|
||||
|
||||
@@ -348,8 +339,12 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
process_packet();
|
||||
|
||||
/* start response transaction */
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; /* assert TREQ */
|
||||
this->treq = 0;
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this]() {
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
});
|
||||
}
|
||||
|
||||
this->in_count = 0;
|
||||
@@ -362,7 +357,6 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
}
|
||||
|
||||
// send dummy byte as idle acknowledge or attention
|
||||
//assert_sr_int();
|
||||
schedule_sr_int(USECS_TO_NSECS(61));
|
||||
} else {
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { /* data transfer: Host --> Cuda */
|
||||
@@ -370,13 +364,11 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
// tell the system we've read the byte after 71 usecs
|
||||
schedule_sr_int(USECS_TO_NSECS(71));
|
||||
//assert_sr_int();
|
||||
} else {
|
||||
LOG_F(WARNING, "Cuda input buffer too small. Truncating data!");
|
||||
}
|
||||
} else { /* data transfer: Cuda --> Host */
|
||||
(this->*out_handler)();
|
||||
//assert_sr_int();
|
||||
// tell the system we've written next byte after 88 usecs
|
||||
schedule_sr_int(USECS_TO_NSECS(88));
|
||||
}
|
||||
|
||||
@@ -237,7 +237,6 @@ private:
|
||||
|
||||
// CUDA methods
|
||||
void cuda_init();
|
||||
bool ready();
|
||||
void write(uint8_t new_state);
|
||||
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
|
||||
void error_response(uint32_t error);
|
||||
|
||||
+127
-49
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,7 +21,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Support for reading and writing of various floppy images. */
|
||||
|
||||
#include "floppyimg.h"
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
@@ -67,27 +68,14 @@ static FlopImgType identify_image(std::ifstream& img_file)
|
||||
return FlopImgType::UNKNOWN;
|
||||
}
|
||||
|
||||
static int64_t get_hfs_vol_size(const uint8_t *mdb_data)
|
||||
{
|
||||
uint16_t drNmAlBlks = READ_WORD_BE_A(&mdb_data[18]);
|
||||
uint32_t drAlBlkSiz = READ_DWORD_BE_A(&mdb_data[20]);
|
||||
|
||||
// calculate size of the volume bitmap
|
||||
uint32_t vol_bmp_size = (((drNmAlBlks + 8) >> 3) + 512) & 0xFFFFFE00UL;
|
||||
|
||||
return (drNmAlBlks * drAlBlkSiz + vol_bmp_size + 3*BLOCK_SIZE);
|
||||
}
|
||||
|
||||
//======================= RAW IMAGE CONVERTER ============================
|
||||
RawFloppyImg::RawFloppyImg(std::string& file_path) : FloppyImgConverter()
|
||||
{
|
||||
this->img_path = file_path;
|
||||
}
|
||||
|
||||
/** For raw images, we're going to ensure that the data fits into
|
||||
one of the supported floppy disk sizes as well as image size
|
||||
matches the size of the embedded HFS/MFS volume.
|
||||
Then we'll attempt to guess disk format based on image size.
|
||||
/**
|
||||
For raw images, we'll attempt to guess disk format based on image size.
|
||||
*/
|
||||
int RawFloppyImg::calc_phys_params()
|
||||
{
|
||||
@@ -102,50 +90,46 @@ int RawFloppyImg::calc_phys_params()
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, img_file.end);
|
||||
this->img_size = img_file.tellg();
|
||||
size_t img_size = img_file.tellg();
|
||||
if (img_size > 2*1024*1024) {
|
||||
LOG_F(ERROR, "RawFloppyImg: image size is too large to determine disk format from image size!");
|
||||
return -1;
|
||||
}
|
||||
this->img_size = (int)img_size;
|
||||
img_file.seekg(0, img_file.beg);
|
||||
|
||||
img_file.close();
|
||||
|
||||
// verify image size
|
||||
if (this->img_size < 5*BLOCK_SIZE) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: image too short!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this->img_size > MFM_HD_SIZE) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "RawFloppyImg: image too big!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// read Master Directory Block from logical block 2
|
||||
uint8_t buf[512] = { 0 };
|
||||
|
||||
img_file.seekg(2*BLOCK_SIZE, img_file.beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
img_file.close();
|
||||
|
||||
uint64_t vol_size = 0;
|
||||
|
||||
if (buf[0] == 0x42 && buf[1] == 0x44) {
|
||||
// check HFS volume size
|
||||
vol_size = get_hfs_vol_size(buf);
|
||||
} else if (buf[0] == 0xD2 && buf[1] == 0xD7) {
|
||||
// check MFS volume size
|
||||
} else {
|
||||
LOG_F(ERROR, "RawFloppyImg: unknown volume type!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vol_size > this->img_size) {
|
||||
LOG_F(INFO, "RawFloppyImg: volume size > image size!");
|
||||
LOG_F(INFO, "Volume size: %llu, Image size: %d", vol_size, this->img_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// raw images don't include anything than raw disk data
|
||||
// raw images don't include anything other than raw disk data
|
||||
this->data_size = this->img_size;
|
||||
|
||||
// see if user has specified disk format manually
|
||||
std::string fmt = GET_STR_PROP("fdd_fmt");
|
||||
if (!fmt.empty()) {
|
||||
if (fmt == "GCR_400K") {
|
||||
this->img_size = 409600;
|
||||
} else if (fmt == "GCR_800K") {
|
||||
this->img_size = 819200;
|
||||
} else if (fmt == "MFM_720K") {
|
||||
this->img_size = 737280;
|
||||
} else if (fmt == "MFM_1440K") {
|
||||
this->img_size = 1474560;
|
||||
} else {
|
||||
LOG_F(WARNING, "Invalid floppy disk format %s", fmt.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// guess disk format from image file size
|
||||
static struct {
|
||||
int capacity;
|
||||
@@ -215,9 +199,102 @@ int RawFloppyImg::export_data()
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ====================== DISK COPY 4.2 IMAGE CONVERTER ======================
|
||||
DiskCopy42Img::DiskCopy42Img(std::string& file_path) : FloppyImgConverter()
|
||||
{
|
||||
this->img_path = file_path;
|
||||
}
|
||||
|
||||
int DiskCopy42Img::calc_phys_params() {
|
||||
std::ifstream img_file;
|
||||
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "DiskCopy42Img: could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, img_file.end);
|
||||
size_t img_size = img_file.tellg();
|
||||
img_file.seekg(0, img_file.beg);
|
||||
|
||||
// get data size from image
|
||||
uint8_t buf[4];
|
||||
img_file.seekg(0x40, img_file.beg);
|
||||
img_file.read((char *)&buf, 4);
|
||||
this->data_size = READ_DWORD_BE_U(buf);
|
||||
|
||||
if (this->data_size > img_size) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "DiskCopy42Img: invalid data size %d", this->data_size);
|
||||
return -1;
|
||||
}
|
||||
this->img_size = (int)img_size;
|
||||
|
||||
uint8_t disk_format = 0xFFU;
|
||||
|
||||
img_file.seekg(0x50, img_file.beg);
|
||||
img_file.read((char *)&disk_format, 1);
|
||||
img_file.read((char *)&this->format_byte, 1);
|
||||
|
||||
img_file.close();
|
||||
|
||||
this->density = 0; // assume double density by default
|
||||
|
||||
this->num_tracks = 80;
|
||||
this->num_sides = ((this->format_byte >> 5) & 1) + 1;
|
||||
|
||||
switch (disk_format) {
|
||||
case 0:
|
||||
case 1:
|
||||
this->rec_method = 0; // GCR
|
||||
this->num_sectors = 800;
|
||||
break;
|
||||
case 2:
|
||||
this->rec_method = 1; // MFM
|
||||
this->num_sectors = 1440;
|
||||
this->format_byte = 2;
|
||||
break;
|
||||
case 3:
|
||||
this->rec_method = 1; // MFM
|
||||
this->density = 1; // report high density
|
||||
this->num_sectors = 2880;
|
||||
this->format_byte = 2;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "DiskCopy42Img: invalid disk format %X", disk_format);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DiskCopy42Img::get_raw_disk_data(char* buf) {
|
||||
std::ifstream img_file;
|
||||
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "DiskCopy42Img: could not open specified floppy image!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
img_file.seekg(0x54, img_file.beg);
|
||||
img_file.read(buf, this->data_size);
|
||||
img_file.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DiskCopy42Img::export_data(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
{
|
||||
FloppyImgConverter *fconv;
|
||||
FloppyImgConverter *fconv = nullptr;
|
||||
|
||||
std::ifstream img_file;
|
||||
|
||||
@@ -239,14 +316,15 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
break;
|
||||
case FlopImgType::DC42:
|
||||
LOG_F(INFO, "Disk Copy 4.2 image");
|
||||
fconv = new DiskCopy42Img(img_path);
|
||||
break;
|
||||
case FlopImgType::WOZ1:
|
||||
case FlopImgType::WOZ2:
|
||||
LOG_F(INFO, "WOZ v%s image", (itype == FlopImgType::WOZ2) ? "2" : "1");
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unknown/unsupported image format!");
|
||||
return nullptr;
|
||||
LOG_F(WARNING, "Unknown image format - assume RAW");
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
}
|
||||
|
||||
if (fconv->calc_phys_params()) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -82,6 +82,17 @@ public:
|
||||
int export_data(void);
|
||||
};
|
||||
|
||||
/** Converter for Disk Copy 4.2 images. */
|
||||
class DiskCopy42Img : public FloppyImgConverter {
|
||||
public:
|
||||
DiskCopy42Img(std::string& file_path);
|
||||
~DiskCopy42Img() = default;
|
||||
|
||||
int calc_phys_params(void);
|
||||
int get_raw_disk_data(char* buf);
|
||||
int export_data(void);
|
||||
};
|
||||
|
||||
extern FloppyImgConverter* open_floppy_image(std::string& img_path);
|
||||
|
||||
#endif // FLOPPY_IMG_H
|
||||
+141
-22
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Macintosh Superdrive emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <loguru.hpp>
|
||||
@@ -35,13 +36,22 @@ MacSuperDrive::MacSuperDrive()
|
||||
this->name = "Superdrive";
|
||||
this->supported_types = HWCompType::FLOPPY_DRV;
|
||||
|
||||
this->media_kind = MediaKind::high_density;
|
||||
this->has_disk = 0; // drive is empty
|
||||
this->eject_latch = 0; // eject latch is off
|
||||
this->drive_mode = RecMethod::MFM; // assume MFM mode by default
|
||||
this->motor_stat = 0; // spindle motor is off
|
||||
this->cur_track = 0; // current head position
|
||||
this->is_ready = 0; // drive not ready
|
||||
|
||||
this->reset_params();
|
||||
}
|
||||
|
||||
void MacSuperDrive::reset_params()
|
||||
{
|
||||
this->media_kind = MediaKind::high_density;
|
||||
this->has_disk = 0; // drive is empty
|
||||
this->motor_stat = 0; // spindle motor is off
|
||||
this->motor_on_time = 0;
|
||||
this->cur_track = 0; // current head position
|
||||
this->is_ready = 0; // drive not ready
|
||||
|
||||
// come up in the MFM mode by default
|
||||
this->switch_drive_mode(RecMethod::MFM);
|
||||
}
|
||||
|
||||
void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
@@ -67,13 +77,25 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
if (this->motor_stat != new_motor_stat) {
|
||||
this->motor_stat = new_motor_stat;
|
||||
if (new_motor_stat) {
|
||||
this->motor_on_time = TimerManager::get_instance()->current_time_ns();
|
||||
this->track_start_time = 0;
|
||||
this->sector_start_time = 0;
|
||||
this->init_track_search(-1);
|
||||
this->is_ready = 1;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor on");
|
||||
} else {
|
||||
this->motor_on_time = 0;
|
||||
this->is_ready = 0;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor off");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Eject_Disk:
|
||||
if (value) {
|
||||
LOG_F(INFO, "Superdrive: disk ejected");
|
||||
this->eject_latch = 1;
|
||||
this->reset_params();
|
||||
}
|
||||
case CommandAddr::Reset_Eject_Latch:
|
||||
if (value) {
|
||||
this->eject_latch = 0;
|
||||
@@ -102,8 +124,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
case StatusAddr::Eject_Latch:
|
||||
return this->eject_latch;
|
||||
case StatusAddr::Select_Head_0:
|
||||
this->cur_head = 0;
|
||||
return 1; // not sure what should be returned here
|
||||
return this->cur_head = 0;
|
||||
case StatusAddr::MFM_Support:
|
||||
return 1; // Superdrive does support MFM encoding scheme
|
||||
case StatusAddr::Double_Sided:
|
||||
@@ -117,8 +138,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
case StatusAddr::Track_Zero:
|
||||
return this->track_zero ^ 1; // reverse logic
|
||||
case StatusAddr::Select_Head_1:
|
||||
this->cur_head = 1;
|
||||
return 1; // not sure what should be returned here
|
||||
return this->cur_head = 1;
|
||||
case StatusAddr::Drive_Mode:
|
||||
return this->drive_mode;
|
||||
case StatusAddr::Drive_Ready:
|
||||
@@ -204,39 +224,138 @@ void MacSuperDrive::switch_drive_mode(int mode)
|
||||
this->track2lblk[trk] = trk * sectors_per_track * 2;
|
||||
}
|
||||
|
||||
// set up disk timing parameters
|
||||
this->index_delay = MFM_INDX_MARK_DELAY;
|
||||
this->addr_mark_delay = MFM_ADR_MARK_DELAY;
|
||||
|
||||
if (this->media_kind) {
|
||||
this->sector_delay = MFM_HD_SECTOR_DELAY;
|
||||
this->eot_delay = MFM_HD_EOT_DELAY;
|
||||
} else {
|
||||
this->sector_delay = MFM_DD_SECTOR_DELAY;
|
||||
this->eot_delay = MFM_DD_EOT_DELAY;
|
||||
}
|
||||
|
||||
this->drive_mode = RecMethod::MFM;
|
||||
}
|
||||
}
|
||||
|
||||
double MacSuperDrive::get_current_track_delay()
|
||||
{
|
||||
return (1.0f / (this->rpm_per_track[this->cur_track] / 60));
|
||||
}
|
||||
|
||||
double MacSuperDrive::get_sector_delay()
|
||||
{
|
||||
return this->get_current_track_delay() / this->sectors_per_track[this->cur_track];
|
||||
return 60.0f / this->rpm_per_track[this->cur_track];
|
||||
}
|
||||
|
||||
void MacSuperDrive::init_track_search(int pos)
|
||||
{
|
||||
if (pos == -1) {
|
||||
// pick random sector number
|
||||
this->cur_sector = this->sectors_per_track[this->cur_track] / 2;
|
||||
uint64_t seed = TimerManager::get_instance()->current_time_ns() >> 8;
|
||||
this->cur_sector = seed % this->sectors_per_track[this->cur_track];
|
||||
LOG_F(9, "Superdrive: current sector number set to %d", this->cur_sector);
|
||||
} else {
|
||||
this->cur_sector = pos;
|
||||
}
|
||||
}
|
||||
|
||||
SectorHdr MacSuperDrive::next_sector_header()
|
||||
uint64_t MacSuperDrive::sync_to_disk()
|
||||
{
|
||||
this->cur_sector++;
|
||||
if (this->cur_sector >= this->sectors_per_track[this->cur_track]) {
|
||||
this->cur_sector = 0;
|
||||
uint64_t cur_time_ns, track_time_ns;
|
||||
|
||||
uint64_t track_delay = this->get_current_track_delay() * NS_PER_SEC;
|
||||
|
||||
// look how much ns have been elapsed since the last motor enabling
|
||||
cur_time_ns = TimerManager::get_instance()->current_time_ns() - this->motor_on_time;
|
||||
|
||||
if (!this->track_start_time ||
|
||||
(cur_time_ns - this->track_start_time) >= track_delay) {
|
||||
// subtract full disk revolutions
|
||||
track_time_ns = cur_time_ns % track_delay;
|
||||
|
||||
this->track_start_time = cur_time_ns - track_time_ns;
|
||||
|
||||
// return delay until the first address mark if we're currently
|
||||
// looking at the end of track
|
||||
if (track_time_ns >= this->eot_delay) {
|
||||
this->next_sector = 0;
|
||||
// CHEAT: don't account for the remaining time of the current track
|
||||
return this->index_delay + this->addr_mark_delay;
|
||||
}
|
||||
|
||||
// return delay until the first address mark
|
||||
// if the first address mark was not reached yet
|
||||
if (track_time_ns < this->index_delay) {
|
||||
this->next_sector = 0;
|
||||
return this->index_delay + this->addr_mark_delay - track_time_ns;
|
||||
}
|
||||
} else {
|
||||
track_time_ns = cur_time_ns - this->track_start_time;
|
||||
}
|
||||
|
||||
// subtract index field delay
|
||||
track_time_ns -= this->index_delay;
|
||||
|
||||
// calculate current sector number from timestamp
|
||||
int cur_sect_num = this->cur_sector = (int)(track_time_ns / this->sector_delay);
|
||||
|
||||
this->sector_start_time = this->track_start_time + cur_sect_num * this->sector_delay +
|
||||
this->index_delay;
|
||||
|
||||
if (this->cur_sector + 1 >= this->sectors_per_track[this->cur_track]) {
|
||||
uint64_t diff = track_delay - (cur_time_ns - this->track_start_time);
|
||||
this->next_sector = 0;
|
||||
this->track_start_time = 0;
|
||||
this->sector_start_time = 0;
|
||||
return diff + this->index_delay + this->addr_mark_delay;
|
||||
} else {
|
||||
this->next_sector = this->cur_sector + 1;
|
||||
uint64_t diff = cur_time_ns - this->sector_start_time;
|
||||
this->sector_start_time += this->sector_delay;
|
||||
return this->sector_delay - diff + this->addr_mark_delay;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t MacSuperDrive::next_addr_mark_delay(uint8_t *next_sect_num)
|
||||
{
|
||||
uint64_t delay;
|
||||
|
||||
if (this->cur_sector + 1 >= this->sectors_per_track[this->cur_track]) {
|
||||
this->next_sector = 0;
|
||||
delay = this->index_delay + this->addr_mark_delay;
|
||||
} else {
|
||||
this->next_sector = this->cur_sector + 1;
|
||||
delay = this->addr_mark_delay;
|
||||
}
|
||||
|
||||
if (next_sect_num) {
|
||||
*next_sect_num = this->next_sector + ((this->rec_method == RecMethod::MFM) ? 1 : 0);
|
||||
}
|
||||
|
||||
return delay;
|
||||
}
|
||||
|
||||
uint64_t MacSuperDrive::next_sector_delay()
|
||||
{
|
||||
if (this->cur_sector + 1 >= this->sectors_per_track[this->cur_track]) {
|
||||
this->next_sector = 0;
|
||||
return this->sector_delay + this->index_delay + this->addr_mark_delay;
|
||||
}
|
||||
|
||||
this->next_sector = this->cur_sector + 1;
|
||||
|
||||
return this->sector_delay - this->addr_mark_delay;
|
||||
}
|
||||
|
||||
uint64_t MacSuperDrive::sector_data_delay()
|
||||
{
|
||||
return MFM_SECT_DATA_DELAY;
|
||||
}
|
||||
|
||||
SectorHdr MacSuperDrive::current_sector_header()
|
||||
{
|
||||
this->cur_sector = this->next_sector;
|
||||
|
||||
// MFM sector numbering is 1-based so we need to bump sector number
|
||||
int sector_num = this->cur_sector + ((this->rec_method == RecMethod::MFM) ? 1 : 0);
|
||||
uint8_t sector_num = this->cur_sector + ((this->rec_method == RecMethod::MFM) ? 1 : 0);
|
||||
|
||||
return SectorHdr {
|
||||
this->cur_track,
|
||||
|
||||
+58
-26
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MAC_SUPERDRIVE_H
|
||||
#define MAC_SUPERDRIVE_H
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
|
||||
@@ -31,6 +32,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// convert number of bytes to disk time = nbytes * bits_per_byte * 2 us
|
||||
#define MFM_BYTES_TO_DISK_TIME(bytes) USECS_TO_NSECS((bytes) * 8 * 2)
|
||||
|
||||
// timing constans for MFM disks
|
||||
constexpr uint32_t MFM_INDX_MARK_DELAY = MFM_BYTES_TO_DISK_TIME(146);
|
||||
constexpr uint32_t MFM_ADR_MARK_DELAY = MFM_BYTES_TO_DISK_TIME(22);
|
||||
constexpr uint32_t MFM_SECT_DATA_DELAY = MFM_BYTES_TO_DISK_TIME(514);
|
||||
constexpr uint32_t MFM_DD_SECTOR_DELAY = MFM_BYTES_TO_DISK_TIME(658);
|
||||
constexpr uint32_t MFM_HD_SECTOR_DELAY = MFM_BYTES_TO_DISK_TIME(675);
|
||||
|
||||
constexpr uint32_t MFM_DD_EOT_DELAY = MFM_BYTES_TO_DISK_TIME( 6250 - 182);
|
||||
constexpr uint32_t MFM_HD_EOT_DELAY = MFM_BYTES_TO_DISK_TIME(12500 - 204);
|
||||
|
||||
namespace MacSuperdrive {
|
||||
|
||||
/** Apple Drive status request addresses. */
|
||||
@@ -56,6 +70,7 @@ enum CommandAddr : uint8_t {
|
||||
Step_Direction = 0,
|
||||
Do_Step = 1,
|
||||
Motor_On_Off = 2,
|
||||
Eject_Disk = 3,
|
||||
Reset_Eject_Latch = 4,
|
||||
Switch_Drive_Mode = 5,
|
||||
};
|
||||
@@ -73,10 +88,10 @@ enum RecMethod : int {
|
||||
};
|
||||
|
||||
typedef struct SectorHdr {
|
||||
int track;
|
||||
int side;
|
||||
int sector;
|
||||
int format;
|
||||
int track;
|
||||
int side;
|
||||
int sector;
|
||||
int format;
|
||||
} SectorHdr;
|
||||
|
||||
class MacSuperDrive : public HWComponent {
|
||||
@@ -87,38 +102,55 @@ public:
|
||||
void command(uint8_t addr, uint8_t value);
|
||||
uint8_t status(uint8_t addr);
|
||||
int insert_disk(std::string& img_path, int write_flag);
|
||||
double get_current_track_delay();
|
||||
double get_sector_delay();
|
||||
void init_track_search(int pos);
|
||||
SectorHdr next_sector_header();
|
||||
uint64_t sync_to_disk();
|
||||
uint64_t next_addr_mark_delay(uint8_t *next_sect_num);
|
||||
uint64_t next_sector_delay();
|
||||
SectorHdr current_sector_header();
|
||||
char* get_sector_data_ptr(int sector_num);
|
||||
uint64_t sector_data_delay();
|
||||
|
||||
double get_current_track_delay();
|
||||
double get_address_mark_delay();
|
||||
|
||||
protected:
|
||||
void reset_params();
|
||||
void set_disk_phys_params();
|
||||
void switch_drive_mode(int mode);
|
||||
|
||||
private:
|
||||
uint8_t has_disk;
|
||||
uint8_t eject_latch;
|
||||
uint8_t motor_stat; // spindle motor status: 1 - on, 0 - off
|
||||
uint8_t drive_mode; // drive mode: 0 - GCR, 1 - MFM
|
||||
uint8_t is_ready;
|
||||
uint8_t track_zero; // 1 - if head is at track zero
|
||||
int step_dir; // step direction -1/+1
|
||||
int cur_track; // track number the head is currently at
|
||||
int cur_head; // current head number: 1 - upper, 0 - lower
|
||||
int cur_sector; // current sector number
|
||||
uint8_t has_disk;
|
||||
uint8_t eject_latch;
|
||||
uint8_t motor_stat; // spindle motor status: 1 - on, 0 - off
|
||||
uint8_t drive_mode; // drive mode: 0 - GCR, 1 - MFM
|
||||
uint8_t is_ready;
|
||||
uint8_t track_zero; // 1 - if head is at track zero
|
||||
int step_dir; // step direction -1/+1
|
||||
int cur_track; // track number the head is currently at
|
||||
int cur_head; // current head number: 1 - upper, 0 - lower
|
||||
int cur_sector; // current sector number
|
||||
int next_sector; // next sector number
|
||||
|
||||
uint64_t motor_on_time = 0; // time in ns the spindle motor was switched on
|
||||
uint64_t track_start_time = 0;
|
||||
uint64_t sector_start_time = 0;
|
||||
|
||||
// physical parameters of the currently inserted disk
|
||||
uint8_t media_kind;
|
||||
uint8_t wr_protect;
|
||||
uint8_t format_byte;
|
||||
int rec_method;
|
||||
int num_tracks;
|
||||
int num_sides;
|
||||
int sectors_per_track[80];
|
||||
int rpm_per_track[80];
|
||||
int track2lblk[80]; // convert track number to first logical block number
|
||||
uint8_t media_kind;
|
||||
uint8_t wr_protect;
|
||||
uint8_t format_byte;
|
||||
int rec_method;
|
||||
int num_tracks;
|
||||
int num_sides;
|
||||
int sectors_per_track[80];
|
||||
int rpm_per_track[80];
|
||||
int track2lblk[80]; // convert track number to first logical block number
|
||||
|
||||
// timing parameters for MFM disks
|
||||
uint32_t index_delay; // number of ns needed to read the index mark
|
||||
uint32_t addr_mark_delay; // number of ns needed to read an address index mark
|
||||
uint32_t sector_delay; // number of ns needed to read a sector
|
||||
uint32_t eot_delay; // number of ns until end of track gap
|
||||
|
||||
std::unique_ptr<FloppyImgConverter> img_conv;
|
||||
|
||||
|
||||
+134
-61
@@ -33,6 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace Swim3;
|
||||
|
||||
@@ -41,14 +42,17 @@ Swim3Ctrl::Swim3Ctrl()
|
||||
this->name = "SWIM3";
|
||||
this->supported_types = HWCompType::FLOPPY_CTRL;
|
||||
|
||||
this->setup_reg = 0;
|
||||
this->mode_reg = 0;
|
||||
this->int_reg = 0;
|
||||
this->int_flags = 0;
|
||||
this->int_mask = 0;
|
||||
this->error = 0;
|
||||
this->xfer_cnt = 0;
|
||||
this->first_sec = 0xFF;
|
||||
this->setup_reg = 0;
|
||||
this->mode_reg = 0;
|
||||
this->int_reg = 0;
|
||||
this->int_flags = 0;
|
||||
this->int_mask = 0;
|
||||
this->error = 0;
|
||||
this->step_count = 0;
|
||||
this->xfer_cnt = 0;
|
||||
this->first_sec = 0xFF;
|
||||
|
||||
this->cur_state = SWIM3_IDLE;
|
||||
|
||||
// Attach virtual Superdrive to the internal drive connector
|
||||
// TODO: make SWIM3/drive wiring user selectable
|
||||
@@ -74,9 +78,11 @@ int Swim3Ctrl::device_postinit()
|
||||
|
||||
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t status_addr, status_val, old_int_flags, old_error;
|
||||
uint8_t status_addr, rddata_val, old_int_flags, old_error;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Timer:
|
||||
return this->calc_timer_val();
|
||||
case Swim3Reg::Error:
|
||||
old_error = this->error;
|
||||
this->error = 0;
|
||||
@@ -88,18 +94,20 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
case Swim3Reg::Handshake_Mode1:
|
||||
if (this->mode_reg & 2) { // internal drive?
|
||||
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
|
||||
status_val = this->int_drive->status(status_addr) & 1;
|
||||
rddata_val = this->int_drive->status(status_addr) & 1;
|
||||
|
||||
// transfer status_val to both bit 2 (RDDATA) and bit 3 (SENSE)
|
||||
// transfer rddata_val to both bit 2 (RDDATA) and bit 3 (SENSE)
|
||||
// because those signals seem to be historically wired together
|
||||
return ((status_val << 2) | (status_val << 3));
|
||||
return (rddata_val << 2) | (rddata_val << 3);
|
||||
}
|
||||
return 4;
|
||||
return 0xC; // report both RdData & Sense high
|
||||
case Swim3Reg::Interrupt_Flags:
|
||||
old_int_flags = this->int_flags;
|
||||
this->int_flags = 0; // read from this register clears all flags
|
||||
update_irq();
|
||||
return old_int_flags;
|
||||
case Swim3Reg::Step:
|
||||
return this->step_count;
|
||||
case Swim3Reg::Current_Track:
|
||||
return this->cur_track;
|
||||
case Swim3Reg::Current_Sector:
|
||||
@@ -120,21 +128,27 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
|
||||
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
uint8_t old_mode_reg;
|
||||
uint8_t status_addr;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Timer:
|
||||
this->init_timer(value);
|
||||
break;
|
||||
case Swim3Reg::Param_Data:
|
||||
this->pram = value;
|
||||
break;
|
||||
case Swim3Reg::Phase:
|
||||
this->phase_lines = value & 0xF;
|
||||
if (value & 8) {
|
||||
if (this->mode_reg & 2) { // internal drive?
|
||||
if (this->phase_lines & 8) { // CA3 aka LSTRB high -> sending a command to the drive
|
||||
if (this->mode_reg & 2) { // if internal drive is selected
|
||||
this->int_drive->command(
|
||||
((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3),
|
||||
(value >> 2) & 1
|
||||
);
|
||||
}
|
||||
} else if (this->phase_lines == 4 && (this->mode_reg & 2)) {
|
||||
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
|
||||
this->rd_line = this->int_drive->status(status_addr) & 1;
|
||||
}
|
||||
break;
|
||||
case Swim3Reg::Setup:
|
||||
@@ -277,53 +291,66 @@ void Swim3Ctrl::start_disk_access()
|
||||
this->mode_reg |= SWIM3_GO;
|
||||
LOG_F(9, "SWIM3: disk access started!");
|
||||
|
||||
if (this->first_sec == 0xFF) {
|
||||
// $FF means no sector to match ->
|
||||
// generate ID_read interrups as long as the GO bit is set
|
||||
this->int_drive->init_track_search(-1); // start at random sector
|
||||
} else {
|
||||
this->cur_sector = this->first_sec;
|
||||
this->target_sect = this->first_sec;
|
||||
|
||||
this->access_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
this->int_drive->sync_to_disk(),
|
||||
[this]() {
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
this->disk_access();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void Swim3Ctrl::disk_access()
|
||||
{
|
||||
MacSuperdrive::SectorHdr hdr;
|
||||
uint64_t delay;
|
||||
|
||||
switch(this->cur_state) {
|
||||
case SWIM3_ADDR_MARK_SEARCH:
|
||||
hdr = this->int_drive->current_sector_header();
|
||||
// update the corresponding SWIM3 registers
|
||||
this->cur_track = ((hdr.side & 1) << 7) | (hdr.track & 0x7F);
|
||||
this->cur_sector = 0x80 /* CRC/checksum valid */ | (hdr.sector & 0x7F);
|
||||
this->format = hdr.format;
|
||||
// generate ID_read interrupt
|
||||
this->int_flags |= INT_ID_READ;
|
||||
update_irq();
|
||||
if ((this->cur_sector & 0x7F) == this->target_sect) {
|
||||
// sector matches -> transfer its data
|
||||
this->cur_state = SWIM3_DATA_XFER;
|
||||
delay = this->int_drive->sector_data_delay();
|
||||
} else {
|
||||
// move to next address mark
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
delay = this->int_drive->next_sector_delay();
|
||||
}
|
||||
break;
|
||||
case SWIM3_DATA_XFER:
|
||||
// transfer sector data over DMA
|
||||
this->dma_ch->push_data(this->int_drive->get_sector_data_ptr(this->cur_sector & 0x7F), 512);
|
||||
if (--this->xfer_cnt == 0) {
|
||||
this->stop_disk_access();
|
||||
// generate sector_done interrupt
|
||||
this->int_flags |= INT_SECT_DONE;
|
||||
update_irq();
|
||||
return;
|
||||
}
|
||||
this->cur_state = SWIM3_ADDR_MARK_SEARCH;
|
||||
delay = this->int_drive->next_addr_mark_delay(&this->target_sect);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "SWIM3: unknown disk access phase 0x%X", this->cur_state);
|
||||
return;
|
||||
}
|
||||
|
||||
// HACK: figure out from bits in int_mask register which kind of disk access is requested
|
||||
if (this->int_mask & INT_ID_READ) { // read address header
|
||||
this->access_timer_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
static_cast<uint64_t>(this->int_drive->get_sector_delay() * NS_PER_SEC + 0.5f),
|
||||
[this]() {
|
||||
// get next sector's address field
|
||||
MacSuperdrive::SectorHdr addr = this->int_drive->next_sector_header();
|
||||
// set up the corresponding SWIM3 registers
|
||||
this->cur_track = ((addr.side & 1) << 7) | (addr.track & 0x7F);
|
||||
this->cur_sector = 0x80 /* CRC/checksum valid */ | (addr.sector & 0x7F);
|
||||
this->format = addr.format;
|
||||
// generate ID_read interrupt
|
||||
this->int_flags |= INT_ID_READ;
|
||||
update_irq();
|
||||
}
|
||||
);
|
||||
} else { // otherwise, read sector data
|
||||
this->access_timer_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
static_cast<uint64_t>(this->int_drive->get_sector_delay() * NS_PER_SEC + 0.5f),
|
||||
[this]() {
|
||||
// transfer sector data over DMA
|
||||
this->dma_ch->push_data(this->int_drive->get_sector_data_ptr(this->cur_sector), 512);
|
||||
|
||||
// get next address field
|
||||
MacSuperdrive::SectorHdr addr = this->int_drive->next_sector_header();
|
||||
// set up the corresponding SWIM3 registers
|
||||
this->cur_track = ((addr.side & 1) << 7) | (addr.track & 0x7F);
|
||||
this->cur_sector = 0x80 /* CRC/checksum valid */ | (addr.sector & 0x7F);
|
||||
this->format = addr.format;
|
||||
|
||||
if (--this->xfer_cnt == 0) {
|
||||
this->stop_disk_access();
|
||||
// generate sector_done interrupt
|
||||
this->int_flags |= INT_SECT_DONE;
|
||||
update_irq();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
this->access_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay,
|
||||
[this]() {
|
||||
this->disk_access();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void Swim3Ctrl::stop_disk_access()
|
||||
@@ -335,11 +362,57 @@ void Swim3Ctrl::stop_disk_access()
|
||||
this->access_timer_id = 0;
|
||||
}
|
||||
|
||||
void Swim3Ctrl::init_timer(const uint8_t start_val)
|
||||
{
|
||||
if (this->timer_val) {
|
||||
LOG_F(WARNING, "SWIM3: attempt to re-arm the timer");
|
||||
}
|
||||
this->timer_val = start_val;
|
||||
if (!this->timer_val) {
|
||||
this->one_us_timer_start = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this->one_us_timer_start = TimerManager::get_instance()->current_time_ns();
|
||||
|
||||
this->one_us_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
this->timer_val * NS_PER_USEC,
|
||||
[this]() {
|
||||
this->timer_val = 0;
|
||||
this->int_flags |= INT_TIMER_DONE;
|
||||
update_irq();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
uint8_t Swim3Ctrl::calc_timer_val()
|
||||
{
|
||||
if (!this->timer_val) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t time_now = TimerManager::get_instance()->current_time_ns();
|
||||
uint64_t us_elapsed = (time_now - this->one_us_timer_start) / NS_PER_USEC;
|
||||
if (us_elapsed > this->timer_val) {
|
||||
return 0;
|
||||
} else {
|
||||
return (this->timer_val - us_elapsed) & 0xFFU;
|
||||
}
|
||||
}
|
||||
|
||||
// floppy disk formats properties for the cases
|
||||
// where disk format needs to be specified manually
|
||||
static const std::vector<std::string> FloppyFormats = {
|
||||
"", "GCR_400K", "GCR_800K", "MFM_720K", "MFM_1440K"
|
||||
};
|
||||
|
||||
static const PropMap Swim3_Properties = {
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
{"fdd_wr_prot",
|
||||
new BinProperty(0)},
|
||||
{"fdd_fmt",
|
||||
new StrProperty("", FloppyFormats)},
|
||||
};
|
||||
|
||||
static const DeviceDescription Swim3_Descriptor = {
|
||||
|
||||
+27
-9
@@ -64,9 +64,17 @@ enum {
|
||||
|
||||
/** Interrupt flags. */
|
||||
enum {
|
||||
INT_STEP_DONE = 0x02,
|
||||
INT_ID_READ = 0x04,
|
||||
INT_SECT_DONE = 0x08,
|
||||
INT_TIMER_DONE = 0x01,
|
||||
INT_STEP_DONE = 0x02,
|
||||
INT_ID_READ = 0x04,
|
||||
INT_SECT_DONE = 0x08,
|
||||
};
|
||||
|
||||
// SWIM3 internal states.
|
||||
enum {
|
||||
SWIM3_IDLE,
|
||||
SWIM3_ADDR_MARK_SEARCH,
|
||||
SWIM3_DATA_XFER,
|
||||
};
|
||||
|
||||
class Swim3Ctrl : public HWComponent {
|
||||
@@ -89,18 +97,22 @@ public:
|
||||
};
|
||||
|
||||
protected:
|
||||
void update_irq();
|
||||
void start_stepping();
|
||||
void do_step();
|
||||
void stop_stepping();
|
||||
void start_disk_access();
|
||||
void stop_disk_access();
|
||||
void update_irq();
|
||||
void start_stepping();
|
||||
void do_step();
|
||||
void stop_stepping();
|
||||
void start_disk_access();
|
||||
void disk_access();
|
||||
void stop_disk_access();
|
||||
void init_timer(const uint8_t start_val);
|
||||
uint8_t calc_timer_val();
|
||||
|
||||
private:
|
||||
std::unique_ptr<MacSuperdrive::MacSuperDrive> int_drive;
|
||||
|
||||
DmaBidirChannel* dma_ch;
|
||||
|
||||
uint8_t timer_val = 0; // internal timer that decrements at a 1 us rate
|
||||
uint8_t setup_reg;
|
||||
uint8_t mode_reg;
|
||||
uint8_t error;
|
||||
@@ -112,14 +124,20 @@ private:
|
||||
uint8_t step_count;
|
||||
uint8_t cur_track;
|
||||
uint8_t cur_sector;
|
||||
uint8_t target_sect;
|
||||
uint8_t format; // format byte from the last GCR/MFM address field
|
||||
uint8_t first_sec;
|
||||
uint8_t xfer_cnt;
|
||||
uint8_t gap_size;
|
||||
uint8_t rd_line;
|
||||
int cur_state;
|
||||
|
||||
int one_us_timer_id = 0;
|
||||
int step_timer_id = 0;
|
||||
int access_timer_id = 0;
|
||||
|
||||
uint64_t one_us_timer_start = 0;
|
||||
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
|
||||
+14
-5
@@ -235,7 +235,7 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
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();
|
||||
this->awacs->dma_out_start();
|
||||
} else {
|
||||
LOG_F(9, "AMIC Sound Out DMA disabled!");
|
||||
this->snd_out_dma->disable();
|
||||
@@ -518,7 +518,7 @@ DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
|
||||
*p_data = mmu_get_dma_mem(
|
||||
(this->snd_buf_num ? this->out_buf1 : this->out_buf0) + this->cur_buf_pos,
|
||||
len);
|
||||
len, nullptr);
|
||||
this->cur_buf_pos += len;
|
||||
*avail_len = len;
|
||||
return DmaPullResult::MoreData;
|
||||
@@ -551,9 +551,14 @@ void AmicFloppyDma::write_ctrl(uint8_t value)
|
||||
|
||||
int AmicFloppyDma::push_data(const char* src_ptr, int len)
|
||||
{
|
||||
bool is_writable;
|
||||
|
||||
len = std::min((int)this->byte_count, len);
|
||||
|
||||
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len);
|
||||
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len, &is_writable);
|
||||
if (!is_writable) {
|
||||
ABORT_F("AMIC: attempting DMA write to read-only memory");
|
||||
}
|
||||
std::memcpy(p_data, src_ptr, len);
|
||||
|
||||
this->addr_ptr += len;
|
||||
@@ -598,7 +603,9 @@ void AmicScsiDma::write_ctrl(uint8_t value)
|
||||
|
||||
int AmicScsiDma::push_data(const char* src_ptr, int len)
|
||||
{
|
||||
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len);
|
||||
bool is_writable;
|
||||
|
||||
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len, &is_writable);
|
||||
std::memcpy(p_data, src_ptr, len);
|
||||
|
||||
this->addr_ptr += len;
|
||||
@@ -609,7 +616,9 @@ int AmicScsiDma::push_data(const char* src_ptr, int len)
|
||||
DmaPullResult AmicScsiDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data)
|
||||
{
|
||||
*p_data = mmu_get_dma_mem(this->addr_ptr, req_len);
|
||||
bool is_writable;
|
||||
|
||||
*p_data = mmu_get_dma_mem(this->addr_ptr, req_len, &is_writable);
|
||||
this->addr_ptr += req_len;
|
||||
*avail_len = req_len;
|
||||
return DmaPullResult::MoreData;
|
||||
|
||||
@@ -35,14 +35,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0002;
|
||||
this->class_rev = 0xFF000002;
|
||||
this->cache_ln_sz = 8;
|
||||
this->bars_cfg[0] = 0xFFFE0000UL; // declare 128Kb of memory-mapped I/O space
|
||||
|
||||
this->setup_bars({{0, 0xFFFE0000UL}}); // declare 128Kb of memory-mapped I/O space
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
@@ -59,8 +60,8 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->awacs->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_start, this->awacs.get()),
|
||||
std::bind(&AwacsScreamer::dma_end, this->awacs.get())
|
||||
std::bind(&AwacsScreamer::dma_out_start, this->awacs.get()),
|
||||
std::bind(&AwacsScreamer::dma_out_stop, this->awacs.get())
|
||||
);
|
||||
|
||||
// connect serial HW
|
||||
@@ -74,6 +75,8 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
|
||||
// connect floppy disk HW
|
||||
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
|
||||
this->floppy_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
|
||||
// set EMMO pin status (active low)
|
||||
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
|
||||
@@ -136,9 +139,11 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
(this->nvram_addr_hi << 5) + ((offset >> 4) & 0x1F));
|
||||
}
|
||||
} else if (offset & 0x8000) { // DMA register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
unsigned subdev_num = (offset >> 8) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 1:
|
||||
return this->floppy_dma->reg_read(offset & 0xFF, size);
|
||||
case 8:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
default:
|
||||
@@ -223,9 +228,12 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->base_addr + offset);
|
||||
}
|
||||
} else if (offset & 0x8000) { // DMA register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
unsigned subdev_num = (offset >> 8) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 1:
|
||||
this->floppy_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case 8:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
|
||||
+59
-33
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -35,7 +35,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
@@ -47,7 +46,7 @@ using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
@@ -55,7 +54,8 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
|
||||
this->class_rev = 0xFF000001;
|
||||
this->cache_ln_sz = 8;
|
||||
this->lat_timer = 0x40;
|
||||
this->bars_cfg[0] = 0xFFF80000UL; // declare 512Kb of memory-mapped I/O space
|
||||
|
||||
this->setup_bars({{0, 0xFFF80000UL}}); // declare 512Kb of memory-mapped I/O space
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
@@ -67,13 +67,14 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
|
||||
// connect Cuda
|
||||
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
this->screamer = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
|
||||
// find appropriate sound chip, create a DMA output channel for sound,
|
||||
// then wire everything together
|
||||
this->snd_codec = dynamic_cast<MacioSndCodec*>(gMachineObj->get_comp_by_type(HWCompType::SND_CODEC));
|
||||
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->screamer->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_codec->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())
|
||||
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec),
|
||||
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
|
||||
);
|
||||
|
||||
// connect SCSI HW
|
||||
@@ -86,8 +87,11 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
|
||||
// connect floppy disk HW
|
||||
// connect floppy disk HW and initialize its DMA channel
|
||||
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
|
||||
this->floppy_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
this->floppy_dma->register_dma_int(this, 2);
|
||||
|
||||
// set EMMO pin status (active low)
|
||||
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
|
||||
@@ -100,7 +104,7 @@ void HeathrowIC::notify_bar_change(int bar_num)
|
||||
|
||||
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
if (this->base_addr) {
|
||||
LOG_F(WARNING, "Heathrow: deallocating I/O memory not implemented");
|
||||
this->host_instance->pci_unregister_mmio_region(this->base_addr, 0x80000, this);
|
||||
}
|
||||
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
@@ -109,21 +113,23 @@ void HeathrowIC::notify_bar_change(int bar_num)
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset >> 8) {
|
||||
case 1:
|
||||
return this->floppy_dma->reg_read(offset & 0xFF, size);
|
||||
case 8:
|
||||
res = this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
break;
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
|
||||
}
|
||||
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset >> 8) {
|
||||
case 1:
|
||||
this->floppy_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case 8:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
@@ -158,7 +164,7 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
case 0x13: // ESCC MacRISC addressing
|
||||
return this->escc->read((offset >> 4) & 0xF);
|
||||
case 0x14:
|
||||
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
||||
res = this->snd_codec->snd_ctrl_read(offset - 0x14000, size);
|
||||
break;
|
||||
case 0x15: // SWIM3
|
||||
return this->swim3->read((offset >> 4 )& 0xF);
|
||||
@@ -208,7 +214,7 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
this->snd_codec->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
break;
|
||||
case 0x15: // SWIM3
|
||||
this->swim3->write((offset >> 4) & 0xF, value);
|
||||
@@ -254,12 +260,17 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
case MIO_INT_LEVELS1:
|
||||
res = this->int_levels1;
|
||||
break;
|
||||
case MIO_HEAT_ID:
|
||||
case MIO_INT_CLEAR1:
|
||||
case MIO_INT_CLEAR2:
|
||||
// some Mac OS drivers reads from those write-only registers
|
||||
// so we return zero here as real HW does
|
||||
break;
|
||||
case MIO_OHARE_ID:
|
||||
LOG_F(9, "read from MIO:ID register at Address %x", ppc_state.pc);
|
||||
res = (this->fp_id << 24) | (this->mon_id << 16) | (this->mb_id << 8) |
|
||||
(this->cpu_id | (this->emmo_pin << 4));
|
||||
break;
|
||||
case MIO_HEAT_FEAT_CTRL:
|
||||
case MIO_OHARE_FEAT_CTRL:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register");
|
||||
res = this->feat_ctrl;
|
||||
break;
|
||||
@@ -297,10 +308,10 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->int_events1 &= BYTESWAP_32(value);
|
||||
}
|
||||
break;
|
||||
case MIO_HEAT_ID:
|
||||
case MIO_OHARE_ID:
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x", value, offset, ppc_state.pc);
|
||||
break;
|
||||
case MIO_HEAT_FEAT_CTRL:
|
||||
case MIO_OHARE_FEAT_CTRL:
|
||||
this->feature_control(BYTESWAP_32(value));
|
||||
break;
|
||||
case 0x3C:
|
||||
@@ -370,23 +381,38 @@ void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
this->int_levels1 &= ~irq_id;
|
||||
}
|
||||
}
|
||||
// signal CPU interrupt
|
||||
if (this->int_events1 || this->int_events2) {
|
||||
if (!this->cpu_int_latch) {
|
||||
this->cpu_int_latch = true;
|
||||
ppc_assert_int();
|
||||
LOG_F(5, "Heathrow: CPU INT asserted, source: %d", irq_id);
|
||||
} else {
|
||||
LOG_F(5, "Heathrow: CPU INT already latched");
|
||||
}
|
||||
}
|
||||
this->signal_cpu_int();
|
||||
} else {
|
||||
ABORT_F("Heathrow: native interrupt mode not implemented");
|
||||
ABORT_F("%s: native interrupt mode not implemented", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
|
||||
this->int_events1 |= irq_id; // signal IRQ line change
|
||||
this->int_events1 &= this->int_mask1;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels1 |= irq_id;
|
||||
} else {
|
||||
this->int_levels1 &= ~irq_id;
|
||||
}
|
||||
this->signal_cpu_int();
|
||||
} else {
|
||||
ABORT_F("%s: native interrupt mode not implemented", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::signal_cpu_int() {
|
||||
if (this->int_events1 || this->int_events2) {
|
||||
if (!this->cpu_int_latch) {
|
||||
this->cpu_int_latch = true;
|
||||
ppc_assert_int();
|
||||
} else {
|
||||
LOG_F(5, "%s: CPU INT already latched", this->name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::clear_cpu_int()
|
||||
|
||||
+51
-4
@@ -142,6 +142,50 @@ private:
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> floppy_dma;
|
||||
};
|
||||
|
||||
class OHare : public PCIDevice, public InterruptCtrl {
|
||||
public:
|
||||
OHare();
|
||||
~OHare() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<OHare>(new OHare());
|
||||
}
|
||||
|
||||
// MMIO device methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
// InterruptCtrl methods
|
||||
uint32_t register_dev_int(IntSrc src_id);
|
||||
uint32_t register_dma_int(IntSrc src_id);
|
||||
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
uint32_t read_ctrl(uint32_t offset, int size);
|
||||
void write_ctrl(uint32_t offset, uint32_t value, int size);
|
||||
uint32_t dma_read(uint32_t offset, int size);
|
||||
void dma_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
private:
|
||||
uint32_t base_addr = 0;
|
||||
|
||||
// interrupt state
|
||||
uint32_t int_mask = 0;
|
||||
uint32_t int_levels = 0;
|
||||
uint32_t int_events = 0;
|
||||
bool cpu_int_latch = false;
|
||||
|
||||
std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
|
||||
NVram* nvram; // NVRAM module
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
EsccController* escc; // ESCC serial controller
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -168,10 +212,10 @@ private:
|
||||
VIA-CUDA register space: 0x00016000, size: 0x00002000
|
||||
*/
|
||||
|
||||
/** Heathrow specific registers. */
|
||||
/** O'Hare/Heathrow specific registers. */
|
||||
enum {
|
||||
MIO_HEAT_ID = 0x34, // IDs register
|
||||
MIO_HEAT_FEAT_CTRL = 0x38, // feature control register
|
||||
MIO_OHARE_ID = 0x34, // IDs register
|
||||
MIO_OHARE_FEAT_CTRL = 0x38, // feature control register
|
||||
};
|
||||
|
||||
class HeathrowIC : public PCIDevice, public InterruptCtrl {
|
||||
@@ -203,6 +247,7 @@ protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
|
||||
void feature_control(const uint32_t value);
|
||||
void signal_cpu_int();
|
||||
void clear_cpu_int();
|
||||
|
||||
private:
|
||||
@@ -224,7 +269,7 @@ private:
|
||||
uint8_t emmo_pin; // factory tester status, active low
|
||||
|
||||
// subdevice objects
|
||||
std::unique_ptr<AwacsScreamer> screamer; // Screamer audio codec instance
|
||||
MacioSndCodec* snd_codec; // audio codec instance
|
||||
|
||||
NVram* nvram; // NVRAM
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
@@ -234,7 +279,9 @@ private:
|
||||
IdeChannel* ide_1; // Media Bay ATA
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
|
||||
// DMA channels
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> floppy_dma;
|
||||
};
|
||||
|
||||
#endif /* MACIO_H */
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/macio.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
OHare::OHare() : PCIDevice("mac-io/ohare"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0007;
|
||||
this->class_rev = 0xFF000001;
|
||||
this->cache_ln_sz = 8;
|
||||
|
||||
this->setup_bars({{0, 0xFFF80000UL}}); // declare 512Kb of memory-mapped I/O space
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
// NVRAM connection
|
||||
this->nvram = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
|
||||
// connect Cuda
|
||||
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
this->awacs = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
|
||||
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->awacs->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_out_start, this->awacs.get()),
|
||||
std::bind(&AwacsScreamer::dma_out_stop, this->awacs.get())
|
||||
);
|
||||
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
}
|
||||
|
||||
void OHare::notify_bar_change(int bar_num)
|
||||
{
|
||||
if (bar_num) // only BAR0 is supported
|
||||
return;
|
||||
|
||||
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
if (this->base_addr) {
|
||||
LOG_F(WARNING, "%s: deallocating I/O memory not implemented",
|
||||
this->pci_name.c_str());
|
||||
}
|
||||
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OHare::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
return read_ctrl(offset, size);
|
||||
case 8:
|
||||
return dma_read(offset & 0x7FFF, size);
|
||||
case 0x13: // ESCC MacRISC addressing
|
||||
return this->escc->read((offset >> 4) & 0xF);
|
||||
case 0x14: // AWACS
|
||||
return this->awacs->snd_ctrl_read(offset & 0xFF, size);
|
||||
case 0x16:
|
||||
case 0x17:
|
||||
return this->viacuda->read((offset >> 9) & 0xF);
|
||||
case 0x20:
|
||||
return 0xFF7FU;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
return this->nvram->read_byte((offset - 0x60000) >> 4);
|
||||
} else {
|
||||
LOG_F(WARNING, "OHare: read from unimplemented register 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
}
|
||||
|
||||
return 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
void OHare::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
this->write_ctrl(offset, value, size);
|
||||
break;
|
||||
case 8:
|
||||
this->dma_write(offset & 0x7FFF, value, size);
|
||||
break;
|
||||
case 0x13: // ESCC MacRISC addressing
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x14: // AWACS
|
||||
this->awacs->snd_ctrl_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x17: // VIA-CUDA
|
||||
this->viacuda->write((offset >> 9) & 0xF, value);
|
||||
break;
|
||||
case 0x20:
|
||||
LOG_F(INFO, "OHare: write to IDE0 register at 0x%X", offset);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
||||
} else {
|
||||
LOG_F(WARNING, "OHare: writing to unimplemented device register 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OHare::read_ctrl(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset & 0xFC) {
|
||||
case MIO_INT_EVENTS1:
|
||||
res = this->int_events;
|
||||
break;
|
||||
case MIO_OHARE_ID: // HACK: no clue what this register is supposed to contain
|
||||
res = 0xFFFFBFFFUL;
|
||||
default:
|
||||
LOG_F(WARNING, "OHare: read from unknown control register at %x", offset);
|
||||
break;
|
||||
}
|
||||
|
||||
return BYTESWAP_32(res);
|
||||
}
|
||||
|
||||
void OHare::write_ctrl(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset) {
|
||||
case MIO_INT_MASK1:
|
||||
this->int_mask = BYTESWAP_32(value);
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
this->int_events = 0;
|
||||
this->cpu_int_latch = false;
|
||||
ppc_release_int();
|
||||
LOG_F(5, "OHare: CPU INT latch cleared");
|
||||
} else {
|
||||
this->int_events &= BYTESWAP_32(value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "OHare: writing to unimplemented control register 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OHare::dma_read(uint32_t offset, int size)
|
||||
{
|
||||
switch (offset >> 8) {
|
||||
case 8:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
default:
|
||||
LOG_F(WARNING, "OHare: unsupported DMA channel read, offset=0x%X", offset);
|
||||
}
|
||||
|
||||
return 0xFFFFFFUL;
|
||||
}
|
||||
|
||||
void OHare::dma_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset >> 8) {
|
||||
case 8:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "OHare: unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OHare::register_dev_int(IntSrc src_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t OHare::register_dma_int(IntSrc src_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OHare::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OHare::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static const vector<string> OHare_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "Mesh", "Escc", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription OHare_Descriptor = {
|
||||
OHare::create, OHare_Subdevices, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(OHare, OHare_Descriptor);
|
||||
+181
-12
@@ -25,7 +25,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <loguru.hpp>
|
||||
|
||||
static inline bool match_mem_entry(const AddressMapEntry* entry,
|
||||
const uint32_t start, const uint32_t end,
|
||||
MMIODevice* dev_instance)
|
||||
{
|
||||
return start == entry->start && end == entry->end &&
|
||||
(!dev_instance || dev_instance == entry->devobj);
|
||||
}
|
||||
|
||||
MemCtrlBase::~MemCtrlBase() {
|
||||
for (auto& entry : address_map) {
|
||||
@@ -52,12 +60,96 @@ AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
||||
}
|
||||
|
||||
|
||||
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* MemCtrlBase::find_range_exact(uint32_t addr, uint32_t size,
|
||||
MMIODevice* dev_instance)
|
||||
{
|
||||
if (size) {
|
||||
const uint32_t end = addr + size - 1;
|
||||
for (auto& entry : address_map) {
|
||||
if (match_mem_entry(entry, addr, end, dev_instance))
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_range_contains(uint32_t addr, uint32_t size) {
|
||||
if (size) {
|
||||
uint32_t end = addr + size - 1;
|
||||
for (auto& entry : address_map) {
|
||||
if (addr >= entry->start && end <= entry->end)
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_range_overlaps(uint32_t addr, uint32_t size) {
|
||||
if (size) {
|
||||
uint32_t end = addr + size - 1;
|
||||
for (auto& entry : address_map) {
|
||||
if (end >= entry->start && addr <= entry->end)
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::is_range_free(uint32_t addr, uint32_t size) {
|
||||
bool result = true;
|
||||
if (size) {
|
||||
uint32_t end = addr + size - 1;
|
||||
for (auto& entry : address_map) {
|
||||
if (addr == entry->start && end == entry->end) {
|
||||
LOG_F(WARNING, "memory region 0x%X..0x%X%s%s%s already exists",
|
||||
addr, end,
|
||||
entry->devobj ? " (" : "",
|
||||
entry->devobj ? entry->devobj->get_name().c_str() : "",
|
||||
entry->devobj ? ")"
|
||||
: ""
|
||||
);
|
||||
result = false;
|
||||
}
|
||||
else if (addr >= entry->start && end <= entry->end) {
|
||||
LOG_F(WARNING, "0x%X..0x%X already exists in memory region 0x%X..0x%X%s%s%s",
|
||||
addr, end, entry->start, entry->end,
|
||||
entry->devobj ? " (" : "",
|
||||
entry->devobj ? entry->devobj->get_name().c_str() : "",
|
||||
entry->devobj ? ")"
|
||||
: ""
|
||||
);
|
||||
result = false;
|
||||
}
|
||||
else if (end >= entry->start && addr <= entry->end) {
|
||||
LOG_F(ERROR, "0x%X..0x%X overlaps existing memory region 0x%X..0x%X%s%s%s",
|
||||
addr, end, entry->start, entry->end,
|
||||
entry->devobj ? " (" : "",
|
||||
entry->devobj ? entry->devobj->get_name().c_str() : "",
|
||||
entry->devobj ? ")"
|
||||
: ""
|
||||
);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
/* error if a memory region for the given range already exists */
|
||||
if (find_range(start_addr) || find_range(start_addr + size))
|
||||
if (!is_range_free(start_addr, size))
|
||||
return false;
|
||||
|
||||
uint8_t* reg_content = new uint8_t[size];
|
||||
@@ -66,8 +158,9 @@ bool MemCtrlBase::add_mem_region(
|
||||
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
uint32_t end = start_addr + size - 1;
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + size - 1;
|
||||
entry->end = end;
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = type;
|
||||
entry->devobj = 0;
|
||||
@@ -75,6 +168,14 @@ bool MemCtrlBase::add_mem_region(
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
LOG_F(INFO, "Added mem region 0x%X..0x%X (%s%s%s%s) -> 0x%X", start_addr, end,
|
||||
entry->type & RT_ROM ? "ROM," : "",
|
||||
entry->type & RT_RAM ? "RAM," : "",
|
||||
entry->type & RT_MMIO ? "MMIO," : "",
|
||||
entry->type & RT_MIRROR ? "MIRROR," : "",
|
||||
dest_addr
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -98,8 +199,9 @@ bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
uint32_t end = start_addr + (ref_entry->end - ref_entry->start);
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + (ref_entry->end - ref_entry->start);
|
||||
entry->end = end;
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = ref_entry->type | RT_MIRROR;
|
||||
entry->devobj = 0;
|
||||
@@ -107,36 +209,54 @@ bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
LOG_F(INFO, "Added mem region mirror 0x%X..0x%X (%s%s%s%s) -> 0x%X : 0x%X..0x%X%s%s%s",
|
||||
start_addr, end,
|
||||
entry->type & RT_ROM ? "ROM," : "",
|
||||
entry->type & RT_RAM ? "RAM," : "",
|
||||
entry->type & RT_MMIO ? "MMIO," : "",
|
||||
entry->type & RT_MIRROR ? "MIRROR," : "",
|
||||
dest_addr,
|
||||
ref_entry->start, ref_entry->end,
|
||||
ref_entry->devobj ? " (" : "",
|
||||
ref_entry->devobj ? ref_entry->devobj->get_name().c_str() : "",
|
||||
ref_entry->devobj ? ")"
|
||||
: ""
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size) {
|
||||
bool MemCtrlBase::set_data(uint32_t load_addr, const uint8_t* data, uint32_t size) {
|
||||
AddressMapEntry* ref_entry;
|
||||
uint32_t cpy_size;
|
||||
|
||||
ref_entry = find_range(reg_addr);
|
||||
ref_entry = find_range(load_addr);
|
||||
if (!ref_entry)
|
||||
return false;
|
||||
|
||||
uint32_t load_offset = load_addr - ref_entry->start;
|
||||
|
||||
cpy_size = std::min(ref_entry->end - ref_entry->start + 1, size);
|
||||
memcpy(ref_entry->mem_ptr, data, cpy_size);
|
||||
memcpy(ref_entry->mem_ptr + load_offset, data, cpy_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance) {
|
||||
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance)
|
||||
{
|
||||
AddressMapEntry *entry;
|
||||
|
||||
/* error if another region for the given range already exists */
|
||||
if (find_range(start_addr) || find_range(start_addr + size - 1))
|
||||
/* error if a memory region for the given range already exists */
|
||||
if (!is_range_free(start_addr, size))
|
||||
return false;
|
||||
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
uint32_t end = start_addr + size - 1;
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + size - 1;
|
||||
entry->end = end;
|
||||
entry->mirror = 0;
|
||||
entry->type = RT_MMIO;
|
||||
entry->devobj = dev_instance;
|
||||
@@ -144,9 +264,58 @@ bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
LOG_F(INFO, "Added mmio region 0x%X..0x%X%s%s%s",
|
||||
start_addr, end,
|
||||
dev_instance ? " (" : "",
|
||||
dev_instance ? dev_instance->get_name().c_str() : "",
|
||||
dev_instance ? ")"
|
||||
: ""
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemCtrlBase::remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance)
|
||||
{
|
||||
int found = 0;
|
||||
|
||||
uint32_t end = start_addr + size - 1;
|
||||
address_map.erase(std::remove_if(address_map.begin(), address_map.end(),
|
||||
[start_addr, end, dev_instance, &found](const AddressMapEntry *entry) {
|
||||
bool result = match_mem_entry(entry, start_addr, end, dev_instance);
|
||||
found += result;
|
||||
return result;
|
||||
}
|
||||
), address_map.end());
|
||||
|
||||
if (found == 0)
|
||||
LOG_F(ERROR, "Cannot find mmio region 0x%X..0x%X%s%s%s to remove",
|
||||
start_addr, end,
|
||||
dev_instance ? " (" : "",
|
||||
dev_instance ? dev_instance->get_name().c_str() : "",
|
||||
dev_instance ? ")"
|
||||
: ""
|
||||
);
|
||||
else if (found > 1)
|
||||
LOG_F(ERROR, "Removed %d occurrences of mmio region 0x%X..0x%X%s%s%s",
|
||||
found, start_addr, end,
|
||||
dev_instance ? " (" : "",
|
||||
dev_instance ? dev_instance->get_name().c_str() : "",
|
||||
dev_instance ? ")"
|
||||
: ""
|
||||
);
|
||||
else
|
||||
LOG_F(INFO, "Removed mmio region 0x%X..0x%X%s%s%s",
|
||||
start_addr, end,
|
||||
dev_instance ? " (" : "",
|
||||
dev_instance ? dev_instance->get_name().c_str() : "",
|
||||
dev_instance ? ")"
|
||||
: ""
|
||||
);
|
||||
|
||||
return (found > 0);
|
||||
}
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_rom_region()
|
||||
{
|
||||
for (auto& entry : address_map) {
|
||||
|
||||
@@ -68,10 +68,16 @@ public:
|
||||
virtual bool add_mem_mirror(uint32_t start_addr, uint32_t dest_addr);
|
||||
|
||||
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
|
||||
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
|
||||
|
||||
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
||||
|
||||
AddressMapEntry* find_range(uint32_t addr);
|
||||
AddressMapEntry* find_range_exact(uint32_t addr, uint32_t size, MMIODevice* dev_instance);
|
||||
AddressMapEntry* find_range_contains(uint32_t addr, uint32_t size);
|
||||
AddressMapEntry* find_range_overlaps(uint32_t addr, uint32_t size);
|
||||
bool is_range_free(uint32_t addr, uint32_t size);
|
||||
|
||||
AddressMapEntry* find_rom_region();
|
||||
|
||||
protected:
|
||||
|
||||
+169
-130
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,19 +26,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle"), PCIHost()
|
||||
{
|
||||
this->name = "Grackle";
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV |
|
||||
HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
|
||||
@@ -50,6 +47,9 @@ MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle"), PCIHost()
|
||||
this->command = 6;
|
||||
this->status = 0x80;
|
||||
|
||||
// assign PCI device number zero to myself
|
||||
this->pci_register_device(DEV_FUN(0,0), this);
|
||||
|
||||
// add PCI/ISA I/O space, 64K for now
|
||||
add_mmio_region(0xFE000000, 0x10000, this);
|
||||
|
||||
@@ -62,7 +62,7 @@ int MPC106::device_postinit()
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots = {
|
||||
{"pci_A1", 0xD}, {"pci_B1", 0xE}, {"pci_C1", 0xF}
|
||||
{"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}
|
||||
};
|
||||
|
||||
for (auto& slot : pci_slots) {
|
||||
@@ -75,153 +75,193 @@ int MPC106::device_postinit()
|
||||
}
|
||||
|
||||
uint32_t MPC106::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
uint32_t result;
|
||||
|
||||
if (rgn_start == 0xFE000000) {
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_read(offset, size, &result)) {
|
||||
return result;
|
||||
}
|
||||
return pci_io_read_broadcast(offset, size);
|
||||
}
|
||||
if (offset < 0x200000) {
|
||||
return this->config_addr;
|
||||
}
|
||||
LOG_F(ERROR, "Attempt to read from unmapped PCI I/O space, offset=0x%X", offset);
|
||||
} else {
|
||||
if (offset >= 0x200000) {
|
||||
if (this->config_addr & 0x80) // process only if bit E (enable) is set
|
||||
return pci_read(size);
|
||||
}
|
||||
if (this->config_addr & 0x80) { // process only if bit E (enable) is set
|
||||
return pci_read(offset, size);
|
||||
}
|
||||
|
||||
// FIXME: reading from CONFIG_ADDR is ignored for now
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPC106::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
|
||||
if (rgn_start == 0xFE000000) {
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_write(offset, value, size)) {
|
||||
pci_io_write_broadcast(offset, size, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "Attempt to write to unmapped PCI I/O space, offset=0x%X", offset);
|
||||
} else {
|
||||
if (offset < 0x200000) {
|
||||
this->config_addr = value;
|
||||
} else {
|
||||
if (this->config_addr & 0x80) // process only if bit E (enable) is set
|
||||
return pci_write(value, size);
|
||||
return;
|
||||
}
|
||||
if (this->config_addr & 0x80) { // process only if bit E (enable) is set
|
||||
return pci_write(offset, value, size);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MPC106::pci_read(uint32_t offset, uint32_t size) {
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIDevice *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_READ;
|
||||
if (device) {
|
||||
return pci_conv_rd_data(device->pci_cfg_read(reg_offs, details), details);
|
||||
}
|
||||
LOG_READ_NON_EXISTENT_PCI_DEVICE();
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
uint32_t MPC106::pci_read(uint32_t size) {
|
||||
int bus_num, dev_num, fun_num, reg_offs;
|
||||
void MPC106::pci_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIDevice *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_WRITE;
|
||||
if (device) {
|
||||
if (size == 4 && !details.offset) { // aligned DWORD writes -> fast path
|
||||
device->pci_cfg_write(reg_offs, BYTESWAP_32(value), details);
|
||||
return;
|
||||
}
|
||||
// otherwise perform necessary data transformations -> slow path
|
||||
uint32_t old_val = details.size == 4 ? 0 : device->pci_cfg_read(reg_offs, details);
|
||||
uint32_t new_val = pci_conv_wr_data(old_val, value, details);
|
||||
device->pci_cfg_write(reg_offs, new_val, details);
|
||||
return;
|
||||
}
|
||||
LOG_WRITE_NON_EXISTENT_PCI_DEVICE();
|
||||
}
|
||||
|
||||
bus_num = (this->config_addr >> 8) & 0xFF;
|
||||
inline void MPC106::cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
|
||||
int &fun_num, uint8_t ®_offs, AccessDetails &details,
|
||||
PCIDevice *&device)
|
||||
{
|
||||
device = NULL;
|
||||
details.size = size;
|
||||
details.offset = offset & 3;
|
||||
|
||||
bus_num = (this->config_addr >> 8) & 0xFF;
|
||||
dev_num = (this->config_addr >> 19) & 0x1F;
|
||||
fun_num = (this->config_addr >> 16) & 0x07;
|
||||
reg_offs = (this->config_addr >> 24) & 0xFC;
|
||||
|
||||
if (bus_num) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: read attempt from non-local PCI bus, config_addr = %x %02x:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), this->config_addr, bus_num, dev_num, fun_num, reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
details.flags = PCI_CONFIG_TYPE_1;
|
||||
device = pci_find_device(bus_num, dev_num, fun_num);
|
||||
}
|
||||
|
||||
if (dev_num == 0 && fun_num == 0) { // dev_num 0 is assigned to myself
|
||||
return this->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
if (this->dev_map.count(dev_num)) {
|
||||
return this->dev_map[dev_num]->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: read attempt from non-existing PCI device %02x:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPC106::pci_write(uint32_t value, uint32_t size) {
|
||||
int bus_num, dev_num, fun_num, reg_offs;
|
||||
|
||||
bus_num = (this->config_addr >> 8) & 0xFF;
|
||||
dev_num = (this->config_addr >> 19) & 0x1F;
|
||||
fun_num = (this->config_addr >> 16) & 0x07;
|
||||
reg_offs = (this->config_addr >> 24) & 0xFC;
|
||||
|
||||
if (bus_num) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: write attempt to non-local PCI bus, config_addr = %x %02x:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), this->config_addr, bus_num, dev_num, fun_num, reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size,
|
||||
size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dev_num == 0 && fun_num == 0) { // dev_num 0 is assigned to myself
|
||||
this->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
if (this->dev_map.count(dev_num)) {
|
||||
this->dev_map[dev_num]->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: write attempt to non-existing PCI device %02x:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size,
|
||||
size * 2, value
|
||||
);
|
||||
else {
|
||||
details.flags = PCI_CONFIG_TYPE_0;
|
||||
if (this->dev_map.count(DEV_FUN(dev_num, fun_num))) {
|
||||
device = this->dev_map[DEV_FUN(dev_num, fun_num)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MPC106::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "read from Grackle register %08X", reg_offs);
|
||||
#endif
|
||||
|
||||
uint32_t MPC106::pci_cfg_read(uint32_t reg_offs, AccessDetails &details) {
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, size);
|
||||
return PCIDevice::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
return read_mem(&this->my_pci_cfg_hdr[reg_offs], size);
|
||||
switch (reg_offs) {
|
||||
case GrackleReg::CFG10:
|
||||
return 0;
|
||||
case GrackleReg::PMCR1:
|
||||
return (this->odcr << 24) | (this->pmcr2 << 16) | this->pmcr1;
|
||||
case GrackleReg::MSAR1:
|
||||
case GrackleReg::MSAR2:
|
||||
return this->mem_start[(reg_offs >> 2) & 1];
|
||||
case GrackleReg::EMSAR1:
|
||||
case GrackleReg::EMSAR2:
|
||||
return this->ext_mem_start[(reg_offs >> 2) & 1];
|
||||
case GrackleReg::MEAR1:
|
||||
case GrackleReg::MEAR2:
|
||||
return this->mem_end[(reg_offs >> 2) & 1];
|
||||
case GrackleReg::EMEAR1:
|
||||
case GrackleReg::EMEAR2:
|
||||
return this->ext_mem_end[(reg_offs >> 2) & 1];
|
||||
case GrackleReg::MBER:
|
||||
return this->mem_bank_en;
|
||||
case GrackleReg::PICR1:
|
||||
return this->picr1;
|
||||
case GrackleReg::PICR2:
|
||||
return this->picr2;
|
||||
case GrackleReg::MCCR1:
|
||||
return this->mccr1;
|
||||
case GrackleReg::MCCR2:
|
||||
return this->mccr2;
|
||||
case GrackleReg::MCCR3:
|
||||
return this->mccr3;
|
||||
case GrackleReg::MCCR4:
|
||||
return this->mccr4;
|
||||
default:
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
|
||||
return 0; // PCI Spec §6.1
|
||||
}
|
||||
|
||||
void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "write %08X to Grackle register %08X", value, reg_offs);
|
||||
#endif
|
||||
|
||||
void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) {
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, size);
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, details);
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: implement write-protection for read-only registers
|
||||
|
||||
write_mem(&this->my_pci_cfg_hdr[reg_offs], value, size);
|
||||
|
||||
if (this->my_pci_cfg_hdr[0xF2] & 8) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "MPC106: MCCR1[MEMGO] was set!");
|
||||
#endif
|
||||
setup_ram();
|
||||
switch (reg_offs) {
|
||||
case GrackleReg::CFG10:
|
||||
// Open Firmware writes 0 to subordinate bus # - we don't care
|
||||
break;
|
||||
case GrackleReg::PMCR1:
|
||||
this->pmcr1 = value & 0xFFFFU;
|
||||
this->pmcr2 = (value >> 16) & 0xFF;
|
||||
this->odcr = value >> 24;
|
||||
break;
|
||||
case GrackleReg::MSAR1:
|
||||
case GrackleReg::MSAR2:
|
||||
this->mem_start[(reg_offs >> 2) & 1] = value;
|
||||
break;
|
||||
case GrackleReg::EMSAR1:
|
||||
case GrackleReg::EMSAR2:
|
||||
this->ext_mem_start[(reg_offs >> 2) & 1] = value;
|
||||
break;
|
||||
case GrackleReg::MEAR1:
|
||||
case GrackleReg::MEAR2:
|
||||
this->mem_end[(reg_offs >> 2) & 1] = value;
|
||||
break;
|
||||
case GrackleReg::EMEAR1:
|
||||
case GrackleReg::EMEAR2:
|
||||
this->ext_mem_end[(reg_offs >> 2) & 1] = value;
|
||||
break;
|
||||
case GrackleReg::MBER:
|
||||
this->mem_bank_en = value & 0xFFU;
|
||||
break;
|
||||
case GrackleReg::PICR1:
|
||||
this->picr1 = value;
|
||||
break;
|
||||
case GrackleReg::PICR2:
|
||||
this->picr2 = value;
|
||||
break;
|
||||
case GrackleReg::MCCR1:
|
||||
if ((value ^ this->mccr1) & MEMGO) {
|
||||
if (value & MEMGO)
|
||||
setup_ram();
|
||||
}
|
||||
this->mccr1 = value;
|
||||
break;
|
||||
case GrackleReg::MCCR2:
|
||||
this->mccr2 = value;
|
||||
break;
|
||||
case GrackleReg::MCCR3:
|
||||
this->mccr3 = value;
|
||||
break;
|
||||
case GrackleReg::MCCR4:
|
||||
this->mccr4 = value;
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,33 +269,32 @@ void MPC106::setup_ram() {
|
||||
uint32_t mem_start, mem_end, ext_mem_start, ext_mem_end, bank_start, bank_end;
|
||||
uint32_t ram_size = 0;
|
||||
|
||||
uint8_t bank_en = this->my_pci_cfg_hdr[0xA0];
|
||||
|
||||
for (int bank = 0; bank < 8; bank++) {
|
||||
if (bank_en & (1 << bank)) {
|
||||
if (this->mem_bank_en & (1 << bank)) {
|
||||
if (bank < 4) {
|
||||
mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x80]);
|
||||
ext_mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x88]);
|
||||
mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x90]);
|
||||
ext_mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x98]);
|
||||
mem_start = this->mem_start[0];
|
||||
ext_mem_start = this->ext_mem_start[0];
|
||||
mem_end = this->mem_end[0];
|
||||
ext_mem_end = this->ext_mem_end[0];
|
||||
} else {
|
||||
mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x84]);
|
||||
ext_mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x8C]);
|
||||
mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x94]);
|
||||
ext_mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x9C]);
|
||||
mem_start = this->mem_start[1];
|
||||
ext_mem_start = this->ext_mem_start[1];
|
||||
mem_end = this->mem_end[1];
|
||||
ext_mem_end = this->ext_mem_end[1];
|
||||
}
|
||||
bank_start = (((ext_mem_start >> bank * 8) & 3) << 30) |
|
||||
(((mem_start >> bank * 8) & 0xFF) << 20);
|
||||
bank_end = (((ext_mem_end >> bank * 8) & 3) << 30) |
|
||||
(((mem_end >> bank * 8) & 0xFF) << 20) | 0xFFFFFUL;
|
||||
if (bank && bank_start != ram_size)
|
||||
LOG_F(WARNING, "MPC106: RAM not contiguous!");
|
||||
LOG_F(WARNING, "Grackle: RAM not contiguous!");
|
||||
ram_size += bank_end - bank_start + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->add_ram_region(0, ram_size)) {
|
||||
LOG_F(ERROR, "MPC106 RAM allocation failed!");
|
||||
LOG_F(WARNING, "Grackle: RAM allocation 0x%X..0x%X failed (maybe already exists?)",
|
||||
0, ram_size - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+54
-97
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** MPC106 (Grackle) emulation
|
||||
/** MPC106 (Grackle) definitions.
|
||||
|
||||
Grackle IC is a combined memory and PCI controller manufactured by Motorola.
|
||||
It's the central device in the Gossamer architecture.
|
||||
@@ -31,8 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
- our virtual device reports revision 4.0 as expected by machine firmware
|
||||
*/
|
||||
|
||||
#ifndef MPC106_H_
|
||||
#define MPC106_H_
|
||||
#ifndef MPC106_H
|
||||
#define MPC106_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
@@ -43,6 +43,32 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
/** Grackle configuration space registers. */
|
||||
enum GrackleReg : uint32_t {
|
||||
CFG10 = 0x40, // bus # + subordinate bus # + disconnect counter
|
||||
PMCR1 = 0x70, // power management config 1
|
||||
MSAR1 = 0x80, // memory starting address 1
|
||||
MSAR2 = 0x84, // memory starting address 2
|
||||
EMSAR1 = 0x88, // extended memory starting address 1
|
||||
EMSAR2 = 0x8C, // extended memory starting address 2
|
||||
MEAR1 = 0x90, // memory ending address 1
|
||||
MEAR2 = 0x94, // memory ending address 2
|
||||
EMEAR1 = 0x98, // extended memory ending address 1
|
||||
EMEAR2 = 0x9C, // extended memory ending address 2
|
||||
MBER = 0xA0, // memory bank enable
|
||||
PICR1 = 0xA8, // processor interface configuration 1
|
||||
PICR2 = 0xAC, // processor interface configuration 2
|
||||
MCCR1 = 0xF0, // memory control configuration 1
|
||||
MCCR2 = 0xF4, // memory control configuration 2
|
||||
MCCR3 = 0xF8, // memory control configuration 3
|
||||
MCCR4 = 0xFC // memory control configuration 4
|
||||
};
|
||||
|
||||
/* MCCR1 bit definitions. */
|
||||
enum {
|
||||
MEMGO = 1 << 19,
|
||||
};
|
||||
|
||||
class MPC106 : public MemCtrlBase, public PCIDevice, public PCIHost {
|
||||
public:
|
||||
MPC106();
|
||||
@@ -59,106 +85,37 @@ public:
|
||||
|
||||
protected:
|
||||
/* PCI access */
|
||||
uint32_t pci_read(uint32_t size);
|
||||
void pci_write(uint32_t value, uint32_t size);
|
||||
uint32_t pci_read(uint32_t offset, uint32_t size);
|
||||
void pci_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
/* my own PCI configuration registers access */
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
bool supports_io_space(void) {
|
||||
return true;
|
||||
};
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
void setup_ram(void);
|
||||
|
||||
private:
|
||||
uint8_t my_pci_cfg_hdr[256] = {
|
||||
0x57, 0x10, // vendor ID: Motorola
|
||||
0x02, 0x00, // device ID: MPC106
|
||||
0x06, 0x00, // PCI command
|
||||
0x80, 0x00, // PCI status
|
||||
0x40, // revision ID: 4.0
|
||||
0x00, // standard programming
|
||||
0x00, // subclass code: host bridge
|
||||
0x06, // class code: bridge device
|
||||
0x08, // cache line size
|
||||
0x00, // latency timer
|
||||
0x00, // header type
|
||||
0x00, // BIST Control
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, // Interrupt line
|
||||
0x00, // Interrupt pin
|
||||
0x00, // MIN GNT
|
||||
0x00, // MAX LAT
|
||||
0x00, // Bus number
|
||||
0x00, // Subordinate bus number
|
||||
0x00, // Discount counter
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // Performance monitor command
|
||||
0x00, 0x00, // Performance monitor mode control
|
||||
0xFF, 0xFF,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 0
|
||||
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 1
|
||||
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 2
|
||||
0x00, 0x00, 0x00, 0x00, // Performance monitor counter 3
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF,
|
||||
|
||||
0x00, 0x00, // Power mgt config 1
|
||||
0x00, // Power mgt config 2
|
||||
0xCD, // default value for ODCR
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, // Memory Starting Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Extended Memory Starting Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Memory Ending Address
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Extended Memory Ending Address
|
||||
|
||||
0x00, // Memory bank enable
|
||||
0xFF, 0xFF,
|
||||
0x00, // Memory page mode
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0x10, 0x00, 0x00, 0xFF, // PICR1
|
||||
0x0C, 0x06, 0x0C, 0x00, // PICR2
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, // ECC single-bit error counter
|
||||
0x00, // ECC single-bit error trigger
|
||||
0x04, // Alternate OS visible paramaters 1
|
||||
0x01, // Alternate OS visible paramaters 2
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0x01, // Error enabling 1
|
||||
0x00, // Error detection 1
|
||||
0xFF,
|
||||
0x00, // 60x bus error status
|
||||
0x00, // Error enabling 2
|
||||
0x00, // Error detection 2
|
||||
0xFF,
|
||||
0x00, // PCI bus error status
|
||||
0x00, 0x00, 0x00, 0x00, // 60x/PCI ERROR address
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF,
|
||||
|
||||
0x42, 0x00, 0xFF, 0x0F, // Emulation support config 1
|
||||
0x00, 0x00, 0x00, 0x00, // Modified memory status (no clear)
|
||||
0x20, 0x00, 0x00, 0x00, // Emulation support config 2
|
||||
0x00, 0x00, 0x00, 0x00, // Modified memory status (clear)
|
||||
|
||||
0x00, 0x00, 0x02, 0xFF, // Memory ctrl config 1
|
||||
0x03, 0x00, 0x00, 0x00, // Memory ctrl config 2
|
||||
0x00, 0x00, 0x00, 0x00, // Memory ctrl config 3
|
||||
0x00, 0x00, 0x10, 0x00 // Memory ctrl config 4
|
||||
};
|
||||
inline void cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
|
||||
int &fun_num, uint8_t ®_offs, AccessDetails &details,
|
||||
PCIDevice *&device);
|
||||
|
||||
uint32_t config_addr;
|
||||
|
||||
uint16_t pmcr1 = 0; // power management config 1
|
||||
uint8_t pmcr2 = 0; // power management config 2
|
||||
uint8_t odcr = 0xCD; // output driver control
|
||||
uint32_t picr1 = 0xFF100010; // ROM on CPU bus, address map B, CPU type = MPC601
|
||||
uint32_t picr2 = 0x000C060C;
|
||||
uint32_t mccr1 = 0xFF820000; // 64bit ROM bus
|
||||
uint32_t mccr2 = 3;
|
||||
uint32_t mccr3 = 0;
|
||||
uint32_t mccr4 = 0x00100000;
|
||||
|
||||
uint32_t mem_start[2] = {};
|
||||
uint32_t ext_mem_start[2] = {};
|
||||
uint32_t mem_end[2] = {};
|
||||
uint32_t ext_mem_end[2] = {};
|
||||
uint8_t mem_bank_en = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // MPC106_H
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** PSX Memory Controller emulation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/psx.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
PsxCtrl::PsxCtrl(int bridge_num, std::string name)
|
||||
{
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
||||
|
||||
// add MMIO region for the PSX control registers
|
||||
add_mmio_region(0xF8000000, 0x70, this);
|
||||
|
||||
this->sys_id = 0x10000000;
|
||||
this->chip_rev = 0; // old PSX, what's about PSX+?
|
||||
this->sys_config = PSX_BUS_SPEED_50;
|
||||
}
|
||||
|
||||
uint32_t PsxCtrl::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
switch (offset >> 3) {
|
||||
case PsxReg::Sys_Id:
|
||||
return this->sys_id;
|
||||
case PsxReg::Revision:
|
||||
return this->chip_rev;
|
||||
case PsxReg::Sys_Config:
|
||||
return this->sys_config;
|
||||
default:
|
||||
LOG_F(WARNING, "PSX: read from unsupported control register at 0x%X", offset);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PsxCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset >> 3) {
|
||||
case PsxReg::Sys_Config:
|
||||
this->sys_config = value;
|
||||
break;
|
||||
case PsxReg::ROM_Config:
|
||||
this->rom_cfg = value;
|
||||
break;
|
||||
case PsxReg::DRAM_Config:
|
||||
this->dram_cfg = value;
|
||||
break;
|
||||
case PsxReg::DRAM_Refresh:
|
||||
this->dram_refresh = value;
|
||||
break;
|
||||
case PsxReg::Flash_Config:
|
||||
this->flash_cfg = value;
|
||||
break;
|
||||
case PsxReg::Page1_Mapping:
|
||||
case PsxReg::Page2_Mapping:
|
||||
case PsxReg::Page3_Mapping:
|
||||
case PsxReg::Page4_Mapping:
|
||||
case PsxReg::Page5_Mapping:
|
||||
this->pages_cfg[(offset >> 3) - PsxReg::Page1_Mapping] = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "PSX: write to unsupported/read-only control register at 0x%X", offset);
|
||||
};
|
||||
}
|
||||
|
||||
void PsxCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
|
||||
{
|
||||
if (slot_num < 0 || slot_num >= 5) {
|
||||
ABORT_F("PSX: invalid DIMM slot %d", slot_num);
|
||||
}
|
||||
|
||||
switch (capacity) {
|
||||
case DRAM_CAP_2MB:
|
||||
case DRAM_CAP_4MB:
|
||||
case DRAM_CAP_8MB:
|
||||
case DRAM_CAP_16MB:
|
||||
case DRAM_CAP_32MB:
|
||||
this->bank_sizes[slot_num] = capacity;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("PSX: unsupported DRAM capacity %d", capacity);
|
||||
}
|
||||
}
|
||||
|
||||
void PsxCtrl::map_phys_ram()
|
||||
{
|
||||
uint32_t total_ram = 0;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
total_ram += this->bank_sizes[i];
|
||||
}
|
||||
|
||||
if (total_ram > DRAM_CAP_32MB) {
|
||||
ABORT_F("PSX: RAM bigger than 32MB not supported yet");
|
||||
}
|
||||
|
||||
if (!add_ram_region(0x00000000, total_ram)) {
|
||||
ABORT_F("PSX: could not allocate RAM storage");
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Psx_Descriptor = {
|
||||
PsxCtrl::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Psx, Psx_Descriptor);
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** PSX Memory Controller definitions. */
|
||||
|
||||
#ifndef PSX_MEMCTRL_H
|
||||
#define PSX_MEMCTRL_H
|
||||
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace PsxReg {
|
||||
enum {
|
||||
Sys_Id = 0,
|
||||
Revision = 1,
|
||||
Sys_Config = 2,
|
||||
ROM_Config = 3,
|
||||
DRAM_Config = 4,
|
||||
DRAM_Refresh = 5,
|
||||
Flash_Config = 6,
|
||||
Page1_Mapping = 8,
|
||||
Page2_Mapping = 9,
|
||||
Page3_Mapping = 10,
|
||||
Page4_Mapping = 11,
|
||||
Page5_Mapping = 12,
|
||||
Bus_Timeout = 13
|
||||
};
|
||||
}; // namespace PsxReg
|
||||
|
||||
/** Bus (aka CPU) speed constants. */
|
||||
enum {
|
||||
PSX_BUS_SPEED_38 = 0, // bus frequency 38 MHz
|
||||
PSX_BUS_SPEED_33 = 1, // bus frequency 33 MHz
|
||||
PSX_BUS_SPEED_40 = 2, // bus frequency 40 MHz
|
||||
PSX_BUS_SPEED_50 = 3, // bus frequency 50 MHz
|
||||
};
|
||||
|
||||
class PsxCtrl : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
PsxCtrl(int bridge_num, std::string name);
|
||||
~PsxCtrl() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<PsxCtrl>(new PsxCtrl(1, "PSX-PCI1"));
|
||||
};
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void insert_ram_dimm(int slot_num, uint32_t capacity);
|
||||
void map_phys_ram();
|
||||
|
||||
private:
|
||||
uint32_t sys_id;
|
||||
uint32_t chip_rev;
|
||||
uint32_t sys_config;
|
||||
uint32_t rom_cfg;
|
||||
uint32_t dram_cfg;
|
||||
uint32_t dram_refresh;
|
||||
uint32_t flash_cfg;
|
||||
uint32_t pages_cfg[5];
|
||||
uint32_t bank_sizes[5] = {};
|
||||
};
|
||||
|
||||
#endif // PSX_MEMCTRL_H
|
||||
@@ -336,7 +336,6 @@ void CharIoSocket::rcv_disable()
|
||||
bool CharIoSocket::rcv_char_available()
|
||||
{
|
||||
static int consecutivechars = 0;
|
||||
static int count = 0;
|
||||
|
||||
if (consecutivechars >= 15) {
|
||||
consecutivechars++;
|
||||
@@ -377,7 +376,7 @@ bool CharIoSocket::rcv_char_available()
|
||||
if (sockfd != -1) {
|
||||
if (FD_ISSET(sockfd, &readfds)) {
|
||||
uint8_t c;
|
||||
int received = recv(sockfd, &c, 1, 0);
|
||||
int received = (int)recv(sockfd, &c, 1, 0);
|
||||
if (received == -1) {
|
||||
if (acceptfd == -1) {
|
||||
//LOG_F(INFO, "socket sock read (not accepted yet) err: %s", strerror(errno)); // this happens once before accept
|
||||
@@ -443,7 +442,7 @@ int CharIoSocket::xmit_char(uint8_t c)
|
||||
CharIoSocket::rcv_char_available();
|
||||
|
||||
if (acceptfd != -1) {
|
||||
int sent = send(acceptfd, &c, 1, 0);
|
||||
int sent = (int)send(acceptfd, &c, 1, 0);
|
||||
if (sent == -1) {
|
||||
LOG_F(INFO, "socket accept write err: %s", strerror(errno));
|
||||
}
|
||||
@@ -463,7 +462,7 @@ int CharIoSocket::rcv_char(uint8_t *c)
|
||||
CharIoSocket::rcv_char_available();
|
||||
|
||||
if (acceptfd != -1) {
|
||||
int received = recv(acceptfd, c, 1, 0);
|
||||
int received = (int)recv(acceptfd, c, 1, 0);
|
||||
if (received == -1) {
|
||||
LOG_F(INFO, "socket accept read err: %s", strerror(errno));
|
||||
}
|
||||
|
||||
@@ -92,7 +92,6 @@ uint8_t EsccController::read(uint8_t reg_offset)
|
||||
} else {
|
||||
return this->ch_a->read_reg(this->reg_ptr);
|
||||
}
|
||||
this->reg_ptr = 0;
|
||||
break;
|
||||
case EsccReg::Port_B_Data:
|
||||
return this->ch_b->receive_byte();
|
||||
|
||||
+54
-70
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,11 +24,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
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/deviceregistry.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <endianswap.h>
|
||||
@@ -38,8 +36,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <loguru.hpp>
|
||||
#include <memory>
|
||||
|
||||
AwacsBase::AwacsBase()
|
||||
AwacsBase::AwacsBase(std::string name)
|
||||
{
|
||||
supports_types(HWCompType::SND_CODEC);
|
||||
|
||||
this->name = name;
|
||||
|
||||
// connect to SoundServer
|
||||
this->snd_server = dynamic_cast<SoundServer *>
|
||||
(gMachineObj->get_comp_by_name("SoundServer"));
|
||||
@@ -49,31 +51,43 @@ AwacsBase::AwacsBase()
|
||||
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);
|
||||
LOG_F(ERROR, "%s: invalid sample rate ID %d!", this->name.c_str(), sr_id);
|
||||
} else {
|
||||
this->cur_sample_rate = this->sr_table[sr_id];
|
||||
}
|
||||
};
|
||||
|
||||
void AwacsBase::start_output_dma()
|
||||
void AwacsBase::dma_out_start()
|
||||
{
|
||||
int err;
|
||||
int err;
|
||||
bool reopen = false;
|
||||
|
||||
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);
|
||||
if (this->out_stream_ready && this->out_sample_rate != this->cur_sample_rate)
|
||||
reopen = true;
|
||||
|
||||
if (reopen) {
|
||||
snd_server->close_out_stream();
|
||||
this->out_stream_ready = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this->out_stream_ready = true;
|
||||
if (!this->out_stream_ready || reopen) {
|
||||
if ((err = this->snd_server->open_out_stream(this->cur_sample_rate,
|
||||
(void *)this->dma_out_ch))) {
|
||||
LOG_F(ERROR, "%s: unable to open sound output stream: %d",
|
||||
this->name.c_str(), err);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "AWACs: could not start sound output stream");
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "%s: could not start sound output stream", this->name.c_str());
|
||||
}
|
||||
|
||||
this->out_sample_rate = this->cur_sample_rate;
|
||||
this->out_stream_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsBase::stop_output_dma()
|
||||
void AwacsBase::dma_out_stop()
|
||||
{
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
@@ -82,7 +96,7 @@ void AwacsBase::stop_output_dma()
|
||||
}
|
||||
|
||||
//=========================== PDM-style AWACs =================================
|
||||
AwacDevicePdm::AwacDevicePdm() : AwacsBase()
|
||||
AwacDevicePdm::AwacDevicePdm() : AwacsBase("AWAC-PDM")
|
||||
{
|
||||
static int pdm_awac_freqs[3] = {22050, 29400, 44100};
|
||||
|
||||
@@ -93,31 +107,24 @@ AwacDevicePdm::AwacDevicePdm() : AwacsBase()
|
||||
|
||||
uint32_t AwacDevicePdm::read_stat()
|
||||
{
|
||||
LOG_F(INFO, "AWACs-PDM: status requested!");
|
||||
LOG_F(INFO, "%s: status requested!", this->name.c_str());
|
||||
// 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);
|
||||
LOG_F(ERROR, "%s: invalid control register address %d!", this->name.c_str(),
|
||||
addr);
|
||||
}
|
||||
}
|
||||
|
||||
//============================= Screamer AWACs ================================
|
||||
AwacsScreamer::AwacsScreamer() : AwacsBase()
|
||||
AwacsScreamer::AwacsScreamer(std::string name) : MacioSndCodec(name)
|
||||
{
|
||||
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
|
||||
};
|
||||
@@ -126,6 +133,16 @@ AwacsScreamer::AwacsScreamer() : AwacsBase()
|
||||
this->max_sr_id = 7;
|
||||
}
|
||||
|
||||
int AwacsScreamer::device_postinit() {
|
||||
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());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t AwacsScreamer::snd_ctrl_read(uint32_t offset, int size)
|
||||
{
|
||||
switch (offset) {
|
||||
@@ -136,7 +153,7 @@ uint32_t AwacsScreamer::snd_ctrl_read(uint32_t offset, int size)
|
||||
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);
|
||||
LOG_F(ERROR, "%s: unsupported register at offset 0x%X", this->name.c_str(), offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -150,58 +167,25 @@ void AwacsScreamer::snd_ctrl_write(uint32_t offset, uint32_t value, int size)
|
||||
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);
|
||||
this->set_sample_rate((this->snd_ctrl_reg >> 8) & 7);
|
||||
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",
|
||||
LOG_F(9, "%s subframe = %d, reg = %d, data = %08X", this->name.c_str(),
|
||||
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);
|
||||
LOG_F(ERROR, "%s: unsupported register at offset 0x%X", this->name.c_str(),
|
||||
offset);
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsScreamer::open_stream(int sample_rate)
|
||||
{
|
||||
int err;
|
||||
static const DeviceDescription Screamer_Descriptor = {
|
||||
AwacsScreamer::create, {}, {}
|
||||
};
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
REGISTER_DEVICE(ScreamerSnd, Screamer_Descriptor);
|
||||
+37
-32
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -28,18 +28,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef AWAC_H
|
||||
#define AWAC_H
|
||||
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** Base class for the AWACs codecs. */
|
||||
class AwacsBase {
|
||||
class AwacsBase : public HWComponent {
|
||||
public:
|
||||
AwacsBase();
|
||||
AwacsBase(std::string name);
|
||||
~AwacsBase() = default;
|
||||
|
||||
void set_dma_out(DmaOutChannel *dma_out_ch) {
|
||||
@@ -47,8 +48,8 @@ public:
|
||||
};
|
||||
|
||||
void set_sample_rate(int sr_id);
|
||||
void start_output_dma();
|
||||
void stop_output_dma();
|
||||
void dma_out_start();
|
||||
void dma_out_stop();
|
||||
|
||||
protected:
|
||||
SoundServer *snd_server; // SoundServer instance pointer
|
||||
@@ -57,8 +58,9 @@ protected:
|
||||
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;
|
||||
bool out_stream_ready = false;
|
||||
int cur_sample_rate = -1;
|
||||
int out_sample_rate = -1;
|
||||
};
|
||||
|
||||
/** AWACs PDM-style sound codec. */
|
||||
@@ -70,24 +72,17 @@ public:
|
||||
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
|
||||
uint16_t ctrl_regs[5] = {}; // 12-bit wide control registers
|
||||
};
|
||||
|
||||
/** AWACs Screamer registers offsets. */
|
||||
/** Offsets to MacIO sound codec registers. */
|
||||
enum {
|
||||
AWAC_SOUND_CTRL_REG = 0x00,
|
||||
AWAC_CODEC_CTRL_REG = 0x10,
|
||||
AWAC_CODEC_STATUS_REG = 0x20,
|
||||
};
|
||||
|
||||
/** 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
|
||||
if the sound codec is available.
|
||||
@@ -107,7 +102,7 @@ public:
|
||||
|
||||
bool send_subaddress(uint8_t sub_addr) {
|
||||
if ((sub_addr & 0xF) > 6)
|
||||
return false; /* invalid subaddress -> no acknowledge */
|
||||
return false; // invalid subaddress -> no acknowledge
|
||||
|
||||
this->sub_addr = sub_addr & 0xF;
|
||||
this->auto_inc = !!(sub_addr & 0x10);
|
||||
@@ -128,7 +123,7 @@ public:
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false; /* invalid sub_addr -> no acknowledge */
|
||||
return false; // invalid sub_addr -> no acknowledge
|
||||
}
|
||||
};
|
||||
|
||||
@@ -139,33 +134,43 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
uint8_t regs[7]; /* control registers, see TDA7433 datasheet */
|
||||
uint8_t regs[7] = {}; // control registers, see TDA7433 datasheet
|
||||
uint8_t sub_addr;
|
||||
int pos;
|
||||
int auto_inc;
|
||||
};
|
||||
|
||||
/** AWACs Screamer sound codec. */
|
||||
class AwacsScreamer : public AwacsBase {
|
||||
/** Sound codec interface with the typical MacIO access. */
|
||||
class MacioSndCodec : public AwacsBase {
|
||||
public:
|
||||
AwacsScreamer();
|
||||
MacioSndCodec(std::string name) : AwacsBase(name) {};
|
||||
virtual uint32_t snd_ctrl_read(uint32_t offset, int size) = 0;
|
||||
virtual void snd_ctrl_write(uint32_t offset, uint32_t value, int size) = 0;
|
||||
};
|
||||
|
||||
/** AWACs Screamer manufacturer and revision. */
|
||||
#define AWAC_MAKER_CRYSTAL 1
|
||||
#define AWAC_REV_SCREAMER 3
|
||||
|
||||
/** Screamer sound codec. */
|
||||
class AwacsScreamer : public MacioSndCodec {
|
||||
public:
|
||||
AwacsScreamer(std::string name = "Screamer");
|
||||
~AwacsScreamer() = default;
|
||||
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void dma_start();
|
||||
void dma_end();
|
||||
int device_postinit();
|
||||
|
||||
protected:
|
||||
void open_stream(int sample_rate);
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AwacsScreamer>(new AwacsScreamer("Screamer"));
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t snd_ctrl_reg = { 0 };
|
||||
uint16_t control_regs[8] = { 0 }; /* control registers, each 12-bits wide */
|
||||
uint8_t is_busy = 0;
|
||||
|
||||
int out_sample_rate;
|
||||
uint32_t snd_ctrl_reg = 0;
|
||||
uint16_t control_regs[8] = {}; // control registers, each 12-bits wide
|
||||
uint8_t is_busy = 0;
|
||||
|
||||
std::unique_ptr<AudioProcessor> audio_proc;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** Burgundy sound codec emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/sound/burgundy.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
BurgundyCodec::BurgundyCodec(std::string name) : MacioSndCodec(name)
|
||||
{
|
||||
supports_types(HWCompType::SND_CODEC);
|
||||
|
||||
static int burgundy_sample_rates[1] = { 44100 };
|
||||
|
||||
// Burgundy seems to supports only one sample rate
|
||||
this->sr_table = burgundy_sample_rates;
|
||||
this->max_sr_id = 1;
|
||||
|
||||
this->set_sample_rate(0); // set default sample rate
|
||||
}
|
||||
|
||||
uint32_t BurgundyCodec::snd_ctrl_read(uint32_t offset, int size) {
|
||||
uint32_t result = 0;
|
||||
|
||||
switch (offset) {
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
result = this->last_ctrl_data;
|
||||
break;
|
||||
case AWAC_CODEC_STATUS_REG:
|
||||
result = (this->first_valid << 23) | BURGUNDY_READY |
|
||||
(this->byte_counter << 14) | (this->read_pos << 12) |
|
||||
(this->data_byte << 4);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: read from unsupported register 0x%X", this->name.c_str(),
|
||||
offset);
|
||||
}
|
||||
|
||||
return BYTESWAP_32(result);
|
||||
}
|
||||
|
||||
void BurgundyCodec::snd_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
uint8_t reg_addr, cur_byte, last_byte;
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
|
||||
switch (offset) {
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
this->last_ctrl_data = value;
|
||||
reg_addr = (value >> 12) & 0xFF;
|
||||
cur_byte = (value >> 8) & 3;
|
||||
last_byte = (value >> 10) & 3;
|
||||
if (value & BURGUNDY_REG_WR) {
|
||||
uint32_t mask = 0xFFU << (cur_byte * 8);
|
||||
this->reg_array[reg_addr] = (this->reg_array[reg_addr] & ~mask) |
|
||||
((value & 0xFFU) << (cur_byte * 8));
|
||||
} else {
|
||||
this->reg_addr = reg_addr;
|
||||
this->read_pos = cur_byte;
|
||||
this->data_byte = (this->reg_array[reg_addr] >> (cur_byte * 8)) & 0xFFU;
|
||||
this->first_valid = 1;
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(10), // not sure if this is the correct delay
|
||||
[this]() {
|
||||
this->first_valid = 0;
|
||||
this->byte_counter = (this->byte_counter + 1) & 3;
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: write to unsupported register 0x%X", this->name.c_str(),
|
||||
offset);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Burgundy_Descriptor = {
|
||||
BurgundyCodec::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(BurgundySnd, Burgundy_Descriptor);
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** Burgundy sound codec definitions. */
|
||||
|
||||
#ifndef BURGUNDY_H
|
||||
#define BURGUNDY_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
enum {
|
||||
BURGUNDY_REG_WR = 1 << 21,
|
||||
BURGUNDY_READY = 1 << 22,
|
||||
};
|
||||
|
||||
/** Number of internal registers implemented in Burgundy. */
|
||||
#define BURGUNDY_NUM_REGS 123
|
||||
|
||||
class BurgundyCodec : public MacioSndCodec {
|
||||
public:
|
||||
BurgundyCodec(std::string name);
|
||||
~BurgundyCodec() = default;
|
||||
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<BurgundyCodec>(new BurgundyCodec("Burgundy"));
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t last_ctrl_data = 0;
|
||||
uint8_t byte_counter = 0;
|
||||
uint8_t reg_addr = 0;
|
||||
uint8_t first_valid = 0;
|
||||
uint8_t read_pos = 0;
|
||||
uint8_t data_byte = 0;
|
||||
|
||||
uint32_t reg_array[BURGUNDY_NUM_REGS] = {};
|
||||
};
|
||||
|
||||
#endif // BURGUNDY_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -147,12 +147,12 @@ long sound_out_callback(cubeb_stream *stream, void *user_data,
|
||||
out_frames = 0;
|
||||
|
||||
while (req_frames > 0) {
|
||||
if (!dma_ch->pull_data(req_frames << 2, &got_len, &p_in)) {
|
||||
if (!dma_ch->pull_data((uint32_t)req_frames << 2, &got_len, &p_in)) {
|
||||
frames = got_len >> 2;
|
||||
|
||||
in_buf = (int16_t*)p_in;
|
||||
|
||||
for (int i = frames; i > 0; i--) {
|
||||
for (int i = (int)frames; i > 0; i--) {
|
||||
out_buf[0] = BYTESWAP_16(in_buf[0]);
|
||||
out_buf[1] = BYTESWAP_16(in_buf[1]);
|
||||
in_buf += 2;
|
||||
@@ -192,7 +192,7 @@ int SoundServer::open_out_stream(uint32_t sample_rate, void *user_data)
|
||||
LOG_F(ERROR, "Could not get minimum latency, error: %d", res);
|
||||
return -1;
|
||||
} else {
|
||||
LOG_F(INFO, "Minimum sound latency: %d frames", latency_frames);
|
||||
LOG_F(9, "Minimum sound latency: %d frames", latency_frames);
|
||||
}
|
||||
|
||||
res = cubeb_stream_init(this->cubeb_ctx, &this->out_stream, "SndOut stream",
|
||||
@@ -203,7 +203,7 @@ int SoundServer::open_out_stream(uint32_t sample_rate, void *user_data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Sound output stream opened.");
|
||||
LOG_F(9, "Sound output stream opened.");
|
||||
|
||||
this->status = SND_STREAM_OPENED;
|
||||
|
||||
@@ -219,5 +219,5 @@ void SoundServer::close_out_stream()
|
||||
{
|
||||
cubeb_stream_stop(this->out_stream);
|
||||
cubeb_stream_destroy(this->out_stream);
|
||||
LOG_F(INFO, "Sound output stream closed.");
|
||||
LOG_F(9, "Sound output stream closed.");
|
||||
}
|
||||
+142
-138
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,150 +31,154 @@ enum {
|
||||
|
||||
/** Mach64 register offsets. */
|
||||
enum {
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_VLINE_CRNT_VLINE = 0x0010,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CONFIG_STAT1 = 0x0094,
|
||||
ATI_CONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_MEM_VGA_WP_SEL = 0x00B4,
|
||||
ATI_MEM_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x000, // 0x0000
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x001, // 0x0004
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x002, // 0x0008
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x003, // 0x000C
|
||||
ATI_CRTC_VLINE_CRNT_VLINE = 0x004, // 0x0010
|
||||
ATI_CRTC_OFF_PITCH = 0x005, // 0x0014
|
||||
ATI_CRTC_INT_CNTL = 0x006, // 0x0018
|
||||
ATI_CRTC_GEN_CNTL = 0x007, // 0x001C
|
||||
ATI_DSP_CONFIG = 0x008, // 0x0020
|
||||
ATI_DSP_ON_OFF = 0x009, // 0x0024
|
||||
ATI_TIMER_CFG = 0x00A, // 0x0028
|
||||
ATI_MEM_BUF_CNTL = 0x00B, // 0x002C
|
||||
ATI_MEM_ADDR_CFG = 0x00D, // 0x0034
|
||||
ATI_CRT_TRAP = 0x00E, // 0x0038
|
||||
ATI_I2C_CNTL_0 = 0x00F, // 0x003C
|
||||
ATI_OVR_CLR = 0x010, // 0x0040
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x011, // 0x0044
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x012, // 0x0048
|
||||
ATI_VGA_DSP_CFG = 0x013, // 0x004C
|
||||
ATI_VGA_DSP_ON_OFF = 0x014, // 0x0050
|
||||
ATI_DSP2_CONFIG = 0x015, // 0x0054 <-- LT specific
|
||||
ATI_DSP2_ON_OFF = 0x016, // 0x0058 <-- LT specific
|
||||
ATI_CRTC2_OFF_PITCH = 0x017, // 0x005C <-- LT specific
|
||||
ATI_CUR_CLR0 = 0x018, // 0x0060
|
||||
ATI_CUR_CLR1 = 0x019, // 0x0064
|
||||
ATI_CUR_OFFSET = 0x01A, // 0x0068
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x01B, // 0x006C
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x01C, // 0x0070
|
||||
ATI_GP_IO = 0x01E, // 0x0078
|
||||
ATI_HW_DEBUG = 0x01F, // 0x007C
|
||||
ATI_SCRATCH_REG0 = 0x020, // 0x0080
|
||||
ATI_SCRATCH_REG1 = 0x021, // 0x0084
|
||||
ATI_SCRATCH_REG2 = 0x022, // 0x0088
|
||||
ATI_SCRATCH_REG3 = 0x023, // 0x008C
|
||||
ATI_CLOCK_CNTL = 0x024, // 0x0090
|
||||
ATI_CONFIG_STAT1 = 0x025, // 0x0094
|
||||
ATI_CONFIG_STAT2 = 0x026, // 0x0098
|
||||
ATI_BUS_CNTL = 0x028, // 0x00A0
|
||||
ATI_EXT_MEM_CNTL = 0x02B, // 0x00AC
|
||||
ATI_MEM_CNTL = 0x02C, // 0x00B0
|
||||
ATI_MEM_VGA_WP_SEL = 0x02D, // 0x00B4
|
||||
ATI_MEM_VGA_RP_SEL = 0x02E, // 0x00B8
|
||||
ATI_I2C_CNTL_1 = 0x02F, // 0x00BC
|
||||
ATI_DAC_REGS = 0x030, // 0x00C0
|
||||
|
||||
// byte offsets for the built-in DAC registers
|
||||
ATI_DAC_W_INDEX = 0x00C0,
|
||||
ATI_DAC_DATA = 0x00C1,
|
||||
ATI_DAC_MASK = 0x00C2,
|
||||
ATI_DAC_R_INDEX = 0x00C3,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CONFIG_CHIP_ID = 0x00E0,
|
||||
ATI_CONFIG_STAT0 = 0x00E4,
|
||||
ATI_GX_CONFIG_STAT1 = 0x00E8, // GX only
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_Y_X_ALIAS1 = 0x00F4,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_DST_X = 0x0104,
|
||||
ATI_DST_Y = 0x0108,
|
||||
ATI_DST_Y_X = 0x010C,
|
||||
ATI_DST_WIDTH = 0x0110,
|
||||
ATI_DST_HEIGHT = 0x0114,
|
||||
ATI_DST_HEIGHT_WIDTH = 0x0118,
|
||||
ATI_DST_X_WIDTH = 0x011C,
|
||||
ATI_DST_BRES_LNTH = 0x0120,
|
||||
ATI_DST_BRES_ERR = 0x0124,
|
||||
ATI_DST_BRES_INC = 0x0128,
|
||||
ATI_DST_BRES_DEC = 0x012C,
|
||||
ATI_DST_CNTL = 0x0130,
|
||||
ATI_DST_Y_X_ALIAS2 = 0x0134,
|
||||
ATI_TRAIL_BRES_ERR = 0x0138,
|
||||
ATI_TRAIL_BRES_INC = 0x013C,
|
||||
ATI_TRAIL_BRES_DEC = 0x0140,
|
||||
ATI_DST_BRES_LNTH_ALIAS1 = 0x0144,
|
||||
ATI_Z_OFF_PITCH = 0x0148,
|
||||
ATI_Z_CNTL = 0x014C,
|
||||
ATI_ALPHA_TST_CNTL = 0x0150,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_SRC_X = 0x0184,
|
||||
ATI_SRC_Y = 0x0188,
|
||||
ATI_SRC_Y_X = 0x018C,
|
||||
ATI_SRC_WIDTH1 = 0x0190,
|
||||
ATI_SRC_HEIGHT1 = 0x0194,
|
||||
ATI_SRC_HEIGHT1_WIDTH1 = 0x0198,
|
||||
ATI_SRC_X_START = 0x019C,
|
||||
ATI_SRC_Y_START = 0x01A0,
|
||||
ATI_SRC_Y_X_START = 0x01A4,
|
||||
ATI_SRC_WIDTH2 = 0x01A8,
|
||||
ATI_SRC_HEIGHT2 = 0x01AC,
|
||||
ATI_SRC_HEIGHT2_WIDTH2 = 0x01B0,
|
||||
ATI_SRC_CNTL = 0x01B4,
|
||||
ATI_SCALE_OFF = 0x01C0,
|
||||
ATI_SCALE_WIDTH = 0x01DC,
|
||||
ATI_SCALE_HEIGHT = 0x01E0,
|
||||
ATI_SCALE_PITCH = 0x01EC,
|
||||
ATI_SCALE_X_INC = 0x01F0,
|
||||
ATI_SCALE_Y_INC = 0x01F4,
|
||||
ATI_SCALE_VACC = 0x01F8,
|
||||
ATI_SCALE_3D_CNTL = 0x01FC,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_PAT_REG0 = 0x0280,
|
||||
ATI_PAT_REG1 = 0x0284,
|
||||
ATI_PAT_CNTL = 0x0288,
|
||||
ATI_SC_LEFT = 0x02A0,
|
||||
ATI_SC_RIGHT = 0x02A4,
|
||||
ATI_SC_LEFT_RIGHT = 0x02A8,
|
||||
ATI_SC_TOP = 0x02AC,
|
||||
ATI_SC_BOTTOM = 0x02B0,
|
||||
ATI_SC_TOP_BOTTOM = 0x02B4,
|
||||
ATI_DP_BKGD_CLR = 0x02C0,
|
||||
ATI_DP_FOG_CLR = 0x02C0,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DP_MIX = 0x02D4,
|
||||
ATI_DP_SRC = 0x02D8,
|
||||
ATI_FRGD_CLR_MIX = 0x02DC,
|
||||
ATI_FRGD_BKGD_CLR = 0x02E0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_USR_DST_PITCH = 0x02F0,
|
||||
ATI_DP_SET_GUI_ENGINE2 = 0x02F4,
|
||||
ATI_DP_SET_GUI_ENGINE = 0x02F8,
|
||||
ATI_CLR_CMP_CLR = 0x0300,
|
||||
ATI_CLR_CMP_MSK = 0x0304,
|
||||
ATI_CLR_CMP_CNTL = 0x0308,
|
||||
ATI_FIFO_STAT = 0x0310,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_GUI_TRAJ_CNTL = 0x0330,
|
||||
ATI_GUI_STAT = 0x0338,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
ATI_SETUP_CNTL = 0x0704,
|
||||
|
||||
ATI_DAC_CNTL = 0x031, // 0x00C4
|
||||
ATI_GEN_TEST_CNTL = 0x034, // 0x00D0
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x035, // 0x00D4
|
||||
ATI_CONFIG_CNTL = 0x037, // 0x00DC
|
||||
ATI_CONFIG_CHIP_ID = 0x038, // 0x00E0
|
||||
ATI_CONFIG_STAT0 = 0x039, // 0x00E4
|
||||
ATI_GX_CONFIG_STAT1 = 0x03A, // 0x00E8 <-- GX/CT specific
|
||||
ATI_CRC_SIG = 0x03A, // 0x00E8
|
||||
|
||||
ATI_DST_OFF_PITCH = 0x040, // 0x0100
|
||||
ATI_DST_X = 0x041, // 0x0104
|
||||
ATI_DST_Y = 0x042, // 0x0108
|
||||
ATI_DST_Y_X = 0x043, // 0x010C
|
||||
ATI_DST_WIDTH = 0x044, // 0x0110
|
||||
ATI_DST_HEIGHT = 0x045, // 0x0114
|
||||
ATI_DST_HEIGHT_WIDTH = 0x046, // 0x0118
|
||||
ATI_DST_X_WIDTH = 0x047, // 0x011C
|
||||
ATI_DST_BRES_LNTH = 0x048, // 0x0120
|
||||
ATI_DST_BRES_ERR = 0x049, // 0x0124
|
||||
ATI_DST_BRES_INC = 0x04A, // 0x0128
|
||||
ATI_DST_BRES_DEC = 0x04B, // 0x012C
|
||||
ATI_DST_CNTL = 0x04C, // 0x0130
|
||||
ATI_DST_Y_X_ALIAS1 = 0x04D, // 0x0134
|
||||
ATI_TRAIL_BRES_ERR = 0x04E, // 0x0138
|
||||
ATI_TRAIL_BRES_INC = 0x04F, // 0x013C
|
||||
ATI_TRAIL_BRES_DEC = 0x050, // 0x0140
|
||||
ATI_DST_BRES_LNTH_ALIAS1 = 0x051, // 0x0144
|
||||
ATI_Z_OFF_PITCH = 0x052, // 0x0148
|
||||
ATI_Z_CNTL = 0x053, // 0x014C
|
||||
ATI_ALPHA_TST_CNTL = 0x054, // 0x0150
|
||||
ATI_SRC_OFF_PITCH = 0x060, // 0x0180
|
||||
ATI_SRC_X = 0x061, // 0x0184
|
||||
ATI_SRC_Y = 0x062, // 0x0188
|
||||
ATI_SRC_Y_X = 0x063, // 0x018C
|
||||
ATI_SRC_WIDTH1 = 0x064, // 0x0190
|
||||
ATI_SRC_HEIGHT1 = 0x065, // 0x0194
|
||||
ATI_SRC_HEIGHT1_WIDTH1 = 0x066, // 0x0198
|
||||
ATI_SRC_X_START = 0x067, // 0x019C
|
||||
ATI_SRC_Y_START = 0x068, // 0x01A0
|
||||
ATI_SRC_Y_X_START = 0x069, // 0x01A4
|
||||
ATI_SRC_WIDTH2 = 0x06A, // 0x01A8
|
||||
ATI_SRC_HEIGHT2 = 0x06B, // 0x01AC
|
||||
ATI_SRC_HEIGHT2_WIDTH2 = 0x06C, // 0x01B0
|
||||
ATI_SRC_CNTL = 0x06D, // 0x01B4
|
||||
ATI_SCALE_OFF = 0x070, // 0x01C0
|
||||
ATI_SCALE_WIDTH = 0x077, // 0x01DC
|
||||
ATI_SCALE_HEIGHT = 0x078, // 0x01E0
|
||||
ATI_SCALE_PITCH = 0x07B, // 0x01EC
|
||||
ATI_SCALE_X_INC = 0x07C, // 0x01F0
|
||||
ATI_SCALE_Y_INC = 0x07D, // 0x01F4
|
||||
ATI_SCALE_VACC = 0x07E, // 0x01F8
|
||||
ATI_SCALE_3D_CNTL = 0x07F, // 0x01FC
|
||||
ATI_HOST_CNTL = 0x090, // 0x0240
|
||||
ATI_PAT_REG0 = 0x0A0, // 0x0280
|
||||
ATI_PAT_REG1 = 0x0A1, // 0x0284
|
||||
ATI_PAT_CNTL = 0x0A2, // 0x0288
|
||||
ATI_SC_LEFT = 0x0A8, // 0x02A0
|
||||
ATI_SC_RIGHT = 0x0A9, // 0x02A4
|
||||
ATI_SC_LEFT_RIGHT = 0x0AA, // 0x02A8
|
||||
ATI_SC_TOP = 0x0AB, // 0x02AC
|
||||
ATI_SC_BOTTOM = 0x0AC, // 0x02B0
|
||||
ATI_SC_TOP_BOTTOM = 0x0AD, // 0x02B4
|
||||
ATI_DP_BKGD_CLR = 0x0B0, // 0x02C0
|
||||
ATI_DP_FRGD_CLR = 0x0B1, // 0x02C4
|
||||
ATI_DP_FOG_CLR = 0x0B1, // 0x02C4
|
||||
ATI_DP_WRITE_MSK = 0x0B2, // 0x02C8
|
||||
ATI_DP_PIX_WIDTH = 0x0B4, // 0x02D0
|
||||
ATI_DP_MIX = 0x0B5, // 0x02D4
|
||||
ATI_DP_SRC = 0x0B6, // 0x02D8
|
||||
ATI_DP_FRGD_CLR_MIX = 0x0B7, // 0x02DC
|
||||
ATI_DP_FRGD_BKGD_CLR = 0x0B8, // 0x02E0
|
||||
ATI_DST_X_Y = 0x0BA, // 0x02E8
|
||||
ATI_DST_WIDTH_HEIGHT = 0x0BB, // 0x02EC
|
||||
ATI_USR_DST_PITCH = 0x0BC, // 0x02F0
|
||||
ATI_DP_SET_GUI_ENGINE2 = 0x0BE, // 0x02F8
|
||||
ATI_DP_SET_GUI_ENGINE = 0x0BF, // 0x02FC
|
||||
ATI_CLR_CMP_CLR = 0x0C0, // 0x0300
|
||||
ATI_CLR_CMP_MSK = 0x0C1, // 0x0304
|
||||
ATI_CLR_CMP_CNTL = 0x0C2, // 0x0308
|
||||
ATI_FIFO_STAT = 0x0C4, // 0x0310
|
||||
ATI_CONTEXT_MASK = 0x0C8, // 0x0320 <-- 264VT specific
|
||||
ATI_GUI_TRAJ_CNTL = 0x0CC, // 0x0330
|
||||
ATI_GUI_STAT = 0x0CE, // 0x0338
|
||||
ATI_MPP_CONFIG = 0x130, // 0x04C0
|
||||
ATI_MPP_STROBE_SEQ = 0x131, // 0x04C4
|
||||
ATI_MPP_ADDR = 0x132, // 0x04C8
|
||||
ATI_MPP_DATA = 0x133, // 0x04CC
|
||||
ATI_TVO_CNTL = 0x140, // 0x0500
|
||||
ATI_SETUP_CNTL = 0x1C1, // 0x0704
|
||||
ATI_INVALID = 0xFFFF
|
||||
};
|
||||
|
||||
constexpr auto APERTURE_SIZE = 0x01000000UL; /* Mach64 aperture size */
|
||||
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 MM_REGS_2_OFF = 0x003FFC00UL; /* offset to memory mapped registers, 4MB aperture */
|
||||
constexpr auto BE_FB_OFFSET = 0x00800000UL; /* Offset to the big-endian frame buffer */
|
||||
constexpr auto APERTURE_SIZE = 0x01000000UL; // Mach64 aperture size
|
||||
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 MM_REGS_2_OFF = 0x003FFC00UL; // offset to memory mapped registers, 4MB aperture
|
||||
constexpr auto BE_FB_OFFSET = 0x00800000UL; // Offset to the big-endian frame buffer
|
||||
|
||||
constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,9 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** ATI Mach64 GX emulation.
|
||||
It emulates an ATI88800GX controller with an IBM RGB514 style RAMDAC.
|
||||
Emulation is limited to a basic framebuffer for now.
|
||||
Emulation is limited to a basic frame buffer for now.
|
||||
*/
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/video/atimach64defs.h>
|
||||
@@ -40,11 +41,12 @@ AtiMach64Gx::AtiMach64Gx()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV);
|
||||
|
||||
/* set up PCI configuration space header */
|
||||
// set up PCI configuration space header
|
||||
this->vendor_id = PCI_VENDOR_ATI;
|
||||
this->device_id = ATI_MACH64_GX_DEV_ID;
|
||||
this->class_rev = (0x030000 << 8) | 3;
|
||||
this->bars_cfg[0] = 0xFF000000UL; // declare main aperture (16MB)
|
||||
|
||||
this->setup_bars({{0, 0xFF000000UL}}); // declare main aperture (16MB)
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
@@ -52,7 +54,8 @@ AtiMach64Gx::AtiMach64Gx()
|
||||
|
||||
// declare expansion ROM containing FCode and Mac OS drivers
|
||||
if (this->attach_exp_rom_image(std::string("113-32900-004_Apple_MACH64.bin"))) {
|
||||
LOG_F(WARNING, "AtiMach64Gx: could not load ROM - this device won't work properly!");
|
||||
ABORT_F("%s: could not load ROM - this device won't work properly!",
|
||||
this->name.c_str());
|
||||
}
|
||||
|
||||
// initialize display identification
|
||||
@@ -61,6 +64,9 @@ AtiMach64Gx::AtiMach64Gx()
|
||||
// allocate video RAM
|
||||
this->vram_size = 2 << 20;
|
||||
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
|
||||
|
||||
// set up RAMDAC identification
|
||||
this->regs[ATI_CONFIG_STAT0] = 1 << 9;
|
||||
}
|
||||
|
||||
void AtiMach64Gx::notify_bar_change(int bar_num)
|
||||
@@ -102,7 +108,7 @@ static const uint32_t io_idx_to_reg_offset[32] = {
|
||||
ATI_DAC_CNTL, ATI_GEN_TEST_CNTL,
|
||||
ATI_CONFIG_CNTL, ATI_CONFIG_CHIP_ID,
|
||||
ATI_CONFIG_STAT0, ATI_GX_CONFIG_STAT1,
|
||||
ATI_INVALID, ATI_INVALID
|
||||
ATI_INVALID, ATI_CRTC_H_TOTAL_DISP
|
||||
};
|
||||
|
||||
bool AtiMach64Gx::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
@@ -115,13 +121,13 @@ bool AtiMach64Gx::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
}
|
||||
|
||||
// convert ISA-style I/O address to MMIO register offset
|
||||
offset = io_idx_to_reg_offset[(offset >> 10) & 0x1F] + (offset & 3);
|
||||
offset = io_idx_to_reg_offset[(offset >> 10) & 0x1F] * 4 + (offset & 3);
|
||||
|
||||
// CONFIG_CNTL is accessible from I/O space only
|
||||
if ((offset & ~3) == ATI_CONFIG_CNTL) {
|
||||
if ((offset >> 2) == ATI_CONFIG_CNTL) {
|
||||
*res = read_mem(((uint8_t *)&this->config_cntl) + (offset & 3), size);
|
||||
} else {
|
||||
*res = this->read_reg(offset, size);
|
||||
*res = BYTESWAP_SIZED(this->read_reg(offset, size), size);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -135,75 +141,109 @@ bool AtiMach64Gx::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
}
|
||||
|
||||
// convert ISA-style I/O address to MMIO register offset
|
||||
offset = io_idx_to_reg_offset[(offset >> 10) & 0x1F] + (offset & 3);
|
||||
offset = io_idx_to_reg_offset[(offset >> 10) & 0x1F] * 4 + (offset & 3);
|
||||
|
||||
// CONFIG_CNTL is accessible from I/O space only
|
||||
if ((offset & ~3) == ATI_CONFIG_CNTL) {
|
||||
if ((offset >> 2) == ATI_CONFIG_CNTL) {
|
||||
write_mem(((uint8_t *)&this->config_cntl) + (offset & 3), value, size);
|
||||
switch (this->config_cntl & 3) {
|
||||
case 0:
|
||||
LOG_F(WARNING, "AtiMach64Gx: linear aperture disabled!");
|
||||
LOG_F(WARNING, "%s: linear aperture disabled!", this->name.c_str());
|
||||
break;
|
||||
case 1:
|
||||
LOG_F(INFO, "AtiMach64Gx: aperture size set to 4MB");
|
||||
LOG_F(INFO, "%s: aperture size set to 4MB", this->name.c_str());
|
||||
this->mm_regs_offset = MM_REGS_2_OFF;
|
||||
break;
|
||||
case 2:
|
||||
LOG_F(INFO, "AtiMach64Gx: aperture size set to 8MB");
|
||||
LOG_F(INFO, "%s: aperture size set to 8MB", this->name.c_str());
|
||||
this->mm_regs_offset = MM_REGS_0_OFF;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AtiMach64Gx: invalid aperture size in CONFIG_CNTL");
|
||||
LOG_F(ERROR, "%s: invalid aperture size in CONFIG_CNTL", this->name.c_str());
|
||||
}
|
||||
} else {
|
||||
this->write_reg(offset, value, size);
|
||||
this->write_reg(offset, BYTESWAP_SIZED(value, size), size);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t AtiMach64Gx::read_reg(uint32_t offset, uint32_t size)
|
||||
uint32_t AtiMach64Gx::read_reg(uint32_t reg_offset, uint32_t size)
|
||||
{
|
||||
LOG_F(INFO, "AtiMach64Gx: read from I/O mapped reg at 0x%X", offset);
|
||||
uint32_t offset = reg_offset & 3;
|
||||
|
||||
return read_mem(&this->mm_regs[offset], size);
|
||||
uint64_t result = this->regs[reg_offset >> 2];
|
||||
|
||||
if (!offset && size == 4) { // fast path
|
||||
return result;
|
||||
} else { // slow path
|
||||
if ((offset + size) > 4) {
|
||||
result |= (uint64_t)(this->regs[(reg_offset >> 2) + 1]) << 32;
|
||||
}
|
||||
return extract_bits<uint64_t>(result, offset * 8, size * 8);
|
||||
}
|
||||
}
|
||||
|
||||
void AtiMach64Gx::write_reg(uint32_t offset, uint32_t value, uint32_t size)
|
||||
void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint8_t gpio_dirs, gpio_levels;
|
||||
int crtc_en;
|
||||
|
||||
// write value to internal registers with endian conversion
|
||||
write_mem(&this->mm_regs[offset], value, size);
|
||||
uint32_t offset = reg_offset & 3;
|
||||
reg_offset >>= 2;
|
||||
|
||||
switch (offset & ~3) {
|
||||
if (offset || size != 4) { // slow path
|
||||
if ((offset + size) > 4) {
|
||||
ABORT_F("%s: unaligned DWORD writes not implemented", this->name.c_str());
|
||||
}
|
||||
uint64_t old_val = this->regs[reg_offset];
|
||||
insert_bits<uint64_t>(old_val, value, offset * 8, size * 8);
|
||||
value = old_val;
|
||||
}
|
||||
|
||||
switch (reg_offset) {
|
||||
case ATI_CRTC_OFF_PITCH:
|
||||
this->fb_pitch = extract_bits<uint32_t>(value, 22, 10) * 8;
|
||||
this->fb_ptr = &this->vram_ptr[extract_bits<uint32_t>(value, 0, 20) * 8];
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
crtc_en = (this->mm_regs[ATI_CRTC_GEN_CNTL+3] >> 1) & 1;
|
||||
if (crtc_en != this->crtc_enable) {
|
||||
if (!crtc_en) {
|
||||
if (bit_changed(this->regs[reg_offset], value, 6)) {
|
||||
if (value & 0x40) {
|
||||
this->blank_on = true;
|
||||
this->blank_display();
|
||||
} else {
|
||||
this->blank_on = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bit_changed(this->regs[reg_offset], value, 25)) {
|
||||
if (!bit_set(value, 25)) {
|
||||
this->disable_crtc_internal();
|
||||
} else {
|
||||
this->blank_on = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
if (size == 1) { // only byte accesses are allowed for DAC registers
|
||||
int dac_reg_addr = ((this->mm_regs[ATI_DAC_CNTL] & 1) << 2) | (offset & 3);
|
||||
rgb514_write_reg(dac_reg_addr, value);
|
||||
int dac_reg_addr = ((this->regs[ATI_DAC_CNTL] & 1) << 2) | offset;
|
||||
rgb514_write_reg(dac_reg_addr, extract_bits<uint32_t>(value, offset * 8, 8));
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_CNTL:
|
||||
// monitor ID is usually accessed using 8bit writes
|
||||
if ((offset & 3) == 3) {
|
||||
gpio_dirs = (value >> 3) & 7;
|
||||
gpio_levels = value & 7;
|
||||
if (offset == 3) {
|
||||
gpio_dirs = extract_bits<uint32_t>(value, 27, 3);
|
||||
gpio_levels = extract_bits<uint32_t>(value, 24, 3);
|
||||
gpio_levels = this->disp_id->read_monitor_sense(gpio_levels, gpio_dirs);
|
||||
this->mm_regs[ATI_DAC_CNTL+3] = (this->mm_regs[ATI_DAC_CNTL+3] & 0xF8U) | gpio_levels;
|
||||
insert_bits<uint32_t>(value, gpio_levels, 24, 3);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "AtiMach64Gx: write 0x%X to I/O mapped reg at 0x%X", value, offset);
|
||||
case ATI_CONFIG_STAT0:
|
||||
return; // prevent writes to this read-only register
|
||||
}
|
||||
|
||||
this->regs[reg_offset] = value;
|
||||
}
|
||||
|
||||
uint32_t AtiMach64Gx::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
@@ -212,7 +252,7 @@ uint32_t AtiMach64Gx::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
if (offset < this->vram_size) {
|
||||
return read_mem(&this->vram_ptr[offset], size);
|
||||
} else if (offset >= this->mm_regs_offset) {
|
||||
return read_reg(offset - this->mm_regs_offset, size);
|
||||
return BYTESWAP_SIZED(read_reg(offset - this->mm_regs_offset, size), size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,33 +270,31 @@ void AtiMach64Gx::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
|
||||
if (offset < this->vram_size) {
|
||||
write_mem(&this->vram_ptr[offset], value, size);
|
||||
} else if (offset >= this->mm_regs_offset) {
|
||||
write_reg(offset - this->mm_regs_offset, value, size);
|
||||
write_reg(offset - this->mm_regs_offset, BYTESWAP_SIZED(value, size), size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AtiMach64Gx::enable_crtc_internal()
|
||||
{
|
||||
int new_width = (this->mm_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
|
||||
uint32_t new_width, new_height;
|
||||
|
||||
int new_height = (READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
|
||||
// check for unsupported modes and fail early
|
||||
if (!bit_set(this->regs[ATI_CRTC_GEN_CNTL], 24))
|
||||
ABORT_F("%s: VGA not supported", this->name.c_str());
|
||||
|
||||
new_width = (extract_bits<uint32_t>(this->regs[ATI_CRTC_H_TOTAL_DISP], 16, 8) + 1) * 8;
|
||||
new_height = extract_bits<uint32_t>(this->regs[ATI_CRTC_V_TOTAL_DISP], 16, 11) + 1;
|
||||
|
||||
if (new_width != this->active_width || new_height != this->active_height) {
|
||||
LOG_F(WARNING, "AtiMach64Gx: display window resizing not implemented yet!");
|
||||
this->create_display_window(new_width, new_height);
|
||||
}
|
||||
|
||||
/* calculate display refresh rate */
|
||||
int hori_total = (this->mm_regs[ATI_CRTC_H_TOTAL_DISP] + 1) * 8;
|
||||
// calculate display refresh rate
|
||||
this->hori_total = (extract_bits<uint32_t>(this->regs[ATI_CRTC_H_TOTAL_DISP], 0, 9) + 1) * 8;
|
||||
this->vert_total = extract_bits<uint32_t>(this->regs[ATI_CRTC_V_TOTAL_DISP], 0, 11) + 1;
|
||||
|
||||
int vert_total = (READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
|
||||
|
||||
this->refresh_rate = this->pixel_clock / hori_total / vert_total;
|
||||
|
||||
int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFFFU) * 8;
|
||||
|
||||
this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8U;
|
||||
|
||||
this->fb_ptr = &this->vram_ptr[src_offset];
|
||||
this->refresh_rate = this->pixel_clock / this->hori_total / this->vert_total;
|
||||
|
||||
// specify framebuffer converter
|
||||
switch (this->pixel_depth) {
|
||||
@@ -266,19 +304,21 @@ void AtiMach64Gx::enable_crtc_internal()
|
||||
};
|
||||
break;
|
||||
default:
|
||||
ABORT_F("AtiMach64Gx: unsupported pixel depth %d", this->pixel_depth);
|
||||
ABORT_F("%s: unsupported pixel depth %d", this->name.c_str(), this->pixel_depth);
|
||||
}
|
||||
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
this->update_screen();
|
||||
|
||||
this->crtc_on = true;
|
||||
|
||||
this->crtc_enable = 1;
|
||||
@@ -286,6 +326,8 @@ void AtiMach64Gx::enable_crtc_internal()
|
||||
|
||||
void AtiMach64Gx::disable_crtc_internal()
|
||||
{
|
||||
this->blank_on = true;
|
||||
this->blank_display();
|
||||
this->crtc_enable = 0;
|
||||
}
|
||||
|
||||
@@ -299,11 +341,8 @@ void AtiMach64Gx::rgb514_write_reg(uint8_t reg_addr, uint8_t value)
|
||||
case Rgb514::CLUT_DATA:
|
||||
this->clut_color[this->comp_index++] = value;
|
||||
if (this->comp_index >= 3) {
|
||||
// TODO: combine separate components into a single ARGB value
|
||||
this->palette[this->clut_index][0] = this->clut_color[0];
|
||||
this->palette[this->clut_index][1] = this->clut_color[1];
|
||||
this->palette[this->clut_index][2] = this->clut_color[2];
|
||||
this->palette[this->clut_index][3] = 255;
|
||||
this->set_palette_color(this->clut_index, clut_color[0],
|
||||
clut_color[1], clut_color[2], 0xFF);
|
||||
this->clut_index++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
@@ -323,14 +362,12 @@ void AtiMach64Gx::rgb514_write_reg(uint8_t reg_addr, uint8_t value)
|
||||
this->rgb514_write_ind_reg((this->dac_idx_hi << 8) + this->dac_idx_lo, value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "RGB514: access to unimplemented register at 0x%X", reg_addr);
|
||||
ABORT_F("RGB514: access to unimplemented register at 0x%X", reg_addr);
|
||||
}
|
||||
}
|
||||
|
||||
void AtiMach64Gx::rgb514_write_ind_reg(uint8_t reg_addr, uint8_t value)
|
||||
{
|
||||
LOG_F(INFO, "RGB514: write 0x%X to register 0x%X", value, reg_addr);
|
||||
|
||||
this->dac_regs[reg_addr] = value;
|
||||
|
||||
switch (reg_addr) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -41,23 +41,23 @@ public:
|
||||
return std::unique_ptr<AtiMach64Gx>(new AtiMach64Gx());
|
||||
}
|
||||
|
||||
/* PCI device methods */
|
||||
// PCI device methods
|
||||
bool supports_io_space(void) {
|
||||
return true;
|
||||
};
|
||||
|
||||
/* I/O space access methods */
|
||||
// I/O space access methods
|
||||
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
/* MMIODevice methods */
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
uint32_t read_reg(uint32_t reg_offset, uint32_t size);
|
||||
void write_reg(uint32_t reg_offset, uint32_t value, uint32_t size);
|
||||
void enable_crtc_internal();
|
||||
void disable_crtc_internal();
|
||||
|
||||
@@ -65,7 +65,7 @@ protected:
|
||||
void rgb514_write_ind_reg(uint8_t reg_addr, uint8_t value);
|
||||
|
||||
private:
|
||||
uint8_t mm_regs[2048] = { 0 }; // internal registers
|
||||
uint32_t regs[256] = {}; // internal registers
|
||||
|
||||
int vram_size;
|
||||
uint32_t aperture_base;
|
||||
@@ -85,4 +85,4 @@ private:
|
||||
std::unique_ptr<uint8_t[]> vram_ptr;
|
||||
};
|
||||
|
||||
#endif /* ATI_MACH64_GX_H */
|
||||
#endif // ATI_MACH64_GX_H
|
||||
+269
-236
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
@@ -89,9 +90,8 @@ static const std::map<uint16_t, std::string> mach64_reg_names = {
|
||||
{0x0704, "SETUP_CNTL"},
|
||||
};
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id)
|
||||
: PCIDevice("ati-rage"), VideoCtrlBase(1024, 768)
|
||||
: PCIDevice("ati-rage"), VideoCtrlBase(640, 480)
|
||||
{
|
||||
uint8_t asic_id;
|
||||
|
||||
@@ -99,11 +99,11 @@ ATIRage::ATIRage(uint16_t dev_id)
|
||||
|
||||
this->vram_size = GET_INT_PROP("gfxmem_size") << 20; // convert MBs to bytes
|
||||
|
||||
/* allocate video RAM */
|
||||
// allocate video RAM
|
||||
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
|
||||
|
||||
/* ATI Rage driver needs to know ASIC ID (manufacturer's internal chip code)
|
||||
to operate properly */
|
||||
// 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
|
||||
@@ -116,7 +116,7 @@ ATIRage::ATIRage(uint16_t dev_id)
|
||||
LOG_F(WARNING, "ATI Rage: bogus ASIC ID assigned!");
|
||||
}
|
||||
|
||||
/* set up PCI configuration space header */
|
||||
// set up PCI configuration space header
|
||||
this->vendor_id = PCI_VENDOR_ATI;
|
||||
this->device_id = dev_id;
|
||||
this->subsys_vndr = PCI_VENDOR_ATI;
|
||||
@@ -124,20 +124,26 @@ ATIRage::ATIRage(uint16_t dev_id)
|
||||
this->class_rev = (0x030000 << 8) | asic_id;
|
||||
this->min_gnt = 8;
|
||||
this->irq_pin = 1;
|
||||
this->bars_cfg[0] = 0xFF000000UL; // declare main aperture (16MB)
|
||||
this->bars_cfg[1] = 0xFFFFFF01UL; // declare I/O region (256 bytes)
|
||||
this->bars_cfg[2] = 0xFFFFF000UL; // declare register aperture (4KB)
|
||||
|
||||
this->setup_bars({
|
||||
{0, 0xFF000000UL}, // declare main aperture (16MB)
|
||||
{1, 0xFFFFFF01UL}, // declare I/O region (256 bytes)
|
||||
{2, 0xFFFFF000UL} // declare register aperture (4KB)
|
||||
});
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
/* stuff default values into chip registers */
|
||||
WRITE_DWORD_LE_A(&this->mm_regs[ATI_CONFIG_CHIP_ID],
|
||||
(asic_id << 24) | dev_id);
|
||||
// stuff default values into chip registers
|
||||
this->regs[ATI_CONFIG_CHIP_ID] = (asic_id << 24) | dev_id;
|
||||
|
||||
/* initialize display identification */
|
||||
// initialize display identification
|
||||
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
|
||||
uint8_t mon_code = this->disp_id->read_monitor_sense(0, 0);
|
||||
|
||||
this->regs[ATI_GP_IO] = ((mon_code & 6) << 11) | ((mon_code & 1) << 8);
|
||||
}
|
||||
|
||||
void ATIRage::notify_bar_change(int bar_num)
|
||||
@@ -161,34 +167,35 @@ void ATIRage::notify_bar_change(int bar_num)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, size);
|
||||
return PCIDevice::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case 0x40:
|
||||
return this->user_cfg;
|
||||
default:
|
||||
LOG_F(WARNING, "ATIRage: reading from unimplemented config register at 0x%X", reg_offs);
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
switch (reg_offs) {
|
||||
case 0x40:
|
||||
this->user_cfg = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ATIRage: writing to unimplemented config register at 0x%X", reg_offs);
|
||||
}
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, details);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case 0x40:
|
||||
this->user_cfg = value;
|
||||
break;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,160 +208,183 @@ const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
uint32_t res;
|
||||
uint32_t ATIRage::read_reg(uint32_t reg_offset, uint32_t size) {
|
||||
uint64_t result;
|
||||
uint32_t offset = reg_offset & 3;
|
||||
|
||||
// perform register-specific pre-read action
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
break;
|
||||
switch (reg_offset >> 2) {
|
||||
case ATI_CLOCK_CNTL:
|
||||
/* reading from internal PLL registers */
|
||||
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
|
||||
!(this->mm_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
return this->plls[this->mm_regs[ATI_CLOCK_CNTL+1] >> 2];
|
||||
result = this->regs[ATI_CLOCK_CNTL];
|
||||
if ((offset + size - 1) >= 2) {
|
||||
uint8_t pll_addr = (this->regs[ATI_CLOCK_CNTL] >> 10) & 0x3F;
|
||||
insert_bits<uint64_t>(result, this->plls[pll_addr], 16, 8);
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
if (offset == ATI_DAC_DATA) {
|
||||
this->mm_regs[ATI_DAC_DATA] =
|
||||
this->palette[this->mm_regs[ATI_DAC_R_INDEX]][this->comp_index];
|
||||
this->comp_index++; /* move to next color component */
|
||||
if (this->comp_index >= 3) {
|
||||
/* autoincrement reading index - move to next palette entry */
|
||||
(this->mm_regs[ATI_DAC_R_INDEX])++;
|
||||
this->comp_index = 0;
|
||||
result = this->regs[ATI_DAC_REGS];
|
||||
switch (reg_offset) {
|
||||
case ATI_DAC_W_INDEX:
|
||||
insert_bits<uint64_t>(result, this->dac_wr_index, 0, 8);
|
||||
break;
|
||||
case ATI_DAC_MASK:
|
||||
insert_bits<uint64_t>(result, this->dac_mask, 16, 8);
|
||||
break;
|
||||
case ATI_DAC_R_INDEX:
|
||||
insert_bits<uint64_t>(result, this->dac_rd_index, 24, 8);
|
||||
break;
|
||||
case ATI_DAC_DATA:
|
||||
if (!this->comp_index) {
|
||||
uint8_t alpha; // temp variable for unused alpha
|
||||
get_palette_colors(this->dac_rd_index, color_buf[0],
|
||||
color_buf[1], color_buf[2], alpha);
|
||||
}
|
||||
insert_bits<uint64_t>(result, color_buf[this->comp_index], 8, 8);
|
||||
if (++this->comp_index >= 3) {
|
||||
this->dac_rd_index++; // auto-increment reading index
|
||||
this->comp_index = 0; // reset color component index
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI Rage: read I/O reg %s at 0x%X, size=%d, val=0x%X",
|
||||
get_reg_name(offset),
|
||||
offset,
|
||||
size,
|
||||
read_mem(&this->mm_regs[offset], size));
|
||||
result = this->regs[reg_offset >> 2];
|
||||
}
|
||||
|
||||
// reading internal registers with necessary endian conversion
|
||||
res = read_mem(&this->mm_regs[offset], size);
|
||||
|
||||
return res;
|
||||
if (!offset && size == 4) { // fast path
|
||||
return result;
|
||||
} else { // slow path
|
||||
if ((offset + size) > 4) {
|
||||
result |= (uint64_t)(this->regs[(reg_offset >> 2) + 1]) << 32;
|
||||
}
|
||||
return extract_bits<uint64_t>(result, offset * 8, size * 8);
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint8_t gpio_levels, gpio_dirs;
|
||||
void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) {
|
||||
uint32_t offset = reg_offset & 3;
|
||||
reg_offset >>= 2;
|
||||
|
||||
// writing internal registers with necessary endian conversion
|
||||
write_mem(&this->mm_regs[offset], value, size);
|
||||
if (offset || size != 4) { // slow path
|
||||
if ((offset + size) > 4) {
|
||||
ABORT_F("%s: unaligned DWORD writes not implemented", this->name.c_str());
|
||||
}
|
||||
uint64_t old_val = this->regs[reg_offset];
|
||||
insert_bits<uint64_t>(old_val, value, offset * 8, size * 8);
|
||||
value = old_val;
|
||||
}
|
||||
|
||||
// perform register-specific post-write action
|
||||
switch (offset & ~3) {
|
||||
switch (reg_offset) {
|
||||
case ATI_CRTC_H_TOTAL_DISP:
|
||||
LOG_F(9, "%s: ATI_CRTC_H_TOTAL_DISP set to 0x%08X", this->name.c_str(), value);
|
||||
break;
|
||||
case ATI_CRTC_OFF_PITCH:
|
||||
LOG_F(INFO, "ATI Rage: CRTC_OFF_PITCH=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]));
|
||||
this->regs[reg_offset] = value;
|
||||
this->fb_pitch = extract_bits<uint32_t>(value, 22, 10) * 8;
|
||||
this->fb_ptr = &this->vram_ptr[extract_bits<uint32_t>(value, 0, 20) * 8];
|
||||
if (bit_set(this->regs[ATI_CRTC_GEN_CNTL], 25) &&
|
||||
!bit_set(this->regs[ATI_CRTC_GEN_CNTL], 6)) {
|
||||
this->crtc_update();
|
||||
}
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
if (this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2) {
|
||||
this->crtc_enable();
|
||||
} else {
|
||||
this->crtc_on = false;
|
||||
if (bit_changed(this->regs[reg_offset], value, 6)) {
|
||||
if (value & 0x40) {
|
||||
this->regs[reg_offset] |= (1 << 6);
|
||||
this->blank_on = true;
|
||||
this->blank_display();
|
||||
} else {
|
||||
this->regs[reg_offset] &= ~(1 << 6);
|
||||
this->blank_on = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bit_changed(this->regs[reg_offset], value, 25)) {
|
||||
this->regs[reg_offset] = value;
|
||||
if (bit_set(this->regs[reg_offset], 25) &&
|
||||
!bit_set(this->regs[reg_offset], 6)) {
|
||||
this->crtc_update();
|
||||
}
|
||||
return;
|
||||
}
|
||||
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_ENABLE=%d", !!(this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2));
|
||||
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_DISPLAY_DIS=%d", !!(this->mm_regs[ATI_CRTC_GEN_CNTL] & 0x40));
|
||||
break;
|
||||
case ATI_CUR_OFFSET:
|
||||
LOG_F(INFO, "ATI Rage: CUR_OFFSET=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_OFFSET]));
|
||||
break;
|
||||
case ATI_CUR_HORZ_VERT_POSN:
|
||||
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_POSN=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_POSN]));
|
||||
break;
|
||||
case ATI_CUR_HORZ_VERT_OFF:
|
||||
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_OFF=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_OFF]));
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
if (offset < (ATI_GP_IO + 2)) {
|
||||
gpio_levels = this->mm_regs[ATI_GP_IO+1];
|
||||
this->regs[reg_offset] = value;
|
||||
if (offset < 2 && (offset + size - 1) >= 1) {
|
||||
uint8_t gpio_levels = (this->regs[ATI_GP_IO] >> 8) & 0xFFU;
|
||||
gpio_levels = ((gpio_levels & 0x30) >> 3) | (gpio_levels & 1);
|
||||
gpio_dirs = this->mm_regs[ATI_GP_IO+3];
|
||||
gpio_dirs = ((gpio_dirs & 0x30) >> 3) | (gpio_dirs & 1);
|
||||
uint8_t gpio_dirs = (this->regs[ATI_GP_IO] >> 24) & 0xFFU;
|
||||
gpio_dirs = ((gpio_dirs & 0x30) >> 3) | (gpio_dirs & 1);
|
||||
gpio_levels = this->disp_id->read_monitor_sense(gpio_levels, gpio_dirs);
|
||||
this->mm_regs[ATI_GP_IO+1] = ((gpio_levels & 6) << 3) | (gpio_levels & 1);
|
||||
insert_bits<uint32_t>(this->regs[ATI_GP_IO],
|
||||
((gpio_levels & 6) << 3) | (gpio_levels & 1), 8, 8);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
case ATI_CLOCK_CNTL:
|
||||
/* writing to internal PLL registers */
|
||||
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
|
||||
(this->mm_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
int pll_addr = this->mm_regs[ATI_CLOCK_CNTL+1] >> 2;
|
||||
uint8_t pll_data = this->mm_regs[ATI_CLOCK_CNTL+2];
|
||||
this->regs[reg_offset] = value;
|
||||
if ((offset + size - 1) >= 2 && bit_set(this->regs[ATI_CLOCK_CNTL], 9)) {
|
||||
uint8_t pll_addr = (this->regs[ATI_CLOCK_CNTL] >> 10) & 0x3F;
|
||||
uint8_t pll_data = (value >> 16) & 0xFF;
|
||||
this->plls[pll_addr] = pll_data;
|
||||
LOG_F(INFO, "ATI Rage: PLL #%d set to 0x%02X", pll_addr, pll_data);
|
||||
} else if (offset == ATI_CLOCK_CNTL && size == 1) {
|
||||
LOG_F(INFO, "ATI Rage: CLOCK_SEL = 0x%02X",
|
||||
this->mm_regs[ATI_CLOCK_CNTL] & 3);
|
||||
LOG_F(9, "%s: PLL #%d set to 0x%02X", this->name.c_str(), pll_addr, pll_data);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
case ATI_DAC_REGS:
|
||||
switch (offset) {
|
||||
/* writing to read/write index registers resets color component index */
|
||||
switch (reg_offset * 4 + offset) {
|
||||
case ATI_DAC_W_INDEX:
|
||||
this->dac_wr_index = value & 0xFFU;
|
||||
this->comp_index = 0;
|
||||
break;
|
||||
case ATI_DAC_MASK:
|
||||
this->dac_mask = (value >> 16) & 0xFFU;
|
||||
break;
|
||||
case ATI_DAC_R_INDEX:
|
||||
this->dac_rd_index = (value >> 24) & 0xFFU;
|
||||
this->comp_index = 0;
|
||||
break;
|
||||
case ATI_DAC_DATA:
|
||||
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF;
|
||||
this->comp_index++; /* move to next color component */
|
||||
if (this->comp_index >= 3) {
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI DAC palette entry #%d set to R=%X, G=%X, B=%X",
|
||||
this->mm_regs[ATI_DAC_W_INDEX],
|
||||
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][0],
|
||||
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][1],
|
||||
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][2]);
|
||||
/* autoincrement writing index - move to next palette entry */
|
||||
(this->mm_regs[ATI_DAC_W_INDEX])++;
|
||||
this->comp_index = 0;
|
||||
this->color_buf[this->comp_index] = (value >> 8) & this->dac_mask;
|
||||
if (++this->comp_index >= 3) {
|
||||
this->set_palette_color(this->dac_wr_index, color_buf[0],
|
||||
color_buf[1], color_buf[2], 0xFF);
|
||||
this->dac_wr_index++; // auto-increment color index
|
||||
this->comp_index = 0; // reset color component index
|
||||
}
|
||||
}
|
||||
break;
|
||||
return;
|
||||
case ATI_GEN_TEST_CNTL:
|
||||
LOG_F(INFO, "HW cursor: %s", this->mm_regs[ATI_GEN_TEST_CNTL] & 0x80 ? "on" : "off");
|
||||
if (bit_changed(this->regs[reg_offset], value, 7)) {
|
||||
if (bit_set(value, 7))
|
||||
this->setup_hw_cursor();
|
||||
else
|
||||
this->cursor_on = false;
|
||||
}
|
||||
if (bit_changed(this->regs[reg_offset], value, 8)) {
|
||||
if (!bit_set(value, 8))
|
||||
LOG_F(9, "%s: reset GUI engine", this->name.c_str());
|
||||
}
|
||||
if (bit_changed(this->regs[reg_offset], value, 9)) {
|
||||
if (bit_set(value, 9))
|
||||
LOG_F(9, "%s: reset memory controller", this->name.c_str());
|
||||
}
|
||||
if (value & 0xFFFFFC00) {
|
||||
LOG_F(WARNING, "%s: unhandled GEN_TEST_CNTL state=0x%X",
|
||||
this->name.c_str(), value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
INFO,
|
||||
"ATI Rage: %s register at 0x%X set to 0x%X",
|
||||
get_reg_name(offset),
|
||||
offset & ~3,
|
||||
READ_DWORD_LE_A(&this->mm_regs[offset & ~3]));
|
||||
case ATI_CONFIG_CHIP_ID:
|
||||
return; // prevent writes to this read-only register
|
||||
}
|
||||
|
||||
//if ((this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2) &&
|
||||
// !(this->mm_regs[ATI_CRTC_GEN_CNTL] & 0x40)) {
|
||||
// int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
|
||||
// this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
|
||||
// this->fb_ptr = &this->vram_ptr[src_offset];
|
||||
// this->update_screen();
|
||||
//}
|
||||
this->regs[reg_offset] = value;
|
||||
}
|
||||
|
||||
bool ATIRage::io_access_allowed(uint32_t offset) {
|
||||
if (!(this->command & 1)) {
|
||||
if (offset >= this->io_base && offset < (this->io_base + 0x100)) {
|
||||
if (this->command & 1) {
|
||||
return true;
|
||||
}
|
||||
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (offset < this->io_base || offset > (this->io_base + 0x100)) {
|
||||
LOG_F(WARNING, "Rage: I/O out of range, base=0x%X, offset=0x%X", io_base, offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -363,7 +393,7 @@ bool ATIRage::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*res = this->read_reg(offset - this->io_base, size);
|
||||
*res = BYTESWAP_SIZED(this->read_reg(offset - this->io_base, size), size);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -373,35 +403,24 @@ bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->write_reg(offset - this->io_base, value, size);
|
||||
this->write_reg(offset - this->io_base, BYTESWAP_SIZED(value, size), size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
LOG_F(8, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", rgn_start, offset, size);
|
||||
|
||||
if (rgn_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to read outside the aperture!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* read from little-endian VRAM region */
|
||||
if (offset < this->vram_size) { // little-endian VRAM region
|
||||
return read_mem(&this->vram_ptr[offset], size);
|
||||
}
|
||||
else if (offset >= BE_FB_OFFSET) {
|
||||
/* read from big-endian VRAM region */
|
||||
return read_mem_rev(&this->vram_ptr[offset - BE_FB_OFFSET], size);
|
||||
else if (offset >= BE_FB_OFFSET) { // big-endian VRAM region
|
||||
return read_mem(&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_0_OFF) { // memory-mapped registers, block 0
|
||||
return BYTESWAP_SIZED(this->read_reg(offset & 0x3FF, size), 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 if (offset >= MM_REGS_1_OFF) { // memory-mapped registers, block 1
|
||||
return BYTESWAP_SIZED(this->read_reg((offset & 0x3FF) + 0x400, size), size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: read attempt from unmapped aperture region at 0x%08X", offset);
|
||||
@@ -412,28 +431,17 @@ uint32_t ATIRage::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
|
||||
void ATIRage::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
LOG_F(8, "Writing reg=%X, offset=%X, value=%X, size %d", rgn_start, offset, value, size);
|
||||
|
||||
if (rgn_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to write outside the aperture!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* write to little-endian VRAM region */
|
||||
if (offset < this->vram_size) { // little-endian VRAM region
|
||||
write_mem(&this->vram_ptr[offset], value, size);
|
||||
}
|
||||
else if (offset >= BE_FB_OFFSET) {
|
||||
/* write to big-endian VRAM region */
|
||||
write_mem_rev(&this->vram_ptr[offset - BE_FB_OFFSET], value, size);
|
||||
else if (offset >= BE_FB_OFFSET) { // big-endian VRAM region
|
||||
write_mem(&this->vram_ptr[offset & (BE_FB_OFFSET - 1)], 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_0_OFF) { // memory-mapped registers, block 0
|
||||
this->write_reg(offset & 0x3FF, BYTESWAP_SIZED(value, size), 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 if (offset >= MM_REGS_1_OFF) { // memory-mapped registers, block 1
|
||||
this->write_reg((offset & 0x3FF) + 0x400, BYTESWAP_SIZED(value, size), size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: write attempt to unmapped aperture region at 0x%08X", offset);
|
||||
@@ -450,15 +458,17 @@ void ATIRage::verbose_pixel_format(int crtc_index) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t fmt = extract_bits<uint32_t>(this->regs[ATI_CRTC_GEN_CNTL], 8, 3);
|
||||
|
||||
const char* what = "Pixel format:";
|
||||
|
||||
switch (this->mm_regs[ATI_CRTC_GEN_CNTL+1] & 7) {
|
||||
switch (fmt) {
|
||||
case 1:
|
||||
LOG_F(INFO, "%s 4 bpp with DAC palette", what);
|
||||
break;
|
||||
case 2:
|
||||
// check the undocumented DAC_DIRECT bit
|
||||
if (this->mm_regs[ATI_DAC_CNTL+1] & 4) {
|
||||
if (bit_set(this->regs[ATI_DAC_CNTL], 10)) {
|
||||
LOG_F(INFO, "%s 8 bpp direct color (RGB322)", what);
|
||||
} else {
|
||||
LOG_F(INFO, "%s 8 bpp with DAC palette", what);
|
||||
@@ -477,95 +487,112 @@ void ATIRage::verbose_pixel_format(int crtc_index) {
|
||||
LOG_F(INFO, "%s 32 bpp direct color (ARGB8888)", what);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "ATI Rage: CRTC pixel format %d not supported",
|
||||
this->mm_regs[ATI_CRTC_GEN_CNTL+2] & 7);
|
||||
LOG_F(ERROR, "%s: CRTC pixel format %d not supported", this->name.c_str(), fmt);
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::crtc_enable() {
|
||||
/* active (visible) width is specified in characters (8 px) - 1 */
|
||||
this->active_width = (this->mm_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
|
||||
void ATIRage::crtc_update() {
|
||||
uint32_t new_width, new_height, new_htotal, new_vtotal;
|
||||
|
||||
/* active (visible) height is specified in lines - 1 */
|
||||
this->active_height =
|
||||
(READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
|
||||
// check for unsupported modes and fail early
|
||||
if (!bit_set(this->regs[ATI_CRTC_GEN_CNTL], 24))
|
||||
ABORT_F("%s: VGA not supported", this->name.c_str());
|
||||
|
||||
if ((this->plls[PLL_VCLK_CNTL] & 3) == 3) {
|
||||
/* look up which VPLL ouput is requested */
|
||||
int clock_sel = this->mm_regs[ATI_CLOCK_CNTL] & 3;
|
||||
if ((this->plls[PLL_VCLK_CNTL] & 3) != 3)
|
||||
ABORT_F("%s: VLCK source != VPLL", this->name.c_str());
|
||||
|
||||
/* calculate VPLL output frequency */
|
||||
float vpll_freq = calc_pll_freq(2, this->plls[VCLK0_FB_DIV + clock_sel]);
|
||||
bool need_recalc = false;
|
||||
|
||||
/* calculate post divider's index */
|
||||
/* NOTE: post divider's index has been extended by an additional
|
||||
bit in Rage Pro. This bit is resided in PLL_EXT_CNTL register.
|
||||
*/
|
||||
int post_div_idx = ((this->plls[PLL_EXT_CNTL] >> (clock_sel + 2)) & 4) |
|
||||
((this->plls[VCLK_POST_DIV] >> (clock_sel * 2)) & 3);
|
||||
new_width = (extract_bits<uint32_t>(this->regs[ATI_CRTC_H_TOTAL_DISP], 16, 8) + 1) * 8;
|
||||
new_height = extract_bits<uint32_t>(this->regs[ATI_CRTC_V_TOTAL_DISP], 16, 11) + 1;
|
||||
|
||||
/* pixel clock = source_freq / post_div */
|
||||
this->pixel_clock = vpll_freq / mach64_post_div[post_div_idx];
|
||||
if (new_width != this->active_width || new_height != this->active_height) {
|
||||
this->create_display_window(new_width, new_height);
|
||||
need_recalc = true;
|
||||
}
|
||||
|
||||
/* calculate display refresh rate */
|
||||
int hori_total =
|
||||
((READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_H_TOTAL_DISP])
|
||||
& 0x1FFUL) + 1) * 8;
|
||||
new_htotal = (extract_bits<uint32_t>(this->regs[ATI_CRTC_H_TOTAL_DISP], 0, 9) + 1) * 8;
|
||||
new_vtotal = extract_bits<uint32_t>(this->regs[ATI_CRTC_V_TOTAL_DISP], 0, 11) + 1;
|
||||
|
||||
int vert_total =
|
||||
(READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
|
||||
if (new_htotal != this->hori_total || new_vtotal != this->vert_total) {
|
||||
this->hori_total = new_htotal;
|
||||
this->vert_total = new_vtotal;
|
||||
need_recalc = true;
|
||||
}
|
||||
|
||||
this->refresh_rate = pixel_clock / hori_total / vert_total;
|
||||
if (!need_recalc)
|
||||
return;
|
||||
|
||||
int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
// look up which VPLL ouput is requested
|
||||
int clock_sel = this->regs[ATI_CLOCK_CNTL] & 3;
|
||||
|
||||
this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
// calculate VPLL output frequency
|
||||
float vpll_freq = calc_pll_freq(2, this->plls[VCLK0_FB_DIV + clock_sel]);
|
||||
|
||||
this->fb_ptr = &this->vram_ptr[src_offset];
|
||||
// calculate post divider's index
|
||||
// NOTE: post divider's index has been extended by an additional
|
||||
// bit in Rage Pro. This bit is resided in PLL_EXT_CNTL register.
|
||||
int post_div_idx = ((this->plls[PLL_EXT_CNTL] >> (clock_sel + 2)) & 4) |
|
||||
((this->plls[VCLK_POST_DIV] >> (clock_sel * 2)) & 3);
|
||||
|
||||
// specify framebuffer converter (hardcoded for now)
|
||||
// pixel clock = source_freq / post_div
|
||||
this->pixel_clock = vpll_freq / mach64_post_div[post_div_idx];
|
||||
|
||||
// calculate display refresh rate
|
||||
this->refresh_rate = pixel_clock / this->hori_total / this->vert_total;
|
||||
|
||||
// set up frame buffer converter
|
||||
int pix_fmt = extract_bits<uint32_t>(this->regs[ATI_CRTC_GEN_CNTL], 8, 3);
|
||||
|
||||
switch (pix_fmt) {
|
||||
case 2:
|
||||
if (bit_set(this->regs[ATI_DAC_CNTL], 10)) {
|
||||
ABORT_F("%s: DAC_DIRECT set!", this->name.c_str());
|
||||
}
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->convert_frame_8bpp(dst_buf, dst_pitch);
|
||||
};
|
||||
|
||||
LOG_F(INFO, "ATI Rage: primary CRT controller enabled:");
|
||||
LOG_F(INFO, "Video mode: %s",
|
||||
(this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 1) ? "extended" : "VGA");
|
||||
LOG_F(INFO, "Video width: %d px", this->active_width);
|
||||
LOG_F(INFO, "Video height: %d px", this->active_height);
|
||||
verbose_pixel_format(0);
|
||||
LOG_F(INFO, "VPLL frequency: %f MHz", vpll_freq * 1e-6);
|
||||
LOG_F(INFO, "Pixel (dot) clock: %f MHz", this->pixel_clock * 1e-6);
|
||||
LOG_F(INFO, "Refresh rate: %f Hz", this->refresh_rate);
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
this->update_screen();
|
||||
} else {
|
||||
LOG_F(WARNING, "ATI Rage: VLCK source != VPLL!");
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported pixel format %d", this->name.c_str(), pix_fmt);
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s: primary CRT controller enabled:", this->name.c_str());
|
||||
LOG_F(INFO, "Video mode: %s",
|
||||
bit_set(this->regs[ATI_CRTC_GEN_CNTL], 24) ? "extended" : "VGA");
|
||||
LOG_F(INFO, "Video width: %d px", this->active_width);
|
||||
LOG_F(INFO, "Video height: %d px", this->active_height);
|
||||
verbose_pixel_format(0);
|
||||
LOG_F(INFO, "VPLL frequency: %f MHz", vpll_freq * 1e-6);
|
||||
LOG_F(INFO, "Pixel (dot) clock: %f MHz", this->pixel_clock * 1e-6);
|
||||
LOG_F(INFO, "Refresh rate: %f Hz", this->refresh_rate);
|
||||
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
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->mm_regs[ATI_CUR_HORZ_VERT_OFF]) & 0x3F;
|
||||
int vert_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_OFF]) >> 16) & 0x3F;
|
||||
int vert_offset = extract_bits<uint32_t>(this->regs[ATI_CUR_HORZ_VERT_OFF], 16, 5);
|
||||
|
||||
src_buf = &this->vram_ptr[(READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_OFFSET]) * 8)];
|
||||
src_buf = &this->vram_ptr[this->regs[ATI_CUR_OFFSET] * 8];
|
||||
|
||||
int cur_height = 64 - vert_offset;
|
||||
|
||||
uint32_t color0 = READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_CLR0]) | 0x000000FFUL;
|
||||
uint32_t color1 = READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_CLR1]) | 0x000000FFUL;
|
||||
uint32_t color0 = this->regs[ATI_CUR_CLR0] | 0x000000FFUL;
|
||||
uint32_t color1 = this->regs[ATI_CUR_CLR1] | 0x000000FFUL;
|
||||
|
||||
for (int h = 0; h < cur_height; h++) {
|
||||
dst_row = &dst_buf[h * dst_pitch];
|
||||
@@ -583,6 +610,7 @@ void ATIRage::draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {
|
||||
WRITE_DWORD_BE_A(dst_row, color1);
|
||||
break;
|
||||
case 2: // transparent
|
||||
WRITE_DWORD_BE_A(dst_row, 0);
|
||||
break;
|
||||
case 3: // 1's complement of display pixel
|
||||
break;
|
||||
@@ -592,6 +620,11 @@ void ATIRage::draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::get_cursor_position(int& x, int& y) {
|
||||
x = this->regs[ATI_CUR_HORZ_VERT_POSN] & 0xFFFFU;
|
||||
y = (this->regs[ATI_CUR_HORZ_VERT_POSN] >> 16) & 0xFFFFU;
|
||||
}
|
||||
|
||||
static const PropMap AtiRage_Properties = {
|
||||
{"gfxmem_size",
|
||||
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
|
||||
|
||||
+20
-18
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -55,19 +55,15 @@ public:
|
||||
return std::unique_ptr<ATIRage>(new ATIRage(ATI_RAGE_PRO_DEV_ID));
|
||||
}
|
||||
|
||||
/* MMIODevice methods */
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) {
|
||||
return true;
|
||||
};
|
||||
// PCI device methods
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
/* I/O space access methods */
|
||||
// I/O space access methods
|
||||
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
@@ -75,19 +71,20 @@ protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
const char* get_reg_name(uint32_t reg_offset);
|
||||
bool io_access_allowed(uint32_t offset);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
uint32_t read_reg(uint32_t reg_offset, uint32_t size);
|
||||
void write_reg(uint32_t reg_addr, uint32_t value, uint32_t size);
|
||||
float calc_pll_freq(int scale, int fb_div);
|
||||
void verbose_pixel_format(int crtc_index);
|
||||
void crtc_update();
|
||||
void crtc_enable();
|
||||
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
|
||||
void get_cursor_position(int& x, int& y);
|
||||
|
||||
private:
|
||||
uint8_t mm_regs[2048] = {0}; // internal registers
|
||||
uint32_t regs[512] = {}; // internal registers
|
||||
uint8_t plls[64] = {}; // internal PLL registers
|
||||
|
||||
uint8_t plls[64] = {0}; // internal PLL registers
|
||||
|
||||
/* Video RAM variables */
|
||||
// Video RAM variables
|
||||
std::unique_ptr<uint8_t[]> vram_ptr;
|
||||
uint32_t vram_size;
|
||||
|
||||
@@ -97,7 +94,12 @@ private:
|
||||
|
||||
std::unique_ptr<DisplayID> disp_id;
|
||||
|
||||
int comp_index; /* color component index for DAC palette access */
|
||||
// DAC interface state
|
||||
uint8_t dac_wr_index = 0; // current DAC color index for writing
|
||||
uint8_t dac_rd_index = 0; // current DAC color index for reading
|
||||
uint8_t dac_mask = 0; // current DAC mask
|
||||
int comp_index = 0; // current color component index
|
||||
uint8_t color_buf[3] = {}; // buffer for storing DAC color components
|
||||
};
|
||||
|
||||
#endif /* ATI_RAGE_H */
|
||||
#endif // ATI_RAGE_H
|
||||
+97
-82
@@ -59,8 +59,12 @@ ControlVideo::ControlVideo()
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 3;
|
||||
this->class_rev = 0;
|
||||
this->bars_cfg[1] = 0xFFFFF000UL; // base address for the HW registers (4KB)
|
||||
this->bars_cfg[2] = 0xFC000000UL; // base address for the VRAM (64MB)
|
||||
|
||||
this->setup_bars({
|
||||
{0, 0xFFFFFFFFUL}, // I/O region (4 bytes but it's weird because bit 1 is set)
|
||||
{1, 0xFFFFF000UL}, // base address for the HW registers (4KB)
|
||||
{2, 0xFC000000UL} // base address for the VRAM (64MB)
|
||||
});
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
@@ -84,6 +88,10 @@ ControlVideo::ControlVideo()
|
||||
void ControlVideo::notify_bar_change(int bar_num)
|
||||
{
|
||||
switch (bar_num) {
|
||||
case 0:
|
||||
this->io_base = this->bars[bar_num] & ~3;
|
||||
LOG_F(INFO, "Control: I/O space address set to 0x%08X", this->io_base);
|
||||
break;
|
||||
case 1:
|
||||
if (this->regs_base != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
this->regs_base = this->bars[bar_num] & 0xFFFFFFF0UL;
|
||||
@@ -116,18 +124,22 @@ uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
}
|
||||
}
|
||||
|
||||
switch (offset >> 4) {
|
||||
case ControlRegs::TEST:
|
||||
result = this->test;
|
||||
break;
|
||||
case ControlRegs::MON_SENSE:
|
||||
result = this->cur_mon_id << 6;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "read from 0x%08X:0x%08X", rgn_start, offset);
|
||||
if (rgn_start == this->regs_base) {
|
||||
switch (offset >> 4) {
|
||||
case ControlRegs::TEST:
|
||||
result = this->test;
|
||||
break;
|
||||
case ControlRegs::MON_SENSE:
|
||||
result = this->cur_mon_id << 6;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "read from 0x%08X:0x%08X", rgn_start, offset);
|
||||
}
|
||||
|
||||
return BYTESWAP_32(result);
|
||||
}
|
||||
|
||||
return BYTESWAP_32(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
@@ -141,75 +153,77 @@ void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
return;
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
if (rgn_start == this->regs_base) {
|
||||
value = BYTESWAP_32(value);
|
||||
|
||||
switch (offset >> 4) {
|
||||
case ControlRegs::VFPEQ:
|
||||
case ControlRegs::VFP:
|
||||
case ControlRegs::VAL:
|
||||
case ControlRegs::VBP:
|
||||
case ControlRegs::VBPEQ:
|
||||
case ControlRegs::VSYNC:
|
||||
case ControlRegs::VHLINE:
|
||||
case ControlRegs::PIPED:
|
||||
case ControlRegs::HPIX:
|
||||
case ControlRegs::HFP:
|
||||
case ControlRegs::HAL:
|
||||
case ControlRegs::HBWAY:
|
||||
case ControlRegs::HSP:
|
||||
case ControlRegs::HEQ:
|
||||
case ControlRegs::HLFLN:
|
||||
case ControlRegs::HSERR:
|
||||
this->swatch_params[(offset >> 4) - 1] = value;
|
||||
break;
|
||||
case ControlRegs::TEST:
|
||||
if (this->test != value) {
|
||||
if ((this->test & ~TEST_STROBE) != (value & ~TEST_STROBE)) {
|
||||
this->test = value;
|
||||
this->test_shift = 0;
|
||||
LOG_F(9, "New TEST value: 0x%08X", this->test);
|
||||
} else {
|
||||
LOG_F(9, "TEST strobe bit flipped, new value: 0x%08X", value);
|
||||
this->test = value;
|
||||
if (++this->test_shift >= 3) {
|
||||
LOG_F(9, "Received TEST reg value: 0x%08X", this->test & ~TEST_STROBE);
|
||||
if ((this->test ^ this->prev_test) & 0x400) {
|
||||
if (this->test & 0x400) {
|
||||
this->disable_display();
|
||||
} else {
|
||||
this->enable_display();
|
||||
switch (offset >> 4) {
|
||||
case ControlRegs::VFPEQ:
|
||||
case ControlRegs::VFP:
|
||||
case ControlRegs::VAL:
|
||||
case ControlRegs::VBP:
|
||||
case ControlRegs::VBPEQ:
|
||||
case ControlRegs::VSYNC:
|
||||
case ControlRegs::VHLINE:
|
||||
case ControlRegs::PIPED:
|
||||
case ControlRegs::HPIX:
|
||||
case ControlRegs::HFP:
|
||||
case ControlRegs::HAL:
|
||||
case ControlRegs::HBWAY:
|
||||
case ControlRegs::HSP:
|
||||
case ControlRegs::HEQ:
|
||||
case ControlRegs::HLFLN:
|
||||
case ControlRegs::HSERR:
|
||||
this->swatch_params[(offset >> 4) - 1] = value;
|
||||
break;
|
||||
case ControlRegs::TEST:
|
||||
if (this->test != value) {
|
||||
if ((this->test & ~TEST_STROBE) != (value & ~TEST_STROBE)) {
|
||||
this->test = value;
|
||||
this->test_shift = 0;
|
||||
LOG_F(9, "New TEST value: 0x%08X", this->test);
|
||||
} else {
|
||||
LOG_F(9, "TEST strobe bit flipped, new value: 0x%08X", value);
|
||||
this->test = value;
|
||||
if (++this->test_shift >= 3) {
|
||||
LOG_F(9, "Received TEST reg value: 0x%08X", this->test & ~TEST_STROBE);
|
||||
if ((this->test ^ this->prev_test) & 0x400) {
|
||||
if (this->test & 0x400) {
|
||||
this->disable_display();
|
||||
} else {
|
||||
this->enable_display();
|
||||
}
|
||||
this->prev_test = this->test;
|
||||
}
|
||||
this->prev_test = this->test;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ControlRegs::GBASE:
|
||||
this->fb_base = value;
|
||||
break;
|
||||
case ControlRegs::ROW_WORDS:
|
||||
this->row_words = value;
|
||||
break;
|
||||
case ControlRegs::MON_SENSE:
|
||||
LOG_F(9, "Control: monitor sense written with 0x%X", value);
|
||||
value = (value >> 3) & 7;
|
||||
this->cur_mon_id = this->display_id->read_monitor_sense(value & 7, value ^ 7);
|
||||
break;
|
||||
case ControlRegs::ENABLE:
|
||||
this->flags = value;
|
||||
break;
|
||||
case ControlRegs::GSC_DIVIDE:
|
||||
this->clock_divider = value;
|
||||
break;
|
||||
case ControlRegs::REFRESH_COUNT:
|
||||
LOG_F(INFO, "Control: refresh count set to 0x%08X", value);
|
||||
break;
|
||||
case ControlRegs::INT_ENABLE:
|
||||
this->int_enable = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "write 0x%08X to 0x%08X:0x%08X", value, rgn_start, offset);
|
||||
}
|
||||
break;
|
||||
case ControlRegs::GBASE:
|
||||
this->fb_base = value;
|
||||
break;
|
||||
case ControlRegs::ROW_WORDS:
|
||||
this->row_words = value;
|
||||
break;
|
||||
case ControlRegs::MON_SENSE:
|
||||
LOG_F(9, "Control: monitor sense written with 0x%X", value);
|
||||
value = (value >> 3) & 7;
|
||||
this->cur_mon_id = this->display_id->read_monitor_sense(value & 7, value ^ 7);
|
||||
break;
|
||||
case ControlRegs::ENABLE:
|
||||
this->flags = value;
|
||||
break;
|
||||
case ControlRegs::GSC_DIVIDE:
|
||||
this->clock_divider = value;
|
||||
break;
|
||||
case ControlRegs::REFRESH_COUNT:
|
||||
LOG_F(INFO, "Control: refresh count set to 0x%08X", value);
|
||||
break;
|
||||
case ControlRegs::INT_ENABLE:
|
||||
this->int_enable = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "write 0x%08X to 0x%08X:0x%08X", value, rgn_start, offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,16 +293,20 @@ void ControlVideo::enable_display()
|
||||
/ (new_height + vert_blank);
|
||||
LOG_F(INFO, "Control: refresh rate set to %f Hz", this->refresh_rate);
|
||||
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
|
||||
// set up periodic timer for display updates
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
this->update_screen();
|
||||
this->blank_on = false;
|
||||
|
||||
LOG_F(INFO, "Control: display enabled");
|
||||
this->crtc_on = true;
|
||||
@@ -338,11 +356,8 @@ void ControlVideo::iodev_write(uint32_t address, uint16_t value)
|
||||
case RadacalRegs::CLUT_DATA:
|
||||
this->clut_color[this->comp_index++] = value;
|
||||
if (this->comp_index >= 3) {
|
||||
// TODO: combine separate components into a single ARGB value
|
||||
this->palette[this->rad_addr][0] = this->clut_color[0];
|
||||
this->palette[this->rad_addr][1] = this->clut_color[1];
|
||||
this->palette[this->rad_addr][2] = this->clut_color[2];
|
||||
this->palette[this->rad_addr][3] = 255;
|
||||
this->set_palette_color(this->rad_addr, clut_color[0],
|
||||
clut_color[1], clut_color[2], 0xFF);
|
||||
this->rad_addr++; // auto-increment CLUT address
|
||||
this->comp_index = 0;
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ private:
|
||||
std::unique_ptr<uint8_t[]> vram_ptr;
|
||||
|
||||
uint32_t vram_size;
|
||||
uint32_t io_base = 0;
|
||||
uint32_t vram_base = 0;
|
||||
uint32_t regs_base = 0;
|
||||
uint32_t prev_test = 0x433;
|
||||
|
||||
@@ -88,7 +88,6 @@ DisplayID::DisplayID(uint8_t std_code, uint8_t ext_code)
|
||||
uint8_t DisplayID::read_monitor_sense(uint8_t levels, uint8_t dirs)
|
||||
{
|
||||
uint8_t scl, sda;
|
||||
uint16_t result;
|
||||
|
||||
switch(this->id_kind) {
|
||||
case Disp_Id_Kind::DDC2B:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -46,6 +46,15 @@ PdmOnboardVideo::PdmOnboardVideo()
|
||||
|
||||
void PdmOnboardVideo::set_video_mode(uint8_t new_mode)
|
||||
{
|
||||
if (this->blanking != (new_mode & 0x80)) {
|
||||
if (new_mode & 0x80) {
|
||||
this->disable_video_internal();
|
||||
} else {
|
||||
this->blank_on = false;
|
||||
this->blanking = 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch(new_mode & 0x7F) {
|
||||
case PdmVideoMode::Portrait:
|
||||
case PdmVideoMode::Rgb12in:
|
||||
@@ -56,20 +65,14 @@ void PdmOnboardVideo::set_video_mode(uint8_t new_mode)
|
||||
this->video_mode = new_mode & 0x1F;
|
||||
LOG_F(INFO, "PDM-Video: video mode set to 0x%X", this->video_mode);
|
||||
}
|
||||
if (this->blanking != (new_mode & 0x80)) {
|
||||
this->blanking = new_mode & 0x80;
|
||||
if (this->blanking) {
|
||||
this->disable_video_internal();
|
||||
} else {
|
||||
this->enable_video_internal();
|
||||
}
|
||||
if (!this->blanking) {
|
||||
this->enable_video_internal();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "PDM-Video: video disabled, new mode = 0x%X", new_mode & 0x1F);
|
||||
this->video_mode = new_mode & 0x1F;
|
||||
this->blanking = 0x80;
|
||||
this->crtc_on = false;
|
||||
this->disable_video_internal();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +110,10 @@ void PdmOnboardVideo::set_clut_color(uint8_t color)
|
||||
{
|
||||
this->clut_color[this->comp_index++] = color;
|
||||
if (this->comp_index >= 3) {
|
||||
// TODO: combine separate components into a single ARGB value
|
||||
this->palette[this->clut_index][0] = this->clut_color[0];
|
||||
this->palette[this->clut_index][1] = this->clut_color[1];
|
||||
this->palette[this->clut_index][2] = this->clut_color[2];
|
||||
this->palette[this->clut_index][3] = 255;
|
||||
this->clut_index++; // assume the HW works like that
|
||||
this->comp_index = 0; // assume the HW works like that
|
||||
this->set_palette_color(this->clut_index, clut_color[0],
|
||||
clut_color[1], clut_color[2], 0xFF);
|
||||
this->clut_index++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,33 +204,38 @@ void PdmOnboardVideo::enable_video_internal()
|
||||
LOG_F(INFO, "PDM-Video: framebuffer phys base addr = 0x%X", fb_base_phys);
|
||||
|
||||
// set framebuffer address and pitch
|
||||
this->fb_ptr = mmu_get_dma_mem(fb_base_phys, PDM_FB_SIZE_MAX);
|
||||
this->fb_ptr = mmu_get_dma_mem(fb_base_phys, PDM_FB_SIZE_MAX, nullptr);
|
||||
this->active_width = new_width;
|
||||
this->active_height = new_height;
|
||||
|
||||
this->set_depth_internal(new_width);
|
||||
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
|
||||
// set up video refresh timer
|
||||
double refresh_rate_hz = (double)(this->pixel_clock) / (new_width + hori_blank) / (new_height + vert_blank);
|
||||
LOG_F(INFO, "PDM-Video: refresh rate set to %f Hz", refresh_rate_hz);
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate_hz * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
this->update_screen();
|
||||
|
||||
LOG_F(INFO, "PDM-Video: video enabled");
|
||||
LOG_F(9, "PDM-Video: video enabled");
|
||||
this->crtc_on = true;
|
||||
}
|
||||
|
||||
void PdmOnboardVideo::disable_video_internal()
|
||||
{
|
||||
this->blank_on = true;
|
||||
this->blank_display();
|
||||
this->blanking = 0x80;
|
||||
this->crtc_on = false;
|
||||
LOG_F(INFO, "PDM-Video: video disabled");
|
||||
LOG_F(9, "PDM-Video: video disabled");
|
||||
}
|
||||
|
||||
/** Ariel II has a weird 1bpp mode where a white pixel is mapped to
|
||||
@@ -245,10 +250,8 @@ void PdmOnboardVideo::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
uint32_t pixels[2];
|
||||
|
||||
// prepare cached ARGB values for white & black pixels
|
||||
pixels[0] = (0xFF << 24) | (this->palette[127][0] << 16) |
|
||||
(this->palette[127][1] << 8) | this->palette[127][2];
|
||||
pixels[1] = (0xFF << 24) | (this->palette[255][0] << 16) |
|
||||
(this->palette[255][1] << 8) | this->palette[255][2];
|
||||
pixels[0] = this->palette[127];
|
||||
pixels[1] = this->palette[255];
|
||||
|
||||
src_buf = this->fb_ptr;
|
||||
src_pitch = this->fb_pitch;
|
||||
|
||||
+133
-61
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,8 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Video Conroller base class implementation. */
|
||||
|
||||
#include "videoctrl.h"
|
||||
#include <core/hostevents.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#include <chrono>
|
||||
@@ -30,55 +32,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
VideoCtrlBase::VideoCtrlBase(int width, int height)
|
||||
{
|
||||
LOG_F(INFO, "Create display window...");
|
||||
EventManager::get_instance()->register_handler(EventType::EVENT_WINDOW,
|
||||
[this](const BaseEvent& event) {
|
||||
const WindowEvent& wnd_event = static_cast<const WindowEvent&>(event);
|
||||
if (wnd_event.sub_type == SDL_WINDOWEVENT_SIZE_CHANGED &&
|
||||
wnd_event.window_id == this->disp_wnd_id)
|
||||
this->resizing = false;
|
||||
});
|
||||
|
||||
this->active_width = width;
|
||||
this->active_height = height;
|
||||
|
||||
// Create display window
|
||||
this->display_wnd = SDL_CreateWindow(
|
||||
"DingusPPC Display",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
this->active_width,
|
||||
this->active_height,
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
|
||||
if (this->display_wnd == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateWindow failed with %s", 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", 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,
|
||||
width, height
|
||||
);
|
||||
|
||||
if (this->disp_texture == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateTexture failed with %s", SDL_GetError());
|
||||
}
|
||||
this->create_display_window(width, height);
|
||||
}
|
||||
|
||||
VideoCtrlBase::~VideoCtrlBase()
|
||||
{
|
||||
if (this->cursor_texture) {
|
||||
SDL_DestroyTexture(this->cursor_texture);
|
||||
}
|
||||
|
||||
if (this->disp_texture) {
|
||||
SDL_DestroyTexture(this->disp_texture);
|
||||
}
|
||||
@@ -92,6 +62,61 @@ VideoCtrlBase::~VideoCtrlBase()
|
||||
}
|
||||
}
|
||||
|
||||
void VideoCtrlBase::create_display_window(int width, int height)
|
||||
{
|
||||
if (!this->display_wnd) { // create display window
|
||||
this->display_wnd = SDL_CreateWindow(
|
||||
"DingusPPC Display",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
width, height,
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
|
||||
this->disp_wnd_id = SDL_GetWindowID(this->display_wnd);
|
||||
|
||||
if (this->display_wnd == NULL) {
|
||||
ABORT_F("Display: SDL_CreateWindow failed with %s", SDL_GetError());
|
||||
}
|
||||
|
||||
this->renderer = SDL_CreateRenderer(this->display_wnd, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (this->renderer == NULL) {
|
||||
ABORT_F("Display: SDL_CreateRenderer failed with %s", SDL_GetError());
|
||||
}
|
||||
|
||||
this->blank_on = true; // TODO: should be true!
|
||||
|
||||
this->blank_display();
|
||||
} else { // resize display window
|
||||
SDL_SetWindowSize(this->display_wnd, width, height);
|
||||
this->resizing = true;
|
||||
}
|
||||
|
||||
this->active_width = width;
|
||||
this->active_height = height;
|
||||
|
||||
if (this->disp_texture) {
|
||||
SDL_DestroyTexture(this->disp_texture);
|
||||
}
|
||||
|
||||
this->disp_texture = SDL_CreateTexture(
|
||||
this->renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
width, height
|
||||
);
|
||||
|
||||
if (this->disp_texture == NULL) {
|
||||
ABORT_F("Display: SDL_CreateTexture failed with %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
void VideoCtrlBase::blank_display() {
|
||||
SDL_SetRenderDrawColor(this->renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderPresent(this->renderer);
|
||||
}
|
||||
|
||||
void VideoCtrlBase::update_screen()
|
||||
{
|
||||
uint8_t* dst_buf;
|
||||
@@ -99,6 +124,14 @@ void VideoCtrlBase::update_screen()
|
||||
|
||||
//auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
if (this->resizing)
|
||||
return;
|
||||
|
||||
if (this->blank_on) {
|
||||
this->blank_display();
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_LockTexture(this->disp_texture, NULL, (void **)&dst_buf, &dst_pitch);
|
||||
|
||||
// texture update callback to get ARGB data from guest framebuffer
|
||||
@@ -107,18 +140,61 @@ void VideoCtrlBase::update_screen()
|
||||
SDL_UnlockTexture(this->disp_texture);
|
||||
SDL_RenderClear(this->renderer);
|
||||
SDL_RenderCopy(this->renderer, this->disp_texture, NULL, NULL);
|
||||
|
||||
// draw HW cursor if enabled
|
||||
if (this->cursor_on) {
|
||||
this->get_cursor_position(cursor_rect.x, cursor_rect.y);
|
||||
SDL_RenderCopy(this->renderer, this->cursor_texture, NULL, &cursor_rect);
|
||||
}
|
||||
|
||||
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);
|
||||
//}
|
||||
void VideoCtrlBase::get_palette_colors(uint8_t index, uint8_t& r, uint8_t& g,
|
||||
uint8_t& b, uint8_t& a)
|
||||
{
|
||||
b = this->palette[index] & 0xFFU;
|
||||
g = (this->palette[index] >> 8) & 0xFFU;
|
||||
r = (this->palette[index] >> 16) & 0xFFU;
|
||||
a = (this->palette[index] >> 24) & 0xFFU;
|
||||
}
|
||||
|
||||
//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());
|
||||
void VideoCtrlBase::set_palette_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||
{
|
||||
this->palette[index] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
void VideoCtrlBase::setup_hw_cursor(int cursor_width, int cursor_height)
|
||||
{
|
||||
uint8_t* dst_buf;
|
||||
int dst_pitch;
|
||||
|
||||
if (this->cursor_texture) {
|
||||
SDL_DestroyTexture(this->cursor_texture);
|
||||
}
|
||||
|
||||
this->cursor_texture = SDL_CreateTexture(
|
||||
this->renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
cursor_width, cursor_height
|
||||
);
|
||||
|
||||
if (this->cursor_texture == NULL) {
|
||||
ABORT_F("SDL_CreateTexture for HW cursor failed with %s", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_LockTexture(this->cursor_texture, NULL, (void **)&dst_buf, &dst_pitch);
|
||||
SDL_SetTextureBlendMode(this->cursor_texture, SDL_BLENDMODE_BLEND);
|
||||
this->draw_hw_cursor(dst_buf, dst_pitch);
|
||||
SDL_UnlockTexture(this->cursor_texture);
|
||||
|
||||
this->cursor_rect.x = 0;
|
||||
this->cursor_rect.y = 0;
|
||||
this->cursor_rect.w = cursor_width;
|
||||
this->cursor_rect.h = cursor_height;
|
||||
|
||||
this->cursor_on = true;
|
||||
}
|
||||
|
||||
void VideoCtrlBase::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
@@ -128,7 +204,7 @@ void VideoCtrlBase::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
|
||||
void VideoCtrlBase::convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
{
|
||||
uint8_t *src_buf, *src_row, *dst_row, pix;
|
||||
uint8_t *src_buf, *src_row, *dst_row;
|
||||
int src_pitch;
|
||||
|
||||
src_buf = this->fb_ptr;
|
||||
@@ -139,11 +215,7 @@ void VideoCtrlBase::convert_frame_8bpp(uint8_t *dst_buf, int dst_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
|
||||
WRITE_DWORD_LE_A(dst_row, this->palette[src_row[x]]);
|
||||
dst_row += 4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -34,33 +34,53 @@ public:
|
||||
VideoCtrlBase(int width = 640, int height = 480);
|
||||
~VideoCtrlBase();
|
||||
|
||||
void create_display_window(int width, int height);
|
||||
void blank_display();
|
||||
void update_screen(void);
|
||||
|
||||
void get_palette_colors(uint8_t index, uint8_t& r, uint8_t& g, uint8_t& b,
|
||||
uint8_t& a);
|
||||
void set_palette_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||
|
||||
// HW cursor support
|
||||
void setup_hw_cursor(int cursor_width=64, int cur_height=64);
|
||||
virtual void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {};
|
||||
virtual void get_cursor_position(int& x, int& y) { x = 0; y = 0; };
|
||||
|
||||
// converters for various framebuffer pixel depths
|
||||
virtual void convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch);
|
||||
virtual void convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
protected:
|
||||
/* CRT controller parameters */
|
||||
// CRT controller parameters
|
||||
bool crtc_on = false;
|
||||
bool blank_on = true;
|
||||
bool resizing = false;
|
||||
bool cursor_on = false;
|
||||
int active_width; // width of the visible display area
|
||||
int active_height; // height of the visible display area
|
||||
int hori_total = 0;
|
||||
int vert_total = 0;
|
||||
int pixel_depth;
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
uint8_t palette[256][4]; /* internal DAC palette in RGBA format */
|
||||
uint32_t palette[256]; // internal DAC palette in RGBA format
|
||||
|
||||
// Framebuffer parameters
|
||||
uint8_t* fb_ptr;
|
||||
int fb_pitch;
|
||||
uint32_t refresh_task_id = 0;
|
||||
|
||||
std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb;
|
||||
|
||||
private:
|
||||
SDL_Window *display_wnd;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *disp_texture;
|
||||
uint32_t disp_wnd_id = 0;
|
||||
SDL_Window* display_wnd = 0;
|
||||
SDL_Renderer* renderer = 0;
|
||||
SDL_Texture* disp_texture = 0;
|
||||
SDL_Texture* cursor_texture = 0;
|
||||
SDL_Rect cursor_rect; // destination rectangle for cursor drawing
|
||||
};
|
||||
|
||||
#endif // VIDEO_CTRL_H
|
||||
@@ -69,4 +69,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#endif
|
||||
|
||||
#define BYTESWAP_SIZED(val, size) \
|
||||
(size) == 2 ? BYTESWAP_16((val)) : ((size) == 4 ? BYTESWAP_32((val)) : (val))
|
||||
|
||||
#endif /* ENDIAN_SWAP_H */
|
||||
@@ -7,4 +7,4 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(machines OBJECT ${SOURCES})
|
||||
target_link_libraries(machines PRIVATE cubeb)
|
||||
target_link_libraries(machines PRIVATE cubeb SDL2::SDL2)
|
||||
@@ -36,13 +36,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
int initialize_catalyst(std::string& id)
|
||||
{
|
||||
LOG_F(INFO, "Building machine Catalyst...");
|
||||
|
||||
PlatinumCtrl* platinum_obj;
|
||||
|
||||
PCIHost *pci_host = dynamic_cast<PCIHost*>(gMachineObj->get_comp_by_name("Bandit1"));
|
||||
|
||||
// add the GrandCentral I/O controller
|
||||
pci_host->pci_register_device(
|
||||
32, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("GrandCentral")));
|
||||
DEV_FUN(0x10,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("GrandCentral")));
|
||||
|
||||
// get (raw) pointer to the memory controller
|
||||
platinum_obj = dynamic_cast<PlatinumCtrl*>(gMachineObj->get_comp_by_name("Platinum"));
|
||||
|
||||
@@ -77,6 +77,7 @@ static const map<string, string> PropHelp = {
|
||||
{"rambank4_size", "specifies RAM bank 4 size in MB"},
|
||||
{"gfxmem_size", "specifies video memory size in MB"},
|
||||
{"fdd_img", "specifies path to floppy disk image"},
|
||||
{"fdd_fmt", "specifies floppy disk format"},
|
||||
{"fdd_wr_prot", "toggles floppy disk's write protection"},
|
||||
{"hdd_img", "specifies path to hard disk image"},
|
||||
{"hdd_wr_prot", "toggles hard disk's write protection"},
|
||||
@@ -271,7 +272,8 @@ void MachineFactory::set_machine_settings(map<string, string> &settings) {
|
||||
|
||||
string MachineFactory::machine_name_from_rom(string& rom_filepath) {
|
||||
ifstream rom_file;
|
||||
uint32_t file_size, config_info_offset, rom_id;
|
||||
size_t file_size;
|
||||
uint32_t config_info_offset, rom_id;
|
||||
char rom_id_str[17];
|
||||
|
||||
string machine_name = "";
|
||||
@@ -329,7 +331,8 @@ bail_out:
|
||||
int MachineFactory::load_boot_rom(string& rom_filepath) {
|
||||
ifstream rom_file;
|
||||
size_t file_size;
|
||||
int result;
|
||||
int result = 0;
|
||||
uint32_t rom_load_addr;
|
||||
AddressMapEntry *rom_reg;
|
||||
|
||||
rom_file.open(rom_filepath, ios::in | ios::binary);
|
||||
@@ -343,10 +346,16 @@ int MachineFactory::load_boot_rom(string& rom_filepath) {
|
||||
file_size = rom_file.tellg();
|
||||
rom_file.seekg(0, rom_file.beg);
|
||||
|
||||
if (file_size != 0x400000UL) {
|
||||
LOG_F(ERROR, "Unxpected ROM File size. Expected size is 4 megabytes.");
|
||||
result = -1;
|
||||
if (file_size == 0x400000UL) { // Old World ROMs
|
||||
rom_load_addr = 0xFFC00000UL;
|
||||
} else if (file_size == 0x100000UL) { // New World ROMs
|
||||
rom_load_addr = 0xFFF00000UL;
|
||||
} else {
|
||||
LOG_F(ERROR, "Unxpected ROM File size: %zu bytes.", file_size);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
unsigned char* sysrom_mem = new unsigned char[file_size];
|
||||
|
||||
rom_file.seekg(0, ios::beg);
|
||||
@@ -356,14 +365,13 @@ int MachineFactory::load_boot_rom(string& rom_filepath) {
|
||||
gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
if ((rom_reg = mem_ctrl->find_rom_region())) {
|
||||
mem_ctrl->set_data(rom_reg->start, sysrom_mem, file_size);
|
||||
mem_ctrl->set_data(rom_load_addr, sysrom_mem, (uint32_t)file_size);
|
||||
} else {
|
||||
ABORT_F("Could not locate physical ROM region!");
|
||||
LOG_F(ERROR, "Could not locate physical ROM region!");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
delete[] sysrom_mem;
|
||||
|
||||
result = 0;
|
||||
}
|
||||
|
||||
rom_file.close();
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Constructs a Gazelle style machine. This family includes
|
||||
Power Macintosh 5500, 6500 and Twentieth Anniversary Mac.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/memctrl/psx.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
// TODO: move it to /cpu/ppc
|
||||
int get_cpu_pll_value(const uint64_t cpu_freq_hz) {
|
||||
switch (cpu_freq_hz / 1000000) {
|
||||
case 225:
|
||||
return 7; // 4.5:1 ratio
|
||||
case 250:
|
||||
return 11; // 5:1 ratio
|
||||
case 275:
|
||||
return 9; // 5.5:1 ratio
|
||||
default:
|
||||
ABORT_F("Unsupported CPU frequency %llu Hz", cpu_freq_hz);
|
||||
}
|
||||
}
|
||||
|
||||
int initialize_gazelle(std::string& id)
|
||||
{
|
||||
LOG_F(INFO, "Building machine Gazelle...");
|
||||
|
||||
PCIHost *pci_host = dynamic_cast<PCIHost*>(gMachineObj->get_comp_by_name("PsxPci1"));
|
||||
|
||||
// register O'Hare I/O controller with the main PCI bus
|
||||
pci_host->pci_register_device(
|
||||
DEV_FUN(0x10,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("OHare")));
|
||||
|
||||
PsxCtrl* psx_obj = dynamic_cast<PsxCtrl*>(gMachineObj->get_comp_by_name("Psx"));
|
||||
|
||||
// allocate ROM region
|
||||
if (!psx_obj->add_rom_region(0xFFC00000, 0x400000)) {
|
||||
LOG_F(ERROR, "Could not allocate ROM region!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// plug 32MB RAM DIMM into slot #0
|
||||
psx_obj->insert_ram_dimm(0, DRAM_CAP_32MB);
|
||||
|
||||
// allocate and map physical RAM
|
||||
psx_obj->map_phys_ram();
|
||||
|
||||
// configure CPU clocks
|
||||
uint64_t bus_freq = 50000000ULL;
|
||||
uint64_t timebase_freq = bus_freq / 4;
|
||||
|
||||
// init virtual CPU and request MPC603ev
|
||||
ppc_cpu_init(psx_obj, PPC_VER::MPC603EV, timebase_freq);
|
||||
|
||||
// CPU frequency is hardcoded to 225 MHz for now
|
||||
ppc_state.spr[SPR::HID1] = get_cpu_pll_value(225000000) << 28;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const PropMap pm6500_settings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(16, vector<uint32_t>({4, 8, 16, 32, 64, 128}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
|
||||
{"rambank3_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
|
||||
{"rambank4_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
|
||||
{"gfxmem_size",
|
||||
new IntProperty( 1, vector<uint32_t>({1, 2, 4}))},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
};
|
||||
|
||||
static vector<string> pm6500_devices = {
|
||||
"Psx", "PsxPci1", "OHare"
|
||||
};
|
||||
|
||||
static const MachineDescription pm6500_descriptor = {
|
||||
.name = "pm6500",
|
||||
.description = "Power Macintosh 6500",
|
||||
.devices = pm6500_devices,
|
||||
.settings = pm6500_settings,
|
||||
.init_func = &initialize_gazelle
|
||||
};
|
||||
|
||||
REGISTER_MACHINE(pm6500, pm6500_descriptor);
|
||||
@@ -92,6 +92,8 @@ static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
||||
|
||||
int initialize_gossamer(std::string& id)
|
||||
{
|
||||
LOG_F(INFO, "Building machine Gossamer...");
|
||||
|
||||
// get pointer to the memory controller/PCI host bridge object
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
|
||||
|
||||
@@ -105,7 +107,7 @@ int initialize_gossamer(std::string& id)
|
||||
|
||||
gMachineObj->add_device("MachineID", std::unique_ptr<GossamerID>(new GossamerID(sys_reg)));
|
||||
grackle_obj->add_mmio_region(
|
||||
0xFF000004, 4096, dynamic_cast<MMIODevice*>(gMachineObj->get_comp_by_name("MachineID")));
|
||||
0xFF000000, 4096, dynamic_cast<MMIODevice*>(gMachineObj->get_comp_by_name("MachineID")));
|
||||
|
||||
// allocate ROM region
|
||||
if (!grackle_obj->add_rom_region(0xFFC00000, 0x400000)) {
|
||||
@@ -120,9 +122,9 @@ int initialize_gossamer(std::string& id)
|
||||
|
||||
// add pci devices
|
||||
grackle_obj->pci_register_device(
|
||||
16, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||
DEV_FUN(0x10,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||
grackle_obj->pci_register_device(
|
||||
18, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(id == "pmg3twr" ? "AtiRagePro" : "AtiRageGT")));
|
||||
DEV_FUN(0x12,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(id == "pmg3twr" ? "AtiRagePro" : "AtiRageGT")));
|
||||
|
||||
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
|
||||
|
||||
@@ -164,7 +166,7 @@ static const PropMap gossamer_settings = {
|
||||
};
|
||||
|
||||
static vector<string> pmg3_devices = {
|
||||
"Grackle", "Heathrow", "AtiRageGT"
|
||||
"Grackle", "ScreamerSnd", "Heathrow", "AtiRageGT"
|
||||
};
|
||||
|
||||
static const MachineDescription pmg3dt_descriptor = {
|
||||
|
||||
@@ -40,6 +40,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
int initialize_pdm(std::string& id)
|
||||
{
|
||||
LOG_F(INFO, "Building machine PDM...");
|
||||
|
||||
uint16_t machine_id;
|
||||
|
||||
// get raw pointer to HMC object
|
||||
|
||||
@@ -73,7 +73,7 @@ bool StrProperty::check_val(std::string str)
|
||||
uint32_t IntProperty::get_int()
|
||||
{
|
||||
try {
|
||||
uint32_t result = strtoul(this->get_string().c_str(), 0, 0);
|
||||
uint32_t result = (uint32_t)strtoul(this->get_string().c_str(), 0, 0);
|
||||
|
||||
/* perform value check */
|
||||
if (!this->check_val(result)) {
|
||||
|
||||
@@ -36,20 +36,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
int initialize_tnt(std::string& id)
|
||||
{
|
||||
LOG_F(INFO, "Building machine TNT...");
|
||||
|
||||
HammerheadCtrl* memctrl_obj;
|
||||
|
||||
PCIHost *pci_host = dynamic_cast<PCIHost*>(gMachineObj->get_comp_by_name("Bandit1"));
|
||||
|
||||
// connect GrandCentral I/O controller to the PCI1 bus
|
||||
pci_host->pci_register_device(
|
||||
32, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("GrandCentral")));
|
||||
DEV_FUN(0x10,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("GrandCentral")));
|
||||
|
||||
// get video PCI controller object
|
||||
PCIHost *vci_host = dynamic_cast<PCIHost*>(gMachineObj->get_comp_by_name("Chaos"));
|
||||
|
||||
// connect built-in video device to the VCI bus
|
||||
vci_host->pci_register_device(
|
||||
1, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("ControlVideo")));
|
||||
DEV_FUN(0x0B,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("ControlVideo")));
|
||||
|
||||
// get (raw) pointer to the memory controller
|
||||
memctrl_obj = dynamic_cast<HammerheadCtrl*>(gMachineObj->get_comp_by_name("Hammerhead"));
|
||||
@@ -60,8 +62,8 @@ int initialize_tnt(std::string& id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// plug 8MB RAM DIMM into slot #0
|
||||
memctrl_obj->insert_ram_dimm(2, DRAM_CAP_16MB);
|
||||
// plug 16MB RAM DIMM into slot #0
|
||||
memctrl_obj->insert_ram_dimm(0, DRAM_CAP_16MB);
|
||||
|
||||
// allocate and map physical RAM
|
||||
memctrl_obj->map_phys_ram();
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 the Yosemite machine (Power Macintosh G3 Blue & White). */
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/pci/dec21154.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <devices/memctrl/spdram.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
||||
if (!capacity_megs)
|
||||
return;
|
||||
|
||||
gMachineObj->add_device(name, std::unique_ptr<SpdSdram168>(new SpdSdram168(i2c_addr)));
|
||||
SpdSdram168* ram_dimm = dynamic_cast<SpdSdram168*>(gMachineObj->get_comp_by_name(name));
|
||||
ram_dimm->set_capacity(capacity_megs);
|
||||
|
||||
// register RAM DIMM with the I2C bus
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(i2c_addr, ram_dimm);
|
||||
}
|
||||
|
||||
int initialize_yosemite(std::string& id)
|
||||
{
|
||||
LOG_F(INFO, "Building machine Yosemite...");
|
||||
|
||||
// get pointer to the memory controller/primary PCI bridge object
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
|
||||
|
||||
// get pointer to the bridge of the secondary PCI bus
|
||||
DecPciBridge *sec_bridge = dynamic_cast<DecPciBridge*>(gMachineObj->get_comp_by_name("Dec21154"));
|
||||
|
||||
// connect PCI devices
|
||||
grackle_obj->pci_register_device(DEV_FUN(13,0),
|
||||
dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Dec21154")));
|
||||
|
||||
sec_bridge->pci_register_device(DEV_FUN(5,0),
|
||||
dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||
|
||||
// allocate ROM region
|
||||
if (!grackle_obj->add_rom_region(0xFFF00000, 0x100000)) {
|
||||
LOG_F(ERROR, "Could not allocate ROM region!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// configure RAM slots
|
||||
setup_ram_slot("RAM_DIMM_1", 0x50, GET_INT_PROP("rambank1_size"));
|
||||
setup_ram_slot("RAM_DIMM_2", 0x51, GET_INT_PROP("rambank2_size"));
|
||||
setup_ram_slot("RAM_DIMM_3", 0x52, GET_INT_PROP("rambank3_size"));
|
||||
setup_ram_slot("RAM_DIMM_4", 0x53, GET_INT_PROP("rambank4_size"));
|
||||
|
||||
// configure CPU clocks
|
||||
uint64_t bus_freq = 66820000ULL;
|
||||
uint64_t timebase_freq = bus_freq / 4;
|
||||
|
||||
// initialize virtual CPU and request MPC750 CPU aka G3
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, timebase_freq);
|
||||
|
||||
// set CPU PLL ratio to 3.5
|
||||
ppc_state.spr[SPR::HID1] = 0xE << 28;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const PropMap yosemite_settings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(256, vector<uint32_t>({8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank3_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank4_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
};
|
||||
|
||||
static vector<string> pmg3nw_devices = {
|
||||
"Grackle", "Dec21154", "BurgundySnd", "Heathrow"
|
||||
};
|
||||
|
||||
static const MachineDescription pmg3nw_descriptor = {
|
||||
.name = "pmg3dt",
|
||||
.description = "Power Macintosh G3 Blue and White",
|
||||
.devices = pmg3nw_devices,
|
||||
.settings = yosemite_settings,
|
||||
.init_func = &initialize_yosemite
|
||||
};
|
||||
|
||||
REGISTER_MACHINE(pmg3nw, pmg3nw_descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,11 +22,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// The main runfile - main.cpp
|
||||
// This is where the magic begins
|
||||
|
||||
#include "debugger/debugger.h"
|
||||
#include "machines/machinefactory.h"
|
||||
#include "machines/machineproperties.h"
|
||||
#include "utils/profiler.h"
|
||||
#include "ppcemu.h"
|
||||
#include <core/hostevents.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <debugger/debugger.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <utils/profiler.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
@@ -196,11 +199,15 @@ int main(int argc, char** argv) {
|
||||
// redirect SIGABRT to our own handler
|
||||
signal(SIGABRT, sigabrt_handler);
|
||||
|
||||
// set up system wide event polling using
|
||||
// default Macintosh polling rate of 11 ms
|
||||
TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(11), [] {
|
||||
EventManager::get_instance()->poll_events();
|
||||
});
|
||||
|
||||
switch (execution_mode) {
|
||||
case 0:
|
||||
for (;;) {
|
||||
ppc_exec();
|
||||
}
|
||||
ppc_exec();
|
||||
break;
|
||||
case 1:
|
||||
enter_debugger();
|
||||
|
||||
Vendored
-16
@@ -1,16 +0,0 @@
|
||||
|
||||
Bugs are now managed in the SDL bug tracker, here:
|
||||
|
||||
https://bugzilla.libsdl.org/
|
||||
|
||||
You may report bugs there, and search to see if a given issue has already
|
||||
been reported, discussed, and maybe even fixed.
|
||||
|
||||
|
||||
You may also find help at the SDL forums/mailing list:
|
||||
|
||||
https://discourse.libsdl.org/
|
||||
|
||||
Bug reports are welcome here, but we really appreciate if you use Bugzilla, as
|
||||
bugs discussed on the mailing list may be forgotten or missed.
|
||||
|
||||
Vendored
-20
@@ -1,20 +0,0 @@
|
||||
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <[email protected]>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Vendored
-13
@@ -1,13 +0,0 @@
|
||||
|
||||
Please distribute this file with the SDL runtime environment:
|
||||
|
||||
The Simple DirectMedia Layer (SDL for short) is a cross-platform library
|
||||
designed to make it easy to write multi-media software, such as games
|
||||
and emulators.
|
||||
|
||||
The Simple DirectMedia Layer library source code is available from:
|
||||
https://www.libsdl.org/
|
||||
|
||||
This library is distributed under the terms of the zlib license:
|
||||
http://www.zlib.net/zlib_license.html
|
||||
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
|
||||
Simple DirectMedia Layer
|
||||
|
||||
(SDL)
|
||||
|
||||
Version 2.0
|
||||
|
||||
---
|
||||
https://www.libsdl.org/
|
||||
|
||||
Simple DirectMedia Layer is a cross-platform development library designed
|
||||
to provide low level access to audio, keyboard, mouse, joystick, and graphics
|
||||
hardware via OpenGL and Direct3D. It is used by video playback software,
|
||||
emulators, and popular games including Valve's award winning catalog
|
||||
and many Humble Bundle games.
|
||||
|
||||
More extensive documentation is available in the docs directory, starting
|
||||
with README.md
|
||||
|
||||
Enjoy!
|
||||
Sam Lantinga ([email protected])
|
||||
Vendored
-529
@@ -1,529 +0,0 @@
|
||||
|
||||
This is a list of major changes in SDL's version history.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.12:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* Added SDL_GetTextureScaleMode() and SDL_SetTextureScaleMode() to get and set the scaling mode used for a texture
|
||||
* Added SDL_LockTextureToSurface(), similar to SDL_LockTexture() but the locked area is exposed as a SDL surface.
|
||||
* Added new blend mode, SDL_BLENDMODE_MUL, which does a modulate and blend operation
|
||||
* Added the hint SDL_HINT_DISPLAY_USABLE_BOUNDS to override the results of SDL_GetDisplayUsableBounds() for display index 0.
|
||||
* Added the window underneath the finger to the SDL_TouchFingerEvent
|
||||
* Added SDL_GameControllerTypeForIndex(), SDL_GameControllerGetType() to return the type of a game controller (Xbox 360, Xbox One, PS3, PS4, or Nintendo Switch Pro)
|
||||
* Added the hint SDL_HINT_GAMECONTROLLERTYPE to override the automatic game controller type detection
|
||||
* Added SDL_JoystickFromPlayerIndex() and SDL_GameControllerFromPlayerIndex() to get the device associated with a player index
|
||||
* Added SDL_JoystickSetPlayerIndex() and SDL_GameControllerSetPlayerIndex() to set the player index associated with a device
|
||||
* Added the hint SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS to specify whether Nintendo Switch Pro controllers should use the buttons as labeled or swapped to match positional layout. The default is to use the buttons as labeled.
|
||||
* Added support for Nintendo GameCube controllers to the HIDAPI driver, and a hint SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE to control whether this is used.
|
||||
* Improved support for Xbox 360 and Xbox One controllers when using the HIDAPI driver
|
||||
* Added support for many game controllers, including:
|
||||
* 8BitDo FC30 Pro
|
||||
* 8BitDo M30 GamePad
|
||||
* BDA PS4 Fightpad
|
||||
* HORI Fighting Commander
|
||||
* Hyperkin Duke
|
||||
* Hyperkin X91
|
||||
* MOGA XP5-A Plus
|
||||
* NACON GC-400ES
|
||||
* NVIDIA Controller v01.04
|
||||
* PDP Versus Fighting Pad
|
||||
* Razer Raion Fightpad for PS4
|
||||
* Razer Serval
|
||||
* Stadia Controller
|
||||
* SteelSeries Stratus Duo
|
||||
* Victrix Pro Fight Stick for PS4
|
||||
* Xbox One Elite Series 2
|
||||
* Fixed blocking game controller rumble calls when using the HIDAPI driver
|
||||
* Added SDL_zeroa() macro to zero an array of elements
|
||||
* Added SDL_HasARMSIMD() which returns true if the CPU has ARM SIMD (ARMv6+) features
|
||||
|
||||
Windows:
|
||||
* Fixed crash when using the release SDL DLL with applications built with gcc
|
||||
* Fixed performance regression in event handling introduced in 2.0.10
|
||||
* Added support for SDL_SetThreadPriority() for UWP applications
|
||||
|
||||
Linux:
|
||||
* Added the hint SDL_HINT_VIDEO_X11_WINDOW_VISUALID to specify the visual chosen for new X11 windows
|
||||
* Added the hint SDL_HINT_VIDEO_X11_FORCE_EGL to specify whether X11 should use GLX or EGL by default
|
||||
|
||||
iOS / tvOS / macOS:
|
||||
* Added SDL_Metal_CreateView() and SDL_Metal_DestroyView() to create CAMetalLayer-backed NSView/UIView and attach it to the specified window.
|
||||
|
||||
iOS/ tvOS:
|
||||
* Added support for Bluetooth Steam Controllers as game controllers
|
||||
|
||||
tvOS:
|
||||
* Fixed support for surround sound on Apple TV
|
||||
|
||||
Android:
|
||||
* Added SDL_GetAndroidSDKVersion() to return the API level of the current device
|
||||
* Added support for audio capture using OpenSL-ES
|
||||
* Added support for Bluetooth Steam Controllers as game controllers
|
||||
* Fixed rare crashes when the app goes into the background or terminates
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.10:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* The SDL_RW* macros have been turned into functions that are available only in 2.0.10 and onward
|
||||
* Added SDL_SIMDGetAlignment(), SDL_SIMDAlloc(), and SDL_SIMDFree(), to allocate memory aligned for SIMD operations for the current CPU
|
||||
* Added SDL_RenderDrawPointF(), SDL_RenderDrawPointsF(), SDL_RenderDrawLineF(), SDL_RenderDrawLinesF(), SDL_RenderDrawRectF(), SDL_RenderDrawRectsF(), SDL_RenderFillRectF(), SDL_RenderFillRectsF(), SDL_RenderCopyF(), SDL_RenderCopyExF(), to allow floating point precision in the SDL rendering API.
|
||||
* Added SDL_GetTouchDeviceType() to get the type of a touch device, which can be a touch screen or a trackpad in relative or absolute coordinate mode.
|
||||
* The SDL rendering API now uses batched rendering by default, for improved performance
|
||||
* Added SDL_RenderFlush() to force batched render commands to execute, if you're going to mix SDL rendering with native rendering
|
||||
* Added the hint SDL_HINT_RENDER_BATCHING to control whether batching should be used for the rendering API. This defaults to "1" if you don't specify what rendering driver to use when creating the renderer.
|
||||
* Added the hint SDL_HINT_EVENT_LOGGING to enable logging of SDL events for debugging purposes
|
||||
* Added the hint SDL_HINT_GAMECONTROLLERCONFIG_FILE to specify a file that will be loaded at joystick initialization with game controller bindings
|
||||
* Added the hint SDL_HINT_MOUSE_TOUCH_EVENTS to control whether SDL will synthesize touch events from mouse events
|
||||
* Improved handling of malformed WAVE and BMP files, fixing potential security exploits
|
||||
|
||||
Linux:
|
||||
* Removed the Mir video driver in favor of Wayland
|
||||
|
||||
iOS / tvOS:
|
||||
* Added support for Xbox and PS4 wireless controllers in iOS 13 and tvOS 13
|
||||
* Added support for text input using Bluetooth keyboards
|
||||
|
||||
Android:
|
||||
* Added low latency audio using OpenSL ES
|
||||
* Removed SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH (replaced by SDL_HINT_MOUSE_TOUCH_EVENTS and SDL_HINT_TOUCH_MOUSE_EVENTS)
|
||||
SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH=1, should be replaced by setting both previous hints to 0.
|
||||
SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH=0, should be replaced by setting both previous hints to 1.
|
||||
* Added the hint SDL_HINT_ANDROID_BLOCK_ON_PAUSE to set whether the event loop will block itself when the app is paused.
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.9:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* Added a new sensor API, initialized by passing SDL_INIT_SENSOR to SDL_Init(), and defined in SDL_sensor.h
|
||||
* Added an event SDL_SENSORUPDATE which is sent when a sensor is updated
|
||||
* Added SDL_GetDisplayOrientation() to return the current display orientation
|
||||
* Added an event SDL_DISPLAYEVENT which is sent when the display orientation changes
|
||||
* Added HIDAPI joystick drivers for more consistent support for Xbox, PS4 and Nintendo Switch Pro controller support across platforms. (Thanks to Valve for contributing the PS4 and Nintendo Switch Pro controller support)
|
||||
* Added support for many other popular game controllers
|
||||
* Added SDL_JoystickGetDevicePlayerIndex(), SDL_JoystickGetPlayerIndex(), and SDL_GameControllerGetPlayerIndex() to get the player index for a controller. For XInput controllers this returns the XInput index for the controller.
|
||||
* Added SDL_GameControllerRumble() and SDL_JoystickRumble() which allow simple rumble without using the haptics API
|
||||
* Added SDL_GameControllerMappingForDeviceIndex() to get the mapping for a controller before it's opened
|
||||
* Added the hint SDL_HINT_MOUSE_DOUBLE_CLICK_TIME to control the mouse double-click time
|
||||
* Added the hint SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS to control the mouse double-click radius, in pixels
|
||||
* Added SDL_HasColorKey() to return whether a surface has a colorkey active
|
||||
* Added SDL_HasAVX512F() to return whether the CPU has AVX-512F features
|
||||
* Added SDL_IsTablet() to return whether the application is running on a tablet
|
||||
* Added SDL_THREAD_PRIORITY_TIME_CRITICAL for threads that must run at the highest priority
|
||||
|
||||
Mac OS X:
|
||||
* Fixed black screen at start on Mac OS X Mojave
|
||||
|
||||
Linux:
|
||||
* Added SDL_LinuxSetThreadPriority() to allow adjusting the thread priority of native threads using RealtimeKit if available.
|
||||
|
||||
iOS:
|
||||
* Fixed Asian IME input
|
||||
|
||||
Android:
|
||||
* Updated required Android SDK to API 26, to match Google's new App Store requirements
|
||||
* Added support for wired USB Xbox, PS4, and Nintendo Switch Pro controllers
|
||||
* Added support for relative mouse mode on Android 7.0 and newer (except where it's broken, on Chromebooks and when in DeX mode with Samsung Experience 9.0)
|
||||
* Added support for custom mouse cursors on Android 7.0 and newer
|
||||
* Added the hint SDL_HINT_ANDROID_TRAP_BACK_BUTTON to control whether the back button will back out of the app (the default) or be passed to the application as SDL_SCANCODE_AC_BACK
|
||||
* Added SDL_AndroidBackButton() to trigger the Android system back button behavior when handling the back button in the application
|
||||
* Added SDL_IsChromebook() to return whether the app is running in the Chromebook Android runtime
|
||||
* Added SDL_IsDeXMode() to return whether the app is running while docked in the Samsung DeX
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.8:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* Added SDL_fmod() and SDL_log10()
|
||||
* Each of the SDL math functions now has the corresponding float version
|
||||
* Added SDL_SetYUVConversionMode() and SDL_GetYUVConversionMode() to control the formula used when converting to and from YUV colorspace. The options are JPEG, BT.601, and BT.709
|
||||
|
||||
Windows:
|
||||
* Implemented WASAPI support on Windows UWP and removed the deprecated XAudio2 implementation
|
||||
* Added resampling support on WASAPI on Windows 7 and above
|
||||
|
||||
Windows UWP:
|
||||
* Added SDL_WinRTGetDeviceFamily() to find out what type of device your application is running on
|
||||
|
||||
Mac OS X:
|
||||
* Added support for the Vulkan SDK for Mac:
|
||||
https://www.lunarg.com/lunarg-releases-vulkan-sdk-1-0-69-0-for-mac/
|
||||
* Added support for OpenGL ES using ANGLE when it's available
|
||||
|
||||
Mac OS X / iOS / tvOS:
|
||||
* Added a Metal 2D render implementation
|
||||
* Added SDL_RenderGetMetalLayer() and SDL_RenderGetMetalCommandEncoder() to insert your own drawing into SDL rendering when using the Metal implementation
|
||||
|
||||
iOS:
|
||||
* Added the hint SDL_HINT_IOS_HIDE_HOME_INDICATOR to control whether the home indicator bar on iPhone X should be hidden. This defaults to dimming the indicator for fullscreen applications and showing the indicator for windowed applications.
|
||||
|
||||
iOS / Android:
|
||||
* Added the hint SDL_HINT_RETURN_KEY_HIDES_IME to control whether the return key on the software keyboard should hide the keyboard or send a key event (the default)
|
||||
|
||||
Android:
|
||||
* SDL now supports building with Android Studio and Gradle by default, and the old Ant project is available in android-project-ant
|
||||
* SDL now requires the API 19 SDK to build, but can still target devices down to API 14 (Android 4.0.1)
|
||||
* Added SDL_IsAndroidTV() to tell whether the application is running on Android TV
|
||||
|
||||
Android / tvOS:
|
||||
* Added the hint SDL_HINT_TV_REMOTE_AS_JOYSTICK to control whether TV remotes should be listed as joystick devices (the default) or send keyboard events.
|
||||
|
||||
Linux:
|
||||
* Added the hint SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR to control whether the X server should skip the compositor for the SDL application. This defaults to "1"
|
||||
* Added the hint SDL_HINT_VIDEO_DOUBLE_BUFFER to control whether the Raspberry Pi and KMSDRM video drivers should use double or triple buffering (the default)
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.7:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* Added audio stream conversion functions:
|
||||
SDL_NewAudioStream
|
||||
SDL_AudioStreamPut
|
||||
SDL_AudioStreamGet
|
||||
SDL_AudioStreamAvailable
|
||||
SDL_AudioStreamFlush
|
||||
SDL_AudioStreamClear
|
||||
SDL_FreeAudioStream
|
||||
* Added functions to query and set the SDL memory allocation functions:
|
||||
SDL_GetMemoryFunctions()
|
||||
SDL_SetMemoryFunctions()
|
||||
SDL_GetNumAllocations()
|
||||
* Added locking functions for multi-threaded access to the joystick and game controller APIs:
|
||||
SDL_LockJoysticks()
|
||||
SDL_UnlockJoysticks()
|
||||
* The following functions are now thread-safe:
|
||||
SDL_SetEventFilter()
|
||||
SDL_GetEventFilter()
|
||||
SDL_AddEventWatch()
|
||||
SDL_DelEventWatch()
|
||||
|
||||
|
||||
General:
|
||||
---------------------------------------------------------------------------
|
||||
2.0.6:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* Added cross-platform Vulkan graphics support in SDL_vulkan.h
|
||||
SDL_Vulkan_LoadLibrary()
|
||||
SDL_Vulkan_GetVkGetInstanceProcAddr()
|
||||
SDL_Vulkan_GetInstanceExtensions()
|
||||
SDL_Vulkan_CreateSurface()
|
||||
SDL_Vulkan_GetDrawableSize()
|
||||
SDL_Vulkan_UnloadLibrary()
|
||||
This is all the platform-specific code you need to bring up Vulkan on all SDL platforms. You can look at an example in test/testvulkan.c
|
||||
* Added SDL_ComposeCustomBlendMode() to create custom blend modes for 2D rendering
|
||||
* Added SDL_HasNEON() which returns whether the CPU has NEON instruction support
|
||||
* Added support for many game controllers, including the Nintendo Switch Pro Controller
|
||||
* Added support for inverted axes and separate axis directions in game controller mappings
|
||||
* Added functions to return information about a joystick before it's opened:
|
||||
SDL_JoystickGetDeviceVendor()
|
||||
SDL_JoystickGetDeviceProduct()
|
||||
SDL_JoystickGetDeviceProductVersion()
|
||||
SDL_JoystickGetDeviceType()
|
||||
SDL_JoystickGetDeviceInstanceID()
|
||||
* Added functions to return information about an open joystick:
|
||||
SDL_JoystickGetVendor()
|
||||
SDL_JoystickGetProduct()
|
||||
SDL_JoystickGetProductVersion()
|
||||
SDL_JoystickGetType()
|
||||
SDL_JoystickGetAxisInitialState()
|
||||
* Added functions to return information about an open game controller:
|
||||
SDL_GameControllerGetVendor()
|
||||
SDL_GameControllerGetProduct()
|
||||
SDL_GameControllerGetProductVersion()
|
||||
* Added SDL_GameControllerNumMappings() and SDL_GameControllerMappingForIndex() to be able to enumerate the built-in game controller mappings
|
||||
* Added SDL_LoadFile() and SDL_LoadFile_RW() to load a file into memory
|
||||
* Added SDL_DuplicateSurface() to make a copy of a surface
|
||||
* Added an experimental JACK audio driver
|
||||
* Implemented non-power-of-two audio resampling, optionally using libsamplerate to perform the resampling
|
||||
* Added the hint SDL_HINT_AUDIO_RESAMPLING_MODE to control the quality of resampling
|
||||
* Added the hint SDL_HINT_RENDER_LOGICAL_SIZE_MODE to control the scaling policy for SDL_RenderSetLogicalSize():
|
||||
"0" or "letterbox" - Uses letterbox/sidebars to fit the entire rendering on screen (the default)
|
||||
"1" or "overscan" - Will zoom the rendering so it fills the entire screen, allowing edges to be drawn offscreen
|
||||
* Added the hints SDL_HINT_MOUSE_NORMAL_SPEED_SCALE and SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE to scale the mouse speed when being read from raw mouse input
|
||||
* Added the hint SDL_HINT_TOUCH_MOUSE_EVENTS to control whether SDL will synthesize mouse events from touch events
|
||||
|
||||
Windows:
|
||||
* The new default audio driver on Windows is WASAPI and supports hot-plugging devices and changing the default audio device
|
||||
* The old XAudio2 audio driver is deprecated and will be removed in the next release
|
||||
* Added hints SDL_HINT_WINDOWS_INTRESOURCE_ICON and SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL to specify a custom icon resource ID for SDL windows
|
||||
* The hint SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING is now on by default for compatibility with .NET languages and various Windows debuggers
|
||||
* Updated the GUID format for game controller mappings, older mappings will be automatically converted on load
|
||||
* Implemented the SDL_WINDOW_ALWAYS_ON_TOP flag on Windows
|
||||
|
||||
Linux:
|
||||
* Added an experimental KMS/DRM video driver for embedded development
|
||||
|
||||
iOS:
|
||||
* Added a hint SDL_HINT_AUDIO_CATEGORY to control the audio category, determining whether the phone mute switch affects the audio
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.5:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* Implemented audio capture support for some platforms
|
||||
* Added SDL_DequeueAudio() to retrieve audio when buffer queuing is turned on for audio capture
|
||||
* Added events for dragging and dropping text
|
||||
* Added events for dragging and dropping multiple items
|
||||
* By default the click raising a window will not be delivered to the SDL application. You can set the hint SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH to "1" to allow that click through to the window.
|
||||
* Saving a surface with an alpha channel as a BMP will use a newer BMP format that supports alpha information. You can set the hint SDL_HINT_BMP_SAVE_LEGACY_FORMAT to "1" to use the old format.
|
||||
* Added SDL_GetHintBoolean() to get the boolean value of a hint
|
||||
* Added SDL_RenderSetIntegerScale() to set whether to smoothly scale or use integral multiples of the viewport size when scaling the rendering output
|
||||
* Added SDL_CreateRGBSurfaceWithFormat() and SDL_CreateRGBSurfaceWithFormatFrom() to create an SDL surface with a specific pixel format
|
||||
* Added SDL_GetDisplayUsableBounds() which returns the area usable for windows. For example, on Mac OS X, this subtracts the area occupied by the menu bar and dock.
|
||||
* Added SDL_GetWindowBordersSize() which returns the size of the window's borders around the client area
|
||||
* Added a window event SDL_WINDOWEVENT_HIT_TEST when a window had a hit test that wasn't SDL_HITTEST_NORMAL (e.g. in the title bar or window frame)
|
||||
* Added SDL_SetWindowResizable() to change whether a window is resizable
|
||||
* Added SDL_SetWindowOpacity() and SDL_GetWindowOpacity() to affect the window transparency
|
||||
* Added SDL_SetWindowModalFor() to set a window as modal for another window
|
||||
* Added support for AUDIO_U16LSB and AUDIO_U16MSB to SDL_MixAudioFormat()
|
||||
* Fixed flipped images when reading back from target textures when using the OpenGL renderer
|
||||
* Fixed texture color modulation with SDL_BLENDMODE_NONE when using the OpenGL renderer
|
||||
* Fixed bug where the alpha value of colorkeys was ignored when blitting in some cases
|
||||
|
||||
Windows:
|
||||
* Added a hint SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING to prevent SDL from raising a debugger exception to name threads. This exception can cause problems with .NET applications when running under a debugger.
|
||||
* The hint SDL_HINT_THREAD_STACK_SIZE is now supported on Windows
|
||||
* Fixed XBox controller triggers automatically being pulled at startup
|
||||
* The first icon from the executable is used as the default window icon at runtime
|
||||
* Fixed SDL log messages being printed twice if SDL was built with C library support
|
||||
* Reset dead keys when the SDL window loses focus, so dead keys pressed in SDL applications don't affect text input into other applications.
|
||||
|
||||
Mac OS X:
|
||||
* Fixed selecting the dummy video driver
|
||||
* The caps lock key now generates a pressed event when pressed and a released event when released, instead of a press/release event pair when pressed.
|
||||
* Fixed mouse wheel events on Mac OS X 10.12
|
||||
* The audio driver has been updated to use AVFoundation for better compatibility with newer versions of Mac OS X
|
||||
|
||||
Linux:
|
||||
* Added support for the Fcitx IME
|
||||
* Added a window event SDL_WINDOWEVENT_TAKE_FOCUS when a window manager asks the SDL window whether it wants to take focus.
|
||||
* Refresh rates are now rounded instead of truncated, e.g. 59.94 Hz is rounded up to 60 Hz instead of 59.
|
||||
* Added initial support for touchscreens on Raspberry Pi
|
||||
|
||||
OpenBSD:
|
||||
* SDL_GetBasePath() is now implemented on OpenBSD
|
||||
|
||||
iOS:
|
||||
* Added support for dynamically loaded objects on iOS 8 and newer
|
||||
|
||||
tvOS:
|
||||
* Added support for Apple TV
|
||||
* Added a hint SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION to control whether he Apple TV remote's joystick axes will automatically match the rotation of the remote.
|
||||
|
||||
Android:
|
||||
* Fixed SDL not resizing window when Android screen resolution changes
|
||||
* Corrected the joystick Z axis reporting for the accelerometer
|
||||
|
||||
Emscripten (running in a web browser):
|
||||
* Many bug fixes and improvements
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.4:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* Added support for web applications using Emscripten, see docs/README-emscripten.md for more information
|
||||
* Added support for web applications using Native Client (NaCl), see docs/README-nacl.md for more information
|
||||
* Added an API to queue audio instead of using the audio callback:
|
||||
SDL_QueueAudio(), SDL_GetQueuedAudioSize(), SDL_ClearQueuedAudio()
|
||||
* Added events for audio device hot plug support:
|
||||
SDL_AUDIODEVICEADDED, SDL_AUDIODEVICEREMOVED
|
||||
* Added SDL_PointInRect()
|
||||
* Added SDL_HasAVX2() to detect CPUs with AVX2 support
|
||||
* Added SDL_SetWindowHitTest() to let apps treat parts of their SDL window like traditional window decorations (drag areas, resize areas)
|
||||
* Added SDL_GetGrabbedWindow() to get the window that currently has input grab, if any
|
||||
* Added SDL_RenderIsClipEnabled() to tell whether clipping is currently enabled in a renderer
|
||||
* Added SDL_CaptureMouse() to capture the mouse to get events while the mouse is not in your window
|
||||
* Added SDL_WarpMouseGlobal() to warp the mouse cursor in global screen space
|
||||
* Added SDL_GetGlobalMouseState() to get the current mouse state outside of an SDL window
|
||||
* Added a direction field to mouse wheel events to tell whether they are flipped (natural) or not
|
||||
* Added GL_CONTEXT_RELEASE_BEHAVIOR GL attribute (maps to [WGL|GLX]_ARB_context_flush_control extension)
|
||||
* Added EGL_KHR_create_context support to allow OpenGL ES version selection on some platforms
|
||||
* Added NV12 and NV21 YUV texture support for OpenGL and OpenGL ES 2.0 renderers
|
||||
* Added a Vivante video driver that is used on various SoC platforms
|
||||
* Added an event SDL_RENDER_DEVICE_RESET that is sent from the D3D renderers when the D3D device is lost, and from Android's event loop when the GLES context had to be recreated
|
||||
* Added a hint SDL_HINT_NO_SIGNAL_HANDLERS to disable SDL's built in signal handling
|
||||
* Added a hint SDL_HINT_THREAD_STACK_SIZE to set the stack size of SDL's threads
|
||||
* Added SDL_sqrtf(), SDL_tan(), and SDL_tanf() to the stdlib routines
|
||||
* Improved support for WAV and BMP files with unusual chunks in them
|
||||
* Renamed SDL_assert_data to SDL_AssertData and SDL_assert_state to SDL_AssertState
|
||||
* Added a hint SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN to prevent window interaction while cursor is hidden
|
||||
* Added SDL_GetDisplayDPI() to get the DPI information for a display
|
||||
* Added SDL_JoystickCurrentPowerLevel() to get the battery level of a joystick
|
||||
* Added SDL_JoystickFromInstanceID(), as a helper function, to get the SDL_Joystick* that an event is referring to.
|
||||
* Added SDL_GameControllerFromInstanceID(), as a helper function, to get the SDL_GameController* that an event is referring to.
|
||||
|
||||
Windows:
|
||||
* Added support for Windows Phone 8.1 and Windows 10/UWP (Universal Windows Platform)
|
||||
* Timer resolution is now 1 ms by default, adjustable with the SDL_HINT_TIMER_RESOLUTION hint
|
||||
* SDLmain no longer depends on the C runtime, so you can use the same .lib in both Debug and Release builds
|
||||
* Added SDL_SetWindowsMessageHook() to set a function to be called for every windows message before TranslateMessage()
|
||||
* Added a hint SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP to control whether SDL_PumpEvents() processes the Windows message loop
|
||||
* You can distinguish between real mouse and touch events by looking for SDL_TOUCH_MOUSEID in the mouse event "which" field
|
||||
* SDL_SysWMinfo now contains the window HDC
|
||||
* Added support for Unicode command line options
|
||||
* Prevent beeping when Alt-key combos are pressed
|
||||
* SDL_SetTextInputRect() re-positions the OS-rendered IME
|
||||
* Added a hint SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 to prevent generating SDL_WINDOWEVENT_CLOSE events when Alt-F4 is pressed
|
||||
* Added a hint SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING to use the old axis and button mapping for XInput devices (deprecated)
|
||||
|
||||
Mac OS X:
|
||||
* Implemented drag-and-drop support
|
||||
* Improved joystick hot-plug detection
|
||||
* The SDL_WINDOWEVENT_EXPOSED window event is triggered in the appropriate situations
|
||||
* Fixed relative mouse mode when the application loses/regains focus
|
||||
* Fixed bugs related to transitioning to and from Spaces-aware fullscreen-desktop mode
|
||||
* Fixed the refresh rate of display modes
|
||||
* SDL_SysWMInfo is now ARC-compatible
|
||||
* Added a hint SDL_HINT_MAC_BACKGROUND_APP to prevent forcing the application to become a foreground process
|
||||
|
||||
Linux:
|
||||
* Enabled building with Mir and Wayland support by default.
|
||||
* Added IBus IME support
|
||||
* Added a hint SDL_HINT_IME_INTERNAL_EDITING to control whether IBus should handle text editing internally instead of sending SDL_TEXTEDITING events
|
||||
* Added a hint SDL_HINT_VIDEO_X11_NET_WM_PING to allow disabling _NET_WM_PING protocol handling in SDL_CreateWindow()
|
||||
* Added support for multiple audio devices when using Pulseaudio
|
||||
* Fixed duplicate mouse events when using relative mouse motion
|
||||
|
||||
iOS:
|
||||
* Added support for iOS 8
|
||||
* The SDL_WINDOW_ALLOW_HIGHDPI window flag now enables high-dpi support, and SDL_GL_GetDrawableSize() or SDL_GetRendererOutputSize() gets the window resolution in pixels
|
||||
* SDL_GetWindowSize() and display mode sizes are in the "DPI-independent points" / "screen coordinates" coordinate space rather than pixels (matches OS X behavior)
|
||||
* Added native resolution support for the iPhone 6 Plus
|
||||
* Added support for MFi game controllers
|
||||
* Added support for the hint SDL_HINT_ACCELEROMETER_AS_JOYSTICK
|
||||
* Added sRGB OpenGL ES context support on iOS 7+
|
||||
* Added support for SDL_DisableScreenSaver(), SDL_EnableScreenSaver() and the hint SDL_HINT_VIDEO_ALLOW_SCREENSAVER
|
||||
* SDL_SysWMinfo now contains the OpenGL ES framebuffer and color renderbuffer objects used by the window's active GLES view
|
||||
* Fixed various rotation and orientation issues
|
||||
* Fixed memory leaks
|
||||
|
||||
Android:
|
||||
* Added a hint SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH to prevent mouse events from being registered as touch events
|
||||
* Added hints SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION and SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION
|
||||
* Added support for SDL_DisableScreenSaver(), SDL_EnableScreenSaver() and the hint SDL_HINT_VIDEO_ALLOW_SCREENSAVER
|
||||
* Added support for SDL_ShowMessageBox() and SDL_ShowSimpleMessageBox()
|
||||
|
||||
Raspberry Pi:
|
||||
* Added support for the Raspberry Pi 2
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.3:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Mac OS X:
|
||||
* Fixed creating an OpenGL context by default on Mac OS X 10.6
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.2:
|
||||
---------------------------------------------------------------------------
|
||||
General:
|
||||
* Added SDL_GL_ResetAttributes() to reset OpenGL attributes to default values
|
||||
* Added an API to load a database of game controller mappings from a file:
|
||||
SDL_GameControllerAddMappingsFromFile(), SDL_GameControllerAddMappingsFromRW()
|
||||
* Added game controller mappings for the PS4 and OUYA controllers
|
||||
* Added SDL_GetDefaultAssertionHandler() and SDL_GetAssertionHandler()
|
||||
* Added SDL_DetachThread()
|
||||
* Added SDL_HasAVX() to determine if the CPU has AVX features
|
||||
* Added SDL_vsscanf(), SDL_acos(), and SDL_asin() to the stdlib routines
|
||||
* EGL can now create/manage OpenGL and OpenGL ES 1.x/2.x contexts, and share
|
||||
them using SDL_GL_SHARE_WITH_CURRENT_CONTEXT
|
||||
* Added a field "clicks" to the mouse button event which records whether the event is a single click, double click, etc.
|
||||
* The screensaver is now disabled by default, and there is a hint SDL_HINT_VIDEO_ALLOW_SCREENSAVER that can change that behavior.
|
||||
* Added a hint SDL_HINT_MOUSE_RELATIVE_MODE_WARP to specify whether mouse relative mode should be emulated using mouse warping.
|
||||
* testgl2 does not need to link with libGL anymore
|
||||
* Added testgles2 test program to demonstrate working with OpenGL ES 2.0
|
||||
* Added controllermap test program to visually map a game controller
|
||||
|
||||
Windows:
|
||||
* Support for OpenGL ES 2.x contexts using either WGL or EGL (natively via
|
||||
the driver or emulated through ANGLE)
|
||||
* Added a hint SDL_HINT_VIDEO_WIN_D3DCOMPILER to specify which D3D shader compiler to use for OpenGL ES 2 support through ANGLE
|
||||
* Added a hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that is useful when creating multiple windows that should share the same OpenGL context.
|
||||
* Added an event SDL_RENDER_TARGETS_RESET that is sent when D3D9 render targets are reset after the device has been restored.
|
||||
|
||||
Mac OS X:
|
||||
* Added a hint SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK to control whether Ctrl+click should be treated as a right click on Mac OS X. This is off by default.
|
||||
|
||||
Linux:
|
||||
* Fixed fullscreen and focused behavior when receiving NotifyGrab events
|
||||
* Added experimental Wayland and Mir support, disabled by default
|
||||
|
||||
Android:
|
||||
* Joystick support (minimum SDK version required to build SDL is now 12,
|
||||
the required runtime version remains at 10, but on such devices joystick
|
||||
support won't be available).
|
||||
* Hotplugging support for joysticks
|
||||
* Added a hint SDL_HINT_ACCELEROMETER_AS_JOYSTICK to control whether the accelerometer should be listed as a 3 axis joystick, which it will by default.
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
2.0.1:
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
General:
|
||||
* Added an API to get common filesystem paths in SDL_filesystem.h:
|
||||
SDL_GetBasePath(), SDL_GetPrefPath()
|
||||
* Added an API to do optimized YV12 and IYUV texture updates:
|
||||
SDL_UpdateYUVTexture()
|
||||
* Added an API to get the amount of RAM on the system:
|
||||
SDL_GetSystemRAM()
|
||||
* Added a macro to perform timestamp comparisons with SDL_GetTicks():
|
||||
SDL_TICKS_PASSED()
|
||||
* Dramatically improved OpenGL ES 2.0 rendering performance
|
||||
* Added OpenGL attribute SDL_GL_FRAMEBUFFER_SRGB_CAPABLE
|
||||
|
||||
Windows:
|
||||
* Created a static library configuration for the Visual Studio 2010 project
|
||||
* Added a hint to create the Direct3D device with support for multi-threading:
|
||||
SDL_HINT_RENDER_DIRECT3D_THREADSAFE
|
||||
* Added a function to get the D3D9 adapter index for a display:
|
||||
SDL_Direct3D9GetAdapterIndex()
|
||||
* Added a function to get the D3D9 device for a D3D9 renderer:
|
||||
SDL_RenderGetD3D9Device()
|
||||
* Fixed building SDL with the mingw32 toolchain (mingw-w64 is preferred)
|
||||
* Fixed crash when using two XInput controllers at the same time
|
||||
* Fixed detecting a mixture of XInput and DirectInput controllers
|
||||
* Fixed clearing a D3D render target larger than the window
|
||||
* Improved support for format specifiers in SDL_snprintf()
|
||||
|
||||
Mac OS X:
|
||||
* Added support for retina displays:
|
||||
Create your window with the SDL_WINDOW_ALLOW_HIGHDPI flag, and then use SDL_GL_GetDrawableSize() to find the actual drawable size. You are responsible for scaling mouse and drawing coordinates appropriately.
|
||||
* Fixed mouse warping in fullscreen mode
|
||||
* Right mouse click is emulated by holding the Ctrl key while left clicking
|
||||
|
||||
Linux:
|
||||
* Fixed float audio support with the PulseAudio driver
|
||||
* Fixed missing line endpoints in the OpenGL renderer on some drivers
|
||||
* X11 symbols are no longer defined to avoid collisions when linking statically
|
||||
|
||||
iOS:
|
||||
* Fixed status bar visibility on iOS 7
|
||||
* Flipped the accelerometer Y axis to match expected values
|
||||
|
||||
Android:
|
||||
IMPORTANT: You MUST get the updated SDLActivity.java to match C code
|
||||
* Moved EGL initialization to native code
|
||||
* Fixed the accelerometer axis rotation relative to the device rotation
|
||||
* Fixed race conditions when handling the EGL context on pause/resume
|
||||
* Touch devices are available for enumeration immediately after init
|
||||
|
||||
Raspberry Pi:
|
||||
* Added support for the Raspberry Pi, see README-raspberrypi.txt for details
|
||||
-454
@@ -1,454 +0,0 @@
|
||||
Android
|
||||
================================================================================
|
||||
|
||||
Matt Styles wrote a tutorial on building SDL for Android with Visual Studio:
|
||||
http://trederia.blogspot.de/2017/03/building-sdl2-for-android-with-visual.html
|
||||
|
||||
The rest of this README covers the Android gradle style build process.
|
||||
|
||||
If you are using the older ant build process, it is no longer officially
|
||||
supported, but you can use the "android-project-ant" directory as a template.
|
||||
|
||||
|
||||
================================================================================
|
||||
Requirements
|
||||
================================================================================
|
||||
|
||||
Android SDK (version 26 or later)
|
||||
https://developer.android.com/sdk/index.html
|
||||
|
||||
Android NDK r15c or later
|
||||
https://developer.android.com/tools/sdk/ndk/index.html
|
||||
|
||||
Minimum API level supported by SDL: 16 (Android 4.1)
|
||||
|
||||
|
||||
================================================================================
|
||||
How the port works
|
||||
================================================================================
|
||||
|
||||
- Android applications are Java-based, optionally with parts written in C
|
||||
- As SDL apps are C-based, we use a small Java shim that uses JNI to talk to
|
||||
the SDL library
|
||||
- This means that your application C code must be placed inside an Android
|
||||
Java project, along with some C support code that communicates with Java
|
||||
- This eventually produces a standard Android .apk package
|
||||
|
||||
The Android Java code implements an "Activity" and can be found in:
|
||||
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
|
||||
|
||||
The Java code loads your game code, the SDL shared library, and
|
||||
dispatches to native functions implemented in the SDL library:
|
||||
src/core/android/SDL_android.c
|
||||
|
||||
|
||||
================================================================================
|
||||
Building an app
|
||||
================================================================================
|
||||
|
||||
For simple projects you can use the script located at build-scripts/androidbuild.sh
|
||||
|
||||
There's two ways of using it:
|
||||
|
||||
androidbuild.sh com.yourcompany.yourapp < sources.list
|
||||
androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c
|
||||
|
||||
sources.list should be a text file with a source file name in each line
|
||||
Filenames should be specified relative to the current directory, for example if
|
||||
you are in the build-scripts directory and want to create the testgles.c test, you'll
|
||||
run:
|
||||
|
||||
./androidbuild.sh org.libsdl.testgles ../test/testgles.c
|
||||
|
||||
One limitation of this script is that all sources provided will be aggregated into
|
||||
a single directory, thus all your source files should have a unique name.
|
||||
|
||||
Once the project is complete the script will tell you where the debug APK is located.
|
||||
If you want to create a signed release APK, you can use the project created by this
|
||||
utility to generate it.
|
||||
|
||||
Finally, a word of caution: re running androidbuild.sh wipes any changes you may have
|
||||
done in the build directory for the app!
|
||||
|
||||
|
||||
For more complex projects, follow these instructions:
|
||||
|
||||
1. Copy the android-project directory wherever you want to keep your projects
|
||||
and rename it to the name of your project.
|
||||
2. Move or symlink this SDL directory into the "<project>/app/jni" directory
|
||||
3. Edit "<project>/app/jni/src/Android.mk" to include your source files
|
||||
|
||||
4a. If you want to use Android Studio, simply open your <project> directory and start building.
|
||||
|
||||
4b. If you want to build manually, run './gradlew installDebug' in the project directory. This compiles the .java, creates an .apk with the native code embedded, and installs it on any connected Android device
|
||||
|
||||
|
||||
If you already have a project that uses CMake, the instructions change somewhat:
|
||||
|
||||
1. Do points 1 and 2 from the instruction above.
|
||||
2. Edit "<project>/app/build.gradle" to comment out or remove sections containing ndk-build
|
||||
and uncomment the cmake sections. Add arguments to the CMake invocation as needed.
|
||||
3. Edit "<project>/app/jni/CMakeLists.txt" to include your project (it defaults to
|
||||
adding the "src" subdirectory). Note that you'll have SDL2, SDL2main and SDL2-static
|
||||
as targets in your project, so you should have "target_link_libraries(yourgame SDL2 SDL2main)"
|
||||
in your CMakeLists.txt file. Also be aware that you should use add_library() instead of
|
||||
add_executable() for the target containing your "main" function.
|
||||
|
||||
If you wish to use Android Studio, you can skip the last step.
|
||||
|
||||
4. Run './gradlew installDebug' or './gradlew installRelease' in the project directory. It will build and install your .apk on any
|
||||
connected Android device
|
||||
|
||||
Here's an explanation of the files in the Android project, so you can customize them:
|
||||
|
||||
android-project/app
|
||||
build.gradle - build info including the application version and SDK
|
||||
src/main/AndroidManifest.xml - package manifest. Among others, it contains the class name of the main Activity and the package name of the application.
|
||||
jni/ - directory holding native code
|
||||
jni/Application.mk - Application JNI settings, including target platform and STL library
|
||||
jni/Android.mk - Android makefile that can call recursively the Android.mk files in all subdirectories
|
||||
jni/CMakeLists.txt - Top-level CMake project that adds SDL as a subproject
|
||||
jni/SDL/ - (symlink to) directory holding the SDL library files
|
||||
jni/SDL/Android.mk - Android makefile for creating the SDL shared library
|
||||
jni/src/ - directory holding your C/C++ source
|
||||
jni/src/Android.mk - Android makefile that you should customize to include your source code and any library references
|
||||
jni/src/CMakeLists.txt - CMake file that you may customize to include your source code and any library references
|
||||
src/main/assets/ - directory holding asset files for your application
|
||||
src/main/res/ - directory holding resources for your application
|
||||
src/main/res/mipmap-* - directories holding icons for different phone hardware
|
||||
src/main/res/values/strings.xml - strings used in your application, including the application name
|
||||
src/main/java/org/libsdl/app/SDLActivity.java - the Java class handling the initialization and binding to SDL. Be very careful changing this, as the SDL library relies on this implementation. You should instead subclass this for your application.
|
||||
|
||||
|
||||
================================================================================
|
||||
Customizing your application name
|
||||
================================================================================
|
||||
|
||||
To customize your application name, edit AndroidManifest.xml and replace
|
||||
"org.libsdl.app" with an identifier for your product package.
|
||||
|
||||
Then create a Java class extending SDLActivity and place it in a directory
|
||||
under src matching your package, e.g.
|
||||
|
||||
src/com/gamemaker/game/MyGame.java
|
||||
|
||||
Here's an example of a minimal class file:
|
||||
|
||||
--- MyGame.java --------------------------
|
||||
package com.gamemaker.game;
|
||||
|
||||
import org.libsdl.app.SDLActivity;
|
||||
|
||||
/**
|
||||
* A sample wrapper class that just calls SDLActivity
|
||||
*/
|
||||
|
||||
public class MyGame extends SDLActivity { }
|
||||
|
||||
------------------------------------------
|
||||
|
||||
Then replace "SDLActivity" in AndroidManifest.xml with the name of your
|
||||
class, .e.g. "MyGame"
|
||||
|
||||
|
||||
================================================================================
|
||||
Customizing your application icon
|
||||
================================================================================
|
||||
|
||||
Conceptually changing your icon is just replacing the "ic_launcher.png" files in
|
||||
the drawable directories under the res directory. There are several directories
|
||||
for different screen sizes.
|
||||
|
||||
|
||||
================================================================================
|
||||
Loading assets
|
||||
================================================================================
|
||||
|
||||
Any files you put in the "app/src/main/assets" directory of your project
|
||||
directory will get bundled into the application package and you can load
|
||||
them using the standard functions in SDL_rwops.h.
|
||||
|
||||
There are also a few Android specific functions that allow you to get other
|
||||
useful paths for saving and loading data:
|
||||
* SDL_AndroidGetInternalStoragePath()
|
||||
* SDL_AndroidGetExternalStorageState()
|
||||
* SDL_AndroidGetExternalStoragePath()
|
||||
|
||||
See SDL_system.h for more details on these functions.
|
||||
|
||||
The asset packaging system will, by default, compress certain file extensions.
|
||||
SDL includes two asset file access mechanisms, the preferred one is the so
|
||||
called "File Descriptor" method, which is faster and doesn't involve the Dalvik
|
||||
GC, but given this method does not work on compressed assets, there is also the
|
||||
"Input Stream" method, which is automatically used as a fall back by SDL. You
|
||||
may want to keep this fact in mind when building your APK, specially when large
|
||||
files are involved.
|
||||
For more information on which extensions get compressed by default and how to
|
||||
disable this behaviour, see for example:
|
||||
|
||||
http://ponystyle.com/blog/2010/03/26/dealing-with-asset-compression-in-android-apps/
|
||||
|
||||
|
||||
================================================================================
|
||||
Pause / Resume behaviour
|
||||
================================================================================
|
||||
|
||||
If SDL_HINT_ANDROID_BLOCK_ON_PAUSE hint is set (the default),
|
||||
the event loop will block itself when the app is paused (ie, when the user
|
||||
returns to the main Android dashboard). Blocking is better in terms of battery
|
||||
use, and it allows your app to spring back to life instantaneously after resume
|
||||
(versus polling for a resume message).
|
||||
|
||||
Upon resume, SDL will attempt to restore the GL context automatically.
|
||||
In modern devices (Android 3.0 and up) this will most likely succeed and your
|
||||
app can continue to operate as it was.
|
||||
|
||||
However, there's a chance (on older hardware, or on systems under heavy load),
|
||||
where the GL context can not be restored. In that case you have to listen for
|
||||
a specific message, (which is not yet implemented!) and restore your textures
|
||||
manually or quit the app (which is actually the kind of behaviour you'll see
|
||||
under iOS, if the OS can not restore your GL context it will just kill your app)
|
||||
|
||||
|
||||
================================================================================
|
||||
Threads and the Java VM
|
||||
================================================================================
|
||||
|
||||
For a quick tour on how Linux native threads interoperate with the Java VM, take
|
||||
a look here: https://developer.android.com/guide/practices/jni.html
|
||||
|
||||
If you want to use threads in your SDL app, it's strongly recommended that you
|
||||
do so by creating them using SDL functions. This way, the required attach/detach
|
||||
handling is managed by SDL automagically. If you have threads created by other
|
||||
means and they make calls to SDL functions, make sure that you call
|
||||
Android_JNI_SetupThread() before doing anything else otherwise SDL will attach
|
||||
your thread automatically anyway (when you make an SDL call), but it'll never
|
||||
detach it.
|
||||
|
||||
|
||||
================================================================================
|
||||
Using STL
|
||||
================================================================================
|
||||
|
||||
You can use STL in your project by creating an Application.mk file in the jni
|
||||
folder and adding the following line:
|
||||
|
||||
APP_STL := c++_shared
|
||||
|
||||
For more information go here:
|
||||
https://developer.android.com/ndk/guides/cpp-support
|
||||
|
||||
|
||||
================================================================================
|
||||
Using the emulator
|
||||
================================================================================
|
||||
|
||||
There are some good tips and tricks for getting the most out of the
|
||||
emulator here: https://developer.android.com/tools/devices/emulator.html
|
||||
|
||||
Especially useful is the info on setting up OpenGL ES 2.0 emulation.
|
||||
|
||||
Notice that this software emulator is incredibly slow and needs a lot of disk space.
|
||||
Using a real device works better.
|
||||
|
||||
|
||||
================================================================================
|
||||
Troubleshooting
|
||||
================================================================================
|
||||
|
||||
You can see if adb can see any devices with the following command:
|
||||
|
||||
adb devices
|
||||
|
||||
You can see the output of log messages on the default device with:
|
||||
|
||||
adb logcat
|
||||
|
||||
You can push files to the device with:
|
||||
|
||||
adb push local_file remote_path_and_file
|
||||
|
||||
You can push files to the SD Card at /sdcard, for example:
|
||||
|
||||
adb push moose.dat /sdcard/moose.dat
|
||||
|
||||
You can see the files on the SD card with a shell command:
|
||||
|
||||
adb shell ls /sdcard/
|
||||
|
||||
You can start a command shell on the default device with:
|
||||
|
||||
adb shell
|
||||
|
||||
You can remove the library files of your project (and not the SDL lib files) with:
|
||||
|
||||
ndk-build clean
|
||||
|
||||
You can do a build with the following command:
|
||||
|
||||
ndk-build
|
||||
|
||||
You can see the complete command line that ndk-build is using by passing V=1 on the command line:
|
||||
|
||||
ndk-build V=1
|
||||
|
||||
If your application crashes in native code, you can use ndk-stack to get a symbolic stack trace:
|
||||
https://developer.android.com/ndk/guides/ndk-stack
|
||||
|
||||
If you want to go through the process manually, you can use addr2line to convert the
|
||||
addresses in the stack trace to lines in your code.
|
||||
|
||||
For example, if your crash looks like this:
|
||||
|
||||
I/DEBUG ( 31): signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 400085d0
|
||||
I/DEBUG ( 31): r0 00000000 r1 00001000 r2 00000003 r3 400085d4
|
||||
I/DEBUG ( 31): r4 400085d0 r5 40008000 r6 afd41504 r7 436c6a7c
|
||||
I/DEBUG ( 31): r8 436c6b30 r9 435c6fb0 10 435c6f9c fp 4168d82c
|
||||
I/DEBUG ( 31): ip 8346aff0 sp 436c6a60 lr afd1c8ff pc afd1c902 cpsr 60000030
|
||||
I/DEBUG ( 31): #00 pc 0001c902 /system/lib/libc.so
|
||||
I/DEBUG ( 31): #01 pc 0001ccf6 /system/lib/libc.so
|
||||
I/DEBUG ( 31): #02 pc 000014bc /data/data/org.libsdl.app/lib/libmain.so
|
||||
I/DEBUG ( 31): #03 pc 00001506 /data/data/org.libsdl.app/lib/libmain.so
|
||||
|
||||
You can see that there's a crash in the C library being called from the main code.
|
||||
I run addr2line with the debug version of my code:
|
||||
|
||||
arm-eabi-addr2line -C -f -e obj/local/armeabi/libmain.so
|
||||
|
||||
and then paste in the number after "pc" in the call stack, from the line that I care about:
|
||||
000014bc
|
||||
|
||||
I get output from addr2line showing that it's in the quit function, in testspriteminimal.c, on line 23.
|
||||
|
||||
You can add logging to your code to help show what's happening:
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
__android_log_print(ANDROID_LOG_INFO, "foo", "Something happened! x = %d", x);
|
||||
|
||||
If you need to build without optimization turned on, you can create a file called
|
||||
"Application.mk" in the jni directory, with the following line in it:
|
||||
|
||||
APP_OPTIM := debug
|
||||
|
||||
|
||||
================================================================================
|
||||
Memory debugging
|
||||
================================================================================
|
||||
|
||||
The best (and slowest) way to debug memory issues on Android is valgrind.
|
||||
Valgrind has support for Android out of the box, just grab code using:
|
||||
|
||||
svn co svn://svn.valgrind.org/valgrind/trunk valgrind
|
||||
|
||||
... and follow the instructions in the file README.android to build it.
|
||||
|
||||
One thing I needed to do on Mac OS X was change the path to the toolchain,
|
||||
and add ranlib to the environment variables:
|
||||
export RANLIB=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-ranlib
|
||||
|
||||
Once valgrind is built, you can create a wrapper script to launch your
|
||||
application with it, changing org.libsdl.app to your package identifier:
|
||||
|
||||
--- start_valgrind_app -------------------
|
||||
#!/system/bin/sh
|
||||
export TMPDIR=/data/data/org.libsdl.app
|
||||
exec /data/local/Inst/bin/valgrind --log-file=/sdcard/valgrind.log --error-limit=no $*
|
||||
------------------------------------------
|
||||
|
||||
Then push it to the device:
|
||||
|
||||
adb push start_valgrind_app /data/local
|
||||
|
||||
and make it executable:
|
||||
|
||||
adb shell chmod 755 /data/local/start_valgrind_app
|
||||
|
||||
and tell Android to use the script to launch your application:
|
||||
|
||||
adb shell setprop wrap.org.libsdl.app "logwrapper /data/local/start_valgrind_app"
|
||||
|
||||
If the setprop command says "could not set property", it's likely that
|
||||
your package name is too long and you should make it shorter by changing
|
||||
AndroidManifest.xml and the path to your class file in android-project/src
|
||||
|
||||
You can then launch your application normally and waaaaaaaiiittt for it.
|
||||
You can monitor the startup process with the logcat command above, and
|
||||
when it's done (or even while it's running) you can grab the valgrind
|
||||
output file:
|
||||
|
||||
adb pull /sdcard/valgrind.log
|
||||
|
||||
When you're done instrumenting with valgrind, you can disable the wrapper:
|
||||
|
||||
adb shell setprop wrap.org.libsdl.app ""
|
||||
|
||||
|
||||
================================================================================
|
||||
Graphics debugging
|
||||
================================================================================
|
||||
|
||||
If you are developing on a compatible Tegra-based tablet, NVidia provides
|
||||
Tegra Graphics Debugger at their website. Because SDL2 dynamically loads EGL
|
||||
and GLES libraries, you must follow their instructions for installing the
|
||||
interposer library on a rooted device. The non-rooted instructions are not
|
||||
compatible with applications that use SDL2 for video.
|
||||
|
||||
The Tegra Graphics Debugger is available from NVidia here:
|
||||
https://developer.nvidia.com/tegra-graphics-debugger
|
||||
|
||||
|
||||
================================================================================
|
||||
Why is API level 16 the minimum required?
|
||||
================================================================================
|
||||
|
||||
The latest NDK toolchain doesn't support targeting earlier than API level 16.
|
||||
As of this writing, according to https://developer.android.com/about/dashboards/index.html
|
||||
about 99% of the Android devices accessing Google Play support API level 16 or
|
||||
higher (January 2018).
|
||||
|
||||
|
||||
================================================================================
|
||||
A note regarding the use of the "dirty rectangles" rendering technique
|
||||
================================================================================
|
||||
|
||||
If your app uses a variation of the "dirty rectangles" rendering technique,
|
||||
where you only update a portion of the screen on each frame, you may notice a
|
||||
variety of visual glitches on Android, that are not present on other platforms.
|
||||
This is caused by SDL's use of EGL as the support system to handle OpenGL ES/ES2
|
||||
contexts, in particular the use of the eglSwapBuffers function. As stated in the
|
||||
documentation for the function "The contents of ancillary buffers are always
|
||||
undefined after calling eglSwapBuffers".
|
||||
Setting the EGL_SWAP_BEHAVIOR attribute of the surface to EGL_BUFFER_PRESERVED
|
||||
is not possible for SDL as it requires EGL 1.4, available only on the API level
|
||||
17+, so the only workaround available on this platform is to redraw the entire
|
||||
screen each frame.
|
||||
|
||||
Reference: http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html
|
||||
|
||||
|
||||
================================================================================
|
||||
Ending your application
|
||||
================================================================================
|
||||
|
||||
Two legitimate ways:
|
||||
|
||||
- return from your main() function. Java side will automatically terminate the
|
||||
Activity by calling Activity.finish().
|
||||
|
||||
- Android OS can decide to terminate your application by calling onDestroy()
|
||||
(see Activity life cycle). Your application will receive a SDL_QUIT event you
|
||||
can handle to save things and quit.
|
||||
|
||||
Don't call exit() as it stops the activity badly.
|
||||
|
||||
NB: "Back button" can be handled as a SDL_KEYDOWN/UP events, with Keycode
|
||||
SDLK_AC_BACK, for any purpose.
|
||||
|
||||
================================================================================
|
||||
Known issues
|
||||
================================================================================
|
||||
|
||||
- The number of buttons reported for each joystick is hardcoded to be 36, which
|
||||
is the current maximum number of buttons Android can report.
|
||||
|
||||
Vendored
-84
@@ -1,84 +0,0 @@
|
||||
CMake
|
||||
================================================================================
|
||||
(www.cmake.org)
|
||||
|
||||
SDL's build system was traditionally based on autotools. Over time, this
|
||||
approach has suffered from several issues across the different supported
|
||||
platforms.
|
||||
To solve these problems, a new build system based on CMake is under development.
|
||||
It works in parallel to the legacy system, so users can experiment with it
|
||||
without complication.
|
||||
While still experimental, the build system should be usable on the following
|
||||
platforms:
|
||||
|
||||
* FreeBSD
|
||||
* Linux
|
||||
* VS.NET 2010
|
||||
* MinGW and Msys
|
||||
* macOS, iOS, and tvOS, with support for XCode
|
||||
|
||||
|
||||
================================================================================
|
||||
Usage
|
||||
================================================================================
|
||||
|
||||
Assuming the source for SDL is located at ~/sdl
|
||||
|
||||
cd ~
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ../sdl
|
||||
|
||||
This will build the static and dynamic versions of SDL in the ~/build directory.
|
||||
|
||||
|
||||
================================================================================
|
||||
Usage, iOS/tvOS
|
||||
================================================================================
|
||||
|
||||
CMake 3.14+ natively includes support for iOS and tvOS. SDL binaries may be built
|
||||
using Xcode or Make, possibly among other build-systems.
|
||||
|
||||
When using a recent version of CMake (3.14+), it should be possible to:
|
||||
|
||||
- build SDL for iOS, both static and dynamic
|
||||
- build SDL test apps (as iOS/tvOS .app bundles)
|
||||
- generate a working SDL_config.h for iOS (using SDL_config.h.cmake as a basis)
|
||||
|
||||
To use, set the following CMake variables when running CMake's configuration stage:
|
||||
|
||||
- `CMAKE_SYSTEM_NAME=<OS>` (either `iOS` or `tvOS`)
|
||||
- `CMAKE_OSX_SYSROOT=<SDK>` (examples: `iphoneos`, `iphonesimulator`, `iphoneos12.4`, `/full/path/to/iPhoneOS.sdk`,
|
||||
`appletvos`, `appletvsimulator`, `appletvos12.4`, `/full/path/to/AppleTVOS.sdk`, etc.)
|
||||
- `CMAKE_OSX_ARCHITECTURES=<semicolon-separated list of CPU architectures>` (example: "arm64;armv7s;x86_64")
|
||||
|
||||
|
||||
### Examples (for iOS/tvOS):
|
||||
|
||||
- for iOS-Simulator, using the latest, installed SDK:
|
||||
|
||||
`cmake ~/sdl -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64`
|
||||
|
||||
- for iOS-Device, using the latest, installed SDK, 64-bit only
|
||||
|
||||
`cmake ~/sdl -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64`
|
||||
|
||||
- for iOS-Device, using the latest, installed SDK, mixed 32/64 bit
|
||||
|
||||
`cmake ~/sdl -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES="arm64;armv7s"`
|
||||
|
||||
- for iOS-Device, using a specific SDK revision (iOS 12.4, in this example):
|
||||
|
||||
`cmake ~/sdl -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos12.4 -DCMAKE_OSX_ARCHITECTURES=arm64`
|
||||
|
||||
- for iOS-Simulator, using the latest, installed SDK, and building SDL test apps (as .app bundles):
|
||||
|
||||
`cmake ~/sdl -DSDL_TEST=1 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64`
|
||||
|
||||
- for tvOS-Simulator, using the latest, installed SDK:
|
||||
|
||||
`cmake ~/sdl -DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvsimulator -DCMAKE_OSX_ARCHITECTURES=x86_64`
|
||||
|
||||
- for tvOS-Device, using the latest, installed SDK:
|
||||
|
||||
`cmake ~/sdl -DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvos -DCMAKE_OSX_ARCHITECTURES=arm64`
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
DirectFB
|
||||
========
|
||||
|
||||
Supports:
|
||||
|
||||
- Hardware YUV overlays
|
||||
- OpenGL - software only
|
||||
- 2D/3D accelerations (depends on directfb driver)
|
||||
- multiple displays
|
||||
- windows
|
||||
|
||||
What you need:
|
||||
|
||||
* DirectFB 1.0.1, 1.2.x, 1.3.0
|
||||
* Kernel-Framebuffer support: required: vesafb, radeonfb ....
|
||||
* Mesa 7.0.x - optional for OpenGL
|
||||
|
||||
/etc/directfbrc
|
||||
|
||||
This file should contain the following lines to make
|
||||
your joystick work and avoid crashes:
|
||||
------------------------
|
||||
disable-module=joystick
|
||||
disable-module=cle266
|
||||
disable-module=cyber5k
|
||||
no-linux-input-grab
|
||||
------------------------
|
||||
|
||||
To disable to use x11 backend when DISPLAY variable is found use
|
||||
|
||||
export SDL_DIRECTFB_X11_CHECK=0
|
||||
|
||||
To disable the use of linux input devices, i.e. multimice/multikeyboard support,
|
||||
use
|
||||
|
||||
export SDL_DIRECTFB_LINUX_INPUT=0
|
||||
|
||||
To use hardware accelerated YUV-overlays for YUV-textures, use:
|
||||
|
||||
export SDL_DIRECTFB_YUV_DIRECT=1
|
||||
|
||||
This is disabled by default. It will only support one
|
||||
YUV texture, namely the first. Every other YUV texture will be
|
||||
rendered in software.
|
||||
|
||||
In addition, you may use (directfb-1.2.x)
|
||||
|
||||
export SDL_DIRECTFB_YUV_UNDERLAY=1
|
||||
|
||||
to make the YUV texture an underlay. This will make the cursor to
|
||||
be shown.
|
||||
|
||||
Simple Window Manager
|
||||
=====================
|
||||
|
||||
The driver has support for a very, very basic window manager you may
|
||||
want to use when running with "wm=default". Use
|
||||
|
||||
export SDL_DIRECTFB_WM=1
|
||||
|
||||
to enable basic window borders. In order to have the window title rendered,
|
||||
you need to have the following font installed:
|
||||
|
||||
/usr/share/fonts/truetype/freefont/FreeSans.ttf
|
||||
|
||||
OpenGL Support
|
||||
==============
|
||||
|
||||
The following instructions will give you *software* OpenGL. However this
|
||||
works at least on all directfb supported platforms.
|
||||
|
||||
As of this writing 20100802 you need to pull Mesa from git and do the following:
|
||||
|
||||
------------------------
|
||||
git clone git://anongit.freedesktop.org/git/mesa/mesa
|
||||
cd mesa
|
||||
git checkout 2c9fdaf7292423c157fc79b5ce43f0f199dd753a
|
||||
------------------------
|
||||
|
||||
Edit configs/linux-directfb so that the Directories-section looks like
|
||||
------------------------
|
||||
# Directories
|
||||
SRC_DIRS = mesa glu
|
||||
GLU_DIRS = sgi
|
||||
DRIVER_DIRS = directfb
|
||||
PROGRAM_DIRS =
|
||||
------------------------
|
||||
|
||||
make linux-directfb
|
||||
make
|
||||
|
||||
echo Installing - please enter sudo pw.
|
||||
|
||||
sudo make install INSTALL_DIR=/usr/local/dfb_GL
|
||||
cd src/mesa/drivers/directfb
|
||||
make
|
||||
sudo make install INSTALL_DIR=/usr/local/dfb_GL
|
||||
------------------------
|
||||
|
||||
To run the SDL - testprograms:
|
||||
|
||||
export SDL_VIDEODRIVER=directfb
|
||||
export LD_LIBRARY_PATH=/usr/local/dfb_GL/lib
|
||||
export LD_PRELOAD=/usr/local/dfb_GL/libGL.so.7
|
||||
|
||||
./testgl
|
||||
|
||||
-130
@@ -1,130 +0,0 @@
|
||||
Dynamic API
|
||||
================================================================================
|
||||
Originally posted by Ryan at:
|
||||
https://plus.google.com/103391075724026391227/posts/TB8UfnDYu4U
|
||||
|
||||
Background:
|
||||
|
||||
- The Steam Runtime has (at least in theory) a really kick-ass build of SDL2,
|
||||
but developers are shipping their own SDL2 with individual Steam games.
|
||||
These games might stop getting updates, but a newer SDL2 might be needed later.
|
||||
Certainly we'll always be fixing bugs in SDL, even if a new video target isn't
|
||||
ever needed, and these fixes won't make it to a game shipping its own SDL.
|
||||
- Even if we replace the SDL2 in those games with a compatible one, that is to
|
||||
say, edit a developer's Steam depot (yuck!), there are developers that are
|
||||
statically linking SDL2 that we can't do this for. We can't even force the
|
||||
dynamic loader to ignore their SDL2 in this case, of course.
|
||||
- If you don't ship an SDL2 with the game in some form, people that disabled the
|
||||
Steam Runtime, or just tried to run the game from the command line instead of
|
||||
Steam might find themselves unable to run the game, due to a missing dependency.
|
||||
- If you want to ship on non-Steam platforms like GOG or Humble Bundle, or target
|
||||
generic Linux boxes that may or may not have SDL2 installed, you have to ship
|
||||
the library or risk a total failure to launch. So now, you might have to have
|
||||
a non-Steam build plus a Steam build (that is, one with and one without SDL2
|
||||
included), which is inconvenient if you could have had one universal build
|
||||
that works everywhere.
|
||||
- We like the zlib license, but the biggest complaint from the open source
|
||||
community about the license change is the static linking. The LGPL forced this
|
||||
as a legal, not technical issue, but zlib doesn't care. Even those that aren't
|
||||
concerned about the GNU freedoms found themselves solving the same problems:
|
||||
swapping in a newer SDL to an older game often times can save the day.
|
||||
Static linking stops this dead.
|
||||
|
||||
So here's what we did:
|
||||
|
||||
SDL now has, internally, a table of function pointers. So, this is what SDL_Init
|
||||
now looks like:
|
||||
|
||||
UInt32 SDL_Init(Uint32 flags)
|
||||
{
|
||||
return jump_table.SDL_Init(flags);
|
||||
}
|
||||
|
||||
Except that is all done with a bunch of macro magic so we don't have to maintain
|
||||
every one of these.
|
||||
|
||||
What is jump_table.SDL_init()? Eventually, that's a function pointer of the real
|
||||
SDL_Init() that you've been calling all this time. But at startup, it looks more
|
||||
like this:
|
||||
|
||||
Uint32 SDL_Init_DEFAULT(Uint32 flags)
|
||||
{
|
||||
SDL_InitDynamicAPI();
|
||||
return jump_table.SDL_Init(flags);
|
||||
}
|
||||
|
||||
SDL_InitDynamicAPI() fills in jump_table with all the actual SDL function
|
||||
pointers, which means that this _DEFAULT function never gets called again.
|
||||
First call to any SDL function sets the whole thing up.
|
||||
|
||||
So you might be asking, what was the value in that? Isn't this what the operating
|
||||
system's dynamic loader was supposed to do for us? Yes, but now we've got this
|
||||
level of indirection, we can do things like this:
|
||||
|
||||
export SDL_DYNAMIC_API=/my/actual/libSDL-2.0.so.0
|
||||
./MyGameThatIsStaticallyLinkedToSDL2
|
||||
|
||||
And now, this game that is statically linked to SDL, can still be overridden
|
||||
with a newer, or better, SDL. The statically linked one will only be used as
|
||||
far as calling into the jump table in this case. But in cases where no override
|
||||
is desired, the statically linked version will provide its own jump table,
|
||||
and everyone is happy.
|
||||
|
||||
So now:
|
||||
- Developers can statically link SDL, and users can still replace it.
|
||||
(We'd still rather you ship a shared library, though!)
|
||||
- Developers can ship an SDL with their game, Valve can override it for, say,
|
||||
new features on SteamOS, or distros can override it for their own needs,
|
||||
but it'll also just work in the default case.
|
||||
- Developers can ship the same package to everyone (Humble Bundle, GOG, etc),
|
||||
and it'll do the right thing.
|
||||
- End users (and Valve) can update a game's SDL in almost any case,
|
||||
to keep abandoned games running on newer platforms.
|
||||
- Everyone develops with SDL exactly as they have been doing all along.
|
||||
Same headers, same ABI. Just get the latest version to enable this magic.
|
||||
|
||||
|
||||
A little more about SDL_InitDynamicAPI():
|
||||
|
||||
Internally, InitAPI does some locking to make sure everything waits until a
|
||||
single thread initializes everything (although even SDL_CreateThread() goes
|
||||
through here before spinning a thread, too), and then decides if it should use
|
||||
an external SDL library. If not, it sets up the jump table using the current
|
||||
SDL's function pointers (which might be statically linked into a program, or in
|
||||
a shared library of its own). If so, it loads that library and looks for and
|
||||
calls a single function:
|
||||
|
||||
SInt32 SDL_DYNAPI_entry(Uint32 version, void *table, Uint32 tablesize);
|
||||
|
||||
That function takes a version number (more on that in a moment), the address of
|
||||
the jump table, and the size, in bytes, of the table.
|
||||
Now, we've got policy here: this table's layout never changes; new stuff gets
|
||||
added to the end. Therefore SDL_DYNAPI_entry() knows that it can provide all
|
||||
the needed functions if tablesize <= sizeof its own jump table. If tablesize is
|
||||
bigger (say, SDL 2.0.4 is trying to load SDL 2.0.3), then we know to abort, but
|
||||
if it's smaller, we know we can provide the entire API that the caller needs.
|
||||
|
||||
The version variable is a failsafe switch.
|
||||
Right now it's always 1. This number changes when there are major API changes
|
||||
(so we know if the tablesize might be smaller, or entries in it have changed).
|
||||
Right now SDL_DYNAPI_entry gives up if the version doesn't match, but it's not
|
||||
inconceivable to have a small dispatch library that only supplies this one
|
||||
function and loads different, otherwise-incompatible SDL libraries and has the
|
||||
right one initialize the jump table based on the version. For something that
|
||||
must generically catch lots of different versions of SDL over time, like the
|
||||
Steam Client, this isn't a bad option.
|
||||
|
||||
Finally, I'm sure some people are reading this and thinking,
|
||||
"I don't want that overhead in my project!"
|
||||
To which I would point out that the extra function call through the jump table
|
||||
probably wouldn't even show up in a profile, but lucky you: this can all be
|
||||
disabled. You can build SDL without this if you absolutely must, but we would
|
||||
encourage you not to do that. However, on heavily locked down platforms like
|
||||
iOS, or maybe when debugging, it makes sense to disable it. The way this is
|
||||
designed in SDL, you just have to change one #define, and the entire system
|
||||
vaporizes out, and SDL functions exactly like it always did. Most of it is
|
||||
macro magic, so the system is contained to one C file and a few headers.
|
||||
However, this is on by default and you have to edit a header file to turn it
|
||||
off. Our hopes is that if we make it easy to disable, but not too easy,
|
||||
everyone will ultimately be able to get what they want, but we've gently
|
||||
nudged everyone towards what we think is the best solution.
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
Emscripten
|
||||
================================================================================
|
||||
|
||||
Build:
|
||||
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ emconfigure ../configure --host=asmjs-unknown-emscripten --disable-assembly --disable-threads --disable-cpuinfo CFLAGS="-O2"
|
||||
$ emmake make
|
||||
|
||||
Or with cmake:
|
||||
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ emcmake cmake ..
|
||||
$ emmake make
|
||||
|
||||
To build one of the tests:
|
||||
|
||||
$ cd test/
|
||||
$ emcc -O2 --js-opts 0 -g4 testdraw2.c -I../include ../build/.libs/libSDL2.a ../build/libSDL2_test.a -o a.html
|
||||
|
||||
Uses GLES2 renderer or software
|
||||
|
||||
Some other SDL2 libraries can be easily built (assuming SDL2 is installed somewhere):
|
||||
|
||||
SDL_mixer (http://www.libsdl.org/projects/SDL_mixer/):
|
||||
|
||||
$ EMCONFIGURE_JS=1 emconfigure ../configure
|
||||
build as usual...
|
||||
|
||||
SDL_gfx (http://cms.ferzkopp.net/index.php/software/13-sdl-gfx):
|
||||
|
||||
$ EMCONFIGURE_JS=1 emconfigure ../configure --disable-mmx
|
||||
build as usual...
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
Dollar Gestures
|
||||
===========================================================================
|
||||
SDL provides an implementation of the $1 gesture recognition system. This allows for recording, saving, loading, and performing single stroke gestures.
|
||||
|
||||
Gestures can be performed with any number of fingers (the centroid of the fingers must follow the path of the gesture), but the number of fingers must be constant (a finger cannot go down in the middle of a gesture). The path of a gesture is considered the path from the time when the final finger went down, to the first time any finger comes up.
|
||||
|
||||
Dollar gestures are assigned an Id based on a hash function. This is guaranteed to remain constant for a given gesture. There is a (small) chance that two different gestures will be assigned the same ID. In this case, simply re-recording one of the gestures should result in a different ID.
|
||||
|
||||
Recording:
|
||||
----------
|
||||
To begin recording on a touch device call:
|
||||
SDL_RecordGesture(SDL_TouchID touchId), where touchId is the id of the touch device you wish to record on, or -1 to record on all connected devices.
|
||||
|
||||
Recording terminates as soon as a finger comes up. Recording is acknowledged by an SDL_DOLLARRECORD event.
|
||||
A SDL_DOLLARRECORD event is a dgesture with the following fields:
|
||||
|
||||
* event.dgesture.touchId - the Id of the touch used to record the gesture.
|
||||
* event.dgesture.gestureId - the unique id of the recorded gesture.
|
||||
|
||||
|
||||
Performing:
|
||||
-----------
|
||||
As long as there is a dollar gesture assigned to a touch, every finger-up event will also cause an SDL_DOLLARGESTURE event with the following fields:
|
||||
|
||||
* event.dgesture.touchId - the Id of the touch which performed the gesture.
|
||||
* event.dgesture.gestureId - the unique id of the closest gesture to the performed stroke.
|
||||
* event.dgesture.error - the difference between the gesture template and the actual performed gesture. Lower error is a better match.
|
||||
* event.dgesture.numFingers - the number of fingers used to draw the stroke.
|
||||
|
||||
Most programs will want to define an appropriate error threshold and check to be sure that the error of a gesture is not abnormally high (an indicator that no gesture was performed).
|
||||
|
||||
|
||||
|
||||
Saving:
|
||||
-------
|
||||
To save a template, call SDL_SaveDollarTemplate(gestureId, dst) where gestureId is the id of the gesture you want to save, and dst is an SDL_RWops pointer to the file where the gesture will be stored.
|
||||
|
||||
To save all currently loaded templates, call SDL_SaveAllDollarTemplates(dst) where dst is an SDL_RWops pointer to the file where the gesture will be stored.
|
||||
|
||||
Both functions return the number of gestures successfully saved.
|
||||
|
||||
|
||||
Loading:
|
||||
--------
|
||||
To load templates from a file, call SDL_LoadDollarTemplates(touchId,src) where touchId is the id of the touch to load to (or -1 to load to all touch devices), and src is an SDL_RWops pointer to a gesture save file.
|
||||
|
||||
SDL_LoadDollarTemplates returns the number of templates successfully loaded.
|
||||
|
||||
|
||||
|
||||
===========================================================================
|
||||
Multi Gestures
|
||||
===========================================================================
|
||||
SDL provides simple support for pinch/rotate/swipe gestures.
|
||||
Every time a finger is moved an SDL_MULTIGESTURE event is sent with the following fields:
|
||||
|
||||
* event.mgesture.touchId - the Id of the touch on which the gesture was performed.
|
||||
* event.mgesture.x - the normalized x coordinate of the gesture. (0..1)
|
||||
* event.mgesture.y - the normalized y coordinate of the gesture. (0..1)
|
||||
* event.mgesture.dTheta - the amount that the fingers rotated during this motion.
|
||||
* event.mgesture.dDist - the amount that the fingers pinched during this motion.
|
||||
* event.mgesture.numFingers - the number of fingers used in the gesture.
|
||||
|
||||
|
||||
===========================================================================
|
||||
Notes
|
||||
===========================================================================
|
||||
For a complete example see test/testgesture.c
|
||||
|
||||
Please direct questions/comments to:
|
||||
jim.tla+sdl_touch@gmail.com
|
||||
Loaded 100 of 214 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user