/// <summary> /// Ctor /// </summary> public S8CPU() { state = new CpuState(); stack = new CpuStack(); SetMaxTicks(DEFAULT_MAX_STEPS); }
//const memory = load(executable); //let stdout = new Uint8Array(); //const backtrace: number[] = []; public byte[] Load(byte[] executable) { int oldMaxTicks = DEFAULT_MAX_STEPS; if (state is not null) { oldMaxTicks = state.maxTicks; } state = new CpuState(); SetMaxTicks(oldMaxTicks); ResetRegs(); if (executable.Length > 4096 * 10) { LogMessage(ERROR_MESSAGE[(int)ERROR_MESSAGE_ID.fileSizeTooBig]); return(null); } if (!validateMagic(executable)) { LogMessage(ERROR_MESSAGE[(int)ERROR_MESSAGE_ID.unsupportedExecutable]); return(null); } state.memory = new byte[4096 * 10]; int seek = 7; UInt16 i = 0; while (seek < executable.Length) { state.memory[i++] = executable[seek++]; } state.memoryUsed = i; return(state.memory); }