public static void set(int addr, int val) {
		val &= 0xFF;
		if (Util.inRange(addr, 0, 0x00EF)) {	// Zero page
			mem[addr] = val;
			return;
		} else if (Util.inRange(addr, 0x00F0, 0x00FF)) {	// Function registers
			writeReg(addr, val);
			return;
		} else if (Util.inRange(addr, 0x0100, 0x7FFF)) {	// Sound RAM
			mem[addr] = val;
			return;
		} else if (Util.inRange(addr, 0xFFC0, 0xFFFF)) {	// IPL-ROM
			if (!iplRomEnable) {
				iplRam[addr - 0xFFC0] = val;
			}
			return;
		}
		
		if (Settings.isTrue(Settings.MEM_THROW_INVALID_ADDR))
			throw new RuntimeException(String.format("APU: Write invalid memory address: 0x%04x",addr));
	}