mirror of
https://github.com/gopher64/gopher64.git
synced 2026-07-11 09:35:21 +02:00
Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b065f807a2 | |||
| ee95816385 | |||
| d021cb5d32 | |||
| 9819fad475 | |||
| dd767047fd | |||
| f6480ea312 | |||
| e4174c7d4b | |||
| f3d8080a26 | |||
| b581bdcd40 | |||
| 842c81988f | |||
| 45d05cecf0 | |||
| eae81c4623 | |||
| b3f8688ba5 | |||
| 0a10b2c0ba | |||
| be67cb264c | |||
| c6c2187652 | |||
| b2c1d88ea4 | |||
| 80176766a7 | |||
| 7ac6f2adb1 | |||
| 643338e086 | |||
| d9a08f112d | |||
| 344f41cf47 | |||
| 9978e28cc3 | |||
| d3c26fb359 | |||
| cd106345c9 | |||
| f75636f7e5 | |||
| 97e4921b6a | |||
| 21300ab7db | |||
| 8fd7688aa7 | |||
| a013e72fda | |||
| f2812b0434 | |||
| 5f84c18b39 | |||
| 9058cd1715 | |||
| 5d00eccb19 | |||
| e821626f2b | |||
| 63b8b79dd7 | |||
| 90c9bfbf09 | |||
| 9a3a56d0c6 | |||
| e71d5a1b2d | |||
| a731b870da | |||
| c54356e6f4 | |||
| b2d2089d95 | |||
| a47801b9cb | |||
| 9a76bcd303 | |||
| ba6fe1bc05 | |||
| e02add9676 | |||
| 24b464fea4 | |||
| 89673df459 | |||
| 774bb672fd | |||
| f5d4160a5b |
@@ -1,2 +1,5 @@
|
||||
[target.'cfg(target_arch = "x86_64")']
|
||||
rustflags = ["-C", "target-cpu=x86-64-v3"]
|
||||
|
||||
[target.'cfg(target_arch = "aarch64")']
|
||||
rustflags = ["-C", "target-cpu=cortex-a76"]
|
||||
|
||||
+92
-19
@@ -12,64 +12,137 @@ env:
|
||||
jobs:
|
||||
build-linux:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TARGET: x86_64-unknown-linux-gnu
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install sdl2 headers
|
||||
run: |
|
||||
sudo apt -y install libsdl2-dev
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
target: ${{ matrix.target }}
|
||||
rustflags: ""
|
||||
- name: Install SDL2
|
||||
if: matrix.target == 'aarch64-unknown-linux-gnu'
|
||||
run: |
|
||||
cat <<EOF > deb822sources
|
||||
Types: deb
|
||||
URIs: http://archive.ubuntu.com/ubuntu/
|
||||
Suites: noble
|
||||
Components: main multiverse universe
|
||||
Architectures: amd64
|
||||
|
||||
Types: deb
|
||||
URIs: http://security.ubuntu.com/ubuntu/
|
||||
Suites: noble-security
|
||||
Components: main multiverse universe
|
||||
Architectures: amd64
|
||||
|
||||
Types: deb
|
||||
URIs: http://archive.ubuntu.com/ubuntu/
|
||||
Suites: noble-updates
|
||||
Components: main multiverse universe
|
||||
Architectures: amd64
|
||||
|
||||
Types: deb
|
||||
URIs: http://archive.ubuntu.com/ubuntu/
|
||||
Suites: noble-backports
|
||||
Components: main multiverse universe
|
||||
Architectures: amd64
|
||||
|
||||
Types: deb
|
||||
URIs: http://ports.ubuntu.com/
|
||||
Suites: noble
|
||||
Components: main multiverse universe
|
||||
Architectures: arm64
|
||||
|
||||
Types: deb
|
||||
URIs: http://ports.ubuntu.com/
|
||||
Suites: noble-security
|
||||
Components: main multiverse universe
|
||||
Architectures: arm64
|
||||
|
||||
Types: deb
|
||||
URIs: http://ports.ubuntu.com/
|
||||
Suites: noble-updates
|
||||
Components: main multiverse universe
|
||||
Architectures: arm64
|
||||
|
||||
Types: deb
|
||||
URIs: http://ports.ubuntu.com/
|
||||
Suites: noble-backports
|
||||
Components: main multiverse universe
|
||||
Architectures: arm64
|
||||
EOF
|
||||
|
||||
sudo mv deb822sources /etc/apt/sources.list.d/ubuntu.sources
|
||||
sudo dpkg --add-architecture arm64
|
||||
sudo apt-get update
|
||||
sudo apt-get -y dist-upgrade
|
||||
sudo apt-get -y install aptitude
|
||||
sudo aptitude -y install libsdl2-dev:arm64 g++-aarch64-linux-gnu
|
||||
- name: Install SDL2
|
||||
if: matrix.target == 'x86_64-unknown-linux-gnu'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y dist-upgrade
|
||||
sudo apt-get -y install libsdl2-dev
|
||||
- name: Set aarch64 linker
|
||||
if: matrix.target == 'aarch64-unknown-linux-gnu'
|
||||
run: echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
|
||||
- name: Build
|
||||
run: |
|
||||
cargo build --release -v --target=${{ env.TARGET }}
|
||||
cargo build --release -v --target=${{ matrix.target }}
|
||||
- name: Upload file
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gopher64-linux
|
||||
path: target/${{ env.TARGET }}/release/gopher64
|
||||
name: gopher64-${{ matrix.target }}
|
||||
path: target/${{ matrix.target }}/release/gopher64
|
||||
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
env:
|
||||
TARGET: x86_64-pc-windows-msvc
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target: [x86_64-pc-windows-msvc]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
target: ${{ matrix.target }}
|
||||
rustflags: ""
|
||||
- name: Build
|
||||
run: |
|
||||
cargo build --release -v --target=${{ env.TARGET }}
|
||||
cargo build --release -v --target=${{ matrix.target }}
|
||||
- name: Upload file
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gopher64-windows
|
||||
path: target/${{ env.TARGET }}/release/gopher64.exe
|
||||
name: gopher64-${{ matrix.target }}
|
||||
path: target/${{ matrix.target }}/release/gopher64.exe
|
||||
|
||||
build-macos:
|
||||
runs-on: macos-latest
|
||||
env:
|
||||
TARGET: x86_64-apple-darwin
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target: [x86_64-apple-darwin, aarch64-apple-darwin]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
target: ${{ env.TARGET }}
|
||||
target: ${{ matrix.target }}
|
||||
rustflags: ""
|
||||
- name: Build
|
||||
run: |
|
||||
cargo build --release -v --target=${{ env.TARGET }}
|
||||
cargo build --release -v --target=${{ matrix.target }}
|
||||
- name: Upload file
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gopher64-mac
|
||||
path: target/${{ env.TARGET }}/release/gopher64
|
||||
name: gopher64-${{ matrix.target }}
|
||||
path: target/${{ matrix.target }}/release/gopher64
|
||||
|
||||
+7
-3
@@ -1,12 +1,13 @@
|
||||
[package]
|
||||
name = "gopher64"
|
||||
version = "0.1.13"
|
||||
version = "0.1.19"
|
||||
edition = "2021"
|
||||
rust-version = "1.82"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dirs = "5.0"
|
||||
dirs = "6.0"
|
||||
zip = "2.1"
|
||||
governor = "0.8"
|
||||
sevenz-rust = "0.6"
|
||||
@@ -20,6 +21,8 @@ rusttype = "0.9"
|
||||
futures = "0.3"
|
||||
sdl2-sys = "0.37"
|
||||
spin_sleep = "1.3"
|
||||
encoding_rs = "0.8"
|
||||
mimalloc = "0.1"
|
||||
clap = { version = "4.4", features = ["derive"] }
|
||||
|
||||
[dependencies.sdl2]
|
||||
@@ -29,7 +32,8 @@ features = ["static-link","bundled"]
|
||||
|
||||
[build-dependencies]
|
||||
winres = "0.1"
|
||||
cc = { version = "1.0", features = ["parallel"] }
|
||||
bindgen = "0.71"
|
||||
cc = { version = "1.2", features = ["parallel"] }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
@@ -24,6 +24,10 @@ Options:
|
||||
-V, --version
|
||||
Print version
|
||||
```
|
||||
## discord
|
||||
|
||||
There is no dedicated server at this point, but there is a #gopher64 channel on the simple64 server: https://discord.gg/R2cz7S94vD
|
||||
|
||||
## goals
|
||||
|
||||
1. Performance. I want to be able to use this emulator on my laptop.
|
||||
@@ -46,6 +50,10 @@ You can create you own mappings by running `./gopher64 --configure-input-profile
|
||||
|
||||
In order to use a controller (for example, an Xbox controller), run `./gopher64 --list-controllers` to get a list of attached controllers, and then assign it by doing `./gopher64 --assign-controller <controller_number> --port 1`
|
||||
|
||||
## portable mode
|
||||
|
||||
If you would like to keep all the game data in the same folder as executable, you just need to create a file called "portable.txt" in the same directory as the executable.
|
||||
|
||||
## contributing
|
||||
|
||||
I am very open to contributions! Please reach out to me via a GitHub issue, or via discord (loganmc10) before doing substantial work on a PR.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
fn main() {
|
||||
println!("cargo::rerun-if-changed=parallel-rdp");
|
||||
println!("cargo::rerun-if-changed=src/compat");
|
||||
|
||||
let mut simd_build = cc::Build::new();
|
||||
let mut build = cc::Build::new();
|
||||
build
|
||||
.cpp(true)
|
||||
@@ -52,11 +54,15 @@ fn main() {
|
||||
.include("parallel-rdp/parallel-rdp-standalone/util")
|
||||
.includes(std::env::var("DEP_SDL2_INCLUDE"));
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
{
|
||||
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
|
||||
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
||||
if os == "windows" {
|
||||
if arch == "x86_64" {
|
||||
build.flag("/arch:AVX2");
|
||||
} else if arch == "aarch64" {
|
||||
panic!("unsupported platform")
|
||||
} else {
|
||||
panic!("unknown arch")
|
||||
}
|
||||
build.flag("-DVK_USE_PLATFORM_WIN32_KHR");
|
||||
|
||||
@@ -64,14 +70,90 @@ fn main() {
|
||||
.set_icon("data/icon.ico")
|
||||
.compile()
|
||||
.unwrap();
|
||||
}
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
{
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
{
|
||||
} else if os == "linux" || os == "macos" {
|
||||
if arch == "x86_64" {
|
||||
build.flag("-march=x86-64-v3");
|
||||
} else if arch == "aarch64" {
|
||||
build.flag("-march=armv8.2-a");
|
||||
simd_build.flag("-march=armv8.2-a");
|
||||
simd_build.flag("-DSSE2NEON_SUPPRESS_WARNINGS");
|
||||
simd_build.file("src/compat/aarch64.c");
|
||||
} else {
|
||||
panic!("unknown arch")
|
||||
}
|
||||
} else {
|
||||
panic!("unknown OS")
|
||||
}
|
||||
|
||||
build.compile("parallel-rdp");
|
||||
|
||||
let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
|
||||
let parallel_bindings = bindgen::Builder::default()
|
||||
.header("parallel-rdp/interface.hpp")
|
||||
.allowlist_function("rdp_init")
|
||||
.allowlist_function("rdp_close")
|
||||
.allowlist_function("rdp_set_vi_register")
|
||||
.allowlist_function("rdp_update_screen")
|
||||
.allowlist_function("rdp_process_commands")
|
||||
.allowlist_function("rdp_full_sync")
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||
.generate()
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
parallel_bindings
|
||||
.write_to_file(out_path.join("parallel_bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
|
||||
if arch == "aarch64" {
|
||||
let simd_bindings = bindgen::Builder::default()
|
||||
.header("src/compat/sse2neon.h")
|
||||
.allowlist_function("_mm_setzero_si128")
|
||||
.allowlist_function("_mm_set_epi8")
|
||||
.allowlist_function("_mm_movemask_epi8")
|
||||
.allowlist_function("_mm_shuffle_epi8")
|
||||
.allowlist_function("_mm_packs_epi16")
|
||||
.allowlist_function("_mm_set_epi16")
|
||||
.allowlist_function("_mm_cmpeq_epi8")
|
||||
.allowlist_function("_mm_and_si128")
|
||||
.allowlist_function("_mm_set1_epi8")
|
||||
.allowlist_function("_mm_mullo_epi16")
|
||||
.allowlist_function("_mm_cmpeq_epi16")
|
||||
.allowlist_function("_mm_add_epi16")
|
||||
.allowlist_function("_mm_slli_epi16")
|
||||
.allowlist_function("_mm_mulhi_epi16")
|
||||
.allowlist_function("_mm_srai_epi16")
|
||||
.allowlist_function("_mm_andnot_si128")
|
||||
.allowlist_function("_mm_or_si128")
|
||||
.allowlist_function("_mm_mulhi_epu16")
|
||||
.allowlist_function("_mm_sub_epi16")
|
||||
.allowlist_function("_mm_unpacklo_epi16")
|
||||
.allowlist_function("_mm_unpackhi_epi16")
|
||||
.allowlist_function("_mm_packs_epi32")
|
||||
.allowlist_function("_mm_adds_epu16")
|
||||
.allowlist_function("_mm_cmpgt_epi16")
|
||||
.allowlist_function("_mm_blendv_epi8")
|
||||
.allowlist_function("_mm_min_epi16")
|
||||
.allowlist_function("_mm_max_epi16")
|
||||
.allowlist_function("_mm_subs_epi16")
|
||||
.allowlist_function("_mm_adds_epi16")
|
||||
.allowlist_function("_mm_xor_si128")
|
||||
.allowlist_function("_mm_cmplt_epi16")
|
||||
.allowlist_function("_mm_subs_epu16")
|
||||
.allowlist_function("_mm_set1_epi32")
|
||||
.blocklist_type("__m128i")
|
||||
.blocklist_type("int64x2_t")
|
||||
.wrap_static_fns(true)
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||
.generate()
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
simd_bindings
|
||||
.write_to_file(out_path.join("simd_bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
|
||||
simd_build.file(std::env::temp_dir().join("bindgen").join("extern.c"));
|
||||
simd_build.include(".");
|
||||
simd_build.compile("simd");
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+74
-53
@@ -51,6 +51,7 @@ enum vi_registers
|
||||
};
|
||||
|
||||
static bool fullscreen;
|
||||
static bool integer_scaling;
|
||||
static SDL_Window *window;
|
||||
static RDP::CommandProcessor *processor;
|
||||
static SDL_WSIPlatform *wsi_platform;
|
||||
@@ -132,13 +133,48 @@ static const unsigned cmd_len_lut[64] = {
|
||||
1,
|
||||
};
|
||||
|
||||
void rdp_init(void *_window, GFX_INFO _gfx_info, bool _fullscreen)
|
||||
int sdl_event_filter(void *userdata, SDL_Event *event)
|
||||
{
|
||||
if (event->type == SDL_WINDOWEVENT)
|
||||
{
|
||||
switch (event->window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
emu_running = false;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
if (emu_running)
|
||||
{
|
||||
wsi_platform->do_resize();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (fullscreen && event->type == SDL_KEYDOWN)
|
||||
{
|
||||
switch (event->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
emu_running = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rdp_init(void *_window, GFX_INFO _gfx_info, bool _upscale, bool _integer_scaling, bool _fullscreen)
|
||||
{
|
||||
window = (SDL_Window *)_window;
|
||||
SDL_SetEventFilter(sdl_event_filter, nullptr);
|
||||
SDL_AddEventWatch(sdl_event_filter, nullptr);
|
||||
|
||||
gfx_info = _gfx_info;
|
||||
fullscreen = _fullscreen;
|
||||
integer_scaling = _integer_scaling;
|
||||
bool window_vsync = 0;
|
||||
wsi = new WSI;
|
||||
wsi_platform = new SDL_WSIPlatform;
|
||||
@@ -156,6 +192,11 @@ void rdp_init(void *_window, GFX_INFO _gfx_info, bool _fullscreen)
|
||||
rdp_close();
|
||||
}
|
||||
RDP::CommandProcessorFlags flags = 0;
|
||||
if (_upscale)
|
||||
{
|
||||
flags |= RDP::COMMAND_PROCESSOR_FLAG_UPSCALING_2X_BIT;
|
||||
flags |= RDP::COMMAND_PROCESSOR_FLAG_SUPER_SAMPLED_DITHER_BIT;
|
||||
}
|
||||
processor = new RDP::CommandProcessor(wsi->get_device(), gfx_info.RDRAM, 0, gfx_info.RDRAM_SIZE, gfx_info.RDRAM_SIZE / 2, flags);
|
||||
|
||||
if (!processor->device_is_supported())
|
||||
@@ -193,72 +234,52 @@ void rdp_close()
|
||||
}
|
||||
}
|
||||
|
||||
int sdl_event_filter(void *userdata, SDL_Event *event)
|
||||
{
|
||||
if (event->type == SDL_WINDOWEVENT)
|
||||
{
|
||||
switch (event->window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
emu_running = false;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
wsi_platform->do_resize();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (fullscreen && event->type == SDL_KEYDOWN)
|
||||
{
|
||||
switch (event->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
emu_running = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void calculate_viewport(float *x, float *y, float *width, float *height)
|
||||
{
|
||||
bool window_widescreen = false;
|
||||
int32_t display_width = (window_widescreen ? 854 : 640);
|
||||
int32_t display_height = 480;
|
||||
const int32_t display_width = 320;
|
||||
const int32_t display_height = 240;
|
||||
|
||||
int w, h;
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
|
||||
*width = w;
|
||||
*height = h;
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
int32_t hw = display_height * *width;
|
||||
int32_t wh = display_width * *height;
|
||||
if (integer_scaling)
|
||||
{
|
||||
// Integer scaling path
|
||||
int scale_x = w / display_width;
|
||||
int scale_y = h / display_height;
|
||||
int scale = (scale_x < scale_y) ? scale_x : scale_y;
|
||||
if (scale < 1)
|
||||
scale = 1;
|
||||
|
||||
// add letterboxes or pillarboxes if the window has a different aspect ratio
|
||||
// than the current display mode
|
||||
if (hw > wh)
|
||||
{
|
||||
int32_t w_max = wh / display_height;
|
||||
*x += (*width - w_max) / 2;
|
||||
*width = w_max;
|
||||
// Calculate scaled dimensions
|
||||
int scaled_width = display_width * scale;
|
||||
int scaled_height = display_height * scale;
|
||||
|
||||
*width = scaled_width;
|
||||
*height = scaled_height;
|
||||
}
|
||||
else if (hw < wh)
|
||||
else
|
||||
{
|
||||
int32_t h_max = hw / display_width;
|
||||
*y += (*height - h_max) / 2;
|
||||
*height = h_max;
|
||||
// Regular scaling path - maintain aspect ratio
|
||||
float scale_x = w / (float)display_width;
|
||||
float scale_y = h / (float)display_height;
|
||||
float scale = (scale_x < scale_y) ? scale_x : scale_y;
|
||||
|
||||
*width = display_width * scale;
|
||||
*height = display_height * scale;
|
||||
}
|
||||
|
||||
// Center the viewport
|
||||
*x = (w - *width) / 2.0f;
|
||||
*y = (h - *height) / 2.0f;
|
||||
}
|
||||
|
||||
static void render_frame(Vulkan::Device &device)
|
||||
{
|
||||
RDP::ScanoutOptions options = {};
|
||||
options.persist_frame_on_invalid_input = true;
|
||||
options.blend_previous_frame = true;
|
||||
options.upscale_deinterlacing = false;
|
||||
Vulkan::ImageHandle image = processor->scanout(options);
|
||||
|
||||
// Normally reflection is automated.
|
||||
|
||||
@@ -23,13 +23,12 @@ extern "C"
|
||||
uint32_t *VI_WIDTH_REG;
|
||||
} GFX_INFO;
|
||||
|
||||
void rdp_init(void *_window, GFX_INFO _gfx_info, bool fullscreen);
|
||||
void rdp_init(void *_window, GFX_INFO _gfx_info, bool _upscale, bool _integer_scaling, bool _fullscreen);
|
||||
void rdp_close();
|
||||
void rdp_set_vi_register(uint32_t reg, uint32_t value);
|
||||
bool rdp_update_screen();
|
||||
uint64_t rdp_process_commands();
|
||||
void rdp_full_sync();
|
||||
int sdl_event_filter(void *userdata, SDL_Event *event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
#include "src/compat/sse2neon.h"
|
||||
|
||||
// Static wrappers
|
||||
|
||||
__m128i _mm_srli_epi16__extern(__m128i __a, int __imm8) { return _mm_srli_epi16(__a, __imm8); }
|
||||
|
||||
__m128i _mm_insert_epi8__extern(__m128i __a, int __i, const int __imm8)
|
||||
{
|
||||
switch (__imm8)
|
||||
{
|
||||
case 0:
|
||||
return _mm_insert_epi8(__a, __i, 0);
|
||||
case 1:
|
||||
return _mm_insert_epi8(__a, __i, 1);
|
||||
case 2:
|
||||
return _mm_insert_epi8(__a, __i, 2);
|
||||
case 3:
|
||||
return _mm_insert_epi8(__a, __i, 3);
|
||||
case 4:
|
||||
return _mm_insert_epi8(__a, __i, 4);
|
||||
case 5:
|
||||
return _mm_insert_epi8(__a, __i, 5);
|
||||
case 6:
|
||||
return _mm_insert_epi8(__a, __i, 6);
|
||||
case 7:
|
||||
return _mm_insert_epi8(__a, __i, 7);
|
||||
case 8:
|
||||
return _mm_insert_epi8(__a, __i, 8);
|
||||
case 9:
|
||||
return _mm_insert_epi8(__a, __i, 9);
|
||||
case 10:
|
||||
return _mm_insert_epi8(__a, __i, 10);
|
||||
case 11:
|
||||
return _mm_insert_epi8(__a, __i, 11);
|
||||
case 12:
|
||||
return _mm_insert_epi8(__a, __i, 12);
|
||||
case 13:
|
||||
return _mm_insert_epi8(__a, __i, 13);
|
||||
case 14:
|
||||
return _mm_insert_epi8(__a, __i, 14);
|
||||
case 15:
|
||||
return _mm_insert_epi8(__a, __i, 15);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int _mm_extract_epi8__extern(__m128i __a, const int __imm8)
|
||||
{
|
||||
switch (__imm8)
|
||||
{
|
||||
case 0:
|
||||
return _mm_extract_epi8(__a, 0);
|
||||
case 1:
|
||||
return _mm_extract_epi8(__a, 1);
|
||||
case 2:
|
||||
return _mm_extract_epi8(__a, 2);
|
||||
case 3:
|
||||
return _mm_extract_epi8(__a, 3);
|
||||
case 4:
|
||||
return _mm_extract_epi8(__a, 4);
|
||||
case 5:
|
||||
return _mm_extract_epi8(__a, 5);
|
||||
case 6:
|
||||
return _mm_extract_epi8(__a, 6);
|
||||
case 7:
|
||||
return _mm_extract_epi8(__a, 7);
|
||||
case 8:
|
||||
return _mm_extract_epi8(__a, 8);
|
||||
case 9:
|
||||
return _mm_extract_epi8(__a, 9);
|
||||
case 10:
|
||||
return _mm_extract_epi8(__a, 10);
|
||||
case 11:
|
||||
return _mm_extract_epi8(__a, 11);
|
||||
case 12:
|
||||
return _mm_extract_epi8(__a, 12);
|
||||
case 13:
|
||||
return _mm_extract_epi8(__a, 13);
|
||||
case 14:
|
||||
return _mm_extract_epi8(__a, 14);
|
||||
case 15:
|
||||
return _mm_extract_epi8(__a, 15);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
__m128i _mm_insert_epi16__extern(__m128i __a, int __i, const int __imm8)
|
||||
{
|
||||
switch (__imm8)
|
||||
{
|
||||
case 0:
|
||||
return _mm_insert_epi16(__a, __i, 0);
|
||||
case 1:
|
||||
return _mm_insert_epi16(__a, __i, 1);
|
||||
case 2:
|
||||
return _mm_insert_epi16(__a, __i, 2);
|
||||
case 3:
|
||||
return _mm_insert_epi16(__a, __i, 3);
|
||||
case 4:
|
||||
return _mm_insert_epi16(__a, __i, 4);
|
||||
case 5:
|
||||
return _mm_insert_epi16(__a, __i, 5);
|
||||
case 6:
|
||||
return _mm_insert_epi16(__a, __i, 6);
|
||||
case 7:
|
||||
return _mm_insert_epi16(__a, __i, 7);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int _mm_extract_epi16__extern(__m128i __a, const int __imm8)
|
||||
{
|
||||
switch (__imm8)
|
||||
{
|
||||
case 0:
|
||||
return _mm_extract_epi16(__a, 0);
|
||||
case 1:
|
||||
return _mm_extract_epi16(__a, 1);
|
||||
case 2:
|
||||
return _mm_extract_epi16(__a, 2);
|
||||
case 3:
|
||||
return _mm_extract_epi16(__a, 3);
|
||||
case 4:
|
||||
return _mm_extract_epi16(__a, 4);
|
||||
case 5:
|
||||
return _mm_extract_epi16(__a, 5);
|
||||
case 6:
|
||||
return _mm_extract_epi16(__a, 6);
|
||||
case 7:
|
||||
return _mm_extract_epi16(__a, 7);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
__m128i _mm_insert_epi32__extern(__m128i __a, int __i, const int __imm8)
|
||||
{
|
||||
switch (__imm8)
|
||||
{
|
||||
case 0:
|
||||
return _mm_insert_epi32(__a, __i, 0);
|
||||
case 1:
|
||||
return _mm_insert_epi32(__a, __i, 1);
|
||||
case 2:
|
||||
return _mm_insert_epi32(__a, __i, 2);
|
||||
case 3:
|
||||
return _mm_insert_epi32(__a, __i, 3);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int _mm_extract_epi32__extern(__m128i __a, const int __imm8)
|
||||
{
|
||||
switch (__imm8)
|
||||
{
|
||||
case 0:
|
||||
return _mm_extract_epi32(__a, 0);
|
||||
case 1:
|
||||
return _mm_extract_epi32(__a, 1);
|
||||
case 2:
|
||||
return _mm_extract_epi32(__a, 2);
|
||||
case 3:
|
||||
return _mm_extract_epi32(__a, 3);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
__m128i _mm_insert_epi64__extern(__m128i __a, int64_t __i, const int __imm8)
|
||||
{
|
||||
switch (__imm8)
|
||||
{
|
||||
case 0:
|
||||
return _mm_insert_epi64(__a, __i, 0);
|
||||
case 1:
|
||||
return _mm_insert_epi64(__a, __i, 1);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int64_t _mm_extract_epi64__extern(__m128i __a, const int __imm8)
|
||||
{
|
||||
switch (__imm8)
|
||||
{
|
||||
case 0:
|
||||
return _mm_extract_epi64(__a, 0);
|
||||
case 1:
|
||||
return _mm_extract_epi64(__a, 1);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
unsafe extern "C" {
|
||||
#[link_name = "_mm_srli_epi16__extern"]
|
||||
pub fn _mm_srli_epi16(__a: __m128i, __imm8: ::std::os::raw::c_int) -> __m128i;
|
||||
|
||||
#[link_name = "_mm_insert_epi8__extern"]
|
||||
pub fn _mm_insert_epi8(
|
||||
__a: __m128i,
|
||||
__i: ::std::os::raw::c_int,
|
||||
__imm8: ::std::os::raw::c_int,
|
||||
) -> __m128i;
|
||||
|
||||
#[link_name = "_mm_extract_epi8__extern"]
|
||||
pub fn _mm_extract_epi8(__a: __m128i, __imm8: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
|
||||
|
||||
#[link_name = "_mm_insert_epi16__extern"]
|
||||
pub fn _mm_insert_epi16(
|
||||
__a: __m128i,
|
||||
__i: ::std::os::raw::c_int,
|
||||
__imm8: ::std::os::raw::c_int,
|
||||
) -> __m128i;
|
||||
|
||||
#[link_name = "_mm_extract_epi16__extern"]
|
||||
pub fn _mm_extract_epi16(__a: __m128i, __imm8: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
|
||||
|
||||
#[link_name = "_mm_insert_epi32__extern"]
|
||||
pub fn _mm_insert_epi32(
|
||||
__a: __m128i,
|
||||
__i: ::std::os::raw::c_int,
|
||||
__imm8: ::std::os::raw::c_int,
|
||||
) -> __m128i;
|
||||
|
||||
#[link_name = "_mm_extract_epi32__extern"]
|
||||
pub fn _mm_extract_epi32(__a: __m128i, __imm8: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
|
||||
|
||||
#[link_name = "_mm_insert_epi64__extern"]
|
||||
pub fn _mm_insert_epi64(
|
||||
__a: __m128i,
|
||||
__i: ::std::os::raw::c_longlong,
|
||||
__imm8: ::std::os::raw::c_int,
|
||||
) -> __m128i;
|
||||
|
||||
#[link_name = "_mm_extract_epi64__extern"]
|
||||
pub fn _mm_extract_epi64(
|
||||
__a: __m128i,
|
||||
__imm8: ::std::os::raw::c_int,
|
||||
) -> ::std::os::raw::c_longlong;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+52
-16
@@ -1,4 +1,17 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
#[derive(Copy, Clone)]
|
||||
#[allow(dead_code)]
|
||||
pub struct __m128i(std::arch::aarch64::int64x2_t);
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
include!(concat!(env!("OUT_DIR"), "/simd_bindings.rs"));
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use std::arch::x86_64::*;
|
||||
|
||||
use crate::ui;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
|
||||
@@ -17,7 +30,6 @@ pub mod exceptions;
|
||||
pub mod fpu_instructions;
|
||||
pub mod is_viewer;
|
||||
pub mod memory;
|
||||
pub mod mempak;
|
||||
pub mod mi;
|
||||
pub mod pi;
|
||||
pub mod pif;
|
||||
@@ -34,7 +46,12 @@ pub mod tlb;
|
||||
pub mod unmapped;
|
||||
pub mod vi;
|
||||
|
||||
pub fn run_game(file_path: &std::path::Path, device: &mut Device, fullscreen: bool) {
|
||||
pub fn run_game(
|
||||
file_path: &std::path::Path,
|
||||
data_dir: std::path::PathBuf,
|
||||
device: &mut Device,
|
||||
fullscreen: bool,
|
||||
) {
|
||||
let rom_contents = get_rom_contents(file_path);
|
||||
|
||||
cart_rom::init(device, rom_contents); // cart needs to come before rdram
|
||||
@@ -48,13 +65,16 @@ pub fn run_game(file_path: &std::path::Path, device: &mut Device, fullscreen: bo
|
||||
|
||||
mi::init(device);
|
||||
pif::init(device);
|
||||
if device.ui.config.input.emulate_vru {
|
||||
controller::vru::init(device);
|
||||
}
|
||||
memory::init(device);
|
||||
rsp_interface::init(device);
|
||||
rdp::init(device);
|
||||
vi::init(device);
|
||||
cpu::init(device);
|
||||
|
||||
ui::storage::init(&mut device.ui);
|
||||
ui::storage::init(&mut device.ui, data_dir);
|
||||
ui::storage::load_saves(&mut device.ui);
|
||||
cart_rom::load_rom_save(device);
|
||||
|
||||
@@ -157,10 +177,11 @@ pub struct Device {
|
||||
si: si::Si,
|
||||
ri: ri::Ri,
|
||||
flashram: sram::Flashram,
|
||||
pub vru: controller::vru::Vru,
|
||||
}
|
||||
|
||||
impl Device {
|
||||
pub fn new() -> Device {
|
||||
pub fn new(config_dir: std::path::PathBuf) -> Device {
|
||||
let mut byte_swap: usize = 0;
|
||||
let test: [u8; 4] = [1, 2, 3, 4];
|
||||
// if the host computer is little endian, that means the RDRAM will be stored as little endian
|
||||
@@ -169,7 +190,7 @@ impl Device {
|
||||
byte_swap = 3;
|
||||
}
|
||||
Device {
|
||||
ui: ui::Ui::new(),
|
||||
ui: ui::Ui::new(config_dir),
|
||||
byte_swap,
|
||||
cpu: cpu::Cpu {
|
||||
cop0: cop0::Cop0 {
|
||||
@@ -217,7 +238,8 @@ impl Device {
|
||||
cop1: cop1::Cop1 {
|
||||
fcr0: 0,
|
||||
fcr31: 0,
|
||||
flush_mode: 0,
|
||||
//#[cfg(target_arch = "x86_64")]
|
||||
//flush_mode: 0,
|
||||
fgr32: [[0; 4]; 32],
|
||||
fgr64: [[0; 8]; 32],
|
||||
instrs: [cop1::reserved; 32],
|
||||
@@ -264,6 +286,7 @@ impl Device {
|
||||
rx_buf: None,
|
||||
process: None,
|
||||
pak_handler: None,
|
||||
change_pak: controller::PakType::None,
|
||||
}; 5],
|
||||
},
|
||||
cart: cart_rom::Cart {
|
||||
@@ -317,21 +340,21 @@ impl Device {
|
||||
sync_point: false,
|
||||
cycle_counter: 0,
|
||||
gpr: [0; 32],
|
||||
vpr: [0; 32],
|
||||
vpr: unsafe { [_mm_setzero_si128(); 32] },
|
||||
reciprocals: [0; 512],
|
||||
inverse_square_roots: [0; 512],
|
||||
divdp: false,
|
||||
divin: 0,
|
||||
divout: 0,
|
||||
shuffle: unsafe { [std::arch::x86_64::_mm_setzero_si128(); 16] },
|
||||
vcol: unsafe { std::arch::x86_64::_mm_setzero_si128() },
|
||||
vcoh: unsafe { std::arch::x86_64::_mm_setzero_si128() },
|
||||
vccl: unsafe { std::arch::x86_64::_mm_setzero_si128() },
|
||||
vcch: unsafe { std::arch::x86_64::_mm_setzero_si128() },
|
||||
vce: unsafe { std::arch::x86_64::_mm_setzero_si128() },
|
||||
accl: unsafe { std::arch::x86_64::_mm_setzero_si128() },
|
||||
accm: unsafe { std::arch::x86_64::_mm_setzero_si128() },
|
||||
acch: unsafe { std::arch::x86_64::_mm_setzero_si128() },
|
||||
shuffle: unsafe { [_mm_setzero_si128(); 16] },
|
||||
vcol: unsafe { _mm_setzero_si128() },
|
||||
vcoh: unsafe { _mm_setzero_si128() },
|
||||
vccl: unsafe { _mm_setzero_si128() },
|
||||
vcch: unsafe { _mm_setzero_si128() },
|
||||
vce: unsafe { _mm_setzero_si128() },
|
||||
accl: unsafe { _mm_setzero_si128() },
|
||||
accm: unsafe { _mm_setzero_si128() },
|
||||
acch: unsafe { _mm_setzero_si128() },
|
||||
special_instrs: [rsp_su_instructions::reserved; 64],
|
||||
regimm_instrs: [rsp_su_instructions::reserved; 32],
|
||||
cop0_instrs: [rsp_su_instructions::reserved; 32],
|
||||
@@ -395,6 +418,19 @@ impl Device {
|
||||
silicon_id: [sram::FLASHRAM_TYPE_ID, sram::MX29L1100_ID],
|
||||
mode: sram::FlashramMode::ReadArray,
|
||||
},
|
||||
vru: controller::vru::Vru {
|
||||
status: 0,
|
||||
voice_state: 0,
|
||||
load_offset: 0,
|
||||
voice_init: 0,
|
||||
word_buffer: [0; 40],
|
||||
words: Vec::new(),
|
||||
talking: false,
|
||||
word_mappings: HashMap::new(),
|
||||
window_notifier: None,
|
||||
word_receiver: None,
|
||||
gui_ctx: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -1,16 +1,16 @@
|
||||
use crate::device;
|
||||
use crate::ui;
|
||||
|
||||
pub const AI_DRAM_ADDR_REG: u32 = 0;
|
||||
pub const AI_LEN_REG: u32 = 1;
|
||||
//pub const AI_CONTROL_REG: u32 = 2;
|
||||
pub const AI_STATUS_REG: u32 = 3;
|
||||
pub const AI_DACRATE_REG: u32 = 4;
|
||||
//pub const AI_BITRATE_REG: u32 = 5;
|
||||
const AI_DRAM_ADDR_REG: u32 = 0;
|
||||
const AI_LEN_REG: u32 = 1;
|
||||
// const AI_CONTROL_REG: u32 = 2;
|
||||
const AI_STATUS_REG: u32 = 3;
|
||||
const AI_DACRATE_REG: u32 = 4;
|
||||
// const AI_BITRATE_REG: u32 = 5;
|
||||
pub const AI_REGS_COUNT: u32 = 6;
|
||||
|
||||
pub const AI_STATUS_BUSY: u32 = 0x40000000;
|
||||
pub const AI_STATUS_FULL: u32 = 0x80000000;
|
||||
const AI_STATUS_BUSY: u32 = 0x40000000;
|
||||
const AI_STATUS_FULL: u32 = 0x80000000;
|
||||
|
||||
pub struct Ai {
|
||||
pub regs: [u32; AI_REGS_COUNT as usize],
|
||||
|
||||
+12
-12
@@ -4,19 +4,19 @@ use chrono::Timelike;
|
||||
use crate::device;
|
||||
use crate::ui;
|
||||
|
||||
pub const JCMD_STATUS: u8 = 0x00;
|
||||
pub const JCMD_EEPROM_READ: u8 = 0x04;
|
||||
pub const JCMD_EEPROM_WRITE: u8 = 0x05;
|
||||
pub const JCMD_AF_RTC_STATUS: u8 = 0x06;
|
||||
pub const JCMD_AF_RTC_READ: u8 = 0x07;
|
||||
pub const JCMD_AF_RTC_WRITE: u8 = 0x08;
|
||||
pub const JCMD_RESET: u8 = 0xff;
|
||||
const JCMD_STATUS: u8 = 0x00;
|
||||
const JCMD_EEPROM_READ: u8 = 0x04;
|
||||
const JCMD_EEPROM_WRITE: u8 = 0x05;
|
||||
const JCMD_AF_RTC_STATUS: u8 = 0x06;
|
||||
const JCMD_AF_RTC_READ: u8 = 0x07;
|
||||
const JCMD_AF_RTC_WRITE: u8 = 0x08;
|
||||
const JCMD_RESET: u8 = 0xff;
|
||||
|
||||
pub const JDT_AF_RTC: u16 = 0x1000; /* RTC */
|
||||
pub const JDT_EEPROM_4K: u16 = 0x8000; /* 4k EEPROM */
|
||||
pub const JDT_EEPROM_16K: u16 = 0xc000; /* 16k EEPROM */
|
||||
pub const EEPROM_BLOCK_SIZE: usize = 8;
|
||||
pub const EEPROM_MAX_SIZE: usize = 0x800;
|
||||
const JDT_AF_RTC: u16 = 0x1000; /* RTC */
|
||||
const JDT_EEPROM_4K: u16 = 0x8000; /* 4k EEPROM */
|
||||
const JDT_EEPROM_16K: u16 = 0xc000; /* 16k EEPROM */
|
||||
const EEPROM_BLOCK_SIZE: usize = 8;
|
||||
const EEPROM_MAX_SIZE: usize = 0x800;
|
||||
|
||||
pub struct AfRtc {
|
||||
pub control: u16,
|
||||
|
||||
@@ -10,7 +10,7 @@ pub enum CicType {
|
||||
CicNus5167,
|
||||
}
|
||||
|
||||
pub const CART_MASK: usize = 0xFFFFFFF;
|
||||
const CART_MASK: usize = 0xFFFFFFF;
|
||||
pub struct Cart {
|
||||
pub rom: Vec<u8>,
|
||||
pub is_viewer_buffer: [u8; 0xFFFF],
|
||||
|
||||
+70
-22
@@ -1,31 +1,37 @@
|
||||
use crate::device;
|
||||
use crate::ui;
|
||||
|
||||
pub mod mempak;
|
||||
pub mod rumble;
|
||||
pub mod vru;
|
||||
|
||||
pub const JCMD_STATUS: u8 = 0x00;
|
||||
pub const JCMD_CONTROLLER_READ: u8 = 0x01;
|
||||
pub const JCMD_PAK_READ: u8 = 0x02;
|
||||
pub const JCMD_PAK_WRITE: u8 = 0x03;
|
||||
//pub const JCMD_VRU_READ: u8 = 0x09;
|
||||
//pub const JCMD_VRU_WRITE: u8 = 0x0A;
|
||||
//pub const JCMD_VRU_READ_STATUS: u8 = 0x0B;
|
||||
//pub const JCMD_VRU_WRITE_CONFIG: u8 = 0x0C;
|
||||
//pub const JCMD_VRU_WRITE_INIT: u8 = 0x0D;
|
||||
const JCMD_PAK_READ: u8 = 0x02;
|
||||
const JCMD_PAK_WRITE: u8 = 0x03;
|
||||
pub const JCMD_RESET: u8 = 0xff;
|
||||
|
||||
//pub const JDT_NONE: u16 = 0x0000;
|
||||
pub const JDT_JOY_ABS_COUNTERS: u16 = 0x0001; /* joystick with absolute coordinates */
|
||||
//pub const JDT_JOY_REL_COUNTERS: u16 = 0x0002; /* joystick with relative coordinates (= mouse) */
|
||||
pub const JDT_JOY_PORT: u16 = 0x0004; /* has port for external paks */
|
||||
//pub const JDT_VRU: u16 = 0x0100; /* VRU */
|
||||
pub const PAK_CHUNK_SIZE: usize = 0x20;
|
||||
pub const CONT_STATUS_PAK_NOT_PRESENT: u8 = 0;
|
||||
pub const CONT_STATUS_PAK_PRESENT: u8 = 1;
|
||||
pub const CONT_FLAVOR: u16 = JDT_JOY_ABS_COUNTERS | JDT_JOY_PORT;
|
||||
//const JDT_NONE: u16 = 0x0000;
|
||||
const JDT_JOY_ABS_COUNTERS: u16 = 0x0001; /* joystick with absolute coordinates */
|
||||
//const JDT_JOY_REL_COUNTERS: u16 = 0x0002; /* joystick with relative coordinates (= mouse) */
|
||||
const JDT_JOY_PORT: u16 = 0x0004; /* has port for external paks */
|
||||
const PAK_CHUNK_SIZE: usize = 0x20;
|
||||
const CONT_STATUS_PAK_PRESENT: u8 = 1;
|
||||
const CONT_STATUS_PAK_NOT_PRESENT: u8 = 2;
|
||||
const CONT_FLAVOR: u16 = JDT_JOY_ABS_COUNTERS | JDT_JOY_PORT;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum PakType {
|
||||
None = 0,
|
||||
MemPak = 1,
|
||||
RumblePak = 2,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PakHandler {
|
||||
pub read: fn(&mut device::Device, usize, u16, usize, usize),
|
||||
pub write: fn(&mut device::Device, usize, u16, usize, usize),
|
||||
pub pak_type: PakType,
|
||||
}
|
||||
|
||||
pub fn process(device: &mut device::Device, channel: usize) {
|
||||
@@ -47,7 +53,23 @@ pub fn process(device: &mut device::Device, channel: usize) {
|
||||
JCMD_CONTROLLER_READ => {
|
||||
let offset = device.pif.channels[channel].rx_buf.unwrap();
|
||||
let input = ui::input::get(&mut device.ui, channel);
|
||||
device.pif.ram[offset..offset + 4].copy_from_slice(&input.to_ne_bytes());
|
||||
device.pif.ram[offset..offset + 4].copy_from_slice(&input.0.to_ne_bytes());
|
||||
if input.1 {
|
||||
// pak change button pressed
|
||||
if device::events::get_event(device, device::events::EventType::PakSwitch).is_none()
|
||||
{
|
||||
device.pif.channels[channel].change_pak =
|
||||
device.pif.channels[channel].pak_handler.unwrap().pak_type;
|
||||
device.pif.channels[channel].pak_handler = None;
|
||||
device::events::create_event(
|
||||
device,
|
||||
device::events::EventType::PakSwitch,
|
||||
device.cpu.cop0.regs[device::cop0::COP0_COUNT_REG as usize]
|
||||
+ (device.cpu.clock_rate), // 1 second
|
||||
pak_switch_event,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
JCMD_PAK_READ => pak_read_block(
|
||||
device,
|
||||
@@ -80,9 +102,9 @@ pub fn pak_read_block(
|
||||
|
||||
if handler.is_some() {
|
||||
(handler.unwrap().read)(device, channel, address, data, PAK_CHUNK_SIZE);
|
||||
device.pif.ram[dcrc] = pak_data_crc(device, data, PAK_CHUNK_SIZE)
|
||||
device.pif.ram[dcrc] = data_crc(device, data, PAK_CHUNK_SIZE)
|
||||
} else {
|
||||
device.pif.ram[dcrc] = !pak_data_crc(device, data, PAK_CHUNK_SIZE)
|
||||
device.pif.ram[dcrc] = !data_crc(device, data, PAK_CHUNK_SIZE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,13 +121,13 @@ pub fn pak_write_block(
|
||||
|
||||
if handler.is_some() {
|
||||
(handler.unwrap().write)(device, channel, address, data, PAK_CHUNK_SIZE);
|
||||
device.pif.ram[dcrc] = pak_data_crc(device, data, PAK_CHUNK_SIZE)
|
||||
device.pif.ram[dcrc] = data_crc(device, data, PAK_CHUNK_SIZE)
|
||||
} else {
|
||||
device.pif.ram[dcrc] = !pak_data_crc(device, data, PAK_CHUNK_SIZE)
|
||||
device.pif.ram[dcrc] = !data_crc(device, data, PAK_CHUNK_SIZE)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pak_data_crc(device: &device::Device, data_offset: usize, size: usize) -> u8 {
|
||||
pub fn data_crc(device: &device::Device, data_offset: usize, size: usize) -> u8 {
|
||||
let mut i = 0;
|
||||
let mut crc = 0;
|
||||
|
||||
@@ -124,3 +146,29 @@ pub fn pak_data_crc(device: &device::Device, data_offset: usize, size: usize) ->
|
||||
}
|
||||
crc
|
||||
}
|
||||
|
||||
pub fn pak_switch_event(device: &mut device::Device) {
|
||||
for (i, channel) in device.pif.channels.iter_mut().enumerate() {
|
||||
if channel.change_pak != PakType::None {
|
||||
if channel.change_pak == PakType::RumblePak {
|
||||
device::ui::input::set_rumble(&mut device.ui, i, 0);
|
||||
let handler = device::controller::PakHandler {
|
||||
read: device::controller::mempak::read,
|
||||
write: device::controller::mempak::write,
|
||||
pak_type: device::controller::PakType::MemPak,
|
||||
};
|
||||
channel.pak_handler = Some(handler);
|
||||
ui::audio::play_pak_switch(&mut device.ui, PakType::MemPak);
|
||||
} else if channel.change_pak == PakType::MemPak {
|
||||
let handler = device::controller::PakHandler {
|
||||
read: device::controller::rumble::read,
|
||||
write: device::controller::rumble::write,
|
||||
pak_type: device::controller::PakType::RumblePak,
|
||||
};
|
||||
channel.pak_handler = Some(handler);
|
||||
ui::audio::play_pak_switch(&mut device.ui, PakType::RumblePak);
|
||||
}
|
||||
channel.change_pak = PakType::None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::device;
|
||||
|
||||
pub const MEMPAK_SIZE: usize = 0x8000;
|
||||
pub const MPK_PAGE_SIZE: usize = 256;
|
||||
const MEMPAK_SIZE: usize = 0x8000;
|
||||
const MPK_PAGE_SIZE: usize = 256;
|
||||
|
||||
pub fn format_mempak(device: &mut device::Device) {
|
||||
if device.ui.saves.mempak.0.len() < MEMPAK_SIZE * 4 {
|
||||
@@ -0,0 +1,20 @@
|
||||
use crate::device;
|
||||
|
||||
pub fn read(device: &mut device::Device, _channel: usize, address: u16, data: usize, size: usize) {
|
||||
let value: u8 = if (0x8000..0x9000).contains(&address) {
|
||||
0x80
|
||||
} else {
|
||||
0x00
|
||||
};
|
||||
|
||||
for i in 0..size {
|
||||
device.pif.ram[data + i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(device: &mut device::Device, channel: usize, address: u16, data: usize, size: usize) {
|
||||
if address == 0xc000 {
|
||||
let rumble = device.pif.ram[data + size - 1];
|
||||
device::ui::input::set_rumble(&mut device.ui, channel, rumble);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+22
-22
@@ -1,37 +1,37 @@
|
||||
use crate::device;
|
||||
|
||||
pub const COP0_INDEX_REG: u32 = 0;
|
||||
pub const COP0_RANDOM_REG: u32 = 1;
|
||||
const COP0_RANDOM_REG: u32 = 1;
|
||||
pub const COP0_ENTRYLO0_REG: u32 = 2;
|
||||
pub const COP0_ENTRYLO1_REG: u32 = 3;
|
||||
pub const COP0_CONTEXT_REG: u32 = 4;
|
||||
pub const COP0_PAGEMASK_REG: u32 = 5;
|
||||
pub const COP0_WIRED_REG: u32 = 6;
|
||||
//pub const COP0_UNUSED_7: u32 = 7;
|
||||
const COP0_WIRED_REG: u32 = 6;
|
||||
//const COP0_UNUSED_7: u32 = 7;
|
||||
pub const COP0_BADVADDR_REG: u32 = 8;
|
||||
pub const COP0_COUNT_REG: u32 = 9;
|
||||
pub const COP0_ENTRYHI_REG: u32 = 10;
|
||||
pub const COP0_COMPARE_REG: u32 = 11;
|
||||
const COP0_COMPARE_REG: u32 = 11;
|
||||
pub const COP0_STATUS_REG: u32 = 12;
|
||||
pub const COP0_CAUSE_REG: u32 = 13;
|
||||
pub const COP0_EPC_REG: u32 = 14;
|
||||
pub const COP0_PREVID_REG: u32 = 15;
|
||||
pub const COP0_CONFIG_REG: u32 = 16;
|
||||
const COP0_PREVID_REG: u32 = 15;
|
||||
const COP0_CONFIG_REG: u32 = 16;
|
||||
pub const COP0_LLADDR_REG: u32 = 17;
|
||||
//pub const COP0_WATCHLO_REG: u32 = 18;
|
||||
//pub const COP0_WATCHHI_REG: u32 = 19;
|
||||
//const COP0_WATCHLO_REG: u32 = 18;
|
||||
//const COP0_WATCHHI_REG: u32 = 19;
|
||||
pub const COP0_XCONTEXT_REG: u32 = 20;
|
||||
//pub const COP0_UNUSED_21: u32 = 21;
|
||||
//pub const COP0_UNUSED_22: u32 = 22;
|
||||
//pub const COP0_UNUSED_23: u32 = 23;
|
||||
//pub const COP0_UNUSED_24: u32 = 24;
|
||||
//pub const COP0_UNUSED_25: u32 = 25;
|
||||
//pub const COP0_PARITYERR_REG: u32 = 26;
|
||||
//pub const COP0_CACHEERR_REG: u32 = 27;
|
||||
//const COP0_UNUSED_21: u32 = 21;
|
||||
//const COP0_UNUSED_22: u32 = 22;
|
||||
//const COP0_UNUSED_23: u32 = 23;
|
||||
//const COP0_UNUSED_24: u32 = 24;
|
||||
//const COP0_UNUSED_25: u32 = 25;
|
||||
//const COP0_PARITYERR_REG: u32 = 26;
|
||||
//const COP0_CACHEERR_REG: u32 = 27;
|
||||
pub const COP0_TAGLO_REG: u32 = 28;
|
||||
//pub const COP0_TAGHI_REG: u32 = 29;
|
||||
pub const COP0_ERROREPC_REG: u32 = 30;
|
||||
//pub const COP0_UNUSED_31: u32 = 31;
|
||||
//const COP0_TAGHI_REG: u32 = 29;
|
||||
const COP0_ERROREPC_REG: u32 = 30;
|
||||
//const COP0_UNUSED_31: u32 = 31;
|
||||
pub const COP0_REGS_COUNT: u32 = 32;
|
||||
|
||||
pub const COP0_STATUS_IE: u64 = 1 << 0;
|
||||
@@ -42,12 +42,12 @@ pub const COP0_STATUS_FR: u64 = 1 << 26;
|
||||
pub const COP0_STATUS_CU1: u64 = 1 << 29;
|
||||
pub const COP0_STATUS_CU2: u64 = 1 << 30;
|
||||
|
||||
//pub const COP0_CAUSE_EXCCODE_INTR: u64 = 0 << 2;
|
||||
//const COP0_CAUSE_EXCCODE_INTR: u64 = 0 << 2;
|
||||
pub const COP0_CAUSE_EXCCODE_MOD: u64 = 1 << 2;
|
||||
pub const COP0_CAUSE_EXCCODE_TLBL: u64 = 2 << 2;
|
||||
pub const COP0_CAUSE_EXCCODE_TLBS: u64 = 3 << 2;
|
||||
//pub const COP0_CAUSE_EXCCODE_ADEL: u64 = 4 << 2;
|
||||
//pub const COP0_CAUSE_EXCCODE_ADES: u64 = 5 << 2;
|
||||
//const COP0_CAUSE_EXCCODE_ADEL: u64 = 4 << 2;
|
||||
//const COP0_CAUSE_EXCCODE_ADES: u64 = 5 << 2;
|
||||
pub const COP0_CAUSE_EXCCODE_SYS: u64 = 8 << 2;
|
||||
pub const COP0_CAUSE_EXCCODE_BP: u64 = 9 << 2;
|
||||
pub const COP0_CAUSE_EXCCODE_RI: u64 = 10 << 2;
|
||||
@@ -55,7 +55,7 @@ pub const COP0_CAUSE_EXCCODE_CPU: u64 = 11 << 2;
|
||||
pub const COP0_CAUSE_EXCCODE_TR: u64 = 13 << 2;
|
||||
pub const COP0_CAUSE_EXCCODE_FPE: u64 = 15 << 2;
|
||||
pub const COP0_CAUSE_IP2: u64 = 1 << 10;
|
||||
pub const COP0_CAUSE_IP7: u64 = 1 << 15;
|
||||
const COP0_CAUSE_IP7: u64 = 1 << 15;
|
||||
pub const COP0_CAUSE_BD: u64 = 1 << 31;
|
||||
|
||||
pub const COP0_CAUSE_CE1: u64 = 1 << 28;
|
||||
|
||||
+30
-24
@@ -1,32 +1,34 @@
|
||||
use crate::device;
|
||||
|
||||
//pub const FCR31_FLAG_INEXACT_BIT: u32 = 1 << 2;
|
||||
//pub const FCR31_FLAG_UNDERFLOW_BIT: u32 = 1 << 3;
|
||||
//pub const FCR31_FLAG_OVERFLOW_BIT: u32 = 1 << 4;
|
||||
//pub const FCR31_FLAG_DIVBYZERO_BIT: u32 = 1 << 5;
|
||||
//pub const FCR31_FLAG_INVALID_BIT: u32 = 1 << 6;
|
||||
//pub const FCR31_ENABLE_INEXACT_BIT: u32 = 1 << 7;
|
||||
//pub const FCR31_ENABLE_UNDERFLOW_BIT: u32 = 1 << 8;
|
||||
//pub const FCR31_ENABLE_OVERFLOW_BIT: u32 = 1 << 9;
|
||||
//pub const FCR31_ENABLE_DIVBYZERO_BIT: u32 = 1 << 10;
|
||||
//pub const FCR31_ENABLE_INVALID_BIT: u32 = 1 << 11;
|
||||
//pub const FCR31_CAUSE_INEXACT_BIT: u32 = 1 << 12;
|
||||
//pub const FCR31_CAUSE_UNDERFLOW_BIT: u32 = 1 << 13;
|
||||
//pub const FCR31_CAUSE_OVERFLOW_BIT: u32 = 1 << 14;
|
||||
//pub const FCR31_CAUSE_DIVBYZERO_BIT: u32 = 1 << 15;
|
||||
//pub const FCR31_CAUSE_INVALID_BIT: u32 = 1 << 16;
|
||||
pub const FCR31_CAUSE_UNIMP_BIT: u32 = 1 << 17;
|
||||
//const FCR31_FLAG_INEXACT_BIT: u32 = 1 << 2;
|
||||
//const FCR31_FLAG_UNDERFLOW_BIT: u32 = 1 << 3;
|
||||
//const FCR31_FLAG_OVERFLOW_BIT: u32 = 1 << 4;
|
||||
//const FCR31_FLAG_DIVBYZERO_BIT: u32 = 1 << 5;
|
||||
//const FCR31_FLAG_INVALID_BIT: u32 = 1 << 6;
|
||||
//const FCR31_ENABLE_INEXACT_BIT: u32 = 1 << 7;
|
||||
//const FCR31_ENABLE_UNDERFLOW_BIT: u32 = 1 << 8;
|
||||
//const FCR31_ENABLE_OVERFLOW_BIT: u32 = 1 << 9;
|
||||
//const FCR31_ENABLE_DIVBYZERO_BIT: u32 = 1 << 10;
|
||||
//const FCR31_ENABLE_INVALID_BIT: u32 = 1 << 11;
|
||||
//const FCR31_CAUSE_INEXACT_BIT: u32 = 1 << 12;
|
||||
//const FCR31_CAUSE_UNDERFLOW_BIT: u32 = 1 << 13;
|
||||
//const FCR31_CAUSE_OVERFLOW_BIT: u32 = 1 << 14;
|
||||
//const FCR31_CAUSE_DIVBYZERO_BIT: u32 = 1 << 15;
|
||||
//const FCR31_CAUSE_INVALID_BIT: u32 = 1 << 16;
|
||||
const FCR31_CAUSE_UNIMP_BIT: u32 = 1 << 17;
|
||||
pub const FCR31_CMP_BIT: u32 = 1 << 23;
|
||||
pub const FCR31_FS_BIT: u32 = 1 << 24;
|
||||
//#[cfg(target_arch = "x86_64")]
|
||||
//const FCR31_FS_BIT: u32 = 1 << 24;
|
||||
|
||||
pub const FCR31_CAUSE_MASK: u32 = 0b00000000000000111111000000000000;
|
||||
pub const FCR31_ENABLE_MASK: u32 = 0b00000000000000000000111110000000;
|
||||
pub const FCR31_WRITE_MASK: u32 = 0b00000001100000111111111111111111;
|
||||
const FCR31_CAUSE_MASK: u32 = 0b00000000000000111111000000000000;
|
||||
const FCR31_ENABLE_MASK: u32 = 0b00000000000000000000111110000000;
|
||||
const FCR31_WRITE_MASK: u32 = 0b00000001100000111111111111111111;
|
||||
|
||||
pub struct Cop1 {
|
||||
pub fcr0: u32,
|
||||
pub fcr31: u32,
|
||||
pub flush_mode: u32,
|
||||
//#[cfg(target_arch = "x86_64")]
|
||||
//pub flush_mode: u32,
|
||||
pub fgr32: [[u8; 4]; 32],
|
||||
pub fgr64: [[u8; 8]; 32],
|
||||
pub instrs: [fn(&mut device::Device, u32); 32],
|
||||
@@ -366,8 +368,9 @@ pub fn set_control_registers_fpu(device: &mut device::Device, index: u32, data:
|
||||
{
|
||||
device::exceptions::floating_point_exception(device)
|
||||
}
|
||||
|
||||
unsafe {
|
||||
/*
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
{
|
||||
let flush_mode;
|
||||
if (device.cpu.cop1.fcr31 & 2) != 0 {
|
||||
if (device.cpu.cop1.fcr31 & FCR31_FS_BIT) != 0 {
|
||||
@@ -380,10 +383,13 @@ pub fn set_control_registers_fpu(device: &mut device::Device, index: u32, data:
|
||||
}
|
||||
if flush_mode != device.cpu.cop1.flush_mode {
|
||||
#[allow(deprecated)]
|
||||
std::arch::x86_64::_MM_SET_FLUSH_ZERO_MODE(flush_mode);
|
||||
unsafe {
|
||||
std::arch::x86_64::_MM_SET_FLUSH_ZERO_MODE(flush_mode)
|
||||
};
|
||||
device.cpu.cop1.flush_mode = flush_mode;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
_ => {
|
||||
panic!("unknown FCR register")
|
||||
|
||||
@@ -11,6 +11,8 @@ pub enum EventType {
|
||||
InterruptCheck,
|
||||
SPDma,
|
||||
Compare,
|
||||
Vru,
|
||||
PakSwitch,
|
||||
Count,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::device;
|
||||
|
||||
pub const IS_VIEWER_MASK: usize = 0xFFFF;
|
||||
const IS_VIEWER_MASK: usize = 0xFFFF;
|
||||
|
||||
pub fn read_mem(
|
||||
device: &mut device::Device,
|
||||
|
||||
+17
-20
@@ -1,24 +1,24 @@
|
||||
use crate::device;
|
||||
|
||||
pub const MM_RDRAM_DRAM: usize = 0x00000000;
|
||||
pub const MM_RDRAM_REGS: usize = 0x03f00000;
|
||||
pub const MM_RSP_MEM: usize = 0x04000000;
|
||||
pub const MM_RSP_REGS: usize = 0x04040000;
|
||||
pub const MM_RSP_REGS_PC: usize = 0x04080000;
|
||||
pub const MM_DPC_REGS: usize = 0x04100000;
|
||||
pub const MM_DPS_REGS: usize = 0x04200000;
|
||||
pub const MM_MI_REGS: usize = 0x04300000;
|
||||
pub const MM_VI_REGS: usize = 0x04400000;
|
||||
pub const MM_AI_REGS: usize = 0x04500000;
|
||||
pub const MM_PI_REGS: usize = 0x04600000;
|
||||
pub const MM_RI_REGS: usize = 0x04700000;
|
||||
pub const MM_SI_REGS: usize = 0x04800000;
|
||||
const MM_RDRAM_DRAM: usize = 0x00000000;
|
||||
const MM_RDRAM_REGS: usize = 0x03f00000;
|
||||
const MM_RSP_MEM: usize = 0x04000000;
|
||||
const MM_RSP_REGS: usize = 0x04040000;
|
||||
const MM_RSP_REGS_PC: usize = 0x04080000;
|
||||
const MM_DPC_REGS: usize = 0x04100000;
|
||||
const MM_DPS_REGS: usize = 0x04200000;
|
||||
const MM_MI_REGS: usize = 0x04300000;
|
||||
const MM_VI_REGS: usize = 0x04400000;
|
||||
const MM_AI_REGS: usize = 0x04500000;
|
||||
const MM_PI_REGS: usize = 0x04600000;
|
||||
const MM_RI_REGS: usize = 0x04700000;
|
||||
const MM_SI_REGS: usize = 0x04800000;
|
||||
//const MM_DOM2_ADDR1: usize = 0x05000000;
|
||||
pub const MM_DOM2_ADDR2: usize = 0x08000000;
|
||||
pub const MM_CART_ROM: usize = 0x10000000;
|
||||
pub const MM_PIF_MEM: usize = 0x1fc00000;
|
||||
//pub const MM_DOM1_ADDR3: usize = 0x1fd00000;
|
||||
pub const MM_IS_VIEWER: usize = 0x13ff0000;
|
||||
const MM_PIF_MEM: usize = 0x1fc00000;
|
||||
//const MM_DOM1_ADDR3: usize = 0x1fd00000;
|
||||
const MM_IS_VIEWER: usize = 0x13ff0000;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum AccessType {
|
||||
@@ -56,13 +56,10 @@ pub fn translate_address(
|
||||
address: u64,
|
||||
access_type: AccessType,
|
||||
) -> (u64, bool, bool) {
|
||||
let mut cached = false;
|
||||
if (address & 0xc0000000) != 0x80000000 {
|
||||
return device::tlb::get_physical_address(device, address, access_type);
|
||||
} else if address & 0x20000000 == 0 {
|
||||
cached = true;
|
||||
}
|
||||
(address & 0x1FFFFFFF, cached, false)
|
||||
(address & 0x1FFFFFFF, address & 0x20000000 == 0, false)
|
||||
}
|
||||
|
||||
pub fn data_read(
|
||||
|
||||
+27
-27
@@ -1,9 +1,9 @@
|
||||
use crate::device;
|
||||
|
||||
pub const MI_INIT_MODE_REG: u32 = 0;
|
||||
pub const MI_VERSION_REG: u32 = 1;
|
||||
pub const MI_INTR_REG: u32 = 2;
|
||||
pub const MI_INTR_MASK_REG: u32 = 3;
|
||||
const MI_INIT_MODE_REG: u32 = 0;
|
||||
const MI_VERSION_REG: u32 = 1;
|
||||
const MI_INTR_REG: u32 = 2;
|
||||
const MI_INTR_MASK_REG: u32 = 3;
|
||||
pub const MI_REGS_COUNT: u32 = 4;
|
||||
|
||||
/* read */
|
||||
@@ -15,34 +15,34 @@ pub const MI_INTR_PI: u32 = 1 << 4;
|
||||
pub const MI_INTR_DP: u32 = 1 << 5;
|
||||
|
||||
/* write */
|
||||
pub const MI_CLR_SP: u32 = 1 << 0;
|
||||
pub const MI_SET_SP: u32 = 1 << 1;
|
||||
pub const MI_CLR_SI: u32 = 1 << 2;
|
||||
pub const MI_SET_SI: u32 = 1 << 3;
|
||||
pub const MI_CLR_AI: u32 = 1 << 4;
|
||||
pub const MI_SET_AI: u32 = 1 << 5;
|
||||
pub const MI_CLR_VI: u32 = 1 << 6;
|
||||
pub const MI_SET_VI: u32 = 1 << 7;
|
||||
pub const MI_CLR_PI: u32 = 1 << 8;
|
||||
pub const MI_SET_PI: u32 = 1 << 9;
|
||||
pub const MI_CLR_DP: u32 = 1 << 10;
|
||||
pub const MI_SET_DP: u32 = 1 << 11;
|
||||
const MI_CLR_SP: u32 = 1 << 0;
|
||||
const MI_SET_SP: u32 = 1 << 1;
|
||||
const MI_CLR_SI: u32 = 1 << 2;
|
||||
const MI_SET_SI: u32 = 1 << 3;
|
||||
const MI_CLR_AI: u32 = 1 << 4;
|
||||
const MI_SET_AI: u32 = 1 << 5;
|
||||
const MI_CLR_VI: u32 = 1 << 6;
|
||||
const MI_SET_VI: u32 = 1 << 7;
|
||||
const MI_CLR_PI: u32 = 1 << 8;
|
||||
const MI_SET_PI: u32 = 1 << 9;
|
||||
const MI_CLR_DP: u32 = 1 << 10;
|
||||
const MI_SET_DP: u32 = 1 << 11;
|
||||
|
||||
/* mode read */
|
||||
pub const MI_INIT_MODE: u32 = 1 << 7;
|
||||
pub const MI_EBUS_MODE: u32 = 1 << 8;
|
||||
pub const MI_RDRAM_MODE: u32 = 1 << 9;
|
||||
const MI_INIT_MODE: u32 = 1 << 7;
|
||||
const MI_EBUS_MODE: u32 = 1 << 8;
|
||||
const MI_RDRAM_MODE: u32 = 1 << 9;
|
||||
|
||||
/* mode write */
|
||||
pub const MI_CLR_INIT: u32 = 1 << 7;
|
||||
pub const MI_SET_INIT: u32 = 1 << 8;
|
||||
pub const MI_CLR_EBUS: u32 = 1 << 9;
|
||||
pub const MI_SET_EBUS: u32 = 1 << 10;
|
||||
pub const MI_CLR_DP_INTR: u32 = 1 << 11;
|
||||
pub const MI_CLR_RDRAM: u32 = 1 << 12;
|
||||
pub const MI_SET_RDRAM: u32 = 1 << 13;
|
||||
const MI_CLR_INIT: u32 = 1 << 7;
|
||||
const MI_SET_INIT: u32 = 1 << 8;
|
||||
const MI_CLR_EBUS: u32 = 1 << 9;
|
||||
const MI_SET_EBUS: u32 = 1 << 10;
|
||||
const MI_CLR_DP_INTR: u32 = 1 << 11;
|
||||
const MI_CLR_RDRAM: u32 = 1 << 12;
|
||||
const MI_SET_RDRAM: u32 = 1 << 13;
|
||||
|
||||
pub const MI_INIT_LENGTH_MASK: u32 = 0b1111111;
|
||||
const MI_INIT_LENGTH_MASK: u32 = 0b1111111;
|
||||
|
||||
pub struct Mi {
|
||||
pub regs: [u32; MI_REGS_COUNT as usize],
|
||||
|
||||
+19
-18
@@ -1,29 +1,30 @@
|
||||
use crate::device;
|
||||
|
||||
pub const PI_DRAM_ADDR_REG: u32 = 0;
|
||||
pub const PI_CART_ADDR_REG: u32 = 1;
|
||||
pub const PI_RD_LEN_REG: u32 = 2;
|
||||
pub const PI_WR_LEN_REG: u32 = 3;
|
||||
const PI_DRAM_ADDR_REG: u32 = 0;
|
||||
const PI_CART_ADDR_REG: u32 = 1;
|
||||
const PI_RD_LEN_REG: u32 = 2;
|
||||
const PI_WR_LEN_REG: u32 = 3;
|
||||
pub const PI_STATUS_REG: u32 = 4;
|
||||
pub const PI_BSD_DOM1_LAT_REG: u32 = 5;
|
||||
pub const PI_BSD_DOM1_PWD_REG: u32 = 6;
|
||||
pub const PI_BSD_DOM1_PGS_REG: u32 = 7;
|
||||
pub const PI_BSD_DOM1_RLS_REG: u32 = 8;
|
||||
pub const PI_BSD_DOM2_LAT_REG: u32 = 9;
|
||||
pub const PI_BSD_DOM2_PWD_REG: u32 = 10;
|
||||
pub const PI_BSD_DOM2_PGS_REG: u32 = 11;
|
||||
pub const PI_BSD_DOM2_RLS_REG: u32 = 12;
|
||||
pub const PI_REGS_COUNT: u32 = 13;
|
||||
const PI_BSD_DOM1_LAT_REG: u32 = 5;
|
||||
const PI_BSD_DOM1_PWD_REG: u32 = 6;
|
||||
const PI_BSD_DOM1_PGS_REG: u32 = 7;
|
||||
const PI_BSD_DOM1_RLS_REG: u32 = 8;
|
||||
const PI_BSD_DOM2_LAT_REG: u32 = 9;
|
||||
const PI_BSD_DOM2_PWD_REG: u32 = 10;
|
||||
const PI_BSD_DOM2_PGS_REG: u32 = 11;
|
||||
const PI_BSD_DOM2_RLS_REG: u32 = 12;
|
||||
//const UNKNOWN_REG: u32 = 13; //LibDragon
|
||||
pub const PI_REGS_COUNT: u32 = 14;
|
||||
|
||||
/* PI_STATUS - read */
|
||||
pub const PI_STATUS_DMA_BUSY: u32 = 1 << 0;
|
||||
const PI_STATUS_DMA_BUSY: u32 = 1 << 0;
|
||||
pub const PI_STATUS_IO_BUSY: u32 = 1 << 1;
|
||||
//pub const PI_STATUS_ERROR: u32 = 1 << 2;
|
||||
pub const PI_STATUS_INTERRUPT: u32 = 1 << 3;
|
||||
//const PI_STATUS_ERROR: u32 = 1 << 2;
|
||||
const PI_STATUS_INTERRUPT: u32 = 1 << 3;
|
||||
|
||||
/* PI_STATUS - write */
|
||||
pub const PI_STATUS_RESET: u32 = 1 << 0;
|
||||
pub const PI_STATUS_CLR_INTR: u32 = 1 << 1;
|
||||
const PI_STATUS_RESET: u32 = 1 << 0;
|
||||
const PI_STATUS_CLR_INTR: u32 = 1 << 1;
|
||||
|
||||
pub struct Pi {
|
||||
pub regs: [u32; PI_REGS_COUNT as usize],
|
||||
|
||||
+15
-5
@@ -15,6 +15,7 @@ pub struct PifChannel {
|
||||
pub rx_buf: Option<usize>,
|
||||
pub process: Option<fn(&mut device::Device, usize)>,
|
||||
pub pak_handler: Option<device::controller::PakHandler>,
|
||||
pub change_pak: device::controller::PakType,
|
||||
}
|
||||
|
||||
pub const PIF_RAM_SIZE: usize = 64;
|
||||
@@ -99,7 +100,7 @@ pub fn update_pif_ram(device: &mut device::Device) -> u64 {
|
||||
for k in 0..PIF_CHANNELS_COUNT {
|
||||
active_channels += process_channel(device, k)
|
||||
}
|
||||
(24000 + (active_channels * 28000)) as u64
|
||||
(24000 + (active_channels * 30000)) as u64
|
||||
}
|
||||
|
||||
pub fn disable_pif_channel(channel: &mut PifChannel) {
|
||||
@@ -225,12 +226,21 @@ pub fn init(device: &mut device::Device) {
|
||||
device.pif.ram[0x27] = device.cart.cic_seed;
|
||||
|
||||
let mempak_handler = device::controller::PakHandler {
|
||||
read: device::mempak::read,
|
||||
write: device::mempak::write,
|
||||
read: device::controller::mempak::read,
|
||||
write: device::controller::mempak::write,
|
||||
pak_type: device::controller::PakType::MemPak,
|
||||
};
|
||||
|
||||
device.pif.channels[0].pak_handler = Some(mempak_handler);
|
||||
device.pif.channels[0].process = Some(device::controller::process);
|
||||
for i in 0..4 {
|
||||
if device.ui.config.input.controller_enabled[i] {
|
||||
device.pif.channels[i].pak_handler = Some(mempak_handler);
|
||||
device.pif.channels[i].process = Some(device::controller::process);
|
||||
}
|
||||
}
|
||||
if device.ui.config.input.emulate_vru {
|
||||
device.pif.channels[3].pak_handler = None;
|
||||
device.pif.channels[3].process = Some(device::controller::vru::process);
|
||||
}
|
||||
device.pif.channels[4].process = Some(device::cart::process)
|
||||
}
|
||||
|
||||
|
||||
+29
-29
@@ -5,41 +5,41 @@ pub const DPC_START_REG: u32 = 0;
|
||||
pub const DPC_END_REG: u32 = 1;
|
||||
pub const DPC_CURRENT_REG: u32 = 2;
|
||||
pub const DPC_STATUS_REG: u32 = 3;
|
||||
pub const DPC_CLOCK_REG: u32 = 4;
|
||||
pub const DPC_BUFBUSY_REG: u32 = 5;
|
||||
pub const DPC_PIPEBUSY_REG: u32 = 6;
|
||||
pub const DPC_TMEM_REG: u32 = 7;
|
||||
const DPC_CLOCK_REG: u32 = 4;
|
||||
const DPC_BUFBUSY_REG: u32 = 5;
|
||||
const DPC_PIPEBUSY_REG: u32 = 6;
|
||||
const DPC_TMEM_REG: u32 = 7;
|
||||
pub const DPC_REGS_COUNT: u32 = 8;
|
||||
|
||||
//pub const DPS_TBIST_REG: u32 = 0;
|
||||
//pub const DPS_TEST_MODE_REG: u32 = 1;
|
||||
//pub const DPS_BUFTEST_ADDR_REG: u32 = 2;
|
||||
//pub const DPS_BUFTEST_DATA_REG: u32 = 3;
|
||||
//const DPS_TBIST_REG: u32 = 0;
|
||||
//const DPS_TEST_MODE_REG: u32 = 1;
|
||||
//const DPS_BUFTEST_ADDR_REG: u32 = 2;
|
||||
//const DPS_BUFTEST_DATA_REG: u32 = 3;
|
||||
pub const DPS_REGS_COUNT: u32 = 4;
|
||||
|
||||
/* DPC status - read */
|
||||
pub const DPC_STATUS_XBUS_DMEM_DMA: u32 = 1 << 0;
|
||||
pub const DPC_STATUS_FREEZE: u32 = 1 << 1;
|
||||
pub const DPC_STATUS_FLUSH: u32 = 1 << 2;
|
||||
pub const DPC_STATUS_START_GCLK: u32 = 1 << 3;
|
||||
pub const DPC_STATUS_TMEM_BUSY: u32 = 1 << 4;
|
||||
pub const DPC_STATUS_PIPE_BUSY: u32 = 1 << 5;
|
||||
pub const DPC_STATUS_CMD_BUSY: u32 = 1 << 6;
|
||||
pub const DPC_STATUS_CBUF_READY: u32 = 1 << 7;
|
||||
//pub const DPC_STATUS_DMA_BUSY: u32 = 1 << 8;
|
||||
//pub const DPC_STATUS_END_VALID: u32 = 1 << 9;
|
||||
pub const DPC_STATUS_START_VALID: u32 = 1 << 10;
|
||||
const DPC_STATUS_XBUS_DMEM_DMA: u32 = 1 << 0;
|
||||
const DPC_STATUS_FREEZE: u32 = 1 << 1;
|
||||
const DPC_STATUS_FLUSH: u32 = 1 << 2;
|
||||
const DPC_STATUS_START_GCLK: u32 = 1 << 3;
|
||||
const DPC_STATUS_TMEM_BUSY: u32 = 1 << 4;
|
||||
const DPC_STATUS_PIPE_BUSY: u32 = 1 << 5;
|
||||
const DPC_STATUS_CMD_BUSY: u32 = 1 << 6;
|
||||
const DPC_STATUS_CBUF_READY: u32 = 1 << 7;
|
||||
//const DPC_STATUS_DMA_BUSY: u32 = 1 << 8;
|
||||
//const DPC_STATUS_END_VALID: u32 = 1 << 9;
|
||||
const DPC_STATUS_START_VALID: u32 = 1 << 10;
|
||||
/* DPC status - write */
|
||||
pub const DPC_CLR_XBUS_DMEM_DMA: u32 = 1 << 0;
|
||||
pub const DPC_SET_XBUS_DMEM_DMA: u32 = 1 << 1;
|
||||
pub const DPC_CLR_FREEZE: u32 = 1 << 2;
|
||||
pub const DPC_SET_FREEZE: u32 = 1 << 3;
|
||||
pub const DPC_CLR_FLUSH: u32 = 1 << 4;
|
||||
pub const DPC_SET_FLUSH: u32 = 1 << 5;
|
||||
pub const DPC_CLR_TMEM_CTR: u32 = 1 << 6;
|
||||
pub const DPC_CLR_PIPE_CTR: u32 = 1 << 7;
|
||||
pub const DPC_CLR_CMD_CTR: u32 = 1 << 8;
|
||||
pub const DPC_CLR_CLOCK_CTR: u32 = 1 << 9;
|
||||
const DPC_CLR_XBUS_DMEM_DMA: u32 = 1 << 0;
|
||||
const DPC_SET_XBUS_DMEM_DMA: u32 = 1 << 1;
|
||||
const DPC_CLR_FREEZE: u32 = 1 << 2;
|
||||
const DPC_SET_FREEZE: u32 = 1 << 3;
|
||||
const DPC_CLR_FLUSH: u32 = 1 << 4;
|
||||
const DPC_SET_FLUSH: u32 = 1 << 5;
|
||||
const DPC_CLR_TMEM_CTR: u32 = 1 << 6;
|
||||
const DPC_CLR_PIPE_CTR: u32 = 1 << 7;
|
||||
const DPC_CLR_CMD_CTR: u32 = 1 << 8;
|
||||
const DPC_CLR_CLOCK_CTR: u32 = 1 << 9;
|
||||
|
||||
pub struct Rdp {
|
||||
pub regs_dpc: [u32; DPC_REGS_COUNT as usize],
|
||||
|
||||
+3
-2
@@ -57,10 +57,11 @@ pub fn write_mem(device: &mut device::Device, address: u64, value: u32, mask: u3
|
||||
|
||||
pub fn read_regs(
|
||||
_device: &mut device::Device,
|
||||
_address: u64,
|
||||
address: u64,
|
||||
_access_size: device::memory::AccessSize,
|
||||
) -> u32 {
|
||||
panic!("rdram read reg");
|
||||
println!("Warning: read from RDRAM reg {:#x}", address);
|
||||
0
|
||||
}
|
||||
|
||||
pub fn write_regs(_device: &mut device::Device, _address: u64, _value: u32, _mask: u32) {
|
||||
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
use crate::device;
|
||||
|
||||
//pub const RI_MODE_REG: u32 = 0;
|
||||
//pub const RI_CONFIG_REG: u32 = 1;
|
||||
//pub const RI_CURRENT_LOAD_REG: u32 = 2;
|
||||
pub const RI_SELECT_REG: u32 = 3;
|
||||
//pub const RI_REFRESH_REG: u32 = 4;
|
||||
//pub const RI_LATENCY_REG: u32 = 5;
|
||||
//pub const RI_ERROR_REG: u32 = 6;
|
||||
//pub const RI_WERROR_REG: u32 = 7;
|
||||
//const RI_MODE_REG: u32 = 0;
|
||||
//const RI_CONFIG_REG: u32 = 1;
|
||||
//const RI_CURRENT_LOAD_REG: u32 = 2;
|
||||
const RI_SELECT_REG: u32 = 3;
|
||||
//const RI_REFRESH_REG: u32 = 4;
|
||||
//const RI_LATENCY_REG: u32 = 5;
|
||||
//const RI_ERROR_REG: u32 = 6;
|
||||
//const RI_WERROR_REG: u32 = 7;
|
||||
pub const RI_REGS_COUNT: u32 = 8;
|
||||
|
||||
pub struct Ri {
|
||||
|
||||
+14
-9
@@ -1,4 +1,9 @@
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use device::__m128i;
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
include!(concat!(env!("OUT_DIR"), "/simd_bindings.rs"));
|
||||
use crate::device;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use std::arch::x86_64::*;
|
||||
|
||||
pub struct BranchState {
|
||||
@@ -30,17 +35,17 @@ pub struct Cpu {
|
||||
pub cycle_counter: u64,
|
||||
pub shuffle: [__m128i; 16],
|
||||
pub gpr: [u32; 32],
|
||||
pub vpr: [u128; 32],
|
||||
pub vpr: [__m128i; 32],
|
||||
pub reciprocals: [u16; 512],
|
||||
pub inverse_square_roots: [u16; 512],
|
||||
pub vcol: std::arch::x86_64::__m128i,
|
||||
pub vcoh: std::arch::x86_64::__m128i,
|
||||
pub vccl: std::arch::x86_64::__m128i,
|
||||
pub vcch: std::arch::x86_64::__m128i,
|
||||
pub vce: std::arch::x86_64::__m128i,
|
||||
pub accl: std::arch::x86_64::__m128i,
|
||||
pub accm: std::arch::x86_64::__m128i,
|
||||
pub acch: std::arch::x86_64::__m128i,
|
||||
pub vcol: __m128i,
|
||||
pub vcoh: __m128i,
|
||||
pub vccl: __m128i,
|
||||
pub vcch: __m128i,
|
||||
pub vce: __m128i,
|
||||
pub accl: __m128i,
|
||||
pub accm: __m128i,
|
||||
pub acch: __m128i,
|
||||
pub divdp: bool,
|
||||
pub divin: i16,
|
||||
pub divout: i16,
|
||||
|
||||
+47
-47
@@ -1,64 +1,64 @@
|
||||
use crate::device;
|
||||
|
||||
pub const SP_MEM_ADDR_REG: u32 = 0;
|
||||
pub const SP_DRAM_ADDR_REG: u32 = 1;
|
||||
pub const SP_RD_LEN_REG: u32 = 2;
|
||||
pub const SP_WR_LEN_REG: u32 = 3;
|
||||
const SP_MEM_ADDR_REG: u32 = 0;
|
||||
const SP_DRAM_ADDR_REG: u32 = 1;
|
||||
const SP_RD_LEN_REG: u32 = 2;
|
||||
const SP_WR_LEN_REG: u32 = 3;
|
||||
pub const SP_STATUS_REG: u32 = 4;
|
||||
pub const SP_DMA_FULL_REG: u32 = 5;
|
||||
pub const SP_DMA_BUSY_REG: u32 = 6;
|
||||
pub const SP_SEMAPHORE_REG: u32 = 7;
|
||||
const SP_DMA_FULL_REG: u32 = 5;
|
||||
const SP_DMA_BUSY_REG: u32 = 6;
|
||||
const SP_SEMAPHORE_REG: u32 = 7;
|
||||
pub const SP_REGS_COUNT: u32 = 8;
|
||||
|
||||
pub const SP_PC_REG: u32 = 0;
|
||||
//pub const SP_IBIST_REG: u32 = 1;
|
||||
//const SP_IBIST_REG: u32 = 1;
|
||||
pub const SP_REGS2_COUNT: u32 = 2;
|
||||
|
||||
/* SP_STATUS - read */
|
||||
pub const SP_STATUS_HALT: u32 = 1 << 0;
|
||||
pub const SP_STATUS_BROKE: u32 = 1 << 1;
|
||||
pub const SP_STATUS_DMA_BUSY: u32 = 1 << 2;
|
||||
pub const SP_STATUS_DMA_FULL: u32 = 1 << 3;
|
||||
//pub const SP_STATUS_IO_FULL: u32 = 1 << 4;
|
||||
pub const SP_STATUS_SSTEP: u32 = 1 << 5;
|
||||
pub const SP_STATUS_INTR_BREAK: u32 = 1 << 6;
|
||||
pub const SP_STATUS_SIG0: u32 = 1 << 7;
|
||||
pub const SP_STATUS_SIG1: u32 = 1 << 8;
|
||||
pub const SP_STATUS_SIG2: u32 = 1 << 9;
|
||||
pub const SP_STATUS_SIG3: u32 = 1 << 10;
|
||||
pub const SP_STATUS_SIG4: u32 = 1 << 11;
|
||||
pub const SP_STATUS_SIG5: u32 = 1 << 12;
|
||||
pub const SP_STATUS_SIG6: u32 = 1 << 13;
|
||||
pub const SP_STATUS_SIG7: u32 = 1 << 14;
|
||||
const SP_STATUS_BROKE: u32 = 1 << 1;
|
||||
const SP_STATUS_DMA_BUSY: u32 = 1 << 2;
|
||||
const SP_STATUS_DMA_FULL: u32 = 1 << 3;
|
||||
//const SP_STATUS_IO_FULL: u32 = 1 << 4;
|
||||
const SP_STATUS_SSTEP: u32 = 1 << 5;
|
||||
const SP_STATUS_INTR_BREAK: u32 = 1 << 6;
|
||||
const SP_STATUS_SIG0: u32 = 1 << 7;
|
||||
const SP_STATUS_SIG1: u32 = 1 << 8;
|
||||
const SP_STATUS_SIG2: u32 = 1 << 9;
|
||||
const SP_STATUS_SIG3: u32 = 1 << 10;
|
||||
const SP_STATUS_SIG4: u32 = 1 << 11;
|
||||
const SP_STATUS_SIG5: u32 = 1 << 12;
|
||||
const SP_STATUS_SIG6: u32 = 1 << 13;
|
||||
const SP_STATUS_SIG7: u32 = 1 << 14;
|
||||
|
||||
/* SP_STATUS - write */
|
||||
pub const SP_CLR_HALT: u32 = 1 << 0;
|
||||
const SP_CLR_HALT: u32 = 1 << 0;
|
||||
pub const SP_SET_HALT: u32 = 1 << 1;
|
||||
pub const SP_CLR_BROKE: u32 = 1 << 2;
|
||||
pub const SP_CLR_INTR: u32 = 1 << 3;
|
||||
pub const SP_SET_INTR: u32 = 1 << 4;
|
||||
pub const SP_CLR_SSTEP: u32 = 1 << 5;
|
||||
pub const SP_SET_SSTEP: u32 = 1 << 6;
|
||||
pub const SP_CLR_INTR_BREAK: u32 = 1 << 7;
|
||||
pub const SP_SET_INTR_BREAK: u32 = 1 << 8;
|
||||
pub const SP_CLR_SIG0: u32 = 1 << 9;
|
||||
pub const SP_SET_SIG0: u32 = 1 << 10;
|
||||
pub const SP_CLR_SIG1: u32 = 1 << 11;
|
||||
pub const SP_SET_SIG1: u32 = 1 << 12;
|
||||
pub const SP_CLR_SIG2: u32 = 1 << 13;
|
||||
pub const SP_SET_SIG2: u32 = 1 << 14;
|
||||
pub const SP_CLR_SIG3: u32 = 1 << 15;
|
||||
pub const SP_SET_SIG3: u32 = 1 << 16;
|
||||
pub const SP_CLR_SIG4: u32 = 1 << 17;
|
||||
pub const SP_SET_SIG4: u32 = 1 << 18;
|
||||
pub const SP_CLR_SIG5: u32 = 1 << 19;
|
||||
pub const SP_SET_SIG5: u32 = 1 << 20;
|
||||
pub const SP_CLR_SIG6: u32 = 1 << 21;
|
||||
pub const SP_SET_SIG6: u32 = 1 << 22;
|
||||
pub const SP_CLR_SIG7: u32 = 1 << 23;
|
||||
pub const SP_SET_SIG7: u32 = 1 << 24;
|
||||
const SP_CLR_BROKE: u32 = 1 << 2;
|
||||
const SP_CLR_INTR: u32 = 1 << 3;
|
||||
const SP_SET_INTR: u32 = 1 << 4;
|
||||
const SP_CLR_SSTEP: u32 = 1 << 5;
|
||||
const SP_SET_SSTEP: u32 = 1 << 6;
|
||||
const SP_CLR_INTR_BREAK: u32 = 1 << 7;
|
||||
const SP_SET_INTR_BREAK: u32 = 1 << 8;
|
||||
const SP_CLR_SIG0: u32 = 1 << 9;
|
||||
const SP_SET_SIG0: u32 = 1 << 10;
|
||||
const SP_CLR_SIG1: u32 = 1 << 11;
|
||||
const SP_SET_SIG1: u32 = 1 << 12;
|
||||
const SP_CLR_SIG2: u32 = 1 << 13;
|
||||
const SP_SET_SIG2: u32 = 1 << 14;
|
||||
const SP_CLR_SIG3: u32 = 1 << 15;
|
||||
const SP_SET_SIG3: u32 = 1 << 16;
|
||||
const SP_CLR_SIG4: u32 = 1 << 17;
|
||||
const SP_SET_SIG4: u32 = 1 << 18;
|
||||
const SP_CLR_SIG5: u32 = 1 << 19;
|
||||
const SP_SET_SIG5: u32 = 1 << 20;
|
||||
const SP_CLR_SIG6: u32 = 1 << 21;
|
||||
const SP_SET_SIG6: u32 = 1 << 22;
|
||||
const SP_CLR_SIG7: u32 = 1 << 23;
|
||||
const SP_SET_SIG7: u32 = 1 << 24;
|
||||
|
||||
pub const RSP_MEM_MASK: usize = 0x1FFF;
|
||||
const RSP_MEM_MASK: usize = 0x1FFF;
|
||||
|
||||
#[derive(PartialEq, Copy, Clone)]
|
||||
pub enum DmaDir {
|
||||
|
||||
+349
-156
@@ -1,4 +1,11 @@
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use device::__m128i;
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
include!(concat!(env!("OUT_DIR"), "/simd_bindings.rs"));
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
include!("../compat/aarch64.rs");
|
||||
use crate::device;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use std::arch::x86_64::*;
|
||||
|
||||
pub fn rd(opcode: u32) -> u32 {
|
||||
@@ -39,28 +46,136 @@ pub fn sign_extend_7bit_offset(offset: u8, shift_amount: u32) -> u32 {
|
||||
(((soffset) as i32) as u32) << shift_amount
|
||||
}
|
||||
|
||||
pub fn modify_vpr_byte(vpr: &mut u128, value: u8, element: u8) {
|
||||
let pos = 15 - (element & 15);
|
||||
let mask = 0xFF << (pos * 8);
|
||||
*vpr &= !mask;
|
||||
*vpr |= (value as u128) << (pos * 8);
|
||||
pub fn modify_vpr8(vpr: &mut __m128i, element: u8, value: u8) {
|
||||
unsafe {
|
||||
*vpr = match element & 15 {
|
||||
0 => _mm_insert_epi8(*vpr, value as i32, 15),
|
||||
1 => _mm_insert_epi8(*vpr, value as i32, 14),
|
||||
2 => _mm_insert_epi8(*vpr, value as i32, 13),
|
||||
3 => _mm_insert_epi8(*vpr, value as i32, 12),
|
||||
4 => _mm_insert_epi8(*vpr, value as i32, 11),
|
||||
5 => _mm_insert_epi8(*vpr, value as i32, 10),
|
||||
6 => _mm_insert_epi8(*vpr, value as i32, 9),
|
||||
7 => _mm_insert_epi8(*vpr, value as i32, 8),
|
||||
8 => _mm_insert_epi8(*vpr, value as i32, 7),
|
||||
9 => _mm_insert_epi8(*vpr, value as i32, 6),
|
||||
10 => _mm_insert_epi8(*vpr, value as i32, 5),
|
||||
11 => _mm_insert_epi8(*vpr, value as i32, 4),
|
||||
12 => _mm_insert_epi8(*vpr, value as i32, 3),
|
||||
13 => _mm_insert_epi8(*vpr, value as i32, 2),
|
||||
14 => _mm_insert_epi8(*vpr, value as i32, 1),
|
||||
15 => _mm_insert_epi8(*vpr, value as i32, 0),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_vpr_byte(vpr: u128, element: u8) -> u8 {
|
||||
let pos = 15 - (element & 15);
|
||||
(vpr >> (pos * 8)) as u8
|
||||
pub fn get_vpr8(vpr: __m128i, element: u8) -> u8 {
|
||||
unsafe {
|
||||
match element & 15 {
|
||||
0 => _mm_extract_epi8(vpr, 15) as u8,
|
||||
1 => _mm_extract_epi8(vpr, 14) as u8,
|
||||
2 => _mm_extract_epi8(vpr, 13) as u8,
|
||||
3 => _mm_extract_epi8(vpr, 12) as u8,
|
||||
4 => _mm_extract_epi8(vpr, 11) as u8,
|
||||
5 => _mm_extract_epi8(vpr, 10) as u8,
|
||||
6 => _mm_extract_epi8(vpr, 9) as u8,
|
||||
7 => _mm_extract_epi8(vpr, 8) as u8,
|
||||
8 => _mm_extract_epi8(vpr, 7) as u8,
|
||||
9 => _mm_extract_epi8(vpr, 6) as u8,
|
||||
10 => _mm_extract_epi8(vpr, 5) as u8,
|
||||
11 => _mm_extract_epi8(vpr, 4) as u8,
|
||||
12 => _mm_extract_epi8(vpr, 3) as u8,
|
||||
13 => _mm_extract_epi8(vpr, 2) as u8,
|
||||
14 => _mm_extract_epi8(vpr, 1) as u8,
|
||||
15 => _mm_extract_epi8(vpr, 0) as u8,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modify_vpr_element(vpr: &mut u128, value: u16, element: u8) {
|
||||
let pos = 7 - (element & 7);
|
||||
let mask = 0xFFFF << (pos * 16);
|
||||
*vpr &= !mask;
|
||||
*vpr |= (value as u128) << (pos * 16);
|
||||
pub fn modify_vpr16(vpr: &mut __m128i, element: u8, value: u16) {
|
||||
unsafe {
|
||||
*vpr = match element & 7 {
|
||||
0 => _mm_insert_epi16(*vpr, value as i32, 7),
|
||||
1 => _mm_insert_epi16(*vpr, value as i32, 6),
|
||||
2 => _mm_insert_epi16(*vpr, value as i32, 5),
|
||||
3 => _mm_insert_epi16(*vpr, value as i32, 4),
|
||||
4 => _mm_insert_epi16(*vpr, value as i32, 3),
|
||||
5 => _mm_insert_epi16(*vpr, value as i32, 2),
|
||||
6 => _mm_insert_epi16(*vpr, value as i32, 1),
|
||||
7 => _mm_insert_epi16(*vpr, value as i32, 0),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_vpr_element(vpr: u128, element: u8) -> u16 {
|
||||
let pos = 7 - (element & 7);
|
||||
(vpr >> (pos * 16)) as u16
|
||||
pub fn get_vpr16(vpr: __m128i, element: u8) -> u16 {
|
||||
unsafe {
|
||||
match element & 7 {
|
||||
0 => _mm_extract_epi16(vpr, 7) as u16,
|
||||
1 => _mm_extract_epi16(vpr, 6) as u16,
|
||||
2 => _mm_extract_epi16(vpr, 5) as u16,
|
||||
3 => _mm_extract_epi16(vpr, 4) as u16,
|
||||
4 => _mm_extract_epi16(vpr, 3) as u16,
|
||||
5 => _mm_extract_epi16(vpr, 2) as u16,
|
||||
6 => _mm_extract_epi16(vpr, 1) as u16,
|
||||
7 => _mm_extract_epi16(vpr, 0) as u16,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modify_vpr32(vpr: &mut __m128i, element: u8, value: u32) {
|
||||
unsafe {
|
||||
*vpr = match element & 3 {
|
||||
0 => _mm_insert_epi32(*vpr, value as i32, 3),
|
||||
1 => _mm_insert_epi32(*vpr, value as i32, 2),
|
||||
2 => _mm_insert_epi32(*vpr, value as i32, 1),
|
||||
3 => _mm_insert_epi32(*vpr, value as i32, 0),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_vpr32(vpr: __m128i, element: u8) -> u32 {
|
||||
unsafe {
|
||||
match element & 3 {
|
||||
0 => _mm_extract_epi32(vpr, 3) as u32,
|
||||
1 => _mm_extract_epi32(vpr, 2) as u32,
|
||||
2 => _mm_extract_epi32(vpr, 1) as u32,
|
||||
3 => _mm_extract_epi32(vpr, 0) as u32,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modify_vpr64(vpr: &mut __m128i, element: u8, value: u64) {
|
||||
unsafe {
|
||||
*vpr = match element & 1 {
|
||||
0 => _mm_insert_epi64(*vpr, value as i64, 1),
|
||||
1 => _mm_insert_epi64(*vpr, value as i64, 0),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_vpr64(vpr: __m128i, element: u8) -> u64 {
|
||||
unsafe {
|
||||
match element & 1 {
|
||||
0 => _mm_extract_epi64(vpr, 1) as u64,
|
||||
1 => _mm_extract_epi64(vpr, 0) as u64,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modify_vpr128(vpr: &mut __m128i, value: u128) {
|
||||
unsafe { *vpr = std::mem::transmute::<u128, __m128i>(value) }
|
||||
}
|
||||
|
||||
pub fn get_vpr128(vpr: __m128i) -> u128 {
|
||||
unsafe { std::mem::transmute::<__m128i, u128>(vpr) }
|
||||
}
|
||||
|
||||
pub fn j(device: &mut device::Device, opcode: u32) {
|
||||
@@ -481,8 +596,8 @@ pub fn mtc0(device: &mut device::Device, opcode: u32) {
|
||||
}
|
||||
|
||||
pub fn mfc2(device: &mut device::Device, opcode: u32) {
|
||||
let hi = get_vpr_byte(device.rsp.cpu.vpr[rd(opcode) as usize], velement(opcode));
|
||||
let lo = get_vpr_byte(
|
||||
let hi = get_vpr8(device.rsp.cpu.vpr[rd(opcode) as usize], velement(opcode));
|
||||
let lo = get_vpr8(
|
||||
device.rsp.cpu.vpr[rd(opcode) as usize],
|
||||
velement(opcode) + 1,
|
||||
);
|
||||
@@ -508,7 +623,7 @@ pub fn cfc2(device: &mut device::Device, opcode: u32) {
|
||||
lo = &mut device.rsp.cpu.vce;
|
||||
}
|
||||
_ => {
|
||||
panic!("unknown ctc2")
|
||||
panic!("unknown cfc2")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,16 +635,16 @@ pub fn cfc2(device: &mut device::Device, opcode: u32) {
|
||||
}
|
||||
|
||||
pub fn mtc2(device: &mut device::Device, opcode: u32) {
|
||||
modify_vpr_byte(
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[rd(opcode) as usize],
|
||||
(device.rsp.cpu.gpr[rt(opcode) as usize] >> 8) as u8,
|
||||
velement(opcode),
|
||||
(device.rsp.cpu.gpr[rt(opcode) as usize] >> 8) as u8,
|
||||
);
|
||||
if velement(opcode) != 15 {
|
||||
modify_vpr_byte(
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[rd(opcode) as usize],
|
||||
device.rsp.cpu.gpr[rt(opcode) as usize] as u8,
|
||||
velement(opcode) + 1,
|
||||
device.rsp.cpu.gpr[rt(opcode) as usize] as u8,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -574,7 +689,7 @@ pub fn ctc2(device: &mut device::Device, opcode: u32) {
|
||||
),
|
||||
_mm_setzero_si128(),
|
||||
);
|
||||
*hi = std::arch::x86_64::_mm_cmpeq_epi8(
|
||||
*hi = _mm_cmpeq_epi8(
|
||||
_mm_and_si128(
|
||||
_mm_set1_epi8(!(device.rsp.cpu.gpr[rt(opcode) as usize] >> 8) as i8),
|
||||
mask,
|
||||
@@ -589,10 +704,10 @@ pub fn lbv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 0));
|
||||
|
||||
let element = velement(opcode);
|
||||
modify_vpr_byte(
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
element,
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -601,15 +716,25 @@ pub fn lsv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 1));
|
||||
|
||||
let mut element = velement(opcode);
|
||||
let end = std::cmp::min(element + 2, 16);
|
||||
while element < end {
|
||||
modify_vpr_byte(
|
||||
|
||||
if element % 2 == 0 {
|
||||
modify_vpr16(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
element,
|
||||
element / 2,
|
||||
(device.rsp.mem[(address & 0xFFF) as usize] as u16) << 8
|
||||
| (device.rsp.mem[((address + 1) & 0xFFF) as usize] as u16),
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
} else {
|
||||
let end = std::cmp::min(element + 2, 16);
|
||||
while element < end {
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
element,
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,15 +743,28 @@ pub fn llv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 2));
|
||||
|
||||
let mut element = velement(opcode);
|
||||
let end = std::cmp::min(element + 4, 16);
|
||||
while element < end {
|
||||
modify_vpr_byte(
|
||||
|
||||
if element % 4 == 0 {
|
||||
let mut value = 0;
|
||||
for i in 0..4 {
|
||||
value |= (device.rsp.mem[((address + i) & 0xFFF) as usize] as u32) << (8 * (3 - i));
|
||||
}
|
||||
modify_vpr32(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
element,
|
||||
element / 4,
|
||||
value,
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
} else {
|
||||
let end = std::cmp::min(element + 4, 16);
|
||||
while element < end {
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
element,
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,15 +773,28 @@ pub fn ldv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 3));
|
||||
|
||||
let mut element = velement(opcode);
|
||||
let end = std::cmp::min(element + 8, 16);
|
||||
while element < end {
|
||||
modify_vpr_byte(
|
||||
|
||||
if element % 8 == 0 {
|
||||
let mut value = 0;
|
||||
for i in 0..8 {
|
||||
value |= (device.rsp.mem[((address + i) & 0xFFF) as usize] as u64) << (8 * (7 - i));
|
||||
}
|
||||
modify_vpr64(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
element,
|
||||
element / 8,
|
||||
value,
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
} else {
|
||||
let end = std::cmp::min(element + 8, 16);
|
||||
while element < end {
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
element,
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -652,15 +803,24 @@ pub fn lqv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 4));
|
||||
|
||||
let mut element = velement(opcode);
|
||||
let end = std::cmp::min(16 + element - ((address & 15) as u8), 16);
|
||||
while element < end {
|
||||
modify_vpr_byte(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
element,
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
|
||||
if element == 0 && address % 16 == 0 {
|
||||
let mut value = 0;
|
||||
for i in 0..16 {
|
||||
value |= (device.rsp.mem[((address + i) & 0xFFF) as usize] as u128) << (8 * (15 - i));
|
||||
}
|
||||
modify_vpr128(&mut device.rsp.cpu.vpr[rt(opcode) as usize], value);
|
||||
} else {
|
||||
let end = std::cmp::min(16 + element - ((address & 15) as u8), 16);
|
||||
while element < end {
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
element,
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,14 +830,22 @@ pub fn lrv(device: &mut device::Device, opcode: u32) {
|
||||
|
||||
let mut element = 16u8.wrapping_sub(((address & 15) as u8).wrapping_sub(velement(opcode)));
|
||||
address &= !15;
|
||||
while element < 16 {
|
||||
modify_vpr_byte(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
element,
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
if element == 0 {
|
||||
let mut value = 0;
|
||||
for i in 0..16 {
|
||||
value |= (device.rsp.mem[((address + i) & 0xFFF) as usize] as u128) << (8 * (15 - i));
|
||||
}
|
||||
modify_vpr128(&mut device.rsp.cpu.vpr[rt(opcode) as usize], value);
|
||||
} else {
|
||||
while element < 16 {
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
element,
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,17 +855,15 @@ pub fn lpv(device: &mut device::Device, opcode: u32) {
|
||||
|
||||
let index = ((address & 7) as u8).wrapping_sub(velement(opcode));
|
||||
address &= !7;
|
||||
let mut offset: u8 = 0;
|
||||
while offset < 8 {
|
||||
modify_vpr_element(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
(device.rsp.mem[((address.wrapping_add(((index.wrapping_add(offset)) & 15) as u32))
|
||||
& 0xFFF) as usize] as u16)
|
||||
<< 8,
|
||||
offset,
|
||||
);
|
||||
offset += 1;
|
||||
let mut value = 0;
|
||||
for i in 0..8 {
|
||||
value |= (((device.rsp.mem
|
||||
[((address.wrapping_add(((index.wrapping_add(i)) & 15) as u32)) & 0xFFF) as usize]
|
||||
as u16)
|
||||
<< 8) as u128)
|
||||
<< (16 * (7 - i));
|
||||
}
|
||||
modify_vpr128(&mut device.rsp.cpu.vpr[rt(opcode) as usize], value);
|
||||
}
|
||||
|
||||
pub fn luv(device: &mut device::Device, opcode: u32) {
|
||||
@@ -706,17 +872,15 @@ pub fn luv(device: &mut device::Device, opcode: u32) {
|
||||
|
||||
let index = ((address & 7) as u8).wrapping_sub(velement(opcode));
|
||||
address &= !7;
|
||||
let mut offset: u8 = 0;
|
||||
while offset < 8 {
|
||||
modify_vpr_element(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
(device.rsp.mem[((address.wrapping_add(((index.wrapping_add(offset)) & 15) as u32))
|
||||
& 0xFFF) as usize] as u16)
|
||||
<< 7,
|
||||
offset,
|
||||
);
|
||||
offset += 1;
|
||||
let mut value = 0;
|
||||
for i in 0..8 {
|
||||
value |= (((device.rsp.mem
|
||||
[((address.wrapping_add(((index.wrapping_add(i)) & 15) as u32)) & 0xFFF) as usize]
|
||||
as u16)
|
||||
<< 7) as u128)
|
||||
<< (16 * (7 - i));
|
||||
}
|
||||
modify_vpr128(&mut device.rsp.cpu.vpr[rt(opcode) as usize], value);
|
||||
}
|
||||
|
||||
pub fn lhv(device: &mut device::Device, opcode: u32) {
|
||||
@@ -725,17 +889,15 @@ pub fn lhv(device: &mut device::Device, opcode: u32) {
|
||||
|
||||
let index = ((address & 7) as u8).wrapping_sub(velement(opcode));
|
||||
address &= !7;
|
||||
let mut offset: u8 = 0;
|
||||
while offset < 8 {
|
||||
modify_vpr_element(
|
||||
&mut device.rsp.cpu.vpr[rt(opcode) as usize],
|
||||
(device.rsp.mem[((address.wrapping_add(((index.wrapping_add(offset * 2)) & 15) as u32))
|
||||
& 0xFFF) as usize] as u16)
|
||||
<< 7,
|
||||
offset,
|
||||
);
|
||||
offset += 1;
|
||||
let mut value = 0;
|
||||
for i in 0..8 {
|
||||
value |= (((device.rsp.mem
|
||||
[((address.wrapping_add(((index.wrapping_add(i * 2)) & 15) as u32)) & 0xFFF) as usize]
|
||||
as u16)
|
||||
<< 7) as u128)
|
||||
<< (16 * (7 - i));
|
||||
}
|
||||
modify_vpr128(&mut device.rsp.cpu.vpr[rt(opcode) as usize], value);
|
||||
}
|
||||
|
||||
pub fn lfv(device: &mut device::Device, opcode: u32) {
|
||||
@@ -746,30 +908,30 @@ pub fn lfv(device: &mut device::Device, opcode: u32) {
|
||||
address &= !7;
|
||||
let start = velement(opcode);
|
||||
let end = std::cmp::min(start + 8, 16);
|
||||
let mut tmp: u128 = 0;
|
||||
let mut tmp: __m128i = unsafe { _mm_setzero_si128() };
|
||||
let mut offset: u8 = 0;
|
||||
while offset < 4 {
|
||||
modify_vpr_element(
|
||||
modify_vpr16(
|
||||
&mut tmp,
|
||||
offset,
|
||||
(device.rsp.mem[((address.wrapping_add(((index.wrapping_add(offset * 4)) & 15) as u32))
|
||||
& 0xFFF) as usize] as u16)
|
||||
<< 7,
|
||||
offset,
|
||||
);
|
||||
modify_vpr_element(
|
||||
modify_vpr16(
|
||||
&mut tmp,
|
||||
offset + 4,
|
||||
(device.rsp.mem[((address
|
||||
.wrapping_add(((index.wrapping_add(offset * 4).wrapping_add(8)) & 15) as u32))
|
||||
& 0xFFF) as usize] as u16)
|
||||
<< 7,
|
||||
offset + 4,
|
||||
);
|
||||
offset += 1;
|
||||
}
|
||||
offset = start;
|
||||
while offset < end {
|
||||
let value = get_vpr_byte(tmp, offset);
|
||||
modify_vpr_byte(&mut device.rsp.cpu.vpr[rt(opcode) as usize], value, offset);
|
||||
let value = get_vpr8(tmp, offset);
|
||||
modify_vpr8(&mut device.rsp.cpu.vpr[rt(opcode) as usize], offset, value);
|
||||
offset += 1;
|
||||
}
|
||||
}
|
||||
@@ -784,28 +946,26 @@ pub fn ltv(device: &mut device::Device, opcode: u32) {
|
||||
address = begin + (((velement(opcode)) as u32 + (address & 8)) & 15);
|
||||
let vtbase = rt(opcode) & !7;
|
||||
let mut vtoff = (velement(opcode)) as u32 >> 1;
|
||||
let mut i = 0;
|
||||
while i < 8 {
|
||||
modify_vpr_byte(
|
||||
for i in 0..8 {
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[(vtbase + vtoff) as usize],
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
i * 2,
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
);
|
||||
address += 1;
|
||||
if address == begin + 16 {
|
||||
address = begin
|
||||
}
|
||||
modify_vpr_byte(
|
||||
modify_vpr8(
|
||||
&mut device.rsp.cpu.vpr[(vtbase + vtoff) as usize],
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
i * 2 + 1,
|
||||
device.rsp.mem[(address & 0xFFF) as usize],
|
||||
);
|
||||
address += 1;
|
||||
if address == begin + 16 {
|
||||
address = begin
|
||||
}
|
||||
vtoff = (vtoff + 1) & 7;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -814,7 +974,7 @@ pub fn sbv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 0));
|
||||
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], velement(opcode))
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], velement(opcode))
|
||||
}
|
||||
|
||||
pub fn ssv(device: &mut device::Device, opcode: u32) {
|
||||
@@ -822,12 +982,20 @@ pub fn ssv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 1));
|
||||
|
||||
let mut element = velement(opcode);
|
||||
let end = element + 2;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
address += 1;
|
||||
element += 1;
|
||||
|
||||
if element % 2 == 0 {
|
||||
let start = (address & 0xFFF) as usize;
|
||||
device.rsp.mem[start..start + 2].copy_from_slice(
|
||||
&get_vpr16(device.rsp.cpu.vpr[rt(opcode) as usize], element / 2).to_be_bytes(),
|
||||
);
|
||||
} else {
|
||||
let end = element + 2;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -836,12 +1004,20 @@ pub fn slv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 2));
|
||||
|
||||
let mut element = velement(opcode);
|
||||
let end = element + 4;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
address += 1;
|
||||
element += 1;
|
||||
|
||||
if element % 4 == 0 {
|
||||
let start = (address & 0xFFF) as usize;
|
||||
device.rsp.mem[start..start + 4].copy_from_slice(
|
||||
&get_vpr32(device.rsp.cpu.vpr[rt(opcode) as usize], element / 4).to_be_bytes(),
|
||||
);
|
||||
} else {
|
||||
let end = element + 4;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -850,12 +1026,20 @@ pub fn sdv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 3));
|
||||
|
||||
let mut element = velement(opcode);
|
||||
let end = element + 8;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
address += 1;
|
||||
element += 1;
|
||||
|
||||
if element % 8 == 0 {
|
||||
let start = (address & 0xFFF) as usize;
|
||||
device.rsp.mem[start..start + 8].copy_from_slice(
|
||||
&get_vpr64(device.rsp.cpu.vpr[rt(opcode) as usize], element / 8).to_be_bytes(),
|
||||
);
|
||||
} else {
|
||||
let end = element + 8;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -864,12 +1048,19 @@ pub fn sqv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 4));
|
||||
|
||||
let mut element = velement(opcode);
|
||||
let end = element + (16 - (address & 15)) as u8;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
address += 1;
|
||||
element += 1;
|
||||
|
||||
if element == 0 && address % 16 == 0 {
|
||||
let start = (address & 0xFFF) as usize;
|
||||
device.rsp.mem[start..start + 16]
|
||||
.copy_from_slice(&get_vpr128(device.rsp.cpu.vpr[rt(opcode) as usize]).to_be_bytes());
|
||||
} else {
|
||||
let end = element + (16 - (address & 15)) as u8;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -881,11 +1072,18 @@ pub fn srv(device: &mut device::Device, opcode: u32) {
|
||||
let end = element + (address & 15) as u8;
|
||||
let base = (16 - (address & 15)) as u8;
|
||||
address &= !15;
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], element + base);
|
||||
address += 1;
|
||||
element += 1;
|
||||
|
||||
if element == 0 && base == 0 {
|
||||
let start = (address & 0xFFF) as usize;
|
||||
device.rsp.mem[start..start + 16]
|
||||
.copy_from_slice(&get_vpr128(device.rsp.cpu.vpr[rt(opcode) as usize]).to_be_bytes());
|
||||
} else {
|
||||
while element < end {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], element + base);
|
||||
address += 1;
|
||||
element += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -898,10 +1096,10 @@ pub fn spv(device: &mut device::Device, opcode: u32) {
|
||||
while element < end {
|
||||
if (element & 15) < 8 {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], (element & 7) << 1);
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], (element & 7) << 1);
|
||||
} else {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
(get_vpr_element(device.rsp.cpu.vpr[rt(opcode) as usize], element) >> 7) as u8;
|
||||
(get_vpr16(device.rsp.cpu.vpr[rt(opcode) as usize], element) >> 7) as u8;
|
||||
}
|
||||
address += 1;
|
||||
element += 1;
|
||||
@@ -917,10 +1115,10 @@ pub fn suv(device: &mut device::Device, opcode: u32) {
|
||||
while element < end {
|
||||
if (element & 15) < 8 {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
(get_vpr_element(device.rsp.cpu.vpr[rt(opcode) as usize], element) >> 7) as u8;
|
||||
(get_vpr16(device.rsp.cpu.vpr[rt(opcode) as usize], element) >> 7) as u8;
|
||||
} else {
|
||||
device.rsp.mem[(address & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], (element & 7) << 1);
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], (element & 7) << 1);
|
||||
}
|
||||
address += 1;
|
||||
element += 1;
|
||||
@@ -934,13 +1132,11 @@ pub fn shv(device: &mut device::Device, opcode: u32) {
|
||||
let element = velement(opcode);
|
||||
let index = (address & 7) as u8;
|
||||
address &= !7;
|
||||
let mut offset = 0;
|
||||
while offset < 8 {
|
||||
for offset in 0..8 {
|
||||
let byte_val = element + offset * 2;
|
||||
let value = (get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val) << 1)
|
||||
| (get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val + 1) >> 7);
|
||||
let value = (get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val) << 1)
|
||||
| (get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val + 1) >> 7);
|
||||
device.rsp.mem[((address + ((index + offset * 2) & 15) as u32) & 0xFFF) as usize] = value;
|
||||
offset += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,8 +1145,7 @@ pub fn sfv(device: &mut device::Device, opcode: u32) {
|
||||
.wrapping_add(sign_extend_7bit_offset(voffset(opcode), 4));
|
||||
let base = address & 7;
|
||||
address &= !7;
|
||||
let element = velement(opcode);
|
||||
let elements = match element {
|
||||
let elements = match velement(opcode) {
|
||||
0 | 15 => [0, 1, 2, 3],
|
||||
1 => [6, 7, 4, 5],
|
||||
4 => [1, 2, 3, 0],
|
||||
@@ -967,12 +1162,10 @@ pub fn sfv(device: &mut device::Device, opcode: u32) {
|
||||
}
|
||||
};
|
||||
let mut offset = 0;
|
||||
let mut i = 0;
|
||||
while i < 4 {
|
||||
for element in elements {
|
||||
device.rsp.mem[((address + ((base + offset) & 15)) & 0xFFF) as usize] =
|
||||
(get_vpr_element(device.rsp.cpu.vpr[rt(opcode) as usize], elements[i]) >> 7) as u8;
|
||||
(get_vpr16(device.rsp.cpu.vpr[rt(opcode) as usize], element) >> 7) as u8;
|
||||
offset += 4;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -986,7 +1179,7 @@ pub fn swv(device: &mut device::Device, opcode: u32) {
|
||||
address &= !7;
|
||||
while element < end {
|
||||
device.rsp.mem[((address + (base & 15)) & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
get_vpr8(device.rsp.cpu.vpr[rt(opcode) as usize], element);
|
||||
base += 1;
|
||||
element += 1;
|
||||
}
|
||||
@@ -1003,11 +1196,11 @@ pub fn stv(device: &mut device::Device, opcode: u32) {
|
||||
let mut offset = start;
|
||||
while offset < end {
|
||||
device.rsp.mem[((address + (base & 15)) & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[offset as usize], element);
|
||||
get_vpr8(device.rsp.cpu.vpr[offset as usize], element);
|
||||
base = base.wrapping_add(1);
|
||||
element += 1;
|
||||
device.rsp.mem[((address + (base & 15)) & 0xFFF) as usize] =
|
||||
get_vpr_byte(device.rsp.cpu.vpr[offset as usize], element);
|
||||
get_vpr8(device.rsp.cpu.vpr[offset as usize], element);
|
||||
base = base.wrapping_add(1);
|
||||
element += 1;
|
||||
offset += 1;
|
||||
|
||||
+196
-669
File diff suppressed because it is too large
Load Diff
+9
-9
@@ -1,18 +1,18 @@
|
||||
use crate::device;
|
||||
|
||||
pub const SI_DRAM_ADDR_REG: u32 = 0;
|
||||
pub const SI_PIF_ADDR_RD64B_REG: u32 = 1;
|
||||
//pub const SI_R2_REG: u32 = 2;
|
||||
//pub const SI_R3_REG: u32 = 3;
|
||||
pub const SI_PIF_ADDR_WR64B_REG: u32 = 4;
|
||||
//pub const SI_R5_REG: u32 = 5;
|
||||
const SI_DRAM_ADDR_REG: u32 = 0;
|
||||
const SI_PIF_ADDR_RD64B_REG: u32 = 1;
|
||||
//const SI_R2_REG: u32 = 2;
|
||||
//const SI_R3_REG: u32 = 3;
|
||||
const SI_PIF_ADDR_WR64B_REG: u32 = 4;
|
||||
//const SI_R5_REG: u32 = 5;
|
||||
pub const SI_STATUS_REG: u32 = 6;
|
||||
pub const SI_REGS_COUNT: u32 = 7;
|
||||
|
||||
pub const SI_STATUS_DMA_BUSY: u32 = 1 << 0;
|
||||
pub const SI_STATUS_IO_BUSY: u32 = 1 << 1;
|
||||
//pub const SI_STATUS_DMA_ERROR: u32 = 1 << 3;
|
||||
pub const SI_STATUS_INTERRUPT: u32 = 1 << 12;
|
||||
//const SI_STATUS_DMA_ERROR: u32 = 1 << 3;
|
||||
const SI_STATUS_INTERRUPT: u32 = 1 << 12;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum DmaDir {
|
||||
@@ -59,7 +59,7 @@ pub fn dma_write(device: &mut device::Device) {
|
||||
device::events::create_event(
|
||||
device,
|
||||
device::events::EventType::SI,
|
||||
device.cpu.cop0.regs[device::cop0::COP0_COUNT_REG as usize] + 5200, //based on https://github.com/rasky/n64-systembench
|
||||
device.cpu.cop0.regs[device::cop0::COP0_COUNT_REG as usize] + 6000, //based on https://github.com/rasky/n64-systembench
|
||||
dma_event,
|
||||
)
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,13 +1,13 @@
|
||||
use crate::device;
|
||||
use crate::ui;
|
||||
|
||||
pub const SRAM_MASK: usize = 0xFFFF;
|
||||
pub const SRAM_SIZE: usize = 0x8000;
|
||||
pub const FLASHRAM_SIZE: usize = 0x20000;
|
||||
const SRAM_MASK: usize = 0xFFFF;
|
||||
const SRAM_SIZE: usize = 0x8000;
|
||||
const FLASHRAM_SIZE: usize = 0x20000;
|
||||
pub const FLASHRAM_TYPE_ID: u32 = 0x11118001;
|
||||
pub const MX29L1100_ID: u32 = 0x00c2001e;
|
||||
pub const MX29L0000_ID: u32 = 0x00c20000;
|
||||
pub const MX29L0001_ID: u32 = 0x00c20001;
|
||||
const MX29L0000_ID: u32 = 0x00c20000;
|
||||
const MX29L0001_ID: u32 = 0x00c20001;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum FlashramMode {
|
||||
|
||||
+10
-10
@@ -2,18 +2,18 @@ use crate::device;
|
||||
use crate::ui;
|
||||
use governor::clock::Clock;
|
||||
|
||||
pub const VI_STATUS_REG: u32 = 0;
|
||||
//pub const VI_ORIGIN_REG: u32 = 1;
|
||||
const VI_STATUS_REG: u32 = 0;
|
||||
//const VI_ORIGIN_REG: u32 = 1;
|
||||
pub const VI_WIDTH_REG: u32 = 2;
|
||||
//pub const VI_V_INTR_REG: u32 = 3;
|
||||
pub const VI_CURRENT_REG: u32 = 4;
|
||||
//pub const VI_BURST_REG: u32 = 5;
|
||||
pub const VI_V_SYNC_REG: u32 = 6;
|
||||
pub const VI_H_SYNC_REG: u32 = 7;
|
||||
//pub const VI_LEAP_REG: u32 = 8;
|
||||
//const VI_V_INTR_REG: u32 = 3;
|
||||
const VI_CURRENT_REG: u32 = 4;
|
||||
//const VI_BURST_REG: u32 = 5;
|
||||
const VI_V_SYNC_REG: u32 = 6;
|
||||
const VI_H_SYNC_REG: u32 = 7;
|
||||
//const VI_LEAP_REG: u32 = 8;
|
||||
pub const VI_H_START_REG: u32 = 9;
|
||||
pub const VI_V_START_REG: u32 = 10;
|
||||
//pub const VI_V_BURST_REG: u32 = 11;
|
||||
//const VI_V_BURST_REG: u32 = 11;
|
||||
pub const VI_X_SCALE_REG: u32 = 12;
|
||||
pub const VI_Y_SCALE_REG: u32 = 13;
|
||||
pub const VI_REGS_COUNT: u32 = 14;
|
||||
@@ -169,6 +169,6 @@ pub fn speed_limiter(device: &device::Device) {
|
||||
let dur = outcome.wait_time_from(governor::clock::DefaultClock::default().now());
|
||||
spin_sleep::sleep(dur);
|
||||
|
||||
device.vi.limiter.as_ref().unwrap().check().unwrap();
|
||||
let _ = device.vi.limiter.as_ref().unwrap().check();
|
||||
}
|
||||
}
|
||||
|
||||
+50
-8
@@ -1,4 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
mod device;
|
||||
mod ui;
|
||||
@@ -18,6 +20,12 @@ struct Args {
|
||||
help = "Create a new input profile (keyboard/gamepad mappings)."
|
||||
)]
|
||||
configure_input_profile: Option<String>,
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
help = "Use DirectInput when configuring a new input profile."
|
||||
)]
|
||||
use_dinput: bool,
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
@@ -54,18 +62,47 @@ struct Args {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let config_dir = dirs::config_dir().unwrap().join("gopher64");
|
||||
let cache_dir = dirs::cache_dir().unwrap().join("gopher64");
|
||||
let exe_path = std::env::current_exe().unwrap();
|
||||
let portable_dir = exe_path.parent();
|
||||
let portable = portable_dir.unwrap().join("portable.txt").exists();
|
||||
let config_dir;
|
||||
let cache_dir;
|
||||
let data_dir;
|
||||
if portable {
|
||||
config_dir = portable_dir.unwrap().join("portable_data").join("config");
|
||||
cache_dir = portable_dir.unwrap().join("portable_data").join("cache");
|
||||
data_dir = portable_dir.unwrap().join("portable_data").join("data");
|
||||
} else {
|
||||
config_dir = dirs::config_dir().unwrap().join("gopher64");
|
||||
cache_dir = dirs::cache_dir().unwrap().join("gopher64");
|
||||
data_dir = dirs::data_dir().unwrap().join("gopher64");
|
||||
};
|
||||
|
||||
let _ = std::fs::create_dir_all(config_dir.clone());
|
||||
let _ = std::fs::create_dir_all(cache_dir.clone());
|
||||
let _ = std::fs::remove_file(cache_dir.clone().join("game_running"));
|
||||
let mut result = std::fs::create_dir_all(config_dir.clone());
|
||||
if result.is_err() {
|
||||
panic!("could not create config dir: {}", result.err().unwrap())
|
||||
}
|
||||
result = std::fs::create_dir_all(cache_dir.clone());
|
||||
if result.is_err() {
|
||||
panic!("could not create cache dir: {}", result.err().unwrap())
|
||||
}
|
||||
result = std::fs::create_dir_all(data_dir.clone().join("saves"));
|
||||
if result.is_err() {
|
||||
panic!("could not create data dir: {}", result.err().unwrap())
|
||||
}
|
||||
let running_file = cache_dir.join("game_running");
|
||||
if running_file.exists() {
|
||||
result = std::fs::remove_file(running_file);
|
||||
if result.is_err() {
|
||||
panic!("could not remove running file: {}", result.err().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
let args = Args::parse();
|
||||
let args_as_strings: Vec<String> = std::env::args().collect();
|
||||
let args_count = args_as_strings.len();
|
||||
if args_count > 1 {
|
||||
let mut device = device::Device::new();
|
||||
let mut device = device::Device::new(config_dir);
|
||||
|
||||
if args.clear_input_bindings {
|
||||
ui::input::clear_bindings(&mut device.ui);
|
||||
@@ -110,13 +147,14 @@ fn main() {
|
||||
ui::input::configure_input_profile(
|
||||
&mut device.ui,
|
||||
args.configure_input_profile.unwrap(),
|
||||
args.use_dinput,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if args.game.is_some() {
|
||||
let file_path = std::path::Path::new(args.game.as_ref().unwrap());
|
||||
device::run_game(file_path, &mut device, args.fullscreen);
|
||||
device::run_game(file_path, data_dir, &mut device, args.fullscreen);
|
||||
}
|
||||
} else {
|
||||
let options = eframe::NativeOptions {
|
||||
@@ -126,7 +164,11 @@ fn main() {
|
||||
eframe::run_native(
|
||||
"gopher64",
|
||||
options,
|
||||
Box::new(|_cc| Ok(Box::new(ui::gui::GopherEguiApp::new()))),
|
||||
Box::new(|cc| {
|
||||
Ok(Box::new(ui::gui::GopherEguiApp::new(
|
||||
cc, config_dir, cache_dir, data_dir,
|
||||
)))
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ pub mod gui;
|
||||
pub mod input;
|
||||
pub mod storage;
|
||||
pub mod video;
|
||||
pub mod vru;
|
||||
|
||||
pub struct Ui {
|
||||
pub controllers: [input::Controllers; 4],
|
||||
@@ -17,6 +18,7 @@ pub struct Ui {
|
||||
pub sdl_context: Option<sdl2::Sdl>,
|
||||
pub video_subsystem: Option<sdl2::VideoSubsystem>,
|
||||
pub audio_subsystem: Option<sdl2::AudioSubsystem>,
|
||||
pub pak_audio: Option<audio::PakAudio>,
|
||||
pub joystick_subsystem: Option<sdl2::JoystickSubsystem>,
|
||||
#[allow(dead_code)]
|
||||
pub controller_subsystem: Option<sdl2::GameControllerSubsystem>,
|
||||
@@ -36,17 +38,14 @@ fn write_config(ui: &Ui) {
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub fn new() -> Ui {
|
||||
pub fn new(config_dir: std::path::PathBuf) -> Ui {
|
||||
let sdl_context = sdl2::init().unwrap();
|
||||
let video_subsystem = sdl_context.video().unwrap();
|
||||
let audio_subsystem = sdl_context.audio().unwrap();
|
||||
let joystick_subsystem = sdl_context.joystick().unwrap();
|
||||
let controller_subsystem = sdl_context.game_controller().unwrap();
|
||||
|
||||
let config_file_path = dirs::config_dir()
|
||||
.unwrap()
|
||||
.join("gopher64")
|
||||
.join("config.json");
|
||||
let config_file_path = config_dir.join("config.json");
|
||||
let config_file = std::fs::read(config_file_path.clone());
|
||||
let mut config_map = config::Config::new();
|
||||
if config_file.is_ok() {
|
||||
@@ -61,18 +60,22 @@ impl Ui {
|
||||
input::Controllers {
|
||||
game_controller: None,
|
||||
joystick: None,
|
||||
rumble: false,
|
||||
},
|
||||
input::Controllers {
|
||||
game_controller: None,
|
||||
joystick: None,
|
||||
rumble: false,
|
||||
},
|
||||
input::Controllers {
|
||||
game_controller: None,
|
||||
joystick: None,
|
||||
rumble: false,
|
||||
},
|
||||
input::Controllers {
|
||||
game_controller: None,
|
||||
joystick: None,
|
||||
rumble: false,
|
||||
},
|
||||
],
|
||||
config_file_path,
|
||||
@@ -101,6 +104,7 @@ impl Ui {
|
||||
controller_subsystem: Some(controller_subsystem),
|
||||
window: None,
|
||||
audio_device: None,
|
||||
pak_audio: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+54
-3
@@ -1,6 +1,11 @@
|
||||
use crate::device;
|
||||
use crate::ui;
|
||||
|
||||
pub struct PakAudio {
|
||||
mempak: Vec<u8>,
|
||||
rumblepak: Vec<u8>,
|
||||
}
|
||||
|
||||
pub fn init(ui: &mut ui::Ui, frequency: u64) {
|
||||
let desired_spec = sdl2::audio::AudioSpecDesired {
|
||||
freq: Some(frequency as i32),
|
||||
@@ -9,16 +14,62 @@ pub fn init(ui: &mut ui::Ui, frequency: u64) {
|
||||
};
|
||||
ui.audio_device = Some(
|
||||
ui.audio_subsystem
|
||||
.as_mut()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.open_queue::<i16, _>(None, &desired_spec)
|
||||
.unwrap(),
|
||||
);
|
||||
ui.audio_device.as_mut().unwrap().resume();
|
||||
let audio_device = ui.audio_device.as_ref().unwrap();
|
||||
audio_device.resume();
|
||||
|
||||
let mempak_audio = Box::new(sdl2::audio::AudioSpecWAV::load_wav_rw(
|
||||
&mut sdl2::rwops::RWops::from_bytes(include_bytes!("../../data/mempak.wav"))
|
||||
.expect("Could not mempak WAV file"),
|
||||
))
|
||||
.expect("Could not load mempak WAV file");
|
||||
let rumblepak_audio = Box::new(
|
||||
sdl2::audio::AudioSpecWAV::load_wav_rw(
|
||||
&mut sdl2::rwops::RWops::from_bytes(include_bytes!("../../data/rumblepak.wav"))
|
||||
.expect("Could not load rumblepak WAV file"),
|
||||
)
|
||||
.expect("Could not load rumblepak WAV file"),
|
||||
);
|
||||
|
||||
let cvt = sdl2::audio::AudioCVT::new(
|
||||
mempak_audio.format,
|
||||
mempak_audio.channels,
|
||||
mempak_audio.freq,
|
||||
audio_device.spec().format,
|
||||
audio_device.spec().channels,
|
||||
audio_device.spec().freq,
|
||||
)
|
||||
.expect("Could not create AudioCVT");
|
||||
|
||||
ui.pak_audio = Some(PakAudio {
|
||||
mempak: cvt.convert(mempak_audio.buffer().to_vec()),
|
||||
rumblepak: cvt.convert(rumblepak_audio.buffer().to_vec()),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn play_pak_switch(ui: &mut ui::Ui, pak: device::controller::PakType) {
|
||||
let sound;
|
||||
if pak == device::controller::PakType::RumblePak {
|
||||
sound = &ui.pak_audio.as_ref().unwrap().rumblepak;
|
||||
} else if pak == device::controller::PakType::MemPak {
|
||||
sound = &ui.pak_audio.as_ref().unwrap().mempak;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
let audio_device = ui.audio_device.as_ref().unwrap();
|
||||
let i16_buffer: Vec<i16> = sound
|
||||
.chunks_exact(2)
|
||||
.map(|chunk| i16::from_le_bytes([chunk[0], chunk[1]]))
|
||||
.collect();
|
||||
audio_device.queue_audio(&i16_buffer).unwrap();
|
||||
}
|
||||
|
||||
pub fn play_audio(device: &mut device::Device, dram_addr: usize, length: u64) {
|
||||
let audio_device = device.ui.audio_device.as_mut().unwrap();
|
||||
let audio_device = device.ui.audio_device.as_ref().unwrap();
|
||||
let mut primary_buffer: Vec<i16> = vec![0; length as usize / 2];
|
||||
let mut i = 0;
|
||||
while i < length as usize / 2 {
|
||||
|
||||
+23
-6
@@ -2,12 +2,13 @@ use crate::ui;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct InputProfile {
|
||||
pub keys: [(bool, i32); 18],
|
||||
pub controller_buttons: [(bool, i32); 14],
|
||||
pub controller_axis: [(bool, i32, i16); 18],
|
||||
pub joystick_buttons: [(bool, u32); 14],
|
||||
pub joystick_hat: [(bool, u32, i8); 14],
|
||||
pub joystick_axis: [(bool, u32, i16); 18],
|
||||
pub keys: [(bool, i32); ui::input::PROFILE_SIZE],
|
||||
pub controller_buttons: [(bool, i32); ui::input::PROFILE_SIZE],
|
||||
pub controller_axis: [(bool, i32, i16); ui::input::PROFILE_SIZE],
|
||||
pub joystick_buttons: [(bool, u32); ui::input::PROFILE_SIZE],
|
||||
pub joystick_hat: [(bool, u32, u8); ui::input::PROFILE_SIZE],
|
||||
pub joystick_axis: [(bool, u32, i16); ui::input::PROFILE_SIZE],
|
||||
pub dinput: bool,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
@@ -15,10 +16,19 @@ pub struct Input {
|
||||
pub input_profiles: std::collections::HashMap<String, InputProfile>,
|
||||
pub input_profile_binding: [String; 4],
|
||||
pub controller_assignment: [Option<String>; 4],
|
||||
pub controller_enabled: [bool; 4],
|
||||
pub emulate_vru: bool,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct Video {
|
||||
pub upscale: bool,
|
||||
pub integer_scaling: bool,
|
||||
pub fullscreen: bool,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct Config {
|
||||
pub input: Input,
|
||||
pub video: Video,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -35,6 +45,13 @@ impl Config {
|
||||
],
|
||||
controller_assignment: [None, None, None, None],
|
||||
input_profiles,
|
||||
controller_enabled: [true, false, false, false],
|
||||
emulate_vru: false,
|
||||
},
|
||||
video: Video {
|
||||
upscale: false,
|
||||
integer_scaling: false,
|
||||
fullscreen: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
+211
-29
@@ -3,12 +3,35 @@ use crate::ui;
|
||||
use eframe::egui;
|
||||
|
||||
pub struct GopherEguiApp {
|
||||
config_dir: std::path::PathBuf,
|
||||
cache_dir: std::path::PathBuf,
|
||||
data_dir: std::path::PathBuf,
|
||||
configure_profile: bool,
|
||||
profile_name: String,
|
||||
controllers: Vec<String>,
|
||||
selected_controller: [i32; 4],
|
||||
selected_profile: [String; 4],
|
||||
input_profiles: Vec<String>,
|
||||
controller_enabled: [bool; 4],
|
||||
upscale: bool,
|
||||
integer_scaling: bool,
|
||||
fullscreen: bool,
|
||||
emulate_vru: bool,
|
||||
dinput: bool,
|
||||
show_vru_dialog: bool,
|
||||
vru_window_receiver: Option<std::sync::mpsc::Receiver<Vec<String>>>,
|
||||
vru_word_notifier: Option<std::sync::mpsc::Sender<String>>,
|
||||
vru_word_list: Vec<String>,
|
||||
}
|
||||
|
||||
struct SaveConfig {
|
||||
selected_controller: [i32; 4],
|
||||
selected_profile: [String; 4],
|
||||
controller_enabled: [bool; 4],
|
||||
upscale: bool,
|
||||
integer_scaling: bool,
|
||||
fullscreen: bool,
|
||||
emulate_vru: bool,
|
||||
}
|
||||
|
||||
fn get_input_profiles(game_ui: &ui::Ui) -> Vec<String> {
|
||||
@@ -31,8 +54,14 @@ fn get_controllers(game_ui: &ui::Ui) -> Vec<String> {
|
||||
}
|
||||
|
||||
impl GopherEguiApp {
|
||||
pub fn new() -> GopherEguiApp {
|
||||
let game_ui = ui::Ui::new();
|
||||
pub fn new(
|
||||
cc: &eframe::CreationContext<'_>,
|
||||
config_dir: std::path::PathBuf,
|
||||
cache_dir: std::path::PathBuf,
|
||||
data_dir: std::path::PathBuf,
|
||||
) -> GopherEguiApp {
|
||||
add_japanese_font(&cc.egui_ctx);
|
||||
let game_ui = ui::Ui::new(config_dir.clone());
|
||||
let joystick_subsystem = game_ui.joystick_subsystem.as_ref().unwrap();
|
||||
let num_joysticks = joystick_subsystem.num_joysticks().unwrap();
|
||||
let mut guids: Vec<String> = vec![];
|
||||
@@ -57,19 +86,32 @@ impl GopherEguiApp {
|
||||
}
|
||||
}
|
||||
GopherEguiApp {
|
||||
cache_dir: cache_dir.clone(),
|
||||
config_dir: config_dir.clone(),
|
||||
data_dir: data_dir.clone(),
|
||||
configure_profile: false,
|
||||
profile_name: "".to_string(),
|
||||
selected_profile: game_ui.config.input.input_profile_binding.clone(),
|
||||
selected_controller,
|
||||
controllers: get_controllers(&game_ui),
|
||||
input_profiles: get_input_profiles(&game_ui),
|
||||
controller_enabled: game_ui.config.input.controller_enabled,
|
||||
upscale: game_ui.config.video.upscale,
|
||||
integer_scaling: game_ui.config.video.integer_scaling,
|
||||
fullscreen: game_ui.config.video.fullscreen,
|
||||
emulate_vru: game_ui.config.input.emulate_vru,
|
||||
show_vru_dialog: false,
|
||||
dinput: false,
|
||||
vru_window_receiver: None,
|
||||
vru_word_notifier: None,
|
||||
vru_word_list: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn save_config(game_ui: &mut ui::Ui, selected_controller: [i32; 4], selected_profile: [String; 4]) {
|
||||
fn save_config(game_ui: &mut ui::Ui, save_config_items: SaveConfig) {
|
||||
let joystick_subsystem = game_ui.joystick_subsystem.as_ref().unwrap();
|
||||
for (pos, item) in selected_controller.iter().enumerate() {
|
||||
for (pos, item) in save_config_items.selected_controller.iter().enumerate() {
|
||||
if *item != -1 {
|
||||
game_ui.config.input.controller_assignment[pos] = Some(
|
||||
joystick_subsystem
|
||||
@@ -82,17 +124,28 @@ fn save_config(game_ui: &mut ui::Ui, selected_controller: [i32; 4], selected_pro
|
||||
}
|
||||
}
|
||||
|
||||
game_ui.config.input.input_profile_binding = selected_profile;
|
||||
game_ui.config.input.input_profile_binding = save_config_items.selected_profile;
|
||||
game_ui.config.input.controller_enabled = save_config_items.controller_enabled;
|
||||
|
||||
game_ui.config.video.upscale = save_config_items.upscale;
|
||||
game_ui.config.video.integer_scaling = save_config_items.integer_scaling;
|
||||
game_ui.config.video.fullscreen = save_config_items.fullscreen;
|
||||
game_ui.config.input.emulate_vru = save_config_items.emulate_vru;
|
||||
}
|
||||
|
||||
impl Drop for GopherEguiApp {
|
||||
fn drop(&mut self) {
|
||||
let mut game_ui = ui::Ui::new();
|
||||
save_config(
|
||||
&mut game_ui,
|
||||
self.selected_controller,
|
||||
self.selected_profile.clone(),
|
||||
);
|
||||
let mut game_ui = ui::Ui::new(self.config_dir.clone());
|
||||
let save_config_items = SaveConfig {
|
||||
selected_controller: self.selected_controller,
|
||||
selected_profile: self.selected_profile.clone(),
|
||||
controller_enabled: self.controller_enabled,
|
||||
upscale: self.upscale,
|
||||
integer_scaling: self.integer_scaling,
|
||||
fullscreen: self.fullscreen,
|
||||
emulate_vru: self.emulate_vru,
|
||||
};
|
||||
save_config(&mut game_ui, save_config_items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,12 +160,19 @@ impl eframe::App for GopherEguiApp {
|
||||
ui.text_edit_singleline(&mut self.profile_name)
|
||||
.labelled_by(name_label.id);
|
||||
});
|
||||
ui.checkbox(&mut self.dinput, "Use DirectInput");
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Configure Profile").clicked() {
|
||||
let profile_name = self.profile_name.clone();
|
||||
execute(async {
|
||||
let mut game_ui = ui::Ui::new();
|
||||
ui::input::configure_input_profile(&mut game_ui, profile_name);
|
||||
let config_dir = self.config_dir.clone();
|
||||
let dinput = self.dinput;
|
||||
execute(async move {
|
||||
let mut game_ui = ui::Ui::new(config_dir);
|
||||
ui::input::configure_input_profile(
|
||||
&mut game_ui,
|
||||
profile_name,
|
||||
dinput,
|
||||
);
|
||||
});
|
||||
self.configure_profile = false;
|
||||
if !self.profile_name.is_empty()
|
||||
@@ -138,32 +198,77 @@ impl eframe::App for GopherEguiApp {
|
||||
let task = rfd::AsyncFileDialog::new().pick_file();
|
||||
let selected_controller = self.selected_controller;
|
||||
let selected_profile = self.selected_profile.clone();
|
||||
let controller_enabled = self.controller_enabled;
|
||||
let upscale = self.upscale;
|
||||
let integer_scaling = self.integer_scaling;
|
||||
let fullscreen = self.fullscreen;
|
||||
let emulate_vru = self.emulate_vru;
|
||||
let config_dir = self.config_dir.clone();
|
||||
let cache_dir = self.cache_dir.clone();
|
||||
let data_dir = self.data_dir.clone();
|
||||
|
||||
let (vru_window_notifier, vru_window_receiver): (
|
||||
std::sync::mpsc::Sender<Vec<String>>,
|
||||
std::sync::mpsc::Receiver<Vec<String>>,
|
||||
) = std::sync::mpsc::channel();
|
||||
|
||||
let (vru_word_notifier, vru_word_receiver): (
|
||||
std::sync::mpsc::Sender<String>,
|
||||
std::sync::mpsc::Receiver<String>,
|
||||
) = std::sync::mpsc::channel();
|
||||
|
||||
if emulate_vru {
|
||||
self.vru_window_receiver = Some(vru_window_receiver);
|
||||
self.vru_word_notifier = Some(vru_word_notifier);
|
||||
}
|
||||
|
||||
let gui_ctx = ctx.clone();
|
||||
execute(async move {
|
||||
let file = task.await;
|
||||
|
||||
if let Some(file) = file {
|
||||
let running_file = dirs::cache_dir()
|
||||
.unwrap()
|
||||
.join("gopher64")
|
||||
.join("game_running");
|
||||
let running_file = cache_dir.join("game_running");
|
||||
if running_file.exists() {
|
||||
return;
|
||||
}
|
||||
let _ = std::fs::File::create(running_file.clone());
|
||||
let mut device = device::Device::new();
|
||||
save_config(&mut device.ui, selected_controller, selected_profile);
|
||||
device::run_game(std::path::Path::new(file.path()), &mut device, false);
|
||||
let _ = std::fs::remove_file(running_file.clone());
|
||||
let result = std::fs::File::create(running_file.clone());
|
||||
if result.is_err() {
|
||||
panic!("could not create running file: {}", result.err().unwrap())
|
||||
}
|
||||
let mut device = device::Device::new(config_dir);
|
||||
|
||||
let save_config_items = SaveConfig {
|
||||
selected_controller,
|
||||
selected_profile,
|
||||
controller_enabled,
|
||||
upscale,
|
||||
integer_scaling,
|
||||
fullscreen,
|
||||
emulate_vru,
|
||||
};
|
||||
save_config(&mut device.ui, save_config_items);
|
||||
|
||||
if emulate_vru {
|
||||
device.vru.window_notifier = Some(vru_window_notifier);
|
||||
device.vru.word_receiver = Some(vru_word_receiver);
|
||||
device.vru.gui_ctx = Some(gui_ctx);
|
||||
}
|
||||
device::run_game(
|
||||
std::path::Path::new(file.path()),
|
||||
data_dir,
|
||||
&mut device,
|
||||
fullscreen,
|
||||
);
|
||||
let result = std::fs::remove_file(running_file.clone());
|
||||
if result.is_err() {
|
||||
panic!("could not remove running file: {}", result.err().unwrap())
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ui.button("Configure Input Profile").clicked() {
|
||||
let running_file = dirs::cache_dir()
|
||||
.unwrap()
|
||||
.join("gopher64")
|
||||
.join("game_running");
|
||||
if running_file.exists() {
|
||||
if self.cache_dir.join("game_running").exists() {
|
||||
return;
|
||||
}
|
||||
self.configure_profile = true;
|
||||
@@ -171,13 +276,15 @@ impl eframe::App for GopherEguiApp {
|
||||
|
||||
ui.add_space(32.0);
|
||||
ui.label("Controller Config:");
|
||||
egui::Grid::new("some_unique_id").show(ui, |ui| {
|
||||
egui::Grid::new("controller_config").show(ui, |ui| {
|
||||
ui.label("Port");
|
||||
ui.label("Enabled");
|
||||
ui.label("Profile");
|
||||
ui.label("Controller");
|
||||
ui.end_row();
|
||||
for i in 0..4 {
|
||||
ui.label(format!("{}", i + 1));
|
||||
ui.checkbox(&mut self.controller_enabled[i], "");
|
||||
|
||||
egui::ComboBox::from_id_salt(format!("profile-combo-{}", i))
|
||||
.selected_text(self.selected_profile[i].clone())
|
||||
@@ -216,11 +323,86 @@ impl eframe::App for GopherEguiApp {
|
||||
}
|
||||
});
|
||||
ui.add_space(32.0);
|
||||
ui.checkbox(&mut self.upscale, "High-Res Graphics");
|
||||
ui.checkbox(&mut self.integer_scaling, "Integer Scaling");
|
||||
ui.checkbox(&mut self.fullscreen, "Fullscreen (Esc closes game)");
|
||||
ui.add_space(32.0);
|
||||
ui.checkbox(
|
||||
&mut self.emulate_vru,
|
||||
"Emulate VRU (connects VRU to controller port 4)",
|
||||
);
|
||||
ui.add_space(32.0);
|
||||
ui.label(format!("Version: {}", env!("CARGO_PKG_VERSION")));
|
||||
});
|
||||
|
||||
if self.emulate_vru && self.vru_window_receiver.is_some() {
|
||||
let result = self.vru_window_receiver.as_ref().unwrap().try_recv();
|
||||
if result.is_ok() {
|
||||
self.show_vru_dialog = true;
|
||||
self.vru_word_list = result.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if self.show_vru_dialog {
|
||||
ctx.show_viewport_immediate(
|
||||
egui::ViewportId::from_hash_of("vru_dialog"),
|
||||
egui::ViewportBuilder::default()
|
||||
.with_title("What would you like to say?")
|
||||
.with_always_on_top(),
|
||||
|ctx, class| {
|
||||
assert!(
|
||||
class == egui::ViewportClass::Immediate,
|
||||
"This egui backend doesn't support multiple viewports"
|
||||
);
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::Grid::new("vru_words").show(ui, |ui| {
|
||||
for (i, v) in self.vru_word_list.iter().enumerate() {
|
||||
if i % 5 == 0 {
|
||||
ui.end_row();
|
||||
}
|
||||
if ui.button((*v).to_string()).clicked() {
|
||||
self.vru_word_notifier
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.send(v.clone())
|
||||
.unwrap();
|
||||
self.show_vru_dialog = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if ctx.input(|i| i.viewport().close_requested()) {
|
||||
self.vru_word_notifier
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.send(String::from(""))
|
||||
.unwrap();
|
||||
self.show_vru_dialog = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn execute<F: std::future::Future<Output = ()> + Send + 'static>(f: F) {
|
||||
std::thread::spawn(move || futures::executor::block_on(f));
|
||||
}
|
||||
|
||||
fn add_japanese_font(ctx: &egui::Context) {
|
||||
ctx.add_font(eframe::epaint::text::FontInsert::new(
|
||||
"japanese_font",
|
||||
egui::FontData::from_static(include_bytes!("../../data/NotoSansJP-Regular.ttf")),
|
||||
vec![
|
||||
eframe::epaint::text::InsertFontFamily {
|
||||
family: egui::FontFamily::Proportional,
|
||||
priority: egui::epaint::text::FontPriority::Lowest,
|
||||
},
|
||||
eframe::epaint::text::InsertFontFamily {
|
||||
family: egui::FontFamily::Monospace,
|
||||
priority: egui::epaint::text::FontPriority::Lowest,
|
||||
},
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
+293
-175
@@ -2,31 +2,34 @@ use std::ops::Neg;
|
||||
|
||||
use crate::ui;
|
||||
|
||||
pub const R_DPAD: usize = 0;
|
||||
pub const L_DPAD: usize = 1;
|
||||
pub const D_DPAD: usize = 2;
|
||||
pub const U_DPAD: usize = 3;
|
||||
pub const START_BUTTON: usize = 4;
|
||||
pub const Z_TRIG: usize = 5;
|
||||
pub const B_BUTTON: usize = 6;
|
||||
pub const A_BUTTON: usize = 7;
|
||||
pub const R_CBUTTON: usize = 8;
|
||||
pub const L_CBUTTON: usize = 9;
|
||||
pub const D_CBUTTON: usize = 10;
|
||||
pub const U_CBUTTON: usize = 11;
|
||||
pub const R_TRIG: usize = 12;
|
||||
pub const L_TRIG: usize = 13;
|
||||
pub const X_AXIS: usize = 16;
|
||||
pub const Y_AXIS: usize = 24;
|
||||
const R_DPAD: usize = 0;
|
||||
const L_DPAD: usize = 1;
|
||||
const D_DPAD: usize = 2;
|
||||
const U_DPAD: usize = 3;
|
||||
const START_BUTTON: usize = 4;
|
||||
const Z_TRIG: usize = 5;
|
||||
const B_BUTTON: usize = 6;
|
||||
const A_BUTTON: usize = 7;
|
||||
const R_CBUTTON: usize = 8;
|
||||
const L_CBUTTON: usize = 9;
|
||||
const D_CBUTTON: usize = 10;
|
||||
const U_CBUTTON: usize = 11;
|
||||
const R_TRIG: usize = 12;
|
||||
const L_TRIG: usize = 13;
|
||||
const AXIS_LEFT: usize = 14;
|
||||
const AXIS_RIGHT: usize = 15;
|
||||
const AXIS_UP: usize = 16;
|
||||
const AXIS_DOWN: usize = 17;
|
||||
const CHANGE_PAK: usize = 18;
|
||||
pub const PROFILE_SIZE: usize = 19;
|
||||
|
||||
pub const AXIS_LEFT: usize = 14;
|
||||
pub const AXIS_RIGHT: usize = 15;
|
||||
pub const AXIS_UP: usize = 16;
|
||||
pub const AXIS_DOWN: usize = 17;
|
||||
const X_AXIS_SHIFT: usize = 16;
|
||||
const Y_AXIS_SHIFT: usize = 24;
|
||||
|
||||
pub const MAX_AXIS_VALUE: f64 = 85.0;
|
||||
const MAX_AXIS_VALUE: f64 = 85.0;
|
||||
|
||||
pub struct Controllers {
|
||||
pub rumble: bool,
|
||||
pub game_controller: Option<sdl2::controller::GameController>,
|
||||
pub joystick: Option<sdl2::joystick::Joystick>,
|
||||
}
|
||||
@@ -78,94 +81,110 @@ pub fn set_axis_from_joystick(
|
||||
(x, y)
|
||||
}
|
||||
|
||||
fn get_axis_from_i32(axis: i32) -> sdl2::controller::Axis {
|
||||
match axis {
|
||||
0 => sdl2::controller::Axis::LeftX,
|
||||
1 => sdl2::controller::Axis::LeftY,
|
||||
2 => sdl2::controller::Axis::RightX,
|
||||
3 => sdl2::controller::Axis::RightY,
|
||||
4 => sdl2::controller::Axis::TriggerLeft,
|
||||
5 => sdl2::controller::Axis::TriggerRight,
|
||||
_ => panic!("Invalid axis"),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_button_from_i32(button: i32) -> sdl2::controller::Button {
|
||||
match button {
|
||||
0 => sdl2::controller::Button::A,
|
||||
1 => sdl2::controller::Button::B,
|
||||
2 => sdl2::controller::Button::X,
|
||||
3 => sdl2::controller::Button::Y,
|
||||
4 => sdl2::controller::Button::Back,
|
||||
5 => sdl2::controller::Button::Guide,
|
||||
6 => sdl2::controller::Button::Start,
|
||||
7 => sdl2::controller::Button::LeftStick,
|
||||
8 => sdl2::controller::Button::RightStick,
|
||||
9 => sdl2::controller::Button::LeftShoulder,
|
||||
10 => sdl2::controller::Button::RightShoulder,
|
||||
11 => sdl2::controller::Button::DPadUp,
|
||||
12 => sdl2::controller::Button::DPadDown,
|
||||
13 => sdl2::controller::Button::DPadLeft,
|
||||
14 => sdl2::controller::Button::DPadRight,
|
||||
_ => panic!("Invalid button"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_axis_from_controller(
|
||||
profile: &ui::config::InputProfile,
|
||||
controller: &sdl2::controller::GameController,
|
||||
) -> (f64, f64) {
|
||||
unsafe {
|
||||
let mut x = 0.0;
|
||||
let mut y = 0.0;
|
||||
if profile.controller_axis[AXIS_LEFT].0 {
|
||||
let axis_position =
|
||||
controller.axis(std::mem::transmute::<i32, sdl2::controller::Axis>(
|
||||
profile.controller_axis[AXIS_LEFT].1,
|
||||
));
|
||||
if axis_position as isize * profile.controller_axis[AXIS_LEFT].2 as isize > 0 {
|
||||
x = axis_position as f64 * MAX_AXIS_VALUE / i16::MAX as f64;
|
||||
}
|
||||
let mut x = 0.0;
|
||||
let mut y = 0.0;
|
||||
if profile.controller_axis[AXIS_LEFT].0 {
|
||||
let axis_position =
|
||||
controller.axis(get_axis_from_i32(profile.controller_axis[AXIS_LEFT].1));
|
||||
if axis_position as isize * profile.controller_axis[AXIS_LEFT].2 as isize > 0 {
|
||||
x = axis_position as f64 * MAX_AXIS_VALUE / i16::MAX as f64;
|
||||
}
|
||||
if profile.controller_axis[AXIS_RIGHT].0 {
|
||||
let axis_position =
|
||||
controller.axis(std::mem::transmute::<i32, sdl2::controller::Axis>(
|
||||
profile.controller_axis[AXIS_RIGHT].1,
|
||||
));
|
||||
if axis_position as isize * profile.controller_axis[AXIS_RIGHT].2 as isize > 0 {
|
||||
x = axis_position as f64 * MAX_AXIS_VALUE / i16::MAX as f64;
|
||||
}
|
||||
}
|
||||
if profile.controller_axis[AXIS_DOWN].0 {
|
||||
let axis_position =
|
||||
controller.axis(std::mem::transmute::<i32, sdl2::controller::Axis>(
|
||||
profile.controller_axis[AXIS_DOWN].1,
|
||||
));
|
||||
if axis_position as isize * profile.controller_axis[AXIS_DOWN].2 as isize > 0 {
|
||||
y = (axis_position as f64 * MAX_AXIS_VALUE / i16::MAX as f64).neg();
|
||||
}
|
||||
}
|
||||
if profile.controller_axis[AXIS_UP].0 {
|
||||
let axis_position =
|
||||
controller.axis(std::mem::transmute::<i32, sdl2::controller::Axis>(
|
||||
profile.controller_axis[AXIS_UP].1,
|
||||
));
|
||||
if axis_position as isize * profile.controller_axis[AXIS_UP].2 as isize > 0 {
|
||||
y = (axis_position as f64 * MAX_AXIS_VALUE / i16::MAX as f64).neg();
|
||||
}
|
||||
}
|
||||
(x, y)
|
||||
}
|
||||
if profile.controller_axis[AXIS_RIGHT].0 {
|
||||
let axis_position =
|
||||
controller.axis(get_axis_from_i32(profile.controller_axis[AXIS_RIGHT].1));
|
||||
if axis_position as isize * profile.controller_axis[AXIS_RIGHT].2 as isize > 0 {
|
||||
x = axis_position as f64 * MAX_AXIS_VALUE / i16::MAX as f64;
|
||||
}
|
||||
}
|
||||
if profile.controller_axis[AXIS_DOWN].0 {
|
||||
let axis_position =
|
||||
controller.axis(get_axis_from_i32(profile.controller_axis[AXIS_DOWN].1));
|
||||
if axis_position as isize * profile.controller_axis[AXIS_DOWN].2 as isize > 0 {
|
||||
y = (axis_position as f64 * MAX_AXIS_VALUE / i16::MAX as f64).neg();
|
||||
}
|
||||
}
|
||||
if profile.controller_axis[AXIS_UP].0 {
|
||||
let axis_position = controller.axis(get_axis_from_i32(profile.controller_axis[AXIS_UP].1));
|
||||
if axis_position as isize * profile.controller_axis[AXIS_UP].2 as isize > 0 {
|
||||
y = (axis_position as f64 * MAX_AXIS_VALUE / i16::MAX as f64).neg();
|
||||
}
|
||||
}
|
||||
(x, y)
|
||||
}
|
||||
|
||||
pub fn set_axis_from_keys(
|
||||
profile: &ui::config::InputProfile,
|
||||
keyboard_state: sdl2::keyboard::KeyboardState,
|
||||
keyboard_state: &sdl2::keyboard::KeyboardState,
|
||||
) -> (f64, f64) {
|
||||
unsafe {
|
||||
let mut x = 0.0;
|
||||
let mut y = 0.0;
|
||||
if profile.keys[AXIS_LEFT].0
|
||||
&& keyboard_state
|
||||
.is_scancode_pressed(std::mem::transmute::<i32, sdl2::keyboard::Scancode>(
|
||||
profile.keys[AXIS_LEFT].1,
|
||||
))
|
||||
{
|
||||
x = -MAX_AXIS_VALUE
|
||||
}
|
||||
if profile.keys[AXIS_RIGHT].0
|
||||
&& keyboard_state
|
||||
.is_scancode_pressed(std::mem::transmute::<i32, sdl2::keyboard::Scancode>(
|
||||
profile.keys[AXIS_RIGHT].1,
|
||||
))
|
||||
{
|
||||
x = MAX_AXIS_VALUE
|
||||
}
|
||||
if profile.keys[AXIS_DOWN].0
|
||||
&& keyboard_state
|
||||
.is_scancode_pressed(std::mem::transmute::<i32, sdl2::keyboard::Scancode>(
|
||||
profile.keys[AXIS_DOWN].1,
|
||||
))
|
||||
{
|
||||
y = -MAX_AXIS_VALUE
|
||||
}
|
||||
if profile.keys[AXIS_UP].0
|
||||
&& keyboard_state
|
||||
.is_scancode_pressed(std::mem::transmute::<i32, sdl2::keyboard::Scancode>(
|
||||
profile.keys[AXIS_UP].1,
|
||||
))
|
||||
{
|
||||
y = MAX_AXIS_VALUE
|
||||
}
|
||||
(x, y)
|
||||
let mut x = 0.0;
|
||||
let mut y = 0.0;
|
||||
if profile.keys[AXIS_LEFT].0
|
||||
&& keyboard_state.is_scancode_pressed(
|
||||
sdl2::keyboard::Scancode::from_i32(profile.keys[AXIS_LEFT].1).unwrap(),
|
||||
)
|
||||
{
|
||||
x = -MAX_AXIS_VALUE
|
||||
}
|
||||
if profile.keys[AXIS_RIGHT].0
|
||||
&& keyboard_state.is_scancode_pressed(
|
||||
sdl2::keyboard::Scancode::from_i32(profile.keys[AXIS_RIGHT].1).unwrap(),
|
||||
)
|
||||
{
|
||||
x = MAX_AXIS_VALUE
|
||||
}
|
||||
if profile.keys[AXIS_DOWN].0
|
||||
&& keyboard_state.is_scancode_pressed(
|
||||
sdl2::keyboard::Scancode::from_i32(profile.keys[AXIS_DOWN].1).unwrap(),
|
||||
)
|
||||
{
|
||||
y = -MAX_AXIS_VALUE
|
||||
}
|
||||
if profile.keys[AXIS_UP].0
|
||||
&& keyboard_state.is_scancode_pressed(
|
||||
sdl2::keyboard::Scancode::from_i32(profile.keys[AXIS_UP].1).unwrap(),
|
||||
)
|
||||
{
|
||||
y = MAX_AXIS_VALUE
|
||||
}
|
||||
(x, y)
|
||||
}
|
||||
|
||||
pub fn set_buttons_from_joystick(
|
||||
@@ -182,9 +201,7 @@ pub fn set_buttons_from_joystick(
|
||||
let profile_joystick_hat = profile.joystick_hat[i];
|
||||
if profile_joystick_hat.0
|
||||
&& joystick.hat(profile_joystick_hat.1).unwrap()
|
||||
== unsafe {
|
||||
std::mem::transmute::<i8, sdl2::joystick::HatState>(profile_joystick_hat.2)
|
||||
}
|
||||
== sdl2::joystick::HatState::from_raw(profile_joystick_hat.2)
|
||||
{
|
||||
*keys |= 1 << i;
|
||||
}
|
||||
@@ -208,21 +225,12 @@ pub fn set_buttons_from_controller(
|
||||
) {
|
||||
let profile_controller_button = profile.controller_buttons[i];
|
||||
if profile_controller_button.0 {
|
||||
unsafe {
|
||||
*keys |= (controller.button(std::mem::transmute::<i32, sdl2::controller::Button>(
|
||||
profile_controller_button.1,
|
||||
)) as u32)
|
||||
<< i;
|
||||
}
|
||||
*keys |= (controller.button(get_button_from_i32(profile_controller_button.1)) as u32) << i;
|
||||
}
|
||||
|
||||
let profile_controller_axis = profile.controller_axis[i];
|
||||
if profile_controller_axis.0 {
|
||||
let axis_position = unsafe {
|
||||
controller.axis(std::mem::transmute::<i32, sdl2::controller::Axis>(
|
||||
profile_controller_axis.1,
|
||||
))
|
||||
};
|
||||
let axis_position = controller.axis(get_axis_from_i32(profile_controller_axis.1));
|
||||
if axis_position as isize * profile_controller_axis.2 as isize > 0
|
||||
&& axis_position.saturating_abs() > i16::MAX / 2
|
||||
{
|
||||
@@ -231,9 +239,70 @@ pub fn set_buttons_from_controller(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(ui: &mut ui::Ui, channel: usize) -> u32 {
|
||||
let context = ui.sdl_context.as_mut().unwrap();
|
||||
let events = context.event_pump().unwrap();
|
||||
pub fn set_rumble(ui: &mut ui::Ui, channel: usize, rumble: u8) {
|
||||
if !ui.controllers[channel].rumble {
|
||||
return;
|
||||
}
|
||||
let controller = &mut ui.controllers[channel].game_controller;
|
||||
let joystick = &mut ui.controllers[channel].joystick;
|
||||
if controller.is_some() {
|
||||
controller
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.set_rumble(
|
||||
(rumble & 1) as u16 * u16::MAX,
|
||||
(rumble & 1) as u16 * u16::MAX,
|
||||
(rumble & 1) as u32 * 60000,
|
||||
)
|
||||
.unwrap();
|
||||
} else if joystick.is_some() {
|
||||
joystick
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.set_rumble(
|
||||
(rumble & 1) as u16 * u16::MAX,
|
||||
(rumble & 1) as u16 * u16::MAX,
|
||||
(rumble & 1) as u32 * 60000,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn change_paks(
|
||||
profile: &ui::config::InputProfile,
|
||||
joystick: &Option<sdl2::joystick::Joystick>,
|
||||
controller: &Option<sdl2::controller::GameController>,
|
||||
keyboard_state: &sdl2::keyboard::KeyboardState,
|
||||
) -> bool {
|
||||
let controller_button = profile.controller_buttons[CHANGE_PAK];
|
||||
let joystick_button = profile.joystick_buttons[CHANGE_PAK];
|
||||
let joystick_hat = profile.joystick_hat[CHANGE_PAK];
|
||||
let key = profile.keys[CHANGE_PAK];
|
||||
|
||||
let mut pressed = false;
|
||||
if controller_button.0 && controller.is_some() {
|
||||
pressed = controller
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.button(get_button_from_i32(controller_button.1));
|
||||
} else if joystick_button.0 && joystick.is_some() {
|
||||
pressed = joystick
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.button(joystick_button.1)
|
||||
.unwrap();
|
||||
} else if joystick_hat.0 && joystick.is_some() {
|
||||
pressed = joystick.as_ref().unwrap().hat(joystick_hat.1).unwrap()
|
||||
== sdl2::joystick::HatState::from_raw(joystick_hat.2);
|
||||
} else if key.0 {
|
||||
pressed =
|
||||
keyboard_state.is_scancode_pressed(sdl2::keyboard::Scancode::from_i32(key.1).unwrap());
|
||||
}
|
||||
pressed
|
||||
}
|
||||
|
||||
pub fn get(ui: &mut ui::Ui, channel: usize) -> (u32, bool) {
|
||||
let events = ui.sdl_context.as_ref().unwrap().event_pump().unwrap();
|
||||
let keyboard_state = events.keyboard_state();
|
||||
|
||||
let profile_name = ui.config.input.input_profile_binding[channel].clone();
|
||||
@@ -245,20 +314,17 @@ pub fn get(ui: &mut ui::Ui, channel: usize) -> u32 {
|
||||
if profile_name != "default" || channel == 0 {
|
||||
let profile_key = profile.keys[i];
|
||||
if profile_key.0 {
|
||||
unsafe {
|
||||
keys |= (keyboard_state
|
||||
.is_scancode_pressed(std::mem::transmute::<i32, sdl2::keyboard::Scancode>(
|
||||
profile_key.1,
|
||||
)) as u32)
|
||||
<< i;
|
||||
}
|
||||
keys |= (keyboard_state
|
||||
.is_scancode_pressed(sdl2::keyboard::Scancode::from_i32(profile_key.1).unwrap())
|
||||
as u32)
|
||||
<< i;
|
||||
}
|
||||
}
|
||||
|
||||
if joystick.is_some() {
|
||||
set_buttons_from_joystick(profile, i, joystick.as_ref().unwrap(), &mut keys);
|
||||
} else if controller.is_some() {
|
||||
if controller.is_some() {
|
||||
set_buttons_from_controller(profile, i, controller.as_ref().unwrap(), &mut keys);
|
||||
} else if joystick.is_some() {
|
||||
set_buttons_from_joystick(profile, i, joystick.as_ref().unwrap(), &mut keys);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,19 +332,23 @@ pub fn get(ui: &mut ui::Ui, channel: usize) -> u32 {
|
||||
let mut y: f64 = 0.0;
|
||||
|
||||
if profile_name != "default" || channel == 0 {
|
||||
(x, y) = set_axis_from_keys(profile, keyboard_state);
|
||||
(x, y) = set_axis_from_keys(profile, &keyboard_state);
|
||||
}
|
||||
|
||||
if joystick.is_some() {
|
||||
(x, y) = set_axis_from_joystick(profile, joystick.as_ref().unwrap())
|
||||
} else if controller.is_some() {
|
||||
if controller.is_some() {
|
||||
(x, y) = set_axis_from_controller(profile, controller.as_ref().unwrap())
|
||||
} else if joystick.is_some() {
|
||||
(x, y) = set_axis_from_joystick(profile, joystick.as_ref().unwrap())
|
||||
}
|
||||
bound_axis(&mut x, &mut y);
|
||||
|
||||
keys |= (x.round() as i8 as u8 as u32) << X_AXIS;
|
||||
keys |= (y.round() as i8 as u8 as u32) << Y_AXIS;
|
||||
keys
|
||||
keys |= (x.round() as i8 as u8 as u32) << X_AXIS_SHIFT;
|
||||
keys |= (y.round() as i8 as u8 as u32) << Y_AXIS_SHIFT;
|
||||
|
||||
(
|
||||
keys,
|
||||
change_paks(profile, joystick, controller, &keyboard_state),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn list_controllers(ui: &ui::Ui) {
|
||||
@@ -322,7 +392,7 @@ pub fn clear_bindings(ui: &mut ui::Ui) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn configure_input_profile(ui: &mut ui::Ui, profile: String) {
|
||||
pub fn configure_input_profile(ui: &mut ui::Ui, profile: String, dinput: bool) {
|
||||
if profile == "default" {
|
||||
println!("Profile name cannot be default");
|
||||
return;
|
||||
@@ -331,10 +401,20 @@ pub fn configure_input_profile(ui: &mut ui::Ui, profile: String) {
|
||||
println!("Profile name cannot be empty");
|
||||
return;
|
||||
}
|
||||
let joystick_subsystem = ui.sdl_context.as_ref().unwrap().joystick().unwrap();
|
||||
let controller_subsystem = ui.controller_subsystem.as_ref().unwrap();
|
||||
let joystick_subsystem = ui.joystick_subsystem.as_ref().unwrap();
|
||||
let mut controllers = vec![];
|
||||
let mut joysticks = vec![];
|
||||
for i in 0..joystick_subsystem.num_joysticks().unwrap() {
|
||||
joysticks.push(ui.sdl_context.as_ref().unwrap().joystick().unwrap().open(i));
|
||||
if !dinput {
|
||||
if let Ok(controller) = controller_subsystem.open(i) {
|
||||
controllers.push(controller);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if let Ok(joystick) = joystick_subsystem.open(i) {
|
||||
joysticks.push(joystick);
|
||||
}
|
||||
}
|
||||
|
||||
let mut builder =
|
||||
@@ -348,7 +428,7 @@ pub fn configure_input_profile(ui: &mut ui::Ui, profile: String) {
|
||||
let font =
|
||||
rusttype::Font::try_from_bytes(include_bytes!("../../data/Roboto-Regular.ttf")).unwrap();
|
||||
|
||||
let key_labels = [
|
||||
let key_labels: [(&str, usize); PROFILE_SIZE] = [
|
||||
("A", A_BUTTON),
|
||||
("B", B_BUTTON),
|
||||
("Start", START_BUTTON),
|
||||
@@ -367,17 +447,21 @@ pub fn configure_input_profile(ui: &mut ui::Ui, profile: String) {
|
||||
("Control Stick Down", AXIS_DOWN),
|
||||
("Control Stick Left", AXIS_LEFT),
|
||||
("Control Stick Right", AXIS_RIGHT),
|
||||
("Change Pak", CHANGE_PAK),
|
||||
];
|
||||
|
||||
let mut new_keys = [(false, 0); 18];
|
||||
let mut new_joystick_buttons = [(false, 0u32); 14];
|
||||
let mut new_joystick_hat = [(false, 0u32, 0); 14];
|
||||
let mut new_joystick_axis = [(false, 0u32, 0); 18];
|
||||
let mut new_keys = [(false, 0); PROFILE_SIZE];
|
||||
let mut new_joystick_buttons = [(false, 0u32); PROFILE_SIZE];
|
||||
let mut new_joystick_hat = [(false, 0u32, 0); PROFILE_SIZE];
|
||||
let mut new_joystick_axis = [(false, 0u32, 0); PROFILE_SIZE];
|
||||
let mut new_controller_buttons = [(false, 0i32); PROFILE_SIZE];
|
||||
let mut new_controller_axis = [(false, 0i32, 0); PROFILE_SIZE];
|
||||
|
||||
let mut last_axis_result = (false, 0, 0);
|
||||
let mut event_pump = ui.sdl_context.as_ref().unwrap().event_pump().unwrap();
|
||||
let mut last_joystick_axis_result = (false, 0, 0);
|
||||
let mut last_controller_axis_result = (false, 0, 0);
|
||||
let mut events = ui.sdl_context.as_ref().unwrap().event_pump().unwrap();
|
||||
for (key, value) in key_labels.iter() {
|
||||
for _event in event_pump.poll_iter() {} // clear events
|
||||
for _event in events.poll_iter() {} // clear events
|
||||
|
||||
ui::video::draw_text(
|
||||
format!("Select binding for: {key}").as_str(),
|
||||
@@ -388,7 +472,7 @@ pub fn configure_input_profile(ui: &mut ui::Ui, profile: String) {
|
||||
let mut key_set = false;
|
||||
while !key_set {
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
for event in event_pump.poll_iter() {
|
||||
for event in events.poll_iter() {
|
||||
match event {
|
||||
sdl2::event::Event::Window {
|
||||
win_event: sdl2::event::WindowEvent::Close,
|
||||
@@ -401,34 +485,57 @@ pub fn configure_input_profile(ui: &mut ui::Ui, profile: String) {
|
||||
new_keys[*value] = (true, scancode as i32);
|
||||
key_set = true
|
||||
}
|
||||
sdl2::event::Event::ControllerButtonDown { button, .. } => {
|
||||
if !controllers.is_empty() {
|
||||
new_controller_buttons[*value] = (true, button as i32);
|
||||
key_set = true
|
||||
}
|
||||
}
|
||||
sdl2::event::Event::ControllerAxisMotion {
|
||||
axis,
|
||||
value: axis_value,
|
||||
..
|
||||
} => {
|
||||
if !controllers.is_empty() && axis_value.saturating_abs() > i16::MAX / 2 {
|
||||
let result =
|
||||
(true, axis as i32, axis_value / axis_value.saturating_abs());
|
||||
if result != last_controller_axis_result {
|
||||
new_controller_axis[*value] = result;
|
||||
last_controller_axis_result = result;
|
||||
key_set = true
|
||||
}
|
||||
}
|
||||
}
|
||||
sdl2::event::Event::JoyButtonDown { button_idx, .. } => {
|
||||
new_joystick_buttons[*value] = (true, button_idx as u32);
|
||||
key_set = true
|
||||
if !joysticks.is_empty() {
|
||||
new_joystick_buttons[*value] = (true, button_idx as u32);
|
||||
key_set = true
|
||||
}
|
||||
}
|
||||
sdl2::event::Event::JoyHatMotion { hat_idx, state, .. } => {
|
||||
new_joystick_hat[*value] = unsafe {
|
||||
(
|
||||
if !joysticks.is_empty() && state != sdl2::joystick::HatState::Centered {
|
||||
new_joystick_hat[*value] = (
|
||||
true,
|
||||
hat_idx as u32,
|
||||
std::mem::transmute::<sdl2::joystick::HatState, i8>(state),
|
||||
)
|
||||
};
|
||||
key_set = true
|
||||
sdl2::joystick::HatState::to_raw(state),
|
||||
);
|
||||
key_set = true
|
||||
}
|
||||
}
|
||||
sdl2::event::Event::JoyAxisMotion {
|
||||
axis_idx,
|
||||
value: axis_value,
|
||||
..
|
||||
} => {
|
||||
if axis_value.saturating_abs() > 24576 {
|
||||
if !joysticks.is_empty() && axis_value.saturating_abs() > i16::MAX / 2 {
|
||||
let result = (
|
||||
true,
|
||||
axis_idx as u32,
|
||||
axis_value / axis_value.saturating_abs(),
|
||||
);
|
||||
if result != last_axis_result {
|
||||
if result != last_joystick_axis_result {
|
||||
new_joystick_axis[*value] = result;
|
||||
last_axis_result = result;
|
||||
last_joystick_axis_result = result;
|
||||
key_set = true
|
||||
}
|
||||
}
|
||||
@@ -441,19 +548,20 @@ pub fn configure_input_profile(ui: &mut ui::Ui, profile: String) {
|
||||
|
||||
let new_profile = ui::config::InputProfile {
|
||||
keys: new_keys,
|
||||
controller_buttons: Default::default(),
|
||||
controller_axis: Default::default(),
|
||||
controller_buttons: new_controller_buttons,
|
||||
controller_axis: new_controller_axis,
|
||||
joystick_buttons: new_joystick_buttons,
|
||||
joystick_hat: new_joystick_hat,
|
||||
joystick_axis: new_joystick_axis,
|
||||
dinput,
|
||||
};
|
||||
ui.config.input.input_profiles.insert(profile, new_profile);
|
||||
}
|
||||
|
||||
pub fn get_default_profile() -> ui::config::InputProfile {
|
||||
let mut default_controller_buttons = [(false, 0); 14];
|
||||
let mut default_controller_axis = [(false, 0, 0); 18];
|
||||
let mut default_keys = [(false, 0); 18];
|
||||
let mut default_controller_buttons = [(false, 0); PROFILE_SIZE];
|
||||
let mut default_controller_axis = [(false, 0, 0); PROFILE_SIZE];
|
||||
let mut default_keys = [(false, 0); PROFILE_SIZE];
|
||||
default_keys[R_DPAD] = (true, sdl2::keyboard::Scancode::D as i32);
|
||||
default_keys[L_DPAD] = (true, sdl2::keyboard::Scancode::A as i32);
|
||||
default_keys[D_DPAD] = (true, sdl2::keyboard::Scancode::S as i32);
|
||||
@@ -472,6 +580,7 @@ pub fn get_default_profile() -> ui::config::InputProfile {
|
||||
default_keys[AXIS_RIGHT] = (true, sdl2::keyboard::Scancode::Right as i32);
|
||||
default_keys[AXIS_UP] = (true, sdl2::keyboard::Scancode::Up as i32);
|
||||
default_keys[AXIS_DOWN] = (true, sdl2::keyboard::Scancode::Down as i32);
|
||||
default_keys[CHANGE_PAK] = (true, sdl2::keyboard::Scancode::Comma as i32);
|
||||
|
||||
default_controller_buttons[R_DPAD] = (true, sdl2::controller::Button::DPadRight as i32);
|
||||
default_controller_buttons[L_DPAD] = (true, sdl2::controller::Button::DPadLeft as i32);
|
||||
@@ -491,6 +600,7 @@ pub fn get_default_profile() -> ui::config::InputProfile {
|
||||
default_controller_axis[AXIS_RIGHT] = (true, sdl2::controller::Axis::LeftX as i32, 1);
|
||||
default_controller_axis[AXIS_UP] = (true, sdl2::controller::Axis::LeftY as i32, -1);
|
||||
default_controller_axis[AXIS_DOWN] = (true, sdl2::controller::Axis::LeftY as i32, 1);
|
||||
default_controller_buttons[CHANGE_PAK] = (true, sdl2::controller::Button::Back as i32);
|
||||
|
||||
ui::config::InputProfile {
|
||||
keys: default_keys,
|
||||
@@ -499,11 +609,13 @@ pub fn get_default_profile() -> ui::config::InputProfile {
|
||||
joystick_buttons: Default::default(),
|
||||
joystick_hat: Default::default(),
|
||||
joystick_axis: Default::default(),
|
||||
dinput: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(ui: &mut ui::Ui) {
|
||||
let joystick_subsystem = ui.joystick_subsystem.as_ref().unwrap();
|
||||
let controller_subsystem = ui.controller_subsystem.as_ref().unwrap();
|
||||
let mut taken = [false; 4];
|
||||
for i in 0..4 {
|
||||
let controller_assignment = &ui.config.input.controller_assignment[i];
|
||||
@@ -520,30 +632,36 @@ pub fn init(ui: &mut ui::Ui) {
|
||||
}
|
||||
}
|
||||
if joystick_index < u32::MAX {
|
||||
if ui.config.input.input_profile_binding[i] == "default" {
|
||||
let controller_result = ui
|
||||
.sdl_context
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.game_controller()
|
||||
.unwrap()
|
||||
.open(joystick_index);
|
||||
let profile_name = ui.config.input.input_profile_binding[i].clone();
|
||||
let profile = ui.config.input.input_profiles.get(&profile_name).unwrap();
|
||||
|
||||
if !profile.dinput {
|
||||
let controller_result = controller_subsystem.open(joystick_index);
|
||||
if controller_result.is_ok() {
|
||||
ui.controllers[i].game_controller = Some(controller_result.unwrap());
|
||||
if ui.controllers[i]
|
||||
.game_controller
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.has_rumble()
|
||||
{
|
||||
ui.controllers[i].rumble = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ui.controllers[i].game_controller.is_none() {
|
||||
let joystick_result = ui
|
||||
.sdl_context
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.joystick()
|
||||
.unwrap()
|
||||
.open(joystick_index);
|
||||
let joystick_result = joystick_subsystem.open(joystick_index);
|
||||
if joystick_result.is_err() {
|
||||
println!("could not connect joystick")
|
||||
println!(
|
||||
"could not connect joystick: {}",
|
||||
joystick_result.err().unwrap()
|
||||
)
|
||||
} else {
|
||||
ui.controllers[i].joystick = Some(joystick_result.unwrap());
|
||||
if ui.controllers[i].joystick.as_ref().unwrap().has_rumble() {
|
||||
ui.controllers[i].rumble = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
+3
-8
@@ -86,16 +86,11 @@ pub fn get_save_type(game_id: &str) -> Vec<SaveTypes> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(ui: &mut ui::Ui) {
|
||||
pub fn init(ui: &mut ui::Ui, data_dir: std::path::PathBuf) {
|
||||
let id = ui.game_id.as_str();
|
||||
ui.save_type = get_save_type(id);
|
||||
|
||||
let base_path = dirs::data_dir().unwrap().join("gopher64").join("saves");
|
||||
|
||||
let result = std::fs::create_dir_all(base_path.clone());
|
||||
if result.is_err() {
|
||||
panic!("could not create save dir")
|
||||
}
|
||||
let base_path = data_dir.join("saves");
|
||||
|
||||
ui.paths.eep_file_path.clone_from(&base_path);
|
||||
ui.paths
|
||||
@@ -148,7 +143,7 @@ pub fn load_saves(ui: &mut ui::Ui) {
|
||||
|
||||
pub fn write_rom_save(ui: &ui::Ui) {
|
||||
let f = std::fs::File::create(ui.paths.romsave_file_path.clone()).unwrap();
|
||||
serde_json::to_writer(f, &ui.saves.romsave).unwrap();
|
||||
serde_json::to_writer(f, &ui.saves.romsave.0).unwrap();
|
||||
}
|
||||
|
||||
pub fn write_saves(ui: &ui::Ui) {
|
||||
|
||||
+18
-39
@@ -1,30 +1,7 @@
|
||||
#![allow(non_snake_case)]
|
||||
include!(concat!(env!("OUT_DIR"), "/parallel_bindings.rs"));
|
||||
use crate::device;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct GfxInfo {
|
||||
pub rdram: *mut u8,
|
||||
pub dmem: *mut u8,
|
||||
pub rdram_size: u32,
|
||||
pub dpc_current_reg: *mut u32,
|
||||
pub dpc_start_reg: *mut u32,
|
||||
pub dpc_end_reg: *mut u32,
|
||||
pub dpc_status_reg: *mut u32,
|
||||
pub vi_h_start_reg: *mut u32,
|
||||
pub vi_v_start_reg: *mut u32,
|
||||
pub vi_x_scale_reg: *mut u32,
|
||||
pub vi_y_scale_reg: *mut u32,
|
||||
pub vi_width_reg: *mut u32,
|
||||
}
|
||||
|
||||
unsafe extern "C" {
|
||||
pub fn rdp_init(window: usize, gfx_info: GfxInfo, fullscreen: bool);
|
||||
pub fn rdp_close();
|
||||
pub fn rdp_update_screen() -> bool;
|
||||
pub fn rdp_set_vi_register(reg: u32, value: u32);
|
||||
pub fn rdp_process_commands() -> u64;
|
||||
pub fn rdp_full_sync();
|
||||
}
|
||||
|
||||
pub fn init(device: &mut device::Device, fullscreen: bool) {
|
||||
let mut builder = device
|
||||
.ui
|
||||
@@ -42,25 +19,27 @@ pub fn init(device: &mut device::Device, fullscreen: bool) {
|
||||
}
|
||||
device.ui.window = Some(builder.build().unwrap());
|
||||
|
||||
let gfx_info = GfxInfo {
|
||||
rdram: device.rdram.mem.as_mut_ptr(),
|
||||
dmem: device.rsp.mem.as_mut_ptr(),
|
||||
rdram_size: device.rdram.size,
|
||||
dpc_current_reg: &mut device.rdp.regs_dpc[device::rdp::DPC_CURRENT_REG as usize],
|
||||
dpc_start_reg: &mut device.rdp.regs_dpc[device::rdp::DPC_START_REG as usize],
|
||||
dpc_end_reg: &mut device.rdp.regs_dpc[device::rdp::DPC_END_REG as usize],
|
||||
dpc_status_reg: &mut device.rdp.regs_dpc[device::rdp::DPC_STATUS_REG as usize],
|
||||
vi_h_start_reg: &mut device.vi.regs[device::vi::VI_H_START_REG as usize],
|
||||
vi_v_start_reg: &mut device.vi.regs[device::vi::VI_V_START_REG as usize],
|
||||
vi_x_scale_reg: &mut device.vi.regs[device::vi::VI_X_SCALE_REG as usize],
|
||||
vi_y_scale_reg: &mut device.vi.regs[device::vi::VI_Y_SCALE_REG as usize],
|
||||
vi_width_reg: &mut device.vi.regs[device::vi::VI_WIDTH_REG as usize],
|
||||
let gfx_info = GFX_INFO {
|
||||
RDRAM: device.rdram.mem.as_mut_ptr(),
|
||||
DMEM: device.rsp.mem.as_mut_ptr(),
|
||||
RDRAM_SIZE: device.rdram.size,
|
||||
DPC_CURRENT_REG: &mut device.rdp.regs_dpc[device::rdp::DPC_CURRENT_REG as usize],
|
||||
DPC_START_REG: &mut device.rdp.regs_dpc[device::rdp::DPC_START_REG as usize],
|
||||
DPC_END_REG: &mut device.rdp.regs_dpc[device::rdp::DPC_END_REG as usize],
|
||||
DPC_STATUS_REG: &mut device.rdp.regs_dpc[device::rdp::DPC_STATUS_REG as usize],
|
||||
VI_H_START_REG: &mut device.vi.regs[device::vi::VI_H_START_REG as usize],
|
||||
VI_V_START_REG: &mut device.vi.regs[device::vi::VI_V_START_REG as usize],
|
||||
VI_X_SCALE_REG: &mut device.vi.regs[device::vi::VI_X_SCALE_REG as usize],
|
||||
VI_Y_SCALE_REG: &mut device.vi.regs[device::vi::VI_Y_SCALE_REG as usize],
|
||||
VI_WIDTH_REG: &mut device.vi.regs[device::vi::VI_WIDTH_REG as usize],
|
||||
};
|
||||
|
||||
unsafe {
|
||||
rdp_init(
|
||||
device.ui.window.as_mut().unwrap().raw() as usize,
|
||||
device.ui.window.as_ref().unwrap().raw() as *mut std::ffi::c_void,
|
||||
gfx_info,
|
||||
device.ui.config.video.upscale,
|
||||
device.ui.config.video.integer_scaling,
|
||||
fullscreen,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
use eframe::egui;
|
||||
|
||||
use crate::ui;
|
||||
|
||||
pub fn prompt_for_match(
|
||||
words: &[String],
|
||||
window_notifier: &std::sync::mpsc::Sender<Vec<String>>,
|
||||
word_index_notifier: &std::sync::mpsc::Receiver<String>,
|
||||
gui_ctx: &egui::Context,
|
||||
) -> u16 {
|
||||
let mut dedup_words = words.to_owned();
|
||||
dedup_words.sort();
|
||||
dedup_words.dedup();
|
||||
window_notifier.send(dedup_words).unwrap();
|
||||
gui_ctx.request_repaint(); // this is so the window pops up right away
|
||||
let mut result = word_index_notifier.try_recv();
|
||||
while result.is_err() {
|
||||
result = word_index_notifier.try_recv();
|
||||
std::thread::sleep(std::time::Duration::from_secs_f64(1.0 / 60.0));
|
||||
ui::video::update_screen(); // so the OS doesn't complain about the game window being frozen
|
||||
}
|
||||
for (i, v) in words.iter().enumerate() {
|
||||
if *v == *result.as_ref().unwrap() {
|
||||
return i as u16;
|
||||
}
|
||||
}
|
||||
0x7FFF
|
||||
}
|
||||
Reference in New Issue
Block a user