using System; using System.Collections.Generic; using System.Text; namespace smallEmulator { class CPUemulator { const UInt16 LDX = 0x01; //Load x const UInt16 LDY = 0x02; //Load y const UInt16 IOX = 0x03; //IO, 0x01 for output, 0x02 for input const UInt16 HLT = 0x04; //Halt the processor UInt16 p = 0, regX = 0, regY = 0; UInt16[] memory = new UInt16[] { LDX, 0x01, LDY, 0x06, IOX, HLT, 'J','u','s','t',' ','a',' ','t','e','s','t', '!', '\n', '\0' }; public void ldx(UInt16 xData) { regX = xData; } public void ldy(UInt16 yData) { regY = yData; } public void iox() { UInt16 walk; switch (regX) { case 0x01: //Console out walk = regY; while (memory[walk] != '\0') { Console.Write((char)memory[walk]); walk++; } break; } } public void run() { bool running = true; while (running) { switch(memory[p]) { case LDX: ldx(memory[p+1]); p+=2; break; case LDY: ldy(memory[p+1]); p+=2; break; case IOX: iox(); p++; break; case HLT: Console.Write("Emulator halted, HLT.\n"); running = false; break; } } } } class driverApp { static void Main(string[] args) { CPUemulator temp = new CPUemulator(); temp.run(); } } }