mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 19:26:43 +01:00
Compare commits
10 Commits
next
...
b23248f359
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b23248f359 | ||
| a651107104 | |||
| 22c35e37f4 | |||
| 805c939097 | |||
| 440e150896 | |||
| 77b2e27346 | |||
| 09e4fcbf14 | |||
|
|
1d89ef8613 | ||
|
|
c7be8be2c4 | ||
|
|
d9f9500b76 |
2313
Cargo.lock
generated
2313
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
@@ -11,21 +11,21 @@ native = ["wasmtime", "uw8-window", "cpal", "rubato" ]
|
|||||||
browser = ["warp", "tokio", "tokio-stream", "webbrowser"]
|
browser = ["warp", "tokio", "tokio-stream", "webbrowser"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmtime = { version = "5.0.0", optional = true }
|
wasmtime = { version = "12.0.0", optional = true }
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
uw8-window = { path = "uw8-window", optional = true }
|
uw8-window = { path = "uw8-window", optional = true }
|
||||||
notify-debouncer-mini = { version = "0.2.1", default-features = false }
|
notify-debouncer-mini = { version = "0.4.1", default-features = false }
|
||||||
pico-args = "0.5"
|
pico-args = "0.5"
|
||||||
curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "0e7ea50" }
|
curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "0e7ea50" }
|
||||||
wat = "1"
|
wat = "1"
|
||||||
uw8-tool = { path = "uw8-tool" }
|
uw8-tool = { path = "uw8-tool" }
|
||||||
same-file = "1"
|
same-file = "1"
|
||||||
warp = { version = "0.3.3", optional = true }
|
warp = { version = "0.3.5", optional = true }
|
||||||
tokio = { version = "1.24.0", features = ["sync", "rt"], optional = true }
|
tokio = { version = "1.32.0", features = ["sync", "rt"], optional = true }
|
||||||
tokio-stream = { version = "0.1.11", features = ["sync"], optional = true }
|
tokio-stream = { version = "0.1.14", features = ["sync"], optional = true }
|
||||||
webbrowser = { version = "0.8.6", optional = true }
|
webbrowser = { version = "0.8.11", optional = true }
|
||||||
ansi_term = "0.12.1"
|
ansi_term = "0.12.1"
|
||||||
cpal = { version = "0.14.2", optional = true }
|
cpal = { version = "0.15.2", optional = true }
|
||||||
rubato = { version = "0.12.0", optional = true }
|
rubato = { version = "0.14.0", optional = true }
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
include "../include/microw8-api.cwa"
|
|
||||||
|
|
||||||
const SPRITE = 0x20000;
|
|
||||||
|
|
||||||
export fn upd() {
|
|
||||||
cls(0);
|
|
||||||
let t = time();
|
|
||||||
let i: i32;
|
|
||||||
loop spriteLoop {
|
|
||||||
let inline x = sin(t * -1.3 + i as f32 / 8_f) * 180_f + 160_f;
|
|
||||||
let inline y = sin(t * 1.7 + i as f32 / 9_f) * 140_f + 120_f;
|
|
||||||
blitSprite(SPRITE, 16, x as i32, y as i32, 0x100);
|
|
||||||
branch_if (i +:= 1) < 200: spriteLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
start fn start() {
|
|
||||||
printChar('OO');
|
|
||||||
circle(8_f, 8_f, 6_f, 75);
|
|
||||||
grabSprite(SPRITE, 16, 0, 0, 0);
|
|
||||||
}
|
|
||||||
@@ -30,13 +30,11 @@ import "env.printInt" fn printInt(i32);
|
|||||||
import "env.setTextColor" fn setTextColor(i32);
|
import "env.setTextColor" fn setTextColor(i32);
|
||||||
import "env.setBackgroundColor" fn setBackgroundColor(i32);
|
import "env.setBackgroundColor" fn setBackgroundColor(i32);
|
||||||
import "env.setCursorPosition" fn setCursorPosition(i32, i32);
|
import "env.setCursorPosition" fn setCursorPosition(i32, i32);
|
||||||
import "env.rectangleOutline" fn rectangleOutline(f32, f32, f32, f32, i32);
|
import "env.rectangle_outline" fn rectangle_outline(f32, f32, f32, f32, i32);
|
||||||
import "env.circleOutline" fn circleOutline(f32, f32, f32, i32);
|
import "env.circle_outline" fn circle_outline(f32, f32, f32, i32);
|
||||||
import "env.exp" fn exp(f32) -> f32;
|
import "env.exp" fn exp(f32) -> f32;
|
||||||
import "env.playNote" fn playNote(i32, i32);
|
import "env.playNote" fn playNote(i32, i32);
|
||||||
import "env.sndGes" fn sndGes(i32) -> f32;
|
import "env.sndGes" fn sndGes(i32) -> f32;
|
||||||
import "env.blitSprite" fn blitSprite(i32, i32, i32, i32, i32);
|
|
||||||
import "env.grabSprite" fn grabSprite(i32, i32, i32, i32, i32);
|
|
||||||
|
|
||||||
const TIME_MS = 0x40;
|
const TIME_MS = 0x40;
|
||||||
const GAMEPAD = 0x44;
|
const GAMEPAD = 0x44;
|
||||||
|
|||||||
@@ -30,13 +30,11 @@
|
|||||||
(import "env" "setTextColor" (func $setTextColor (param i32)))
|
(import "env" "setTextColor" (func $setTextColor (param i32)))
|
||||||
(import "env" "setBackgroundColor" (func $setBackgroundColor (param i32)))
|
(import "env" "setBackgroundColor" (func $setBackgroundColor (param i32)))
|
||||||
(import "env" "setCursorPosition" (func $setCursorPosition (param i32) (param i32)))
|
(import "env" "setCursorPosition" (func $setCursorPosition (param i32) (param i32)))
|
||||||
(import "env" "rectangleOutline" (func $rectangleOutline (param f32) (param f32) (param f32) (param f32) (param i32)))
|
(import "env" "rectangle_outline" (func $rectangle_outline (param f32) (param f32) (param f32) (param f32) (param i32)))
|
||||||
(import "env" "circleOutline" (func $circleOutline (param f32) (param f32) (param f32) (param i32)))
|
(import "env" "circle_outline" (func $circle_outline (param f32) (param f32) (param f32) (param i32)))
|
||||||
(import "env" "exp" (func $exp (param f32) (result f32)))
|
(import "env" "exp" (func $exp (param f32) (result f32)))
|
||||||
(import "env" "playNote" (func $playNote (param i32) (param i32)))
|
(import "env" "playNote" (func $playNote (param i32) (param i32)))
|
||||||
(import "env" "sndGes" (func $sndGes (param i32) (result f32)))
|
(import "env" "sndGes" (func $sndGes (param i32) (result f32)))
|
||||||
(import "env" "blitSprite" (func $blitSprite (param i32) (param i32) (param i32) (param i32) (param i32)))
|
|
||||||
(import "env" "grabSprite" (func $grabSprite (param i32) (param i32) (param i32) (param i32) (param i32)))
|
|
||||||
|
|
||||||
;; to use defines, include this file with a preprocessor
|
;; to use defines, include this file with a preprocessor
|
||||||
;; like gpp (https://logological.org/gpp).
|
;; like gpp (https://logological.org/gpp).
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ pub fn build(b: *std.build.Builder) void {
|
|||||||
|
|
||||||
const lib = b.addSharedLibrary("cart", "main.zig", .unversioned);
|
const lib = b.addSharedLibrary("cart", "main.zig", .unversioned);
|
||||||
lib.setBuildMode(mode);
|
lib.setBuildMode(mode);
|
||||||
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding, .cpu_features_add = std.Target.wasm.featureSet(&.{.nontrapping_fptoint}) });
|
lib.setTarget(.{
|
||||||
|
.cpu_arch = .wasm32,
|
||||||
|
.os_tag = .freestanding,
|
||||||
|
.cpu_features_add = std.Target.wasm.featureSet(&.{ .nontrapping_fptoint })
|
||||||
|
});
|
||||||
lib.import_memory = true;
|
lib.import_memory = true;
|
||||||
lib.initial_memory = 262144;
|
lib.initial_memory = 262144;
|
||||||
lib.max_memory = 262144;
|
lib.max_memory = 262144;
|
||||||
@@ -14,13 +18,19 @@ pub fn build(b: *std.build.Builder) void {
|
|||||||
lib.install();
|
lib.install();
|
||||||
|
|
||||||
if (lib.install_step) |install_step| {
|
if (lib.install_step) |install_step| {
|
||||||
const run_filter_exports = b.addSystemCommand(&[_][]const u8{ "uw8", "filter-exports", "zig-out/lib/cart.wasm", "zig-out/lib/cart-filtered.wasm" });
|
const run_filter_exports = b.addSystemCommand(&[_][]const u8{
|
||||||
|
"uw8", "filter-exports", "zig-out/lib/cart.wasm", "zig-out/lib/cart-filtered.wasm"
|
||||||
|
});
|
||||||
run_filter_exports.step.dependOn(&install_step.step);
|
run_filter_exports.step.dependOn(&install_step.step);
|
||||||
|
|
||||||
const run_wasm_opt = b.addSystemCommand(&[_][]const u8{ "wasm-opt", "--enable-nontrapping-float-to-int", "-Oz", "-o", "zig-out/cart.wasm", "zig-out/lib/cart-filtered.wasm" });
|
const run_wasm_opt = b.addSystemCommand(&[_][]const u8{
|
||||||
|
"wasm-opt", "-Oz", "-o", "zig-out/cart.wasm", "zig-out/lib/cart-filtered.wasm"
|
||||||
|
});
|
||||||
run_wasm_opt.step.dependOn(&run_filter_exports.step);
|
run_wasm_opt.step.dependOn(&run_filter_exports.step);
|
||||||
|
|
||||||
const run_uw8_pack = b.addSystemCommand(&[_][]const u8{ "uw8", "pack", "-l", "9", "zig-out/cart.wasm", "zig-out/cart.uw8" });
|
const run_uw8_pack = b.addSystemCommand(&[_][]const u8{
|
||||||
|
"uw8", "pack", "-l", "9", "zig-out/cart.wasm", "zig-out/cart.uw8"
|
||||||
|
});
|
||||||
run_uw8_pack.step.dependOn(&run_wasm_opt.step);
|
run_uw8_pack.step.dependOn(&run_wasm_opt.step);
|
||||||
|
|
||||||
const make_opt = b.step("make_opt", "make size optimized cart");
|
const make_opt = b.step("make_opt", "make size optimized cart");
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
extern fn atan2(x: f32, y: f32) f32;
|
extern fn atan2(x: f32, y: f32) f32;
|
||||||
extern fn time() f32;
|
extern fn time() f32;
|
||||||
|
|
||||||
pub const FRAMEBUFFER: *[320 * 240]u8 = @intToPtr(*[320 * 240]u8, 120);
|
pub const FRAMEBUFFER: *[320*240]u8 = @intToPtr(*[320*240]u8, 120);
|
||||||
|
|
||||||
export fn upd() void {
|
export fn upd() void {
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
while (true) {
|
while(true) {
|
||||||
var t = time() * 63.0;
|
var t = time() * 63.0;
|
||||||
var x = @intToFloat(f32, (@intCast(i32, i % 320) - 160));
|
var x = @intToFloat(f32, (@intCast(i32, i % 320) - 160));
|
||||||
var y = @intToFloat(f32, (@intCast(i32, i / 320) - 120));
|
var y = @intToFloat(f32, (@intCast(i32, i / 320) - 120));
|
||||||
@@ -13,10 +13,8 @@ export fn upd() void {
|
|||||||
var u = atan2(x, y) * 512.0 / 3.141;
|
var u = atan2(x, y) * 512.0 / 3.141;
|
||||||
var c = @intCast(u8, (@floatToInt(i32, d + t * 2.0) ^ @floatToInt(i32, u + t)) & 255) >> 4;
|
var c = @intCast(u8, (@floatToInt(i32, d + t * 2.0) ^ @floatToInt(i32, u + t)) & 255) >> 4;
|
||||||
|
|
||||||
FRAMEBUFFER[i] = c;
|
FRAMEBUFFER[@as(usize, i)] = c;
|
||||||
i += 1;
|
i += 1;
|
||||||
if (i >= 320 * 240) {
|
if(i >= 320*240) { break; }
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -62,7 +62,6 @@ export fn sndGes(t: i32) -> f32 {
|
|||||||
let phase = channelState!GesChannelState.Phase;
|
let phase = channelState!GesChannelState.Phase;
|
||||||
|
|
||||||
let inline pulseWidth = channelReg?1;
|
let inline pulseWidth = channelReg?1;
|
||||||
let phaseShift = (pulseWidth - 128) * 255;
|
|
||||||
let invPhaseInc = 1 as f32 / phaseInc as f32;
|
let invPhaseInc = 1 as f32 / phaseInc as f32;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
@@ -131,7 +130,7 @@ export fn sndGes(t: i32) -> f32 {
|
|||||||
let phaseInc = (freq * (65536.0 / 44100.0)) as i32;
|
let phaseInc = (freq * (65536.0 / 44100.0)) as i32;
|
||||||
|
|
||||||
let phase = channelState!GesChannelState.Phase;
|
let phase = channelState!GesChannelState.Phase;
|
||||||
if modSrc > ch {
|
if modSrc < ch {
|
||||||
phase = phase - (phaseInc << 6);
|
phase = phase - (phaseInc << 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ export fn rectangle(x: f32, y: f32, w: f32, h: f32, col: i32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn rectangleOutline(x: f32, y: f32, w: f32, h: f32, col: i32) {
|
export fn rectangle_outline(x: f32, y: f32, w: f32, h: f32, col: i32) {
|
||||||
let xl = nearest(x) as i32;
|
let xl = nearest(x) as i32;
|
||||||
let xr = nearest(x + w) as i32;
|
let xr = nearest(x + w) as i32;
|
||||||
let yt = nearest(y) as i32;
|
let yt = nearest(y) as i32;
|
||||||
@@ -212,7 +212,7 @@ export fn circle(cx: f32, cy: f32, radius: f32, col: i32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn circleOutline(cx: f32, cy: f32, radius: f32, col: i32) {
|
export fn circle_outline(cx: f32, cy: f32, radius: f32, col: i32) {
|
||||||
let prev_w: f32;
|
let prev_w: f32;
|
||||||
let y = clamp(nearest(cy - radius) as i32, -1, 241);
|
let y = clamp(nearest(cy - radius) as i32, -1, 241);
|
||||||
let maxY = clamp(nearest(cy + radius) as i32, -1, 241);
|
let maxY = clamp(nearest(cy + radius) as i32, -1, 241);
|
||||||
@@ -352,92 +352,6 @@ export fn line(x1: f32, y1: f32, x2: f32, y2: f32, col: i32) {
|
|||||||
setPixel(i32.trunc_sat_f32_s(x1 + f * dx), i32.trunc_sat_f32_s(y1 + f * dy), col);
|
setPixel(i32.trunc_sat_f32_s(x1 + f * dx), i32.trunc_sat_f32_s(y1 + f * dy), col);
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn blitSprite(sprite: i32, size: i32, x: i32, y: i32, control: i32) {
|
|
||||||
let lazy width = size & 65535;
|
|
||||||
let lazy height = select(size >> 16, size >> 16, width);
|
|
||||||
|
|
||||||
let lazy x0 = select(x < 0, -x, 0);
|
|
||||||
let lazy x1 = select(x + width > 320, 320 - x, width);
|
|
||||||
let lazy y0 = select(y < 0, -y, 0);
|
|
||||||
let lazy y1 = select(y + height > 240, 240 - y, height);
|
|
||||||
|
|
||||||
let lazy numRows = y1 - y0;
|
|
||||||
let lazy numCols = x1 - x0;
|
|
||||||
if numRows <= 0 | numCols <= 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let trans = (control & 511) - 256;
|
|
||||||
let lazy flip_x = 1 - ((control >> 8) & 2);
|
|
||||||
let lazy flip_y = 1 - ((control >> 9) & 2);
|
|
||||||
if flip_x < 0 {
|
|
||||||
sprite += width - 1;
|
|
||||||
}
|
|
||||||
if flip_y < 0 {
|
|
||||||
sprite += (height - 1) * width;
|
|
||||||
}
|
|
||||||
|
|
||||||
let spriteRow = sprite + x0 * flip_x + y0 * flip_y * width;
|
|
||||||
let screenRow = x + x0 + (y + y0) * 320;
|
|
||||||
|
|
||||||
loop yloop {
|
|
||||||
let lx = 0;
|
|
||||||
loop xloop {
|
|
||||||
let lazy col = (spriteRow + lx * flip_x)?0;
|
|
||||||
if col != trans {
|
|
||||||
(screenRow + lx)?120 = col;
|
|
||||||
}
|
|
||||||
branch_if (lx +:= 1) < numCols: xloop;
|
|
||||||
}
|
|
||||||
spriteRow += width * flip_y;
|
|
||||||
screenRow += 320;
|
|
||||||
branch_if numRows -:= 1: yloop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export fn grabSprite(sprite: i32, size: i32, x: i32, y: i32, control: i32) {
|
|
||||||
let lazy width = size & 65535;
|
|
||||||
let lazy height = select(size >> 16, size >> 16, width);
|
|
||||||
|
|
||||||
let lazy x0 = select(x < 0, -x, 0);
|
|
||||||
let lazy x1 = select(x + width > 320, 320 - x, width);
|
|
||||||
let lazy y0 = select(y < 0, -y, 0);
|
|
||||||
let lazy y1 = select(y + height > 240, 240 - y, height);
|
|
||||||
|
|
||||||
let lazy numRows = y1 - y0;
|
|
||||||
let lazy numCols = x1 - x0;
|
|
||||||
if numRows <= 0 | numCols <= 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let trans = (control & 511) - 256;
|
|
||||||
let lazy flip_x = 1 - ((control >> 8) & 2);
|
|
||||||
let lazy flip_y = 1 - ((control >> 9) & 2);
|
|
||||||
if flip_x < 0 {
|
|
||||||
sprite += width - 1;
|
|
||||||
}
|
|
||||||
if flip_y < 0 {
|
|
||||||
sprite += (height - 1) * width;
|
|
||||||
}
|
|
||||||
|
|
||||||
let spriteRow = sprite + x0 * flip_x + y0 * flip_y * width;
|
|
||||||
let screenRow = x + x0 + (y + y0) * 320;
|
|
||||||
|
|
||||||
loop yloop {
|
|
||||||
let lx = 0;
|
|
||||||
loop xloop {
|
|
||||||
let lazy col = (screenRow + lx)?120;
|
|
||||||
if col != trans {
|
|
||||||
(spriteRow + lx * flip_x)?0 = col;
|
|
||||||
}
|
|
||||||
branch_if (lx +:= 1) < numCols: xloop;
|
|
||||||
}
|
|
||||||
spriteRow += width * flip_y;
|
|
||||||
screenRow += 320;
|
|
||||||
branch_if numRows -:= 1: yloop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// TEXT //
|
// TEXT //
|
||||||
//////////
|
//////////
|
||||||
|
|||||||
@@ -146,13 +146,13 @@ Fills the circle at `cx, cy` and with `radius` with the given color index.
|
|||||||
|
|
||||||
(Sets all pixels where the pixel center lies inside the circle.)
|
(Sets all pixels where the pixel center lies inside the circle.)
|
||||||
|
|
||||||
### fn rectangleOutline(x: f32, y: f32, w: f32, h: f32, color: i32)
|
### fn rectangle_outline(x: f32, y: f32, w: f32, h: f32, color: i32)
|
||||||
|
|
||||||
Draws a one pixel outline on the inside of the given rectangle.
|
Draws a one pixel outline on the inside of the given rectangle.
|
||||||
|
|
||||||
(Draws the outermost pixels that are still inside the rectangle area.)
|
(Draws the outermost pixels that are still inside the rectangle area.)
|
||||||
|
|
||||||
### fn circleOutline(cx: f32, cy: f32, radius: f32, color: i32)
|
### fn circle_outline(cx: f32, cy: f32, radius: f32, color: i32)
|
||||||
|
|
||||||
Draws a one pixel outline on the inside of the given circle.
|
Draws a one pixel outline on the inside of the given circle.
|
||||||
|
|
||||||
@@ -162,21 +162,6 @@ Draws a one pixel outline on the inside of the given circle.
|
|||||||
|
|
||||||
Draws a line from `x1,y1` to `x2,y2` in the given color index.
|
Draws a line from `x1,y1` to `x2,y2` in the given color index.
|
||||||
|
|
||||||
### fn blitSprite(spriteData: i32, size: i32, x: i32, y: i32, control: i32)
|
|
||||||
|
|
||||||
Copies the pixel data at `spriteData` onto the screen at `x`, `y`. The size of the sprite is passed as `width | (height << 16)`.
|
|
||||||
If the height is given as 0, the sprite is is treated as square (width x width).
|
|
||||||
|
|
||||||
The control parameter controls masking and flipping of the sprite:
|
|
||||||
* bits 0-7: color mask index
|
|
||||||
* bit 8: switch on masked blit (pixel with color mask index are treated as transparent)
|
|
||||||
* bit 9: flip sprite x
|
|
||||||
* bit 10: flip sprite y
|
|
||||||
|
|
||||||
### fn grabSprite(spriteData: i32, size: i32, x: i32, y: i32, control: i32)
|
|
||||||
|
|
||||||
Copies the pixel data on the screen at `x`, `y` to `spriteData`. Parameters are exactly the same as `blitSprite`.
|
|
||||||
|
|
||||||
## Input
|
## Input
|
||||||
|
|
||||||
MicroW8 provides input from a gamepad with one D-Pad and 4 buttons, or a keyboard emulation thereof.
|
MicroW8 provides input from a gamepad with one D-Pad and 4 buttons, or a keyboard emulation thereof.
|
||||||
|
|||||||
@@ -16,17 +16,15 @@ pub struct FileWatcher {
|
|||||||
impl FileWatcher {
|
impl FileWatcher {
|
||||||
pub fn new() -> Result<FileWatcher> {
|
pub fn new() -> Result<FileWatcher> {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
let debouncer = new_debouncer(Duration::from_millis(100), None, move |res| match res {
|
let debouncer = new_debouncer(Duration::from_millis(100), move |res| match res {
|
||||||
Ok(events) => {
|
Ok(events) => {
|
||||||
for event in events {
|
for event in events {
|
||||||
let _ = tx.send(event);
|
let _ = tx.send(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(errs) => {
|
Err(err) => {
|
||||||
for err in errs {
|
|
||||||
eprintln!("Error watching for file changes: {err}");
|
eprintln!("Error watching for file changes: {err}");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})?;
|
})?;
|
||||||
Ok(FileWatcher {
|
Ok(FileWatcher {
|
||||||
debouncer,
|
debouncer,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use cpal::traits::*;
|
|||||||
use rubato::Resampler;
|
use rubato::Resampler;
|
||||||
use uw8_window::{Window, WindowConfig};
|
use uw8_window::{Window, WindowConfig};
|
||||||
use wasmtime::{
|
use wasmtime::{
|
||||||
Engine, GlobalType, Memory, MemoryType, Module, Mutability, Store, TypedFunc, ValType,
|
Engine, Func, GlobalType, Memory, MemoryType, Module, Mutability, Store, TypedFunc, ValType,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct MicroW8 {
|
pub struct MicroW8 {
|
||||||
@@ -90,7 +90,7 @@ impl super::Runtime for MicroW8 {
|
|||||||
let memory = wasmtime::Memory::new(&mut store, MemoryType::new(4, Some(4)))?;
|
let memory = wasmtime::Memory::new(&mut store, MemoryType::new(4, Some(4)))?;
|
||||||
|
|
||||||
let mut linker = wasmtime::Linker::new(&self.engine);
|
let mut linker = wasmtime::Linker::new(&self.engine);
|
||||||
linker.define("env", "memory", memory)?;
|
linker.define(&store, "env", "memory", memory)?;
|
||||||
|
|
||||||
let loader_instance = linker.instantiate(&mut store, &self.loader_module)?;
|
let loader_instance = linker.instantiate(&mut store, &self.loader_module)?;
|
||||||
let load_uw8 = loader_instance.get_typed_func::<i32, i32>(&mut store, "load_uw8")?;
|
let load_uw8 = loader_instance.get_typed_func::<i32, i32>(&mut store, "load_uw8")?;
|
||||||
@@ -181,12 +181,10 @@ impl super::Runtime for MicroW8 {
|
|||||||
if let Some(mut instance) = self.instance.take() {
|
if let Some(mut instance) = self.instance.take() {
|
||||||
let time = (now - instance.start_time).as_millis() as i32;
|
let time = (now - instance.start_time).as_millis() as i32;
|
||||||
let next_frame = {
|
let next_frame = {
|
||||||
let frame = (time as u32 as u64 * 6 / 100) as u32;
|
let offset = ((time as u32 as i64 * 6) % 100 - 50) / 6;
|
||||||
let cur_offset = (time as u32).wrapping_sub((frame as u64 * 100 / 6) as u32);
|
let max = now + Duration::from_millis(17);
|
||||||
let next_time =
|
let next_center = now + Duration::from_millis((16 - offset) as u64);
|
||||||
((frame as u64 + 1) * 100 / 6 + cur_offset.max(1).min(4) as u64) as u32;
|
next_center.min(max)
|
||||||
let offset = next_time.wrapping_sub(time as u32);
|
|
||||||
now + Duration::from_millis(offset as u64)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -257,15 +255,12 @@ fn add_native_functions(
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
for i in 0..16 {
|
for i in 0..16 {
|
||||||
linker.define(
|
let global = wasmtime::Global::new(
|
||||||
"env",
|
|
||||||
&format!("g_reserved{}", i),
|
|
||||||
wasmtime::Global::new(
|
|
||||||
&mut *store,
|
&mut *store,
|
||||||
GlobalType::new(ValType::I32, Mutability::Const),
|
GlobalType::new(ValType::I32, Mutability::Const),
|
||||||
0.into(),
|
0.into(),
|
||||||
)?,
|
|
||||||
)?;
|
)?;
|
||||||
|
linker.define(&store, "env", &format!("g_reserved{}", i), global)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -278,14 +273,18 @@ fn instantiate_platform(
|
|||||||
) -> Result<wasmtime::Instance> {
|
) -> Result<wasmtime::Instance> {
|
||||||
let platform_instance = linker.instantiate(&mut *store, &platform_module)?;
|
let platform_instance = linker.instantiate(&mut *store, &platform_module)?;
|
||||||
|
|
||||||
for export in platform_instance.exports(&mut *store) {
|
let exports: Vec<(String, Func)> = platform_instance
|
||||||
linker.define(
|
.exports(&mut *store)
|
||||||
"env",
|
.map(|e| {
|
||||||
export.name(),
|
(
|
||||||
export
|
e.name().to_owned(),
|
||||||
.into_func()
|
e.into_func()
|
||||||
.expect("platform surely only exports functions"),
|
.expect("platform surely only exports functions"),
|
||||||
)?;
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
for (name, func) in exports {
|
||||||
|
linker.define(&store, "env", &name, func)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(platform_instance)
|
Ok(platform_instance)
|
||||||
@@ -312,7 +311,7 @@ fn init_sound(
|
|||||||
let memory = wasmtime::Memory::new(&mut store, MemoryType::new(4, Some(4)))?;
|
let memory = wasmtime::Memory::new(&mut store, MemoryType::new(4, Some(4)))?;
|
||||||
|
|
||||||
let mut linker = wasmtime::Linker::new(engine);
|
let mut linker = wasmtime::Linker::new(engine);
|
||||||
linker.define("env", "memory", memory)?;
|
linker.define(&store, "env", "memory", memory)?;
|
||||||
add_native_functions(&mut linker, &mut store)?;
|
add_native_functions(&mut linker, &mut store)?;
|
||||||
|
|
||||||
let platform_instance = instantiate_platform(&mut linker, &mut store, platform_module)?;
|
let platform_instance = instantiate_platform(&mut linker, &mut store, platform_module)?;
|
||||||
@@ -329,23 +328,26 @@ fn init_sound(
|
|||||||
let mut configs: Vec<_> = device
|
let mut configs: Vec<_> = device
|
||||||
.supported_output_configs()?
|
.supported_output_configs()?
|
||||||
.filter(|config| {
|
.filter(|config| {
|
||||||
config.channels() == 2 && config.sample_format() == cpal::SampleFormat::F32
|
config.channels() == 2
|
||||||
|
&& (config.sample_format() == cpal::SampleFormat::F32
|
||||||
|
|| config.sample_format() == cpal::SampleFormat::I16)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
configs.sort_by_key(|config| {
|
configs.sort_by_key(|config| {
|
||||||
let rate = 44100
|
let rate = 44100
|
||||||
.max(config.min_sample_rate().0)
|
.max(config.min_sample_rate().0)
|
||||||
.min(config.max_sample_rate().0);
|
.min(config.max_sample_rate().0);
|
||||||
if rate >= 44100 {
|
let prio = if rate >= 44100 {
|
||||||
rate - 44100
|
rate - 44100
|
||||||
} else {
|
} else {
|
||||||
(44100 - rate) * 1000
|
(44100 - rate) * 1000
|
||||||
}
|
};
|
||||||
|
prio + (config.sample_format() == cpal::SampleFormat::I16) as u32
|
||||||
});
|
});
|
||||||
let config = configs
|
let config = configs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| anyhow!("Could not find float output config"))?;
|
.ok_or_else(|| anyhow!("Could not find float or 16bit signed output config"))?;
|
||||||
let sample_rate = cpal::SampleRate(44100)
|
let sample_rate = cpal::SampleRate(44100)
|
||||||
.max(config.min_sample_rate())
|
.max(config.min_sample_rate())
|
||||||
.min(config.max_sample_rate());
|
.min(config.max_sample_rate());
|
||||||
@@ -356,6 +358,7 @@ fn init_sound(
|
|||||||
cpal::BufferSize::Fixed(256.max(min).min(max))
|
cpal::BufferSize::Fixed(256.max(min).min(max))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let sample_format = config.sample_format();
|
||||||
let config = cpal::StreamConfig {
|
let config = cpal::StreamConfig {
|
||||||
buffer_size,
|
buffer_size,
|
||||||
..config.config()
|
..config.config()
|
||||||
@@ -375,8 +378,8 @@ fn init_sound(
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let rs = rubato::FftFixedIn::new(44100, sample_rate, 128, 1, 2)?;
|
let rs = rubato::FftFixedIn::new(44100, sample_rate, 128, 1, 2)?;
|
||||||
let input_buffers = rs.input_buffer_allocate();
|
let input_buffers = rs.input_buffer_allocate(true);
|
||||||
let output_buffers = rs.output_buffer_allocate();
|
let output_buffers = rs.output_buffer_allocate(true);
|
||||||
Some(Resampler {
|
Some(Resampler {
|
||||||
resampler: rs,
|
resampler: rs,
|
||||||
input_buffers,
|
input_buffers,
|
||||||
@@ -388,9 +391,8 @@ fn init_sound(
|
|||||||
let mut sample_index = 0;
|
let mut sample_index = 0;
|
||||||
let mut pending_updates: Vec<RegisterUpdate> = Vec::with_capacity(30);
|
let mut pending_updates: Vec<RegisterUpdate> = Vec::with_capacity(30);
|
||||||
let mut current_time = 0;
|
let mut current_time = 0;
|
||||||
let stream = device.build_output_stream(
|
|
||||||
&config,
|
let mut callback = move |mut outer_buffer: &mut [f32], _: &_| {
|
||||||
move |mut outer_buffer: &mut [f32], _| {
|
|
||||||
let mut first_update = true;
|
let mut first_update = true;
|
||||||
while let Ok(update) = rx.try_recv() {
|
while let Ok(update) = rx.try_recv() {
|
||||||
if first_update {
|
if first_update {
|
||||||
@@ -425,6 +427,14 @@ fn init_sound(
|
|||||||
mem[64..68].copy_from_slice(¤t_time.to_le_bytes());
|
mem[64..68].copy_from_slice(¤t_time.to_le_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn clamp_sample(s: f32) -> f32 {
|
||||||
|
if s.is_nan() {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
s.max(-1.0).min(1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref mut resampler) = resampler {
|
if let Some(ref mut resampler) = resampler {
|
||||||
while !buffer.is_empty() {
|
while !buffer.is_empty() {
|
||||||
let copy_size = resampler.output_buffers[0]
|
let copy_size = resampler.output_buffers[0]
|
||||||
@@ -435,10 +445,12 @@ fn init_sound(
|
|||||||
resampler.input_buffers[0].clear();
|
resampler.input_buffers[0].clear();
|
||||||
resampler.input_buffers[1].clear();
|
resampler.input_buffers[1].clear();
|
||||||
for _ in 0..resampler.resampler.input_frames_next() {
|
for _ in 0..resampler.resampler.input_frames_next() {
|
||||||
resampler.input_buffers[0]
|
resampler.input_buffers[0].push(clamp_sample(
|
||||||
.push(snd.call(&mut store, (sample_index,)).unwrap_or(0.0));
|
snd.call(&mut store, (sample_index,)).unwrap_or(0.0),
|
||||||
resampler.input_buffers[1]
|
));
|
||||||
.push(snd.call(&mut store, (sample_index + 1,)).unwrap_or(0.0));
|
resampler.input_buffers[1].push(clamp_sample(
|
||||||
|
snd.call(&mut store, (sample_index + 1,)).unwrap_or(0.0),
|
||||||
|
));
|
||||||
sample_index = sample_index.wrapping_add(2);
|
sample_index = sample_index.wrapping_add(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,8 +465,7 @@ fn init_sound(
|
|||||||
resampler.output_index = 0;
|
resampler.output_index = 0;
|
||||||
} else {
|
} else {
|
||||||
for i in 0..copy_size {
|
for i in 0..copy_size {
|
||||||
buffer[i * 2] =
|
buffer[i * 2] = resampler.output_buffers[0][resampler.output_index + i];
|
||||||
resampler.output_buffers[0][resampler.output_index + i];
|
|
||||||
buffer[i * 2 + 1] =
|
buffer[i * 2 + 1] =
|
||||||
resampler.output_buffers[1][resampler.output_index + i];
|
resampler.output_buffers[1][resampler.output_index + i];
|
||||||
}
|
}
|
||||||
@@ -464,20 +475,46 @@ fn init_sound(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for v in buffer {
|
for v in buffer {
|
||||||
*v = snd.call(&mut store, (sample_index,)).unwrap_or(0.0);
|
*v = clamp_sample(snd.call(&mut store, (sample_index,)).unwrap_or(0.0));
|
||||||
sample_index = sample_index.wrapping_add(1);
|
sample_index = sample_index.wrapping_add(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outer_buffer = &mut outer_buffer[step_size..];
|
outer_buffer = &mut outer_buffer[step_size..];
|
||||||
current_time =
|
current_time = current_time.wrapping_add((step_size * 500 / sample_rate).max(1) as i32);
|
||||||
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| {
|
move |err| {
|
||||||
dbg!(err);
|
dbg!(err);
|
||||||
},
|
},
|
||||||
)?;
|
None,
|
||||||
|
)?
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Uw8Sound { stream, tx })
|
Ok(Uw8Sound { stream, tx })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,14 +152,14 @@ impl BaseModule {
|
|||||||
add_function(
|
add_function(
|
||||||
&mut functions,
|
&mut functions,
|
||||||
&type_map,
|
&type_map,
|
||||||
"rectangleOutline",
|
"rectangle_outline",
|
||||||
&[F32, F32, F32, F32, I32],
|
&[F32, F32, F32, F32, I32],
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
add_function(
|
add_function(
|
||||||
&mut functions,
|
&mut functions,
|
||||||
&type_map,
|
&type_map,
|
||||||
"circleOutline",
|
"circle_outline",
|
||||||
&[F32, F32, F32, I32],
|
&[F32, F32, F32, I32],
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
@@ -169,21 +169,6 @@ impl BaseModule {
|
|||||||
add_function(&mut functions, &type_map, "playNote", &[I32, I32], None);
|
add_function(&mut functions, &type_map, "playNote", &[I32, I32], None);
|
||||||
add_function(&mut functions, &type_map, "sndGes", &[I32], Some(F32));
|
add_function(&mut functions, &type_map, "sndGes", &[I32], Some(F32));
|
||||||
|
|
||||||
add_function(
|
|
||||||
&mut functions,
|
|
||||||
&type_map,
|
|
||||||
"blitSprite",
|
|
||||||
&[I32, I32, I32, I32, I32],
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
add_function(
|
|
||||||
&mut functions,
|
|
||||||
&type_map,
|
|
||||||
"grabSprite",
|
|
||||||
&[I32, I32, I32, I32, I32],
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
for i in functions.len()..64 {
|
for i in functions.len()..64 {
|
||||||
add_function(
|
add_function(
|
||||||
&mut functions,
|
&mut functions,
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
use std::path::Path;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn filter_exports(in_path: &Path, out_path: &Path) -> Result<()> {
|
pub fn filter_exports(in_path: &Path, out_path: &Path) -> Result<()> {
|
||||||
let mut module = walrus::Module::from_file(in_path)?;
|
let mut module = walrus::Module::from_file(in_path)?;
|
||||||
|
|
||||||
let exports_to_delete: Vec<_> = module.exports.iter().filter_map(|export| match export.name.as_str() {
|
let exports_to_delete: Vec<_> = module
|
||||||
"upd" => None,
|
.exports
|
||||||
_ => Some(export.id())
|
.iter()
|
||||||
}).collect();
|
.filter_map(|export| match export.name.as_str() {
|
||||||
|
"start" | "upd" | "snd" => None,
|
||||||
|
_ => Some(export.id()),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
for id in exports_to_delete {
|
for id in exports_to_delete {
|
||||||
module.exports.delete(id);
|
module.exports.delete(id);
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ fn to_val_type(type_: &wasmparser::ValType) -> Result<ValType> {
|
|||||||
I64 => ValType::I64,
|
I64 => ValType::I64,
|
||||||
F32 => ValType::F32,
|
F32 => ValType::F32,
|
||||||
F64 => ValType::F64,
|
F64 => ValType::F64,
|
||||||
|
V128 => ValType::V128,
|
||||||
_ => bail!("Type {:?} isn't a value type", type_),
|
_ => bail!("Type {:?} isn't a value type", type_),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -967,6 +968,244 @@ fn remap_function(
|
|||||||
De::I64TruncSatF64U => En::I64TruncSatF64U,
|
De::I64TruncSatF64U => En::I64TruncSatF64U,
|
||||||
De::MemoryCopy { src_mem, dst_mem } => En::MemoryCopy { src_mem, dst_mem },
|
De::MemoryCopy { src_mem, dst_mem } => En::MemoryCopy { src_mem, dst_mem },
|
||||||
De::MemoryFill { mem } => En::MemoryFill(mem),
|
De::MemoryFill { mem } => En::MemoryFill(mem),
|
||||||
|
|
||||||
|
De::V128Const { value } => En::V128Const(value.i128()),
|
||||||
|
De::V128Load { memarg } => En::V128Load(mem(memarg)),
|
||||||
|
De::V128Store { memarg } => En::V128Store(mem(memarg)),
|
||||||
|
De::V128Load8x8S { memarg } => En::V128Load8x8S(mem(memarg)),
|
||||||
|
De::V128Load8x8U { memarg } => En::V128Load8x8U(mem(memarg)),
|
||||||
|
De::V128Load16x4S { memarg } => En::V128Load16x4S(mem(memarg)),
|
||||||
|
De::V128Load16x4U { memarg } => En::V128Load16x4U(mem(memarg)),
|
||||||
|
De::V128Load32x2S { memarg } => En::V128Load32x2S(mem(memarg)),
|
||||||
|
De::V128Load32x2U { memarg } => En::V128Load32x2U(mem(memarg)),
|
||||||
|
De::V128Load8Splat { memarg } => En::V128Load8Splat(mem(memarg)),
|
||||||
|
De::V128Load16Splat { memarg } => En::V128Load16Splat(mem(memarg)),
|
||||||
|
De::V128Load32Splat { memarg } => En::V128Load32Splat(mem(memarg)),
|
||||||
|
De::V128Load64Splat { memarg } => En::V128Load64Splat(mem(memarg)),
|
||||||
|
De::V128Load32Zero { memarg } => En::V128Load32Zero(mem(memarg)),
|
||||||
|
De::V128Load64Zero { memarg } => En::V128Load64Zero(mem(memarg)),
|
||||||
|
|
||||||
|
De::V128Load8Lane { memarg, lane } => En::V128Load8Lane { memarg: mem(memarg), lane },
|
||||||
|
De::V128Load16Lane { memarg, lane } => En::V128Load16Lane { memarg: mem(memarg), lane },
|
||||||
|
De::V128Load32Lane { memarg, lane } => En::V128Load32Lane { memarg: mem(memarg), lane },
|
||||||
|
De::V128Load64Lane { memarg, lane } => En::V128Load64Lane { memarg: mem(memarg), lane },
|
||||||
|
De::V128Store8Lane { memarg, lane } => En::V128Store8Lane { memarg: mem(memarg), lane },
|
||||||
|
De::V128Store16Lane { memarg, lane } => En::V128Store16Lane { memarg: mem(memarg), lane },
|
||||||
|
De::V128Store32Lane { memarg, lane } => En::V128Store32Lane { memarg: mem(memarg), lane },
|
||||||
|
De::V128Store64Lane { memarg, lane } => En::V128Store64Lane { memarg: mem(memarg), lane },
|
||||||
|
|
||||||
|
De::I8x16ExtractLaneS { lane } => En::I8x16ExtractLaneS(lane),
|
||||||
|
De::I8x16ExtractLaneU { lane } => En::I8x16ExtractLaneU(lane),
|
||||||
|
De::I8x16ReplaceLane { lane } => En::I8x16ReplaceLane(lane),
|
||||||
|
De::I16x8ExtractLaneS { lane } => En::I16x8ExtractLaneS(lane),
|
||||||
|
De::I16x8ExtractLaneU { lane } => En::I16x8ExtractLaneU(lane),
|
||||||
|
De::I16x8ReplaceLane { lane } => En::I16x8ReplaceLane(lane),
|
||||||
|
De::I32x4ExtractLane { lane } => En::I32x4ExtractLane(lane),
|
||||||
|
De::I32x4ReplaceLane { lane } => En::I32x4ReplaceLane(lane),
|
||||||
|
De::I64x2ExtractLane { lane } => En::I64x2ExtractLane(lane),
|
||||||
|
De::I64x2ReplaceLane { lane } => En::I64x2ReplaceLane(lane),
|
||||||
|
De::F32x4ExtractLane { lane } => En::F32x4ExtractLane(lane),
|
||||||
|
De::F32x4ReplaceLane { lane } => En::F32x4ReplaceLane(lane),
|
||||||
|
De::F64x2ExtractLane { lane } => En::F64x2ExtractLane(lane),
|
||||||
|
De::F64x2ReplaceLane { lane } => En::F64x2ReplaceLane(lane),
|
||||||
|
|
||||||
|
De::I8x16Splat => En::I8x16Splat,
|
||||||
|
De::I16x8Splat => En::I16x8Splat,
|
||||||
|
De::I32x4Splat => En::I32x4Splat,
|
||||||
|
De::I64x2Splat => En::I64x2Splat,
|
||||||
|
De::F32x4Splat => En::F32x4Splat,
|
||||||
|
De::F64x2Splat => En::F64x2Splat,
|
||||||
|
De::I8x16Swizzle => En::I8x16Swizzle,
|
||||||
|
De::I8x16Add => En::I8x16Add,
|
||||||
|
De::I16x8Add => En::I16x8Add,
|
||||||
|
De::I32x4Add => En::I32x4Add,
|
||||||
|
De::I64x2Add => En::I64x2Add,
|
||||||
|
De::F32x4Add => En::F32x4Add,
|
||||||
|
De::F64x2Add => En::F64x2Add,
|
||||||
|
De::I8x16Sub => En::I8x16Sub,
|
||||||
|
De::I16x8Sub => En::I16x8Sub,
|
||||||
|
De::I32x4Sub => En::I32x4Sub,
|
||||||
|
De::I64x2Sub => En::I64x2Sub,
|
||||||
|
De::F32x4Sub => En::F32x4Sub,
|
||||||
|
De::F64x2Sub => En::F64x2Sub,
|
||||||
|
De::I16x8Mul => En::I16x8Mul,
|
||||||
|
De::I32x4Mul => En::I32x4Mul,
|
||||||
|
De::I64x2Mul => En::I64x2Mul,
|
||||||
|
De::F32x4Mul => En::F32x4Mul,
|
||||||
|
De::F64x2Mul => En::F64x2Mul,
|
||||||
|
De::I32x4DotI16x8S => En::I32x4DotI16x8S,
|
||||||
|
De::I8x16Neg => En::I8x16Neg,
|
||||||
|
De::I16x8Neg => En::I16x8Neg,
|
||||||
|
De::I32x4Neg => En::I32x4Neg,
|
||||||
|
De::I64x2Neg => En::I64x2Neg,
|
||||||
|
De::F32x4Neg => En::F32x4Neg,
|
||||||
|
De::F64x2Neg => En::F64x2Neg,
|
||||||
|
De::I16x8ExtMulLowI8x16S => En::I16x8ExtMulLowI8x16S,
|
||||||
|
De::I16x8ExtMulHighI8x16S => En::I16x8ExtMulHighI8x16S,
|
||||||
|
De::I16x8ExtMulLowI8x16U => En::I16x8ExtMulLowI8x16U,
|
||||||
|
De::I16x8ExtMulHighI8x16U => En::I16x8ExtMulHighI8x16U,
|
||||||
|
De::I32x4ExtMulLowI16x8S => En::I32x4ExtMulLowI16x8S,
|
||||||
|
De::I32x4ExtMulHighI16x8S => En::I32x4ExtMulHighI16x8S,
|
||||||
|
De::I32x4ExtMulLowI16x8U => En::I32x4ExtMulLowI16x8U,
|
||||||
|
De::I32x4ExtMulHighI16x8U => En::I32x4ExtMulHighI16x8U,
|
||||||
|
De::I64x2ExtMulLowI32x4S => En::I64x2ExtMulLowI32x4S,
|
||||||
|
De::I64x2ExtMulHighI32x4S => En::I64x2ExtMulHighI32x4S,
|
||||||
|
De::I64x2ExtMulLowI32x4U => En::I64x2ExtMulLowI32x4U,
|
||||||
|
De::I64x2ExtMulHighI32x4U => En::I64x2ExtMulHighI32x4U,
|
||||||
|
De::I16x8ExtAddPairwiseI8x16S => En::I16x8ExtAddPairwiseI8x16S,
|
||||||
|
De::I16x8ExtAddPairwiseI8x16U => En::I16x8ExtAddPairwiseI8x16U,
|
||||||
|
De::I32x4ExtAddPairwiseI16x8S => En::I32x4ExtAddPairwiseI16x8S,
|
||||||
|
De::I32x4ExtAddPairwiseI16x8U => En::I32x4ExtAddPairwiseI16x8U,
|
||||||
|
De::I8x16AddSatS => En::I8x16AddSatS,
|
||||||
|
De::I8x16AddSatU => En::I8x16AddSatU,
|
||||||
|
De::I16x8AddSatS => En::I16x8AddSatS,
|
||||||
|
De::I16x8AddSatU => En::I16x8AddSatU,
|
||||||
|
De::I8x16SubSatS => En::I8x16SubSatS,
|
||||||
|
De::I8x16SubSatU => En::I8x16SubSatU,
|
||||||
|
De::I16x8SubSatS => En::I16x8SubSatS,
|
||||||
|
De::I16x8SubSatU => En::I16x8SubSatU,
|
||||||
|
De::I16x8Q15MulrSatS => En::I16x8Q15MulrSatS,
|
||||||
|
De::I8x16MinS => En::I8x16MinS,
|
||||||
|
De::I8x16MinU => En::I8x16MinU,
|
||||||
|
De::I16x8MinS => En::I16x8MinS,
|
||||||
|
De::I16x8MinU => En::I16x8MinU,
|
||||||
|
De::I32x4MinS => En::I32x4MinS,
|
||||||
|
De::I32x4MinU => En::I32x4MinU,
|
||||||
|
De::F32x4Min => En::F32x4Min,
|
||||||
|
De::F64x2Min => En::F64x2Min,
|
||||||
|
De::F32x4PMin => En::F32x4PMin,
|
||||||
|
De::F64x2PMin => En::F64x2PMin,
|
||||||
|
De::I8x16MaxS => En::I8x16MaxS,
|
||||||
|
De::I8x16MaxU => En::I8x16MaxU,
|
||||||
|
De::I16x8MaxS => En::I16x8MaxS,
|
||||||
|
De::I16x8MaxU => En::I16x8MaxU,
|
||||||
|
De::I32x4MaxS => En::I32x4MaxS,
|
||||||
|
De::I32x4MaxU => En::I32x4MaxU,
|
||||||
|
De::F32x4Max => En::F32x4Max,
|
||||||
|
De::F64x2Max => En::F64x2Max,
|
||||||
|
De::F32x4PMax => En::F32x4PMax,
|
||||||
|
De::F64x2PMax => En::F64x2PMax,
|
||||||
|
De::I8x16AvgrU => En::I8x16AvgrU,
|
||||||
|
De::I16x8AvgrU => En::I16x8AvgrU,
|
||||||
|
De::I8x16Abs => En::I8x16Abs,
|
||||||
|
De::I16x8Abs => En::I16x8Abs,
|
||||||
|
De::I32x4Abs => En::I32x4Abs,
|
||||||
|
De::I64x2Abs => En::I64x2Abs,
|
||||||
|
De::F32x4Abs => En::F32x4Abs,
|
||||||
|
De::F64x2Abs => En::F64x2Abs,
|
||||||
|
De::I8x16Shl => En::I8x16Shl,
|
||||||
|
De::I16x8Shl => En::I16x8Shl,
|
||||||
|
De::I32x4Shl => En::I32x4Shl,
|
||||||
|
De::I64x2Shl => En::I64x2Shl,
|
||||||
|
De::I8x16ShrS => En::I8x16ShrS,
|
||||||
|
De::I8x16ShrU => En::I8x16ShrU,
|
||||||
|
De::I16x8ShrS => En::I16x8ShrS,
|
||||||
|
De::I16x8ShrU => En::I16x8ShrU,
|
||||||
|
De::I32x4ShrS => En::I32x4ShrS,
|
||||||
|
De::I32x4ShrU => En::I32x4ShrU,
|
||||||
|
De::I64x2ShrS => En::I64x2ShrS,
|
||||||
|
De::I64x2ShrU => En::I64x2ShrU,
|
||||||
|
De::V128And => En::V128And,
|
||||||
|
De::V128Or => En::V128Or,
|
||||||
|
De::V128Xor => En::V128Xor,
|
||||||
|
De::V128Not => En::V128Not,
|
||||||
|
De::V128AndNot => En::V128AndNot,
|
||||||
|
De::V128Bitselect => En::V128Bitselect,
|
||||||
|
De::I8x16Popcnt => En::I8x16Popcnt,
|
||||||
|
De::V128AnyTrue => En::V128AnyTrue,
|
||||||
|
De::I8x16AllTrue => En::I8x16AllTrue,
|
||||||
|
De::I16x8AllTrue => En::I16x8AllTrue,
|
||||||
|
De::I32x4AllTrue => En::I32x4AllTrue,
|
||||||
|
De::I64x2AllTrue => En::I64x2AllTrue,
|
||||||
|
De::I8x16Bitmask => En::I8x16Bitmask,
|
||||||
|
De::I16x8Bitmask => En::I16x8Bitmask,
|
||||||
|
De::I32x4Bitmask => En::I32x4Bitmask,
|
||||||
|
De::I64x2Bitmask => En::I64x2Bitmask,
|
||||||
|
De::I8x16Eq => En::I8x16Eq,
|
||||||
|
De::I16x8Eq => En::I16x8Eq,
|
||||||
|
De::I32x4Eq => En::I32x4Eq,
|
||||||
|
De::I64x2Eq => En::I64x2Eq,
|
||||||
|
De::F32x4Eq => En::F32x4Eq,
|
||||||
|
De::F64x2Eq => En::F64x2Eq,
|
||||||
|
De::I8x16Ne => En::I8x16Ne,
|
||||||
|
De::I16x8Ne => En::I16x8Ne,
|
||||||
|
De::I32x4Ne => En::I32x4Ne,
|
||||||
|
De::I64x2Ne => En::I64x2Ne,
|
||||||
|
De::F32x4Ne => En::F32x4Ne,
|
||||||
|
De::F64x2Ne => En::F64x2Ne,
|
||||||
|
De::I8x16LtS => En::I8x16LtS,
|
||||||
|
De::I8x16LtU => En::I8x16LtU,
|
||||||
|
De::I16x8LtS => En::I16x8LtS,
|
||||||
|
De::I16x8LtU => En::I16x8LtU,
|
||||||
|
De::I32x4LtS => En::I32x4LtS,
|
||||||
|
De::I32x4LtU => En::I32x4LtU,
|
||||||
|
De::F32x4Lt => En::F32x4Lt,
|
||||||
|
De::F64x2Lt => En::F64x2Lt,
|
||||||
|
De::I8x16LeS => En::I8x16LeS,
|
||||||
|
De::I8x16LeU => En::I8x16LeU,
|
||||||
|
De::I16x8LeS => En::I16x8LeS,
|
||||||
|
De::I16x8LeU => En::I16x8LeU,
|
||||||
|
De::I32x4LeS => En::I32x4LeS,
|
||||||
|
De::I32x4LeU => En::I32x4LeU,
|
||||||
|
De::F32x4Le => En::F32x4Le,
|
||||||
|
De::F64x2Le => En::F64x2Le,
|
||||||
|
De::I8x16GtS => En::I8x16GtS,
|
||||||
|
De::I8x16GtU => En::I8x16GtU,
|
||||||
|
De::I16x8GtS => En::I16x8GtS,
|
||||||
|
De::I16x8GtU => En::I16x8GtU,
|
||||||
|
De::I32x4GtS => En::I32x4GtS,
|
||||||
|
De::I32x4GtU => En::I32x4GtU,
|
||||||
|
De::F32x4Gt => En::F32x4Gt,
|
||||||
|
De::F64x2Gt => En::F64x2Gt,
|
||||||
|
De::I8x16GeS => En::I8x16GeS,
|
||||||
|
De::I8x16GeU => En::I8x16GeU,
|
||||||
|
De::I16x8GeS => En::I16x8GeS,
|
||||||
|
De::I16x8GeU => En::I16x8GeU,
|
||||||
|
De::I32x4GeS => En::I32x4GeS,
|
||||||
|
De::I32x4GeU => En::I32x4GeU,
|
||||||
|
De::F32x4Ge => En::F32x4Ge,
|
||||||
|
De::F64x2Ge => En::F64x2Ge,
|
||||||
|
De::F32x4Div => En::F32x4Div,
|
||||||
|
De::F64x2Div => En::F64x2Div,
|
||||||
|
De::F32x4Sqrt => En::F32x4Sqrt,
|
||||||
|
De::F64x2Sqrt => En::F64x2Sqrt,
|
||||||
|
De::F32x4Ceil => En::F32x4Ceil,
|
||||||
|
De::F64x2Ceil => En::F64x2Ceil,
|
||||||
|
De::F32x4Floor => En::F32x4Floor,
|
||||||
|
De::F64x2Floor => En::F64x2Floor,
|
||||||
|
De::F32x4Trunc => En::F32x4Trunc,
|
||||||
|
De::F64x2Trunc => En::F64x2Trunc,
|
||||||
|
De::F32x4Nearest => En::F32x4Nearest,
|
||||||
|
De::F64x2Nearest => En::F64x2Nearest,
|
||||||
|
De::F32x4ConvertI32x4S => En::F32x4ConvertI32x4S,
|
||||||
|
De::F32x4ConvertI32x4U => En::F32x4ConvertI32x4U,
|
||||||
|
De::F64x2ConvertLowI32x4S => En::F64x2ConvertLowI32x4S,
|
||||||
|
De::F64x2ConvertLowI32x4U => En::F64x2ConvertLowI32x4U,
|
||||||
|
De::I32x4TruncSatF32x4S => En::I32x4TruncSatF32x4S,
|
||||||
|
De::I32x4TruncSatF32x4U => En::I32x4TruncSatF32x4U,
|
||||||
|
De::I32x4TruncSatF64x2SZero => En::I32x4TruncSatF64x2SZero,
|
||||||
|
De::I32x4TruncSatF64x2UZero => En::I32x4TruncSatF64x2UZero,
|
||||||
|
De::F32x4DemoteF64x2Zero => En::F32x4DemoteF64x2Zero,
|
||||||
|
De::F64x2PromoteLowF32x4 => En::F64x2PromoteLowF32x4,
|
||||||
|
De::I8x16NarrowI16x8S => En::I8x16NarrowI16x8S,
|
||||||
|
De::I8x16NarrowI16x8U => En::I8x16NarrowI16x8U,
|
||||||
|
De::I16x8NarrowI32x4S => En::I16x8NarrowI32x4S,
|
||||||
|
De::I16x8NarrowI32x4U => En::I16x8NarrowI32x4U,
|
||||||
|
De::I16x8ExtendLowI8x16S => En::I16x8ExtendLowI8x16S,
|
||||||
|
De::I16x8ExtendHighI8x16S => En::I16x8ExtendHighI8x16S,
|
||||||
|
De::I16x8ExtendLowI8x16U => En::I16x8ExtendLowI8x16U,
|
||||||
|
De::I16x8ExtendHighI8x16U => En::I16x8ExtendHighI8x16U,
|
||||||
|
De::I32x4ExtendLowI16x8S => En::I32x4ExtendLowI16x8S,
|
||||||
|
De::I32x4ExtendHighI16x8S => En::I32x4ExtendHighI16x8S,
|
||||||
|
De::I32x4ExtendLowI16x8U => En::I32x4ExtendLowI16x8U,
|
||||||
|
De::I32x4ExtendHighI16x8U => En::I32x4ExtendHighI16x8U,
|
||||||
|
De::I64x2ExtendLowI32x4S => En::I64x2ExtendLowI32x4S,
|
||||||
|
De::I64x2ExtendHighI32x4S => En::I64x2ExtendHighI32x4S,
|
||||||
|
De::I64x2ExtendLowI32x4U => En::I64x2ExtendLowI32x4U,
|
||||||
|
De::I64x2ExtendHighI32x4U => En::I64x2ExtendHighI32x4U,
|
||||||
|
|
||||||
|
De::I8x16Shuffle { lanes } => En::I8x16Shuffle(lanes),
|
||||||
|
|
||||||
other => bail!("Unsupported instruction {:?}", other),
|
other => bail!("Unsupported instruction {:?}", other),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
810
uw8-window/Cargo.lock
generated
810
uw8-window/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -6,13 +6,13 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
winit = "0.27.5"
|
winit = "0.28.6"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pico-args = "0.5"
|
pico-args = "0.5"
|
||||||
wgpu = "0.15"
|
wgpu = "0.17"
|
||||||
pollster = "0.2.5"
|
pollster = "0.3.0"
|
||||||
bytemuck = { version = "1.13", features = [ "derive" ] }
|
bytemuck = { version = "1.13", features = [ "derive" ] }
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
minifb = { version = "0.23.0", default-features = false, features = ["x11"] }
|
minifb = { version = "0.25.0", default-features = false, features = ["x11"] }
|
||||||
winapi = { version = "0.3.9", features = [ "timeapi" ] }
|
winapi = { version = "0.3.9", features = [ "timeapi" ] }
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ fn row_factor(offset: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn col_factor(offset: f32) -> f32 {
|
fn col_factor(offset: f32) -> f32 {
|
||||||
let offset = max(0.0, abs(offset) - 0.4);
|
let o = max(0.0, abs(offset) - 0.4);
|
||||||
return 1.0 / (1.0 + offset * offset * 16.0);
|
return 1.0 / (1.0 + o * o * 16.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sample_screen(tex_coords: vec2<f32>) -> vec4<f32> {
|
fn sample_screen(tex_coords: vec2<f32>) -> vec4<f32> {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{Input, WindowConfig, WindowImpl};
|
use crate::{Input, WindowConfig, WindowImpl};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use std::{num::NonZeroU32, time::Instant};
|
use std::time::Instant;
|
||||||
|
|
||||||
use winit::{
|
use winit::{
|
||||||
dpi::PhysicalSize,
|
dpi::PhysicalSize,
|
||||||
@@ -41,7 +41,10 @@ impl Window {
|
|||||||
async fn create(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()
|
let window = WindowBuilder::new()
|
||||||
.with_inner_size(PhysicalSize::new(640u32, 480))
|
.with_inner_size(PhysicalSize::new(
|
||||||
|
(320. * window_config.scale).round() as u32,
|
||||||
|
(240. * window_config.scale).round() as u32,
|
||||||
|
))
|
||||||
.with_min_inner_size(PhysicalSize::new(320u32, 240))
|
.with_min_inner_size(PhysicalSize::new(320u32, 240))
|
||||||
.with_title("MicroW8")
|
.with_title("MicroW8")
|
||||||
.with_fullscreen(if window_config.fullscreen {
|
.with_fullscreen(if window_config.fullscreen {
|
||||||
@@ -72,7 +75,13 @@ impl Window {
|
|||||||
|
|
||||||
let surface_config = wgpu::SurfaceConfiguration {
|
let surface_config = wgpu::SurfaceConfiguration {
|
||||||
present_mode: wgpu::PresentMode::AutoNoVsync,
|
present_mode: wgpu::PresentMode::AutoNoVsync,
|
||||||
..surface.get_default_config(&adapter, window.inner_size().width, window.inner_size().height).expect("Surface incompatible with adapter")
|
..surface
|
||||||
|
.get_default_config(
|
||||||
|
&adapter,
|
||||||
|
window.inner_size().width,
|
||||||
|
window.inner_size().height,
|
||||||
|
)
|
||||||
|
.expect("Surface incompatible with adapter")
|
||||||
};
|
};
|
||||||
|
|
||||||
let filter: Box<dyn Filter> = create_filter(
|
let filter: Box<dyn Filter> = create_filter(
|
||||||
@@ -354,7 +363,7 @@ impl PaletteScreenMode {
|
|||||||
format: wgpu::TextureFormat::R8Uint,
|
format: wgpu::TextureFormat::R8Uint,
|
||||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||||
label: None,
|
label: None,
|
||||||
view_formats: &[]
|
view_formats: &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
let palette_texture = device.create_texture(&wgpu::TextureDescriptor {
|
let palette_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||||
@@ -369,7 +378,7 @@ impl PaletteScreenMode {
|
|||||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||||
label: None,
|
label: None,
|
||||||
view_formats: &[]
|
view_formats: &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
let screen_texture = device.create_texture(&wgpu::TextureDescriptor {
|
let screen_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||||
@@ -384,7 +393,7 @@ impl PaletteScreenMode {
|
|||||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
label: None,
|
label: None,
|
||||||
view_formats: &[]
|
view_formats: &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
let framebuffer_texture_view =
|
let framebuffer_texture_view =
|
||||||
@@ -491,7 +500,7 @@ impl PaletteScreenMode {
|
|||||||
&bytemuck::cast_slice(pixels),
|
&bytemuck::cast_slice(pixels),
|
||||||
wgpu::ImageDataLayout {
|
wgpu::ImageDataLayout {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
bytes_per_row: NonZeroU32::new(320),
|
bytes_per_row: Some(320),
|
||||||
rows_per_image: None,
|
rows_per_image: None,
|
||||||
},
|
},
|
||||||
wgpu::Extent3d {
|
wgpu::Extent3d {
|
||||||
@@ -513,7 +522,7 @@ impl PaletteScreenMode {
|
|||||||
&bytemuck::cast_slice(palette),
|
&bytemuck::cast_slice(palette),
|
||||||
wgpu::ImageDataLayout {
|
wgpu::ImageDataLayout {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
bytes_per_row: NonZeroU32::new(256 * 4),
|
bytes_per_row: Some(256 * 4),
|
||||||
rows_per_image: None,
|
rows_per_image: None,
|
||||||
},
|
},
|
||||||
wgpu::Extent3d {
|
wgpu::Extent3d {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ struct FpsCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(config: WindowConfig) -> Result<Window> {
|
pub fn new(mut config: WindowConfig) -> Result<Window> {
|
||||||
let fps_counter = if config.fps_counter {
|
let fps_counter = if config.fps_counter {
|
||||||
Some(FpsCounter {
|
Some(FpsCounter {
|
||||||
start: Instant::now(),
|
start: Instant::now(),
|
||||||
@@ -24,6 +24,7 @@ impl Window {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
config.scale = config.scale.max(1.).min(20.);
|
||||||
if config.enable_gpu {
|
if config.enable_gpu {
|
||||||
match gpu::Window::new(config) {
|
match gpu::Window::new(config) {
|
||||||
Ok(window) => {
|
Ok(window) => {
|
||||||
@@ -71,6 +72,7 @@ pub struct WindowConfig {
|
|||||||
filter: u32,
|
filter: u32,
|
||||||
fullscreen: bool,
|
fullscreen: bool,
|
||||||
fps_counter: bool,
|
fps_counter: bool,
|
||||||
|
scale: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WindowConfig {
|
impl Default for WindowConfig {
|
||||||
@@ -80,6 +82,7 @@ impl Default for WindowConfig {
|
|||||||
filter: 5,
|
filter: 5,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
fps_counter: false,
|
fps_counter: false,
|
||||||
|
scale: 2.,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,6 +105,10 @@ impl WindowConfig {
|
|||||||
}
|
}
|
||||||
self.fullscreen = args.contains("--fullscreen");
|
self.fullscreen = args.contains("--fullscreen");
|
||||||
self.fps_counter = args.contains("--fps");
|
self.fps_counter = args.contains("--fps");
|
||||||
|
self.scale = args
|
||||||
|
.opt_value_from_str("--scale")
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_or(self.scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ export default function MicroW8(screen, config = {}) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let restart = false;
|
let restart = false;
|
||||||
let nextFrame = 0;
|
let thisFrame;
|
||||||
if (!isPaused) {
|
if (!isPaused) {
|
||||||
let gamepads = navigator.getGamepads();
|
let gamepads = navigator.getGamepads();
|
||||||
let gamepad = 0;
|
let gamepad = 0;
|
||||||
@@ -321,12 +321,13 @@ export default function MicroW8(screen, config = {}) {
|
|||||||
}
|
}
|
||||||
canvasCtx.putImageData(imageData, 0, 0);
|
canvasCtx.putImageData(imageData, 0, 0);
|
||||||
|
|
||||||
let thisFrame = Math.floor(time * 6 / 100);
|
let timeOffset = ((time * 6) % 100 - 50) / 6;
|
||||||
let timeOffset = time - thisFrame * 100 / 6;
|
thisFrame = startTime + time - timeOffset / 8;
|
||||||
nextFrame = Math.ceil(startTime + (thisFrame + 1) * 100 / 6 + Math.min(4, timeOffset));
|
} else {
|
||||||
|
thisFrame = Date.now();
|
||||||
}
|
}
|
||||||
let now = Date.now();
|
let now = Date.now();
|
||||||
nextFrame = Math.max(nextFrame, now);
|
let nextFrame = Math.max(thisFrame + timePerFrame, now);
|
||||||
|
|
||||||
if (restart) {
|
if (restart) {
|
||||||
runModule(currentData);
|
runModule(currentData);
|
||||||
|
|||||||
Reference in New Issue
Block a user