mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
176
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee838f0519 | ||
|
|
5c646e8270 | ||
|
|
65c5d2425e | ||
|
|
f2676e0324 | ||
|
|
48adf99690 | ||
|
|
3c0432053b | ||
|
|
ebc2fcf216 | ||
|
|
25c74f76d2 | ||
|
|
e3839bdea6 | ||
|
|
742a810624 | ||
|
|
dbc10ab027 | ||
|
|
383f6dd9a1 | ||
|
|
be04300846 | ||
|
|
80c1ebe57d | ||
|
|
5996358308 | ||
|
|
380827e09b | ||
|
|
c4be881d52 | ||
|
|
ae56bb3743 | ||
|
|
fd5bcddcb7 | ||
|
|
af8124a525 | ||
|
|
8105defb0b | ||
|
|
7429a4111e | ||
|
|
a537d09c63 | ||
|
|
7fdb11d64f | ||
|
|
5567041c2b | ||
|
|
c94cfe0d40 | ||
|
|
73d5a2374b | ||
|
|
017f559e90 | ||
|
|
29f9ab14ee | ||
|
|
17b2a1a6e4 | ||
|
|
77f1f72122 | ||
|
|
03ec9d9589 | ||
|
|
b813a080da | ||
|
|
2b0b926f52 | ||
|
|
0ac0a5b77e | ||
|
|
d19de22540 | ||
|
|
e7535eaec5 | ||
|
|
7699075377 | ||
|
|
2bdf79f813 | ||
|
|
df738e9edc | ||
|
|
9656753232 | ||
|
|
e569e7ea05 | ||
|
|
59abb96caa | ||
|
|
678b51ddfb | ||
|
|
a51e740f5a | ||
|
|
d8f65dafd0 | ||
|
|
ebc6590c8f | ||
|
|
a91481fb4d | ||
|
|
87f1a1b553 | ||
|
|
c0d3edbc5d | ||
|
|
697ab30992 | ||
|
|
490de061f5 | ||
|
|
a9b589af86 | ||
|
|
4efb269c96 | ||
|
|
a7deca1228 | ||
|
|
3639f40eb0 | ||
|
|
47e56614af | ||
|
|
6ca2a0a29b | ||
|
|
c3448e1e7c | ||
|
|
9290c897e1 | ||
|
|
d8461475f2 | ||
|
|
0b4487d6b7 | ||
|
|
40c82785c9 | ||
|
|
d6db6c9d7c | ||
|
|
c0d5f6df4f | ||
|
|
7a8f3958c2 | ||
|
|
f10c6594e5 | ||
|
|
eb88f94763 | ||
|
|
5248c31df1 | ||
|
|
8230223440 | ||
|
|
8db57534d3 | ||
|
|
8f3b4ffa05 | ||
|
|
4846f2708f | ||
|
|
c7fbd5ed4a | ||
|
|
58fe6e6977 | ||
|
|
dc96137c47 | ||
|
|
a543d46a10 | ||
|
|
550bc8af67 | ||
|
|
4d1765dd9a | ||
|
|
ddd8c21c6d | ||
|
|
ee776e41cf | ||
|
|
ca5989332b | ||
|
|
a6b6fc1b61 | ||
|
|
049c843891 | ||
|
|
df134894cf | ||
|
|
fa4a2e38b7 | ||
|
|
d7b3709ee1 | ||
|
|
367c0012ce | ||
|
|
fb5f1ed915 | ||
|
|
d789935a6d | ||
|
|
1b3cfb7f24 | ||
|
|
9144bfbbc2 | ||
|
|
2f0f264ef2 | ||
|
|
f6dbbe73f2 | ||
|
|
79992a9a64 | ||
|
|
36b3e7279b | ||
|
|
369e2ca238 | ||
|
|
2a68f57b65 | ||
|
|
facbd05b9e | ||
|
|
1b719f2d8f | ||
|
|
1b7ec272d8 | ||
|
|
b509f4aaf6 | ||
|
|
c1197423b4 | ||
|
|
436c196ba5 | ||
|
|
b447193a22 | ||
|
|
63be7f318e | ||
|
|
8d718ca8d1 | ||
|
|
31bf69eba2 | ||
|
|
c4eb3bb4e4 | ||
|
|
26724feff1 | ||
|
|
d13a283791 | ||
|
|
fc0777c45f | ||
|
|
a686f4c4bb | ||
|
|
91cb5fc6ad | ||
|
|
0f8876f348 | ||
|
|
dbadbb4cce | ||
|
|
23b142008f | ||
|
|
d3e0b743bb | ||
|
|
91410f3690 | ||
|
|
5412fbc198 | ||
|
|
3f830eb5b5 | ||
|
|
7ed8bda0fe | ||
|
|
3eaf38b1d8 | ||
|
|
bad8adc0c3 | ||
|
|
5ed44f73cd | ||
|
|
7b7dc90158 | ||
|
|
8c05e8ac82 | ||
|
|
53a393a2c2 | ||
|
|
7fbc250128 | ||
|
|
b351b578b7 | ||
|
|
8de664b708 | ||
|
|
6c12c34297 | ||
|
|
1fae4d28ac | ||
|
|
881c0f7d4e | ||
|
|
4a824cd9aa | ||
|
|
33e351926f | ||
|
|
3f57d072ec | ||
|
|
0f17a04b2f | ||
|
|
fbfbfb4b33 | ||
|
|
af25d41375 | ||
|
|
508c4fa461 | ||
|
|
20eec5cdc8 | ||
|
|
6b50f85bfc | ||
|
|
a27ba815e4 | ||
|
|
6142033397 | ||
|
|
7674bc3677 | ||
|
|
157bd6de88 | ||
|
|
53eafa5f24 | ||
|
|
2701a72598 | ||
|
|
5b1c832a05 | ||
|
|
c317ed8b42 | ||
|
|
253cffbaca | ||
|
|
60558ebf71 | ||
|
|
a1a22cb1ef | ||
|
|
723e84930b | ||
|
|
b7a4e14ee9 | ||
|
|
bd9d7ea275 | ||
|
|
ca77b141a6 | ||
|
|
2068803c6b | ||
|
|
35f2ce14f1 | ||
|
|
6f00113554 | ||
|
|
a8b6a16e1a | ||
|
|
393854dee0 | ||
|
|
bbbaf00b9a | ||
|
|
bf396600ba | ||
|
|
143498f5dd | ||
|
|
eb61ab8c61 | ||
|
|
89139f3bae | ||
|
|
2419731dbc | ||
|
|
8258b7fb28 | ||
|
|
3646732db3 | ||
|
|
224d869bdd | ||
|
|
69490df8f8 | ||
|
|
27e99edfeb | ||
|
|
101d8aa885 | ||
|
|
9f9160c956 |
No files matched your search
@@ -97,6 +97,21 @@ if (NOT EMSCRIPTEN)
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
|
||||
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
|
||||
# Warn if no audio backends were detected on Linux/Unix systems
|
||||
if (UNIX AND NOT APPLE)
|
||||
if (NOT USE_PULSE AND NOT USE_ALSA AND NOT USE_JACK AND
|
||||
NOT USE_SNDIO AND NOT USE_OSS AND NOT USE_SUN)
|
||||
message(WARNING
|
||||
"No Cubeb audio backends detected on Linux/Unix system!\n"
|
||||
"Audio will NOT work at runtime.\n"
|
||||
"Please install development headers for at least one of:\n"
|
||||
" - PulseAudio (libpulse-dev / pulseaudio-libs-devel)\n"
|
||||
" - ALSA (libasound2-dev / alsa-lib-devel)\n"
|
||||
" - JACK (libjack-dev / jack-audio-connection-kit-devel)\n"
|
||||
" - sndio (libsndio-dev)")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
- Randrianasulu
|
||||
- lefp
|
||||
- mathstuf
|
||||
- seanm
|
||||
- erichelgeson
|
||||
- alicela1n
|
||||
|
||||
## Testing
|
||||
|
||||
|
||||
@@ -8,17 +8,19 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
|
||||
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs accurately (except for QEMU).
|
||||
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC Mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC NuBus and Old World ROMs, including those of the Power Mac 6100, 7200, and G3 Beige.
|
||||
|
||||
## Implemented Features
|
||||
|
||||
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow Open Firmware to boot, going so far as to allow audio playback of the boot-up jingles.
|
||||
Several machines have been implemented to varying degrees, like many Old World PowerPC Macs, early New World PowerPC Macs, and the Pippin.
|
||||
|
||||
This emulator has a debugging environment, complete with a disassembler.
|
||||
|
||||
## How to Use
|
||||
|
||||
This program currently uses the command prompt to work.
|
||||
|
||||
There are a few command line arguments one must enter when starting the program.
|
||||
There are a few command line arguments one can enter when starting the program.
|
||||
|
||||
```
|
||||
-r, --realtime
|
||||
@@ -36,21 +38,31 @@ Enter the interactive debugger.
|
||||
-b, --bootrom TEXT:FILE
|
||||
```
|
||||
|
||||
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
|
||||
Specifies the Boot ROM path. It otherwise looks for bootrom.bin.
|
||||
|
||||
```
|
||||
-m, --machine TEXT
|
||||
```
|
||||
|
||||
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
|
||||
Specify machine ID. Otherwise, the emulator will attempt to determine machine ID from the boot rom otherwise.
|
||||
|
||||
As of now, the most complete machines are the Power Mac 6100 (SCSI emulation in progress) and the Power Mac G3 Beige (SCSI + ATA emulation in progress, No ATI Rage acceleration).
|
||||
As of now, the most complete machines are the Power Mac 6100, the Power Mac 7500, and the Power Mac G3 Beige.
|
||||
|
||||
To go into to the debugger regardless of how you started the emulator, press Control and C on the terminal window.
|
||||
|
||||
## How to Compile
|
||||
|
||||
You need to install development tools first.
|
||||
|
||||
At least, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
At minimum, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
Clone the repository using the appropriate command:
|
||||
|
||||
```
|
||||
git clone https://github.com/dingusdev/dingusppc
|
||||
```
|
||||
|
||||
If this is from a mirror, replace the argument with the source you want to use instead.
|
||||
|
||||
You will also have to recursive clone or run
|
||||
```
|
||||
@@ -100,7 +112,3 @@ make testppc
|
||||
- 2 GB of RAM
|
||||
- 2 GB of Hard Disk Space
|
||||
- Graphics Card with a minimum resolution of 800*600
|
||||
|
||||
## Compiler Requirements
|
||||
|
||||
- Any C++20 compatible compiler
|
||||
+9
-4
@@ -42,6 +42,7 @@ enum : uint16_t {
|
||||
DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE,
|
||||
DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED,
|
||||
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE,
|
||||
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE,
|
||||
DPPC_WINDOWEVENT_WINDOW_BIGGER,
|
||||
DPPC_WINDOWEVENT_WINDOW_SMALLER,
|
||||
};
|
||||
@@ -75,7 +76,6 @@ public:
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t key;
|
||||
uint16_t keys_state;
|
||||
};
|
||||
|
||||
|
||||
@@ -126,9 +126,11 @@ public:
|
||||
event_manager = new EventManager();
|
||||
}
|
||||
return event_manager;
|
||||
};
|
||||
}
|
||||
|
||||
void poll_events(uint32_t kbd_locale);
|
||||
void poll_events();
|
||||
void set_keyboard_locale(uint32_t keyboard_id);
|
||||
void post_keyboard_state_events();
|
||||
|
||||
template <typename T>
|
||||
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
|
||||
@@ -159,17 +161,19 @@ public:
|
||||
_window_signal.disconnect_all();
|
||||
_mouse_signal.disconnect_all();
|
||||
_keyboard_signal.disconnect_all();
|
||||
_gamepad_signal.disconnect_all();
|
||||
_post_signal.disconnect_all();
|
||||
}
|
||||
|
||||
void disable_input_handlers() {
|
||||
_mouse_signal.disable();
|
||||
_keyboard_signal.disable();
|
||||
_gamepad_signal.disable();
|
||||
}
|
||||
|
||||
private:
|
||||
static EventManager* event_manager;
|
||||
EventManager() {}; // private constructor to implement a singleton
|
||||
EventManager() {} // private constructor to implement a singleton
|
||||
|
||||
CoreSignal<const WindowEvent&> _window_signal;
|
||||
CoreSignal<const MouseEvent&> _mouse_signal;
|
||||
@@ -182,6 +186,7 @@ private:
|
||||
uint64_t key_downs = 0;
|
||||
uint64_t key_ups = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
uint32_t kbd_locale = 0;
|
||||
};
|
||||
|
||||
#endif // EVENT_MANAGER_H
|
||||
+119
-14
@@ -32,7 +32,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_l
|
||||
|
||||
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
|
||||
|
||||
void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
void EventManager::set_keyboard_locale(uint32_t keyboard_id) {
|
||||
this->kbd_locale = keyboard_id;
|
||||
}
|
||||
|
||||
void EventManager::poll_events() {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
@@ -54,9 +58,12 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
if (event.key.repeat)
|
||||
break;
|
||||
|
||||
// Internal shortcuts, intentionally not sent to the host.
|
||||
// Control-G: mouse grab
|
||||
if (event.key.keysym.sym == SDLK_g && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.key.keysym.sym == SDLK_g && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we;
|
||||
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE;
|
||||
@@ -69,7 +76,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
return;
|
||||
}
|
||||
// Control-S: scale quality
|
||||
if (event.key.keysym.sym == SDLK_s && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.key.keysym.sym == SDLK_s && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE;
|
||||
@@ -79,7 +86,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
return;
|
||||
}
|
||||
// Control-F: fullscreen
|
||||
if (event.key.keysym.sym == SDLK_f && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE;
|
||||
@@ -88,8 +95,18 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-Shift-F: fullscreen reverse
|
||||
if (event.key.keysym.sym == SDLK_f && (event.key.keysym.mod & KMOD_ALL) == (KMOD_LCTRL | KMOD_LSHIFT)) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE_REVERSE;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-+: bigger
|
||||
if (event.key.keysym.sym == SDLK_EQUALS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.key.keysym.sym == SDLK_EQUALS && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_BIGGER;
|
||||
@@ -99,7 +116,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
return;
|
||||
}
|
||||
// Control--: smaller
|
||||
if (event.key.keysym.sym == SDLK_MINUS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.key.keysym.sym == SDLK_MINUS && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SMALLER;
|
||||
@@ -108,8 +125,26 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-L: log toggle
|
||||
if (event.key.keysym.sym == SDLK_l && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
loguru::g_stderr_verbosity = loguru::g_stderr_verbosity == loguru::Verbosity_MAX ?
|
||||
loguru::Verbosity_INFO
|
||||
:
|
||||
loguru::Verbosity_MAX;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-D: debugger
|
||||
if (event.key.keysym.sym == SDLK_d && (event.key.keysym.mod & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
power_on = false;
|
||||
power_off_reason = po_enter_debugger;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Ralt+delete => ctrl+alt+del
|
||||
if (event.key.keysym.sym == SDLK_DELETE && ((SDL_GetModState() & KMOD_ALL) == KMOD_RALT) != 0) {
|
||||
if (event.key.keysym.sym == SDLK_DELETE && ((event.key.keysym.mod & KMOD_ALL) == KMOD_RALT) != 0) {
|
||||
KeyboardEvent ke{};
|
||||
ke.key = AdbKey_Control;
|
||||
|
||||
@@ -126,7 +161,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
this->_keyboard_signal.emit(ke);
|
||||
return;
|
||||
}
|
||||
int key_code = get_sdl_event_key_code(event.key, kbd_locale);
|
||||
int key_code = get_sdl_event_key_code(event.key, this->kbd_locale);
|
||||
if (key_code != -1) {
|
||||
KeyboardEvent ke{};
|
||||
ke.key = key_code;
|
||||
@@ -139,7 +174,7 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
}
|
||||
// Caps Lock is a special case, since it's a toggle key
|
||||
if (ke.key == AdbKey_CapsLock) {
|
||||
ke.flags = SDL_GetModState() & KMOD_CAPS ?
|
||||
ke.flags = event.key.keysym.mod & KMOD_CAPS ?
|
||||
KEYBOARD_EVENT_DOWN : KEYBOARD_EVENT_UP;
|
||||
}
|
||||
this->_keyboard_signal.emit(ke);
|
||||
@@ -249,6 +284,76 @@ void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
this->_post_signal.emit();
|
||||
}
|
||||
|
||||
void EventManager::post_keyboard_state_events() {
|
||||
int numkeys;
|
||||
const Uint8 *states = SDL_GetKeyboardState(&numkeys);
|
||||
int modstate = SDL_GetModState();
|
||||
|
||||
SDL_KeyboardEvent keyevent = { .type = SDL_KEYDOWN };
|
||||
SDL_Scancode scancode;
|
||||
KeyboardEvent ke{};
|
||||
|
||||
typedef struct {
|
||||
SDL_Scancode scancode;
|
||||
SDL_Keymod keymod;
|
||||
AdbKey adbkey;
|
||||
} Modifier_t;
|
||||
|
||||
static Modifier_t modifiers[] = {
|
||||
SDL_SCANCODE_LSHIFT , KMOD_LSHIFT , AdbKey_Shift ,
|
||||
SDL_SCANCODE_RSHIFT , KMOD_RSHIFT , AdbKey_RightShift ,
|
||||
SDL_SCANCODE_LCTRL , KMOD_LCTRL , AdbKey_Control ,
|
||||
SDL_SCANCODE_RCTRL , KMOD_RCTRL , AdbKey_RightControl,
|
||||
SDL_SCANCODE_LALT , KMOD_LALT , AdbKey_Option ,
|
||||
SDL_SCANCODE_RALT , KMOD_RALT , AdbKey_RightOption ,
|
||||
SDL_SCANCODE_LGUI , KMOD_LGUI , AdbKey_Command ,
|
||||
SDL_SCANCODE_RGUI , KMOD_RGUI , AdbKey_Command ,
|
||||
// SDL_SCANCODE_NUMLOCKCLEAR , KMOD_NUM , AdbKey_KeypadClear ,
|
||||
SDL_SCANCODE_CAPSLOCK , KMOD_CAPS , AdbKey_CapsLock ,
|
||||
// SDL_SCANCODE_MODE , KMOD_MODE , AdbKey_???? ,
|
||||
// SDL_SCANCODE_SCROLLLOCK , KMOD_SCROLL , AdbKey_F14 ,
|
||||
SDL_SCANCODE_UNKNOWN
|
||||
};
|
||||
|
||||
LOG_F(INFO, "Current keyboard state:");
|
||||
|
||||
for (Modifier_t *mod = modifiers; mod->scancode != SDL_SCANCODE_UNKNOWN; mod++) {
|
||||
if (!(modstate & mod->keymod))
|
||||
continue;
|
||||
LOG_F(INFO, " mod:%s", SDL_GetScancodeName(mod->scancode));
|
||||
ke.key = mod->adbkey;
|
||||
ke.flags = KEYBOARD_EVENT_DOWN;
|
||||
this->_keyboard_signal.emit(ke);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numkeys; i++) {
|
||||
if (!states[i])
|
||||
continue;
|
||||
|
||||
scancode = (SDL_Scancode)i;
|
||||
|
||||
Modifier_t *mod = modifiers;
|
||||
for (; mod->scancode != SDL_SCANCODE_UNKNOWN && mod->scancode != scancode; mod++);
|
||||
if (mod->scancode == scancode) {
|
||||
LOG_F(INFO, " ignore:%s", SDL_GetScancodeName(scancode));
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG_F(INFO, " key:%s", SDL_GetScancodeName(scancode));
|
||||
keyevent.keysym.scancode = scancode;
|
||||
keyevent.keysym.sym = SDL_GetKeyFromScancode(scancode);
|
||||
keyevent.keysym.mod = modstate;
|
||||
|
||||
int key_code = get_sdl_event_key_code(keyevent, this->kbd_locale);
|
||||
if (key_code != -1) {
|
||||
ke.key = key_code;
|
||||
ke.flags = KEYBOARD_EVENT_DOWN;
|
||||
this->_keyboard_signal.emit(ke);
|
||||
} else {
|
||||
LOG_F(WARNING, "Unknown key %x pressed", keyevent.keysym.sym);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
|
||||
{
|
||||
@@ -331,11 +436,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
|
||||
case SDLK_PAGEDOWN: return AdbKey_PageDown;
|
||||
|
||||
case SDLK_LCTRL: return AdbKey_Control;
|
||||
case SDLK_RCTRL: return AdbKey_Control;
|
||||
case SDLK_RCTRL: return AdbKey_RightControl;
|
||||
case SDLK_LSHIFT: return AdbKey_Shift;
|
||||
case SDLK_RSHIFT: return AdbKey_Shift;
|
||||
case SDLK_RSHIFT: return AdbKey_RightShift;
|
||||
case SDLK_LALT: return AdbKey_Option;
|
||||
case SDLK_RALT: return AdbKey_Option;
|
||||
case SDLK_RALT: return AdbKey_RightOption;
|
||||
case SDLK_LGUI: return AdbKey_Command;
|
||||
case SDLK_RGUI: return AdbKey_Command;
|
||||
case SDLK_MENU: return AdbKey_Grave;
|
||||
@@ -345,7 +450,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
|
||||
case SDLK_DOWN: return AdbKey_ArrowDown;
|
||||
case SDLK_LEFT: return AdbKey_ArrowLeft;
|
||||
case SDLK_RIGHT: return AdbKey_ArrowRight;
|
||||
;
|
||||
|
||||
case SDLK_KP_0: return AdbKey_Keypad0;
|
||||
case SDLK_KP_1: return AdbKey_Keypad1;
|
||||
case SDLK_KP_2: return AdbKey_Keypad2;
|
||||
@@ -364,7 +469,7 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_l
|
||||
case SDLK_KP_ENTER: return AdbKey_KeypadEnter;
|
||||
case SDLK_KP_EQUALS: return AdbKey_KeypadEquals;
|
||||
case SDLK_NUMLOCKCLEAR: return AdbKey_KeypadClear;
|
||||
;
|
||||
|
||||
case SDLK_F1: return AdbKey_F1;
|
||||
case SDLK_F2: return AdbKey_F2;
|
||||
case SDLK_F3: return AdbKey_F3;
|
||||
|
||||
+8
-8
@@ -64,13 +64,13 @@ public:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
void push(T val)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
std::priority_queue<T, Container, Compare>::push(val);
|
||||
};
|
||||
}
|
||||
|
||||
T pop()
|
||||
{
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
T val = std::priority_queue<T, Container, Compare>::top();
|
||||
std::priority_queue<T, Container, Compare>::pop();
|
||||
return val;
|
||||
};
|
||||
}
|
||||
|
||||
std::recursive_mutex& get_mtx()
|
||||
{
|
||||
@@ -111,20 +111,20 @@ public:
|
||||
timer_manager = new TimerManager();
|
||||
}
|
||||
return timer_manager;
|
||||
};
|
||||
}
|
||||
|
||||
// callback for retrieving current time
|
||||
void set_time_now_cb(const std::function<uint64_t()> &cb) {
|
||||
this->get_time_now = cb;
|
||||
};
|
||||
}
|
||||
|
||||
// callback for acknowledging time changes
|
||||
void set_notify_changes_cb(const timer_cb &cb) {
|
||||
this->notify_timer_changes = cb;
|
||||
};
|
||||
}
|
||||
|
||||
// return current virtual time in nanoseconds
|
||||
uint64_t current_time_ns() { return get_time_now(); };
|
||||
uint64_t current_time_ns() { return get_time_now(); }
|
||||
|
||||
// creating and cancelling timers
|
||||
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
|
||||
private:
|
||||
static TimerManager* timer_manager;
|
||||
TimerManager(){}; // private constructor to implement a singleton
|
||||
TimerManager(){} // private constructor to implement a singleton
|
||||
|
||||
// timer queue
|
||||
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
|
||||
|
||||
@@ -253,9 +253,9 @@ const char* trap_cond[32] = {/*Trap conditions*/
|
||||
"twlt", "", "", "", "twle", "", "", "",
|
||||
"twne", "", "", "", "", "", "", ""};
|
||||
|
||||
const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "", "",
|
||||
const char* spr_index0[32] = {"mq", "xer", "", "", "rtcu", "rtcl", "dec", "",
|
||||
"lr", "ctr", "", "", "", "", "", "",
|
||||
"", "", "dsisr", "dar", "", "", "dec", "",
|
||||
"", "", "dsisr", "dar", "rtcu", "rtcl", "dec", "",
|
||||
"", "sdr1", "srr0", "srr1", "", "", "", ""};
|
||||
|
||||
const char* spr_index8[32] = {
|
||||
|
||||
@@ -114,6 +114,8 @@ enum SPR : int {
|
||||
PMC2 = 954,
|
||||
SIA = 955,
|
||||
MMCR1 = 956,
|
||||
PMC3 = 957,
|
||||
PMC4 = 958,
|
||||
SDA = 959,
|
||||
HID0 = 1008,
|
||||
HID1 = 1009,
|
||||
|
||||
+6
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -118,7 +118,7 @@ std::unordered_map<uint32_t, uint64_t> num_opcodes;
|
||||
|
||||
class CPUProfile : public BaseProfile {
|
||||
public:
|
||||
CPUProfile() : BaseProfile("PPC_CPU") {};
|
||||
CPUProfile() : BaseProfile("PPC_CPU") {}
|
||||
|
||||
void populate_variables(std::vector<ProfileVar>& vars) {
|
||||
vars.clear();
|
||||
@@ -169,7 +169,7 @@ public:
|
||||
.count_total = num_executed_instrs});
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
void reset() {
|
||||
num_executed_instrs = 0;
|
||||
@@ -180,7 +180,7 @@ public:
|
||||
#ifdef CPU_PROFILING_OPS
|
||||
num_opcodes.clear();
|
||||
#endif
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -899,7 +899,8 @@ static map<string, int> SPRName2Num = {
|
||||
{"SDR1", SPR::SDR1}, {"MQ", SPR::MQ}, {"RTCU", SPR::RTCU_S},
|
||||
{"RTCL", SPR::RTCL_S}, {"DSISR", SPR::DSISR}, {"DAR", SPR::DAR},
|
||||
{"MMCR0", SPR::MMCR0}, {"PMC1", SPR::PMC1}, {"PMC2", SPR::PMC2},
|
||||
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1}
|
||||
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1},
|
||||
{"PMC3", SPR::PMC3}, {"PMC4", SPR::PMC4},
|
||||
};
|
||||
|
||||
static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
|
||||
|
||||
+18
-13
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -782,9 +782,9 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
static void tlb_flush_primary_entry(std::array<TLBEntry, TLB_SIZE> &tlb1, uint32_t tag)
|
||||
{
|
||||
TLBEntry *tlb_entry = &tlb1[(tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask];
|
||||
if (tlb_entry->tag == tag) {
|
||||
if (tlb_entry->tag != TLB_INVALID_TAG && (tlb_entry->tag & TLB_VPS_MASK) == tag) {
|
||||
tlb_entry->tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", ea);
|
||||
//LOG_F(INFO, "Invalidated primary TLB entry at 0x%X", tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -792,16 +792,16 @@ static void tlb_flush_secondary_entry(std::array<TLBEntry, TLB_SIZE*TLB2_WAYS> &
|
||||
{
|
||||
TLBEntry *tlb_entry = &tlb2[((tag >> PPC_PAGE_SIZE_BITS) & tlb_size_mask) * TLB2_WAYS];
|
||||
for (int i = 0; i < TLB2_WAYS; i++) {
|
||||
if (tlb_entry[i].tag == tag) {
|
||||
if (tlb_entry[i].tag != TLB_INVALID_TAG && (tlb_entry[i].tag & TLB_VPS_MASK) == tag) {
|
||||
tlb_entry[i].tag = TLB_INVALID_TAG;
|
||||
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", ea);
|
||||
//LOG_F(INFO, "Invalidated secondary TLB entry at 0x%X", tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tlb_flush_entry(uint32_t ea)
|
||||
{
|
||||
const uint32_t tag = ea & ~0xFFFUL;
|
||||
const uint32_t tag = ea & TLB_VPS_MASK;
|
||||
tlb_flush_primary_entry(itlb1_mode1, tag);
|
||||
tlb_flush_secondary_entry(itlb2_mode1, tag);
|
||||
tlb_flush_primary_entry(itlb1_mode2, tag);
|
||||
@@ -951,6 +951,11 @@ static void mpc601_bat_update(uint32_t bat_reg)
|
||||
}
|
||||
}
|
||||
|
||||
static void mpc601_dbat_update(uint32_t /*bat_reg*/)
|
||||
{
|
||||
// ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
|
||||
static void ppc_ibat_update(uint32_t bat_reg)
|
||||
{
|
||||
int upper_reg_num;
|
||||
@@ -999,7 +1004,6 @@ static void ppc_dbat_update(uint32_t bat_reg)
|
||||
gTLBFlushDPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void mmu_pat_ctx_changed()
|
||||
@@ -1340,7 +1344,7 @@ template void write_unaligned<uint64_t>(uint32_t opcode, uint32_t guest_va, uint
|
||||
|
||||
class MMUProfile : public BaseProfile {
|
||||
public:
|
||||
MMUProfile() : BaseProfile("PPC_MMU") {};
|
||||
MMUProfile() : BaseProfile("PPC_MMU") {}
|
||||
|
||||
void populate_variables(std::vector<ProfileVar>& vars) {
|
||||
vars.clear();
|
||||
@@ -1388,7 +1392,7 @@ public:
|
||||
vars.push_back({.name = "Unaligned Crosspage Writes Total",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = unaligned_crossp_w});
|
||||
};
|
||||
}
|
||||
|
||||
void reset() {
|
||||
dmem_reads_total = 0;
|
||||
@@ -1402,7 +1406,7 @@ public:
|
||||
unaligned_writes = 0;
|
||||
unaligned_crossp_r = 0;
|
||||
unaligned_crossp_w = 0;
|
||||
};
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1414,7 +1418,7 @@ public:
|
||||
|
||||
class TLBProfile : public BaseProfile {
|
||||
public:
|
||||
TLBProfile() : BaseProfile("PPC:MMU:TLB") {};
|
||||
TLBProfile() : BaseProfile("PPC:MMU:TLB") {}
|
||||
|
||||
void populate_variables(std::vector<ProfileVar>& vars) {
|
||||
vars.clear();
|
||||
@@ -1446,14 +1450,14 @@ public:
|
||||
vars.push_back({.name = "Number of replaced TLB entries",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_entry_replacements});
|
||||
};
|
||||
}
|
||||
|
||||
void reset() {
|
||||
num_primary_dtlb_hits = 0;
|
||||
num_secondary_dtlb_hits = 0;
|
||||
num_dtlb_refills = 0;
|
||||
num_entry_replacements = 0;
|
||||
};
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1638,6 +1642,7 @@ void ppc_mmu_init()
|
||||
if (is_601) {
|
||||
// use 601-style unified BATs
|
||||
ibat_update = &mpc601_bat_update;
|
||||
dbat_update = &mpc601_dbat_update;
|
||||
} else {
|
||||
// use PPC-style BATs
|
||||
ibat_update = &ppc_ibat_update;
|
||||
|
||||
@@ -87,6 +87,7 @@ constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
|
||||
constexpr uint32_t TLB_SIZE = 4096;
|
||||
constexpr uint32_t TLB2_WAYS = 4;
|
||||
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
|
||||
constexpr uint32_t TLB_VPS_MASK = 0x0FFFF000; // mask for TLB invalidation
|
||||
|
||||
typedef struct TLBEntry {
|
||||
uint32_t tag;
|
||||
|
||||
@@ -931,6 +931,7 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
#endif
|
||||
if (ppc_state.msr & MSR::PR) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -972,6 +973,20 @@ void dppc_interpreter::ppc_mfspr(uint32_t opcode) {
|
||||
ppc_state.gpr[reg_d] = ppc_state.spr[SPR::DEC_S] = val;
|
||||
break;
|
||||
}
|
||||
case SPR::TBL_S: {
|
||||
uint64_t tbr_value = calc_tbr_value();
|
||||
ppc_state.gpr[reg_d] =
|
||||
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
|
||||
ppc_state.spr[TBU_S] = uint32_t(tbr_value >> 32);
|
||||
break;
|
||||
}
|
||||
case SPR::TBU_S: {
|
||||
uint64_t tbr_value = calc_tbr_value();
|
||||
ppc_state.gpr[reg_d] =
|
||||
ppc_state.spr[TBU_S] = uint32_t(tbr_value >> 32);
|
||||
ppc_state.spr[TBL_S] = uint32_t(tbr_value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// FIXME: Unknown SPR should be noop or illegal instruction.
|
||||
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
|
||||
@@ -988,6 +1003,7 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
#endif
|
||||
if (ppc_state.msr & MSR::PR) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1065,6 +1081,7 @@ void dppc_interpreter::ppc_mtspr(uint32_t opcode) {
|
||||
case 543:
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
dbat_update(ref_spr);
|
||||
break;
|
||||
default:
|
||||
// FIXME: Unknown SPR should be noop or illegal instruction.
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
|
||||
@@ -321,7 +321,8 @@ int main() {
|
||||
initialize_ppc_opcode_table(); //kludge
|
||||
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
|
||||
// Also set MSR[FP] bit so we can test FPU instructions.
|
||||
ppc_state.msr = (MSR::ME | MSR::IP | MSR::FP);
|
||||
int new_msr = (MSR::ME | MSR::IP | MSR::FP);
|
||||
ppc_msr_did_change(ppc_state.msr, new_msr, false);
|
||||
|
||||
cout << "Running DingusPPC emulator tests..." << endl << endl;
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
|
||||
}
|
||||
return debugger_obj.get();
|
||||
};
|
||||
}
|
||||
|
||||
void enter_debugger();
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/clockgen/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
|
||||
@@ -26,12 +26,10 @@ platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.h"
|
||||
|
||||
@@ -94,7 +94,7 @@ void AdbAppleJack::set_register_3() {
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbAppleJack_Descriptor = {
|
||||
AdbAppleJack::create, {}, {}
|
||||
AdbAppleJack::create, {}, {}, HWCompType::ADB_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
|
||||
@@ -133,7 +133,7 @@ static const PropMap AdbBus_Properties = {
|
||||
};
|
||||
|
||||
static const DeviceDescription AdbBus_Descriptor = {
|
||||
AdbBus::create, {}, AdbBus_Properties
|
||||
AdbBus::create, {}, AdbBus_Properties, HWCompType::ADB_HOST
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
|
||||
void register_device(AdbDevice* dev_obj);
|
||||
uint8_t process_command(const uint8_t* in_data, int data_size);
|
||||
uint8_t get_output_count() { return this->output_count; };
|
||||
uint8_t get_output_count() { return this->output_count; }
|
||||
|
||||
// Polls devices that have a service request flag set. Returns the talk
|
||||
// command corresponding to the first device that responded with data, or
|
||||
@@ -63,11 +63,11 @@ public:
|
||||
uint8_t poll();
|
||||
|
||||
// callbacks meant to be called by devices
|
||||
const uint8_t* get_input_buf() { return this->input_buf; };
|
||||
uint8_t* get_output_buf() { return this->output_buf; };
|
||||
uint8_t get_input_count() { return this->input_count; };
|
||||
void set_output_count(uint8_t count) { this->output_count = count; };
|
||||
bool already_answered() { return this->got_answer; };
|
||||
const uint8_t* get_input_buf() { return this->input_buf; }
|
||||
uint8_t* get_output_buf() { return this->output_buf; }
|
||||
uint8_t get_input_count() { return this->input_count; }
|
||||
void set_output_count(uint8_t count) { this->output_count = count; }
|
||||
bool already_answered() { return this->got_answer; }
|
||||
|
||||
private:
|
||||
std::vector<AdbDevice*> devices;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -37,7 +37,7 @@ int AdbDevice::device_postinit() {
|
||||
this->host_obj->register_device(this);
|
||||
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
uint8_t AdbDevice::poll() {
|
||||
if (!this->srq_flag) {
|
||||
@@ -84,12 +84,16 @@ void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
|
||||
switch(reg_num & 3) {
|
||||
case 0:
|
||||
this->set_register_0();
|
||||
break;
|
||||
case 1:
|
||||
this->set_register_1();
|
||||
break;
|
||||
case 2:
|
||||
this->set_register_2();
|
||||
break;
|
||||
case 3:
|
||||
this->set_register_3();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,5 +108,5 @@ bool AdbDevice::get_register_3() {
|
||||
}
|
||||
|
||||
uint8_t AdbDevice::gen_random_address() {
|
||||
return (TimerManager::get_instance()->current_time_ns() + 8) & 0xF;
|
||||
return TimerManager::get_instance()->current_time_ns() & 0xF;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
virtual void reset() = 0;
|
||||
virtual bool talk(const uint8_t dev_addr, const uint8_t reg_num);
|
||||
virtual void listen(const uint8_t dev_addr, const uint8_t reg_num);
|
||||
virtual uint8_t get_address() { return this->my_addr; };
|
||||
virtual uint8_t get_address() { return this->my_addr; }
|
||||
|
||||
// Attempts to poll the device. Returns the talk command corresponding to
|
||||
// the device if it has data, 0 otherwise.
|
||||
@@ -56,18 +56,19 @@ public:
|
||||
protected:
|
||||
uint8_t gen_random_address();
|
||||
|
||||
virtual bool get_register_0() { return false; };
|
||||
virtual bool get_register_1() { return false; };
|
||||
virtual bool get_register_2() { return false; };
|
||||
virtual bool get_register_0() { return false; }
|
||||
virtual bool get_register_1() { return false; }
|
||||
virtual bool get_register_2() { return false; }
|
||||
virtual bool get_register_3();
|
||||
|
||||
virtual void set_register_0() {};
|
||||
virtual void set_register_1() {};
|
||||
virtual void set_register_2() {};
|
||||
virtual void set_register_3() {};
|
||||
virtual void set_register_0() {}
|
||||
virtual void set_register_1() {}
|
||||
virtual void set_register_2() {}
|
||||
virtual void set_register_3() {}
|
||||
|
||||
uint8_t exc_event_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
uint8_t led_state = 0;
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t dev_handler_id = 0;
|
||||
bool got_collision = false;
|
||||
|
||||
@@ -35,13 +35,18 @@ AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
|
||||
|
||||
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
|
||||
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
|
||||
|
||||
if (this->pending_events.size() == 1) {
|
||||
this->srq_flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void AdbKeyboard::reset() {
|
||||
this->my_addr = ADB_ADDR_KBD;
|
||||
this->dev_handler_id = 2; // Extended ADB keyboard
|
||||
this->exc_event_flag = 1;
|
||||
this->srq_flag = 1; // enable service requests
|
||||
this->srq_flag = 0; // don't process keyboard service requests yet
|
||||
this->led_state = 0; // LEDs off
|
||||
this->pending_events.clear();
|
||||
}
|
||||
|
||||
@@ -53,6 +58,11 @@ bool AdbKeyboard::get_register_0() {
|
||||
out_buf[0] = this->consume_pending_event();
|
||||
out_buf[1] = this->consume_pending_event();
|
||||
this->host_obj->set_output_count(2);
|
||||
|
||||
if (this->pending_events.empty()) {
|
||||
this->srq_flag = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -68,19 +78,44 @@ uint8_t AdbKeyboard::consume_pending_event() {
|
||||
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
|
||||
this->pending_events.pop_front();
|
||||
|
||||
uint8_t key_state = 0;
|
||||
if (event->flags & KEYBOARD_EVENT_DOWN) {
|
||||
key_state = 0;
|
||||
} else if (event->flags & KEYBOARD_EVENT_UP) {
|
||||
key_state = 1;
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
|
||||
uint8_t key_state = (event->flags & KEYBOARD_EVENT_UP) ? 1 : 0;
|
||||
|
||||
if (this->dev_handler_id != 3) {
|
||||
switch (event->key) {
|
||||
case AdbKey_RightControl : event->key = AdbKey_Control; break;
|
||||
case AdbKey_RightShift : event->key = AdbKey_Shift ; break;
|
||||
case AdbKey_RightOption : event->key = AdbKey_Option ; break;
|
||||
}
|
||||
}
|
||||
|
||||
return (key_state << 7) | (event->key & 0x7F);
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_2() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
out_buf[0] = 0;
|
||||
out_buf[1] = this->led_state & 0x07;
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_2() {
|
||||
if (this->host_obj->get_input_count() < 2)
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
this->led_state = in_data[1] & 0x07;
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_3() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
out_buf[0] = (this->my_addr << 4) | (1 << 1) | 1; // Address + SRQ Enable + Exc Event
|
||||
out_buf[1] = this->dev_handler_id;
|
||||
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_3() {
|
||||
@@ -111,7 +146,7 @@ void AdbKeyboard::set_register_3() {
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbKeyboard_Descriptor = {
|
||||
AdbKeyboard::create, {}, {}
|
||||
AdbKeyboard::create, {}, {}, HWCompType::ADB_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbKeyboard, AdbKeyboard_Descriptor);
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
void event_handler(const KeyboardEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
bool get_register_2() override;
|
||||
bool get_register_3() override;
|
||||
void set_register_2() override;
|
||||
void set_register_3() override;
|
||||
|
||||
@@ -128,6 +130,10 @@ enum AdbKey {
|
||||
AdbKey_Command = 0x37,
|
||||
AdbKey_CapsLock = 0x39,
|
||||
|
||||
AdbKey_RightControl = 0x7d,
|
||||
AdbKey_RightShift = 0x7b,
|
||||
AdbKey_RightOption = 0x7c,
|
||||
|
||||
AdbKey_ArrowUp = 0x3e,
|
||||
AdbKey_ArrowDown = 0x3d,
|
||||
AdbKey_ArrowLeft = 0x3b,
|
||||
|
||||
@@ -172,7 +172,7 @@ uint8_t AdbMouse::get_buttons_state() const {
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbMouse_Descriptor = {
|
||||
AdbMouse::create, {}, {}
|
||||
AdbMouse::create, {}, {}, HWCompType::ADB_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbMouse, AdbMouse_Descriptor);
|
||||
@@ -21,13 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Basic ATA device emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <cinttypes>
|
||||
#include <core/timermanager.h>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
@@ -110,7 +111,7 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (is_selected() && this->has_data()) {
|
||||
if (this->is_selected() && this->has_data()) {
|
||||
*this->cur_data_ptr++ = BYTESWAP_16(value);
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
@@ -159,7 +160,7 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
break;
|
||||
}
|
||||
this->r_command = value;
|
||||
if (is_selected() || this->r_command == DIAGNOSTICS) {
|
||||
if (this->is_selected() || this->r_command == DIAGNOSTICS) {
|
||||
perform_command();
|
||||
}
|
||||
break;
|
||||
@@ -191,6 +192,38 @@ void AtaBaseDevice::device_control(const uint8_t new_ctrl) {
|
||||
this->r_dev_ctrl = new_ctrl;
|
||||
}
|
||||
|
||||
int AtaBaseDevice::pull_data(uint8_t *buf, int len) {
|
||||
if (!this->xfer_cnt || !this->is_dma_xfer)
|
||||
return 0;
|
||||
|
||||
int xfer_size = std::min(this->xfer_cnt, len);
|
||||
|
||||
if (this->xfer_cnt != len)
|
||||
LOG_F(WARNING, "%s: xfer_cnt != len", this->name.c_str());
|
||||
|
||||
//for (int i = 0; i < xfer_size >> 1; i++)
|
||||
// this->data_ptr[i] = BYTESWAP_16(this->data_ptr[i]);
|
||||
|
||||
std::memcpy(buf, this->data_ptr, xfer_size);
|
||||
|
||||
this->xfer_cnt -= xfer_size;
|
||||
if (!this->xfer_cnt) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(500, [this]() {
|
||||
this->r_status &= ~(BSY | DRQ);
|
||||
this->update_intrq(1);
|
||||
});
|
||||
} else {
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= DRQ;
|
||||
}
|
||||
|
||||
return xfer_size;
|
||||
}
|
||||
|
||||
int AtaBaseDevice::push_data(uint8_t *buf, int len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
|
||||
if (!this->is_selected() || (this->r_dev_ctrl & IEN))
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -43,10 +43,12 @@ public:
|
||||
void set_host(IdeChannel* host, uint8_t dev_id) {
|
||||
this->host_obj = host;
|
||||
this->my_dev_id = dev_id;
|
||||
};
|
||||
}
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
int pull_data(uint8_t *buf, int len) override;
|
||||
int push_data(uint8_t *buf, int len) override;
|
||||
|
||||
virtual int perform_command() = 0;
|
||||
|
||||
@@ -54,7 +56,7 @@ public:
|
||||
|
||||
void pdiag_callback() override {
|
||||
this->r_error &= 0x7F;
|
||||
};
|
||||
}
|
||||
|
||||
virtual void device_reset(bool is_soft_reset);
|
||||
virtual void device_set_signature();
|
||||
@@ -103,6 +105,7 @@ protected:
|
||||
int xfer_cnt = 0;
|
||||
int chunk_cnt = 0;
|
||||
int chunk_size = 0;
|
||||
bool is_dma_xfer = false;
|
||||
|
||||
std::function<void()> post_xfer_action = nullptr;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -56,7 +56,8 @@ enum ATA_Reg : int {
|
||||
COMMAND = 0x07, // command (write)
|
||||
ALT_STATUS = 0x16, // alt status (read)
|
||||
DEV_CTRL = 0x16, // device control (write)
|
||||
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
|
||||
TIME_CONFIG = 0x20, // Apple ASIC specific timing configuration
|
||||
INT_REG = 0x30, // Interrupt Register (read) 0x40 = int request (KeyLargo only)
|
||||
};
|
||||
|
||||
/** ATAPI specific register offsets. */
|
||||
@@ -142,8 +143,11 @@ enum ATA_Cmd : uint8_t {
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
SET_MULTIPLE_MODE = 0xC6,
|
||||
READ_DMA = 0xC8,
|
||||
READ_DMA_NR = 0xC9,
|
||||
WRITE_DMA = 0xCA,
|
||||
STANDBY_IMMEDIATE_E0 = 0xE0,
|
||||
WRITE_DMA_NR = 0xCB,
|
||||
STANDBY_IMMEDIATE = 0xE0,
|
||||
SLEEP = 0xE6,
|
||||
FLUSH_CACHE = 0xE7, // ATA-5
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
@@ -151,7 +155,7 @@ enum ATA_Cmd : uint8_t {
|
||||
SET_FEATURES = 0xEF,
|
||||
};
|
||||
|
||||
}; // namespace ata_interface
|
||||
} // namespace ata_interface
|
||||
|
||||
/** Interface for ATA devices. */
|
||||
class AtaInterface {
|
||||
@@ -160,9 +164,11 @@ public:
|
||||
virtual ~AtaInterface() = default;
|
||||
virtual uint16_t read(const uint8_t reg_addr) = 0;
|
||||
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
|
||||
virtual int pull_data(uint8_t *buf, int len) { return 0; };
|
||||
virtual int push_data(uint8_t *buf, int len) { return 0; };
|
||||
|
||||
virtual int get_device_id() = 0;
|
||||
virtual void pdiag_callback() {};
|
||||
virtual void pdiag_callback() {}
|
||||
};
|
||||
|
||||
/** Dummy ATA device. */
|
||||
@@ -178,12 +184,12 @@ public:
|
||||
// to prevent the software from waiting for a long time
|
||||
// for empty slots
|
||||
return 0xFF7FU;
|
||||
};
|
||||
}
|
||||
|
||||
void write(const uint8_t reg_addr, const uint16_t val) override {};
|
||||
void write(const uint8_t reg_addr, const uint16_t val) override {}
|
||||
|
||||
// invalid device ID means no real device is present
|
||||
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; };
|
||||
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; }
|
||||
};
|
||||
|
||||
#endif // ATA_INTERFACE_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -191,7 +191,11 @@ int AtaHardDisk::perform_command() {
|
||||
this->signal_data_ready();
|
||||
break;
|
||||
case SET_FEATURES:
|
||||
if (this->r_features == 3) {
|
||||
switch (this->r_features) {
|
||||
case 2:
|
||||
LOG_F(INFO, "%s: write cache enabled", this->name.c_str());
|
||||
break;
|
||||
case 3:
|
||||
switch(this->r_sect_count >> 3) {
|
||||
case 0:
|
||||
LOG_F(INFO, "%s: default transfer mode requested", this->name.c_str());
|
||||
@@ -201,8 +205,9 @@ int AtaHardDisk::perform_command() {
|
||||
this->r_sect_count & 7);
|
||||
break;
|
||||
case 4:
|
||||
this->cur_dma_mode = this->r_sect_count & 7;
|
||||
LOG_F(INFO, "%s: Multiword DMA mode set to 0x%X", this->name.c_str(),
|
||||
this->r_sect_count & 7);
|
||||
this->cur_dma_mode);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported transfer mode 0x%X", this->name.c_str(),
|
||||
@@ -210,15 +215,19 @@ int AtaHardDisk::perform_command() {
|
||||
this->r_error |= ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
case 0xAA:
|
||||
LOG_F(INFO, "%s: read look-ahead enabled", this->name.c_str());
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unsupported SET_FEATURES subcommand code 0x%X",
|
||||
this->name.c_str(), this->r_features);
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case STANDBY_IMMEDIATE_E0:
|
||||
LOG_F(INFO, "%s: STANDBY_IMMEDIATE_E0", this->name.c_str());
|
||||
case STANDBY_IMMEDIATE:
|
||||
LOG_F(INFO, "%s: immediate standby requested", this->name.c_str());
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
@@ -236,35 +245,40 @@ void AtaHardDisk::prepare_identify_info() {
|
||||
|
||||
std::memset(this->data_buf, 0, sizeof(this->data_buf));
|
||||
|
||||
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
|
||||
buf_ptr[49] = 0x0200; // report LBA support
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 0], 0x0040); // ATA device, non-removable media, non-removable drive
|
||||
WRITE_WORD_LE_A(&buf_ptr[49], 0x0200); // report LBA support
|
||||
|
||||
// Maximum number of logical sectors per data block that the device supports
|
||||
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
buf_ptr[47] = 0x8000 | SECTORS_PER_INT;
|
||||
WRITE_WORD_LE_A(&buf_ptr[47], 0x8000 | SECTORS_PER_INT);
|
||||
|
||||
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
|
||||
// logical sectors that shall be transferred per data block for
|
||||
// READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
if (this->sectors_per_int)
|
||||
buf_ptr[59] = 0x100 | this->sectors_per_int;
|
||||
WRITE_WORD_LE_A(&buf_ptr[59], 0x100 | this->sectors_per_int);
|
||||
|
||||
buf_ptr[ 1] = this->cylinders;
|
||||
buf_ptr[ 3] = this->heads;
|
||||
buf_ptr[ 6] = this->sectors;
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 1], this->cylinders);
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 3], this->heads);
|
||||
WRITE_WORD_LE_A(&buf_ptr[ 6], this->sectors);
|
||||
|
||||
buf_ptr[57] = this->total_sectors & 0xFFFFU;
|
||||
buf_ptr[58] = (this->total_sectors >> 16) & 0xFFFFU;
|
||||
WRITE_WORD_LE_A(&buf_ptr[51], 0x0200); // max. PIO mode for a basic device
|
||||
|
||||
// report validity for the advanced PIO and MWDMA fields
|
||||
//WRITE_WORD_LE_A(&buf_ptr[53], 0x0003);
|
||||
|
||||
WRITE_DWORD_LE_A(&buf_ptr[57], this->total_sectors);
|
||||
|
||||
// report LBA capacity
|
||||
WRITE_WORD_LE_A(&buf_ptr[60], (this->total_sectors & 0xFFFFU));
|
||||
WRITE_WORD_LE_A(&buf_ptr[61], (this->total_sectors >> 16) & 0xFFFFU);
|
||||
WRITE_DWORD_LE_A(&buf_ptr[60], this->total_sectors);
|
||||
|
||||
WRITE_WORD_LE_A(&buf_ptr[63], ((1 << this->cur_dma_mode) << 8) | 7);
|
||||
}
|
||||
|
||||
uint64_t AtaHardDisk::get_lba() {
|
||||
if (this->r_dev_head & ATA_Dev_Head::LBA) {
|
||||
return ((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
|
||||
(this->r_cylinder_lo << 8) | (this->r_sect_num);
|
||||
return uint64_t(((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
|
||||
(this->r_cylinder_lo << 8) | (this->r_sect_num));
|
||||
} else { // translate old fashioned CHS addressing to LBA
|
||||
uint16_t c = (this->r_cylinder_hi << 8) + this->r_cylinder_lo;
|
||||
uint8_t h = this->r_dev_head & 0xF;
|
||||
@@ -274,7 +288,7 @@ uint64_t AtaHardDisk::get_lba() {
|
||||
LOG_F(ERROR, "%s: zero sector number is not allowed!", this->name.c_str());
|
||||
return -1ULL;
|
||||
} else
|
||||
return (this->heads * c + h) * this->sectors + s - 1;
|
||||
return uint64_t((this->heads * c + h) * this->sectors + s - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +345,7 @@ static const PropMap AtaHardDisk_Properties = {
|
||||
};
|
||||
|
||||
static const DeviceDescription AtaHardDisk_Descriptor = {
|
||||
AtaHardDisk::create, {}, AtaHardDisk_Properties
|
||||
AtaHardDisk::create, {}, AtaHardDisk_Properties, HWCompType::IDE_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -71,6 +71,7 @@ private:
|
||||
uint8_t sectors;
|
||||
|
||||
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
|
||||
uint8_t cur_dma_mode = 2; // current multi-word DMA mode
|
||||
|
||||
char * buffer = new char[1 <<17];
|
||||
};
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
// methods to be implemented in the particular device
|
||||
int perform_command() override;
|
||||
virtual void perform_packet_command() = 0;
|
||||
virtual int get_config(uint8_t* pkt, uint8_t* buf) = 0;
|
||||
virtual int request_data() = 0;
|
||||
virtual bool data_available() = 0;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <core/timermanager.h>
|
||||
|
||||
@@ -315,6 +316,18 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->data_out_phase();
|
||||
break;
|
||||
}
|
||||
case ScsiCommand::GET_CONFIG: {
|
||||
this->xfer_cnt = this->get_config(this->cmd_pkt, this->data_buf);
|
||||
if (this->xfer_cnt == 0) {
|
||||
this->present_status();
|
||||
} else {
|
||||
this->xfer_cnt = std::min((int)this->r_byte_count, this->xfer_cnt);
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported ATAPI command 0x%X", this->name.c_str(),
|
||||
this->cmd_pkt[0]);
|
||||
@@ -323,6 +336,29 @@ void AtapiCdrom::perform_packet_command() {
|
||||
}
|
||||
}
|
||||
|
||||
int AtapiCdrom::get_config(uint8_t* pkt, uint8_t* buf) {
|
||||
std::memset(buf, 0, 16);
|
||||
|
||||
// Data length (4 bytes header + 8 bytes for one feature descriptor - 4 bytes for length field)
|
||||
uint32_t data_len = 8;
|
||||
buf[0] = (data_len >> 24) & 0xFF;
|
||||
buf[1] = (data_len >> 16) & 0xFF;
|
||||
buf[2] = (data_len >> 8) & 0xFF;
|
||||
buf[3] = data_len & 0xFF;
|
||||
|
||||
// Feature Descriptor 1 - Set profile to CD-ROM
|
||||
buf[6] = 0;
|
||||
buf[7] = 0x08;
|
||||
|
||||
// Feature Descriptor 2 - Feature Code, Version 0
|
||||
buf[8] = 0x00;
|
||||
buf[9] = 0x01; // Core Feature Code
|
||||
buf[10] = 0x03; // Persist and Current bits set
|
||||
buf[11] = 0x04; // Additional Length
|
||||
|
||||
return 12;
|
||||
}
|
||||
|
||||
int AtapiCdrom::request_data() {
|
||||
// continuation of READ_CD above
|
||||
|
||||
@@ -358,11 +394,12 @@ uint16_t AtapiCdrom::get_data() {
|
||||
area_end += 4; // Header
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
AddrMsf msf = lba_to_msf(this->current_block + 150);
|
||||
uint8_t header[4];
|
||||
header[0] = msf.min;
|
||||
header[1] = msf.sec;
|
||||
header[2] = msf.frm;
|
||||
header[3] = 0x01; // Mode 1
|
||||
uint8_t header[4]{
|
||||
(uint8_t)msf.min,
|
||||
(uint8_t)msf.sec,
|
||||
(uint8_t)msf.frm,
|
||||
0x01 // Mode 1
|
||||
};
|
||||
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
|
||||
}
|
||||
}
|
||||
@@ -438,7 +475,7 @@ static const PropMap AtapiCdrom_Properties = {
|
||||
};
|
||||
|
||||
static const DeviceDescription AtapiCdrom_Descriptor = {
|
||||
AtapiCdrom::create, {}, AtapiCdrom_Properties
|
||||
AtapiCdrom::create, {}, AtapiCdrom_Properties, HWCompType::IDE_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
|
||||
void perform_packet_command() override;
|
||||
|
||||
int get_config(uint8_t* pkt, uint8_t* buf) override;
|
||||
|
||||
int request_data() override;
|
||||
|
||||
bool data_available() override {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -139,7 +139,7 @@ bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
|
||||
switch(reg_offset) {
|
||||
|
||||
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
and interrupt handling.
|
||||
*/
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
@@ -81,6 +82,21 @@ void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int siz
|
||||
}
|
||||
}
|
||||
|
||||
int IdeChannel::xfer_from(uint8_t *buf, int len) {
|
||||
return this->devices[this->cur_dev]->pull_data(buf, len);
|
||||
}
|
||||
|
||||
int IdeChannel::xfer_to(uint8_t *buf, int len) {
|
||||
return this->devices[this->cur_dev]->push_data(buf, len);
|
||||
}
|
||||
|
||||
void IdeChannel::assert_dmareq(uint64_t delay) {
|
||||
TimerManager::get_instance()->add_oneshot_timer(delay, [this]() {
|
||||
//LOG_F(INFO, "%s: DMAREQ asserted", this->name.c_str());
|
||||
this->channel_obj->xfer_retry();
|
||||
});
|
||||
}
|
||||
|
||||
int MacioIdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
@@ -117,11 +133,11 @@ void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const in
|
||||
}
|
||||
|
||||
static const DeviceDescription Ide0_Descriptor = {
|
||||
MacioIdeChannel::create_first, {}, {}
|
||||
MacioIdeChannel::create_first, {}, {}, HWCompType::IDE_BUS
|
||||
};
|
||||
|
||||
static const DeviceDescription Ide1_Descriptor = {
|
||||
MacioIdeChannel::create_second, {}, {}
|
||||
MacioIdeChannel::create_second, {}, {}, HWCompType::IDE_BUS
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define IDE_CHANNEL_H
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
@@ -33,7 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class IdeChannel : public HWComponent
|
||||
class IdeChannel : public HWComponent, public DmaDevice
|
||||
{
|
||||
public:
|
||||
IdeChannel(const std::string name);
|
||||
@@ -41,8 +42,11 @@ public:
|
||||
|
||||
void register_device(int id, AtaInterface* dev_obj);
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
virtual uint32_t read(const uint8_t reg_addr, const int size);
|
||||
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
|
||||
int xfer_from(uint8_t *buf, int len) override;
|
||||
int xfer_to(uint8_t *buf, int len) override;
|
||||
|
||||
void assert_pdiag() {
|
||||
this->devices[0]->pdiag_callback();
|
||||
@@ -60,6 +64,8 @@ public:
|
||||
this->irq_callback(intrq_state);
|
||||
}
|
||||
|
||||
void assert_dmareq(uint64_t delay);
|
||||
|
||||
protected:
|
||||
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
|
||||
|
||||
@@ -74,7 +80,7 @@ private:
|
||||
class MacioIdeChannel : public IdeChannel
|
||||
{
|
||||
public:
|
||||
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
|
||||
MacioIdeChannel(const std::string name) : IdeChannel(name) {}
|
||||
~MacioIdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
@@ -87,8 +93,8 @@ public:
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
virtual uint32_t read(const uint8_t reg_addr, const int size) override;
|
||||
virtual void write(const uint8_t reg_addr, const uint32_t val, const int size) override;
|
||||
|
||||
private:
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -38,10 +38,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr)
|
||||
{
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr) : I2CDevice() {
|
||||
set_name("Athens");
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
|
||||
@@ -75,10 +73,9 @@ bool AthensClocks::send_subaddress(uint8_t sub_addr)
|
||||
|
||||
bool AthensClocks::send_byte(uint8_t data)
|
||||
{
|
||||
switch (this->pos) {
|
||||
switch (this->pos++) {
|
||||
case 0:
|
||||
this->reg_num = data;
|
||||
this->pos++;
|
||||
break;
|
||||
case 1:
|
||||
if (this->reg_num >= ATHENS_NUM_REGS) {
|
||||
@@ -90,7 +87,7 @@ bool AthensClocks::send_byte(uint8_t data)
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: too much data received!", this->name.c_str());
|
||||
return false; // return NACK
|
||||
//return false; // return NACK
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -103,6 +100,8 @@ bool AthensClocks::receive_byte(uint8_t* p_data)
|
||||
|
||||
int AthensClocks::get_sys_freq()
|
||||
{
|
||||
LOG_F(ERROR, "%s: sys clock calculation not implemented yet", this->name.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,7 +24,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ATHENS_H
|
||||
#define ATHENS_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -47,10 +46,9 @@ enum AthensRegs: uint8_t {
|
||||
P1 = 7
|
||||
};
|
||||
|
||||
}; // namespace AthensRegs
|
||||
} // namespace AthensRegs
|
||||
|
||||
class AthensClocks : public I2CDevice, public HWComponent
|
||||
{
|
||||
class AthensClocks : public I2CDevice {
|
||||
public:
|
||||
AthensClocks(uint8_t dev_addr);
|
||||
AthensClocks(uint8_t dev_addr, const float crystal_freq);
|
||||
|
||||
@@ -313,6 +313,15 @@ uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
result = this->cmd_ptr;
|
||||
break;
|
||||
case DMAReg::INT_SELECT:
|
||||
result = this->int_select;
|
||||
break;
|
||||
case DMAReg::BRANCH_SELECT:
|
||||
result = this->branch_select;
|
||||
break;
|
||||
case DMAReg::WAIT_SELECT:
|
||||
result = this->wait_select;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
|
||||
this->get_name().c_str(), offset);
|
||||
@@ -431,6 +440,9 @@ void DMAChannel::xfer_from_device() {
|
||||
if (got_bytes == this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
this->finish_cmd();
|
||||
} else if (got_bytes) {
|
||||
LOG_F(WARNING, "%s: got unexpected amount of data in xfer_from_device",
|
||||
this->get_name().c_str());
|
||||
}
|
||||
|
||||
this->interpret_cmd();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -99,7 +99,7 @@ namespace DBDMA_Cmd {
|
||||
NOP = 6,
|
||||
STOP = 7
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
this->irq_id = irq_id;
|
||||
};
|
||||
}
|
||||
|
||||
protected:
|
||||
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
|
||||
|
||||
+21
-21
@@ -35,15 +35,15 @@ enum DmaPullResult : int {
|
||||
|
||||
class DmaOutChannel {
|
||||
public:
|
||||
DmaOutChannel(std::string name) { this->name = name; };
|
||||
DmaOutChannel(std::string name) { this->name = name; }
|
||||
|
||||
virtual bool is_out_active() { return true; };
|
||||
virtual bool is_out_active() { return true; }
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
virtual int get_pull_data_remaining() { return 1; };
|
||||
virtual void end_pull_data() { };
|
||||
virtual int get_pull_data_remaining() { return 1; }
|
||||
virtual void end_pull_data() {}
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
std::string get_name(void) { return this->name; }
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
@@ -51,14 +51,14 @@ private:
|
||||
|
||||
class DmaInChannel {
|
||||
public:
|
||||
DmaInChannel(std::string name) { this->name = name; };
|
||||
DmaInChannel(std::string name) { this->name = name; }
|
||||
|
||||
virtual bool is_in_active() { return true; };
|
||||
virtual bool is_in_active() { return true; }
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
virtual int get_push_data_remaining() { return 1; };
|
||||
virtual void end_push_data() { };
|
||||
virtual int get_push_data_remaining() { return 1; }
|
||||
virtual void end_push_data() {}
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
std::string get_name(void) { return this->name; }
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
@@ -68,9 +68,9 @@ private:
|
||||
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
|
||||
public:
|
||||
DmaBidirChannel(std::string name) : DmaOutChannel(name + " Out"),
|
||||
DmaInChannel(name + std::string(" In")) { this->name = name; };
|
||||
DmaInChannel(name + std::string(" In")) { this->name = name; }
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
std::string get_name(void) { return this->name; }
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
@@ -96,11 +96,11 @@ public:
|
||||
DmaDevice() = default;
|
||||
~DmaDevice() = default;
|
||||
|
||||
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
|
||||
virtual void notify(DmaMsg msg) {};
|
||||
virtual int xfer_from(uint8_t *buf, int len) { return len; };
|
||||
virtual int xfer_to(uint8_t *buf, int len) { return len; };
|
||||
virtual int tell_xfer_size() { return 0; };
|
||||
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; }
|
||||
virtual void notify(DmaMsg msg) {}
|
||||
virtual int xfer_from(uint8_t *buf, int len) { return len; }
|
||||
virtual int xfer_to(uint8_t *buf, int len) { return len; }
|
||||
virtual int tell_xfer_size() { return 0; }
|
||||
|
||||
protected:
|
||||
DmaChannel* channel_obj = nullptr;
|
||||
@@ -111,10 +111,10 @@ public:
|
||||
DmaChannel() = default;
|
||||
~DmaChannel() = default;
|
||||
|
||||
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
|
||||
virtual void notify(DmaMsg msg) {};
|
||||
virtual bool is_ready() { return false; };
|
||||
virtual void xfer_retry() {};
|
||||
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; }
|
||||
virtual void notify(DmaMsg msg) {}
|
||||
virtual bool is_ready() { return false; }
|
||||
virtual void xfer_retry() {}
|
||||
|
||||
protected:
|
||||
DmaDevice* dev_obj = nullptr;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -35,6 +35,7 @@ enum HWCompType : uint64_t {
|
||||
MMIO_DEV = 1ULL << 4, // memory mapped I/O device
|
||||
PCI_HOST = 1ULL << 5, // PCI host
|
||||
PCI_DEV = 1ULL << 6, // PCI device
|
||||
NUBUS_DEV = 1ULL << 7, // Nubus device
|
||||
I2C_HOST = 1ULL << 8, // I2C host
|
||||
I2C_DEV = 1ULL << 9, // I2C device
|
||||
ADB_HOST = 1ULL << 12, // ADB host
|
||||
@@ -53,6 +54,7 @@ enum HWCompType : uint64_t {
|
||||
FLOPPY_CTRL = 1ULL << 32, // floppy disk controller
|
||||
FLOPPY_DRV = 1ULL << 33, // floppy disk drive
|
||||
ETHER_MAC = 1ULL << 40, // Ethernet media access controller
|
||||
MACHINE = 1ULL << 41, // machine root
|
||||
};
|
||||
|
||||
/** Base class for HW components. */
|
||||
@@ -63,22 +65,22 @@ public:
|
||||
|
||||
virtual std::string get_name(void) {
|
||||
return this->name;
|
||||
};
|
||||
}
|
||||
virtual void set_name(std::string name) {
|
||||
this->name = name;
|
||||
};
|
||||
}
|
||||
|
||||
virtual bool supports_type(HWCompType type) {
|
||||
return !!(this->supported_types & type);
|
||||
};
|
||||
}
|
||||
|
||||
virtual void supports_types(uint64_t types) {
|
||||
this->supported_types = types;
|
||||
};
|
||||
}
|
||||
|
||||
virtual int device_postinit() {
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -35,8 +36,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
|
||||
/** Base class for I2C devices */
|
||||
class I2CDevice {
|
||||
class I2CDevice : virtual public HWComponent {
|
||||
public:
|
||||
I2CDevice() {
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
}
|
||||
virtual ~I2CDevice() = default;
|
||||
|
||||
virtual void start_transaction() = 0;
|
||||
virtual bool send_subaddress(uint8_t sub_addr) = 0;
|
||||
virtual bool send_byte(uint8_t data) = 0;
|
||||
@@ -44,11 +50,11 @@ public:
|
||||
};
|
||||
|
||||
/** Base class for I2C hosts */
|
||||
class I2CBus {
|
||||
class I2CBus : virtual public HWComponent {
|
||||
public:
|
||||
I2CBus() {
|
||||
std::memset(this->dev_list, 0, sizeof(this->dev_list));
|
||||
};
|
||||
}
|
||||
virtual ~I2CBus() = default;
|
||||
|
||||
virtual void register_device(uint8_t dev_addr, I2CDevice* dev_obj) {
|
||||
@@ -57,7 +63,7 @@ public:
|
||||
}
|
||||
this->dev_list[dev_addr] = dev_obj;
|
||||
LOG_F(INFO, "New I2C device, address = 0x%X", dev_addr);
|
||||
};
|
||||
}
|
||||
|
||||
virtual bool start_transaction(uint8_t dev_addr) {
|
||||
if (this->dev_list[dev_addr]) {
|
||||
@@ -66,28 +72,28 @@ public:
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
virtual bool send_subaddress(uint8_t dev_addr, uint8_t sub_addr) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
return this->dev_list[dev_addr]->send_subaddress(sub_addr);
|
||||
};
|
||||
}
|
||||
|
||||
virtual bool send_byte(uint8_t dev_addr, uint8_t data) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
return this->dev_list[dev_addr]->send_byte(data);
|
||||
};
|
||||
}
|
||||
|
||||
virtual bool receive_byte(uint8_t dev_addr, uint8_t* p_data) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
return this->dev_list[dev_addr]->receive_byte(p_data);
|
||||
};
|
||||
}
|
||||
|
||||
protected:
|
||||
I2CDevice* dev_list[128]; /* list of registered I2C devices */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -54,17 +54,17 @@ void I2CProm::set_memory(int start, const uint8_t* in_data, int size)
|
||||
|
||||
void I2CProm::start_transaction() {
|
||||
this->pos = 0;
|
||||
};
|
||||
}
|
||||
|
||||
bool I2CProm::send_subaddress(uint8_t sub_addr) {
|
||||
this->pos = sub_addr;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
bool I2CProm::send_byte(uint8_t data) {
|
||||
LOG_F(9, "I2CRom: 0x%X received", data);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
bool I2CProm::receive_byte(uint8_t* p_data) {
|
||||
if (this->pos >= this->rom_size) {
|
||||
@@ -72,4 +72,4 @@ bool I2CProm::receive_byte(uint8_t* p_data) {
|
||||
}
|
||||
*p_data = this->data[this->pos++];
|
||||
return true;
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,14 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef I2C_PROM_H
|
||||
#define I2C_PROM_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class I2CProm : public I2CDevice, public HWComponent
|
||||
{
|
||||
class I2CProm : public I2CDevice {
|
||||
public:
|
||||
I2CProm(uint8_t dev_addr, int size);
|
||||
~I2CProm() = default;
|
||||
|
||||
+12
-12
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -43,7 +43,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Machine ID register for NuBus Power Macs.
|
||||
It's located at physical address 0x5FFFFFFC and contains four bytes:
|
||||
+0 uint16_t signature = 0xA55A
|
||||
+1 uint8_t machine_type (3 - Power Mac)
|
||||
+1 uint8_t machine_type (0x30 - Power Mac)
|
||||
+2 uint8_t model (0x10 = PDM, 0x12 = Carl Sagan, 0x13 = Cold Fusion)
|
||||
*/
|
||||
class NubusMacID : public MMIODevice {
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
this->id[2] = (id >> 8) & 0xFF;
|
||||
this->id[3] = id & 0xFF;
|
||||
supports_types(HWCompType::MMIO_DEV);
|
||||
};
|
||||
}
|
||||
~NubusMacID() = default;
|
||||
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
@@ -67,10 +67,10 @@ public:
|
||||
}
|
||||
ABORT_F("NubusMacID: invalid read size %d, offset %d!", size, offset);
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
|
||||
|
||||
private:
|
||||
uint8_t id[4];
|
||||
@@ -88,19 +88,19 @@ public:
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::IOBUS_DEV);
|
||||
this->data = data;
|
||||
};
|
||||
}
|
||||
~BoardRegister() = default;
|
||||
|
||||
uint16_t iodev_read(uint32_t address) {
|
||||
return this->data;
|
||||
};
|
||||
}
|
||||
|
||||
// appears read-only to guest
|
||||
void iodev_write(uint32_t address, uint16_t value) {};
|
||||
void iodev_write(uint32_t address, uint16_t value) {}
|
||||
|
||||
void update_bits(const uint16_t val, const uint16_t mask) {
|
||||
this->data = (this->data & ~mask) | (val & mask);
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t data;
|
||||
@@ -118,15 +118,15 @@ public:
|
||||
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 == 4 && size == 2) ? this->id : 0);
|
||||
};
|
||||
}
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {}
|
||||
|
||||
private:
|
||||
uint16_t id;
|
||||
|
||||
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -46,6 +47,9 @@ NVram::NVram(std::string file_name, uint32_t ram_size)
|
||||
this->file_name = file_name;
|
||||
this->ram_size = ram_size;
|
||||
|
||||
if (ram_size == 8192)
|
||||
this->of_nvram_offset = OF_NVRAM_OFFSET;
|
||||
|
||||
// allocate memory storage and fill it with zeroes
|
||||
this->storage = std::unique_ptr<uint8_t[]>(new uint8_t[ram_size] ());
|
||||
|
||||
@@ -99,7 +103,7 @@ void NVram::save() {
|
||||
}
|
||||
|
||||
static const DeviceDescription Nvram_Descriptor = {
|
||||
NVram::create, {}, {}
|
||||
NVram::create, {}, {}, HWCompType::NVRAM
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(NVRAM, Nvram_Descriptor);
|
||||
@@ -45,11 +45,13 @@ public:
|
||||
|
||||
uint8_t read_byte(uint32_t offset);
|
||||
void write_byte(uint32_t offset, uint8_t value);
|
||||
uint32_t get_of_nvram_offset() { return of_nvram_offset; }
|
||||
|
||||
private:
|
||||
std::string file_name; // file name for the backing file
|
||||
uint16_t ram_size; // NVRAM size
|
||||
std::unique_ptr<uint8_t[]> storage;
|
||||
uint32_t of_nvram_offset = 0;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
|
||||
@@ -67,7 +67,7 @@ bool OfConfigAppl::validate() {
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfConfigHdrAppl); i++) {
|
||||
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
|
||||
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
|
||||
}
|
||||
|
||||
// validate partition signature and version
|
||||
@@ -81,7 +81,7 @@ bool OfConfigAppl::validate() {
|
||||
|
||||
// read the entire partition into the local buffer
|
||||
for (i = 0; i < this->size; i++) {
|
||||
this->buf[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
|
||||
this->buf[i] = this->nvram_obj->read_byte(this->nvram_obj->get_of_nvram_offset() + i);
|
||||
}
|
||||
|
||||
// verify partition checksum
|
||||
@@ -161,7 +161,7 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
|
||||
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_offset = READ_WORD_BE_A(&this->buf[offset]) - this->nvram_obj->get_of_nvram_offset();
|
||||
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
|
||||
|
||||
if ((str_offset + str_len) > OF_CFG_SIZE) {
|
||||
@@ -194,7 +194,7 @@ void OfConfigAppl::update_partition() {
|
||||
|
||||
// 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]);
|
||||
this->nvram_obj->write_byte(this->nvram_obj->get_of_nvram_offset() + i, this->buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,8 +266,8 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
|
||||
}
|
||||
|
||||
// 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 - this->nvram_obj->get_of_nvram_offset()],
|
||||
&this->buf[top - this->nvram_obj->get_of_nvram_offset()], str_offset - top);
|
||||
|
||||
for (auto& var : of_vars) {
|
||||
auto type = std::get<0>(var.second);
|
||||
@@ -284,7 +284,7 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
|
||||
// copy new string into NVRAM buffer char by char
|
||||
i = 0;
|
||||
for(char& ch : value) {
|
||||
this->buf[top + i - OF_NVRAM_OFFSET] = ch == '\x0A' ? '\x0D' : ch;
|
||||
this->buf[top + i - this->nvram_obj->get_of_nvram_offset()] = ch == '\x0A' ? '\x0D' : ch;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
// Old World implementation
|
||||
class OfConfigAppl : public OfConfigImpl {
|
||||
public:
|
||||
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
|
||||
OfConfigAppl(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
|
||||
~OfConfigAppl() = default;
|
||||
|
||||
bool validate();
|
||||
@@ -108,7 +108,7 @@ private:
|
||||
// New World implementation
|
||||
class OfConfigChrp : public OfConfigImpl {
|
||||
public:
|
||||
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; };
|
||||
OfConfigChrp(NVram* nvram_obj) { this->nvram_obj = nvram_obj; }
|
||||
~OfConfigChrp() = default;
|
||||
|
||||
bool validate();
|
||||
|
||||
@@ -394,23 +394,23 @@ static const std::vector<std::string> Chaos_Subdevices = {
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit1_Descriptor = {
|
||||
Bandit::create_first, {}, Bandit1_Properties
|
||||
Bandit::create_first, {}, Bandit1_Properties, HWCompType::PCI_HOST
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit2_Descriptor = {
|
||||
Bandit::create_second, {}, Bandit2_Properties
|
||||
Bandit::create_second, {}, Bandit2_Properties, HWCompType::PCI_HOST
|
||||
};
|
||||
|
||||
static const DeviceDescription PsxPci1_Descriptor = {
|
||||
Bandit::create_psx_first, {}, PsxPci1_Properties
|
||||
Bandit::create_psx_first, {}, PsxPci1_Properties, HWCompType::PCI_HOST
|
||||
};
|
||||
|
||||
static const DeviceDescription Chaos_Descriptor = {
|
||||
Chaos::create, Chaos_Subdevices, Chaos_Properties
|
||||
Chaos::create, Chaos_Subdevices, Chaos_Properties, HWCompType::PCI_HOST
|
||||
};
|
||||
|
||||
static const DeviceDescription AspenPci1_Descriptor = {
|
||||
AspenPci::create, {}, Bandit1_Properties
|
||||
AspenPci::create, {}, Bandit1_Properties, HWCompType::PCI_HOST
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -71,7 +71,7 @@ enum {
|
||||
*/
|
||||
class BanditHost : public PCIHost, public MMIODevice {
|
||||
public:
|
||||
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
|
||||
BanditHost(int bridge_num) { this->bridge_num = bridge_num; }
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
|
||||
@@ -121,15 +121,15 @@ public:
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
|
||||
};
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(2, "Bandit-PCI2"));
|
||||
};
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_psx_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<BanditPciDevice> my_pci_device;
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<Chaos>(new Chaos("VCI0"));
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AspenPci>(new AspenPci("Aspen-PCI1"));
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
#endif // BANDIT_PCI_H
|
||||
@@ -102,11 +102,11 @@ static const PropMap Dec21154Yosemite_Properties = {
|
||||
};
|
||||
|
||||
static const DeviceDescription Dec21154_Descriptor = {
|
||||
DecPciBridge::create, {}, {}
|
||||
DecPciBridge::create, {}, {}, HWCompType::PCI_HOST | HWCompType::PCI_DEV
|
||||
};
|
||||
|
||||
static const DeviceDescription Dec21154Yosemite_Descriptor = {
|
||||
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties
|
||||
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties, HWCompType::PCI_HOST | HWCompType::PCI_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -41,7 +41,10 @@ PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
|
||||
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
|
||||
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
|
||||
|
||||
this->pci_wr_stat = [](uint16_t val) {};
|
||||
this->pci_wr_stat = [this](uint16_t val) {
|
||||
this->status &= ~(0b1111100100000000 & val);
|
||||
};
|
||||
|
||||
this->pci_wr_cmd = [this](uint16_t cmd) {
|
||||
/*
|
||||
FIXME: should register or unregister BAR mmio regions if (cmd & 2) changes.
|
||||
@@ -54,7 +57,7 @@ PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
|
||||
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
|
||||
|
||||
this->pci_notify_bar_change = [](int bar_num) {};
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t PCIBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -86,16 +86,16 @@ public:
|
||||
|
||||
virtual bool supports_io_space() {
|
||||
return has_io_space;
|
||||
};
|
||||
}
|
||||
|
||||
/* I/O space access methods */
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
virtual bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
// configuration space access methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -39,12 +39,12 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
|
||||
|
||||
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->memory_base_32 = (((uint64_t)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->memory_limit_32 = (((uint64_t)this->memory_limit & 0xfff0) << 16) + 0x100000;
|
||||
};
|
||||
|
||||
this->pci_wr_io_base = [this](uint8_t val) {
|
||||
@@ -61,12 +61,13 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
|
||||
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);
|
||||
(((uint64_t)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->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
|
||||
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
|
||||
0x100000;
|
||||
};
|
||||
this->pci_wr_io_base_upper16 = [this](uint16_t val) {
|
||||
if ((this->io_base & 15) == 1)
|
||||
@@ -85,16 +86,17 @@ PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1,
|
||||
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);
|
||||
(((uint64_t)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->pref_mem_limit_64 = (((uint64_t)this->pref_limit_upper32 << 32) | \
|
||||
(((uint64_t)this->pref_mem_limit & 0xfff0) << 16)) + \
|
||||
0x100000;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@ PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_b
|
||||
};
|
||||
this->pci_wr_sec_status = [this](uint16_t val) {};
|
||||
this->pci_wr_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
|
||||
};
|
||||
}
|
||||
|
||||
AddressMapEntry* PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
bool supports_io_space() override {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -126,7 +126,7 @@ PCICardbusBridge::PCICardbusBridge(std::string name) : PCIBridgeBase(name, PCI_H
|
||||
this->io_limit_1 = (val & this->io_1_cfg);
|
||||
this->io_limit_1_32 = this->io_limit_1 + 4;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t PCICardbusBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
@@ -219,5 +219,5 @@ bool PCICardbusBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t si
|
||||
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
|
||||
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
|
||||
) return false;
|
||||
return this->pci_io_read_loop(offset, size, value);
|
||||
return this->pci_io_write_loop(offset, size, value);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
PCIDevice::PCIDevice(std::string name) : PCIBase(name, PCI_HEADER_TYPE_0, 6)
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
PCIHost() {
|
||||
this->dev_map.clear();
|
||||
io_space_devs.clear();
|
||||
};
|
||||
}
|
||||
~PCIHost() = default;
|
||||
|
||||
virtual bool pci_register_device(int dev_fun_num, PCIBase* dev_instance);
|
||||
@@ -89,13 +89,13 @@ public:
|
||||
|
||||
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
|
||||
this->my_irq_map = irq_map;
|
||||
};
|
||||
}
|
||||
virtual int pcihost_device_postinit();
|
||||
|
||||
virtual bool register_pci_int(PCIBase* dev_instance);
|
||||
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
};
|
||||
}
|
||||
virtual InterruptCtrl *get_interrupt_controller();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -209,7 +209,16 @@ void MeshController::perform_command(const uint8_t cmd) {
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::BusFree:
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
// Don't release ACK if ATN is asserted. This condition indicates
|
||||
// that the initiator wants to reject last message.
|
||||
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN))
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
// Let the target switch to next bus phase if
|
||||
// - both ACK and ATN are asserted so the target will reject last message
|
||||
// - when in MESSAGE_IN phase to tell the target the initiator accepts last message
|
||||
if (this->is_initiator && (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN) ||
|
||||
this->bus_obj->current_phase() == ScsiPhase::MESSAGE_IN))
|
||||
this->bus_obj->target_next_step();
|
||||
// generate phase mismatch exception
|
||||
// if the target is still connected
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY)) {
|
||||
@@ -282,7 +291,11 @@ void MeshController::step_completed() {
|
||||
}
|
||||
|
||||
void MeshController::report_error(const int error) {
|
||||
switch(error) {
|
||||
switch (error) {
|
||||
case ARB_LOST:
|
||||
this->exception |= EXC_ARB_LOST;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
break;
|
||||
case SEL_TIMEOUT:
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
@@ -299,12 +312,16 @@ static const PropMap Mesh_properties = {
|
||||
{"cdr_img2", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const std::vector<std::string> Mesh_Subdevices = {
|
||||
"ScsiMesh"
|
||||
};
|
||||
|
||||
static const DeviceDescription Mesh_Tnt_Descriptor = {
|
||||
MeshController::create_for_tnt, {}, Mesh_properties
|
||||
MeshController::create_for_tnt, Mesh_Subdevices, Mesh_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
|
||||
};
|
||||
|
||||
static const DeviceDescription Mesh_Heathrow_Descriptor = {
|
||||
MeshController::create_for_heathrow, {}, Mesh_properties
|
||||
MeshController::create_for_heathrow, Mesh_Subdevices, Mesh_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(MeshTnt, Mesh_Tnt_Descriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -91,7 +91,7 @@ namespace MeshScsi {
|
||||
INT_ERROR = 1 << 2,
|
||||
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
|
||||
};
|
||||
}; // namespace MeshScsi
|
||||
} // namespace MeshScsi
|
||||
|
||||
class MeshBase {
|
||||
public:
|
||||
@@ -107,8 +107,8 @@ public:
|
||||
~MeshStub() = default;
|
||||
|
||||
// registers access
|
||||
uint8_t read(uint8_t reg_offset) override { return 0; };
|
||||
void write(uint8_t reg_offset, uint8_t value) override {};
|
||||
uint8_t read(uint8_t reg_offset) override { return 0; }
|
||||
void write(uint8_t reg_offset, uint8_t value) override {}
|
||||
};
|
||||
|
||||
class MeshController : public ScsiBusController, public MeshBase {
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
MeshController(uint8_t mesh_id) : ScsiBusController("MESH", 7) {
|
||||
this->chip_id = mesh_id;
|
||||
this->reset(true);
|
||||
};
|
||||
}
|
||||
~MeshController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_for_tnt() {
|
||||
|
||||
@@ -97,7 +97,11 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
return this->cmd_fifo[0];
|
||||
case Read::Reg53C94::Status:
|
||||
if (this->config2 & CFG2_ENF) {
|
||||
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
|
||||
static bool log_it = true;
|
||||
if (log_it) {
|
||||
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
|
||||
log_it = false;
|
||||
}
|
||||
bus_phase = SCSI_CTRL_MSG; // use reserved bus phase
|
||||
} else
|
||||
bus_phase = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
@@ -849,11 +853,13 @@ int Sc53C94::xfer_from(uint8_t *buf, int len) {
|
||||
|
||||
len = std::min(len, (int)(this->xfer_count));
|
||||
|
||||
// see if there are data bytes in the FIFO we want to grab first
|
||||
if (this->data_fifo_pos) {
|
||||
int fifo_bytes = std::min(this->data_fifo_pos, len);
|
||||
std::memcpy(buf, this->data_fifo, fifo_bytes);
|
||||
this->data_fifo_pos -= fifo_bytes;
|
||||
this->xfer_count -= fifo_bytes;
|
||||
len -= fifo_bytes;
|
||||
bytes_moved += fifo_bytes;
|
||||
buf += fifo_bytes;
|
||||
if (!this->xfer_count) {
|
||||
@@ -864,12 +870,14 @@ int Sc53C94::xfer_from(uint8_t *buf, int len) {
|
||||
}
|
||||
}
|
||||
|
||||
if (this->bus_obj->pull_data(this->target_id, buf, this->xfer_count)) {
|
||||
bytes_moved += this->xfer_count;
|
||||
this->xfer_count = 0;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
if (this->bus_obj->pull_data(this->target_id, buf, len)) {
|
||||
bytes_moved += len;
|
||||
this->xfer_count -= len;
|
||||
if (!this->xfer_count) {
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
|
||||
return bytes_moved;
|
||||
@@ -924,8 +932,12 @@ static const PropMap Sc53C94_properties = {
|
||||
{"cdr_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const std::vector<std::string> Sc53C94_Subdevices = {
|
||||
"ScsiCurio"
|
||||
};
|
||||
|
||||
static const DeviceDescription Sc53C94_Descriptor = {
|
||||
Sc53C94::create, {}, Sc53C94_properties
|
||||
Sc53C94::create, Sc53C94_Subdevices, Sc53C94_properties, HWCompType::SCSI_HOST | HWCompType::SCSI_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Sc53C94, Sc53C94_Descriptor);
|
||||
@@ -58,7 +58,7 @@ namespace Read {
|
||||
Xfer_Cnt_Hi = 0xE, // Current Transfer Count Register High ; Am53CF94 extension
|
||||
//
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** 53C94 write registers */
|
||||
namespace Write {
|
||||
@@ -80,7 +80,7 @@ namespace Write {
|
||||
Xfer_Cnt_Hi = 0xE, // Start Transfer Count Register High ; Am53CF94 extension
|
||||
Data_Align = 0xF, // Data Alignment Register
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** NCR53C94/Am53CF94 commands. */
|
||||
enum {
|
||||
@@ -180,7 +180,7 @@ namespace SeqState {
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
constexpr auto DATA_FIFO_MAX = 16;
|
||||
|
||||
@@ -228,7 +228,7 @@ public:
|
||||
std::bind(&Sc53C94::dma_stop, this)
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void set_drq_callback(DrqCb cb) {
|
||||
this->drq_cb = cb;
|
||||
@@ -236,18 +236,18 @@ public:
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiNotification notif_type, int param) override;
|
||||
bool prepare_data() override { return false; };
|
||||
bool get_more_data() override { return false; };
|
||||
bool has_data() override { return this->data_fifo_pos != 0; };
|
||||
bool prepare_data() override { return false; }
|
||||
bool get_more_data() override { return false; }
|
||||
bool has_data() override { return this->data_fifo_pos != 0; }
|
||||
int send_data(uint8_t* dst_ptr, int count) override;
|
||||
void process_command() override {};
|
||||
void process_command() override {}
|
||||
|
||||
// DmaDevice methods
|
||||
int xfer_from(uint8_t *buf, int len) override;
|
||||
int xfer_to(uint8_t *buf, int len) override;
|
||||
int tell_xfer_size() override {
|
||||
return this->xfer_count;
|
||||
};
|
||||
}
|
||||
|
||||
protected:
|
||||
void reset_device();
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace ScsiPhase {
|
||||
MESSAGE_OUT,
|
||||
RESET,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** SCSI status codes. */
|
||||
namespace ScsiStatus {
|
||||
@@ -70,7 +70,7 @@ namespace ScsiStatus {
|
||||
GOOD = 0,
|
||||
CHECK_CONDITION = 2,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** Standard message codes. */
|
||||
namespace ScsiMessage {
|
||||
@@ -83,7 +83,7 @@ namespace ScsiMessage {
|
||||
HAS_DISCONNECT_PRIVILEDGE = 0x40,
|
||||
IDENTIFY = 0x80,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** Extended message codes. */
|
||||
namespace ScsiExtMessage {
|
||||
@@ -92,7 +92,7 @@ namespace ScsiExtMessage {
|
||||
SYNCH_XFER_REQ = 1,
|
||||
WIDE_XFER_REQ = 3,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** Internal notification codes for our SCSI implementation. */
|
||||
enum ScsiNotification : int {
|
||||
@@ -106,6 +106,7 @@ enum ScsiCommand : uint8_t {
|
||||
REQ_SENSE = 0x03,
|
||||
FORMAT_UNIT = 0x04,
|
||||
READ_BLK_LIMITS = 0x05,
|
||||
REASSIGN = 0x07,
|
||||
READ_6 = 0x08,
|
||||
WRITE_6 = 0x0A,
|
||||
SEEK_6 = 0x0B,
|
||||
@@ -122,17 +123,32 @@ enum ScsiCommand : uint8_t {
|
||||
READ_CAPACITY_10 = 0x25,
|
||||
READ_10 = 0x28,
|
||||
WRITE_10 = 0x2A,
|
||||
SEEK_10 = 0x2B,
|
||||
VERIFY_WRITE_10 = 0x2E,
|
||||
VERIFY_10 = 0x2F,
|
||||
READ_LONG_10 = 0x35,
|
||||
WRITE_BUFFER = 0x3B,
|
||||
READ_BUFFER = 0x3C,
|
||||
GET_CONFIG = 0x46,
|
||||
GET_EVENT_STATUS_NOTIFY = 0x4A,
|
||||
READ_DISC_INFO = 0x51,
|
||||
MODE_SELECT_10 = 0x55,
|
||||
MODE_SENSE_10 = 0x5A,
|
||||
READ_12 = 0xA8,
|
||||
WRITE_12 = 0xAA,
|
||||
READ_DVD_STRUCTURE = 0xAD,
|
||||
SET_SPEED = 0xBB,
|
||||
|
||||
// CD-ROM specific commands
|
||||
READ_TOC = 0x43,
|
||||
SET_CD_SPEED = 0xBB,
|
||||
READ_CD = 0xBE,
|
||||
|
||||
// vendor specific commands
|
||||
VENDOR_09 = 0x09,
|
||||
EJECT = 0xC0,
|
||||
READ_CDDA = 0xD8, //TOSHIBA
|
||||
READ_CDDA_MSF = 0xD9, //TOSHIBA
|
||||
};
|
||||
|
||||
enum ScsiSense : int {
|
||||
@@ -186,7 +202,7 @@ public:
|
||||
this->scsi_id = my_id;
|
||||
this->lun = 0,
|
||||
this->cur_phase = ScsiPhase::BUS_FREE;
|
||||
};
|
||||
}
|
||||
~ScsiDevice() = default;
|
||||
|
||||
virtual void notify(ScsiNotification notif_type, int param);
|
||||
@@ -195,7 +211,7 @@ public:
|
||||
virtual void switch_phase(const int new_phase);
|
||||
virtual bool allow_phase_change();
|
||||
|
||||
virtual bool has_data() { return this->data_size != 0; };
|
||||
virtual bool has_data() { return this->data_size != 0; }
|
||||
virtual int xfer_data();
|
||||
virtual int send_data(uint8_t* dst_ptr, int count);
|
||||
virtual int rcv_data(const uint8_t* src_ptr, const int count);
|
||||
@@ -230,6 +246,7 @@ protected:
|
||||
int ascq;
|
||||
int sksv;
|
||||
int field;
|
||||
bool valid;
|
||||
|
||||
bool last_selection_has_atention = false;
|
||||
uint8_t last_selection_message = 0;
|
||||
@@ -279,7 +296,7 @@ public:
|
||||
uint16_t test_ctrl_lines(uint16_t mask);
|
||||
|
||||
// reading/writing data lines
|
||||
uint8_t get_data_lines() { return this->data_lines; };
|
||||
uint8_t get_data_lines() { return this->data_lines; }
|
||||
|
||||
// high-level control/status
|
||||
int switch_phase(int id, int new_phase);
|
||||
|
||||
@@ -377,11 +377,11 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
|
||||
}
|
||||
|
||||
static const DeviceDescription ScsiCurio_Descriptor = {
|
||||
ScsiBus::create_ScsiCurio, {}, {}
|
||||
ScsiBus::create_ScsiCurio, {}, {}, HWCompType::SCSI_BUS
|
||||
};
|
||||
|
||||
static const DeviceDescription ScsiMesh_Descriptor = {
|
||||
ScsiBus::create_ScsiMesh, {}, {}
|
||||
ScsiBus::create_ScsiMesh, {}, {}, HWCompType::SCSI_BUS
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ScsiCurio, ScsiCurio_Descriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -95,8 +95,10 @@ void ScsiBusController::sequencer() {
|
||||
if (this->fifo_pos) {
|
||||
this->bus_obj->target_xfer_data();
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ATN);
|
||||
if (this->to_xfer <= 0)
|
||||
if (this->to_xfer <= 0) {
|
||||
this->bus_obj->target_next_step();
|
||||
this->step_completed();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
@@ -147,9 +149,12 @@ void ScsiBusController::sequencer() {
|
||||
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
|
||||
this->rcv_data();
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_MESSAGE)
|
||||
if (this->cur_state == SeqState::RCV_STATUS) {
|
||||
this->bus_obj->target_next_step();
|
||||
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_REQ);
|
||||
} else if (this->cur_state == SeqState::RCV_MESSAGE)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
this->bus_obj->target_next_step();
|
||||
this->step_completed();
|
||||
this->cur_state = SeqState::IDLE;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Scsi_Bus_Controller {
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** Sequencer error codes. */
|
||||
enum : int {
|
||||
@@ -75,12 +75,12 @@ public:
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiNotification notif_type, int param) override;
|
||||
bool prepare_data() override { return false; };
|
||||
bool get_more_data() override { return false; };
|
||||
bool has_data() override { return false; };
|
||||
bool prepare_data() override { return false; }
|
||||
bool get_more_data() override { return false; }
|
||||
bool has_data() override { return false; }
|
||||
bool rcv_data();
|
||||
int send_data(uint8_t* dst_ptr, int count) override;
|
||||
void process_command() override {};
|
||||
void process_command() override {}
|
||||
|
||||
// DmaDevice methods
|
||||
int xfer_from(uint8_t *buf, int len) override;
|
||||
|
||||
@@ -45,6 +45,8 @@ void ScsiCdrom::process_command()
|
||||
{
|
||||
uint32_t lba;
|
||||
|
||||
uint32_t cdda_start, cdda_end, cdda_len;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
|
||||
@@ -98,6 +100,19 @@ void ScsiCdrom::process_command()
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::READ_CDDA:
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
cdda_len = READ_DWORD_BE_U(&cmd[6]);
|
||||
this->read(lba, cdda_len, 12);
|
||||
break;
|
||||
case ScsiCommand::READ_CDDA_MSF:
|
||||
cdda_start = (cmd[3] * 60 * 75) + (cmd[4] * 75) + cmd[5];
|
||||
cdda_end = (cmd[7] * 60 * 75) + (cmd[8] * 75) + cmd[9];
|
||||
|
||||
cdda_len = (cdda_end > cdda_start) ? (cdda_end - cdda_start) : 0;
|
||||
|
||||
this->read(cdda_start, cdda_len, 12);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), cmd[0]);
|
||||
this->illegal_command(cmd);
|
||||
|
||||
@@ -86,7 +86,7 @@ void ScsiDevice::next_step()
|
||||
!this->allow_phase_change())
|
||||
return;
|
||||
|
||||
// check for puggable sequences and follow them if applicable
|
||||
// check for pluggable sequences and follow them if applicable
|
||||
if (this->seq_steps && *this->seq_steps >= 0) {
|
||||
if (this->cur_phase == *this->seq_steps) {
|
||||
this->seq_steps++;
|
||||
|
||||
@@ -75,6 +75,9 @@ void ScsiHardDisk::process_command() {
|
||||
case ScsiCommand::FORMAT_UNIT:
|
||||
this->format();
|
||||
break;
|
||||
case ScsiCommand::REASSIGN:
|
||||
this->reassign();
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->read(lba, cmd[4], 6);
|
||||
@@ -350,7 +353,7 @@ void ScsiHardDisk::mode_sense_6() {
|
||||
// default values taken from Empire 540/1080S manual
|
||||
WRITE_WORD_BE_U(&p_buf[ 2], 6); // tracks per defect zone
|
||||
WRITE_WORD_BE_U(&p_buf[ 4], 1); // alternate sectors per zone
|
||||
WRITE_WORD_BE_U(&p_buf[10], 92); // sectors per track in the outermost zone
|
||||
WRITE_WORD_BE_U(&p_buf[10], 64); // sectors per track in the outermost zone
|
||||
WRITE_WORD_BE_U(&p_buf[12], 512); // bytes per sector
|
||||
WRITE_WORD_BE_U(&p_buf[14], 1); // interleave factor
|
||||
WRITE_WORD_BE_U(&p_buf[16], 19); // track skew factor
|
||||
@@ -360,6 +363,18 @@ void ScsiHardDisk::mode_sense_6() {
|
||||
got_page = true;
|
||||
}
|
||||
|
||||
if (page_code == 4 || page_code == 0x3f) { // Rigid Disk Drive Geometry Page
|
||||
page_size = 24;
|
||||
p_buf[0] = 4; // page code
|
||||
p_buf[1] = page_size - 2; // page length
|
||||
std::memset(&p_buf[2], 0, 22);
|
||||
int num_cylinders = this->total_blocks / 64 / 4;
|
||||
p_buf[2] = (num_cylinders >> 16) & 0xFF;
|
||||
WRITE_WORD_BE_U(&p_buf[3], num_cylinders & 0xFFFFU); // number of cylinders
|
||||
p_buf[5] = 4; // number of heads
|
||||
got_page = true;
|
||||
}
|
||||
|
||||
if (page_code == 0x30 || page_code == 0x3f) { // Copyright page for Apple certified drives
|
||||
if (sub_page_code != 0x00 && sub_page_code != 0xff)
|
||||
goto bad_sub_page;
|
||||
@@ -445,6 +460,18 @@ void ScsiHardDisk::format() {
|
||||
});
|
||||
}
|
||||
|
||||
void ScsiHardDisk::reassign() {
|
||||
LOG_F(WARNING, "%s: attempt to reassign blocks on the disk!", this->name.c_str());
|
||||
|
||||
this->status = ScsiStatus::GOOD;
|
||||
this->sense = ScsiSense::NO_SENSE;
|
||||
this->asc = ScsiError::NO_ERROR;
|
||||
this->valid = false;
|
||||
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
NS_PER_SEC, [this]() { this->switch_phase(ScsiPhase::STATUS); });
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
void insert_image(std::string filename);
|
||||
void process_command();
|
||||
bool prepare_data();
|
||||
bool get_more_data() { return false; };
|
||||
bool get_more_data() { return false; }
|
||||
|
||||
protected:
|
||||
int test_unit_ready();
|
||||
@@ -49,6 +49,7 @@ protected:
|
||||
|
||||
void mode_sense_6();
|
||||
void format();
|
||||
void reassign();
|
||||
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
|
||||
void read_capacity_10();
|
||||
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
|
||||
+101
-67
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
@@ -39,7 +40,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
ViaCuda::ViaCuda() {
|
||||
ViaCuda::ViaCuda() : I2CBus() {
|
||||
this->name = "ViaCuda";
|
||||
|
||||
supports_types(HWCompType::ADB_HOST | HWCompType::I2C_HOST);
|
||||
@@ -58,7 +59,6 @@ ViaCuda::ViaCuda() {
|
||||
// (not prescribed in the 6522 datasheet)
|
||||
this->via_t1ll = 0xFF;
|
||||
this->via_t1lh = 0xFF;
|
||||
this->via_t2cl = 0xFF;
|
||||
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
@@ -204,12 +204,9 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
LOG_F(9, "VIA_DIRA = 0x%X", value);
|
||||
break;
|
||||
case VIA_T1CL:
|
||||
this->via_t1cl = value;
|
||||
this->via_t1ll = value; // writes to T1CL are redirected to T1LL
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
if (this->via_acr & 0xC0) {
|
||||
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_acr);
|
||||
}
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
@@ -218,33 +215,25 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
// load initial value into counter 1
|
||||
this->t1_counter = (value << 8) | this->via_t1cl;
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t1_timer_id = 0;
|
||||
this->assert_t1_int();
|
||||
}
|
||||
);
|
||||
// load the high-order latch from the current T1CH value
|
||||
this->via_t1lh = value;
|
||||
// load the T1 counter from the corresponding latches
|
||||
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
|
||||
this->activate_t1();
|
||||
break;
|
||||
case VIA_T1LL:
|
||||
this->via_t1ll = value;
|
||||
break;
|
||||
case VIA_T1LH:
|
||||
this->via_t1lh = value;
|
||||
// writes to T1LH clear T1 interrupt in the Apple VIA cell
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
break;
|
||||
case VIA_T2CL:
|
||||
this->via_t2cl = value;
|
||||
this->via_t2ll = value; // writes to T2CL are redirected to T2LL
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
if (this->via_acr & 0x20) {
|
||||
ABORT_F("VIA T2 pulse count mode not supported!");
|
||||
}
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
@@ -254,7 +243,7 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_t2cl;
|
||||
this->t2_counter = (value << 8) | this->via_t2ll;
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
@@ -273,7 +262,7 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
update_irq();
|
||||
break;
|
||||
case VIA_ACR:
|
||||
this->via_acr = value;
|
||||
this->via_acr = value & VIA_ACR_IMPL_BITS;
|
||||
LOG_F(9, "VIA_ACR = 0x%X", value);
|
||||
break;
|
||||
case VIA_PCR:
|
||||
@@ -282,7 +271,8 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
break;
|
||||
case VIA_IFR:
|
||||
// for each "1" in value clear the corresponding flags
|
||||
this->_via_ifr &= ~value;
|
||||
// bit 7 is ignored
|
||||
this->_via_ifr &= ~(value & 0x7F);
|
||||
update_irq();
|
||||
break;
|
||||
case VIA_IER:
|
||||
@@ -305,6 +295,24 @@ uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t& last
|
||||
return last_val - diff;
|
||||
}
|
||||
|
||||
void ViaCuda::activate_t1() {
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
// reload the T1 counter from the corresponding latches
|
||||
this->t1_counter = (this->via_t1lh << 8) | this->via_t1ll;
|
||||
this->t1_timer_id = 0;
|
||||
this->assert_t1_int();
|
||||
if (this->via_acr & 0x40)
|
||||
this->activate_t1();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ViaCuda::print_enabled_ints() {
|
||||
const char* via_int_src[] = {"CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1"};
|
||||
|
||||
@@ -314,15 +322,15 @@ void ViaCuda::print_enabled_ints() {
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::update_irq()
|
||||
{
|
||||
void ViaCuda::update_irq() {
|
||||
uint8_t active_ints = this->_via_ifr & this->_via_ier & 0x7F;
|
||||
if (active_ints != this->old_ifr) {
|
||||
uint8_t new_irq = !!active_ints;
|
||||
this->_via_ifr = (active_ints) | (new_irq << 7);
|
||||
this->old_ifr = active_ints;
|
||||
LOG_F(6, "VIA: assert IRQ, IFR=0x%02X", this->_via_ifr);
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
uint8_t irq_state = !!active_ints;
|
||||
// let CPU know when irq_state is "1" or it changes from "1" to "0"
|
||||
if (irq_state || (irq_state != (this->_via_ifr >> 7))) {
|
||||
this->_via_ifr = (irq_state << 7) | (this->_via_ifr & 0x7F);
|
||||
LOG_F(6, "%s: signal IRQ line change to 0x%X, IFR=0x%02X",
|
||||
this->name.c_str(), irq_state, this->_via_ifr);
|
||||
this->int_ctrl->ack_int(this->irq_id, irq_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +369,7 @@ void ViaCuda::assert_ctrl_line(ViaLine line)
|
||||
this->_via_ifr |= VIA_IF_CB1;
|
||||
break;
|
||||
case ViaLine::CB2:
|
||||
this->_via_ifr |= VIA_IF_CB1;
|
||||
this->_via_ifr |= VIA_IF_CB2;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("Assertion of unknown VIA line requested!");
|
||||
@@ -494,6 +502,15 @@ void ViaCuda::error_response(uint32_t error) {
|
||||
this->is_open_ended = false;
|
||||
}
|
||||
|
||||
void ViaCuda::one_byte_header(uint32_t pkt_type) {
|
||||
this->out_buf[0] = pkt_type;
|
||||
this->out_count = 1;
|
||||
this->out_pos = 0;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
this->next_out_handler = &ViaCuda::null_out_handler;
|
||||
this->is_open_ended = false;
|
||||
}
|
||||
|
||||
void ViaCuda::process_packet() {
|
||||
if (this->in_count < 2) {
|
||||
LOG_F(ERROR, "Cuda: invalid packet (too few data)!");
|
||||
@@ -521,20 +538,41 @@ void ViaCuda::process_packet() {
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::append_data(uint8_t* src, int len) {
|
||||
if (len > 0) {
|
||||
std::memcpy(&this->out_buf[this->out_count], src, len);
|
||||
this->out_count += len;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void ViaCuda::append_data(T data) {
|
||||
switch(sizeof(T)) {
|
||||
case 1: this->out_buf[this->out_count] = data;
|
||||
case 2: WRITE_WORD_BE_U( &this->out_buf[this->out_count], data);
|
||||
case 4: WRITE_DWORD_BE_U(&this->out_buf[this->out_count], data);
|
||||
}
|
||||
this->out_count += sizeof(T);
|
||||
}
|
||||
template void ViaCuda::append_data(uint8_t data);
|
||||
template void ViaCuda::append_data(uint16_t data);
|
||||
template void ViaCuda::append_data(uint32_t data);
|
||||
|
||||
void ViaCuda::process_adb_command() {
|
||||
uint8_t adb_stat, output_size;
|
||||
|
||||
adb_stat = this->adb_bus_obj->process_command(&this->in_buf[1],
|
||||
this->in_count - 1);
|
||||
response_header(CUDA_PKT_ADB, adb_stat);
|
||||
output_size = this->adb_bus_obj->get_output_count();
|
||||
if (output_size) {
|
||||
std::memcpy(&this->out_buf[3], this->adb_bus_obj->get_output_buf(), output_size);
|
||||
this->out_count += output_size;
|
||||
}
|
||||
this->append_data(this->adb_bus_obj->get_output_buf(), this->adb_bus_obj->get_output_count());
|
||||
}
|
||||
|
||||
void ViaCuda::autopoll_handler() {
|
||||
if (this->do_post_keyboard_state_events && !(!this->old_tip || !this->treq)) {
|
||||
EventManager::get_instance()->post_keyboard_state_events();
|
||||
this->do_post_keyboard_state_events = false;
|
||||
}
|
||||
|
||||
uint8_t poll_command = this->autopoll_enabled ? this->adb_bus_obj->poll() : 0;
|
||||
|
||||
if (poll_command) {
|
||||
@@ -545,11 +583,7 @@ void ViaCuda::autopoll_handler() {
|
||||
// prepare autopoll packet
|
||||
response_header(CUDA_PKT_ADB, ADB_STAT_OK | ADB_STAT_AUTOPOLL);
|
||||
this->out_buf[2] = poll_command; // put the proper ADB command
|
||||
uint8_t output_size = this->adb_bus_obj->get_output_count();
|
||||
if (output_size) {
|
||||
std::memcpy(&this->out_buf[3], this->adb_bus_obj->get_output_buf(), output_size);
|
||||
this->out_count += output_size;
|
||||
}
|
||||
this->append_data(this->adb_bus_obj->get_output_buf(), this->adb_bus_obj->get_output_count());
|
||||
|
||||
// assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ;
|
||||
@@ -571,12 +605,10 @@ void ViaCuda::autopoll_handler() {
|
||||
this->out_buf[2] = CUDA_GET_REAL_TIME;
|
||||
if (send_time || this->one_sec_mode == 1) {
|
||||
uint32_t real_time = this_time + this->time_offset;
|
||||
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
|
||||
this->out_count = 7;
|
||||
this->append_data(real_time);
|
||||
}
|
||||
} else if (this->one_sec_mode == 3) {
|
||||
response_header(CUDA_PKT_TICK, 0);
|
||||
this->out_count = 1;
|
||||
one_byte_header(CUDA_PKT_TICK);
|
||||
}
|
||||
this->last_time = this_time;
|
||||
|
||||
@@ -600,9 +632,11 @@ void ViaCuda::pseudo_command() {
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: autopoll started, rate: %d ms", this->poll_rate);
|
||||
this->autopoll_enabled = true;
|
||||
this->do_post_keyboard_state_events = true;
|
||||
} else {
|
||||
LOG_F(INFO, "Cuda: autopoll stopped");
|
||||
this->autopoll_enabled = false;
|
||||
this->do_post_keyboard_state_events = false;
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
@@ -616,11 +650,10 @@ void ViaCuda::pseudo_command() {
|
||||
this->next_out_handler = &ViaCuda::pram_out_handler;
|
||||
} else if (addr >= CUDA_ROM_START) {
|
||||
// HACK: Cuda ROM dump requsted so let's partially fake it
|
||||
this->out_buf[3] = 0; // empty copyright string
|
||||
WRITE_WORD_BE_A(&this->out_buf[4], 0x0019U);
|
||||
WRITE_WORD_BE_A(&this->out_buf[6], CUDA_FW_VERSION_MAJOR);
|
||||
WRITE_WORD_BE_A(&this->out_buf[8], CUDA_FW_VERSION_MINOR);
|
||||
this->out_count += 7;
|
||||
this->append_data(uint8_t(0)); // empty copyright string
|
||||
this->append_data(uint16_t(0x0019U));
|
||||
this->append_data(uint16_t(CUDA_FW_VERSION_MAJOR));
|
||||
this->append_data(uint16_t(CUDA_FW_VERSION_MINOR));
|
||||
}
|
||||
this->is_open_ended = true;
|
||||
break;
|
||||
@@ -628,8 +661,7 @@ void ViaCuda::pseudo_command() {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
uint32_t this_time = this->calc_real_time();
|
||||
uint32_t real_time = this_time + this->time_offset;
|
||||
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
|
||||
this->out_count = 7;
|
||||
this->append_data(real_time);
|
||||
break;
|
||||
}
|
||||
case CUDA_WRITE_MCU_MEM:
|
||||
@@ -659,7 +691,7 @@ void ViaCuda::pseudo_command() {
|
||||
case CUDA_SET_REAL_TIME: {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
uint32_t real_time = this->calc_real_time();
|
||||
uint32_t new_time = READ_DWORD_BE_U(&in_buf[2]);
|
||||
uint32_t new_time = READ_DWORD_BE_U(&this->in_buf[2]);
|
||||
this->time_offset = new_time - real_time;
|
||||
break;
|
||||
}
|
||||
@@ -692,18 +724,15 @@ void ViaCuda::pseudo_command() {
|
||||
break;
|
||||
case CUDA_GET_AUTOPOLL_RATE:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[3] = this->poll_rate;
|
||||
this->out_count++;
|
||||
this->append_data(this->poll_rate);
|
||||
break;
|
||||
case CUDA_SET_DEVICE_LIST:
|
||||
case CUDA_SET_DEVICE_BITMAP:
|
||||
this->device_mask = READ_WORD_BE_U(&this->in_buf[2]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->device_mask = ((uint16_t)in_buf[2]) >> 8;
|
||||
this->device_mask += ((uint16_t)in_buf[3]);
|
||||
break;
|
||||
case CUDA_GET_DEVICE_LIST:
|
||||
case CUDA_GET_DEVICE_BITMAP:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = (uint8_t)((this->device_mask >> 8) & 0xFF);
|
||||
this->out_buf[3] = (uint8_t)((this->device_mask) & 0xFF);
|
||||
this->append_data(this->device_mask);
|
||||
break;
|
||||
case CUDA_ONE_SECOND_MODE:
|
||||
LOG_F(INFO, "Cuda: One Second Interrupt Mode: %d", this->in_buf[2]);
|
||||
@@ -711,12 +740,17 @@ void ViaCuda::pseudo_command() {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_SET_POWER_MESSAGES:
|
||||
LOG_F(WARNING, "Cuda: unsupported pseudo command 0x%X SET_POWER_MESSAGES", cmd);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
|
||||
break;
|
||||
case CUDA_TIMER_TICKLE:
|
||||
LOG_F(WARNING, "Cuda: unsupported pseudo command 0x%X TIMER_TICKLE - Byte Sent: 0x%02x", cmd, this->in_buf[2]);
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_COMB_FMT_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
if (this->in_count >= 5) {
|
||||
@@ -855,7 +889,7 @@ static const vector<string> Cuda_Subdevices = {
|
||||
};
|
||||
|
||||
static const DeviceDescription ViaCuda_Descriptor = {
|
||||
ViaCuda::create, Cuda_Subdevices, {}
|
||||
ViaCuda::create, Cuda_Subdevices, {}, HWCompType::ADB_HOST | HWCompType::I2C_HOST
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ViaCuda, ViaCuda_Descriptor);
|
||||
+29
-19
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,8 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Versatile interface adapter (VIA) is an old I/O controller that can be found
|
||||
in nearly every Macintosh computer. In the 68k era, VIA was used to control
|
||||
various peripheral devices. In a Power Macintosh, its function is limited
|
||||
to the I/O interface with the Cuda MCU. I therefore decided to put VIA
|
||||
emulation code here.
|
||||
to the I/O interface with the Cuda MCU and some basic timer functionality.
|
||||
|
||||
Cuda MCU is a multipurpose IC built around a custom version of the Motorola
|
||||
MC68HC05 microcontroller. It provides several functions including:
|
||||
@@ -43,7 +42,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
@@ -93,6 +91,9 @@ enum class ViaLine {
|
||||
CB2
|
||||
};
|
||||
|
||||
// for masking unimplemented bits in the Apple VIA cell.
|
||||
constexpr uint8_t VIA_ACR_IMPL_BITS = 0x5C;
|
||||
|
||||
/** Cuda communication signals (active low -> 0 - true, 1 - false). */
|
||||
enum {
|
||||
CUDA_TIP = 0x20, // transaction in progress
|
||||
@@ -119,17 +120,23 @@ enum {
|
||||
CUDA_WRITE_MCU_MEM = 0x08, // write internal Cuda memory
|
||||
CUDA_SET_REAL_TIME = 0x09, // set real time
|
||||
CUDA_POWER_DOWN = 0x0A, // power down system
|
||||
CUDA_SET_POWER_UPTIME = 0x0B, // set power up time
|
||||
CUDA_WRITE_PRAM = 0x0C, // write parameter RAM
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, // mono stable reset
|
||||
CUDA_SEND_DFAC = 0x0E, // send dfac
|
||||
CUDA_BATTERY_SWAP_SENSE = 0x10, // battery swap sense
|
||||
CUDA_RESTART_SYSTEM = 0x11, // restart system
|
||||
CUDA_SET_IPL_LEVEL = 0x12, // set IPL level
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, // set file server flag
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, // set auto-polling rate
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, // get auto-polling rate
|
||||
CUDA_SET_DEVICE_LIST = 0x19, // set device list
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, // get device list
|
||||
CUDA_SET_DEVICE_BITMAP = 0x19, // set device bitmap
|
||||
CUDA_GET_DEVICE_BITMAP = 0x1A, // get device bitmap
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, // one second interrupt mode
|
||||
CUDA_SET_POWER_MESSAGES = 0x21, // set power message flag
|
||||
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C device
|
||||
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C
|
||||
CUDE_TOGGLE_WAKEUP = 0x23, // toggle wake-up
|
||||
CUDA_TIMER_TICKLE = 0x24, // set timer tickle
|
||||
CUDA_COMB_FMT_I2C = 0x25, // combined format I2C transaction
|
||||
CUDA_OUT_PB0 = 0x26, // output one bit to Cuda's PB0 line
|
||||
};
|
||||
@@ -156,7 +163,7 @@ constexpr auto CUDA_ROM_START = 0xF00; // starting address of ROM contain
|
||||
constexpr auto CUDA_FW_VERSION_MAJOR = 0x0002;
|
||||
constexpr auto CUDA_FW_VERSION_MINOR = 0x0029;
|
||||
|
||||
class ViaCuda : public HWComponent, public I2CBus {
|
||||
class ViaCuda : public I2CBus {
|
||||
public:
|
||||
ViaCuda();
|
||||
~ViaCuda();
|
||||
@@ -183,10 +190,6 @@ private:
|
||||
uint8_t via_porta = 0;
|
||||
uint8_t via_ddrb = 0;
|
||||
uint8_t via_ddra = 0;
|
||||
uint8_t via_t1cl = 0xFF;
|
||||
uint8_t via_t1ll = 0xFF;
|
||||
uint8_t via_t1lh = 0xFF;
|
||||
uint8_t via_t2cl = 0xFF;
|
||||
uint8_t via_sr;
|
||||
uint8_t via_acr = 0;
|
||||
uint8_t via_pcr = 0;
|
||||
@@ -198,21 +201,23 @@ private:
|
||||
uint8_t last_orb = 0; // last value written to the ORB register.
|
||||
|
||||
// timer 1 state
|
||||
uint16_t t1_counter;
|
||||
uint32_t t1_timer_id = 0;
|
||||
uint8_t via_t1ll; // low-order latch
|
||||
uint8_t via_t1lh; // high-order latch
|
||||
uint16_t t1_counter; // internal counter
|
||||
uint32_t t1_timer_id = 0;
|
||||
uint64_t t1_start_time = 0;
|
||||
|
||||
// timer 2 state
|
||||
uint16_t t2_counter;
|
||||
uint8_t via_t2ll; // low-order latch (write-only)
|
||||
uint16_t t2_counter; // internal counter
|
||||
uint32_t t2_timer_id = 0;
|
||||
uint64_t t2_start_time = 0;
|
||||
|
||||
// VIA interrupt related stuff
|
||||
InterruptCtrl* int_ctrl;
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint64_t irq_id;
|
||||
uint8_t _via_ifr;
|
||||
uint8_t _via_ier;
|
||||
uint8_t old_ifr = 0;
|
||||
uint8_t _via_ifr = 0;
|
||||
uint8_t _via_ier = 0;
|
||||
|
||||
/* Cuda state. */
|
||||
uint8_t old_tip;
|
||||
@@ -243,6 +248,7 @@ private:
|
||||
|
||||
AdbBus* adb_bus_obj = nullptr;
|
||||
bool autopoll_enabled = false;
|
||||
bool do_post_keyboard_state_events = false;
|
||||
|
||||
// VIA methods
|
||||
void print_enabled_ints(); // print enabled VIA interrupts and their sources
|
||||
@@ -253,12 +259,16 @@ private:
|
||||
void assert_t2_int();
|
||||
void schedule_sr_int(uint64_t timeout_ns);
|
||||
uint16_t calc_counter_val(const uint16_t last_val, const uint64_t& last_time);
|
||||
void activate_t1();
|
||||
|
||||
// CUDA methods
|
||||
void cuda_init();
|
||||
void write(uint8_t new_state);
|
||||
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
|
||||
void error_response(uint32_t error);
|
||||
void one_byte_header(uint32_t pkt_type);
|
||||
inline void append_data(uint8_t* src, int len);
|
||||
template <class T> inline void append_data(T data);
|
||||
void process_packet();
|
||||
void process_adb_command();
|
||||
void pseudo_command();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -40,6 +40,8 @@ struct DeviceDescription {
|
||||
CreateFunc m_create_func;
|
||||
std::vector<std::string> subdev_list;
|
||||
PropMap properties;
|
||||
uint64_t supports_types;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
class DeviceRegistry
|
||||
|
||||
+153
-16
@@ -35,6 +35,7 @@ BigMac::BigMac(uint8_t id) {
|
||||
|
||||
void BigMac::chip_reset() {
|
||||
this->event_mask = 0xFFFFU; // disable HW events causing on-chip interrupts
|
||||
this->rng_seed = (uint16_t)rand();
|
||||
this->stat = 0;
|
||||
|
||||
this->phy_reset();
|
||||
@@ -46,13 +47,25 @@ uint16_t BigMac::read(uint16_t reg_offset) {
|
||||
switch (reg_offset) {
|
||||
case BigMacReg::XIFC:
|
||||
return this->tx_if_ctrl;
|
||||
case BigMacReg::XCVR_IF:
|
||||
return this->xcvr_if_ctrl;
|
||||
case BigMacReg::CHIP_ID:
|
||||
return this->chip_id;
|
||||
case BigMacReg::TX_FIFO_TH:
|
||||
return this->tx_fifo_tresh;
|
||||
case BigMacReg::TX_FIFO_CSR:
|
||||
return (this->tx_fifo_enable & 1) | ((((this->tx_fifo_size >> 7) - 1) & 0xFF) << 1);
|
||||
case BigMacReg::RX_FIFO_CSR:
|
||||
return (this->tx_fifo_enable & 1) | ((((this->tx_fifo_size >> 7) - 1) & 0xFF) << 1);
|
||||
case BigMacReg::TX_PNTR:
|
||||
return this->tx_ptr;
|
||||
case BigMacReg::RX_PNTR:
|
||||
return this->rx_ptr;
|
||||
case BigMacReg::MIF_CSR:
|
||||
return (this->mif_csr_old & ~Mif_Data_In) | (this->mii_in_bit << 3);
|
||||
case BigMacReg::GLOB_STAT: {
|
||||
uint16_t old_stat = this->stat;
|
||||
this->stat = 0; // clear-on-read
|
||||
this->stat = 0; // clear-on-read
|
||||
return old_stat;
|
||||
}
|
||||
case BigMacReg::EVENT_MASK:
|
||||
@@ -63,22 +76,83 @@ uint16_t BigMac::read(uint16_t reg_offset) {
|
||||
return this->tx_reset;
|
||||
case BigMacReg::TX_CONFIG:
|
||||
return this->tx_config;
|
||||
case BigMacReg::TX_MAX:
|
||||
return this->tx_max;
|
||||
case BigMacReg::TX_MIN:
|
||||
return this->tx_min;
|
||||
case BigMacReg::PEAK_ATT: {
|
||||
uint8_t old_val = this->peak_attempts;
|
||||
this->peak_attempts = 0; // clear-on-read
|
||||
return old_val;
|
||||
}
|
||||
uint8_t old_val = this->peak_attempts;
|
||||
this->peak_attempts = 0; // clear-on-read
|
||||
return old_val;
|
||||
}
|
||||
case BigMacReg::NC_CNT:
|
||||
return this->norm_coll_cnt;
|
||||
case BigMacReg::NT_CNT:
|
||||
return this->net_coll_cnt;
|
||||
case BigMacReg::EX_CNT:
|
||||
return this->excs_coll_cnt;
|
||||
case BigMacReg::LT_CNT:
|
||||
return this->late_coll_cnt;
|
||||
case BigMacReg::RNG_SEED:
|
||||
return this->rng_seed;
|
||||
case BigMacReg::RX_FRM_CNT:
|
||||
return this->rcv_frame_cnt;
|
||||
case BigMacReg::RX_LE_CNT:
|
||||
return this->len_err_cnt;
|
||||
case BigMacReg::RX_AE_CNT:
|
||||
return this->align_err_cnt;
|
||||
case BigMacReg::RX_FE_CNT:
|
||||
return this->fcs_err_cnt;
|
||||
case BigMacReg::RX_CVE_CNT:
|
||||
return this->cv_err_cnt;
|
||||
case BigMacReg::RX_CONFIG:
|
||||
return this->rx_config;
|
||||
case BigMacReg::RX_MAX:
|
||||
return this->rx_max;
|
||||
case BigMacReg::RX_MIN:
|
||||
return this->rx_min;
|
||||
case BigMacReg::MEM_ADD:
|
||||
return this->mem_add;
|
||||
case BigMacReg::MEM_DATA_HI:
|
||||
return this->mem_data_hi;
|
||||
case BigMacReg::MEM_DATA_LO:
|
||||
return this->mem_data_lo;
|
||||
case BigMacReg::IPG_1:
|
||||
return this->ipg1;
|
||||
case BigMacReg::IPG_2:
|
||||
return this->ipg2;
|
||||
case BigMacReg::A_LIMIT:
|
||||
return this->attempt_limit;
|
||||
case BigMacReg::SLOT:
|
||||
return this->slot_time;
|
||||
case BigMacReg::PA_LEN:
|
||||
return this->preamble_len;
|
||||
case BigMacReg::PA_PAT:
|
||||
return this->preamble_pat;
|
||||
case BigMacReg::TX_SFD:
|
||||
return this->tx_sfd;
|
||||
case BigMacReg::JAM_SIZE:
|
||||
return this->jam_size;
|
||||
case BigMacReg::DEFER_TMR:
|
||||
return this->defer_timer;
|
||||
case BigMacReg::MAC_ADDR_0:
|
||||
case BigMacReg::MAC_ADDR_1:
|
||||
case BigMacReg::MAC_ADDR_2:
|
||||
return this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)];
|
||||
case BigMacReg::HASH_TAB_0:
|
||||
case BigMacReg::HASH_TAB_1:
|
||||
case BigMacReg::HASH_TAB_2:
|
||||
case BigMacReg::HASH_TAB_3:
|
||||
return this->hash_table[(reg_offset >> 4) & 3];
|
||||
case BigMacReg::AFR_0:
|
||||
case BigMacReg::AFR_1:
|
||||
case BigMacReg::AFR_2:
|
||||
return this->addr_filters[((reg_offset >> 4) & 0xF) - 4];
|
||||
case BigMacReg::AFC_R:
|
||||
return this->addr_filt_mask;
|
||||
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unimplemented register at 0x%X", this->name.c_str(),
|
||||
reg_offset);
|
||||
LOG_F(WARNING, "%s: unimplemented register at 0x%X", this->name.c_str(), reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -89,16 +163,25 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
|
||||
case BigMacReg::XIFC:
|
||||
this->tx_if_ctrl = value;
|
||||
break;
|
||||
case BigMacReg::XCVR_IF:
|
||||
this->xcvr_if_ctrl = value;
|
||||
break;
|
||||
case BigMacReg::TX_FIFO_CSR:
|
||||
this->tx_fifo_enable = !!(value & 1);
|
||||
this->tx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
|
||||
this->tx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
|
||||
break;
|
||||
case BigMacReg::TX_FIFO_TH:
|
||||
this->tx_fifo_tresh = value;
|
||||
break;
|
||||
case BigMacReg::RX_FIFO_CSR:
|
||||
this->rx_fifo_enable = !!(value & 1);
|
||||
this->rx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
|
||||
this->rx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
|
||||
break;
|
||||
case BigMacReg::TX_PNTR:
|
||||
this->tx_ptr = value;
|
||||
break;
|
||||
case BigMacReg::RX_PNTR:
|
||||
this->rx_ptr = value;
|
||||
break;
|
||||
case BigMacReg::MIF_CSR:
|
||||
if (value & Mif_Data_Out_En) {
|
||||
@@ -111,6 +194,9 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
|
||||
}
|
||||
this->mif_csr_old = value;
|
||||
break;
|
||||
case BigMacReg::MEM_ADD:
|
||||
this->mem_add = value;
|
||||
break;
|
||||
case BigMacReg::EVENT_MASK:
|
||||
this->event_mask = value;
|
||||
break;
|
||||
@@ -127,7 +213,7 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
|
||||
case BigMacReg::TX_SW_RST:
|
||||
if (value == 1) {
|
||||
LOG_F(INFO, "%s: transceiver soft reset asserted", this->name.c_str());
|
||||
this->tx_reset = 0; // acknowledge SW reset
|
||||
this->tx_reset = 0; // acknowledge SW reset
|
||||
}
|
||||
break;
|
||||
case BigMacReg::TX_CONFIG:
|
||||
@@ -156,10 +242,32 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
|
||||
case BigMacReg::RX_CONFIG:
|
||||
this->rx_config = value;
|
||||
break;
|
||||
case BigMacReg::MAC_ADDR_0:
|
||||
case BigMacReg::MAC_ADDR_1:
|
||||
case BigMacReg::MAC_ADDR_2:
|
||||
this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)] = value;
|
||||
case BigMacReg::RX_MAX:
|
||||
this->rx_max = value;
|
||||
break;
|
||||
case BigMacReg::RX_MIN:
|
||||
this->rx_min = value;
|
||||
break;
|
||||
case BigMacReg::SLOT:
|
||||
this->slot_time = value;
|
||||
break;
|
||||
case BigMacReg::PA_LEN:
|
||||
this->preamble_len = value;
|
||||
break;
|
||||
case BigMacReg::PA_PAT:
|
||||
this->preamble_pat = value;
|
||||
break;
|
||||
case BigMacReg::TX_SFD:
|
||||
this->tx_sfd = value;
|
||||
break;
|
||||
case BigMacReg::JAM_SIZE:
|
||||
this->jam_size = value;
|
||||
break;
|
||||
case BigMacReg::PEAK_ATT:
|
||||
this->peak_attempts = value;
|
||||
break;
|
||||
case BigMacReg::DEFER_TMR:
|
||||
this->defer_timer = value;
|
||||
break;
|
||||
case BigMacReg::RX_FRM_CNT:
|
||||
this->rcv_frame_cnt = value;
|
||||
@@ -176,15 +284,44 @@ void BigMac::write(uint16_t reg_offset, uint16_t value) {
|
||||
case BigMacReg::RX_CVE_CNT:
|
||||
this->cv_err_cnt = value;
|
||||
break;
|
||||
case BigMacReg::MAC_ADDR_0:
|
||||
case BigMacReg::MAC_ADDR_1:
|
||||
case BigMacReg::MAC_ADDR_2:
|
||||
this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)] = value;
|
||||
break;
|
||||
case BigMacReg::HASH_TAB_0:
|
||||
case BigMacReg::HASH_TAB_1:
|
||||
case BigMacReg::HASH_TAB_2:
|
||||
case BigMacReg::HASH_TAB_3:
|
||||
this->hash_table[(reg_offset >> 4) & 3] = value;
|
||||
break;
|
||||
case BigMacReg::IPG_1:
|
||||
this->ipg1 = value;
|
||||
break;
|
||||
case BigMacReg::IPG_2:
|
||||
this->ipg2 = value;
|
||||
break;
|
||||
case BigMacReg::A_LIMIT:
|
||||
this->attempt_limit = value;
|
||||
break;
|
||||
case BigMacReg::AFR_0:
|
||||
case BigMacReg::AFR_1:
|
||||
case BigMacReg::AFR_2:
|
||||
this->addr_filters[((reg_offset >> 4) & 0xF) - 4] = value;
|
||||
break;
|
||||
case BigMacReg::AFC_R:
|
||||
this->addr_filt_mask = value;
|
||||
break;
|
||||
case BigMacReg::CHIP_ID:
|
||||
case BigMacReg::TX_SM:
|
||||
case BigMacReg::RX_ST_MCHN:
|
||||
LOG_F(WARNING, "%s: Attempted write to read-only register at 0x%X with 0x%X",
|
||||
this->name.c_str(), reg_offset, value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unimplemented register at 0x%X is written with 0x%X",
|
||||
this->name.c_str(), reg_offset, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,11 +581,11 @@ void BigMac::srom_xmit_bit(const uint8_t bit_val) {
|
||||
}
|
||||
|
||||
static const DeviceDescription BigMac_Heathrow_Descriptor = {
|
||||
BigMac::create_for_heathrow, {}, {}
|
||||
BigMac::create_for_heathrow, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
|
||||
};
|
||||
|
||||
static const DeviceDescription BigMac_Paddington_Descriptor = {
|
||||
BigMac::create_for_paddington, {}, {}
|
||||
BigMac::create_for_paddington, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(BigMacHeathrow, BigMac_Heathrow_Descriptor);
|
||||
|
||||
@@ -183,7 +183,8 @@ private:
|
||||
// BigMac state
|
||||
uint16_t tx_reset = 0; // self-clearing one-bit register
|
||||
uint16_t tx_if_ctrl = 0;
|
||||
uint16_t rng_seed;
|
||||
uint16_t xcvr_if_ctrl = 0;
|
||||
uint16_t rng_seed = 0;
|
||||
uint16_t norm_coll_cnt = 0;
|
||||
uint16_t net_coll_cnt = 0;
|
||||
uint16_t excs_coll_cnt = 0;
|
||||
@@ -201,8 +202,29 @@ private:
|
||||
uint16_t rx_fifo_size = 0;
|
||||
uint16_t hash_table[4] = {};
|
||||
uint16_t mac_addr_flt[3] = {};
|
||||
uint16_t addr_filters[3] = {};
|
||||
uint16_t addr_filt_mask = 0;
|
||||
uint16_t tx_config = 0;
|
||||
uint16_t tx_sfd = 0;
|
||||
uint16_t tx_ptr = 0;
|
||||
uint16_t tx_min = 0;
|
||||
uint16_t tx_max = 0;
|
||||
uint16_t rx_config = 0;
|
||||
uint16_t rx_ptr = 0;
|
||||
uint16_t rx_min = 0;
|
||||
uint16_t rx_max = 0;
|
||||
uint16_t ipg1 = 0;
|
||||
uint16_t ipg2 = 0;
|
||||
uint16_t attempt_limit = 0;
|
||||
uint16_t mem_add = 0;
|
||||
uint16_t mem_data_hi = 0;
|
||||
uint16_t mem_data_lo = 0;
|
||||
uint16_t slot_time = 0;
|
||||
uint16_t preamble_len = 0;
|
||||
uint16_t preamble_pat = 0;
|
||||
uint16_t jam_size = 0;
|
||||
uint16_t defer_timer = 0;
|
||||
|
||||
|
||||
// Interrupt state
|
||||
uint16_t event_mask = 0xFFFFU; // inverted mask: 0 - enabled, 1 - disabled
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,9 +31,19 @@ using namespace MaceEnet;
|
||||
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
switch (reg_offset) {
|
||||
case MaceReg::Rcv_FIFO:
|
||||
return 0; //No FIFO yet
|
||||
case MaceReg::Rcv_Frame_Ctrl:
|
||||
return this->rcv_fc;
|
||||
case MaceReg::Xmit_Frame_Stat:
|
||||
return this->xmt_fs;
|
||||
case MaceReg::Xmit_Retry_Cnt:
|
||||
return this->xmt_retry;
|
||||
case MaceReg::Rcv_Frame_Stat:
|
||||
return this->rcv_fs;
|
||||
case MaceReg::FIFO_Frame_Cnt:
|
||||
return this->fifo_fc;
|
||||
case MaceReg::Interrupt: {
|
||||
uint8_t ret_val = this->int_stat;
|
||||
this->int_stat = 0;
|
||||
@@ -42,12 +52,26 @@ uint8_t MaceController::read(uint8_t reg_offset)
|
||||
}
|
||||
case MaceReg::Interrupt_Mask:
|
||||
return this->int_mask;
|
||||
case MaceReg::Poll:
|
||||
return this->poll_reg;
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
return this->biu_ctrl;
|
||||
case MaceReg::FIFO_Config:
|
||||
return this->fifo_ctrl;
|
||||
case MaceReg::MAC_Config_Ctrl:
|
||||
return this->mac_cc;
|
||||
case MaceReg::PLS_Config_Ctrl:
|
||||
return this->pls_cc;
|
||||
case MaceReg::PHY_Config_Ctrl:
|
||||
return this->phy_cc;
|
||||
case MaceReg::Chip_ID_Lo:
|
||||
return this->chip_id & 0xFFU;
|
||||
case MaceReg::Chip_ID_Hi:
|
||||
return (this->chip_id >> 8) & 0xFFU;
|
||||
case MaceReg::Int_Addr_Config:
|
||||
return this->addr_cfg;
|
||||
case MaceReg::Missed_Pkt_Cnt:
|
||||
return this->missed_pkts;
|
||||
default:
|
||||
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
|
||||
}
|
||||
@@ -64,9 +88,6 @@ void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
case MaceReg::Interrupt_Mask:
|
||||
this->int_mask = value;
|
||||
break;
|
||||
case MaceReg::MAC_Config_Ctrl:
|
||||
this->mac_cfg = value;
|
||||
break;
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
if (value & BIU_SWRST) {
|
||||
LOG_F(INFO, "%s: soft reset asserted", this->name.c_str());
|
||||
@@ -74,6 +95,12 @@ void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
}
|
||||
this->biu_ctrl = value;
|
||||
break;
|
||||
case MaceReg::FIFO_Config:
|
||||
this->fifo_ctrl = value;
|
||||
break;
|
||||
case MaceReg::MAC_Config_Ctrl:
|
||||
this->mac_cfg = value;
|
||||
break;
|
||||
case MaceReg::PLS_Config_Ctrl:
|
||||
if (value != 7)
|
||||
LOG_F(WARNING, "%s: unsupported transceiver interface 0x%X in PLSCC",
|
||||
@@ -113,7 +140,7 @@ void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
}
|
||||
|
||||
static const DeviceDescription Mace_Descriptor = {
|
||||
MaceController::create, {}, {}
|
||||
MaceController::create, {}, {}, HWCompType::MMIO_DEV | HWCompType::ETHER_MAC
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Mace, Mace_Descriptor);
|
||||
+23
-11
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -79,7 +79,7 @@ namespace MaceEnet {
|
||||
IAC_ADDRCHG = 1 << 7
|
||||
};
|
||||
|
||||
}; // namespace MaceEnet
|
||||
} // namespace MaceEnet
|
||||
|
||||
class MaceController : public DmaDevice, public HWComponent {
|
||||
public:
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
this->chip_id = id;
|
||||
this->set_name("MACE");
|
||||
this->supports_types(HWCompType::MMIO_DEV | HWCompType::ETHER_MAC);
|
||||
};
|
||||
}
|
||||
~MaceController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
@@ -99,14 +99,26 @@ public:
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
private:
|
||||
uint16_t chip_id; // per-instance MACE Chip ID
|
||||
uint8_t addr_cfg = 0;
|
||||
uint8_t addr_ptr = 0;
|
||||
uint8_t rcv_fc = 1;
|
||||
uint8_t biu_ctrl = 0;
|
||||
uint8_t mac_cfg = 0;
|
||||
uint64_t phys_addr = 0;
|
||||
uint64_t log_addr = 0;
|
||||
uint16_t chip_id; // per-instance MACE Chip ID
|
||||
uint8_t addr_cfg = 0;
|
||||
uint8_t addr_ptr = 0;
|
||||
uint8_t xmt_fs = 0;
|
||||
uint8_t xmt_retry = 0;
|
||||
uint8_t rcv_fc = 1;
|
||||
uint8_t rcv_fs = 0;
|
||||
uint8_t biu_ctrl = 0;
|
||||
uint8_t fifo_ctrl = 0;
|
||||
|
||||
uint8_t poll_reg = 0;
|
||||
|
||||
uint8_t mac_cfg = 0;
|
||||
uint8_t mac_cc = 0;
|
||||
uint8_t pls_cc = 0;
|
||||
uint8_t phy_cc = 0;
|
||||
uint8_t fifo_fc = 0;
|
||||
uint8_t missed_pkts = 0;
|
||||
uint64_t phys_addr = 0;
|
||||
uint64_t log_addr = 0;
|
||||
|
||||
// interrupt stuff
|
||||
uint8_t int_stat = 0;
|
||||
|
||||
@@ -34,8 +34,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
static FlopImgType identify_image(ImgFile& img_file)
|
||||
{
|
||||
// WOZ images identification strings
|
||||
static uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
static uint8_t WOZ2_SIG[] = {0x57, 0x4F, 0x5A, 0x32, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
static const uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
static const uint8_t WOZ2_SIG[] = {0x57, 0x4F, 0x5A, 0x32, 0xFF, 0x0A, 0x0D, 0x0A};
|
||||
|
||||
uint8_t buf[8] = { 0 };
|
||||
|
||||
@@ -47,20 +47,23 @@ static FlopImgType identify_image(ImgFile& img_file)
|
||||
} else if (!std::memcmp(buf, WOZ2_SIG, sizeof(buf))) {
|
||||
return FlopImgType::WOZ2;
|
||||
} else {
|
||||
for (int offset = 0; offset <=84; offset += 84) {
|
||||
auto check_hfs_mfs = [](ImgFile& img, std::size_t offset) -> bool {
|
||||
/* 2 bytes needed for MFS/HFS signature */
|
||||
unsigned char buf[2];
|
||||
|
||||
// rewind to logical block 2
|
||||
img_file.read((char *)buf, 2*BLOCK_SIZE + offset, sizeof(buf));
|
||||
img.read((char *)buf, 2*BLOCK_SIZE + offset, sizeof(buf));
|
||||
|
||||
// check for HFS/MFS signature at the start of the logical block 2
|
||||
if ((buf[0] == 0x42 && buf[1] == 0x44) ||
|
||||
(buf[0] == 0xD2 && buf[1] == 0xD7)) {
|
||||
if (offset) {
|
||||
return FlopImgType::DC42;
|
||||
} else {
|
||||
return FlopImgType::RAW;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ((buf[0] == 0x42 && buf[1] == 0x44)
|
||||
|| (buf[0] == 0xD2 && buf[1] == 0xD7));
|
||||
};
|
||||
|
||||
if (check_hfs_mfs(img_file, 84))
|
||||
return FlopImgType::DC42;
|
||||
|
||||
if (check_hfs_mfs(img_file, 0))
|
||||
return FlopImgType::RAW;
|
||||
}
|
||||
|
||||
return FlopImgType::UNKNOWN;
|
||||
@@ -285,7 +288,7 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
|
||||
if (!img_file.open(img_path)) {
|
||||
img_file.close();
|
||||
LOG_F(ERROR, "Could not open specified floppy image (%s)!", img_path.c_str());
|
||||
LOG_F(ERROR, "Could not open specified floppy image (\"%s\")!", img_path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -295,19 +298,19 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
|
||||
switch(itype) {
|
||||
case FlopImgType::RAW:
|
||||
LOG_F(INFO, "Raw floppy image");
|
||||
LOG_F(INFO, "Raw floppy image (\"%s\")", img_path.c_str());
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
break;
|
||||
case FlopImgType::DC42:
|
||||
LOG_F(INFO, "Disk Copy 4.2 image");
|
||||
LOG_F(INFO, "Disk Copy 4.2 image (\"%s\")", img_path.c_str());
|
||||
fconv = new DiskCopy42Img(img_path);
|
||||
break;
|
||||
case FlopImgType::WOZ1:
|
||||
case FlopImgType::WOZ2:
|
||||
LOG_F(INFO, "WOZ v%s image", (itype == FlopImgType::WOZ2) ? "2" : "1");
|
||||
LOG_F(INFO, "WOZ v%s image (\"%s\")", (itype == FlopImgType::WOZ2) ? "2" : "1", img_path.c_str());
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unknown image format - assume RAW");
|
||||
LOG_F(WARNING, "Unknown image format - assume RAW (\"%s\")", img_path.c_str());
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,15 +21,56 @@ 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>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
namespace loguru {
|
||||
enum : Verbosity {
|
||||
Verbosity_READWRITE = loguru::Verbosity_9,
|
||||
Verbosity_SUPERDRIVE = loguru::Verbosity_9,
|
||||
};
|
||||
}
|
||||
|
||||
using namespace MacSuperdrive;
|
||||
|
||||
std::string MacSuperdrive::get_command_name(uint8_t addr)
|
||||
{
|
||||
switch (addr) {
|
||||
#define one_command(x) case CommandAddr::x: return #x;
|
||||
one_command(Step_Direction)
|
||||
one_command(Do_Step)
|
||||
one_command(Motor_On_Off)
|
||||
one_command(Eject_Disk)
|
||||
one_command(Reset_Eject_Latch)
|
||||
one_command(Switch_Drive_Mode)
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
std::string MacSuperdrive::get_status_name(uint8_t addr)
|
||||
{
|
||||
switch (addr) {
|
||||
#define one_status(x) case StatusAddr::x: return #x;
|
||||
one_status(Step_Status)
|
||||
one_status(Motor_Status)
|
||||
one_status(Eject_Latch)
|
||||
one_status(Select_Head_0)
|
||||
one_status(MFM_Support)
|
||||
one_status(Double_Sided)
|
||||
one_status(Drive_Exists)
|
||||
one_status(Disk_In_Drive)
|
||||
one_status(Write_Protect)
|
||||
one_status(Track_Zero)
|
||||
one_status(Select_Head_1)
|
||||
one_status(Drive_Mode)
|
||||
one_status(Drive_Ready)
|
||||
one_status(Media_Kind)
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
MacSuperDrive::MacSuperDrive(std::string name)
|
||||
{
|
||||
this->set_name(name);
|
||||
@@ -55,7 +96,8 @@ void MacSuperDrive::reset_params()
|
||||
|
||||
void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
{
|
||||
LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value);
|
||||
LOG_F(SUPERDRIVE, "%s: command %-17s addr=0x%X, value=%d",
|
||||
this->get_name().c_str(), get_command_name(addr).c_str(), addr, value);
|
||||
|
||||
switch(addr) {
|
||||
case CommandAddr::Step_Direction:
|
||||
@@ -71,7 +113,6 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
this->get_name().c_str(), this->cur_track, this->num_tracks - 1);
|
||||
this->cur_track = this->num_tracks - 1;
|
||||
}
|
||||
this->track_zero = this->cur_track == 0;
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Motor_On_Off:
|
||||
@@ -121,7 +162,6 @@ void MacSuperDrive::set_motor_stat(uint8_t new_motor_stat)
|
||||
|
||||
uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
{
|
||||
LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr);
|
||||
uint8_t value;
|
||||
|
||||
switch(addr) {
|
||||
@@ -153,7 +193,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
value = this->wr_protect ^ 1; // reverse logic
|
||||
break;
|
||||
case StatusAddr::Track_Zero:
|
||||
value = this->track_zero ^ 1; // reverse logic
|
||||
value = this->cur_track != 0; // reverse logic
|
||||
break;
|
||||
case StatusAddr::Select_Head_1:
|
||||
value = this->cur_head = 1;
|
||||
@@ -171,6 +211,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
LOG_F(WARNING, "%s: unimplemented status request, addr=0x%X", this->get_name().c_str(), addr);
|
||||
value = 0;
|
||||
}
|
||||
LOG_F(SUPERDRIVE, "%s: status %-13s 0x%X = %d", this->get_name().c_str(), get_status_name(addr).c_str(), addr, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -390,6 +431,8 @@ SectorHdr MacSuperDrive::current_sector_header()
|
||||
|
||||
char* MacSuperDrive::get_sector_data_ptr(int sector_num)
|
||||
{
|
||||
LOG_F(READWRITE, "%s: get_sector_data_ptr track:%d head:%d sector:%d",
|
||||
this->get_name().c_str(), this->cur_track, this->cur_head, sector_num);
|
||||
return this->disk_data.get() +
|
||||
((this->track2lblk[this->cur_track] +
|
||||
(this->cur_head * this->sectors_per_track[this->cur_track]) +
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -35,7 +35,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// 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
|
||||
// timing constants 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);
|
||||
@@ -94,6 +94,9 @@ typedef struct SectorHdr {
|
||||
int format;
|
||||
} SectorHdr;
|
||||
|
||||
std::string get_command_name(uint8_t addr);
|
||||
std::string get_status_name(uint8_t addr);
|
||||
|
||||
class MacSuperDrive : public HWComponent {
|
||||
public:
|
||||
MacSuperDrive(std::string name);
|
||||
@@ -125,7 +128,6 @@ private:
|
||||
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
|
||||
@@ -158,6 +160,6 @@ private:
|
||||
std::unique_ptr<char[]> disk_data;
|
||||
};
|
||||
|
||||
}; // namespace MacSuperdrive
|
||||
} // namespace MacSuperdrive
|
||||
|
||||
#endif // MAC_SUPERDRIVE_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -40,7 +40,7 @@ using namespace Swim3;
|
||||
Swim3Ctrl::Swim3Ctrl()
|
||||
{
|
||||
this->name = "SWIM3";
|
||||
this->supported_types = HWCompType::FLOPPY_CTRL;
|
||||
supports_types(HWCompType::FLOPPY_CTRL);
|
||||
|
||||
this->reset();
|
||||
|
||||
@@ -98,7 +98,7 @@ int Swim3Ctrl::device_postinit()
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
{
|
||||
@@ -290,8 +290,8 @@ void Swim3Ctrl::stop_stepping()
|
||||
// cancel stepping task
|
||||
if (this->step_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
|
||||
this->step_timer_id = 0;
|
||||
}
|
||||
this->step_timer_id = 0;
|
||||
this->step_count = 0; // not sure this one is required
|
||||
}
|
||||
|
||||
@@ -382,8 +382,8 @@ void Swim3Ctrl::stop_disk_access()
|
||||
// cancel disk access timer
|
||||
if (this->access_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
|
||||
this->access_timer_id = 0;
|
||||
}
|
||||
this->access_timer_id = 0;
|
||||
}
|
||||
|
||||
void Swim3Ctrl::init_timer(const uint8_t start_val)
|
||||
@@ -440,7 +440,7 @@ static const PropMap Swim3_Properties = {
|
||||
};
|
||||
|
||||
static const DeviceDescription Swim3_Descriptor = {
|
||||
Swim3Ctrl::create, {}, Swim3_Properties
|
||||
Swim3Ctrl::create, {}, Swim3_Properties, HWCompType::FLOPPY_CTRL
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Swim3, Swim3_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -73,7 +73,8 @@ enum {
|
||||
INT_STEP_DONE = 0x02,
|
||||
INT_ID_READ = 0x04,
|
||||
INT_SECT_DONE = 0x08,
|
||||
INT_SENSE = 0x10, // unused by SWIM3 driver
|
||||
INT_SENSE = 0x10, // generates interrupts on sense line changes
|
||||
INT_ERROR = 0x20, // missing in SWIM3 ERS but used in MkLinux/BeOS
|
||||
};
|
||||
|
||||
// SWIM3 internal states.
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
}
|
||||
|
||||
protected:
|
||||
void reset();
|
||||
@@ -151,6 +152,6 @@ private:
|
||||
uint8_t irq = 0;
|
||||
};
|
||||
|
||||
}; // namespace Swim3
|
||||
} // namespace Swim3
|
||||
|
||||
#endif // SWIM3_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -329,11 +329,10 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
break;
|
||||
case AMICReg::VIA2_IFR:
|
||||
// if bit 7 is set, clear the corresponding IRQ bit for each "1" in value
|
||||
// writing any value to VIA2_IFR with bit 7 cleared has no effect
|
||||
if (value & 0x80) {
|
||||
this->via2_ifr &= ~(value & 0x7F);
|
||||
this->update_via2_irq();
|
||||
} else { // writing any value to VIA2_IFR with bit 7 cleared has no effect
|
||||
LOG_F(WARNING, "%s: bit 7 of VIA2_IFR is cleared!", this->name.c_str());
|
||||
}
|
||||
break;
|
||||
case AMICReg::VIA2_Slot_IER:
|
||||
@@ -824,14 +823,14 @@ DmaPullResult AmicSerialXmitDma::pull_data(uint32_t req_len, uint32_t *avail_len
|
||||
uint8_t **p_data)
|
||||
{
|
||||
return DmaPullResult::NoMoreData;
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> Amic_Subdevices = {
|
||||
"ScsiCurio", "Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
|
||||
"Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription Amic_Descriptor = {
|
||||
AMIC::create, Amic_Subdevices, {}
|
||||
AMIC::create, Amic_Subdevices, {}, HWCompType::MMIO_DEV | HWCompType::INT_CTRL
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Amic, Amic_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -106,19 +106,19 @@ public:
|
||||
~AmicSndOutDma() = default;
|
||||
|
||||
void init(uint32_t buf_base, uint32_t buf_samples);
|
||||
void enable() { this->enabled = true; };
|
||||
void disable() { this->enabled = false; };
|
||||
void enable() { this->enabled = true; }
|
||||
void disable() { this->enabled = false; }
|
||||
uint8_t read_stat();
|
||||
void update_irq();
|
||||
void write_dma_out_ctrl(uint8_t value);
|
||||
uint32_t get_cur_buf_pos() { return this->cur_buf_pos; };
|
||||
uint32_t get_cur_buf_pos() { return this->cur_buf_pos; }
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data);
|
||||
|
||||
void init_interrupts(InterruptCtrl *int_ctrl, uint64_t irq_id) {
|
||||
this->int_ctrl = int_ctrl;
|
||||
this->snd_dma_irq_id = irq_id;
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
bool enabled = false;
|
||||
@@ -144,7 +144,7 @@ public:
|
||||
void reinit(const uint32_t addr_ptr, const uint16_t byte_cnt);
|
||||
void reset(const uint32_t addr_ptr);
|
||||
void write_ctrl(const uint8_t value);
|
||||
uint8_t read_stat() { return this->stat; };
|
||||
uint8_t read_stat() { return this->stat; }
|
||||
|
||||
int push_data(const char* src_ptr, int len);
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
~AmicSerialXmitDma() = default;
|
||||
|
||||
void write_ctrl(const uint8_t value);
|
||||
uint8_t read_stat() { return this->stat; };
|
||||
uint8_t read_stat() { return this->stat; }
|
||||
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data);
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
void reinit(const uint32_t addr_ptr);
|
||||
void reset(const uint32_t addr_ptr);
|
||||
void write_ctrl(const uint8_t value);
|
||||
uint8_t read_stat() { return this->stat; };
|
||||
uint8_t read_stat() { return this->stat; }
|
||||
|
||||
void xfer_to_device();
|
||||
void xfer_from_device();
|
||||
|
||||
@@ -33,35 +33,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
uint16_t NvramAddrHiDev::iodev_read(uint32_t address) {
|
||||
return nvram_addr_hi;
|
||||
}
|
||||
|
||||
void NvramAddrHiDev::iodev_write(uint32_t address, uint16_t value) {
|
||||
this->nvram_addr_hi = value;
|
||||
}
|
||||
|
||||
NvramDev::NvramDev(NvramAddrHiDev *addr_hi) {
|
||||
// NVRAM connection
|
||||
this->nvram = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
this->addr_hi = addr_hi;
|
||||
}
|
||||
|
||||
uint16_t NvramDev::iodev_read(uint32_t address) {
|
||||
return this->nvram->read_byte((addr_hi->iodev_read(0) << 5) + address);
|
||||
}
|
||||
|
||||
void NvramDev::iodev_write(uint32_t address, uint16_t value) {
|
||||
this->nvram->write_byte((addr_hi->iodev_read(0) << 5) + address, value);
|
||||
}
|
||||
|
||||
GrandCentral::GrandCentral() : PCIDevice("mac-io_grandcentral"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
|
||||
supports_types(HWCompType::IOBUS_HOST | HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = MIO_DEV_ID_GRANDCENTRAL;
|
||||
this->status = 0x0200; // 9:DEVSEL
|
||||
this->class_rev = 0xFF000002;
|
||||
this->cache_ln_sz = 8;
|
||||
|
||||
@@ -230,6 +215,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
uint8_t val = mac_address[(offset >> 4) & 0x7];
|
||||
if (((offset >> 4) & 0x7) < 6) {
|
||||
if (mac_address[0] == 0x08 && bit_flip_0x08)
|
||||
// reverse the order of the bits
|
||||
val = (val * 0x0202020202ULL & 0x010884422010ULL) % 1023;
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: reading byte %d of ENET_ROM using offset %x",
|
||||
@@ -271,6 +257,13 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
return this->enet_tx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ETH_RCV:
|
||||
return this->enet_rx_dma->reg_read(offset & 0xFF, size);
|
||||
|
||||
case MIO_GC_DMA_ESCC_A_XMIT:
|
||||
case MIO_GC_DMA_ESCC_A_RCV:
|
||||
case MIO_GC_DMA_ESCC_B_XMIT:
|
||||
case MIO_GC_DMA_ESCC_B_RCV:
|
||||
return 0;
|
||||
/*Stubbed out due to serial emulation being unfinished.
|
||||
case MIO_GC_DMA_ESCC_A_XMIT:
|
||||
return this->escc_a_tx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ESCC_A_RCV:
|
||||
@@ -278,7 +271,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
case MIO_GC_DMA_ESCC_B_XMIT:
|
||||
return this->escc_b_tx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ESCC_B_RCV:
|
||||
return this->escc_b_rx_dma->reg_read(offset & 0xFF, size);
|
||||
return this->escc_b_rx_dma->reg_read(offset & 0xFF, size);*/
|
||||
case MIO_GC_DMA_AUDIO_OUT:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_AUDIO_IN:
|
||||
@@ -307,7 +300,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
case MIO_INT_MASK1:
|
||||
return BYTESWAP_32(this->int_mask);
|
||||
case MIO_INT_CLEAR1:
|
||||
// some Mac OS drivers reads from this write-only register
|
||||
// some Mac OS drivers read from this write-only register
|
||||
// so we return zero here as real HW does
|
||||
return 0;
|
||||
case MIO_INT_LEVELS1:
|
||||
@@ -405,16 +398,16 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->enet_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_A_XMIT:
|
||||
this->escc_a_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
//this->escc_a_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_A_RCV:
|
||||
this->escc_a_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
//this->escc_a_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_B_XMIT:
|
||||
this->escc_b_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
//this->escc_b_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_B_RCV:
|
||||
this->escc_b_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
//this->escc_b_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_AUDIO_OUT:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
@@ -468,8 +461,6 @@ void GrandCentral::attach_iodevice(int dev_num, IobusDevice* dev_obj)
|
||||
}
|
||||
}
|
||||
|
||||
#define INT_TO_IRQ_ID(intx) (1 << intx)
|
||||
|
||||
uint64_t GrandCentral::register_dev_int(IntSrc src_id) {
|
||||
switch (src_id) {
|
||||
case IntSrc::SCSI_CURIO : return INT_TO_IRQ_ID(0x0C);
|
||||
@@ -577,12 +568,23 @@ void GrandCentral::clear_cpu_int() {
|
||||
}
|
||||
}
|
||||
|
||||
static const std::vector<std::string> GCSubdevices = {
|
||||
"NVRAM", "ViaCuda", "Escc", "ScsiCurio", "Sc53C94", "Mace", "Swim3"
|
||||
static const std::vector<std::string> GrandCentralCatalyst_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "Escc", "Sc53C94", "Mace", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription GC_Descriptor = {
|
||||
GrandCentral::create, GCSubdevices, {}
|
||||
static const std::vector<std::string> GrandCentralTnt_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "Escc", "Sc53C94", "MeshTnt", "Mace", "Swim3"
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(GrandCentral, GC_Descriptor);
|
||||
static const DeviceDescription GrandCentralCatalyst_Descriptor = {
|
||||
GrandCentral::create, GrandCentralCatalyst_Subdevices, {},
|
||||
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
|
||||
};
|
||||
|
||||
static const DeviceDescription GrandCentralTnt_Descriptor = {
|
||||
GrandCentral::create, GrandCentralTnt_Subdevices, {},
|
||||
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(GrandCentralCatalyst, GrandCentralCatalyst_Descriptor);
|
||||
REGISTER_DEVICE(GrandCentralTnt, GrandCentralTnt_Descriptor);
|
||||
+107
-137
@@ -69,6 +69,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** PCI device IDs for various MacIO ASICs. */
|
||||
enum {
|
||||
@@ -82,24 +83,20 @@ enum {
|
||||
#define MACIO_INT_CLR 0x80UL // clears bits in the interrupt events registers
|
||||
#define MACIO_INT_MODE 0x80000000UL // interrupt mode: 0 - native, 1 - 68k-style
|
||||
|
||||
#define INT_TO_IRQ_ID(intx) (1ULL << intx)
|
||||
|
||||
/** Offsets to common MacIO interrupt registers. */
|
||||
enum {
|
||||
MIO_INT_EVENTS2 = 0x10,
|
||||
MIO_INT_MASK2 = 0x14,
|
||||
MIO_INT_CLEAR2 = 0x18,
|
||||
MIO_INT_LEVELS2 = 0x1C,
|
||||
MIO_INT_EVENTS2 = 0x10, // Heathrow/Paddington only
|
||||
MIO_INT_MASK2 = 0x14, // Heathrow/Paddington only
|
||||
MIO_INT_CLEAR2 = 0x18, // Heathrow/Paddington only
|
||||
MIO_INT_LEVELS2 = 0x1C, // Heathrow/Paddington only
|
||||
MIO_INT_EVENTS1 = 0x20,
|
||||
MIO_INT_MASK1 = 0x24,
|
||||
MIO_INT_CLEAR1 = 0x28,
|
||||
MIO_INT_LEVELS1 = 0x2C
|
||||
};
|
||||
|
||||
class IobusDevice {
|
||||
public:
|
||||
virtual uint16_t iodev_read(uint32_t address) = 0;
|
||||
virtual void iodev_write(uint32_t address, uint16_t value) = 0;
|
||||
};
|
||||
|
||||
/** GrandCentral DBDMA channels. */
|
||||
enum : uint8_t {
|
||||
MIO_GC_DMA_SCSI_CURIO = 0,
|
||||
@@ -115,11 +112,22 @@ enum : uint8_t {
|
||||
MIO_GC_DMA_SCSI_MESH = 0xA,
|
||||
};
|
||||
|
||||
class IobusDevice {
|
||||
public:
|
||||
virtual uint16_t iodev_read(uint32_t address) = 0;
|
||||
virtual void iodev_write(uint32_t address, uint16_t value) = 0;
|
||||
};
|
||||
|
||||
class NvramAddrHiDev: public IobusDevice {
|
||||
public:
|
||||
// IobusDevice methods
|
||||
uint16_t iodev_read(uint32_t address);
|
||||
void iodev_write(uint32_t address, uint16_t value);
|
||||
uint16_t iodev_read(uint32_t address) {
|
||||
return nvram_addr_hi;
|
||||
}
|
||||
|
||||
void iodev_write(uint32_t address, uint16_t value) {
|
||||
this->nvram_addr_hi = value;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint16_t nvram_addr_hi = 0;
|
||||
@@ -130,12 +138,59 @@ public:
|
||||
NvramDev(NvramAddrHiDev *addr_hi);
|
||||
|
||||
// IobusDevice methods
|
||||
uint16_t iodev_read(uint32_t address);
|
||||
void iodev_write(uint32_t address, uint16_t value);
|
||||
uint16_t iodev_read(uint32_t address) {
|
||||
return this->nvram->read_byte((addr_hi->iodev_read(0) << 5) + address);
|
||||
}
|
||||
|
||||
void iodev_write(uint32_t address, uint16_t value) {
|
||||
this->nvram->write_byte((addr_hi->iodev_read(0) << 5) + address, value);
|
||||
}
|
||||
|
||||
protected:
|
||||
NVram* nvram;
|
||||
NvramAddrHiDev* addr_hi;
|
||||
NVram* nvram = nullptr;
|
||||
NvramAddrHiDev* addr_hi = nullptr;
|
||||
};
|
||||
|
||||
/** This class provides common building blocks for various MacIO ASICs. */
|
||||
class MacIoBase : public PCIDevice, public InterruptCtrl {
|
||||
public:
|
||||
MacIoBase(std::string name, uint16_t dev_id, uint8_t rev=1);
|
||||
~MacIoBase() = default;
|
||||
|
||||
uint64_t register_dma_int(IntSrc src_id) override;
|
||||
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override;
|
||||
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override;
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
|
||||
void signal_cpu_int();
|
||||
void clear_cpu_int();
|
||||
|
||||
// PCI device state
|
||||
uint32_t iomem_size = 0;
|
||||
uint32_t base_addr = 0;
|
||||
|
||||
// interrupt state
|
||||
uint64_t int_mask = 0;
|
||||
bool cpu_int_latch = false;
|
||||
std::atomic<uint64_t> int_levels{0};
|
||||
std::atomic<uint64_t> int_events{0};
|
||||
|
||||
// Subdevice objects
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
MacioSndCodec* snd_codec; // audio codec instance
|
||||
EsccController* escc; // ESCC serial controller
|
||||
|
||||
// DMA channels
|
||||
std::unique_ptr<DMAChannel> floppy_dma;
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> snd_in_dma;
|
||||
std::unique_ptr<DMAChannel> escc_a_tx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_a_rx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_b_tx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_b_rx_dma;
|
||||
};
|
||||
|
||||
class GrandCentral : public PCIDevice, public InterruptCtrl {
|
||||
@@ -206,92 +261,6 @@ private:
|
||||
uint16_t unsupported_dma_channel_write = 0;
|
||||
};
|
||||
|
||||
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) override;
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override;
|
||||
|
||||
// InterruptCtrl methods
|
||||
uint64_t register_dev_int(IntSrc src_id) override;
|
||||
uint64_t register_dma_int(IntSrc src_id) override;
|
||||
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override;
|
||||
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override;
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
|
||||
uint32_t mio_ctrl_read(uint32_t offset, int size);
|
||||
uint32_t mio_ctrl_read_aligned(uint32_t offset);
|
||||
void mio_ctrl_write(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);
|
||||
|
||||
void feature_control(const uint32_t value);
|
||||
|
||||
void signal_cpu_int();
|
||||
void clear_cpu_int();
|
||||
|
||||
private:
|
||||
uint32_t base_addr = 0;
|
||||
|
||||
// interrupt state
|
||||
uint32_t int_mask = 0;
|
||||
std::atomic<uint32_t> int_levels{0};
|
||||
std::atomic<uint32_t> int_events{0};
|
||||
bool cpu_int_latch = false;
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
|
||||
// subdevice objects
|
||||
MacioSndCodec* snd_codec; // audio codec instance
|
||||
|
||||
NVram* nvram; // NVRAM
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
MeshController* mesh; // MESH SCSI cell instance
|
||||
EsccController* escc; // ESCC serial controller
|
||||
IdeChannel* ide_0; // Internal ATA
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
|
||||
// DMA channels
|
||||
std::unique_ptr<DMAChannel> mesh_dma;
|
||||
std::unique_ptr<DMAChannel> floppy_dma;
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
|
||||
uint16_t unsupported_dma_channel_read = 0;
|
||||
uint16_t unsupported_dma_channel_write = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
Heathrow ASIC emulation
|
||||
|
||||
Heathrow is a MIO-compliant ASIC used in the Gossamer architecture. It's
|
||||
hard-wired to PCI device number 16. Its I/O memory (512Kb) will be configured
|
||||
by the Macintosh firmware to live at 0xF3000000.
|
||||
|
||||
Emulated subdevices and their offsets within Heathrow I/O space:
|
||||
----------------------------------------------------------------
|
||||
mesh(SCSI) register space: 0x00010000, DMA space: 0x00008000
|
||||
bmac(ethernet) register space: 0x00011000, DMA space: 0x00008200, 0x00008300
|
||||
escc(compat) register space: 0x00012000, size: 0x00001000
|
||||
DMA space: 0x00008400, size: 0x00000400
|
||||
escc(MacRISC) register space: 0x00013000, size: 0x00001000
|
||||
DMA space: 0x00008400, size: 0x00000400
|
||||
escc:ch-a register space: 0x00013020, DMA space: 0x00008400, 0x00008500
|
||||
escc:ch-b register space: 0x00013000, DMA space: 0x00008600, 0x00008700
|
||||
davbus(sound) register space: 0x00014000, DMA space: 0x00008800, 0x00008900
|
||||
SWIM3(floppy) register space: 0x00015000, DMA space: 0x00008100
|
||||
NVRAM register space: 0x00060000, size: 0x00020000
|
||||
IDE register space: 0x00020000, DMA space: 0x00008b00
|
||||
VIA-CUDA register space: 0x00016000, size: 0x00002000
|
||||
*/
|
||||
|
||||
/** O'Hare/Heathrow specific registers. */
|
||||
enum {
|
||||
MIO_OHARE_ID = 0x34, // IDs register
|
||||
@@ -303,7 +272,7 @@ enum {
|
||||
enum {
|
||||
MIO_OH_ID_FP = 0x70000000, // Flat panel ID
|
||||
MIO_OH_ID_MON = 0x00300000, // Monitor ID (mon_id?=1, no s-video/composite=3 but only if fatman exists).
|
||||
MIO_OH_ID_MB = 0x0000F000, // Media Bay ID (0,1=swim, 3=ata, 5=pci, 7=?)
|
||||
MIO_OH_ID_MB = 0x0000F000, // Media Bay ID (0,1=swim, 3=ata, 5=pci, 7=?, 4=TAM)
|
||||
MIO_OH_ID_CPU = 0x000000E0, // CPUID field
|
||||
MIO_OH_ID_DISABLE_SCSI_TERMINATORS = 0x00000010, // clear this bit to disable-scsi-terminators - read this bit for emmo_pin
|
||||
MIO_OH_ID_ENABLE_SCSI_TERMINATORS = 0x00000008, // set this bit to enable-scsi-terminators
|
||||
@@ -339,8 +308,8 @@ enum {
|
||||
MIO_OH_FC_NOT_IDE1_RESET = 1 << 23,
|
||||
MIO_OH_FC_SLOW_SCC_PCLK = 1 << 24,
|
||||
MIO_OH_FC_RESET_SCC = 1 << 25,
|
||||
MIO_OH_FC_MFDC_CELL_EN = 1 << 26,
|
||||
MIO_OH_FC_USE_MFDC = 1 << 27,
|
||||
MIO_OH_FC_MFDC_CELL_EN = 1 << 26, // Heathrow/Paddington only
|
||||
MIO_OH_FC_USE_MFDC = 1 << 27, // Heathrow/Paddington only
|
||||
MIO_OH_FC_RESVD28 = 1 << 28,
|
||||
MIO_OH_FC_RESVD29 = 1 << 29,
|
||||
MIO_OH_FC_RESVD30 = 1 << 30,
|
||||
@@ -363,16 +332,39 @@ enum : uint8_t {
|
||||
MIO_OHARE_DMA_IDE1 = 0xC
|
||||
};
|
||||
|
||||
class HeathrowIC : public PCIDevice, public InterruptCtrl {
|
||||
/** Implementation class for O'Hare/Heathrow/Paddington devices. */
|
||||
class MacIoTwo : public MacIoBase {
|
||||
public:
|
||||
HeathrowIC();
|
||||
~HeathrowIC() = default;
|
||||
MacIoTwo(std::string name, uint16_t dev_id);
|
||||
~MacIoTwo() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<HeathrowIC>(new HeathrowIC());
|
||||
static std::unique_ptr<HWComponent> create_ohare() {
|
||||
return std::unique_ptr<MacIoTwo>(new MacIoTwo("ohare", MIO_DEV_ID_OHARE));
|
||||
}
|
||||
|
||||
void set_media_bay_id(uint8_t id);
|
||||
static std::unique_ptr<HWComponent> create_heathrow() {
|
||||
return std::unique_ptr<MacIoTwo>(new MacIoTwo("heathrow", MIO_DEV_ID_HEATHROW));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_paddington() {
|
||||
return std::unique_ptr<MacIoTwo>(new MacIoTwo("paddington", MIO_DEV_ID_PADDINGTON));
|
||||
}
|
||||
|
||||
void set_fp_id(uint8_t id) {
|
||||
this->fp_id = id;
|
||||
}
|
||||
|
||||
void set_mon_id(uint8_t id) {
|
||||
this->mon_id = id;
|
||||
}
|
||||
|
||||
void set_media_bay_id(uint8_t id) {
|
||||
this->mb_id = id;
|
||||
}
|
||||
|
||||
void set_cpu_id(uint8_t id) {
|
||||
this->cpu_id = id;
|
||||
}
|
||||
|
||||
// MMIO device methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
|
||||
@@ -381,8 +373,6 @@ public:
|
||||
// InterruptCtrl methods
|
||||
uint64_t register_dev_int(IntSrc src_id) override;
|
||||
uint64_t register_dma_int(IntSrc src_id) override;
|
||||
void ack_int(uint64_t irq_id, uint8_t irq_line_state) override;
|
||||
void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) override;
|
||||
|
||||
protected:
|
||||
uint32_t dma_read(uint32_t offset, int size);
|
||||
@@ -391,23 +381,9 @@ protected:
|
||||
uint32_t mio_ctrl_read(uint32_t offset, int size);
|
||||
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void notify_bar_change(int bar_num);
|
||||
void ack_int_common(uint64_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
void feature_control(uint32_t value);
|
||||
|
||||
void signal_cpu_int();
|
||||
void clear_cpu_int();
|
||||
|
||||
private:
|
||||
uint32_t base_addr = 0;
|
||||
|
||||
// interrupt state
|
||||
uint64_t int_mask = 0;
|
||||
std::atomic<uint64_t> int_levels{0};
|
||||
std::atomic<uint64_t> int_events{0};
|
||||
bool cpu_int_latch = false;
|
||||
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
|
||||
@@ -415,27 +391,21 @@ private:
|
||||
uint8_t mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_HEAT_ID)
|
||||
uint8_t mon_id = 0x10; // Monitor ID (bits 23:16 of the MIO_HEAT_ID)
|
||||
uint8_t fp_id = 0x70; // Flat panel ID (MSB of the MIO_HEAT_ID)
|
||||
uint8_t emmo_pin; // factory tester status, active low
|
||||
|
||||
// subdevice objects
|
||||
MacioSndCodec* snd_codec; // audio codec instance
|
||||
uint8_t emmo = 0x01; // factory tester status, active low
|
||||
|
||||
// Subdevice object pointers
|
||||
NVram* nvram; // NVRAM
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
MeshController* mesh; // MESH SCSI cell instance
|
||||
EsccController* escc; // ESCC serial controller
|
||||
IdeChannel* ide_0; // Internal ATA
|
||||
IdeChannel* ide_1; // Media Bay ATA
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
BigMac* bmac; // Ethernet MAC cell
|
||||
|
||||
// DMA channels
|
||||
std::unique_ptr<DMAChannel> mesh_dma;
|
||||
std::unique_ptr<DMAChannel> floppy_dma;
|
||||
std::unique_ptr<DMAChannel> enet_xmit_dma;
|
||||
std::unique_ptr<DMAChannel> enet_rcv_dma;
|
||||
std::unique_ptr<DMAChannel> escc_b_rcv_dma;
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> ide0_dma;
|
||||
std::unique_ptr<DMAChannel> ide1_dma;
|
||||
|
||||
uint16_t unsupported_dma_channel_read = 0;
|
||||
uint16_t unsupported_dma_channel_write = 0;
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 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/common/hwcomponent.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
MacIoBase::MacIoBase(std::string name, uint16_t dev_id, uint8_t rev) :
|
||||
PCIDevice("mac-io_" + name), 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 = dev_id;
|
||||
this->class_rev = 0xFF000000 + rev;
|
||||
this->cache_ln_sz = 8;
|
||||
|
||||
// select memory mapped I/O size: 128Kb for Grand Central, 512Kb for others
|
||||
this->iomem_size = (dev_id == MIO_DEV_ID_GRANDCENTRAL) ? 0x20000 : 0x80000;
|
||||
|
||||
this->setup_bars({{0, -this->iomem_size}});
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
// connect Cuda
|
||||
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
|
||||
// find the sound codec, create its DMA channels, 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("snd_out"));
|
||||
this->snd_out_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Tx));
|
||||
this->snd_codec->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec),
|
||||
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
|
||||
);
|
||||
this->snd_in_dma = std::unique_ptr<DMAChannel> (new DMAChannel("snd_in"));
|
||||
this->snd_in_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Rx));
|
||||
this->snd_codec->set_dma_in(this->snd_in_dma.get());
|
||||
this->snd_in_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_in_start, this->snd_codec),
|
||||
std::bind(&AwacsScreamer::dma_in_stop, this->snd_codec)
|
||||
);
|
||||
|
||||
// connect floppy disk controller 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("floppy"));
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
this->floppy_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SWIM3));
|
||||
|
||||
// connect serial HW to its DMA channels
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
this->escc_a_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_a_tx"));
|
||||
this->escc_a_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_a_rx"));
|
||||
this->escc_b_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_b_tx"));
|
||||
this->escc_b_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Escc_b_rx"));
|
||||
this->escc_a_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCA_Tx));
|
||||
this->escc_a_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCA_Rx));
|
||||
this->escc_b_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCB_Tx));
|
||||
this->escc_b_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCCB_Rx));
|
||||
this->escc->set_dma_channel(0, this->escc_a_tx_dma.get());
|
||||
this->escc->set_dma_channel(1, this->escc_a_rx_dma.get());
|
||||
this->escc->set_dma_channel(2, this->escc_b_tx_dma.get());
|
||||
this->escc->set_dma_channel(3, this->escc_b_rx_dma.get());
|
||||
}
|
||||
|
||||
void MacIoBase::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) {
|
||||
this->host_instance->pci_unregister_mmio_region(this->base_addr,
|
||||
this->iomem_size, this);
|
||||
}
|
||||
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, this->iomem_size, this);
|
||||
LOG_F(INFO, "%s: base address set to 0x%X", this->name.c_str(), this->base_addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t MacIoBase::register_dma_int(IntSrc src_id) {
|
||||
switch (src_id) {
|
||||
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
|
||||
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04);
|
||||
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05);
|
||||
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06);
|
||||
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07);
|
||||
case IntSrc::DMA_DAVBUS_Tx : return INT_TO_IRQ_ID(0x08);
|
||||
case IntSrc::DMA_DAVBUS_Rx : return INT_TO_IRQ_ID(0x09);
|
||||
default:
|
||||
ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MacIoBase::ack_int_common(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
// native mode: set IRQ bits in int_events on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events on all transitions
|
||||
#if 0
|
||||
LOG_F(INTERRUPT, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change:%08x.%08x state:%d",
|
||||
this->name.c_str(), uint32_t(this->int_events >> 32), uint32_t(this->int_events),
|
||||
uint32_t(this->int_levels >> 32), uint32_t(this->int_levels),
|
||||
uint32_t(irq_id >> 32), uint32_t(irq_id), irq_line_state
|
||||
);
|
||||
#endif
|
||||
if ((this->int_mask & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels & irq_id))) {
|
||||
this->int_events |= irq_id;
|
||||
} else {
|
||||
this->int_events &= ~irq_id;
|
||||
}
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels |= irq_id;
|
||||
} else {
|
||||
this->int_levels &= ~irq_id;
|
||||
}
|
||||
|
||||
this->signal_cpu_int();
|
||||
}
|
||||
|
||||
void MacIoBase::ack_int(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
this->ack_int_common(irq_id, irq_line_state);
|
||||
}
|
||||
|
||||
void MacIoBase::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) {
|
||||
this->ack_int_common(irq_id, irq_line_state);
|
||||
}
|
||||
|
||||
void MacIoBase::signal_cpu_int() {
|
||||
if (this->int_events & this->int_mask) {
|
||||
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 MacIoBase::clear_cpu_int() {
|
||||
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
|
||||
this->cpu_int_latch = false;
|
||||
ppc_release_int();
|
||||
LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,66 +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/>.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
/** @file MacIO 2nd generation I/O controllers emulation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), 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 = MIO_DEV_ID_HEATHROW;
|
||||
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);
|
||||
};
|
||||
|
||||
MacIoTwo::MacIoTwo(std::string name, uint16_t dev_id) : MacIoBase(name, dev_id) {
|
||||
// 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"));
|
||||
|
||||
// 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("snd_out"));
|
||||
this->snd_out_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Tx));
|
||||
this->snd_codec->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec),
|
||||
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
|
||||
);
|
||||
|
||||
// connect SCSI HW and the corresponding DMA channel
|
||||
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("MeshHeathrow"));
|
||||
// connect SCSI controller cell and its DMA channel
|
||||
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_type(HWCompType::SCSI_HOST));
|
||||
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh"));
|
||||
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
|
||||
this->mesh_dma->connect(this->mesh);
|
||||
@@ -86,130 +39,35 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io_heathrow"), InterruptCtrl()
|
||||
|
||||
// connect IDE HW
|
||||
this->ide_0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide0"));
|
||||
this->ide_1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide1"));
|
||||
this->ide0_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Ide0-Dma"));
|
||||
this->ide0_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_IDE0));
|
||||
this->ide0_dma->connect(this->ide_0);
|
||||
this->ide_0->connect(this->ide0_dma.get());
|
||||
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
|
||||
// connect DBDMA
|
||||
this->escc_b_rcv_dma = std::unique_ptr<DMAChannel>(new DMAChannel("DBDMABRx"));
|
||||
|
||||
// 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("floppy"));
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
this->floppy_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SWIM3));
|
||||
|
||||
// connect Ethernet HW
|
||||
this->bmac = dynamic_cast<BigMac*>(gMachineObj->get_comp_by_type(HWCompType::ETHER_MAC));
|
||||
this->enet_xmit_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacTx"));
|
||||
this->enet_rcv_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacRx"));
|
||||
|
||||
// set EMMO pin status (active low)
|
||||
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
|
||||
}
|
||||
|
||||
static const char *get_name_dma(unsigned dma_channel) {
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH : return "DMA_MESH" ;
|
||||
case MIO_OHARE_DMA_FLOPPY : return "DMA_FLOPPY" ;
|
||||
case MIO_OHARE_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
|
||||
case MIO_OHARE_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
|
||||
case MIO_OHARE_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
|
||||
case MIO_OHARE_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
|
||||
case MIO_OHARE_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
|
||||
case MIO_OHARE_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
|
||||
case MIO_OHARE_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
|
||||
case MIO_OHARE_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
|
||||
case MIO_OHARE_DMA_IDE0 : return "DMA_IDE0" ;
|
||||
case MIO_OHARE_DMA_IDE1 : return "DMA_IDE1" ;
|
||||
default : return "unknown" ;
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::set_media_bay_id(uint8_t id) {
|
||||
this->mb_id = id;
|
||||
}
|
||||
|
||||
void HeathrowIC::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) {
|
||||
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);
|
||||
LOG_F(INFO, "%s: base address set to 0x%X", this->get_name().c_str(), this->base_addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
|
||||
int dma_channel = offset >> 8;
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH:
|
||||
if (this->mesh_dma)
|
||||
return this->mesh_dma->reg_read(offset & 0xFF, size);
|
||||
else
|
||||
return 0;
|
||||
case MIO_OHARE_DMA_FLOPPY:
|
||||
return this->floppy_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_ETH_XMIT:
|
||||
return this->enet_xmit_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_ETH_RCV:
|
||||
return this->enet_rcv_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_ESCC_B_RCV:
|
||||
return this->escc_b_rcv_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_AUDIO_OUT:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
default:
|
||||
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
|
||||
unsupported_dma_channel_read |= (1 << dma_channel);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c", this->name.c_str(),
|
||||
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size));
|
||||
}
|
||||
this->ide_1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name_optional("Ide1"));
|
||||
this->ide1_dma = std::unique_ptr<DMAChannel> (new DMAChannel("Ide1-Dma"));
|
||||
this->ide1_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_IDE1));
|
||||
if (this->ide_1) {
|
||||
this->ide1_dma->connect(this->ide_1);
|
||||
this->ide_1->connect(this->ide1_dma.get());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
|
||||
int dma_channel = offset >> 8;
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH:
|
||||
if (this->mesh_dma) this->mesh_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_FLOPPY:
|
||||
this->floppy_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_ETH_XMIT:
|
||||
this->enet_xmit_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_ETH_RCV:
|
||||
this->enet_rcv_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_ESCC_B_RCV:
|
||||
this->escc_b_rcv_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_AUDIO_OUT:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
|
||||
unsupported_dma_channel_write |= (1 << dma_channel);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x", this->name.c_str(),
|
||||
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
// connect Ethernet HW (Heathrow and Paddington)
|
||||
if (this->device_id != MIO_DEV_ID_OHARE) {
|
||||
this->bmac = dynamic_cast<BigMac*>(gMachineObj->get_comp_by_type(HWCompType::ETHER_MAC));
|
||||
this->enet_xmit_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacTx"));
|
||||
this->enet_rcv_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacRx"));
|
||||
}
|
||||
|
||||
// set EMMO status (active low)
|
||||
this->emmo = GET_BIN_PROP("emmo") ^ 1;
|
||||
}
|
||||
|
||||
|
||||
uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
uint32_t MacIoTwo::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
uint32_t value;
|
||||
|
||||
LOG_F(9, "%s: reading from offset %x", this->name.c_str(), offset);
|
||||
LOG_F(9, "%s: read @%x.%c", this->get_name().c_str(),
|
||||
offset, SIZE_ARG(size));
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
@@ -233,7 +91,8 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
}
|
||||
if ((offset & 0xFF) < 0x60) {
|
||||
value = 0;
|
||||
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(), offset, SIZE_ARG(size));
|
||||
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(),
|
||||
offset, SIZE_ARG(size));
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
@@ -251,25 +110,27 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
value = this->viacuda->read((offset >> 9) & 0xF);
|
||||
break;
|
||||
case 0x20: // IDE 0
|
||||
value = this->ide_0->read((offset >> 4) & 0x1F, size);
|
||||
value = this->ide_0->read((offset >> 4) & 0x3F, size);
|
||||
break;
|
||||
case 0x21: // IDE 1
|
||||
value = this->ide_1->read((offset >> 4) & 0x1F, size);
|
||||
value = this->ide_1 ? this->ide_1->read((offset >> 4) & 0x3F, size) : 0;
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
value = this->nvram->read_byte((offset >> 4) & 0x1FFF);
|
||||
} else {
|
||||
value = 0;
|
||||
LOG_F(WARNING, "Attempting to read from unmapped I/O space: %x", offset);
|
||||
LOG_F(WARNING, "%s: read @%x.%c", this->get_name().c_str(),
|
||||
offset, SIZE_ARG(size));
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
|
||||
LOG_F(9, "%s: writing to offset %x", this->name.c_str(), offset);
|
||||
void MacIoTwo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
|
||||
LOG_F(9, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
@@ -310,22 +171,111 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
|
||||
case 0x17:
|
||||
this->viacuda->write((offset >> 9) & 0xF, value);
|
||||
break;
|
||||
case 0x20: // IDE O
|
||||
this->ide_0->write((offset >> 4) & 0x1F, value, size);
|
||||
case 0x20: // IDE 0
|
||||
this->ide_0->write((offset >> 4) & 0x3F, value, size);
|
||||
break;
|
||||
case 0x21: // IDE 1
|
||||
this->ide_1->write((offset >> 4) & 0x1F, value, size);
|
||||
if (this->ide_1)
|
||||
this->ide_1->write((offset >> 4) & 0x3F, value, size);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
||||
} else {
|
||||
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x", offset);
|
||||
LOG_F(WARNING, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
static const char *get_name_dma(unsigned dma_channel) {
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH : return "DMA_MESH" ;
|
||||
case MIO_OHARE_DMA_FLOPPY : return "DMA_FLOPPY" ;
|
||||
case MIO_OHARE_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
|
||||
case MIO_OHARE_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
|
||||
case MIO_OHARE_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
|
||||
case MIO_OHARE_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
|
||||
case MIO_OHARE_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
|
||||
case MIO_OHARE_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
|
||||
case MIO_OHARE_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
|
||||
case MIO_OHARE_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
|
||||
case MIO_OHARE_DMA_IDE0 : return "DMA_IDE0" ;
|
||||
case MIO_OHARE_DMA_IDE1 : return "DMA_IDE1" ;
|
||||
default : return "unknown" ;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MacIoTwo::dma_read(uint32_t offset, int size) {
|
||||
int dma_channel = offset >> 8;
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH:
|
||||
return this->mesh_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_FLOPPY:
|
||||
return this->floppy_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_ETH_XMIT:
|
||||
return this->enet_xmit_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_ETH_RCV:
|
||||
return this->enet_rcv_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_ESCC_B_RCV:
|
||||
return 0;
|
||||
//return this->escc_b_rx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_AUDIO_OUT:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_IDE0:
|
||||
return this->ide0_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_IDE1:
|
||||
return this->ide1_dma->reg_read(offset & 0xFF, size);
|
||||
default:
|
||||
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
|
||||
unsupported_dma_channel_read |= (1 << dma_channel);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c",
|
||||
this->name.c_str(), dma_channel, get_name_dma(dma_channel),
|
||||
offset & 0xFF, SIZE_ARG(size));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MacIoTwo::dma_write(uint32_t offset, uint32_t value, int size) {
|
||||
int dma_channel = offset >> 8;
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH:
|
||||
this->mesh_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_FLOPPY:
|
||||
this->floppy_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_ETH_XMIT:
|
||||
this->enet_xmit_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_ETH_RCV:
|
||||
this->enet_rcv_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_ESCC_B_RCV:
|
||||
this->escc_b_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_AUDIO_OUT:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_IDE0:
|
||||
this->ide0_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_IDE1:
|
||||
this->ide1_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
|
||||
unsupported_dma_channel_write |= (1 << dma_channel);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x",
|
||||
this->name.c_str(), dma_channel, get_name_dma(dma_channel),
|
||||
offset & 0xFF, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MacIoTwo::mio_ctrl_read(uint32_t offset, int size) {
|
||||
uint32_t value;
|
||||
|
||||
switch (offset & 0xFC) {
|
||||
@@ -349,29 +299,31 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
case MIO_INT_CLEAR2:
|
||||
// some Mac OS drivers reads from those write-only registers
|
||||
// some Mac OS drivers read from these write-only registers
|
||||
// so we return zero here as real HW does
|
||||
value = 0;
|
||||
break;
|
||||
case MIO_OHARE_ID:
|
||||
LOG_F(9, "read from MIO:ID register at Address %x", ppc_state.pc);
|
||||
value = (this->fp_id << 24) | (this->mon_id << 16) | (this->mb_id << 8) |
|
||||
(this->cpu_id | (this->emmo_pin << 4));
|
||||
(this->cpu_id | (this->emmo << 4));
|
||||
LOG_F(9, "%s: read OHARE_ID @%02x = %08x",
|
||||
this->get_name().c_str(), offset, value);
|
||||
break;
|
||||
case MIO_OHARE_FEAT_CTRL:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register");
|
||||
value = this->feat_ctrl;
|
||||
LOG_F(9, "%s: read FEAT_CTRL @%02x = %08x",
|
||||
this->get_name().c_str(), offset, value);
|
||||
break;
|
||||
default:
|
||||
value = 0;
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x", offset);
|
||||
break;
|
||||
LOG_F(WARNING, "%s: read @%02x",
|
||||
this->get_name().c_str(), offset);
|
||||
}
|
||||
|
||||
return BYTESWAP_32(value);
|
||||
}
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
void MacIoTwo::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset & 0xFC) {
|
||||
case MIO_INT_MASK2:
|
||||
this->int_mask |= uint64_t(BYTESWAP_32(value) & ~MACIO_INT_MODE) << 32;
|
||||
@@ -396,38 +348,41 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
clear_cpu_int();
|
||||
break;
|
||||
case MIO_OHARE_ID:
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x", value, offset, ppc_state.pc);
|
||||
LOG_F(ERROR, "%s: write OHARE_ID @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
break;
|
||||
case MIO_OHARE_FEAT_CTRL:
|
||||
LOG_F(WARNING, "%s: write FEAT_CTRL @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
this->feature_control(BYTESWAP_32(value));
|
||||
break;
|
||||
case MIO_AUX_CTRL:
|
||||
LOG_F(9, "write %x to MIO:Aux_Ctrl register", value);
|
||||
LOG_F(9, "%s: write AUX_CTRL @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
this->aux_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "write %x to unknown MIO register at %x", value, offset);
|
||||
break;
|
||||
LOG_F(WARNING, "%s: write @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::feature_control(uint32_t value)
|
||||
{
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register", value);
|
||||
|
||||
void MacIoTwo::feature_control(uint32_t value) {
|
||||
this->feat_ctrl = value;
|
||||
|
||||
if (!(this->feat_ctrl & 1)) {
|
||||
LOG_F(9, "Heathrow: Monitor sense enabled");
|
||||
LOG_F(9, "%s: monitor sense enabled", this->name.c_str());
|
||||
} else {
|
||||
LOG_F(9, "Heathrow: Monitor sense disabled");
|
||||
LOG_F(9, "%s: monitor sense disabled", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
#define INT_TO_IRQ_ID(intx) (1ULL << intx)
|
||||
uint64_t MacIoTwo::register_dev_int(IntSrc src_id) {
|
||||
if (this->device_id == MIO_DEV_ID_OHARE && src_id == ETHERNET) {
|
||||
ABORT_F("%s: attempt to register non-existing Ethernet device int",
|
||||
this->name.c_str());
|
||||
}
|
||||
|
||||
uint64_t HeathrowIC::register_dev_int(IntSrc src_id)
|
||||
{
|
||||
switch (src_id) {
|
||||
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0C);
|
||||
case IntSrc::IDE0 : return INT_TO_IRQ_ID(0x0D); // Beige G3 first IDE controller, or Yosemite ata-3
|
||||
@@ -439,11 +394,23 @@ uint64_t HeathrowIC::register_dev_int(IntSrc src_id)
|
||||
case IntSrc::SWIM3 : return INT_TO_IRQ_ID(0x13);
|
||||
case IntSrc::NMI : return INT_TO_IRQ_ID(0x14); // nmiSource in AppleHeathrow/Heathrow.cpp; programmer-switch in B&W G3
|
||||
|
||||
case IntSrc::BANDIT1 : return INT_TO_IRQ_ID(0x16);
|
||||
case IntSrc::PCI_E : return (this->device_id == MIO_DEV_ID_OHARE)
|
||||
? INT_TO_IRQ_ID(0x16) // same interrupt as bandit
|
||||
: INT_TO_IRQ_ID(0x18); // Lombard GPU
|
||||
case IntSrc::PCI_F : return INT_TO_IRQ_ID(0x18);
|
||||
case IntSrc::PCI_A : return INT_TO_IRQ_ID(0x17);
|
||||
case IntSrc::PCI_B : return (this->device_id == MIO_DEV_ID_OHARE)
|
||||
? INT_TO_IRQ_ID(0x19)
|
||||
: INT_TO_IRQ_ID(0x18);
|
||||
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1A);
|
||||
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1B);
|
||||
case IntSrc::PCI_C : return (this->device_id == MIO_DEV_ID_OHARE)
|
||||
? INT_TO_IRQ_ID(0x1C)
|
||||
: INT_TO_IRQ_ID(0x19);
|
||||
|
||||
case IntSrc::PERCH2 : return INT_TO_IRQ_ID(0x15);
|
||||
case IntSrc::PCI_GPU : return INT_TO_IRQ_ID(0x16);
|
||||
case IntSrc::PCI_A : return INT_TO_IRQ_ID(0x17);
|
||||
case IntSrc::PCI_B : return INT_TO_IRQ_ID(0x18);
|
||||
case IntSrc::PCI_C : return INT_TO_IRQ_ID(0x19);
|
||||
case IntSrc::PERCH1 : return INT_TO_IRQ_ID(0x1A);
|
||||
case IntSrc::PCI_PERCH : return INT_TO_IRQ_ID(0x1C);
|
||||
|
||||
@@ -453,100 +420,66 @@ uint64_t HeathrowIC::register_dev_int(IntSrc src_id)
|
||||
case IntSrc::PCI_J10 : return INT_TO_IRQ_ID(0x18); // Yosemite 64-bit 33MHz slot
|
||||
case IntSrc::PCI_J9 : return INT_TO_IRQ_ID(0x19); // Yosemite 64-bit 33MHz slot
|
||||
case IntSrc::ATA : return INT_TO_IRQ_ID(0x1A); // Yosemite PCI pci-ata
|
||||
case IntSrc::USB : return INT_TO_IRQ_ID(0x1C); // Yosemite PCI usb
|
||||
case IntSrc::USB : return INT_TO_IRQ_ID(0x1C); // Yosemite PCI USB
|
||||
|
||||
case IntSrc::ETHERNET : return INT_TO_IRQ_ID(0x2A);
|
||||
|
||||
default:
|
||||
ABORT_F("Heathrow: unknown interrupt source %d", src_id);
|
||||
ABORT_F("%s: unknown interrupt source %d", this->name.c_str(), src_id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t HeathrowIC::register_dma_int(IntSrc src_id)
|
||||
{
|
||||
uint64_t MacIoTwo::register_dma_int(IntSrc src_id) {
|
||||
if (this->device_id == MIO_DEV_ID_OHARE &&
|
||||
(src_id == IntSrc::DMA_ETHERNET_Tx || src_id == IntSrc::DMA_ETHERNET_Rx)) {
|
||||
ABORT_F("%s: attempt to register non-existing Ethernet DMA int", this->name.c_str());
|
||||
}
|
||||
|
||||
switch (src_id) {
|
||||
case IntSrc::DMA_SCSI_MESH : return INT_TO_IRQ_ID(0x00);
|
||||
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
|
||||
case IntSrc::DMA_IDE0 : return INT_TO_IRQ_ID(0x02);
|
||||
case IntSrc::DMA_IDE1 : return INT_TO_IRQ_ID(0x03);
|
||||
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04);
|
||||
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05);
|
||||
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06);
|
||||
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07);
|
||||
case IntSrc::DMA_DAVBUS_Tx : return INT_TO_IRQ_ID(0x08);
|
||||
case IntSrc::DMA_DAVBUS_Rx : return INT_TO_IRQ_ID(0x09);
|
||||
case IntSrc::DMA_ETHERNET_Tx : return INT_TO_IRQ_ID(0x20);
|
||||
case IntSrc::DMA_ETHERNET_Rx : return INT_TO_IRQ_ID(0x21);
|
||||
default:
|
||||
ABORT_F("Heathrow: unknown DMA interrupt source %d", src_id);
|
||||
return MacIoBase::register_dma_int(src_id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_int_common(uint64_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
// native mode: set IRQ bits in int_events on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events on all transitions
|
||||
#if 0
|
||||
LOG_F(INTERRUPT, "%s: native interrupt events:%08x.%08x levels:%08x.%08x change:%08x.%08x state:%d",
|
||||
this->name.c_str(), uint32_t(this->int_events >> 32), uint32_t(this->int_events), uint32_t(this->int_levels >> 32),
|
||||
uint32_t(this->int_levels), uint32_t(irq_id >> 32), uint32_t(irq_id), irq_line_state
|
||||
);
|
||||
#endif
|
||||
if ((this->int_mask & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels & irq_id))) {
|
||||
this->int_events |= irq_id;
|
||||
} else {
|
||||
this->int_events &= ~irq_id;
|
||||
}
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels |= irq_id;
|
||||
} else {
|
||||
this->int_levels &= ~irq_id;
|
||||
}
|
||||
//===========================================================================
|
||||
static const std::vector<std::string> OHare_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "MeshTnt", "Escc", "Swim3", "Ide0", "Ide1"
|
||||
};
|
||||
|
||||
this->signal_cpu_int();
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_int(uint64_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
this->ack_int_common(irq_id, irq_line_state);
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
this->ack_int_common(irq_id, irq_line_state);
|
||||
}
|
||||
|
||||
void HeathrowIC::signal_cpu_int() {
|
||||
if (this->int_events & this->int_mask) {
|
||||
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()
|
||||
{
|
||||
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
|
||||
this->cpu_int_latch = false;
|
||||
ppc_release_int();
|
||||
LOG_F(5, "Heathrow: CPU INT latch cleared");
|
||||
}
|
||||
}
|
||||
|
||||
static const vector<string> Heathrow_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3", "Ide0", "Ide1",
|
||||
static const std::vector<std::string> Heathrow_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "MeshHeathrow", "Escc", "Swim3", "Ide0", "Ide1",
|
||||
"BigMacHeathrow"
|
||||
};
|
||||
|
||||
static const DeviceDescription Heathrow_Descriptor = {
|
||||
HeathrowIC::create, Heathrow_Subdevices, {}
|
||||
static const std::vector<std::string> Paddington_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "MeshHeathrow", "Escc", "Swim3", "Ide0", "Ide1",
|
||||
"BigMacPaddington"
|
||||
};
|
||||
|
||||
static const DeviceDescription OHare_Descriptor = {
|
||||
MacIoTwo::create_ohare, OHare_Subdevices, {},
|
||||
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
|
||||
};
|
||||
|
||||
static const DeviceDescription Heathrow_Descriptor = {
|
||||
MacIoTwo::create_heathrow, Heathrow_Subdevices, {},
|
||||
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
|
||||
};
|
||||
|
||||
static const DeviceDescription Paddington_Descriptor = {
|
||||
MacIoTwo::create_paddington, Paddington_Subdevices, {},
|
||||
HWCompType::MMIO_DEV | HWCompType::PCI_DEV | HWCompType::INT_CTRL
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(OHare, OHare_Descriptor);
|
||||
REGISTER_DEVICE(Heathrow, Heathrow_Descriptor);
|
||||
REGISTER_DEVICE(Paddington, Paddington_Descriptor);
|
||||
@@ -1,499 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 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/deviceregistry.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <devices/sound/awacs.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace loguru {
|
||||
enum : Verbosity {
|
||||
Verbosity_INTERRUPT = loguru::Verbosity_9,
|
||||
Verbosity_DBDMA = loguru::Verbosity_9
|
||||
};
|
||||
}
|
||||
|
||||
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 = MIO_DEV_ID_OHARE;
|
||||
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"));
|
||||
|
||||
// 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("snd_out"));
|
||||
this->snd_out_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_DAVBUS_Tx));
|
||||
this->snd_codec->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_out_start, this->snd_codec),
|
||||
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
|
||||
);
|
||||
|
||||
// connect SCSI HW and the corresponding DMA channel
|
||||
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("MeshHeathrow"));
|
||||
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh"));
|
||||
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
|
||||
this->mesh_dma->connect(this->mesh);
|
||||
this->mesh->connect(this->mesh_dma.get());
|
||||
|
||||
// connect IDE HW
|
||||
this->ide_0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide0"));
|
||||
//this->ide_1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide1"));
|
||||
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
|
||||
// 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("floppy"));
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
this->floppy_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SWIM3));
|
||||
|
||||
// connect Ethernet HW
|
||||
//this->bmac = dynamic_cast<BigMac*>(gMachineObj->get_comp_by_type(HWCompType::ETHER_MAC));
|
||||
//this->enet_xmit_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacTx"));
|
||||
//this->enet_rcv_dma = std::unique_ptr<DMAChannel> (new DMAChannel("BmacRx"));
|
||||
|
||||
// set EMMO pin status (active low) FIXME: Is there an emmo pin?
|
||||
//this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
|
||||
}
|
||||
|
||||
static const char *get_name_dma(unsigned dma_channel) {
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH : return "DMA_MESH" ;
|
||||
case MIO_OHARE_DMA_FLOPPY : return "DMA_FLOPPY" ;
|
||||
case MIO_OHARE_DMA_ETH_XMIT : return "DMA_ETH_XMIT" ;
|
||||
case MIO_OHARE_DMA_ETH_RCV : return "DMA_ETH_RCV" ;
|
||||
case MIO_OHARE_DMA_ESCC_A_XMIT : return "DMA_ESCC_A_XMIT";
|
||||
case MIO_OHARE_DMA_ESCC_A_RCV : return "DMA_ESCC_A_RCV" ;
|
||||
case MIO_OHARE_DMA_ESCC_B_XMIT : return "DMA_ESCC_B_XMIT";
|
||||
case MIO_OHARE_DMA_ESCC_B_RCV : return "DMA_ESCC_B_RCV" ;
|
||||
case MIO_OHARE_DMA_AUDIO_OUT : return "DMA_AUDIO_OUT" ;
|
||||
case MIO_OHARE_DMA_AUDIO_IN : return "DMA_AUDIO_IN" ;
|
||||
case MIO_OHARE_DMA_IDE0 : return "DMA_IDE0" ;
|
||||
case MIO_OHARE_DMA_IDE1 : return "DMA_IDE1" ;
|
||||
default : return "unknown" ;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
LOG_F(INFO, "%s: base address set to 0x%X", this->get_name().c_str(), this->base_addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OHare::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
uint32_t value;
|
||||
|
||||
LOG_F(9, "%s: read @%x.%c", this->get_name().c_str(),
|
||||
offset, SIZE_ARG(size));
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
value = mio_ctrl_read(offset, size);
|
||||
break;
|
||||
case 8:
|
||||
value = dma_read(offset & 0x7FFF, size);
|
||||
break;
|
||||
case 0x10: // SCSI
|
||||
value = this->mesh->read((offset >> 4) & 0xF);
|
||||
break;
|
||||
case 0x12: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 0x0C) {
|
||||
value = this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
|
||||
break;
|
||||
}
|
||||
if ((offset & 0xFF) < 0x60) {
|
||||
value = 0;
|
||||
LOG_F(ERROR, "%s: ESCC compatible read @%x.%c", this->name.c_str(), offset, SIZE_ARG(size));
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case 0x13: // ESCC MacRISC addressing
|
||||
value = this->escc->read((offset >> 4) & 0xF);
|
||||
break;
|
||||
case 0x14:
|
||||
value = this->snd_codec->snd_ctrl_read(offset & 0xFF, size);
|
||||
break;
|
||||
case 0x15: // SWIM3
|
||||
value = this->swim3->read((offset >> 4) & 0xF);
|
||||
break;
|
||||
case 0x16: // VIA-CUDA
|
||||
case 0x17:
|
||||
value = this->viacuda->read((offset >> 9) & 0xF);
|
||||
break;
|
||||
case 0x20: // IDE 0
|
||||
value = this->ide_0->read((offset >> 4) & 0x1F, size);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
value = this->nvram->read_byte((offset - 0x60000) >> 4);
|
||||
} else {
|
||||
value = 0;
|
||||
LOG_F(WARNING, "%s: read @%x.%c", this->get_name().c_str(),
|
||||
offset, SIZE_ARG(size));
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void OHare::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
LOG_F(9, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
switch (sub_addr) {
|
||||
case 0:
|
||||
this->mio_ctrl_write(offset, value, size);
|
||||
break;
|
||||
case 8:
|
||||
this->dma_write(offset & 0x7FFF, value, size);
|
||||
break;
|
||||
case 0x10: // SCSI
|
||||
this->mesh->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x12: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 0x0C) {
|
||||
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
|
||||
break;
|
||||
}
|
||||
if ((offset & 0xFF) < 0x60) {
|
||||
LOG_F(ERROR, "%s: SCC write @%x.%c = %0*x", this->name.c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case 0x13: // ESCC MacRISC addressing
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x14:
|
||||
this->snd_codec->snd_ctrl_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case 0x15: // SWIM3
|
||||
this->swim3->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x16: // VIA-CUDA
|
||||
case 0x17:
|
||||
this->viacuda->write((offset >> 9) & 0xF, value);
|
||||
break;
|
||||
case 0x20: // IDE 0
|
||||
this->ide_0->write((offset >> 4) & 0x1F, value, size);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: write @%x.%c = %0*x", this->get_name().c_str(),
|
||||
offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OHare::mio_ctrl_read(uint32_t offset, int size) {
|
||||
uint32_t value;
|
||||
|
||||
switch (offset & 0xFC) {
|
||||
case MIO_INT_EVENTS1:
|
||||
value = this->int_events;
|
||||
break;
|
||||
case MIO_INT_MASK1:
|
||||
value = this->int_mask;
|
||||
break;
|
||||
case MIO_INT_LEVELS1:
|
||||
value = this->int_levels;
|
||||
break;
|
||||
case MIO_OHARE_ID: // FIXME: HACK: no clue what this register is supposed to contain
|
||||
value = ~0x00004000; // 1<<14
|
||||
LOG_F(ERROR, "%s: read OHARE_ID @%02x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
break;
|
||||
case MIO_OHARE_FEAT_CTRL:
|
||||
value = this->feat_ctrl;
|
||||
LOG_F(WARNING, "%s: read FEAT_CTRL @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
break;
|
||||
default:
|
||||
value = 0;
|
||||
LOG_F(WARNING, "%s: read @%02x.%c",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size));
|
||||
}
|
||||
|
||||
return BYTESWAP_32(value);
|
||||
}
|
||||
|
||||
void OHare::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset) {
|
||||
case MIO_INT_MASK1:
|
||||
this->int_mask = BYTESWAP_32(value);
|
||||
LOG_F(INTERRUPT, "%s: int_mask:0x%08x", name.c_str(), this->int_mask);
|
||||
this->signal_cpu_int();
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
if ((this->int_mask & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
|
||||
this->int_events = 0;
|
||||
} else {
|
||||
this->int_events &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
|
||||
}
|
||||
clear_cpu_int();
|
||||
break;
|
||||
case MIO_INT_LEVELS1:
|
||||
LOG_F(INTERRUPT, "%s: write INT_LEVELS1 @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value); // writing 0x100000 happens often
|
||||
break;
|
||||
case MIO_OHARE_ID:
|
||||
LOG_F(ERROR, "%s: write OHARE_ID @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
break;
|
||||
case MIO_OHARE_FEAT_CTRL:
|
||||
LOG_F(WARNING, "%s: write FEAT_CTRL @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
this->feature_control(BYTESWAP_32(value));
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: write @%x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OHare::dma_read(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t value;
|
||||
int dma_channel = offset >> 8;
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH:
|
||||
if (this->mesh_dma)
|
||||
value = this->mesh_dma->reg_read(offset & 0xFF, size);
|
||||
else
|
||||
value = 0;
|
||||
break;
|
||||
case MIO_OHARE_DMA_FLOPPY:
|
||||
value = this->floppy_dma->reg_read(offset & 0xFF, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_AUDIO_OUT:
|
||||
value = this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
break;
|
||||
default:
|
||||
if (!(unsupported_dma_channel_read & (1 << dma_channel))) {
|
||||
unsupported_dma_channel_read |= (1 << dma_channel);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s read @%02x.%c", this->name.c_str(),
|
||||
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size));
|
||||
return 0;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void OHare::dma_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int dma_channel = offset >> 8;
|
||||
|
||||
switch (dma_channel) {
|
||||
case MIO_OHARE_DMA_MESH:
|
||||
if (this->mesh_dma) this->mesh_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_FLOPPY:
|
||||
this->floppy_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_AUDIO_OUT:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
if (!(unsupported_dma_channel_write & (1 << dma_channel))) {
|
||||
unsupported_dma_channel_write |= (1 << dma_channel);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel %d %s write @%02x.%c = %0*x", this->name.c_str(),
|
||||
dma_channel, get_name_dma(dma_channel), offset & 0xFF, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OHare::feature_control(const uint32_t value)
|
||||
{
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register", value);
|
||||
|
||||
this->feat_ctrl = value;
|
||||
|
||||
if (!(this->feat_ctrl & 1)) {
|
||||
LOG_F(9, "%s: Monitor sense enabled", this->get_name().c_str());
|
||||
} else {
|
||||
LOG_F(9, "%s: Monitor sense disabled", this->get_name().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
#define INT_TO_IRQ_ID(intx) (1 << intx)
|
||||
|
||||
uint64_t OHare::register_dev_int(IntSrc src_id)
|
||||
{
|
||||
switch (src_id) {
|
||||
case IntSrc::SCSI_MESH : return INT_TO_IRQ_ID(0x0C);
|
||||
case IntSrc::IDE0 : return INT_TO_IRQ_ID(0x0D);
|
||||
// case IntSrc::IDE1 : return INT_TO_IRQ_ID(0x0E);
|
||||
case IntSrc::SCCA : return INT_TO_IRQ_ID(0x0F);
|
||||
case IntSrc::SCCB : return INT_TO_IRQ_ID(0x10);
|
||||
case IntSrc::DAVBUS : return INT_TO_IRQ_ID(0x11);
|
||||
case IntSrc::VIA_CUDA : return INT_TO_IRQ_ID(0x12);
|
||||
case IntSrc::SWIM3 : return INT_TO_IRQ_ID(0x13);
|
||||
// case IntSrc::NMI : return INT_TO_IRQ_ID(0x14);
|
||||
// case IntSrc::EXT1 : return INT_TO_IRQ_ID(0x15);
|
||||
|
||||
case IntSrc::BANDIT1 : return INT_TO_IRQ_ID(0x16);
|
||||
case IntSrc::PCI_E : return INT_TO_IRQ_ID(0x16); // same interrupt as bandit
|
||||
case IntSrc::PCI_A : return INT_TO_IRQ_ID(0x17);
|
||||
case IntSrc::PCI_F : return INT_TO_IRQ_ID(0x18);
|
||||
case IntSrc::PCI_B : return INT_TO_IRQ_ID(0x19);
|
||||
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1A);
|
||||
// case IntSrc::??? : return INT_TO_IRQ_ID(0x1B);
|
||||
case IntSrc::PCI_C : return INT_TO_IRQ_ID(0x1C);
|
||||
|
||||
default:
|
||||
ABORT_F("%s: unknown interrupt source %d", this->name.c_str(), src_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t OHare::register_dma_int(IntSrc src_id)
|
||||
{
|
||||
switch (src_id) {
|
||||
case IntSrc::DMA_SCSI_MESH: return INT_TO_IRQ_ID(0x00);
|
||||
case IntSrc::DMA_SWIM3 : return INT_TO_IRQ_ID(0x01);
|
||||
case IntSrc::DMA_IDE0 : return INT_TO_IRQ_ID(0x02);
|
||||
//
|
||||
case IntSrc::DMA_SCCA_Tx : return INT_TO_IRQ_ID(0x04);
|
||||
case IntSrc::DMA_SCCA_Rx : return INT_TO_IRQ_ID(0x05);
|
||||
case IntSrc::DMA_SCCB_Tx : return INT_TO_IRQ_ID(0x06);
|
||||
case IntSrc::DMA_SCCB_Rx : return INT_TO_IRQ_ID(0x07);
|
||||
case IntSrc::DMA_DAVBUS_Tx: return INT_TO_IRQ_ID(0x08);
|
||||
case IntSrc::DMA_DAVBUS_Rx: return INT_TO_IRQ_ID(0x09);
|
||||
default:
|
||||
ABORT_F("%s: unknown DMA interrupt source %d", this->name.c_str(), src_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OHare::ack_int_common(uint64_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
// native mode: set IRQ bits in int_events on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events on all transitions
|
||||
#if 0
|
||||
LOG_F(INTERRUPT, "%s: native interrupt mask:%08x events:%08x levels:%08x change:%08x state:%d",
|
||||
this->name.c_str(), this->int_mask, this->int_events + 0, this->int_levels + 0, irq_id, irq_line_state
|
||||
);
|
||||
#endif
|
||||
if ((this->int_mask & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels & irq_id))) {
|
||||
this->int_events |= (uint32_t)irq_id;
|
||||
} else {
|
||||
this->int_events &= ~(uint32_t)irq_id;
|
||||
}
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels |= (uint32_t)irq_id;
|
||||
} else {
|
||||
this->int_levels &= ~(uint32_t)irq_id;
|
||||
}
|
||||
|
||||
this->signal_cpu_int();
|
||||
}
|
||||
|
||||
void OHare::ack_int(uint64_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
this->ack_int_common(irq_id, irq_line_state);
|
||||
}
|
||||
|
||||
void OHare::ack_dma_int(uint64_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
this->ack_int_common(irq_id, irq_line_state);
|
||||
}
|
||||
|
||||
void OHare::signal_cpu_int() {
|
||||
if (this->int_events & this->int_mask) {
|
||||
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 OHare::clear_cpu_int()
|
||||
{
|
||||
if (!(this->int_events & this->int_mask) && this->cpu_int_latch) {
|
||||
this->cpu_int_latch = false;
|
||||
ppc_release_int();
|
||||
LOG_F(5, "%s: CPU INT latch cleared", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static const std::vector<std::string> OHare_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "ScsiMesh", "MeshHeathrow", "Escc", "Swim3", "Ide0"
|
||||
};
|
||||
|
||||
static const DeviceDescription OHare_Descriptor = {
|
||||
OHare::create, OHare_Subdevices, {
|
||||
}};
|
||||
|
||||
REGISTER_DEVICE(OHare, OHare_Descriptor);
|
||||
@@ -172,7 +172,7 @@ int AspenCtrl::map_phys_ram() {
|
||||
}
|
||||
|
||||
static const DeviceDescription Aspen_Descriptor = {
|
||||
AspenCtrl::create, {}, {}
|
||||
AspenCtrl::create, {}, {}, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Aspen, Aspen_Descriptor);
|
||||
@@ -170,7 +170,7 @@ void HammerheadCtrl::map_phys_ram()
|
||||
}
|
||||
|
||||
static const DeviceDescription Hammerhead_Descriptor = {
|
||||
HammerheadCtrl::create, {}, {}
|
||||
HammerheadCtrl::create, {}, {}, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Hammerhead, Hammerhead_Descriptor);
|
||||
@@ -101,7 +101,7 @@ namespace Hammerhead {
|
||||
BANK_25_BASE_LSB = 0x4F0,
|
||||
};
|
||||
|
||||
}; // namespace Hammerhead
|
||||
} // namespace Hammerhead
|
||||
|
||||
class HammerheadCtrl : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
@@ -118,15 +118,15 @@ public:
|
||||
|
||||
void set_motherboard_id(const uint8_t val) {
|
||||
this->mb_id = val & 7;
|
||||
};
|
||||
}
|
||||
|
||||
void set_rom_type(const uint8_t val) {
|
||||
this->rom_type = val & 1;
|
||||
};
|
||||
}
|
||||
|
||||
void set_bus_speed(const uint8_t val) {
|
||||
this->bus_speed = val & 7;
|
||||
};
|
||||
}
|
||||
|
||||
void insert_ram_dimm(int slot_num, uint32_t capacity);
|
||||
void map_phys_ram();
|
||||
|
||||
@@ -205,7 +205,7 @@ int HMC::install_ram(uint32_t mb_bank_size, uint32_t bank_a_size, uint32_t bank_
|
||||
}
|
||||
|
||||
static const DeviceDescription Hmc_Descriptor = {
|
||||
HMC::create, {}, {}
|
||||
HMC::create, {}, {}, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(HMC, Hmc_Descriptor);
|
||||
+24
-1
@@ -40,11 +40,34 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/* Control register bit definitions. */
|
||||
enum {
|
||||
HMC_CTRL_BITS = 35, // width of the HMC control register
|
||||
|
||||
HMC_CSIZ = 0, // Cache size inputs
|
||||
HMC_WBRST = 2, // Write-buffer burst clocks
|
||||
HMC_WINIT = 3, // Write-buffer initial clocks
|
||||
HMC_RCASD = 4, // Read CAS duration
|
||||
HMC_RASP = 6, // RAS pre-charge clocks
|
||||
HMC_RASD = 8, // RAS duration
|
||||
HMC_RDAC = 12, // Read data access clocks
|
||||
HMC_WCASD = 14, // Write CAS duration
|
||||
HMC_WCASP = 15, // Write CAS pre-charge
|
||||
HMC_RFSH = 16, // Refresh period
|
||||
HMC_ROMD = 22, // ROM cycle duration
|
||||
HMC_NBLROM = 24, // Nibble ROM
|
||||
HMC_L2_ROMW = 25, // L2 Cache update on ROM write
|
||||
HMC_L2_BRST = 26, // L2 Cache burst clocks
|
||||
HMC_L2_EN = 27, // L2 Cache enable
|
||||
HMC_L2_INST = 28, // L2 Cache instruction only
|
||||
HMC_SIZE = 29, // RAM size
|
||||
HMC_MB_RAM = 31, // Motherboard RAM
|
||||
HMC_VTST = 32, // Video test
|
||||
HMC_VBASE = 33, // Video Base
|
||||
HMC_L2_INIT = 34, // L2 initial access
|
||||
|
||||
HMC_RAM_CFG_POS = 29, // DRAM configuration bits position
|
||||
HMC_VBASE_BIT = 33, // framebuffer base address: 0 - 0x00100000, 1 - 0x0
|
||||
};
|
||||
|
||||
/* Motherboard RAM size constans. */
|
||||
/* Motherboard RAM size constants. */
|
||||
enum {
|
||||
BANK_CFG_128MB = 0, // 12 x 12 address maxtrix (reset config)
|
||||
BANK_CFG_2MB = 1, // 9 x 9 address maxtrix
|
||||
|
||||
@@ -48,22 +48,22 @@ static std::string get_type_str(uint32_t type) {
|
||||
if (str.length())
|
||||
str += ",";
|
||||
str += "ROM";
|
||||
};
|
||||
}
|
||||
if (type & RT_RAM) {
|
||||
if (str.length())
|
||||
str += ",";
|
||||
str += "RAM";
|
||||
};
|
||||
}
|
||||
if (type & RT_MMIO) {
|
||||
if (str.length())
|
||||
str += ",";
|
||||
str += "MMIO";
|
||||
};
|
||||
}
|
||||
if (type & RT_MIRROR) {
|
||||
if (str.length())
|
||||
str += ",";
|
||||
str += "MIRROR";
|
||||
};
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
@@ -317,14 +317,15 @@ static const PropMap Grackle_Properties = {
|
||||
new StrProperty("")},
|
||||
{"pci_C1",
|
||||
new StrProperty("")},
|
||||
{"pci_GPU",
|
||||
new StrProperty("")},
|
||||
//{"pci_GPU",
|
||||
// new StrProperty("")},
|
||||
{"pci_J12",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Grackle_Descriptor = {
|
||||
MPC106::create, {}, Grackle_Properties
|
||||
MPC106::create, {}, Grackle_Properties,
|
||||
HWCompType::MEM_CTRL | HWCompType::MMIO_DEV | HWCompType::PCI_HOST | HWCompType::PCI_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Grackle, Grackle_Descriptor);
|
||||
@@ -86,7 +86,7 @@ PlatinumCtrl::PlatinumCtrl() : MemCtrlBase(), VideoCtrlBase() {
|
||||
|
||||
int PlatinumCtrl::device_postinit() {
|
||||
// attach IOBus Device #2 0xF301B000 ; register DACula with the I/O controller
|
||||
GrandCentral* gc_obj = dynamic_cast<GrandCentral*>(gMachineObj->get_comp_by_name("GrandCentral"));
|
||||
GrandCentral* gc_obj = dynamic_cast<GrandCentral*>(gMachineObj->get_comp_by_name("GrandCentralCatalyst"));
|
||||
gc_obj->attach_iodevice(1, this->dacula.get());
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
@@ -519,12 +519,12 @@ void PlatinumCtrl::enable_display() {
|
||||
break;
|
||||
case 16:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->convert_frame_15bpp_BE(dst_buf, dst_pitch);
|
||||
this->convert_frame_15bpp<BE>(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
case 32:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->convert_frame_32bpp_BE(dst_buf, dst_pitch);
|
||||
this->convert_frame_32bpp<BE>(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
default:
|
||||
@@ -618,7 +618,7 @@ static const PropMap Platinum_Properties = {
|
||||
};
|
||||
|
||||
static const DeviceDescription Platinum_Descriptor = {
|
||||
PlatinumCtrl::create, {}, Platinum_Properties
|
||||
PlatinumCtrl::create, {}, Platinum_Properties, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Platinum, Platinum_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -295,7 +295,7 @@ enum {
|
||||
constexpr auto VRAM_REGION_BASE = 0xF1000000UL;
|
||||
constexpr auto PLATINUM_IOREG_BASE = 0xF8000000UL;
|
||||
|
||||
}; // namespace Platinum
|
||||
} // namespace Platinum
|
||||
|
||||
class PlatinumCtrl : public MemCtrlBase, public VideoCtrlBase, public MMIODevice {
|
||||
public:
|
||||
@@ -307,11 +307,11 @@ public:
|
||||
}
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
int device_postinit() override;
|
||||
|
||||
// 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);
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override;
|
||||
|
||||
void insert_ram_dimm(int slot_num, uint32_t capacity);
|
||||
void map_phys_ram();
|
||||
|
||||
+57
-12
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
PsxCtrl::PsxCtrl(int bridge_num, std::string name)
|
||||
{
|
||||
@@ -75,12 +76,15 @@ void PsxCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int siz
|
||||
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;
|
||||
case PsxReg::Page_Mappings_1:
|
||||
case PsxReg::Page_Mappings_2:
|
||||
case PsxReg::Page_Mappings_3:
|
||||
case PsxReg::Page_Mappings_4:
|
||||
case PsxReg::Page_Mappings_5:
|
||||
LOG_F(INFO, "PSX: write Page Mappings %d @%02x.%c = %0*x",
|
||||
(offset >> 3) - PsxReg::Page_Mappings_1 + 1, offset, SIZE_ARG(size), size * 2, value);
|
||||
this->pages_cfg[(offset >> 3) - PsxReg::Page_Mappings_1] = value;
|
||||
this->map_phys_ram();
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "PSX: write to unsupported/read-only control register at 0x%X", offset);
|
||||
@@ -96,12 +100,15 @@ void PsxCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
|
||||
switch (capacity) {
|
||||
case 0:
|
||||
break;
|
||||
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;
|
||||
this->bank_size[slot_num] = capacity;
|
||||
break;
|
||||
case DRAM_CAP_64MB:
|
||||
this->bank_size[slot_num + 0] = capacity / 2;
|
||||
this->bank_size[slot_num + 1] = capacity / 2;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("PSX: unsupported DRAM capacity %d", capacity);
|
||||
@@ -111,18 +118,56 @@ void PsxCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
|
||||
void PsxCtrl::map_phys_ram()
|
||||
{
|
||||
uint32_t total_ram = 0;
|
||||
uint32_t bank_size_remaining[5];
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
total_ram += this->bank_sizes[i];
|
||||
bank_size_remaining[i] = this->bank_size[i];
|
||||
total_ram += this->bank_size[i];
|
||||
}
|
||||
|
||||
if (!add_ram_region(0x00000000, total_ram)) {
|
||||
ABORT_F("PSX: could not allocate RAM storage");
|
||||
if (!this->dram_ptr) {
|
||||
this->dram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[total_ram]()); /* () intializer clears the memory to zero */
|
||||
if (!this->dram_ptr) {
|
||||
ABORT_F("%s: could not allocate RAM storage", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
ram_map.erase(std::remove_if(ram_map.begin(), ram_map.end(),
|
||||
[this](AddressMapEntry *entry) {
|
||||
delete this->remove_region(entry);
|
||||
return true;
|
||||
}
|
||||
), ram_map.end());
|
||||
|
||||
uint32_t ram_offset = -1;
|
||||
uint32_t mem_start = 0;
|
||||
for (int page = 0; page < 41; page++) {
|
||||
int bank = page >= 40 ? 8 : (this->pages_cfg[page / 8] >> ((page % 8) * 4)) & 15;
|
||||
//LOG_F(INFO, "page:%02d bank:%d", page, bank);
|
||||
if ((ram_offset == -1) == (bank < 5 && bank_size_remaining[bank] > 0)) {
|
||||
if (ram_offset == -1) {
|
||||
ram_offset = page * DRAM_CAP_4MB;
|
||||
//LOG_F(INFO, "ram_offset:%08x", ram_offset);
|
||||
} else {
|
||||
uint32_t mem_size = page * DRAM_CAP_4MB - ram_offset;
|
||||
AddressMapEntry *entry = this->add_ram_region(ram_offset, mem_size, &dram_ptr[mem_start]);
|
||||
mem_start += mem_size;
|
||||
ram_offset = -1;
|
||||
if (entry) {
|
||||
ram_map.push_back(entry);
|
||||
} else {
|
||||
ABORT_F("%s: could not allocate RAM storage", this->name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ram_offset != -1) {
|
||||
bank_size_remaining[bank] -= DRAM_CAP_4MB;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Psx_Descriptor = {
|
||||
PsxCtrl::create, {}, {}
|
||||
PsxCtrl::create, {}, {}, HWCompType::MEM_CTRL | HWCompType::MMIO_DEV
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Psx, Psx_Descriptor);
|
||||
Loaded 100 of 161 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user