mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 19:26:43 +01:00
fix rectangle function, change resolution to 320x240
This commit is contained in:
@@ -34,18 +34,18 @@ export fn cls(col: i32) {
|
|||||||
col = (col & 255) * 0x1010101;
|
col = (col & 255) * 0x1010101;
|
||||||
loop pixels {
|
loop pixels {
|
||||||
i!120 = col;
|
i!120 = col;
|
||||||
branch_if (i := i + 4) < 320*256: pixels;
|
branch_if (i := i + 4) < 320*240: pixels;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn setPixel(x: i32, y: i32, col: i32) {
|
export fn setPixel(x: i32, y: i32, col: i32) {
|
||||||
if x #< 320 & y #< 256 {
|
if x #< 320 & y #< 240 {
|
||||||
(x + y * 320)?120 = col
|
(x + y * 320)?120 = col
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn getPixel(x: i32, y: i32) -> i32 {
|
export fn getPixel(x: i32, y: i32) -> i32 {
|
||||||
if x #< 320 & y #< 256 {
|
if x #< 320 & y #< 240 {
|
||||||
(x + y * 320)?120
|
(x + y * 320)?120
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
@@ -59,7 +59,7 @@ fn clamp(v: i32, min: i32, max: i32) -> i32 {
|
|||||||
export fn hline(x1: i32, x2: i32, y: i32, col: i32) {
|
export fn hline(x1: i32, x2: i32, y: i32, col: i32) {
|
||||||
x1 = clamp(x1, 0, 320);
|
x1 = clamp(x1, 0, 320);
|
||||||
x2 = clamp(x2, 0, 320);
|
x2 = clamp(x2, 0, 320);
|
||||||
if x1 < x2 & y #< 256 {
|
if x1 < x2 & y #< 240 {
|
||||||
let ptr = y * 320 + x1;
|
let ptr = y * 320 + x1;
|
||||||
let end = ptr + x2 - x1;
|
let end = ptr + x2 - x1;
|
||||||
loop pixels {
|
loop pixels {
|
||||||
@@ -72,13 +72,13 @@ export fn hline(x1: i32, x2: i32, y: i32, col: i32) {
|
|||||||
export fn rectangle(x: f32, y: f32, w: f32, h: f32, col: i32) {
|
export fn rectangle(x: f32, y: f32, w: f32, h: f32, col: i32) {
|
||||||
if abs(w) == w & abs(h) == h {
|
if abs(w) == w & abs(h) == h {
|
||||||
let x1 = nearest(x) as i32;
|
let x1 = nearest(x) as i32;
|
||||||
let y1 = clamp(nearest(y) as i32, 0, 256);
|
let y1 = clamp(nearest(y) as i32, 0, 240);
|
||||||
let x2 = nearest(x + w) as i32;
|
let x2 = nearest(x + w) as i32;
|
||||||
let y2 = clamp(nearest(y + h) as i32, 0, 256);
|
let y2 = clamp(nearest(y + h) as i32, 0, 240);
|
||||||
block done {
|
block done {
|
||||||
loop lines {
|
loop lines {
|
||||||
branch_if y1 >= y2: done;
|
branch_if y1 >= y2: done;
|
||||||
hline(x1, y1, x2, col);
|
hline(x1, x2, y1, col);
|
||||||
y1 = y1 + 1;
|
y1 = y1 + 1;
|
||||||
branch lines;
|
branch lines;
|
||||||
}
|
}
|
||||||
@@ -87,8 +87,8 @@ export fn rectangle(x: f32, y: f32, w: f32, h: f32, col: i32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export fn circle(cx: f32, cy: f32, radius: f32, col: i32) {
|
export fn circle(cx: f32, cy: f32, radius: f32, col: i32) {
|
||||||
let y = clamp(nearest(cy - radius) as i32, 0, 256);
|
let y = clamp(nearest(cy - radius) as i32, 0, 240);
|
||||||
let maxY = clamp(nearest(cy + radius) as i32, 0, 256);
|
let maxY = clamp(nearest(cy + radius) as i32, 0, 240);
|
||||||
|
|
||||||
block done {
|
block done {
|
||||||
loop lines {
|
loop lines {
|
||||||
@@ -110,7 +110,7 @@ export fn circle(cx: f32, cy: f32, radius: f32, col: i32) {
|
|||||||
start fn setup() {
|
start fn setup() {
|
||||||
let i: i32;
|
let i: i32;
|
||||||
loop colors {
|
loop colors {
|
||||||
(i*4)!(120+320*256) = i * 0x10101;
|
(i*4)!(120+320*240) = i * 0x10101;
|
||||||
branch_if (i := i + 1) < 256: colors
|
branch_if (i := i + 1) < 256: colors
|
||||||
}
|
}
|
||||||
randomSeed(random());
|
randomSeed(random());
|
||||||
|
|||||||
@@ -83,6 +83,6 @@ possible but no examples are provided, yet.
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
* [Technotunnel](v0.1pre2#AQrDAQHAAQIBfwp9A0AgAUEAsiABQcACb7JDmhkgQ5MiBCAEIASUIAFBwAJtQYABa7IiBSAFlJKRIgaVIgcgByAAskHQD7KVIgIQAEPNzEw/lCIDlCAHIAeUIAOUIAOUQQGykiADIAOUk5GSIgiUIAOTQQqylCACkiIJqCAFIAaVIAiUQQqylCACkiIKqHMgCEEyspQgBpUiCyACkkEUspSocUEFcbJBArIgC5OUQRaylJeoOgB4IAFBAWoiAUGAgAVIDQALCw==) (199 bytes): A port of my [entry](https://tic80.com/play?cart=1873) in the Outline'21 bytebattle quater final
|
* [Technotunnel](v0.1pre2#AQrDAQHAAQIBfwp9A0AgAUEAsiABQcACb7JDmhkgQ5MiBCAEIASUIAFBwAJtQfgAa7IiBSAFlJKRIgaVIgcgByAAskHQD7KVIgIQAEPNzEw/lCIDlCAHIAeUIAOUIAOUQQGykiADIAOUk5GSIgiUIAOTQQqylCACkiIJqCAFIAaVIAiUQQqylCACkiIKqHMgCEEyspQgBpUiCyACkkEUspSocUEFcbJBArIgC5OUQRaylJeoOgB4IAFBAWoiAUGA2ARIDQALCw==) (199 bytes): A port of my [entry](https://tic80.com/play?cart=1873) in the Outline'21 bytebattle quater final
|
||||||
* [XorScroll](v0.1pre2#AQovAS0BAX8DQCABIAFBwAJvIABBCm1qIAFBwAJtczoAeCABQQFqIgFBgIAFSA0ACws=) (50 bytes): A simple scrolling XOR pattern. Fun fact: This is the pre-loaded effect when entering a bytebattle.
|
* [XorScroll](v0.1pre2#AQovAS0BAX8DQCABIAFBwAJvIABBCm1qIAFBwAJtczoAeCABQQFqIgFBgNgESA0ACws=) (50 bytes): A simple scrolling XOR pattern. Fun fact: This is the pre-loaded effect when entering a bytebattle.
|
||||||
* [CircleWorm](v0.1pre2#AQp7AXkCAX8CfUEgEA0DQCABskEEspUiAkECspUgALJBiCeylSIDQQWylJIQAEEBspJBoAGylCACQQOylSADQQSylJIQAEEBspJBgAGylCADQRGylCACQQKylJIQAEECspJBELKUIAFBAmxBP2oQEiABQQFqIgFBP0gNAAsL) (126 bytes): Just a test for the circle fill function.
|
* [CircleWorm](v0.1pre2#AQp7AXkCAX8CfUEgEA0DQCABskEEspUiAkECspUgALJBiCeylSIDQQWylJIQAEEBspJBoAGylCACQQOylSADQQSylJIQAEEBspJB+ACylCADQRGylCACQQKylJIQAEECspJBELKUIAFBAmxBP2oQEiABQQFqIgFBP0gNAAsL) (126 bytes): Just a test for the circle fill function.
|
||||||
File diff suppressed because one or more lines are too long
@@ -133,13 +133,13 @@ impl MicroW8 {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
let framebuffer = &instance.memory.data(&instance.store)[120..];
|
let framebuffer = &instance.memory.data(&instance.store)[120..];
|
||||||
let palette = &framebuffer[320 * 256..];
|
let palette = &framebuffer[320 * 240..];
|
||||||
for i in 0..320 * 240 {
|
for i in 0..320 * 240 {
|
||||||
let offset = framebuffer[i] as usize * 4;
|
let offset = framebuffer[i] as usize * 4;
|
||||||
self.window_buffer[i] = 0xff000000
|
self.window_buffer[i] = 0xff000000
|
||||||
| ((palette[offset + 2] as u32) << 16)
|
| ((palette[offset + 0] as u32) << 16)
|
||||||
| ((palette[offset + 1] as u32) << 8)
|
| ((palette[offset + 1] as u32) << 8)
|
||||||
| palette[offset] as u32;
|
| palette[offset + 2] as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.instance = Some(instance);
|
self.instance = Some(instance);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="centered">
|
<div id="centered">
|
||||||
<canvas id="screen" width="640" height="512"></canvas>
|
<canvas id="screen" width="640" height="480"></canvas>
|
||||||
<div id="message"></div>
|
<div id="message"></div>
|
||||||
<button id="cartButton">Load cart...</button>
|
<button id="cartButton">Load cart...</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ function setMessage(size, error) {
|
|||||||
|
|
||||||
let framebufferCanvas = document.createElement("canvas");
|
let framebufferCanvas = document.createElement("canvas");
|
||||||
framebufferCanvas.width = 320;
|
framebufferCanvas.width = 320;
|
||||||
framebufferCanvas.height = 256;
|
framebufferCanvas.height = 240;
|
||||||
let framebufferCanvasCtx = framebufferCanvas.getContext("2d");
|
let framebufferCanvasCtx = framebufferCanvas.getContext("2d");
|
||||||
let imageData = framebufferCanvasCtx.createImageData(320, 256);
|
let imageData = framebufferCanvasCtx.createImageData(320, 240);
|
||||||
let screen = document.getElementById('screen');
|
let screen = document.getElementById('screen');
|
||||||
let canvasCtx = screen.getContext('2d');
|
let canvasCtx = screen.getContext('2d');
|
||||||
|
|
||||||
@@ -120,14 +120,14 @@ async function runModule(data) {
|
|||||||
try {
|
try {
|
||||||
instance.exports.tic(Date.now() - startTime);
|
instance.exports.tic(Date.now() - startTime);
|
||||||
|
|
||||||
let framebuffer = new Uint8Array(importObject.env.memory.buffer.slice(120, 120 + 320 * 256));
|
let framebuffer = new Uint8Array(importObject.env.memory.buffer.slice(120, 120 + 320 * 240));
|
||||||
let palette = new Uint32Array(importObject.env.memory.buffer.slice(82040, 82040 + 1024));
|
let palette = new Uint32Array(importObject.env.memory.buffer.slice(76920, 76920 + 1024));
|
||||||
for (let i = 0; i < 320 * 256; ++i) {
|
for (let i = 0; i < 320 * 240; ++i) {
|
||||||
buffer[i] = palette[framebuffer[i]] | 0xff000000;
|
buffer[i] = palette[framebuffer[i]] | 0xff000000;
|
||||||
}
|
}
|
||||||
framebufferCanvasCtx.putImageData(imageData, 0, 0);
|
framebufferCanvasCtx.putImageData(imageData, 0, 0);
|
||||||
canvasCtx.imageSmoothingEnabled = false;
|
canvasCtx.imageSmoothingEnabled = false;
|
||||||
canvasCtx.drawImage(framebufferCanvas, 0, 0, 640, 512);
|
canvasCtx.drawImage(framebufferCanvas, 0, 0, 640, 480);
|
||||||
|
|
||||||
window.requestAnimationFrame(mainloop);
|
window.requestAnimationFrame(mainloop);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user