mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
added unlicense, more style, started math imports
This commit is contained in:
24
UNLICENSE
Normal file
24
UNLICENSE
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org/>
|
||||||
1
platform/.gitignore
vendored
Normal file
1
platform/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.wasm
|
||||||
3
platform/base.cwa
Normal file
3
platform/base.cwa
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import "env.memory" memory(2);
|
||||||
|
|
||||||
|
export fn tic(time: i32) {}
|
||||||
64
platform/loader.cwa
Normal file
64
platform/loader.cwa
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import "env.memory" memory(8);
|
||||||
|
|
||||||
|
export fn load_uw8(module_start: i32, module_end: i32, base_start: i32, base_end: i32) -> i32 {
|
||||||
|
if ?module_start == 0 {
|
||||||
|
let defer length = module_end - module_start;
|
||||||
|
copy(base_end, module_start, length);
|
||||||
|
return base_end + length;
|
||||||
|
}
|
||||||
|
|
||||||
|
copy(base_end, base_start, 8);
|
||||||
|
base_start = base_start + 8;
|
||||||
|
let dest = base_end + 8;
|
||||||
|
let src = module_start + 1;
|
||||||
|
|
||||||
|
loop sections {
|
||||||
|
if src < module_end & (base_start >= base_end | ?src <= ?base_start) {
|
||||||
|
let defer length2 = copy_section(dest, src);
|
||||||
|
dest = dest + length2;
|
||||||
|
if base_start < base_end & ?src == ?base_start {
|
||||||
|
base_start = base_start + section_size(base_start);
|
||||||
|
}
|
||||||
|
src = src + length2;
|
||||||
|
branch sections;
|
||||||
|
}
|
||||||
|
|
||||||
|
if base_start < base_end {
|
||||||
|
let defer length3 = copy_section(dest, base_start);
|
||||||
|
dest = dest + length3;
|
||||||
|
base_start = base_start + length3;
|
||||||
|
branch sections;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dest
|
||||||
|
}
|
||||||
|
|
||||||
|
fn section_size(ptr: i32) -> i32 {
|
||||||
|
let p = ptr + 1;
|
||||||
|
let l = 0;
|
||||||
|
let shift = 0;
|
||||||
|
loop size {
|
||||||
|
let defer b = ?p;
|
||||||
|
l = l | ((b & 127) << shift);
|
||||||
|
shift = shift + 7;
|
||||||
|
p = p + 1;
|
||||||
|
branch_if b & 128: size;
|
||||||
|
}
|
||||||
|
p - ptr + l
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy_section(dest: i32, src: i32) -> i32 {
|
||||||
|
let defer length = section_size(src);
|
||||||
|
copy(dest, src, length);
|
||||||
|
length
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy(dest: i32, src: i32, len: i32) {
|
||||||
|
if len > 0 {
|
||||||
|
loop bytes {
|
||||||
|
?(dest + (len := len - 1)) = ?(src + len);
|
||||||
|
branch_if len: bytes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
platform/makefile
Normal file
7
platform/makefile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
all: loader.wasm base.wasm
|
||||||
|
|
||||||
|
loader.wasm: loader.cwa
|
||||||
|
curlywas loader.cwa
|
||||||
|
|
||||||
|
base.wasm: base.cwa
|
||||||
|
curlywas base.cwa
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"license": "Unlicense",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@parcel/optimizer-data-url": "^2.0.0",
|
"@parcel/optimizer-data-url": "^2.0.0",
|
||||||
"@parcel/transformer-inline-string": "^2.0.0",
|
"@parcel/transformer-inline-string": "^2.0.0",
|
||||||
|
|||||||
@@ -12,7 +12,11 @@
|
|||||||
<div id="centered">
|
<div id="centered">
|
||||||
<canvas id="screen" width="640" height="512"></canvas>
|
<canvas id="screen" width="640" height="512"></canvas>
|
||||||
<div id="message"></div>
|
<div id="message"></div>
|
||||||
<input id="cart" type="file" accept=".wasm,.uw8,application/wasm">
|
<button onclick="document.getElementById('cart').click()">Load cart...</button>
|
||||||
|
<input id="cart" style="visibility: hidden" type="file" accept=".wasm,.uw8,application/wasm">
|
||||||
|
</div>
|
||||||
|
<div id="footer">
|
||||||
|
<a href="http://unlicense.org/" ref="license">Unlicense</a>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import loaderUrl from "data-url:./uw8loader.wasm";
|
import loaderUrl from "data-url:../../platform/loader.wasm";
|
||||||
import baseUrl from "data-url:./base.wasm";
|
import baseUrl from "data-url:../../platform/base.wasm";
|
||||||
|
|
||||||
async function loadWasm(url, imports) {
|
async function loadWasm(url, imports) {
|
||||||
let wasm_module = await (await fetch(url)).arrayBuffer();
|
let wasm_module = await (await fetch(url)).arrayBuffer();
|
||||||
@@ -21,8 +21,8 @@ framebufferCanvas.width = 320;
|
|||||||
framebufferCanvas.height = 256;
|
framebufferCanvas.height = 256;
|
||||||
let framebufferCanvasCtx = framebufferCanvas.getContext("2d");
|
let framebufferCanvasCtx = framebufferCanvas.getContext("2d");
|
||||||
let imageData = framebufferCanvasCtx.createImageData(320, 256);
|
let imageData = framebufferCanvasCtx.createImageData(320, 256);
|
||||||
let canvasCtx = document.getElementById('screen').getContext('2d');
|
let screen = document.getElementById('screen');
|
||||||
canvasCtx.imageSmoothingEnabled = false;
|
let canvasCtx = screen.getContext('2d');
|
||||||
|
|
||||||
let cancelFunction;
|
let cancelFunction;
|
||||||
|
|
||||||
@@ -53,6 +53,8 @@ async function runModule(data) {
|
|||||||
history.pushState(null, null, newURL);
|
history.pushState(null, null, newURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
screen.width = screen.width;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
let loaderImport = {
|
let loaderImport = {
|
||||||
@@ -79,6 +81,10 @@ async function runModule(data) {
|
|||||||
let importObject = {
|
let importObject = {
|
||||||
env: {
|
env: {
|
||||||
memory: new WebAssembly.Memory({ initial: 8, maximum: 8 }),
|
memory: new WebAssembly.Memory({ initial: 8, maximum: 8 }),
|
||||||
|
},
|
||||||
|
math: {
|
||||||
|
sin: Math.sin,
|
||||||
|
cos: Math.cos
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -107,6 +113,7 @@ async function runModule(data) {
|
|||||||
buffer[i * 4 + 3] = 255;
|
buffer[i * 4 + 3] = 255;
|
||||||
}
|
}
|
||||||
framebufferCanvasCtx.putImageData(imageData, 0, 0);
|
framebufferCanvasCtx.putImageData(imageData, 0, 0);
|
||||||
|
canvasCtx.imageSmoothingEnabled = false;
|
||||||
canvasCtx.drawImage(framebufferCanvas, 0, 0, 640, 512);
|
canvasCtx.drawImage(framebufferCanvas, 0, 0, 640, 512);
|
||||||
|
|
||||||
window.requestAnimationFrame(mainloop);
|
window.requestAnimationFrame(mainloop);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
|
html, body, canvas {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
html {
|
html {
|
||||||
font-family: 'Josefin Sans', sans-serif;
|
font-family: 'Josefin Sans', Verdana, 'Arial Black', sans-serif;
|
||||||
background-color: #202024;
|
background-color: #202024;
|
||||||
color: #808070;
|
color: #808070;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -7,16 +12,55 @@ html {
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: grid;
|
||||||
justify-content: center;
|
grid-template-rows: 1fr 0fr;
|
||||||
align-items: center;
|
}
|
||||||
|
|
||||||
|
#centered {
|
||||||
|
align-self: center;
|
||||||
|
justify-self: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
color: #202420;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #303630;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: #405040;
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas {
|
canvas {
|
||||||
margin: 8px;
|
background-color: #202428;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
border: 4px solid #303040;
|
||||||
box-shadow: 5px 5px 20px black;
|
box-shadow: 5px 5px 20px black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.error {
|
#message {
|
||||||
color: red;
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: #e04030;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
font-family: inherit;
|
||||||
|
background-color: #303440;
|
||||||
|
color: #808070;
|
||||||
|
padding: 4px;
|
||||||
|
border: 1px solid #404040;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: #202010;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:active {
|
||||||
|
background-color: #504450;
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user