package hatelace; public class IntMemory extends Memory { protected int[] memory; public IntMemory() { this.memory = new int[256]; } public IntMemory(int size) { this.memory = new int[size]; } public int read(int address) { return this.memory[address]; } public int size() { return this.memory.length; } public void write(int address, Word data) { if (address < 0 || address >= this.memory.length) { throw new IllegalArgumentException("Invalid memory address"); } this.memory[address] = data.getValue(); } /** Dump as IHEX-like format (see https://en.wikipedia.org/wiki/Intel_HEX) */ public void dump() { for(int i = 0; i < this.memory.length; i+= 16) { System.out.printf(":%02X%04X00 ", 16, i); for(int j = 0; j < 16; j++) { int content = this.memory[i + j]; // Print it as faded if it's zero if (content == 0) System.out.print("\u001B[2m"); System.out.printf("%02X ", this.memory[i + j]); System.out.print("\u001B[0m"); } System.out.println(); } } }