4 Commits

8 changed files with 97 additions and 58 deletions

1
Cargo.lock generated
View File

@@ -1543,6 +1543,7 @@ dependencies = [
"pico-args",
"uw8-tool",
"wasmtime",
"wat",
]
[[package]]

View File

@@ -12,4 +12,5 @@ minifb = "0.19"
notify = "4"
pico-args = "0.4"
curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "196719b" }
wat = "1"
uw8-tool = { path = "uw8-tool" }

View File

@@ -0,0 +1,26 @@
(module
(import "env" "memory" (memory 4))
(func (export "upd")
(local $i i32) ;; local variables are zero initialized
(loop $pixels
local.get $i ;; pixel index to write to
(i32.rem_u (local.get $i) (i32.const 320)) ;; x
(i32.div_u (i32.load (i32.const 64)) (i32.const 10)) ;; time / 10
i32.add
(i32.div_u (local.get $i) (i32.const 320)) ;; y
i32.xor ;; (x + time / 10) ^ y
(i32.shr_u (i32.const 3)) ;; .. >> 3
(i32.and (i32.const 127)) ;; .. & 127
i32.store8 offset=120 ;; store at pixel index + 120
(i32.add (local.get $i) (i32.const 1)) ;; i + 1
local.tee $i ;; write it back but keep it on the stack
(br_if $pixels (i32.lt_s (i32.const 76800))) ;; branch to start of loop if i < 320*240
)
)
)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -0,0 +1,3 @@
#<23><>I<EFBFBD>ޮaV<>p<EFBFBD>v[VLc<4C><63><1C><>^<>ȯ<>C<EFBFBD><43>M[<5B><>5<EFBFBD><35>$<24>S<EFBFBD>.}<15><>a'<27>c<EFBFBD><63><EFBFBD>b<EFBFBD><62>V-=X<><58><EFBFBD>Lguu8<75><06><><EFBFBD>
9<EFBFBD>\<5C><>ݯ<EFBFBD>h<EFBFBD><<3C>4?zk<7A><6B>.<2E><02><>8<10><>&/<2F>@<40>6ֿ<36><D6BF>;8<>{.<2E>8_<38><5F>^<5E><><EFBFBD>t/kp|<7C><>n<0F><>,'<27>>1<>0^4=@ <0C><>{NI
<EFBFBD>b<EFBFBD>_=<3D>U`Y<><59><EFBFBD>=<3D>\<5C><><4F><D9A6><EFBFBD>bxh&<26><>g<>tO<74><4F>; <09>#<23>@H<><48><EFBFBD><EFBFBD><EFBFBD><EFBFBD>z<EFBFBD>Ζ<EFBFBD><CE96><EFBFBD>+<2B>Xw<58><11><>

File diff suppressed because one or more lines are too long

View File

@@ -97,7 +97,11 @@ fn load_cart(filename: &Path, uw8: &mut MicroW8, config: &Config) -> Result<()>
if cart[0] >= 10 {
let src = String::from_utf8(cart)?;
cart = curlywas::compile_str(&src, filename, curlywas::Options::default())?;
cart = if src.chars().find(|c| !c.is_whitespace()) == Some('(') {
wat::parse_str(src)?
} else {
curlywas::compile_str(&src, filename, curlywas::Options::default())?
};
}
if config.pack {

View File

@@ -24,40 +24,39 @@ let pad = 0;
let keyHandler = (e) => {
let isKeyDown = e.type == 'keydown';
let mask;
switch(e.code) {
case 'ArrowUp':
mask = 1;
break;
case 'ArrowDown':
mask = 2;
break;
case 'ArrowLeft':
mask = 4;
break;
case 'ArrowRight':
mask = 8;
break;
case 'KeyZ':
mask = 16;
break;
case 'KeyX':
mask = 32;
break;
case 'KeyA':
mask = 64;
break;
case 'KeyS':
mask = 128;
break;
case 'KeyR':
if(isKeyDown)
{
runModule(currentData);
}
break;
switch (e.code) {
case 'ArrowUp':
mask = 1;
break;
case 'ArrowDown':
mask = 2;
break;
case 'ArrowLeft':
mask = 4;
break;
case 'ArrowRight':
mask = 8;
break;
case 'KeyZ':
mask = 16;
break;
case 'KeyX':
mask = 32;
break;
case 'KeyA':
mask = 64;
break;
case 'KeyS':
mask = 128;
break;
case 'KeyR':
if (isKeyDown) {
runModule(currentData);
}
break;
}
if(isKeyDown) {
if (isKeyDown) {
pad |= mask;
} else {
pad &= ~mask;
@@ -66,7 +65,7 @@ let keyHandler = (e) => {
window.onkeydown = keyHandler;
window.onkeyup = keyHandler;
async function runModule(data) {
async function runModule(data, keepUrl) {
if (cancelFunction) {
cancelFunction();
cancelFunction = null;
@@ -82,15 +81,16 @@ async function runModule(data) {
currentData = data;
let newURL = window.location.pathname;
if (cartridgeSize <= 1024) {
if (cartridgeSize <= 1024 && !keepUrl) {
let dataString = '';
for (let byte of U8(data)) {
dataString += String.fromCharCode(byte);
}
newURL += '#' + btoa(dataString);
}
if (newURL != window.location.pathname + window.location.hash) {
history.pushState(null, null, newURL);
if (newURL != window.location.pathname + window.location.hash) {
history.pushState(null, null, newURL);
}
}
screen.width = screen.width;
@@ -139,7 +139,7 @@ async function runModule(data) {
let platform_instance = await loadModuleURL(platformUrl);
for(let name in platform_instance.exports) {
for (let name in platform_instance.exports) {
importObject.env[name] = platform_instance.exports[name]
}
@@ -163,29 +163,29 @@ async function runModule(data) {
try {
let now = Date.now();
let restart = false;
if(now >= nextFrame) {
if (now >= nextFrame) {
let gamepads = navigator.getGamepads();
let gamepad = 0;
for(let i = 0; i < 4; ++i) {
for (let i = 0; i < 4; ++i) {
let pad = gamepads[i];
if(!pad) {
if (!pad) {
continue;
}
for(let j = 0; j < 8; ++j) {
let buttonIdx = (j+12) % 16;
if(pad.buttons.length > buttonIdx && pad.buttons[buttonIdx].pressed) {
for (let j = 0; j < 8; ++j) {
let buttonIdx = (j + 12) % 16;
if (pad.buttons.length > buttonIdx && pad.buttons[buttonIdx].pressed) {
gamepad |= 1 << (i * 8 + j);
}
}
if(pad.axes.length > 1) {
for(let j = 0; j < 4; ++j) {
let v = pad.axes[1-(j>>1)];
if(((j & 1) ? v : -v) > 0.5) {
if (pad.axes.length > 1) {
for (let j = 0; j < 4; ++j) {
let v = pad.axes[1 - (j >> 1)];
if (((j & 1) ? v : -v) > 0.5) {
gamepad |= 1 << (i * 8 + j);
}
}
}
if(pad.buttons.length > 9 && pad.buttons[9].pressed) {
if (pad.buttons.length > 9 && pad.buttons[9].pressed) {
restart = true;
}
}
@@ -204,7 +204,7 @@ async function runModule(data) {
nextFrame = Math.max(nextFrame + timePerFrame, now);
}
if(restart) {
if (restart) {
runModule(currentData);
} else {
window.requestAnimationFrame(mainloop);
@@ -220,14 +220,18 @@ async function runModule(data) {
}
}
async function runModuleFromURL(url) {
runModule(await (await fetch(url)).arrayBuffer());
async function runModuleFromURL(url, keepUrl) {
runModule(await (await fetch(url)).arrayBuffer(), keepUrl);
}
function runModuleFromHash() {
let base64Data = window.location.hash.slice(1);
if (base64Data.length > 0) {
runModuleFromURL('data:;base64,' + base64Data);
let hash = window.location.hash.slice(1);
if (hash.length > 0) {
if (hash.startsWith("url=")) {
runModuleFromURL(hash.slice(4), true);
} else {
runModuleFromURL('data:;base64,' + hash);
}
} else {
runModule(new ArrayBuffer(0));
}