mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
Compare commits
15 Commits
842cf9f139
...
v0.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fc3353599 | |||
| fd10378e4d | |||
| 0659f8a57e | |||
| f4fa9e9c62 | |||
| 4c1ce8075e | |||
| 94764d631e | |||
| 8913fdaf6b | |||
| 195376cd28 | |||
| bf14d4bd3f | |||
| 0c68328700 | |||
| fb3fd5e8bb | |||
| b85f96b0bb | |||
| b69055b58d | |||
| 0878aa3f02 | |||
| 5cd1ecb98a |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -44,7 +44,7 @@ jobs:
|
||||
- name: Build
|
||||
run: cargo build --release --verbose
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: uw8-${{ matrix.build }}
|
||||
path: target/release/${{ matrix.exe }}
|
||||
|
||||
1815
Cargo.lock
generated
1815
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "uw8"
|
||||
version = "0.2.2"
|
||||
version = "0.4.1"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@@ -11,7 +11,7 @@ native = ["wasmtime", "uw8-window", "cpal", "rubato" ]
|
||||
browser = ["warp", "tokio", "tokio-stream", "webbrowser"]
|
||||
|
||||
[dependencies]
|
||||
wasmtime = { version = "19.0.1", optional = true }
|
||||
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime.git", rev = "0f48f939b9870036562ca02ff21253547a9f1a5c", optional = true }
|
||||
anyhow = "1"
|
||||
env_logger = "0.11.3"
|
||||
log = "0.4"
|
||||
@@ -28,4 +28,4 @@ tokio-stream = { version = "0.1.15", features = ["sync"], optional = true }
|
||||
webbrowser = { version = "0.8.13", optional = true }
|
||||
ansi_term = "0.12.1"
|
||||
cpal = { version = "0.15.3", optional = true }
|
||||
rubato = { version = "0.15.0", optional = true }
|
||||
rubato = { version = "0.12.0", optional = true }
|
||||
|
||||
@@ -15,9 +15,9 @@ See [here](https://exoticorn.github.io/microw8/) for more information and docs.
|
||||
|
||||
## Downloads
|
||||
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-windows.zip)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-windows.zip)
|
||||
|
||||
The download includes
|
||||
|
||||
|
||||
@@ -3,14 +3,16 @@ include "../include/microw8-api.cwa"
|
||||
export fn upd() {
|
||||
let i: i32;
|
||||
loop pixels {
|
||||
let inline t = time() * 63 as f32;
|
||||
let lazy x = (i % 320 - 160) as f32;
|
||||
let lazy y = (i / 320 - 120) as f32;
|
||||
let inline d = 40000 as f32 / sqrt(x * x + y * y);
|
||||
let inline u = atan2(x, y) * (512.0 / 3.141);
|
||||
let inline c = ((i32.trunc_sat_f32_s(d + t * 2 as f32) ^ i32.trunc_sat_f32_s(u + t)) & 255) >> 4;
|
||||
let inline t = 16!56;
|
||||
let inline x = (i % 320 - 160) as f32;
|
||||
let inline y = (i #/ 320 - 120) as f32;
|
||||
let inline d = 0xa000 as f32 / sqrt(x * x + y * y);
|
||||
let inline a = atan2(x, y) * 163_f; // (512 / pi)
|
||||
let inline u = i32.trunc_sat_f32_s(a) + t;
|
||||
let inline v = i32.trunc_sat_f32_s(d) + t * 2;
|
||||
let inline c = ((v ^ u) #/ 16) % 16;
|
||||
i?FRAMEBUFFER = c;
|
||||
|
||||
branch_if (i := i + 1) < 320*240: pixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -31,51 +31,20 @@ Examplers for older versions:
|
||||
|
||||
## Versions
|
||||
|
||||
### v0.2.2
|
||||
### v0.4.1
|
||||
|
||||
* [Web runtime](v0.2.2)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-windows.zip)
|
||||
* [Web runtime](../v0.4.1)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-windows.zip)
|
||||
|
||||
Changes:
|
||||
|
||||
* call `start` function after loading cart if the cart exports one
|
||||
* fix `sndGes` having the wrong name and not being included in the auto imports
|
||||
* fix control codes 4-6 (change text output mode) being invoked when used as parameters in other control sequences
|
||||
* only open browser window once a cart was compiled sucessfully when running with `-b`
|
||||
* Windows: fix bad/inconsistent frame rate
|
||||
* fix choppy sound on devices with sample rates != 44100 kHz
|
||||
* add scale mode 'fill' option
|
||||
|
||||
### v0.2.1
|
||||
|
||||
* [Web runtime](v0.2.1)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.1/microw8-0.2.1-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.1/microw8-0.2.1-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.1/microw8-0.2.1-windows.zip)
|
||||
|
||||
Changes:
|
||||
|
||||
* new gpu accelerated renderer with (optional) crt filter
|
||||
* optimized `hline` function, a big speed-up when drawing large filled circles or rectangles
|
||||
* print fractional size of packed `uw8` cart
|
||||
|
||||
### v0.2.0
|
||||
|
||||
* [Web runtime](v0.2.0)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.0/microw8-0.2.0-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.0/microw8-0.2.0-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.0/microw8-0.2.0-windows.zip)
|
||||
|
||||
Changes:
|
||||
|
||||
* [add sound support!](docs#sound)
|
||||
* add support to redirect text output to the console for debugging using control code 6
|
||||
* update curlywas:
|
||||
* add support for `else if`
|
||||
* add support for escape sequences in strings
|
||||
* add support for char literals
|
||||
* add support for binop-assignment, eg. `+=`, `^=`, `<<=` etc. (also support for the tee operator: `+:=`)
|
||||
* "integer constant cast to float" literal syntax in CurlyWas (ex. `1_f` is equivalent to `1 as f32`)
|
||||
|
||||
### Older versions
|
||||
|
||||
[Find older versions here.](versions)
|
||||
[Find older versions here.](versions)
|
||||
|
||||
@@ -21,7 +21,7 @@ loaded.
|
||||
00000-00040: user memory
|
||||
00040-00044: time since module start in ms
|
||||
00044-0004c: gamepad state
|
||||
0004c-00050: reserved
|
||||
0004c-00050: number of frames since module start
|
||||
00050-00070: sound data (synced to sound thread)
|
||||
00070-00078: reserved
|
||||
00078-12c78: frame buffer
|
||||
@@ -468,6 +468,7 @@ when using the native runtime:
|
||||
* `--no-gpu`: Force old cpu-only window code
|
||||
* `--filter FILTER`: Select an upscale filter at startup
|
||||
* `--fullscreen`: Start in fullscreen mode
|
||||
* `--scale-fill`: Scale to fill whole screen, potentially cropping parts of the frame buffer.
|
||||
|
||||
Note that the cpu-only window does not support fullscreen nor upscale filters.
|
||||
|
||||
@@ -484,7 +485,7 @@ The upscale filter options are:
|
||||
5, auto_crt (default) : ss_crt below 960x720, chromatic_crt otherwise
|
||||
```
|
||||
|
||||
You can switch the upscale filter at any time using the keys 1-5. You can toggle fullscreen with F.
|
||||
You can switch the upscale filter at any time using the keys 1-5. You can toggle fullscreen with F. You can toggle between scale modes 'fit' and 'fill' with M.
|
||||
|
||||
## `uw8 pack`
|
||||
|
||||
@@ -594,7 +595,7 @@ a base module provided by MicroW8.
|
||||
|
||||
You can generate this base module yourself using
|
||||
`uw8-tool`. As a quick summary, it provides all function
|
||||
types with up to 5 parameters (i32 or f32) where the
|
||||
types with up to 7 parameters (i32 or f32) where the
|
||||
`f32` parameters always preceed the `i32` parameters.
|
||||
Then it includes all imports that MicroW8 provides,
|
||||
a function section with a single function of type
|
||||
|
||||
@@ -2,9 +2,77 @@
|
||||
description = "Versions"
|
||||
+++
|
||||
|
||||
### v0.4.1
|
||||
|
||||
* [Web runtime](../v0.4.1)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.4.1/microw8-0.4.1-windows.zip)
|
||||
|
||||
Changes:
|
||||
|
||||
* Windows: fix bad/inconsistent frame rate
|
||||
* fix choppy sound on devices with sample rates != 44100 kHz
|
||||
* add scale mode 'fill' option
|
||||
|
||||
### v0.4.0
|
||||
|
||||
* [Web runtime](../v0.4.0)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.4.0/microw8-0.4.0-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.4.0/microw8-0.4.0-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.4.0/microw8-0.4.0-windows.zip)
|
||||
|
||||
Changes:
|
||||
|
||||
* add support for sound on mono- and surround-only devices
|
||||
* update wasmtime dependency to fix performance regression in 0.3.0
|
||||
* add frame counter since module start at location 72
|
||||
* add 6 and 7 parameter function types to base module
|
||||
|
||||
### v0.3.0
|
||||
|
||||
* [Web runtime](../v0.3.0)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.3.0/microw8-0.3.0-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.3.0/microw8-0.3.0-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.3.0/microw8-0.3.0-windows.zip)
|
||||
|
||||
Changes:
|
||||
|
||||
* add blitSprite and grabSprite API calls
|
||||
* add support for integer scaling up to 16x for printing text
|
||||
* fix incompatibility with sound devices only offering 16bit audio formats
|
||||
* add support for br_table instruction in packed carts
|
||||
|
||||
### v0.2.2
|
||||
|
||||
* [Web runtime](../v0.2.2)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.2/microw8-0.2.2-windows.zip)
|
||||
|
||||
Changes:
|
||||
|
||||
* call `start` function after loading cart if the cart exports one
|
||||
* fix `sndGes` having the wrong name and not being included in the auto imports
|
||||
* fix control codes 4-6 (change text output mode) being invoked when used as parameters in other control sequences
|
||||
* only open browser window once a cart was compiled sucessfully when running with `-b`
|
||||
|
||||
### v0.2.1
|
||||
|
||||
* [Web runtime](../v0.2.1)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.1/microw8-0.2.1-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.1/microw8-0.2.1-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.1/microw8-0.2.1-windows.zip)
|
||||
|
||||
Changes:
|
||||
|
||||
* new gpu accelerated renderer with (optional) crt filter
|
||||
* optimized `hline` function, a big speed-up when drawing large filled circles or rectangles
|
||||
* print fractional size of packed `uw8` cart
|
||||
|
||||
### v0.2.0
|
||||
|
||||
* [Web runtime](v0.2.0)
|
||||
* [Web runtime](../v0.2.0)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.0/microw8-0.2.0-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.0/microw8-0.2.0-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.0/microw8-0.2.0-windows.zip)
|
||||
@@ -22,7 +90,7 @@ Changes:
|
||||
|
||||
### v0.2.0-rc3
|
||||
|
||||
* [Web runtime](v0.2.0-rc3)
|
||||
* [Web runtime](../v0.2.0-rc3)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc3/microw8-0.2.0-rc3-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc3/microw8-0.2.0-rc3-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc3/microw8-0.2.0-rc3-windows.zip)
|
||||
@@ -40,7 +108,7 @@ Changes:
|
||||
|
||||
### v0.2.0-rc2
|
||||
|
||||
* [Web runtime](v0.2.0-rc2)
|
||||
* [Web runtime](../v0.2.0-rc2)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc2/microw8-0.2.0-rc2-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc2/microw8-0.2.0-rc2-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc2/microw8-0.2.0-rc2-windows.zip)
|
||||
@@ -51,7 +119,7 @@ Changes:
|
||||
|
||||
### v0.2.0-rc1
|
||||
|
||||
* [Web runtime](v0.2.0-rc1)
|
||||
* [Web runtime](../v0.2.0-rc1)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc1/microw8-0.2.0-rc1-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc1/microw8-0.2.0-rc1-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.2.0-rc1/microw8-0.2.0-rc1-windows.zip)
|
||||
@@ -67,7 +135,7 @@ Known issues:
|
||||
|
||||
### v0.1.2
|
||||
|
||||
* [Web runtime](v0.1.2)
|
||||
* [Web runtime](../v0.1.2)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.1.2/microw8-0.1.2-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.1.2/microw8-0.1.2-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.1.2/microw8-0.1.2-windows.zip)
|
||||
@@ -75,13 +143,13 @@ Known issues:
|
||||
Changes:
|
||||
|
||||
* add option to `uw8 run` to run the cart in the browser using the web runtime
|
||||
* CurlyWas: implement `include` support
|
||||
*../ CurlyWas: implement `include` support
|
||||
* CurlyWas: implement support for constants
|
||||
* fix crash when trying to draw zero sized line
|
||||
|
||||
### v0.1.1
|
||||
|
||||
* [Web runtime](v0.1.1)
|
||||
* [Web runtime](../v0.1.1)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.1.1/microw8-0.1.1-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.1.1/microw8-0.1.1-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.1.1/microw8-0.1.1-windows.zip)
|
||||
@@ -90,16 +158,16 @@ Changes:
|
||||
|
||||
* implement more robust file watcher
|
||||
* add basic video recording on F10 in web runtime
|
||||
* add screenshot on F9
|
||||
*../ add screenshot on F9
|
||||
* add watchdog to interrupt hanging update in native runtime
|
||||
* add devkit mode to web runtime
|
||||
* add unpack and compile commands to uw8
|
||||
*../ add unpack and compile commands to uw8
|
||||
* add support for table/element section in pack command
|
||||
* disable wayland support (caused missing window decorations in gnome)
|
||||
|
||||
### v0.1.0
|
||||
|
||||
* [Web runtime](v0.1.0)
|
||||
* [Web runtime](../v0.1.0)
|
||||
* [Linux](https://github.com/exoticorn/microw8/releases/download/v0.1.0/microw8-0.1.0-linux.tgz)
|
||||
* [MacOS](https://github.com/exoticorn/microw8/releases/download/v0.1.0/microw8-0.1.0-macos.tgz)
|
||||
* [Windows](https://github.com/exoticorn/microw8/releases/download/v0.1.0/microw8-0.1.0-windows.zip)
|
||||
|
||||
1
site/static/v0.3.0/index.html
Normal file
1
site/static/v0.3.0/index.html
Normal file
File diff suppressed because one or more lines are too long
1
site/static/v0.4.0/index.html
Normal file
1
site/static/v0.4.0/index.html
Normal file
File diff suppressed because one or more lines are too long
1
site/static/v0.4.1/index.html
Normal file
1
site/static/v0.4.1/index.html
Normal file
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@
|
||||
<section>
|
||||
<h1 class="text-center heading-text">A WebAssembly based fantasy console</h1>
|
||||
</section>
|
||||
<a href="v0.2.2">
|
||||
<a href="v0.4.1">
|
||||
<img class="demonstration-gif" style="width:640px;height:480px;image-rendering:pixelated" src="img/technotunnel.png"></img>
|
||||
</a>
|
||||
</div>
|
||||
@@ -15,4 +15,4 @@
|
||||
{% endblock hero %}
|
||||
|
||||
{% block footer %}
|
||||
{% endblock footer %}
|
||||
{% endblock footer %}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@ use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use std::{thread, time::Instant};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use cpal::traits::*;
|
||||
use rubato::Resampler;
|
||||
use uw8_window::{Window, WindowConfig};
|
||||
@@ -27,6 +27,7 @@ struct UW8Instance {
|
||||
end_frame: TypedFunc<(), ()>,
|
||||
update: Option<TypedFunc<(), ()>>,
|
||||
start_time: Instant,
|
||||
frame_counter: u32,
|
||||
watchdog: Arc<Mutex<UW8WatchDog>>,
|
||||
sound_tx: Option<mpsc::SyncSender<RegisterUpdate>>,
|
||||
}
|
||||
@@ -159,6 +160,7 @@ impl super::Runtime for MicroW8 {
|
||||
end_frame,
|
||||
update,
|
||||
start_time: Instant::now(),
|
||||
frame_counter: 0,
|
||||
watchdog,
|
||||
sound_tx,
|
||||
});
|
||||
@@ -191,8 +193,11 @@ impl super::Runtime for MicroW8 {
|
||||
let mem = instance.memory.data_mut(&mut instance.store);
|
||||
mem[64..68].copy_from_slice(&time.to_le_bytes());
|
||||
mem[68..72].copy_from_slice(&input.gamepads);
|
||||
mem[72..76].copy_from_slice(&instance.frame_counter.to_le_bytes());
|
||||
}
|
||||
|
||||
instance.frame_counter = instance.frame_counter.wrapping_add(1);
|
||||
|
||||
instance.store.set_epoch_deadline(self.timeout as u64);
|
||||
if let Some(ref update) = instance.update {
|
||||
if let Err(err) = update.call(&mut instance.store, ()) {
|
||||
@@ -328,26 +333,37 @@ fn init_sound(
|
||||
let mut configs: Vec<_> = device
|
||||
.supported_output_configs()?
|
||||
.filter(|config| {
|
||||
config.channels() == 2
|
||||
&& (config.sample_format() == cpal::SampleFormat::F32
|
||||
|| config.sample_format() == cpal::SampleFormat::I16)
|
||||
config.sample_format() == cpal::SampleFormat::F32
|
||||
|| config.sample_format() == cpal::SampleFormat::I16
|
||||
})
|
||||
.collect();
|
||||
|
||||
if configs.is_empty() {
|
||||
eprintln!(
|
||||
"No suitable audio output config found on device \"{}\", available configs:",
|
||||
device.name()?
|
||||
);
|
||||
for config in device.supported_output_configs()? {
|
||||
eprintln!(" {}ch {}", config.channels(), config.sample_format());
|
||||
}
|
||||
bail!("Failed to configure audio out");
|
||||
}
|
||||
|
||||
configs.sort_by_key(|config| {
|
||||
let rate = 44100
|
||||
.max(config.min_sample_rate().0)
|
||||
.min(config.max_sample_rate().0);
|
||||
let prio = if rate >= 44100 {
|
||||
let rate_prio = if rate >= 44100 {
|
||||
rate - 44100
|
||||
} else {
|
||||
(44100 - rate) * 1000
|
||||
};
|
||||
prio + (config.sample_format() == cpal::SampleFormat::I16) as u32
|
||||
let format_prio = (config.sample_format() == cpal::SampleFormat::I16) as u32;
|
||||
let channels_prio = (config.channels() != 2) as u32 * 16777216;
|
||||
rate_prio + format_prio + channels_prio
|
||||
});
|
||||
let config = configs
|
||||
.into_iter()
|
||||
.next()
|
||||
.ok_or_else(|| anyhow!("Could not find float or 16bit signed output config"))?;
|
||||
let config = configs.into_iter().next().unwrap();
|
||||
|
||||
let sample_rate = cpal::SampleRate(44100)
|
||||
.max(config.min_sample_rate())
|
||||
.min(config.max_sample_rate());
|
||||
@@ -359,6 +375,7 @@ fn init_sound(
|
||||
}
|
||||
};
|
||||
let sample_format = config.sample_format();
|
||||
let num_channels = config.channels();
|
||||
let config = cpal::StreamConfig {
|
||||
buffer_size,
|
||||
..config.config()
|
||||
@@ -378,8 +395,8 @@ fn init_sound(
|
||||
None
|
||||
} else {
|
||||
let rs = rubato::FftFixedIn::new(44100, sample_rate, 128, 1, 2)?;
|
||||
let input_buffers = rs.input_buffer_allocate(true);
|
||||
let output_buffers = rs.output_buffer_allocate(true);
|
||||
let input_buffers = rs.input_buffer_allocate();
|
||||
let output_buffers = rs.output_buffer_allocate();
|
||||
Some(Resampler {
|
||||
resampler: rs,
|
||||
input_buffers,
|
||||
@@ -392,7 +409,7 @@ fn init_sound(
|
||||
let mut pending_updates: Vec<RegisterUpdate> = Vec::with_capacity(30);
|
||||
let mut current_time = 0;
|
||||
|
||||
let mut callback = move |mut outer_buffer: &mut [f32], _: &_| {
|
||||
let mut callback = move |mut outer_buffer: &mut [f32]| {
|
||||
let mut first_update = true;
|
||||
while let Ok(update) = rx.try_recv() {
|
||||
if first_update {
|
||||
@@ -484,36 +501,126 @@ fn init_sound(
|
||||
current_time = current_time.wrapping_add((step_size * 500 / sample_rate).max(1) as i32);
|
||||
}
|
||||
};
|
||||
let stream = if sample_format == cpal::SampleFormat::F32 {
|
||||
device.build_output_stream(
|
||||
&config,
|
||||
callback,
|
||||
move |err| {
|
||||
dbg!(err);
|
||||
},
|
||||
None,
|
||||
)?
|
||||
} else {
|
||||
device.build_output_stream(
|
||||
&config,
|
||||
move |mut buffer: &mut [i16], info| {
|
||||
let mut float_buffer = [0f32; 256];
|
||||
|
||||
while !buffer.is_empty() {
|
||||
let step_size = buffer.len().min(float_buffer.len());
|
||||
let step_buffer = &mut float_buffer[..step_size];
|
||||
callback(step_buffer, info);
|
||||
for (dest, src) in buffer.iter_mut().take(step_size).zip(step_buffer.iter()) {
|
||||
*dest = (src.max(-1.0).min(1.0) * 32767.0) as i16;
|
||||
}
|
||||
buffer = &mut buffer[step_size..];
|
||||
}
|
||||
},
|
||||
move |err| {
|
||||
dbg!(err);
|
||||
},
|
||||
None,
|
||||
)?
|
||||
fn f32_to_i16<F>(mut buffer: &mut [i16], callback: &mut F)
|
||||
where
|
||||
F: FnMut(&mut [f32]),
|
||||
{
|
||||
let mut float_buffer = [0f32; 256];
|
||||
|
||||
while !buffer.is_empty() {
|
||||
let step_size = buffer.len().min(float_buffer.len());
|
||||
let step_buffer = &mut float_buffer[..step_size];
|
||||
callback(step_buffer);
|
||||
for (dest, src) in buffer.iter_mut().take(step_size).zip(step_buffer.iter()) {
|
||||
*dest = (src.max(-1.0).min(1.0) * 32767.0) as i16;
|
||||
}
|
||||
buffer = &mut buffer[step_size..];
|
||||
}
|
||||
}
|
||||
|
||||
fn stereo_to_mono<F>(mut buffer: &mut [f32], callback: &mut F)
|
||||
where
|
||||
F: FnMut(&mut [f32]),
|
||||
{
|
||||
let mut in_buffer = [0f32; 256];
|
||||
|
||||
while !buffer.is_empty() {
|
||||
let step_size = buffer.len().min(in_buffer.len() / 2);
|
||||
let step_buffer = &mut in_buffer[..step_size * 2];
|
||||
callback(step_buffer);
|
||||
for (index, dest) in buffer.iter_mut().take(step_size).enumerate() {
|
||||
*dest = (step_buffer[index * 2] + step_buffer[index * 2 + 1]) * 0.5;
|
||||
}
|
||||
buffer = &mut buffer[step_size..];
|
||||
}
|
||||
}
|
||||
|
||||
fn stereo_to_surround<F>(mut buffer: &mut [f32], num_channels: usize, callback: &mut F)
|
||||
where
|
||||
F: FnMut(&mut [f32]),
|
||||
{
|
||||
let mut in_buffer = [0f32; 256];
|
||||
buffer.fill(0.);
|
||||
|
||||
while !buffer.is_empty() {
|
||||
let step_size = (buffer.len() / num_channels).min(in_buffer.len() / 2);
|
||||
let step_buffer = &mut in_buffer[..step_size * 2];
|
||||
callback(step_buffer);
|
||||
for index in 0..step_size {
|
||||
buffer[index * num_channels + 0] = step_buffer[index * 2 + 0];
|
||||
buffer[index * num_channels + 1] = step_buffer[index * 2 + 1];
|
||||
}
|
||||
buffer = &mut buffer[step_size * num_channels..];
|
||||
}
|
||||
}
|
||||
|
||||
let stream = if sample_format == cpal::SampleFormat::F32 {
|
||||
if num_channels == 2 {
|
||||
device.build_output_stream(
|
||||
&config,
|
||||
move |buffer: &mut [f32], _| callback(buffer),
|
||||
move |err| {
|
||||
dbg!(err);
|
||||
},
|
||||
None,
|
||||
)?
|
||||
} else if num_channels == 1 {
|
||||
device.build_output_stream(
|
||||
&config,
|
||||
move |buffer: &mut [f32], _| stereo_to_mono(buffer, &mut callback),
|
||||
move |err| {
|
||||
dbg!(err);
|
||||
},
|
||||
None,
|
||||
)?
|
||||
} else {
|
||||
device.build_output_stream(
|
||||
&config,
|
||||
move |buffer: &mut [f32], _| {
|
||||
stereo_to_surround(buffer, num_channels as usize, &mut callback)
|
||||
},
|
||||
move |err| {
|
||||
dbg!(err);
|
||||
},
|
||||
None,
|
||||
)?
|
||||
}
|
||||
} else {
|
||||
if num_channels == 2 {
|
||||
device.build_output_stream(
|
||||
&config,
|
||||
move |buffer: &mut [i16], _| f32_to_i16(buffer, &mut callback),
|
||||
move |err| {
|
||||
dbg!(err);
|
||||
},
|
||||
None,
|
||||
)?
|
||||
} else if num_channels == 1 {
|
||||
device.build_output_stream(
|
||||
&config,
|
||||
move |buffer: &mut [i16], _| {
|
||||
f32_to_i16(buffer, &mut |b| stereo_to_mono(b, &mut callback))
|
||||
},
|
||||
move |err| {
|
||||
dbg!(err);
|
||||
},
|
||||
None,
|
||||
)?
|
||||
} else {
|
||||
device.build_output_stream(
|
||||
&config,
|
||||
move |buffer: &mut [i16], _| {
|
||||
f32_to_i16(buffer, &mut |b| {
|
||||
stereo_to_surround(b, num_channels as usize, &mut callback)
|
||||
})
|
||||
},
|
||||
move |err| {
|
||||
dbg!(err);
|
||||
},
|
||||
None,
|
||||
)?
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Uw8Sound { stream, tx })
|
||||
|
||||
@@ -37,7 +37,7 @@ impl BaseModule {
|
||||
|
||||
let mut types = vec![];
|
||||
let mut type_map = HashMap::new();
|
||||
for num_params in 0..6 {
|
||||
for num_params in 0..8 {
|
||||
for num_f32 in 0..=num_params {
|
||||
for &result in &[None, Some(ValType::I32), Some(ValType::F32)] {
|
||||
let mut params = vec![];
|
||||
|
||||
911
uw8-window/Cargo.lock
generated
911
uw8-window/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -6,11 +6,11 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
winit = "0.29.15"
|
||||
env_logger = "0.11.3"
|
||||
winit = "0.28.6"
|
||||
log = "0.4"
|
||||
pico-args = "0.5"
|
||||
wgpu = "0.19.3"
|
||||
wgpu = "0.17"
|
||||
pollster = "0.3.0"
|
||||
bytemuck = { version = "1.15", features = [ "derive" ] }
|
||||
anyhow = "1"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use wgpu::util::DeviceExt;
|
||||
use winit::dpi::PhysicalSize;
|
||||
|
||||
use super::Filter;
|
||||
use super::{scale_mode::ScaleMode, Filter};
|
||||
|
||||
pub struct CrtFilter {
|
||||
uniform_buffer: wgpu::Buffer,
|
||||
@@ -15,9 +15,10 @@ impl CrtFilter {
|
||||
screen: &wgpu::TextureView,
|
||||
resolution: PhysicalSize<u32>,
|
||||
surface_format: wgpu::TextureFormat,
|
||||
scale_mode: ScaleMode,
|
||||
) -> CrtFilter {
|
||||
let uniforms = Uniforms {
|
||||
texture_scale: texture_scale_from_resolution(resolution),
|
||||
texture_scale: scale_mode.texture_scale_from_resolution(resolution),
|
||||
};
|
||||
|
||||
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
@@ -112,9 +113,9 @@ impl CrtFilter {
|
||||
}
|
||||
|
||||
impl Filter for CrtFilter {
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>) {
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>, scale_mode: ScaleMode) {
|
||||
let uniforms = Uniforms {
|
||||
texture_scale: texture_scale_from_resolution(new_size),
|
||||
texture_scale: scale_mode.texture_scale_from_resolution(new_size),
|
||||
};
|
||||
queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[uniforms]));
|
||||
}
|
||||
@@ -126,16 +127,6 @@ impl Filter for CrtFilter {
|
||||
}
|
||||
}
|
||||
|
||||
fn texture_scale_from_resolution(res: PhysicalSize<u32>) -> [f32; 4] {
|
||||
let scale = ((res.width as f32) / 160.0).min((res.height as f32) / 120.0);
|
||||
[
|
||||
res.width as f32 / scale,
|
||||
res.height as f32 / scale,
|
||||
2.0 / scale,
|
||||
0.0,
|
||||
]
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
struct Uniforms {
|
||||
|
||||
@@ -17,7 +17,7 @@ fn vs_main(
|
||||
let i = in_vertex_index / 3u + in_vertex_index % 3u;
|
||||
let x = -1.0 + f32(i % 2u) * 322.0;
|
||||
let y = -1.0 + f32(i / 2u) * 242.0;
|
||||
out.clip_position = vec4<f32>((vec2<f32>(x, y) - vec2<f32>(160.0, 120.0)) / uniforms.texture_scale.xy, 0.0, 1.0);
|
||||
out.clip_position = vec4<f32>((vec2<f32>(x, y) - vec2<f32>(160.0, 120.0)) * uniforms.texture_scale.xy, 0.0, 1.0);
|
||||
out.tex_coords = vec2<f32>(x, y);
|
||||
return out;
|
||||
}
|
||||
@@ -72,4 +72,4 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
acc = acc + sample_pixel(pixel + vec2<i32>(1, 1), offset_x2 + offset_yr);
|
||||
|
||||
return vec4<f32>(acc, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use wgpu::util::DeviceExt;
|
||||
use winit::dpi::PhysicalSize;
|
||||
|
||||
use super::Filter;
|
||||
use super::{scale_mode::ScaleMode, Filter};
|
||||
|
||||
pub struct FastCrtFilter {
|
||||
uniform_buffer: wgpu::Buffer,
|
||||
@@ -16,9 +16,10 @@ impl FastCrtFilter {
|
||||
resolution: PhysicalSize<u32>,
|
||||
surface_format: wgpu::TextureFormat,
|
||||
chromatic: bool,
|
||||
scale_mode: ScaleMode,
|
||||
) -> FastCrtFilter {
|
||||
let uniforms = Uniforms {
|
||||
texture_scale: texture_scale_from_resolution(resolution),
|
||||
texture_scale: scale_mode.texture_scale_from_resolution(resolution),
|
||||
};
|
||||
|
||||
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
@@ -131,9 +132,9 @@ impl FastCrtFilter {
|
||||
}
|
||||
|
||||
impl Filter for FastCrtFilter {
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>) {
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>, scale_mode: ScaleMode) {
|
||||
let uniforms = Uniforms {
|
||||
texture_scale: texture_scale_from_resolution(new_size),
|
||||
texture_scale: scale_mode.texture_scale_from_resolution(new_size),
|
||||
};
|
||||
queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[uniforms]));
|
||||
}
|
||||
@@ -145,16 +146,6 @@ impl Filter for FastCrtFilter {
|
||||
}
|
||||
}
|
||||
|
||||
fn texture_scale_from_resolution(res: PhysicalSize<u32>) -> [f32; 4] {
|
||||
let scale = ((res.width as f32) / 160.0).min((res.height as f32) / 120.0);
|
||||
[
|
||||
scale / res.width as f32,
|
||||
scale / res.height as f32,
|
||||
2.0 / scale,
|
||||
0.0,
|
||||
]
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
struct Uniforms {
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
use crate::{Input, WindowConfig, WindowImpl};
|
||||
use anyhow::{anyhow, Result};
|
||||
use std::{sync::Arc, time::Instant};
|
||||
use scale_mode::ScaleMode;
|
||||
use std::time::Instant;
|
||||
|
||||
use winit::{
|
||||
dpi::PhysicalSize,
|
||||
event::{Event, WindowEvent},
|
||||
event::{Event, VirtualKeyCode, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
keyboard::{Key, KeyCode, NamedKey, PhysicalKey},
|
||||
platform::pump_events::{EventLoopExtPumpEvents, PumpStatus},
|
||||
window::{Fullscreen, WindowBuilder},
|
||||
};
|
||||
|
||||
use winit::platform::run_return::EventLoopExtRunReturn;
|
||||
|
||||
mod crt;
|
||||
mod fast_crt;
|
||||
pub mod scale_mode;
|
||||
mod square;
|
||||
|
||||
use crt::CrtFilter;
|
||||
@@ -21,7 +23,7 @@ use square::SquareFilter;
|
||||
|
||||
pub struct Window {
|
||||
_instance: wgpu::Instance,
|
||||
surface: wgpu::Surface<'static>,
|
||||
surface: wgpu::Surface,
|
||||
_adapter: wgpu::Adapter,
|
||||
device: wgpu::Device,
|
||||
queue: wgpu::Queue,
|
||||
@@ -29,17 +31,18 @@ pub struct Window {
|
||||
surface_config: wgpu::SurfaceConfiguration,
|
||||
filter: Box<dyn Filter>,
|
||||
event_loop: EventLoop<()>,
|
||||
window: Arc<winit::window::Window>,
|
||||
window: winit::window::Window,
|
||||
gamepads: [u8; 4],
|
||||
next_frame: Instant,
|
||||
is_fullscreen: bool,
|
||||
is_open: bool,
|
||||
scale_mode: ScaleMode,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn new(window_config: WindowConfig) -> Result<Window> {
|
||||
async fn create(window_config: WindowConfig) -> Result<Window> {
|
||||
let event_loop = EventLoop::new()?;
|
||||
let event_loop = EventLoop::new();
|
||||
let window = WindowBuilder::new()
|
||||
.with_inner_size(PhysicalSize::new(
|
||||
(320. * window_config.scale).round() as u32,
|
||||
@@ -56,10 +59,8 @@ impl Window {
|
||||
|
||||
window.set_cursor_visible(false);
|
||||
|
||||
let window = Arc::new(window);
|
||||
|
||||
let instance = wgpu::Instance::new(Default::default());
|
||||
let surface = instance.create_surface(window.clone())?;
|
||||
let surface = unsafe { instance.create_surface(&window) }?;
|
||||
let adapter = instance
|
||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||
power_preference: wgpu::PowerPreference::LowPower,
|
||||
@@ -92,6 +93,7 @@ impl Window {
|
||||
window.inner_size(),
|
||||
surface_config.format,
|
||||
window_config.filter,
|
||||
window_config.scale_mode,
|
||||
);
|
||||
|
||||
surface.configure(&device, &surface_config);
|
||||
@@ -111,6 +113,7 @@ impl Window {
|
||||
next_frame: Instant::now(),
|
||||
is_fullscreen: window_config.fullscreen,
|
||||
is_open: true,
|
||||
scale_mode: window_config.scale_mode,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -121,93 +124,103 @@ impl Window {
|
||||
impl WindowImpl for Window {
|
||||
fn begin_frame(&mut self) -> Input {
|
||||
let mut reset = false;
|
||||
self.event_loop
|
||||
.set_control_flow(ControlFlow::WaitUntil(self.next_frame));
|
||||
while self.is_open {
|
||||
let timeout = self.next_frame.saturating_duration_since(Instant::now());
|
||||
let status = self.event_loop.pump_events(Some(timeout), |event, elwt| {
|
||||
let mut new_filter = None;
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::Resized(new_size) => {
|
||||
self.surface_config.width = new_size.width;
|
||||
self.surface_config.height = new_size.height;
|
||||
self.surface.configure(&self.device, &self.surface_config);
|
||||
self.filter.resize(&self.queue, new_size);
|
||||
}
|
||||
WindowEvent::CloseRequested => {
|
||||
elwt.exit();
|
||||
}
|
||||
WindowEvent::KeyboardInput { event, .. } => {
|
||||
fn gamepad_button(input: &winit::event::KeyEvent) -> u8 {
|
||||
match input.physical_key {
|
||||
PhysicalKey::Code(KeyCode::KeyZ) => 16,
|
||||
PhysicalKey::Code(KeyCode::KeyX) => 32,
|
||||
PhysicalKey::Code(KeyCode::KeyA) => 64,
|
||||
PhysicalKey::Code(KeyCode::KeyS) => 128,
|
||||
_ => match input.logical_key {
|
||||
Key::Named(NamedKey::ArrowUp) => 1,
|
||||
Key::Named(NamedKey::ArrowDown) => 2,
|
||||
Key::Named(NamedKey::ArrowLeft) => 4,
|
||||
Key::Named(NamedKey::ArrowRight) => 8,
|
||||
_ => 0,
|
||||
},
|
||||
}
|
||||
self.event_loop.run_return(|event, _, control_flow| {
|
||||
*control_flow = ControlFlow::WaitUntil(self.next_frame);
|
||||
let mut new_filter = None;
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::Resized(new_size) => {
|
||||
self.surface_config.width = new_size.width;
|
||||
self.surface_config.height = new_size.height;
|
||||
self.surface.configure(&self.device, &self.surface_config);
|
||||
self.filter.resize(&self.queue, new_size, self.scale_mode);
|
||||
}
|
||||
WindowEvent::CloseRequested => {
|
||||
self.is_open = false;
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
WindowEvent::KeyboardInput { input, .. } => {
|
||||
fn gamepad_button(input: &winit::event::KeyboardInput) -> u8 {
|
||||
match input.scancode {
|
||||
44 => 16,
|
||||
45 => 32,
|
||||
30 => 64,
|
||||
31 => 128,
|
||||
_ => match input.virtual_keycode {
|
||||
Some(VirtualKeyCode::Up) => 1,
|
||||
Some(VirtualKeyCode::Down) => 2,
|
||||
Some(VirtualKeyCode::Left) => 4,
|
||||
Some(VirtualKeyCode::Right) => 8,
|
||||
_ => 0,
|
||||
},
|
||||
}
|
||||
if event.state == winit::event::ElementState::Pressed {
|
||||
match event.logical_key {
|
||||
Key::Named(NamedKey::Escape) => {
|
||||
elwt.exit();
|
||||
}
|
||||
Key::Character(ref c) => match c.as_str() {
|
||||
"f" => {
|
||||
let fullscreen = if self.window.fullscreen().is_some() {
|
||||
None
|
||||
} else {
|
||||
Some(Fullscreen::Borderless(None))
|
||||
};
|
||||
self.is_fullscreen = fullscreen.is_some();
|
||||
self.window.set_fullscreen(fullscreen);
|
||||
}
|
||||
"r" => reset = true,
|
||||
"1" => new_filter = Some(1),
|
||||
"2" => new_filter = Some(2),
|
||||
"3" => new_filter = Some(3),
|
||||
"4" => new_filter = Some(4),
|
||||
"5" => new_filter = Some(5),
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
if input.state == winit::event::ElementState::Pressed {
|
||||
match input.virtual_keycode {
|
||||
Some(VirtualKeyCode::Escape) => {
|
||||
self.is_open = false;
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
Some(VirtualKeyCode::F) => {
|
||||
let fullscreen = if self.window.fullscreen().is_some() {
|
||||
None
|
||||
} else {
|
||||
Some(Fullscreen::Borderless(None))
|
||||
};
|
||||
self.is_fullscreen = fullscreen.is_some();
|
||||
self.window.set_fullscreen(fullscreen);
|
||||
}
|
||||
Some(VirtualKeyCode::M) => {
|
||||
self.scale_mode = match self.scale_mode {
|
||||
ScaleMode::Fit => ScaleMode::Fill,
|
||||
ScaleMode::Fill => ScaleMode::Fit,
|
||||
};
|
||||
self.filter.resize(
|
||||
&self.queue,
|
||||
PhysicalSize {
|
||||
width: self.surface_config.width,
|
||||
height: self.surface_config.height,
|
||||
},
|
||||
self.scale_mode,
|
||||
);
|
||||
}
|
||||
Some(VirtualKeyCode::R) => reset = true,
|
||||
Some(VirtualKeyCode::Key1) => new_filter = Some(1),
|
||||
Some(VirtualKeyCode::Key2) => new_filter = Some(2),
|
||||
Some(VirtualKeyCode::Key3) => new_filter = Some(3),
|
||||
Some(VirtualKeyCode::Key4) => new_filter = Some(4),
|
||||
Some(VirtualKeyCode::Key5) => new_filter = Some(5),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
self.gamepads[0] |= gamepad_button(&event);
|
||||
} else {
|
||||
self.gamepads[0] &= !gamepad_button(&event);
|
||||
}
|
||||
self.gamepads[0] |= gamepad_button(&input);
|
||||
} else {
|
||||
self.gamepads[0] &= !gamepad_button(&input);
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
Event::RedrawEventsCleared => {
|
||||
if Instant::now() >= self.next_frame
|
||||
// workaround needed on Wayland until the next winit release
|
||||
&& self.window.fullscreen().is_some() == self.is_fullscreen
|
||||
{
|
||||
*control_flow = ControlFlow::Exit
|
||||
}
|
||||
}
|
||||
if let Some(new_filter) = new_filter {
|
||||
self.filter = create_filter(
|
||||
&self.device,
|
||||
&self.palette_screen_mode.screen_view,
|
||||
self.window.inner_size(),
|
||||
self.surface_config.format,
|
||||
new_filter,
|
||||
);
|
||||
}
|
||||
});
|
||||
match status {
|
||||
PumpStatus::Exit(_) => self.is_open = false,
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if Instant::now() >= self.next_frame {
|
||||
break;
|
||||
if let Some(new_filter) = new_filter {
|
||||
self.filter = create_filter(
|
||||
&self.device,
|
||||
&self.palette_screen_mode.screen_view,
|
||||
self.window.inner_size(),
|
||||
self.surface_config.format,
|
||||
new_filter,
|
||||
self.scale_mode,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
Input {
|
||||
gamepads: self.gamepads,
|
||||
reset,
|
||||
@@ -243,12 +256,10 @@ impl WindowImpl for Window {
|
||||
b: 0.0,
|
||||
a: 1.0,
|
||||
}),
|
||||
store: wgpu::StoreOp::Store,
|
||||
store: true,
|
||||
},
|
||||
})],
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
});
|
||||
|
||||
self.filter.render(&mut render_pass);
|
||||
@@ -269,6 +280,7 @@ fn create_filter(
|
||||
window_size: PhysicalSize<u32>,
|
||||
surface_format: wgpu::TextureFormat,
|
||||
filter: u32,
|
||||
scale_mode: ScaleMode,
|
||||
) -> Box<dyn Filter> {
|
||||
match filter {
|
||||
1 => Box::new(SquareFilter::new(
|
||||
@@ -276,6 +288,7 @@ fn create_filter(
|
||||
screen_texture,
|
||||
window_size,
|
||||
surface_format,
|
||||
scale_mode,
|
||||
)),
|
||||
2 => Box::new(FastCrtFilter::new(
|
||||
device,
|
||||
@@ -283,12 +296,14 @@ fn create_filter(
|
||||
window_size,
|
||||
surface_format,
|
||||
false,
|
||||
scale_mode,
|
||||
)),
|
||||
3 => Box::new(CrtFilter::new(
|
||||
device,
|
||||
screen_texture,
|
||||
window_size,
|
||||
surface_format,
|
||||
scale_mode,
|
||||
)),
|
||||
4 => Box::new(FastCrtFilter::new(
|
||||
device,
|
||||
@@ -296,18 +311,20 @@ fn create_filter(
|
||||
window_size,
|
||||
surface_format,
|
||||
true,
|
||||
scale_mode,
|
||||
)),
|
||||
_ => Box::new(AutoCrtFilter::new(
|
||||
device,
|
||||
screen_texture,
|
||||
window_size,
|
||||
surface_format,
|
||||
scale_mode,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
trait Filter {
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>);
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>, scale_mode: ScaleMode);
|
||||
fn render<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>);
|
||||
}
|
||||
|
||||
@@ -323,9 +340,11 @@ impl AutoCrtFilter {
|
||||
screen: &wgpu::TextureView,
|
||||
resolution: PhysicalSize<u32>,
|
||||
surface_format: wgpu::TextureFormat,
|
||||
scale_mode: ScaleMode,
|
||||
) -> AutoCrtFilter {
|
||||
let small = CrtFilter::new(device, screen, resolution, surface_format);
|
||||
let large = FastCrtFilter::new(device, screen, resolution, surface_format, true);
|
||||
let small = CrtFilter::new(device, screen, resolution, surface_format, scale_mode);
|
||||
let large =
|
||||
FastCrtFilter::new(device, screen, resolution, surface_format, true, scale_mode);
|
||||
AutoCrtFilter {
|
||||
small,
|
||||
large,
|
||||
@@ -335,9 +354,9 @@ impl AutoCrtFilter {
|
||||
}
|
||||
|
||||
impl Filter for AutoCrtFilter {
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>) {
|
||||
self.small.resize(queue, new_size);
|
||||
self.large.resize(queue, new_size);
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>, scale_mode: ScaleMode) {
|
||||
self.small.resize(queue, new_size, scale_mode);
|
||||
self.large.resize(queue, new_size, scale_mode);
|
||||
self.resolution = new_size;
|
||||
}
|
||||
|
||||
@@ -550,12 +569,10 @@ impl PaletteScreenMode {
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Load,
|
||||
store: wgpu::StoreOp::Store,
|
||||
store: true,
|
||||
},
|
||||
})],
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
});
|
||||
|
||||
render_pass.set_pipeline(&self.pipeline);
|
||||
|
||||
28
uw8-window/src/gpu/scale_mode.rs
Normal file
28
uw8-window/src/gpu/scale_mode.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use winit::dpi::PhysicalSize;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum ScaleMode {
|
||||
Fit,
|
||||
Fill,
|
||||
}
|
||||
|
||||
impl Default for ScaleMode {
|
||||
fn default() -> ScaleMode {
|
||||
ScaleMode::Fit
|
||||
}
|
||||
}
|
||||
|
||||
impl ScaleMode {
|
||||
pub fn texture_scale_from_resolution(&self, res: PhysicalSize<u32>) -> [f32; 4] {
|
||||
let scale = match self {
|
||||
ScaleMode::Fit => ((res.width as f32) / 160.0).min((res.height as f32) / 120.0),
|
||||
ScaleMode::Fill => ((res.width as f32) / 160.0).max((res.height as f32) / 120.0),
|
||||
};
|
||||
[
|
||||
scale / res.width as f32,
|
||||
scale / res.height as f32,
|
||||
2.0 / scale,
|
||||
0.0,
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use wgpu::util::DeviceExt;
|
||||
use winit::dpi::PhysicalSize;
|
||||
|
||||
use super::Filter;
|
||||
use super::{scale_mode::ScaleMode, Filter};
|
||||
|
||||
pub struct SquareFilter {
|
||||
uniform_buffer: wgpu::Buffer,
|
||||
@@ -15,9 +15,10 @@ impl SquareFilter {
|
||||
screen: &wgpu::TextureView,
|
||||
resolution: PhysicalSize<u32>,
|
||||
surface_format: wgpu::TextureFormat,
|
||||
scale_mode: ScaleMode,
|
||||
) -> SquareFilter {
|
||||
let uniforms = Uniforms {
|
||||
texture_scale: texture_scale_from_resolution(resolution),
|
||||
texture_scale: scale_mode.texture_scale_from_resolution(resolution),
|
||||
};
|
||||
|
||||
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
@@ -126,9 +127,9 @@ impl SquareFilter {
|
||||
}
|
||||
|
||||
impl Filter for SquareFilter {
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>) {
|
||||
fn resize(&mut self, queue: &wgpu::Queue, new_size: PhysicalSize<u32>, scale_mode: ScaleMode) {
|
||||
let uniforms = Uniforms {
|
||||
texture_scale: texture_scale_from_resolution(new_size),
|
||||
texture_scale: scale_mode.texture_scale_from_resolution(new_size),
|
||||
};
|
||||
queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[uniforms]));
|
||||
}
|
||||
@@ -140,16 +141,6 @@ impl Filter for SquareFilter {
|
||||
}
|
||||
}
|
||||
|
||||
fn texture_scale_from_resolution(res: PhysicalSize<u32>) -> [f32; 4] {
|
||||
let scale = ((res.width as f32) / 160.0).min((res.height as f32) / 120.0);
|
||||
[
|
||||
scale / res.width as f32,
|
||||
scale / res.height as f32,
|
||||
2.0 / scale,
|
||||
0.0,
|
||||
]
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
struct Uniforms {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use gpu::scale_mode::ScaleMode;
|
||||
use std::time::Instant;
|
||||
|
||||
mod cpu;
|
||||
@@ -73,6 +74,7 @@ pub struct WindowConfig {
|
||||
fullscreen: bool,
|
||||
fps_counter: bool,
|
||||
scale: f32,
|
||||
scale_mode: ScaleMode,
|
||||
}
|
||||
|
||||
impl Default for WindowConfig {
|
||||
@@ -83,6 +85,7 @@ impl Default for WindowConfig {
|
||||
fullscreen: false,
|
||||
fps_counter: false,
|
||||
scale: 2.,
|
||||
scale_mode: ScaleMode::Fit,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +112,9 @@ impl WindowConfig {
|
||||
.opt_value_from_str("--scale")
|
||||
.unwrap()
|
||||
.unwrap_or(self.scale);
|
||||
if args.contains("--scale-fill") {
|
||||
self.scale_mode = ScaleMode::Fill;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
"@parcel/optimizer-data-url": "^2.0.0",
|
||||
"@parcel/transformer-inline-string": "^2.0.0",
|
||||
"parcel": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="uw8">
|
||||
<a href="https://exoticorn.github.io/microw8">MicroW8</a> 0.2.2
|
||||
<a href="https://exoticorn.github.io/microw8">MicroW8</a> 0.4.1
|
||||
</div>
|
||||
<div id="centered">
|
||||
<canvas class="screen" id="screen" width="320" height="240">
|
||||
@@ -27,4 +27,4 @@
|
||||
<script type="module">
|
||||
import "./main.js";
|
||||
</script>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -240,6 +240,7 @@ export default function MicroW8(screen, config = {}) {
|
||||
await audioReadyPromise;
|
||||
|
||||
let startTime = Date.now();
|
||||
let frameCounter = 0;
|
||||
|
||||
const timePerFrame = 1000 / 60;
|
||||
|
||||
@@ -306,6 +307,7 @@ export default function MicroW8(screen, config = {}) {
|
||||
let time = Date.now() - startTime;
|
||||
u32Mem[16] = time;
|
||||
u32Mem[17] = pad | gamepad;
|
||||
u32Mem[18] = frameCounter++;
|
||||
if(instance.exports.upd) {
|
||||
instance.exports.upd();
|
||||
}
|
||||
|
||||
1746
web/yarn.lock
1746
web/yarn.lock
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user