Advertisement
Guest User

Untitled

a guest
May 30th, 2022
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Windows.Forms;
  7. using System.Drawing;
  8. using System.Drawing.Imaging;
  9. using System.Windows.Threading;
  10. using System.Threading;
  11.  
  12. namespace SpaceInvaders
  13. {
  14.     class _8080
  15.     {
  16.         private CPU cpu = new CPU();
  17.         private MainForm MainForm = new MainForm();
  18.  
  19.         public void StartEmulator()
  20.         {
  21.             cpu.initialiseEmulator(); // Reset
  22.  
  23.             LoadProgram("invaders.rom"); // Load ROM
  24.  
  25.             cpu.emulateCPU();
  26.         }
  27.  
  28.         private bool LoadProgram(string filename)
  29.         {
  30.             Console.WriteLine("\nLoading: " + filename + "\n");
  31.             //Initialize();  //reset
  32.  
  33.             //load file
  34.             byte[] loadedProgramBytes = null;
  35.             try
  36.             {
  37.                 loadedProgramBytes = File.ReadAllBytes(filename);
  38.             }
  39.             catch (Exception Ex)
  40.             {
  41.                 Debug.WriteLine(Ex.ToString());
  42.             }
  43.  
  44.             //verify file is not empty
  45.             if (loadedProgramBytes == null)
  46.             {
  47.                 Debug.WriteLine("Error loading program.  The byte array loaded is null.");
  48.                 return false;
  49.             }
  50.  
  51.             int lSize = loadedProgramBytes.Count();
  52.  
  53.             for (int i = 0; i < lSize; ++i)
  54.             {
  55.                 cpu.memory[i] = loadedProgramBytes[i]; // Store file into memory.
  56.             }
  57.  
  58.             Debug.WriteLine("ROM loaded in successfully.\n");
  59.             return true;
  60.         }
  61.  
  62.         private void updateScreen(int addr, int val)
  63.         {
  64.             int x = addr >> 5;
  65.             int y = 255 - ((addr & 0x1f) << 3);
  66.  
  67.             for (int bit = 1; bit <= 128; bit <<= 1)
  68.             {
  69.                 //screenBuffer.SetPixel(x, y--, (bit & val) != 0 ? Color.White : Color.Black);
  70.             }
  71.  
  72.             //Bitmap clone = (Bitmap)screenBuffer.Clone();
  73.             //MainForm.pictureBox1.BackgroundImage = clone;
  74.         }
  75.  
  76.     }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement