コード例 #1
0
            public byte[] GetBuffer()
            {
                if (this.availableCells > 0)
                {
                    MemoryCell retCell = null;

                    lock (this.cellsListLock)
                    {
                        if (this.availableCells > 0)
                        {
                            if (null != this.cellsListHeadCell)
                            {
                                retCell = this.cellsListHeadCell;
                                this.cellsListHeadCell = retCell.NextCell;
                                retCell.NextCell       = null;
                            }
                            else
                            {
                                retCell = new MemoryCell(this.BufferSize);
                                ++this.allocatedCells;
                            }

                            --this.availableCells;
                        }
                    }

                    if (null != retCell)
                    {
                        this.cellsInUse.TryAdd(retCell.Buffer, retCell);
                        return(retCell.Buffer);
                    }
                }

                return(null);
            }
コード例 #2
0
            public byte[] GetBuffer()
            {
                if (this.availableCells > 0)
                {
                    MemoryCell retCell = null;

                    lock (this.cellsListLock)
                    {
                        if (this.availableCells > 0)
                        {
                            if (null != this.cellsListHeadCell)
                            {
                                retCell = this.cellsListHeadCell;
                                this.cellsListHeadCell = retCell.NextCell;
                                retCell.NextCell = null;
                            }
                            else
                            {
                                retCell = new MemoryCell(this.BufferSize);
                                ++this.allocatedCells;
                            }

                            --this.availableCells;
                        }
                    }

                    if (null != retCell)
                    {
                        this.cellsInUse.TryAdd(retCell.Buffer, retCell);
                        return retCell.Buffer;
                    }
                }

                return null;
            }
コード例 #3
0
            public void AddBuffers(byte[][] buffers)
            {
                if (null == buffers)
                {
                    throw new ArgumentNullException("buffers");
                }

                if (buffers.Length == 1)
                {
                    this.AddBuffer(buffers[0]);
                    return;
                }

                foreach (var buffer in buffers)
                {
                    MemoryCell cell;
                    if (this.cellsInUse.TryRemove(buffer, out cell))
                    {
                        lock (this.cellsListLock)
                        {
                            cell.NextCell          = this.cellsListHeadCell;
                            this.cellsListHeadCell = cell;
                            ++this.availableCells;
                        }
                    }
                }
            }
コード例 #4
0
        public bool Init(Context.SEAContext.DoHandler doCallback)
        {
            try
            {
                var    key        = new StringBuilder(32, 32);
                var    textWriter = MyAPIGateway.Utilities.WriteFileInGlobalStorage(SEAUtilities.KEY_FILE_NAME);
                Random r          = new Random();
                memoryCells = new MemoryCell[THREAD_COUNT];

                var i = 0;
                while (i < THREAD_COUNT)
                {
                    memoryCells[i++] = new MemoryCell(r, doCallback, ref key);
                    textWriter.WriteLine(key.ToString());
                    key.Clear();
                }
                textWriter.Flush();
                textWriter.Close();
                textWriter.Dispose();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #5
0
    public static void Main(string[] args)
    {
        MemoryCell m = new MemoryCell( );

        m.Write("57");
        string val = (string)m.Read( );

        Console.WriteLine("Contents are: " + val);
    }
コード例 #6
0
            public MemoryPool(int cellsCount, int bufferSize)
            {
                this.BufferSize = bufferSize;

                this.availableCells    = cellsCount;
                this.allocatedCells    = 0;
                this.cellsListLock     = new object();
                this.cellsListHeadCell = null;
                this.cellsInUse        = new ConcurrentDictionary <byte[], MemoryCell>();
            }
コード例 #7
0
            public MemoryPool(int cellsCount, int bufferSize)
            {
                this.BufferSize = bufferSize;

                this.availableCells = cellsCount;
                this.allocatedCells = 0;
                this.cellsListLock = new object();
                this.cellsListHeadCell = null;
                this.cellsInUse = new ConcurrentDictionary<byte[], MemoryCell>();
            }
コード例 #8
0
ファイル: GameBoy.cs プロジェクト: Antiox/SharpBoyEmulator
        public IMemoryCell[] GetMemoryCells(int startIndex, int endIndex)
        {
            var cells = new IMemoryCell[endIndex - startIndex + 1];

            for (int i = startIndex; i <= endIndex; i++)
            {
                cells[i - startIndex] = new MemoryCell(i, Memory.ReadByte((ushort)i));
            }

            return(cells);
        }
コード例 #9
0
     /// <summary>
     /// Construct a new MemoryBlock.
     /// </summary>
     /// <param name="memorySize">The size of the MemoryBlock to instantiate.</param>
     /// <param name="fillValue">Default cell initialization / fill value.</param>
     public MemoryBlock(int memorySize, byte fillValue = 0xff)
     {
         Cells = new MemoryCell[memorySize];
         for (var i = 0; i < memorySize; i++)
         {
             Cells[i] = new MemoryCell(i)
             {
                 Value = fillValue
             }
         }
         ;
     }
 }
コード例 #10
0
     /// <summary>
     /// Construct a new MemoryBlock.
     /// </summary>
     /// <param name="memorySize">The size of the MemoryBlock to instantiate.</param>
     /// <param name="fillValue">Default cell initialization / fill value.</param>
     public MemoryBlock(int memorySize, byte fillValue = 0xff, int startAddress = 0)
     {
         Cells = new MemoryCell[memorySize];
         for (var i = 0; i < memorySize; i++)
         {
             Cells[i] = new MemoryCell(startAddress + i)
             {
                 Value = fillValue
             }
         }
         ;
     }
 }
コード例 #11
0
            public void AddBuffer(byte[] buffer)
            {
                if (null == buffer)
                {
                    throw new ArgumentNullException("buffer");
                }

                MemoryCell cell;

                if (this.cellsInUse.TryRemove(buffer, out cell))
                {
                    lock (this.cellsListLock)
                    {
                        cell.NextCell          = this.cellsListHeadCell;
                        this.cellsListHeadCell = cell;
                        ++this.availableCells;
                    }
                }
            }
コード例 #12
0
            public byte[][] GetBuffers(int count)
            {
                if (this.availableCells >= count)
                {
                    List <MemoryCell> retCells = null;

                    lock (this.cellsListLock)
                    {
                        if (this.availableCells >= count)
                        {
                            retCells = new List <MemoryCell>();

                            for (int i = 0; i < count; i++)
                            {
                                MemoryCell retCell;
                                if (null != this.cellsListHeadCell)
                                {
                                    retCell = this.cellsListHeadCell;
                                    this.cellsListHeadCell = retCell.NextCell;
                                    retCell.NextCell       = null;
                                }
                                else
                                {
                                    retCell = new MemoryCell(this.BufferSize);
                                    ++this.allocatedCells;
                                }

                                --this.availableCells;

                                this.cellsInUse.TryAdd(retCell.Buffer, retCell);
                                retCells.Add(retCell);
                            }
                        }
                    }

                    if (null != retCells)
                    {
                        return(retCells.Select(c => c.Buffer).ToArray());
                    }
                }

                return(null);
            }
コード例 #13
0
ファイル: Form_Debug.cs プロジェクト: cbmeeks/Ultimate64
        public Form_Debug()
        {
            InitializeComponent();
            tbIPAddress.Text = cfg.Hostname;

            SetupGrid();

            SetTimers();

            Thread t = new Thread(new ThreadStart(UDPListener));

            t.Priority = ThreadPriority.Highest;
            t.Start();

            for (int a = 0; a < memory.Length; a++)
            {
                memory[a]         = new MemoryCell();
                memory[a].address = (UInt16)a;
            }
        }
コード例 #14
0
        public void LastIndexOfMemoryCellArrayReturnsCorrectIndexWhenFound()
        {
            var cell1 = new MemoryCell(0x00)
            {
                Value = 0xF0
            };
            var cell2 = new MemoryCell(0x01)
            {
                Value = 0xB0
            };
            var cell3 = new MemoryCell(0x02)
            {
                Value = 0xF0
            };
            var cell4 = new MemoryCell(0x03)
            {
                Value = 0xB0
            };
            var cell5 = new MemoryCell(0x04)
            {
                Value = 0xF0
            };
            var cell6 = new MemoryCell(0x05)
            {
                Value = 0xF0
            };
            var cell7 = new MemoryCell(0x06)
            {
                Value = 0xAA
            };

            var cells = new[] { cell1, cell2, cell3, cell4, cell5, cell6, cell7 };

            cells.LastIndexOf(cell => cell.Value == 0xB0).Should().Be(3);
            cells.LastIndexOf(cell => cell.Value == 0xAA).Should().Be(6);
            cells.LastIndexOf(cell => cell.Value == 0xF0).Should().Be(5);
            cells.LastIndexOf(cell => cell.Value == 0xFF).Should().Be(-1); // Not found
        }
コード例 #15
0
        public static Blueprint Generate(VideoMemoryConfiguration configuration, List <bool[, ]> frames = null)
        {
            var width       = configuration.Width ?? 32;
            var height      = configuration.Height ?? 2;
            var baseAddress = configuration.BaseAddress ?? 1;

            var frameHeight = frames?.ElementAtOrDefault(0)?.GetLength(0) ?? 0;

            const int framesPerRow = 32;
            const int maxFilters   = 20;

            var entities   = new List <Entity>();
            var memoryRows = new MemoryRow[height];

            var metadata = new Entity
            {
                Name     = ItemNames.ConstantCombinator,
                Position = new Position
                {
                    X = 2,
                    Y = 0
                },
                Direction        = Direction.Down,
                Control_behavior = new ControlBehavior
                {
                    Filters = new List <Filter>
                    {
                        Filter.Create(VirtualSignalNames.LetterOrDigit('Z'), frames?.Count ?? 0)
                    }
                }
            };

            entities.Add(metadata);

            for (var row = 0; row < height; row++)
            {
                var cellY     = row * 9 - (row % 2 == 1 ? 1 : 0) + 2;
                var rowFrames = frames?.Skip(row * framesPerRow).Take(framesPerRow).ToList();

                var addressMatcher = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = 1,
                        Y = cellY + 0.5
                    },
                    Direction        = Direction.Down,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Info),
                            Constant              = row + baseAddress,
                            Comparator            = Comparators.IsNotEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Check),
                            Copy_count_from_input = false
                        }
                    }
                };
                entities.Add(addressMatcher);

                var memoryCells = new MemoryCell[width];

                for (var column = 0; column < width; column++)
                {
                    var cellX = column + 2;

                    var enabler = new Entity
                    {
                        Name     = ItemNames.DeciderCombinator,
                        Position = new Position
                        {
                            X = cellX,
                            Y = cellY + 0.5
                        },
                        Direction        = Direction.Up,
                        Control_behavior = new ControlBehavior
                        {
                            Decider_conditions = new DeciderConditions
                            {
                                First_signal          = SignalID.Create(VirtualSignalNames.Check),
                                Constant              = 0,
                                Comparator            = Comparators.IsEqual,
                                Output_signal         = SignalID.Create(VirtualSignalNames.Everything),
                                Copy_count_from_input = true
                            }
                        }
                    };
                    entities.Add(enabler);

                    var pixelFilters = Enumerable.Range(0, frameHeight)
                                       .Select(frameRow =>
                    {
                        var pixel = rowFrames
                                    .Select((frame, frameOffset) => frame[frameRow, column] ? 1 << frameOffset : 0)
                                    .Sum();

                        return(Filter.Create(ScreenUtil.PixelSignals[frameRow], pixel));
                    })
                                       .Where(pixelFilter => pixelFilter.Count != 0)
                                       .ToList();

                    var subCellCount = column % 18 >= 16 ? 6 : 7;
                    var subCells     = new Entity[subCellCount];

                    for (var subCellIndex = 0; subCellIndex < subCellCount; subCellIndex++)
                    {
                        var subCell = new Entity
                        {
                            Name     = ItemNames.ConstantCombinator,
                            Position = new Position
                            {
                                X = cellX,
                                Y = subCellIndex < 6 || row % 2 == 1 ? cellY + subCellIndex + 2 : cellY - 1
                            },
                            Direction        = Direction.Down,
                            Control_behavior = new ControlBehavior
                            {
                                Filters = pixelFilters.Skip(subCellIndex * maxFilters).Take(maxFilters).ToList()
                            }
                        };
                        entities.Add(subCell);
                        subCells[subCellIndex] = subCell;
                    }

                    memoryCells[column] = new MemoryCell
                    {
                        Enabler  = enabler,
                        SubCells = subCells
                    };
                }

                memoryRows[row] = new MemoryRow
                {
                    AddressMatcher = addressMatcher,
                    Cells          = memoryCells
                };
            }

            BlueprintUtil.PopulateEntityNumbers(entities);

            var substationWidth  = (width + 9) / 18 + 1;
            var substationHeight = height / 2 + 1;

            entities.AddRange(CreateSubstations(substationWidth, substationHeight, 0, 0, entities.Count + 1));

            for (var row = 0; row < height; row++)
            {
                var memoryRow = memoryRows[row];

                AddConnection(CircuitColor.Red, memoryRow.AddressMatcher, CircuitId.Output, memoryRow.Cells[0].Enabler, CircuitId.Input);

                var adjacentRow = row - 1;
                if (adjacentRow >= 0)
                {
                    var adjacentMemoryRow = memoryRows[adjacentRow];

                    AddConnection(CircuitColor.Green, memoryRow.AddressMatcher, CircuitId.Input, adjacentMemoryRow.AddressMatcher, CircuitId.Input);

                    for (var column = 0; column < width; column++)
                    {
                        var memoryCell         = memoryRow.Cells[column];
                        var adjacentMemoryCell = adjacentMemoryRow.Cells[column];

                        AddConnection(CircuitColor.Green, memoryCell.Enabler, CircuitId.Output, adjacentMemoryCell.Enabler, CircuitId.Output);
                    }
                }

                for (var column = 0; column < width; column++)
                {
                    var memoryCell = memoryRow.Cells[column];

                    AddConnection(CircuitColor.Green, memoryCell.SubCells[0], null, memoryCell.Enabler, CircuitId.Input);

                    for (var subCellIndex = 1; subCellIndex < memoryCell.SubCells.Length; subCellIndex++)
                    {
                        var subCell         = memoryCell.SubCells[subCellIndex];
                        var adjacentSubCell = memoryCell.SubCells[subCellIndex < 6 || row % 2 == 1 ? subCellIndex - 1 : 0];

                        AddConnection(CircuitColor.Green, subCell, null, adjacentSubCell, null);
                    }

                    var adjacentColumn = column - 1;
                    if (adjacentColumn >= 0)
                    {
                        var adjacentMemoryCell = memoryRow.Cells[adjacentColumn];

                        AddConnection(CircuitColor.Red, memoryCell.Enabler, CircuitId.Input, adjacentMemoryCell.Enabler, CircuitId.Input);
                    }
                }
            }

            return(new Blueprint
            {
                Label = $"Video ROM",
                Icons = new List <Icon>
                {
                    Icon.Create(ItemNames.Lamp),
                    Icon.Create(ItemNames.ConstantCombinator)
                },
                Entities = entities,
                Item = ItemNames.Blueprint,
                Version = BlueprintVersions.CurrentVersion
            });
        }
コード例 #16
0
            public void AddBuffer(byte[] buffer)
            {
                if (null == buffer)
                {
                    throw new ArgumentNullException("buffer");
                }

                MemoryCell cell;
                if (this.cellsInUse.TryRemove(buffer, out cell))
                {
                    lock (this.cellsListLock)
                    {
                        cell.NextCell = this.cellsListHeadCell;
                        this.cellsListHeadCell = cell;
                        ++this.availableCells;
                    }
                }
            }