changed futex crate for mac compat (maybe) and image to bitmap assembly converter

This commit is contained in:
Mwa
2026-03-17 16:31:45 +01:00
parent 20f7c289ed
commit 47efeef83d
5 changed files with 50 additions and 45 deletions

41
Cargo.lock generated
View File

@@ -173,16 +173,6 @@ dependencies = [
"regex",
]
[[package]]
name = "atomic-wait"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a55b94919229f2c42292fd71ffa4b75e83193bffdd77b1e858cd55fd2d0b0ea8"
dependencies = [
"libc",
"windows-sys 0.42.0",
]
[[package]]
name = "atomic-waker"
version = "1.1.2"
@@ -2150,9 +2140,9 @@ dependencies = [
name = "simu"
version = "0.1.0"
dependencies = [
"atomic-wait",
"parse_int",
"pixels",
"wait_on_address",
"winit",
"winit_input_helper",
]
@@ -2451,6 +2441,20 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "wait_on_address"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f46f0d222fdc7fac38a2ad9f0fabdc5af18d0c9d12c5fc52438509cf88674cf"
dependencies = [
"js-sys",
"libc",
"rustversion",
"wasm-bindgen",
"web-sys",
"windows-sys 0.61.2",
]
[[package]]
name = "walkdir"
version = "2.5.0"
@@ -2843,21 +2847,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.45.0"

View File

@@ -1,12 +1,27 @@
use regex::Regex;
use std::env::args;
fn main() {
println!("Hello, world!");
let path = args().nth(1).expect("usage: 1 image file argument");
let (data, name, width, height) = path_to_img(path.as_str());
println!("{name}:");
println!(" D {width}");
println!(" D {height}");
for d in data {
println!(" D 0x{d:08x}");
}
}
fn remove_non_alphanumeric(input: &str) -> String {
let re = Regex::new(r"[^a-zA-Z0-9_]+").unwrap();
re.replace_all(input, "").to_string()
}
fn path_to_img(path: &str) -> (Vec<u32>, String, u32, u32){
fn path_to_img(path: &str) -> (Vec<u32>, String, u32, u32) {
let img = match image::open(path) {
Ok(img) => img.to_luma8(),
Err(e) => panic!("failed to open image {path}: {e}"),
}
};
let width = img.width();
let height = img.height();
@@ -18,7 +33,7 @@ fn path_to_img(path: &str) -> (Vec<u32>, String, u32, u32){
for x in 0..width {
let pix = img.get_pixel(x, y)[0];
if pix >= 127 {
byte |= 1<<bit
byte |= 1 << bit
}
bit += 1;
if bit == 32 {
@@ -31,6 +46,8 @@ fn path_to_img(path: &str) -> (Vec<u32>, String, u32, u32){
if bit != 0 {
bytes.push(byte);
}
let path = path.split
(bytes,name,width,height)
let path = path.split('/').next_back().unwrap();
let split: Vec<_> = path.split('.').collect();
let name = remove_non_alphanumeric(&split[0..split.len() - 1].join("_")).to_lowercase();
(bytes, name, width, height)
}

View File

@@ -4,11 +4,11 @@ version = "0.1.0"
edition = "2024"
[dependencies]
atomic-wait = "1.1.0"
pixels = "0.15.0"
winit = { version = "0.30.13", features = ["x11", "x11-dl", "x11rb", "ahash", "bytemuck", "memmap2", "rwh_06", "sctk", "sctk-adwaita"] }
winit_input_helper = "0.17.0"
parse_int = { version = "0.9.0", optional = true }
wait_on_address = "0.1.4"
[features]

View File

@@ -9,7 +9,7 @@ use std::{
sync::atomic::AtomicU32,
time::{self, Instant},
};
use wait_on_address::AtomicWait;
pub(crate) struct SharedState {
pub(crate) keyboard: [AtomicU32; 4],
pub(crate) screen_buf: [AtomicU32; 480 * 640],
@@ -124,6 +124,7 @@ impl Cond {
}
}
#[allow(unused)] //depen on features
enum Instruction {
Copy(Reg, Op2),
Add(Reg, Reg, Op2),
@@ -599,7 +600,7 @@ impl Computer {
}
println!("awaiting interupt...");
}
atomic_wait::wait(&SHARED.external_interupts, 0);
SHARED.external_interupts.wait(0);
}
self.pc = (addr + self.pc as u32) as usize;
}
@@ -642,7 +643,7 @@ impl Computer {
InteruptKind::MMIO => {
(&SHARED.external_interupts)
.store(0, std::sync::atomic::Ordering::Release);
atomic_wait::wake_all(&SHARED.external_interupts);
SHARED.external_interupts.notify_one();
//no need to check prev because MMIO is the lowest priority
self.interupts = InteruptState::Enabled
}
@@ -687,7 +688,7 @@ impl Computer {
(&SHARED.external_enabled_interupts)
.store(0, std::sync::atomic::Ordering::Relaxed);
(&SHARED.external_interupts).store(0, std::sync::atomic::Ordering::Relaxed);
atomic_wait::wake_all(&SHARED.external_interupts);
SHARED.external_interupts.notify_all();
}
Instruction::Swi() => {
self.pc += 1;

View File

@@ -8,7 +8,6 @@
use std::env::args;
use std::hint::unlikely;
use std::io::stdin;
use std::process::exit;
use std::sync::{
Arc,
@@ -18,17 +17,16 @@ use std::thread::scope;
use std::time::{Duration, Instant};
use pixels::{Error, Pixels, SurfaceTexture};
use wait_on_address::AtomicWait;
use winit::application::ApplicationHandler;
use winit::dpi::LogicalSize;
use winit::event::WindowEvent;
use winit::event_loop::EventLoop;
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement;
use winit::platform::scancode::PhysicalKeyExtScancode;
use winit::window::Window;
// use winit_input_helper::WinitInputHelper;
use crate::cpu::{Computer, MMIOInterupt};
mod cpu;
use cpu::SHARED;
@@ -37,7 +35,7 @@ fn wait_int() {
while unlikely(v != 0) {
#[cfg(feature = "debug")]
println!("wating for interupt clear {v}");
atomic_wait::wait(&SHARED.external_interupts, v);
SHARED.external_interupts.wait(v);
v = (&SHARED.external_interupts).load(Acquire);
}
}
@@ -123,7 +121,7 @@ impl<'a> ApplicationHandler for App<'a> {
(&SHARED.external_interupts).store(MMIOInterupt::Keyboard.into(), Release);
#[cfg(feature = "debug")]
println!("wake due to keyboard event");
atomic_wait::wake_all(&SHARED.external_interupts);
SHARED.external_interupts.notify_one();
}
}
WindowEvent::CursorMoved { position, .. } => {
@@ -152,7 +150,7 @@ impl<'a> ApplicationHandler for App<'a> {
(&SHARED.external_interupts).store(MMIOInterupt::MouseMove.into(), Release);
#[cfg(feature = "debug")]
println!("wake due mouse move");
atomic_wait::wake_all(&SHARED.external_interupts);
SHARED.external_interupts.notify_one();
}
}
// WindowEvent::MouseWheel {
@@ -186,7 +184,7 @@ impl<'a> ApplicationHandler for App<'a> {
(&SHARED.external_interupts).store(MMIOInterupt::MouseClick.into(), Release);
#[cfg(feature = "debug")]
println!("wake mouse click");
atomic_wait::wake_all(&SHARED.external_interupts);
SHARED.external_interupts.notify_one();
}
}
WindowEvent::ScaleFactorChanged { .. } => {
@@ -199,7 +197,7 @@ impl<'a> ApplicationHandler for App<'a> {
!= 0;
if enabled {
(&SHARED.external_interupts).store(MMIOInterupt::VSync.into(), Relaxed);
atomic_wait::wake_all(&SHARED.external_interupts);
SHARED.external_interupts.notify_one();
wait_int();
}
let pix = self.pixels.as_mut().unwrap();