Beispiel #1
0
 public static void float_to_reg(SPU spu, int r, float[] d)
 {
     for (int i = 0; i < 4; i++)
     {
         spu.Register[r, i] = ConversionUtil.byteToUInt(BitConverter.GetBytes(d[i]));
     }
 }
Beispiel #2
0
 public static void ls2reg(SPU spu, int r, uint addr)
 {
     addr &= SPUCommandHelper.LSLR & 0xfffffff0;
     byte[] ls = new byte[4];
     System.Array.Copy(spu.LocalStorage, addr, ls, 0, 4);
     spu.Register[r, 0] = ConversionUtil.byteToUInt(ls);
     System.Array.Copy(spu.LocalStorage, addr + 4, ls, 0, 4);
     spu.Register[r, 1] = ConversionUtil.byteToUInt(ls);
     System.Array.Copy(spu.LocalStorage, addr + 8, ls, 0, 4);
     spu.Register[r, 2] = ConversionUtil.byteToUInt(ls);
     System.Array.Copy(spu.LocalStorage, addr + 12, ls, 0, 4);
     spu.Register[r, 3] = ConversionUtil.byteToUInt(ls);
 }
Beispiel #3
0
 public static void double_to_reg(SPU spu, int r, double[] d)
 {
     byte[] b;
     byte[] b2 = new byte[4];
     b     = BitConverter.GetBytes(d[0]);
     b2[0] = b[4]; b2[1] = b[5]; b2[2] = b[6]; b2[3] = b[7];
     spu.Register[r, 1] = ConversionUtil.byteToUInt(b);
     spu.Register[r, 0] = ConversionUtil.byteToUInt(b2);
     b     = BitConverter.GetBytes(d[1]);
     b2[0] = b[4]; b2[1] = b[5]; b2[2] = b[6]; b2[3] = b[7];
     spu.Register[r, 3] = ConversionUtil.byteToUInt(b);
     spu.Register[r, 2] = ConversionUtil.byteToUInt(b2);
 }
Beispiel #4
0
        public static void LoadElf(string FileName, SPU spu, bool setProgramCounter)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(FileName));

            // GetElfHeader
            byte[] elfMagic = new byte[4];
            br.Read(elfMagic, 0, 4);
            if (elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F)
            {
                MessageBox.Show("Elf Magic Wrong (" + FileName + ")");
                return;
            }
            br.BaseStream.Seek(0, SeekOrigin.Begin);
            byte[] eHDR = new byte[0x34];
            br.Read(eHDR, 0, eHDR.Length);
            uint   phdr_offset = ConversionUtil.byteToUInt(eHDR, 0x1C);
            ushort n_phdrs     = ConversionUtil.byteToUShort(eHDR, 0x2C);

            for (ushort i = 0; i < n_phdrs; i++)
            {
                int error = LoadElfPHDR(br, spu, phdr_offset, i);
                if (error == 1)
                {
                    MessageBox.Show("Didn't Load phdr " + i + " of File " + FileName);
                }
                else if (error == 2)
                {
                    MessageBox.Show("Local Storage Overflow!");
                }
            }

            if (setProgramCounter)
            {
                spu.IP = ConversionUtil.byteToUInt(eHDR, 0x18);
            }
            br.Close();
        }
Beispiel #5
0
        public static int LoadElfPHDR(BinaryReader br, SPU spu, uint phdr_offset, uint i)
        {
            byte[] phdr = new byte[0x20];
            uint   offset, paddr, size;

            br.BaseStream.Seek(phdr_offset + 0x20 * i, SeekOrigin.Begin);
            br.Read(phdr, 0, phdr.Length);
            if (ConversionUtil.byteToUInt(phdr) != 1)
            {
                return(1);
            }
            offset = ConversionUtil.byteToUInt(phdr, 0x04);
            paddr  = ConversionUtil.byteToUInt(phdr, 0x0C);
            size   = ConversionUtil.byteToUInt(phdr, 0x10);

            if ((offset + size) > spu.LocalStorage.Length)
            {
                return(2);
            }
            br.BaseStream.Seek(offset, SeekOrigin.Begin);
            br.Read(spu.LocalStorage, (int)paddr, (int)size);
            return(0);
        }