Esempio n. 1
0
        public void Transfer(Dma.Direction direction, int size, DmaEnum address, ref uint value)
        {
            switch (address)
            {
            case DmaEnum.KIRK_PATTERN:
                value = 1;
                break;

            case DmaEnum.KIRK_COMMAND:
                TransferUtils.Transfer(direction, ref _kirkCommand, ref value);
                break;

            case DmaEnum.KIRK_RESULT:
                TransferUtils.Transfer(direction, ref _kirkResult, ref value);
                break;

            case DmaEnum.KIRK_SOURCE_ADDRESS:
                TransferUtils.Transfer(direction, ref _kirkSource, ref value);
                break;

            case DmaEnum.KIRK_DESTINATION_ADDRESS:
                TransferUtils.Transfer(direction, ref _kirkDestination, ref value);
                break;

            case DmaEnum.KIRK_START:
                if (_kirkCommand != 1)
                {
                    throw new NotImplementedException();
                }

                var sourcePtr      = (byte *)Memory.PspAddressToPointerSafe(_kirkSource);
                var destinationPtr = (byte *)Memory.PspAddressToPointerSafe(_kirkDestination);

                //var Out = new byte[10000];

                //fixed (byte* OutPtr = Out)
                {
                    //DestinationPtr = OutPtr;
                    Console.WriteLine("Input:");
                    ArrayUtils.HexDump(PointerUtils.PointerToByteArray(sourcePtr, 0x200));

                    /*
                     * try
                     * {
                     *  Kirk.kirk_CMD1(DestinationPtr, SourcePtr, -1, true);
                     *  this.KirkResult = (uint)Kirk.ResultEnum.OK;
                     * }
                     * catch (Kirk.KirkException KirkException)
                     * {
                     *  this.KirkResult = (uint)KirkException.Result;
                     *  Console.Error.WriteLine("Kirk.KirkException : {0}", KirkException);
                     * }
                     */

                    this._kirkResult = (uint)Kirk.SceUtilsBufferCopyWithRange(destinationPtr, -1, sourcePtr, -1, 1);

                    Console.WriteLine("Output:");
                    ArrayUtils.HexDump(PointerUtils.PointerToByteArray(destinationPtr, 0x200));
                    Console.WriteLine("LOADADDR:{0:X8}", ((uint *)destinationPtr)[0]);
                    Console.WriteLine("BLOCKSIZE:{0:X8}", ((uint *)destinationPtr)[1]);
                    Console.WriteLine("ENTRY:{0:X8}", ((uint *)destinationPtr)[2]);
                    Console.WriteLine("CHECKSUM:{0:X8}", ((uint *)destinationPtr)[3]);
                }

                //Thread.Sleep(4);
                break;
            }
        }
Esempio n. 2
0
        public void Transfer(Dma.Direction direction, int size, DmaEnum address, ref uint value)
        {
            // Reading sector
            if (address >= DmaEnum.NAND__DATA_PAGE_START && address < DmaEnum.NAND__DATA_PAGE_END)
            {
                var offset = (int)(address - DmaEnum.NAND__DATA_PAGE_START);
                //Console.WriteLine("{0:X8}", (uint)Address);
                //Console.WriteLine("Transfer {0} / {1} [{2}]", Offset, Size, NandBlock.Length);
                TransferUtils.TransferToArray(direction, NandBlock, offset, size, ref value);
                return;
            }

            if (address >= DmaEnum.NAND__DATA_SPARE_BUF0_REG && address < DmaEnum.NAND__DATA_EXTRA_END)
            {
                var offset = (int)(address - DmaEnum.NAND__DATA_SPARE_BUF0_REG);
                TransferUtils.TransferToArray(direction, NandBlock, 512 + offset + 4, size, ref value);
                return;
            }

            switch (address)
            {
            case DmaEnum.NAND__CONTROL:
                TransferUtils.Transfer(direction, ref _controlRegister, ref value);
                break;

            case DmaEnum.NAND__STATUS:
                TransferUtils.Transfer(direction, ref _status, ref value);
                //Thread.Sleep(200);
                break;

            case DmaEnum.NAND__COMMAND:
                TransferUtils.Transfer(direction, ref _command, ref value);

                // Reset
                if (direction == Dma.Direction.Write)
                {
                    switch ((EnumCommands)value)
                    {
                    case EnumCommands.Reset:
                        _status = EnumStatus.Ready;
                        break;
                    }
                }
                break;

            case DmaEnum.NAND__ADDRESS:
                TransferUtils.Transfer(direction, ref address, ref value);
                break;

            case DmaEnum.NAND__RESET:
                if (direction == Dma.Direction.Write)
                {
                    Reset();
                }
                break;

            case DmaEnum.NAND__DMA_ADDRESS:
                TransferUtils.Transfer(direction, ref _dmaAddress, ref value);
                break;

            case DmaEnum.NAND__DMA_CONTROL:
                if (direction == Dma.Direction.Write)
                {
                    if (value == 0x301)
                    {
                        //0x20000/2/512*(512+16)
                        NandStream.Position = _dmaAddress / 2 / 512 * (512 + 16);
                        NandBlock           = NandStream.ReadBytes(512 + 16);
                        Console.WriteLine("Read from NAND: 0x{0:X8}", _dmaAddress);
                        ArrayUtils.HexDump(NandBlock);

                        //Thread.Sleep(TimeSpan.FromSeconds(0.5));
                        //Thread.Sleep(-1);
                    }
                }
                else
                {
                    value = 0;
                }
                break;

            case DmaEnum.NAND__DMA_ERROR:
                value = 0;
                break;
            }
        }