Exemplo n.º 1
0
        public void Read()
        {
            var        buffer    = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            const uint frameSize = 4;
            var        ram       = new Ram(buffer, frameSize);
            var        pageSet   = new PageInfo();

            var pcb = new ProcessContextBlock {
                Id = 1
            };

            ram.Allocate(pcb);
            pageSet.Append(ram.Allocate(pcb));
            pageSet.Append(ram.Allocate(pcb));

            var pageStream = new PageStream(ram, pageSet);

            Assert.That(pageStream.Length, Is.EqualTo(8));

            var b = new byte[6];

            pageStream.Read(b, 0, 6);

            Assert.That(pageStream.Position, Is.EqualTo(6));

            Assert.That(b, Is.EquivalentTo(new[] { 5, 6, 7, 8, 9, 10 }));
        }
Exemplo n.º 2
0
        public void Write()
        {
            var        buffer    = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            const uint frameSize = 4;
            var        ram       = new Ram(buffer, frameSize);
            var        pageSet   = new PageInfo();

            var pcb = new ProcessContextBlock {
                Id = 1
            };

            ram.Allocate(pcb);
            pageSet.Append(ram.Allocate(pcb));
            pageSet.Append(ram.Allocate(pcb));

            var pageStream = new PageStream(ram, pageSet);

            Assert.That(pageStream.Length, Is.EqualTo(8));

            var b = new byte[] { 91, 92, 93, 94, };

            pageStream.Position = 2;
            pageStream.Write(b, 0, 4);

            Assert.That(buffer, Is.EquivalentTo(new[] { 1, 2, 3, 4, 5, 6, 91, 92, 93, 94, 11, 12, }));
        }
Exemplo n.º 3
0
        public void Free()
        {
            var ram = new Ram(2, 1);

            var pcb = new ProcessContextBlock {
                Id = 1
            };
            var frame = ram.Allocate(pcb);

            Assert.That(frame, Is.Not.Null);

            frame = ram.Allocate(pcb);
            Assert.That(frame, Is.Not.Null);

            ram.Free(frame);

            frame = ram.Allocate(pcb);
            Assert.That(frame, Is.Not.Null);
        }
Exemplo n.º 4
0
        public void Allocate()
        {
            var ram = new Ram(2, 1);

            var pcb = new ProcessContextBlock {
                Id = 1
            };
            var page = ram.Allocate(pcb);

            Assert.That(page, Is.Not.Null);
            Assert.That(page.PageNumber, Is.Not.EqualTo(0));

            page = ram.Allocate(pcb);
            Assert.That(page, Is.Not.Null);
            Assert.That(page.PageNumber, Is.Not.EqualTo(0));

            page = ram.Allocate(pcb);
            Assert.That(page, Is.Null);
        }
Exemplo n.º 5
0
        public void CreateShared()
        {
            var ram    = new Ram(1024, 256);
            var offset = ram.AllocateShared(512);

            Assert.That(offset, Is.EqualTo(0));

            var pcb = new ProcessContextBlock {
                Id = 10
            };
            var p1 = ram.Allocate(pcb);
            var p2 = ram.Allocate(pcb);

            var p1Offset = ram.ToPhysicalAddress(10, p1.VirtualAddress);
            var p2Offset = ram.ToPhysicalAddress(10, p2.VirtualAddress);

            Assert.That(p1Offset, Is.GreaterThan(offset));
            Assert.That(p2Offset, Is.GreaterThan(offset));
            Assert.That(p2Offset, Is.GreaterThan(p1Offset));
        }
        //TODO: this doesn't have to be aligned to a page, so allow scenes to use this directly with their ram refs
        public void Setup(U16 pageStart, U8 length)
        {
            _done = VByte.New(Ram, $"{nameof(VRamQueue)}{nameof(_done)}");
            _executeLoopContinue = Labels.New();
            _executeLoopBreak    = Labels.New();

            var VRAM = Ram.Allocate(Addr(pageStart), Addr((U16)(pageStart + 0xFF)), "VRAM");

            _ops = new List <VRamQueueOp>();
            _ops.Add(new NOP());
            _opHandlers = new List <Label>();
            _liveQueue  = LiveQueue.New(Zp, Ram, VRAM, length, $"{nameof(VRamQueue)}{nameof(_liveQueue)}", Op <Stop>()?.Id ?? 255);
        }
Exemplo n.º 7
0
        //TODO: this doesn't have to be aligned to a page, so allow scenes to use this directly with their ram refs
        public void SetupAligned(U16 pageStart, U8 length, params Option[] options)
        {
            _done = VByte.New(Ram, $"{nameof(VRamQueue)}{nameof(_done)}");
            //_handlerAddress = VWord.New(ram, "VRamQueue_handlerAddress");
            _executeLoopContinue = Labels.New();
            _executeLoopBreak    = Labels.New();

            var VRAM = Ram.Allocate(Addr(pageStart), Addr((U16)(pageStart + 0xFF)), "VRAM");

            _liveQueue = LiveQueue.New(Zp, Ram, VRAM, length, $"{nameof(VRamQueue)}{nameof(_liveQueue)}", Op.Stop);

            _options = options ?? Array.Empty <Option>();

            OptionModules();
        }