3 Commits

17 changed files with 119 additions and 69 deletions

View File

@@ -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 }}

2
Cargo.lock generated
View File

@@ -3467,7 +3467,7 @@ checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0"
[[package]]
name = "uw8"
version = "0.4.0"
version = "0.4.1"
dependencies = [
"ansi_term",
"anyhow",

View File

@@ -1,6 +1,6 @@
[package]
name = "uw8"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -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.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)
* [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

View File

@@ -31,19 +31,19 @@ Examplers for older versions:
## Versions
### v0.4.0
### v0.4.1
* [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)
* [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:
* 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
* Windows: fix bad/inconsistent frame rate
* fix choppy sound on devices with sample rates != 44100 kHz
* add scale mode 'fill' option
### Older versions

View File

@@ -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`

View File

@@ -2,6 +2,19 @@
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)

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,7 @@
<section>
<h1 class="text-center heading-text">A WebAssembly based fantasy console</h1>
</section>
<a href="v0.4.0">
<a href="v0.4.1">
<img class="demonstration-gif" style="width:640px;height:480px;image-rendering:pixelated" src="img/technotunnel.png"></img>
</a>
</div>

View File

@@ -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 {

View File

@@ -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;
}

View File

@@ -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 {

View File

@@ -1,5 +1,6 @@
use crate::{Input, WindowConfig, WindowImpl};
use anyhow::{anyhow, Result};
use scale_mode::ScaleMode;
use std::time::Instant;
use winit::{
@@ -13,6 +14,7 @@ use winit::platform::run_return::EventLoopExtRunReturn;
mod crt;
mod fast_crt;
pub mod scale_mode;
mod square;
use crt::CrtFilter;
@@ -34,6 +36,7 @@ pub struct Window {
next_frame: Instant,
is_fullscreen: bool,
is_open: bool,
scale_mode: ScaleMode,
}
impl Window {
@@ -90,6 +93,7 @@ impl Window {
window.inner_size(),
surface_config.format,
window_config.filter,
window_config.scale_mode,
);
surface.configure(&device, &surface_config);
@@ -109,6 +113,7 @@ impl Window {
next_frame: Instant::now(),
is_fullscreen: window_config.fullscreen,
is_open: true,
scale_mode: window_config.scale_mode,
})
}
@@ -128,7 +133,7 @@ impl WindowImpl for Window {
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.filter.resize(&self.queue, new_size, self.scale_mode);
}
WindowEvent::CloseRequested => {
self.is_open = false;
@@ -165,6 +170,20 @@ impl WindowImpl for Window {
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),
@@ -198,6 +217,7 @@ impl WindowImpl for Window {
self.window.inner_size(),
self.surface_config.format,
new_filter,
self.scale_mode,
);
}
});
@@ -260,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(
@@ -267,6 +288,7 @@ fn create_filter(
screen_texture,
window_size,
surface_format,
scale_mode,
)),
2 => Box::new(FastCrtFilter::new(
device,
@@ -274,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,
@@ -287,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>);
}
@@ -314,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,
@@ -326,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;
}

View 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,
]
}
}

View File

@@ -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 {

View File

@@ -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;
}
}
}

View File

@@ -10,7 +10,7 @@
</head>
<body>
<div id="uw8">
<a href="https://exoticorn.github.io/microw8">MicroW8</a> 0.4.0
<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">