Exemple #1
0
            public void DecodeBlock(Block Block)
            {
                int SampleOffset = 0;
                int ShiftFactor  = (int)BitUtils.Extract(Block.Modificator, 0, 4);
                int PredictIndex = (int)BitUtils.Extract(Block.Modificator, 4, 4) % Vag.VAG_f.Length;

                //if (predict_nr > VAG_f.length) predict_nr = 0;

                // @TODO: maybe we can change << 12 >> shift_factor for "<< (12 - shift_factor)"
                // and move the substract outside the for.

                Predict1 = VAG_f[PredictIndex * 2 + 0];
                Predict2 = VAG_f[PredictIndex * 2 + 1];

                //History1 = 0;
                //History2 = 0;

                // Mono 4-bit/28 Samples per block.
                for (int n = 0; n < CompressedBytesInBlock; n++)
                {
                    var DataByte = Block.Data[n];

                    DecodedBlockSamples[SampleOffset++] =
                        HandleSampleKeepHistory(((short)((((uint)DataByte >> 0) & 0xF) << 12)) >> ShiftFactor);
                    DecodedBlockSamples[SampleOffset++] =
                        HandleSampleKeepHistory(((short)((((uint)DataByte >> 4) & 0xF) << 12)) >> ShiftFactor);
                }
            }
        public AstNodeStm Vrot()
        {
            var imm5      = _instruction.Imm5;
            var cosIndex  = BitUtils.Extract(imm5, 0, 2);
            var sinIndex  = BitUtils.Extract(imm5, 2, 2);
            var negateSin = BitUtils.ExtractBool(imm5, 4);

            var dest = VecVd;
            var src  = CelVs;

            AstNodeExpr sine   = _ast.CallStatic((Func <float, float>)MathFloat.SinV1, src.Get());
            AstNodeExpr cosine = _ast.CallStatic((Func <float, float>)MathFloat.CosV1, src.Get());

            if (negateSin)
            {
                sine = -sine;
            }

            //Console.WriteLine("{0},{1},{2}", CosIndex, SinIndex, NegateSin);

            return(dest.SetVector(index =>
            {
                if (index == cosIndex)
                {
                    return cosine;
                }
                if (index == sinIndex)
                {
                    return sine;
                }
                return (sinIndex == cosIndex) ? sine : 0f;
            }, _pc));
        }
Exemple #3
0
        //[GpuOpCodesNotImplemented]
        public void OP_REGION2()
        {
            var X2 = (short)BitUtils.Extract(Params24, 0, 10);
            var Y2 = (short)BitUtils.Extract(Params24, 10, 10);

            GpuState->Viewport.RegionBottomRight.X = X2;
            GpuState->Viewport.RegionBottomRight.Y = Y2;
        }
Exemple #4
0
        // void drawRegion(int x, int y, int width, int height)
        // void sceGuDispBuffer(int width, int height, void* dispbp, int dispbw)
        //[GpuOpCodesNotImplemented]
        public void OP_REGION1()
        {
            var X1 = (short)BitUtils.Extract(Params24, 0, 10);
            var Y1 = (short)BitUtils.Extract(Params24, 10, 10);

            GpuState->Viewport.RegionTopLeft.X = X1;
            GpuState->Viewport.RegionTopLeft.Y = Y1;
        }
Exemple #5
0
        // S000 <-- S(Matrix)(Column)(Row)
        private void _VfpuLoadVectorWithIndexPointer(uint Register, uint Index, uint Size, bool Debug = false)
        {
            uint     Line     = BitUtils.Extract(Register, 0, 2);     // 0-3
            uint     Matrix   = BitUtils.Extract(Register, 2, 3);     // 0-7
            LineType LineType = LineType.None;
            uint     Row      = 0;
            uint     Column   = 0;

            if (Size == 1)
            {
                Column = Line;
                Row    = (Register >> 5) & 3;
            }
            else
            {
                uint Offset = (Register & 64) >> (int)(3 + Size);
                LineType = ((Register & 32) == 0) ? LineType.Column : LineType.Row;

                if (LineType == LineType.Row)
                {
                    Column = Offset + Index;
                    Row    = Line;
                }
                else
                {
                    Column = Line;
                    Row    = Offset + Index;
                }
            }

            uint RegisterIndex = Matrix * 16 + Row * 4 + Column;

            if (Debug)
            {
                char C = 'S';
                if (LineType != LineType.None)
                {
                    C = (LineType == LineType.Row) ? 'R' : 'C';
                }
                Console.Error.WriteLine(
                    "_VfpuLoadVectorWithIndexPointer(R={0},I={1},S={2}): " +
                    "{9}{3}{4}{5} Index({1}) :: Matrix={3}, Column={4}, Row={5}, Type={6}, " +
                    "RegisterIndex={7}, Line={8}",
                    Register, Index, Size,
                    Matrix, Column, Row, LineType,
                    RegisterIndex,
                    Line, C
                    );
            }

            //if (Reg == null) throw(new InvalidOperationException("Invalid Vfpu register"));
            MipsMethodEmiter.LoadFieldPtr(typeof(CpuThreadState).GetField("VFR" + RegisterIndex));
        }
Exemple #6
0
        void _vzero_x(uint VectorSize, uint Register)
        {
            uint IndexOne = BitUtils.Extract(Register, 0, 2);

            foreach (var Index in XRange(VectorSize))
            {
                VfpuSave_Register(Register, Index, VectorSize, PrefixNone, () =>
                {
                    MipsMethodEmiter.ILGenerator.Emit(OpCodes.Ldc_R4, 0.0f);
                }
                                  //, Debug: true
                                  );
            }
        }
        // TextureMipmap Size
        private void _OP_TSIZE(int Index)
        {
            // Astonishia Story is using normalArgument = 0x1804
            // -> use texture_height = 1 << 0x08 (and not 1 << 0x18)
            //        texture_width  = 1 << 0x04
            // The maximum texture size is 512x512: the exponent value must be [0..9]
            // Maybe a bit flag for something?

            var  MipMap      = MipMapState(Index);
            var  WidthExp    = (int)BitUtils.Extract(Params24, 0, 4);
            var  HeightExp   = (int)BitUtils.Extract(Params24, 8, 4);
            bool UnknownFlag = BitUtils.Extract(Params24, 15, 1) != 0;

            if (UnknownFlag)
            {
                Console.Error.WriteLine("_OP_TSIZE UnknownFlag : 0x{0:X}", Params24);
            }
            WidthExp  = Math.Min(WidthExp, 9);
            HeightExp = Math.Min(HeightExp, 9);

            MipMap->TextureWidth  = (int)(1 << WidthExp);
            MipMap->TextureHeight = (int)(1 << HeightExp);
        }
Exemple #8
0
            public bool DecodeBlock(Block Block, short[] Samples, ref int SampleOffset)
            {
                this.Samples      = Samples;
                this.SampleOffset = SampleOffset;

                int ShiftFactor  = (int)BitUtils.Extract(Block.Modificator, 0, 4);
                int PredictIndex = (int)BitUtils.Extract(Block.Modificator, 4, 4) % Vag.VAG_f.Length;

                //if (predict_nr > VAG_f.length) predict_nr = 0;

                if (Block.Type == Block.TypeEnum.End)
                {
                    return(true);
                }

                // @TODO: maybe we can change << 12 >> shift_factor for "<< (12 - shift_factor)"
                // and move the substract outside the for.

                Predict1 = VAG_f[PredictIndex][0];
                Predict2 = VAG_f[PredictIndex][1];

                // Mono 4-bit/28 Samples per block.
                for (int n = 0; n < 14; n++)
                {
                    var DataByte = Block.Data[n];

                    PutSample(((short)(BitUtils.Extract(DataByte, 0, 4) << 12)) >> ShiftFactor);
                    PutSample(((short)(BitUtils.Extract(DataByte, 4, 4) << 12)) >> ShiftFactor);
                    //PutSample(SampleLeft);
                    //PutSample(SampleRight);
                }

                SampleOffset = this.SampleOffset;

                return(false);
            }
Exemple #9
0
 // cst(xyzw)
 public bool SourceConstant(int i)
 {
     //assert(i >= 0 && i < 4);
     //return (value >> (12 + i * 1)) & 1;
     return(BitUtils.Extract(Value, 12 + i * 1, 1) != 0);
 }
Exemple #10
0
 // swz(xyzw)
 public uint SourceIndex(int i)
 {
     //assert(i >= 0 && i < 4);
     //return (value >> (0 + i * 2)) & 3;
     return(BitUtils.Extract(Value, 0 + i * 2, 2));
 }
Exemple #11
0
 // abs(xyzw)
 public bool SourceAbsolute(int i)
 {
     //assert(i >= 0 && i < 4);
     //return (value >> (8 + i * 1)) & 1;
     return(BitUtils.Extract(Value, 8 + i * 1, 1) != 0);
 }
Exemple #12
0
 // abs(xyzw)
 //assert(i >= 0 && i < 4);
 //return (value >> (8 + i * 1)) & 1;
 public bool SourceAbsolute(int i) => BitUtils.Extract(Value, 8 + i * 1, 1) != 0;
Exemple #13
0
        /**
         * Set what to scissor within the current framebuffer
         *
         * Note that scissoring is only performed if the custom scissoring is enabled (GU_SCISSOR_TEST)
         *
         * @param x - Left of scissor region
         * @param y - Top of scissor region
         * @param stopX - Right of scissor region
         * @param stopY - Bottom of scissor region
         **/
        // void sceGuScissor(int x, int y, int stopX, int stopY); // OP_SCISSOR1 + OP_SCISSOR2

        // SCISSOR start (1)
        public void OP_SCISSOR1()
        {
            GpuState->ClipPlaneState.Scissor.Left = BitUtils.Extract(Params24, 0, 10);
            GpuState->ClipPlaneState.Scissor.Top  = BitUtils.Extract(Params24, 10, 10);
        }
Exemple #14
0
 // msk(xyzw)
 public bool DestinationMask(int i)
 {
     //assert(i >= 0 && i < 4);
     //return (value >> (8 + i * 1)) & 1;
     return(BitUtils.Extract(Value, 8 + i * 1, 1) != 0);
 }
Exemple #15
0
 //[GpuOpCodesNotImplemented]
 public void OP_OFFSETY()
 {
     GpuState->Offset.Y = (short)BitUtils.Extract(Params24, 0, 4);
     //gpu.state.offsetY = command.extract!(uint, 0, 4);
 }
Exemple #16
0
 // SCISSOR end (2)
 public void OP_SCISSOR2()
 {
     GpuState->ClipPlaneState.Scissor.Right  = BitUtils.Extract(Params24, 0, 10);
     GpuState->ClipPlaneState.Scissor.Bottom = BitUtils.Extract(Params24, 10, 10);
 }
 public void OP_TEXTURE_ENV_MAP_MATRIX()
 {
     GpuState->TextureMappingState.ShadeU = (short)BitUtils.Extract(Params24, 0, 2);
     GpuState->TextureMappingState.ShadeV = (short)BitUtils.Extract(Params24, 8, 2);
 }
 public static float _vh2f_1(uint a) => HalfFloat.ToFloat((int)BitUtils.Extract(a, 16, 16));
 public static uint _ext_impl(uint data, int pos, int size) => BitUtils.Extract(data, pos, size);
Exemple #20
0
 // msk(xyzw)
 //assert(i >= 0 && i < 4);
 //return (value >> (8 + i * 1)) & 1;
 public bool DestinationMask(int i) => BitUtils.Extract(Value, 8 + i * 1, 1) != 0;
Exemple #21
0
 // neg(xyzw)
 //assert(i >= 0 && i < 4);
 //return (value >> (16 + i * 1)) & 1;
 public bool SourceNegate(int i) => BitUtils.Extract(Value, 16 + i * 1, 1) != 0;
Exemple #22
0
 // cst(xyzw)
 //assert(i >= 0 && i < 4);
 //return (value >> (12 + i * 1)) & 1;
 public bool SourceConstant(int i) => BitUtils.Extract(Value, 12 + i * 1, 1) != 0;
Exemple #23
0
 // neg(xyzw)
 public bool SourceNegate(int i)
 {
     //assert(i >= 0 && i < 4);
     //return (value >> (16 + i * 1)) & 1;
     return(BitUtils.Extract(Value, 16 + i * 1, 1) != 0);
 }
Exemple #24
0
        private void _Patch(PspMemory PspMemory)
        {
            uint Info = this.Code & 0x0FFFFFFF;
            //uint Address = 0x08804000 + Info;
            uint Address = 0x08800000 + Info;

            try
            {
                switch (OpCode)
                {
                // [t]8-bit Constant Write 0x0aaaaaaa 0x000000dd
                case 0x0:
                    PspMemory.WriteSafe(Address, (byte)BitUtils.Extract(Values[0], 0, 8));
                    break;

                // [t]16-bit Constant write 0x1aaaaaaa 0x0000dddd
                case 0x1:
                    PspMemory.WriteSafe(Address, (ushort)BitUtils.Extract(Values[0], 0, 16));
                    break;

                // [t]32-bit Constant write 0x2aaaaaaa 0xdddddddd
                case 0x2:
                    PspMemory.WriteSafe(Address, (uint)BitUtils.Extract(Values[0], 0, 32));
                    break;

                // 32-bit Multi-Address Write/Value increase	0x4aaaaaaa 0xxxxxyyyy 0xdddddddd 0xIIIIIIII
                case 0x4:
                {
                    var Count          = BitUtils.Extract(Values[0], 16, 16);
                    var Increment      = BitUtils.Extract(Values[0], 0, 16);
                    var Value          = BitUtils.Extract(Values[1], 0, 32);
                    var IncrementValue = BitUtils.Extract(Values[2], 0, 32);
                    for (int n = 0; n < Count; n++)
                    {
                        PspMemory.WriteSafe((uint)(Address + n * Increment), (uint)(Value + IncrementValue * n));
                    }
                }
                break;

                case 0x8:
                    // 16-bit Multi-Address Write/Value increas	0x8aaaaaaa 0xxxxxyyyy 0x1000dddd 0xIIIIIIII
                    if (BitUtils.Extract(Values[1], 28, 4) == 1)
                    {
                        var Count          = BitUtils.Extract(Values[0], 16, 16);
                        var Increment      = BitUtils.Extract(Values[0], 0, 16);
                        var Value          = BitUtils.Extract(Values[1], 0, 16);
                        var IncrementValue = BitUtils.Extract(Values[2], 0, 32);
                        for (int n = 0; n < Count; n++)
                        {
                            PspMemory.WriteSafe((uint)(Address + n * Increment),
                                                (ushort)(Value + IncrementValue * n));
                        }
                    }
                    // 8-bit Multi-Address Write/Value increase	0x8aaaaaaa 0xxxxxyyyy 0x000000dd 0xIIIIIIII
                    else
                    {
                        var Count          = BitUtils.Extract(Values[0], 16, 16);
                        var Increment      = BitUtils.Extract(Values[0], 0, 16);
                        var Value          = BitUtils.Extract(Values[1], 0, 8);
                        var IncrementValue = BitUtils.Extract(Values[2], 0, 32);
                        for (int n = 0; n < Count; n++)
                        {
                            PspMemory.WriteSafe((uint)(Address + n * Increment),
                                                (byte)(Value + IncrementValue * n));
                        }
                    }
                    break;

                // 16-bit XOR - 0x7aaaaaaa 0x0005vvvv
                // 8-bit  XOR - 0x7aaaaaaa 0x000400vv
                // 16-bit AND - 0x7aaaaaaa 0x0003vvvv
                // 8-bit  AND - 0x7aaaaaaa 0x000200vv
                // 16-bit OR  - 0x7aaaaaaa 0x0001vvvv
                // 8-bit  OR  - 0x7aaaaaaa 0x000000vv
                case 0x7:
                {
                    uint SubOpCode = (Values[0] >> 16) & 0xFFFF;
                    uint SubValue  = (Values[0] >> 0) & 0xFFFF;
                    switch (SubOpCode)
                    {
                    // 8-bit  OR  - 0x7aaaaaaa 0x000000vv
                    case 0:
                        PspMemory.WriteSafe(Address,
                                            (byte)(PspMemory.ReadSafe <byte>(Address) | (SubValue & 0xFF)));
                        break;

                    default:
                        Console.Error.WriteLine("Invalid CWCheatOpCode: 0x{0:X} : 0x{1:X}", OpCode, SubOpCode);
                        break;
                    }
                }
                break;

                default:
                    Console.Error.WriteLine("Invalid CWCheatOpCode: 0x{0:X}", OpCode);
                    break;
                }
            }
            catch (Exception Exception)
            {
                throw new Exception($"At Address: 0x{Address:X}", Exception);
            }
        }
Exemple #25
0
 // sat(xyzw)
 public uint DestinationSaturation(int i)
 {
     //assert(i >= 0 && i < 4);
     //return (value >> (0 + i * 2)) & 3;
     return(BitUtils.Extract(Value, 0 + i * 2, 2));
 }
 /**
  * Set which color components that the material will receive
  *
  * The components are ORed together from the following values:
  *   - GU_AMBIENT
  *   - GU_DIFFUSE
  *   - GU_SPECULAR
  *
  * @param components - Which components to receive
  **/
 // void sceGuColorMaterial(int components); // OP_CMAT
 // Material Color
 public void OP_CMAT()
 {
     GpuState->LightingState.MaterialColorComponents = (LightComponentsSet)BitUtils.Extract(Params24, 0, 8);
 }
Exemple #27
0
 private uint Get(int offset, int count) => BitUtils.Extract(Value, offset, count);
Exemple #28
0
 // sat(xyzw)
 //assert(i >= 0 && i < 4);
 //return (value >> (0 + i * 2)) & 3;
 public uint DestinationSaturation(int i) => BitUtils.Extract(Value, 0 + i * 2, 2);
Exemple #29
0
 /////////////////////////////////////////////////////////////////////////////////////////////////
 // EXTract/INSert.
 /////////////////////////////////////////////////////////////////////////////////////////////////
 static public uint _ext_impl(uint Data, int Pos, int Size)
 {
     return(BitUtils.Extract(Data, Pos, Size));
 }
Exemple #30
0
 // swz(xyzw)
 //assert(i >= 0 && i < 4);
 //return (value >> (0 + i * 2)) & 3;
 public uint SourceIndex(int i)
 {
     return(BitUtils.Extract(Value, 0 + i * 2, 2));
 }