diff --git a/assembly/api.ts b/assembly/api.ts index 7f680c7..9b5ba76 100644 --- a/assembly/api.ts +++ b/assembly/api.ts @@ -36,11 +36,19 @@ export function resetGenericWithMemory( interpreter = int; } -export function nextStep(steps: number = 1): boolean { +export function nextStep(): boolean { + if (interpreter !== null) { + const int = interpreter; + return int.nextStep(); + } + return false; +} + +export function run(steps: u32): boolean { if (interpreter !== null) { const int = interpreter; let isOk = true; - for (let i = 0; i < steps; i++) { + for (let i: u32 = 0; i < steps; i++) { isOk = int.nextStep(); if (!isOk) { return false; @@ -119,6 +127,14 @@ export function getRegisters(): Uint8Array { return flat; } +export function setRegisters(flatRegisters: u8[]): void { + if (interpreter === null) { + return; + } + const int = interpreter; + fillRegisters(int.registers, flatRegisters); +} + export function getPageDump(index: u32): Uint8Array { if (interpreter === null) { return new Uint8Array(PAGE_SIZE).fill(0); @@ -132,6 +148,18 @@ export function getPageDump(index: u32): Uint8Array { return page; } +export function setMemory(address: u32, data: Uint8Array): void { + if (interpreter === null) { + return; + } + const int = interpreter; + const end = address + data.length; + for (let i = address; i < end; i++) { + // TODO [ToDr] handle page fault? + int.memory.setU8(i, data[i]); + } +} + function fillRegisters(registers: Registers, flat: u8[]): void { const len = registers.length * REG_SIZE_BYTES; if (len !== flat.length) { diff --git a/assembly/index.ts b/assembly/index.ts index 071f7cb..dc6a400 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -24,7 +24,7 @@ export function disassemble(input: u8[], kind: InputKind): string { return `Unknown kind: ${kind}`; } -export function run(input: u8[], kind: InputKind): void { +export function runProgram(input: u8[], kind: InputKind): void { if (kind === InputKind.Generic) { const vmInput = new VmInput(); vmInput.registers[7] = 9; diff --git a/web/conway.html b/web/conway.html index 0f98179..629ce26 100644 --- a/web/conway.html +++ b/web/conway.html @@ -8,7 +8,7 @@ }