Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f17d62876b | ||
|
|
4004047d68 | ||
|
|
e8fb942896 | ||
|
|
53cda2e515 | ||
|
|
1935d116ca |
Generated
+355
-359
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -4,7 +4,7 @@ description = "An emulator for the Virtual Boy."
|
|||||||
repository = "https://git.virtual-boy.com/PVB/lemur"
|
repository = "https://git.virtual-boy.com/PVB/lemur"
|
||||||
publish = false
|
publish = false
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
version = "0.15.1"
|
version = "0.15.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+13
-13
@@ -10,30 +10,30 @@ RUN apt-get update && \
|
|||||||
apt-get install -y ca-certificates
|
apt-get install -y ca-certificates
|
||||||
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y bash bzip2 clang-22 git lld-22 llvm-22 make patch xz-utils && \
|
apt-get install -y bash bzip2 clang-23 git lld-23 llvm-23 make patch xz-utils && \
|
||||||
ln -s $(which clang-22) /usr/bin/clang && \
|
ln -s $(which clang-23) /usr/bin/clang && \
|
||||||
ln -s $(which clang++-22) /usr/bin/clang++ && \
|
ln -s $(which clang++-23) /usr/bin/clang++ && \
|
||||||
ln -s $(which ld64.lld-22) /usr/bin/ld64.lld && \
|
ln -s $(which ld64.lld-23) /usr/bin/ld64.lld && \
|
||||||
SDK_VERSION=14.5 UNATTENDED=1 ENABLE_COMPILER_RT_INSTALL=1 TARGET_DIR=/osxcross ./build.sh
|
SDK_VERSION=14.5 UNATTENDED=1 ENABLE_COMPILER_RT_INSTALL=1 TARGET_DIR=/osxcross ./build.sh
|
||||||
|
|
||||||
FROM rust:1.98-trixie
|
FROM rust:1.99-trixie
|
||||||
ADD --chmod=644 "https://apt.llvm.org/llvm-snapshot.gpg.key" /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
ADD --chmod=644 "https://apt.llvm.org/llvm-snapshot.gpg.key" /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||||
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
||||||
RUN rustup target add x86_64-pc-windows-msvc && \
|
RUN rustup target add x86_64-pc-windows-msvc && \
|
||||||
rustup target add x86_64-apple-darwin && \
|
rustup target add x86_64-apple-darwin && \
|
||||||
rustup target add aarch64-apple-darwin && \
|
rustup target add aarch64-apple-darwin && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y clang-22 lld-22 libc6-dev libasound2-dev libudev-dev genisoimage mingw-w64 && \
|
apt-get install -y clang-23 lld-23 libc6-dev libasound2-dev libudev-dev genisoimage mingw-w64 && \
|
||||||
cargo install cargo-bundle xwin && \
|
cargo install cargo-bundle xwin && \
|
||||||
xwin --accept-license splat --output xwin && \
|
xwin --accept-license splat --output xwin && \
|
||||||
rm -rf .xwin-cache && \
|
rm -rf .xwin-cache && \
|
||||||
ln -s $(which clang-22) /usr/bin/clang && \
|
ln -s $(which clang-23) /usr/bin/clang && \
|
||||||
ln -s $(which clang++-22) /usr/bin/clang++
|
ln -s $(which clang++-23) /usr/bin/clang++
|
||||||
COPY --from=osxcross /osxcross /osxcross
|
COPY --from=osxcross /osxcross /osxcross
|
||||||
|
|
||||||
ENV PATH="/osxcross/bin:$PATH" \
|
ENV PATH="/osxcross/bin:$PATH" \
|
||||||
LD_LIBRARY_PATH="/osxcross/lib" \
|
LD_LIBRARY_PATH="/osxcross/lib" \
|
||||||
CC="clang-22" CXX="clang++-22" AR="llvm-ar-22" \
|
CC="clang-23" CXX="clang++-23" AR="llvm-ar-23" \
|
||||||
CC_x86_64-apple-darwin="o64-clang" \
|
CC_x86_64-apple-darwin="o64-clang" \
|
||||||
CXX_x86_64-apple-darwin="o64-clang++" \
|
CXX_x86_64-apple-darwin="o64-clang++" \
|
||||||
CC_aarch64-apple-darwin="oa64-clang" \
|
CC_aarch64-apple-darwin="oa64-clang" \
|
||||||
@@ -43,11 +43,11 @@ ENV PATH="/osxcross/bin:$PATH" \
|
|||||||
SHROOMS_CFLAGS_x86_64-pc-windows-msvc="-flto" \
|
SHROOMS_CFLAGS_x86_64-pc-windows-msvc="-flto" \
|
||||||
CFLAGS_x86_64-pc-windows-msvc="-I/xwin/crt/include -I/xwin/sdk/include/ucrt -I/xwin/sdk/include/um -I/xwin/sdk/include/shared" \
|
CFLAGS_x86_64-pc-windows-msvc="-I/xwin/crt/include -I/xwin/sdk/include/ucrt -I/xwin/sdk/include/um -I/xwin/sdk/include/shared" \
|
||||||
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-Lnative=/xwin/crt/lib/x86_64 -Lnative=/xwin/sdk/lib/um/x86_64 -Lnative=/xwin/sdk/lib/ucrt/x86_64 -Clinker-plugin-lto -Clink-arg=-fuse-ld=lld" \
|
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-Lnative=/xwin/crt/lib/x86_64 -Lnative=/xwin/sdk/lib/um/x86_64 -Lnative=/xwin/sdk/lib/ucrt/x86_64 -Clinker-plugin-lto -Clink-arg=-fuse-ld=lld" \
|
||||||
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER="lld-link-22" \
|
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER="lld-link-23" \
|
||||||
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="o64-clang" \
|
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="o64-clang" \
|
||||||
CARGO_TARGET_X86_64_APPLE_DARWIN_AR="llvm-ar-22" \
|
CARGO_TARGET_X86_64_APPLE_DARWIN_AR="llvm-ar-23" \
|
||||||
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER="oa64-clang" \
|
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER="oa64-clang" \
|
||||||
CARGO_TARGET_AARCH64_APPLE_DARWIN_AR="llvm-ar-22" \
|
CARGO_TARGET_AARCH64_APPLE_DARWIN_AR="llvm-ar-23" \
|
||||||
RC_PATH="llvm-rc-22" \
|
RC_PATH="llvm-rc-23" \
|
||||||
MACOSX_DEPLOYMENT_TARGET="14.5"
|
MACOSX_DEPLOYMENT_TARGET="14.5"
|
||||||
ENTRYPOINT ["bash"]
|
ENTRYPOINT ["bash"]
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
.define("VB_DIRECT_FRAME", "on_frame")
|
.define("VB_DIRECT_FRAME", "on_frame")
|
||||||
.define("VB_DIRECT_READ", "on_read")
|
.define("VB_DIRECT_READ", "on_read")
|
||||||
.define("VB_DIRECT_WRITE", "on_write")
|
.define("VB_DIRECT_WRITE", "on_write")
|
||||||
.define("VBU_REALLOC", "vbu_realloc_shim")
|
.define("VBU_MEMMGR", "VBU_MEMMGR")
|
||||||
.file(Path::new("shrooms-vb-core/core/vb.c"))
|
.file(Path::new("shrooms-vb-core/core/vb.c"))
|
||||||
.file(Path::new("shrooms-vb-core/util/isx.c"))
|
.file(Path::new("shrooms-vb-core/util/isx.c"))
|
||||||
.file(Path::new("shrooms-vb-core/util/vbu.c"))
|
.file(Path::new("shrooms-vb-core/util/vbu.c"))
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Types: deb deb-src
|
Types: deb deb-src
|
||||||
URIs: http://apt.llvm.org/trixie/
|
URIs: http://apt.llvm.org/trixie/
|
||||||
Suites: llvm-toolchain-trixie-22
|
Suites: llvm-toolchain-trixie-23
|
||||||
Components: main
|
Components: main
|
||||||
|
|||||||
+1
-1
Submodule shrooms-vb-core updated: 31b7403252...6e9b727b31
@@ -1,13 +1,95 @@
|
|||||||
use std::ffi::c_void;
|
use std::{ffi::c_void, sync::{LazyLock, Mutex}};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Reallocator {
|
||||||
|
allocations: Vec<Allocation>,
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for Reallocator {}
|
||||||
|
|
||||||
|
struct Allocation {
|
||||||
|
ptr: *mut u8,
|
||||||
|
size: usize,
|
||||||
|
}
|
||||||
|
impl Allocation {
|
||||||
|
fn new(size: usize) -> Self {
|
||||||
|
let layout = Self::layout(size);
|
||||||
|
// SAFETY: our layout is not zero, not too big, and properly aligned
|
||||||
|
let ptr = unsafe { std::alloc::alloc_zeroed(layout) };
|
||||||
|
if ptr.is_null() {
|
||||||
|
std::alloc::handle_alloc_error(layout);
|
||||||
|
}
|
||||||
|
Self { ptr, size }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn layout(size: usize) -> std::alloc::Layout {
|
||||||
|
assert!(size != 0);
|
||||||
|
std::alloc::Layout::from_size_align(size, 8).expect("far too large an allocation")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_slice(&self) -> &[u8] {
|
||||||
|
// SAFETY: we allocated this ourselves, it's safe
|
||||||
|
unsafe { std::slice::from_raw_parts(self.ptr, self.size) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_mut_slice(&mut self) -> &mut [u8] {
|
||||||
|
// SAFETY: we allocated this ourselves, it's safe
|
||||||
|
unsafe { std::slice::from_raw_parts_mut(self.ptr, self.size) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for Allocation {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
// SAFETY: we allocated this ourselves with this layout, and it hasn't been freed
|
||||||
|
unsafe { std::alloc::dealloc(self.ptr, Self::layout(self.size)) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reallocator {
|
||||||
|
fn realloc(&mut self, ptr: *mut c_void, new_size: usize) -> *mut c_void {
|
||||||
|
if let Some(old_data) = self.load_allocation(ptr) {
|
||||||
|
if new_size == 0 {
|
||||||
|
// free
|
||||||
|
std::ptr::null_mut()
|
||||||
|
} else {
|
||||||
|
// actually reallocate and copy the data over
|
||||||
|
let mut new_data = Allocation::new(new_size);
|
||||||
|
let bytes_to_copy = old_data.size.min(new_size);
|
||||||
|
new_data.as_mut_slice()[..bytes_to_copy].copy_from_slice(&old_data.as_slice()[..bytes_to_copy]);
|
||||||
|
self.store_allocation(new_data)
|
||||||
|
}
|
||||||
|
} else if new_size > 0 {
|
||||||
|
// fresh allocation
|
||||||
|
let allocation = Allocation::new(new_size);
|
||||||
|
self.store_allocation(allocation)
|
||||||
|
} else {
|
||||||
|
std::ptr::null_mut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_allocation(&mut self, ptr: *mut c_void) -> Option<Allocation> {
|
||||||
|
if ptr.is_null() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let index = self.allocations.iter().enumerate().find_map(|(i, alloc)| std::ptr::addr_eq(alloc.ptr, ptr).then_some(i))?;
|
||||||
|
let allocation = self.allocations.remove(index);
|
||||||
|
Some(allocation)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn store_allocation(&mut self, allocation: Allocation) -> *mut c_void {
|
||||||
|
let ptr = allocation.ptr;
|
||||||
|
self.allocations.push(allocation);
|
||||||
|
ptr.cast()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static VBU_ALLOC: LazyLock<Mutex<Reallocator>> = LazyLock::new(|| Mutex::new(Reallocator::default()));
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
unsafe fn vbu_realloc_shim(ptr: *mut c_void, new_size: usize) -> *mut c_void {
|
#[allow(nonstandard_style)]
|
||||||
if !ptr.is_null() {
|
unsafe fn VBU_MEMMGR(ptr: *mut c_void, new_size: usize) -> *mut c_void {
|
||||||
// not supporting proper realloc because it needs bookkeeping and it's unnecessary
|
let mut allocator = VBU_ALLOC.lock().unwrap();
|
||||||
return std::ptr::null_mut();
|
allocator.realloc(ptr, new_size)
|
||||||
}
|
|
||||||
let allocation = vec![0u8; new_size].into_boxed_slice();
|
|
||||||
Box::into_raw(allocation).cast()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[link(name = "vb")]
|
#[link(name = "vb")]
|
||||||
@@ -25,7 +107,7 @@ pub fn rom_from_isx(bytes: &[u8]) -> Option<Vec<u8>> {
|
|||||||
if raw_rom.is_null() {
|
if raw_rom.is_null() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// SAFETY: the rom was allocated by vbu_realloc_shim, which created it from a Vec<u8>.
|
let bytes = VBU_ALLOC.lock().unwrap().load_allocation(raw_rom)?;
|
||||||
let rom = unsafe { Vec::from_raw_parts(raw_rom.cast(), rom_length, rom_length) };
|
assert_eq!(bytes.size, rom_length);
|
||||||
Some(rom)
|
Some(bytes.as_slice().to_vec())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -944,7 +944,7 @@ impl WorldHeader {
|
|||||||
let ron = data & 0x4000 != 0;
|
let ron = data & 0x4000 != 0;
|
||||||
let mode = WorldMode::from_u16((data >> 12) & 0x3).unwrap();
|
let mode = WorldMode::from_u16((data >> 12) & 0x3).unwrap();
|
||||||
let scx = (data >> 10) as u32 & 0x03;
|
let scx = (data >> 10) as u32 & 0x03;
|
||||||
let scy = (data >> 10) as u32 & 0x03;
|
let scy = (data >> 8) as u32 & 0x03;
|
||||||
let over = data & 0x0080 != 0;
|
let over = data & 0x0080 != 0;
|
||||||
let end = data & 0x0040 != 0;
|
let end = data & 0x0040 != 0;
|
||||||
let base = (data & 0x000f) as usize;
|
let base = (data & 0x000f) as usize;
|
||||||
|
|||||||
Reference in New Issue
Block a user