diff --git a/components/src/chips/memory.tsx b/components/src/chips/memory.tsx index a3c203352..2a9d6bd00 100644 --- a/components/src/chips/memory.tsx +++ b/components/src/chips/memory.tsx @@ -28,6 +28,11 @@ import VirtualScroll, { VirtualScrollSettings } from "../virtual_scroll.js"; const ITEM_HEIGHT = 34; +interface CellData { + value: number; + wasChanged: boolean; +} + export const MemoryBlock = ({ memory, jmp = { value: 0 }, @@ -63,18 +68,21 @@ export const MemoryBlock = ({ [memory.size, jmp] ); const get = useCallback( - (pos: number, count: number) => + (pos: number, count: number): [number, CellData][] => memory .range(pos + offset, pos + offset + count) - .map((v, i) => [i + pos + offset, v] as [number, number]), + .map((v, i) => [ + i + pos + offset, + { value: v, wasChanged: memory.wasChanged(i + pos + offset) }, + ]), [memory] ); const row = useCallback( - ([i, v]: [number, number]) => ( + ([i, v]: [number, CellData]) => ( label.length)) : 0 )} @@ -91,7 +99,7 @@ export const MemoryBlock = ({ ); return ( - + settings={settings} get={get} row={row} diff --git a/components/src/inline_edit.tsx b/components/src/inline_edit.tsx index a8efc8b1d..96c035f31 100644 --- a/components/src/inline_edit.tsx +++ b/components/src/inline_edit.tsx @@ -26,14 +26,17 @@ export const InlineEdit = (props: { }; const view = () => ( - { setMode(Mode.EDIT); }} > - {value} - + {value}  + ); const doSelect = useCallback( diff --git a/simulator/src/cpu/memory.ts b/simulator/src/cpu/memory.ts index dcf42970f..bf0c5eb29 100644 --- a/simulator/src/cpu/memory.ts +++ b/simulator/src/cpu/memory.ts @@ -17,6 +17,8 @@ export interface MemoryAdapter { size: number; get(index: number): number; set(index: number, value: number): void; + wasChanged(index: number): boolean; + setChanged(index: number, value: boolean): void; reset(): void; update(cell: number, value: string, format: Format): void; load(fs: FileSystem, path: string, offset?: number): Promise; @@ -38,6 +40,7 @@ export interface KeyboardAdapter { export class Memory implements MemoryAdapter { private memory: Int16Array; + private changed: boolean[]; get size(): number { return this.memory.length; @@ -46,8 +49,10 @@ export class Memory implements MemoryAdapter { constructor(memory: ArrayBuffer | number) { if (typeof memory === "number") { this.memory = new Int16Array(memory); + this.changed = new Array(memory).fill(false); } else { this.memory = new Int16Array(memory); + this.changed = new Array(this.size).fill(true); } } @@ -58,14 +63,24 @@ export class Memory implements MemoryAdapter { return this.memory[index] ?? 0; } + wasChanged(index: number): boolean { + return this.changed[index]; + } + + setChanged(index: number, value: boolean): void { + this.changed[index] = value; + } + set(index: number, value: number): void { if (index >= 0 && index < this.size) { this.memory[index] = value & 0xffff; + this.setChanged(index, true); } } reset(): void { this.memory.fill(0); + this.changed.fill(false); } update(cell: number, value: string, format: Format) { @@ -106,7 +121,9 @@ export class Memory implements MemoryAdapter { loadBytes(bytes: number[], offset?: number): void { this.memory.set(new Int16Array(bytes), offset); + this.changed.fill(true, 0, bytes.length); this.memory.fill(0, bytes.length, this.size); + this.changed.fill(false, bytes.length, this.size); } range(start = 0, end = this.size): number[] { @@ -143,7 +160,15 @@ export class SubMemory implements MemoryAdapter { return this.parent.get(this.offset + index); } - set(index: number, value: number): void { + wasChanged(index: number): boolean { + return this.parent.wasChanged(this.offset + index); + } + + setChanged(index: number, value: boolean): void { + this.parent.setChanged(index + this.offset, value); + } + + set(index: number, value: number, trackChange = true): void { if (index >= 0 && index < this.size) { this.parent.set(index + this.offset, value); } @@ -151,7 +176,8 @@ export class SubMemory implements MemoryAdapter { reset(): void { for (let i = 0; i < this.size; i++) { - this.set(i, 0); + this.set(i, 0, false); + this.setChanged(i, false); } } diff --git a/simulator/src/vm/vm.ts b/simulator/src/vm/vm.ts index 24a6ab99a..252dd939a 100644 --- a/simulator/src/vm/vm.ts +++ b/simulator/src/vm/vm.ts @@ -522,8 +522,6 @@ export class Vm { }, ]; this.memory.reset(); - this.memory.ARG = 0; - this.memory.LCL = 0; this.memory.SP = 256; this.segmentInitializations = { local: { initialized: false, n: 0 }, diff --git a/web/src/pages/cpu.scss b/web/src/pages/cpu.scss index 69333a6ad..2a13dab7c 100644 --- a/web/src/pages/cpu.scss +++ b/web/src/pages/cpu.scss @@ -2,19 +2,19 @@ .CpuPage { grid-template-areas: "ROM RAM" "IO IO" "test test"; - grid-template-columns: 1fr 1fr; - grid-template-rows: 1fr 1fr 1fr; + grid-template-columns: 1fr 1fr !important; + grid-template-rows: 1fr 1fr 1fr !important; @media screen and (min-width: 1024px) { grid-template-areas: "ROM RAM IO" "test test test"; - grid-template-columns: 1fr 1fr var(--screen-size); - grid-template-rows: 1fr 1fr; + grid-template-columns: 1fr 1fr var(--screen-size) !important; + grid-template-rows: 1fr 1fr !important; } @media screen and (min-width: 1500px) { grid-template-areas: "ROM RAM IO test"; - grid-template-columns: 350px 350px var(--screen-size) auto; - grid-template-rows: 1fr; + grid-template-columns: 350px 350px var(--screen-size) auto !important; + grid-template-rows: 1fr !important; // "IO IO test" // "ROM RAM test"; }