From f649402ffdb87f20b99d0af87a9e3e7c9920673e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Drwi=C4=99ga?= Date: Fri, 6 Dec 2024 18:07:23 +0100 Subject: [PATCH] Fix issue with `OneRegTwoImm` decoding and add Game of Life example on the website. (#9) * Render game of life. * Perform multiple steps at once. * QA. --- assembly/api.ts | 11 ++- assembly/arguments.ts | 11 ++- assembly/codec.ts | 2 +- assembly/instructions-outcome.ts | 2 +- assembly/interpreter.ts | 4 +- assembly/memory.ts | 4 +- web/conway.html | 156 +++++++++++++++++++++++++++++++ web/index.html | 57 +---------- web/styles.css | 51 ++++++++++ 9 files changed, 233 insertions(+), 65 deletions(-) create mode 100644 web/conway.html create mode 100644 web/styles.css diff --git a/assembly/api.ts b/assembly/api.ts index 69138a0..7f680c7 100644 --- a/assembly/api.ts +++ b/assembly/api.ts @@ -36,10 +36,17 @@ export function resetGenericWithMemory( interpreter = int; } -export function nextStep(): boolean { +export function nextStep(steps: number = 1): boolean { if (interpreter !== null) { const int = interpreter; - return int.nextStep(); + let isOk = true; + for (let i = 0; i < steps; i++) { + isOk = int.nextStep(); + if (!isOk) { + return false; + } + } + return isOk; } return false; } diff --git a/assembly/arguments.ts b/assembly/arguments.ts index 872cde9..70d1763 100644 --- a/assembly/arguments.ts +++ b/assembly/arguments.ts @@ -16,7 +16,7 @@ export enum Arguments { /** How many numbers in `Args` is relevant for given `Arguments`. */ export const RELEVANT_ARGS = [0, 1, 2, 1, 2, 3, 3, 2, 3, 3, 4, 3]; -@unmanaged +// @unmanaged export class Args { a: u32 = 0; b: u32 = 0; @@ -67,8 +67,11 @@ export const DECODERS: ArgsDecoder[] = [ }, //DECODERS[Arguments.OneRegTwoImm] = (data: Uint8Array) => { - const result = twoImm(data.subarray(1)); - return asArgs(nibbles(data[0]).low, result.a, result.b, result.c); + const first = nibbles(data[0]); + const split = first.hig + 1; + const immA = decodeI32(data.subarray(1, split)); + const immB = decodeI32(data.subarray(split)); + return asArgs(first.low, immA, immB, 0); }, // DECODERS[Arguments.OneRegOneImmOneOff] = (data: Uint8Array) => { @@ -104,7 +107,7 @@ export const DECODERS: ArgsDecoder[] = [ }, ]; -@unmanaged +// @unmanaged class Nibbles { low: u8 = 0; hig: u8 = 0; diff --git a/assembly/codec.ts b/assembly/codec.ts index 0810e40..57aee97 100644 --- a/assembly/codec.ts +++ b/assembly/codec.ts @@ -81,7 +81,7 @@ export class Decoder { } } -@unmanaged +// @unmanaged export class ValOffset { constructor( public readonly value: T, diff --git a/assembly/instructions-outcome.ts b/assembly/instructions-outcome.ts index 4c0a397..f8bcf59 100644 --- a/assembly/instructions-outcome.ts +++ b/assembly/instructions-outcome.ts @@ -13,7 +13,7 @@ export enum Outcome { Result = 3, } -@unmanaged +// @unmanaged export class OutcomeData { outcome: Outcome = Outcome.Ok; staticJump: i32 = 0; diff --git a/assembly/interpreter.ts b/assembly/interpreter.ts index 39b3c14..a2b0284 100644 --- a/assembly/interpreter.ts +++ b/assembly/interpreter.ts @@ -141,7 +141,7 @@ export class Interpreter { } } -@unmanaged +// @unmanaged class BranchResult { isOkay: boolean = false; newPc: u32 = 0; @@ -163,7 +163,7 @@ enum DjumpStatus { PANIC = 2, } -@unmanaged +// @unmanaged class DjumpResult { status: DjumpStatus = DjumpStatus.OK; newPc: u32 = 0; diff --git a/assembly/memory.ts b/assembly/memory.ts index 8b65356..b24d442 100644 --- a/assembly/memory.ts +++ b/assembly/memory.ts @@ -1,12 +1,12 @@ import { Access, Arena, PAGE_SIZE, PAGE_SIZE_SHIFT, Page, PageIndex } from "./memory-page"; -@unmanaged +// @unmanaged export class MaybePageFault { isFault: boolean = false; fault: u32 = 0; } -@unmanaged +// @unmanaged export class Result { ok: u32 = 0; fault: MaybePageFault = new MaybePageFault(); diff --git a/web/conway.html b/web/conway.html new file mode 100644 index 0000000..0f98179 --- /dev/null +++ b/web/conway.html @@ -0,0 +1,156 @@ + + + + + + + + +

Check out other fluffy stuff.

+

🍍 Anan-AS - Game Of Life

+

Download: + release.wasm|wat + or + debug.wasm|wat +

+

+ Home +

+
+  
+ + + + Looking for a better disassembler for PVM? + + diff --git a/web/index.html b/web/index.html index bcb4151..9619584 100644 --- a/web/index.html +++ b/web/index.html @@ -1,59 +1,7 @@ - +