public void CanSetSpriteAtByteBorderBit() { var sprite = new byte[5]; sprite[0] = 0xff; var display = new TestDisplay(); var cpu = new CPU(new Memory(), display, null); cpu.SetSprite(8, 0, sprite, 1); // 0 1 2 3 // 0000000011111110000000000000000 // 0x0 0xff 0x0 0x0 Assert.AreEqual(0xff, display.Screen[1]); }
public void CanSetSprite1() { var sprite = new byte[5]; sprite[0] = 0x20; sprite[1] = 0x60; sprite[2] = 0x20; sprite[3] = 0x20; sprite[4] = 0x70; var display = new TestDisplay(); var cpu = new CPU(new Memory(), display, null); cpu.SetSprite(4, 4, sprite, 5); display.Print(); }
public void CanDetectCollisions() { var sprite = new byte[1]; sprite[0] = 0x20; // 00100000 lsb = 00000100 msb var display = new TestDisplay(); display.Screen[0] = 0x4; // 00100000 lsb var memory = new Memory(); memory.LoadAt(sprite, 0x300); var cpu = new CPU(memory, display, new Keyboard()); cpu.Register[0] = 0; cpu.Register[1] = 0; cpu.AddressRegister = 0x300; cpu.ProcessInstruction(0xd011); Assert.AreEqual(1, cpu.Register[0xf]); }
public void Run(string programpath) { var display = new ConsoleDisplay(); var keyboard = new ConsoleKeyboard(); memory = new Memory(); cpu = new CPU(memory, display, keyboard); disassembler = new Disassembler(); // Load ROM var romfile = File.OpenRead("ROM.bin"); var rom = new byte[512]; romfile.Read(rom, 0, 512); romfile.Close(); memory.InitializeROM(rom); // Load Program var programfile = File.OpenRead(programpath); var program = new byte[3584]; programfile.Read(program, 0, 3584); memory.LoadProgram(program); // Start clock Stopwatch sw = new Stopwatch(); var cpuspeed = 6 * Stopwatch.Frequency / 1000; while (true){ var debug = keyboard.CheckKeys(); if (debug){ StartDebugging(); debug = false; continue; } if(!sw.IsRunning || sw.ElapsedTicks > cpuspeed) { cpu.Clock(); sw.Restart(); } } }
public void CanSetSpriteAtOddBit() { var sprite = new byte[5]; sprite[0] = 0xff; var display = new TestDisplay(); var cpu = new CPU(new Memory(), display, null); cpu.SetSprite(10, 0, sprite, 1); display.Print(); // 0 1 2 3 // 0000000000111111100000000000000 // 0000000011111110000000011000000 msb -> lsb // 0x0 0x3f 0xc0 0x0 Assert.AreEqual(0xfc, display.Screen[1]); Assert.AreEqual(0x03, display.Screen[2]); }
public void CanWrapSpriteAtY() { var sprite = new byte[5]; sprite[0] = 0xff; sprite[1] = 0xff; var display = new TestDisplay(); var cpu = new CPU(new Memory(), display, null); cpu.SetSprite(0, 31, sprite, 2); Assert.AreEqual(0xff, display.Screen[31*8]); Assert.AreEqual(0xff, display.Screen[0]); }
public void CanWrapSpriteAtX() { var sprite = new byte[5]; sprite[0] = 0xff; var display = new TestDisplay(); var cpu = new CPU(new Memory(), display, null); cpu.SetSprite(62, 0, sprite, 1); // 62 63 |64 65 // 11111100 00000000 |00000000 00000011 // 00111111 00000000 |00000000 11000000 lsb // 0xfc 0x0 0x0 0x3 display.Print(); Assert.AreEqual(0xc0, display.Screen[7]); Assert.AreEqual(0x3f, display.Screen[0]); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Chip8Android.Resource.Layout.Main); SetClickHandler(Resource.Id.button0); SetClickHandler(Resource.Id.button1); SetClickHandler(Resource.Id.button2); SetClickHandler(Resource.Id.button3); SetClickHandler(Resource.Id.button4); SetClickHandler(Resource.Id.button5); SetClickHandler(Resource.Id.button6); SetClickHandler(Resource.Id.button7); SetClickHandler(Resource.Id.button8); SetClickHandler(Resource.Id.button9); SetClickHandler(Resource.Id.buttonA); SetClickHandler(Resource.Id.buttonB); SetClickHandler(Resource.Id.buttonC); SetClickHandler(Resource.Id.buttonD); SetClickHandler(Resource.Id.buttonE); SetClickHandler(Resource.Id.buttonF); Chip8View view = (Chip8View)FindViewById(Resource.Id.chip8view); var memory = new Memory(); memory.InitializeInterpreterBuffer(); int appno = 2; var apps = new string[]{ "IBM Logo.ch8", "Brix.ch8", "Keypad Test.ch8", "Trip8 Demo.ch8" }; var stream = Assets.Open(apps[appno]); byte[] buffer = new byte[3584]; stream.Read(buffer, 0, 3584); memory.LoadProgram(buffer); keyboard = new KeyboardHandler(); var chip8 = new CPU(memory, view, keyboard); timer = new System.Timers.Timer(1); timer.Elapsed += (sender, e) => chip8.Clock(); timer.Enabled = true; // GridView view = (GridView)FindViewById(Resource.Id.gridview); // view.Adapter = new ImageAdapter(this.BaseContext); }