Ejemplo n.º 1
0
 public static void Init()
 {
     //Copy funcs to those RAM chunks
     Y.Set(0);
     Loop.Do_old(_ => {
         AddrWriteVerify[Y].Set(A.Set(LabelFor(_WriteVerify)[Y]));
         Y.Increment();
         CPU6502.CPY(_lenTotalRamLength);
     }).While(() => Y.NotEquals(0));
 }
 private void Handler()
 {
     _liveQueue.Unsafe_Pop(Y);
     X.Set(_liveQueue.Unsafe_Peek(Y));             //Number of bytes of data
     Loop.Do_old(_ => {
         _liveQueue.Unsafe_Pop(Y);
         NES.PPU.Data.Set(_liveQueue.Unsafe_Peek(Y));
         X.Dec();
     }).While(() => X.NotEquals(0));
     GoTo(_executeLoopContinue);
 }
Ejemplo n.º 3
0
        private static void _WriteVerify()
        {
            Loop.Do_old(_ => {
                A.Set(TargetAddress[Y]).CMP(TargetAddress[Y]);
                //TODO: verify, there should probably be some Y inc/dec in here
            }).While(() => A.NotEquals(0));
            Return();

            //If(() => A.Set(TargetAddress[Y]).Equals(TargetAddress[Y]), () => {
            //	Return();
            //});
            //Use(Label["EraseSector"]);
        }
Ejemplo n.º 4
0
        public void Reset()
        {
            NES.IRQ.Disable();
            CPU6502.CLD();
            NES.APU.FrameCounter.Set(0x40);
            Stack.Reset();
            NES.PPU.Control.Set(0);
            NES.PPU.Mask.Set(0);
            NES.APU.DMC.Disable();
            //NES.APU.SetChannelsEnabled(NES.APU.Channels.DMC | NES.APU.Channels.Pulse1);

            Hardware.WaitForVBlank();
            Hardware.ClearRAM();
            Hardware.WaitForVBlank();

            ////TODO: move this to title, along with datasection
            //Comment("Load palettes");
            //Hardware.LoadPalettes(Palettes);

            Module <SceneManager>().Load(Module <Scenes.Title>());
            Hardware.WaitForVBlank();
            NES.PPU.Control.Set(NES.PPU.LazyControl);
            NES.PPU.Mask.Set(NES.PPU.LazyMask);
            ScrollUtil.Update();
            Loop.Infinite(_ => {
                Comment("Main Loop");

                Module <Gamepads>().Update();

                Module <SceneManager>().Step();

                A.Set(nmiCount);
                Loop.Do_old().While(() => nmiCount.Equals(A));

                Module <SceneManager>().CheckLoadNeeded();

                //Set shadow OAM address
                NES.PPU.OAM.Address.Set(0x00);                  //low byte of RAM address
                NES.PPU.OAM.DMA.Set(0x02);                      //high byte of RAM address
            });
        }
Ejemplo n.º 5
0
        public static void ChrCopy()
        {
            Comment("Copy a chunk to CHR (<=255 bytes)");

            NES.PPU.Address.Write(Y, (U8)0); //Hi then Lo
            Y.Set(0);                        //starting index into the first page

            //Ptr p = Globals.graphicsPtr;
            //p.Bytes[1]++;

            Loop.Do_old(_ => {
                Loop.Do_old(_ => {
                    NES.PPU.Data.Write(GraphicsPtr[Y]);
                    Y.Increment();
                    //TODO: more here
                }).While(() => Y.NotEquals(0));
                //GraphicsPtr.Address[1]++;
                GraphicsPtr.Hi.Inc();
                X.Dec();
                //TODO: more here
            }).While(() => X.NotEquals(0));
        }
Ejemplo n.º 6
0
        public static RegisterA GetTVSystem(VByte nmis)
        {
            X.Set(0);
            Y.Set(0);
            A.Set(nmis);
            Loop.Do_old().While(() => A.Equals(nmis));
            A.Set(nmis);

            Loop.Do_old(_ => {
                //Each iteration takes 11 cycles.
                //NTSC NES:	29780 cycles or 2707 = $A93 iterations
                //PAL NES:	33247 cycles or 3022 = $BCE iterations
                //Dendy:	35464 cycles or 3224 = $C98 iterations
                //so we can divide by $100 (rounding down), subtract ten,
                //and end up with 0=ntsc, 1=pal, 2=dendy, 3=unknown
                X.Inc();
                If.True(() => X.Equals(0), () => Y.Increment());
            }).While(() => A.Equals(nmis));

            If.True(() => A.Set(Y).Subtract(10).GreaterThanOrEqualTo(3), () => A.Set(3));
            return(A);
        }
Ejemplo n.º 7
0
 public static void WaitForVBlank()
 {
     Loop.Do_old(_ => {
         CPU6502.BIT(NES.PPU.Status);
     }).While(() => Condition.IsPositive);
 }
Ejemplo n.º 8
0
        public override void Step()
        {
            If.Block(c => c
                     .True(_gamepad.IsHeld(NES.Button.Right), () => _charX.Set(z => z.Add(_MoveDist)))
                     .True(_gamepad.IsHeld(NES.Button.Left), () => _charX.Set(z => z.Subtract(_MoveDist)))
                     );
            If.Block(c => c
                     .True(_gamepad.IsHeld(NES.Button.Down), () => _charY.Set(z => z.Add(_MoveDist)))
                     .True(_gamepad.IsHeld(NES.Button.Up), () => _charY.Set(z => z.Subtract(_MoveDist)))
                     );
            If.Block(c => c
                     .True(_gamepad.WasPressed(NES.Button.B), () => {
                _skipOptionIndex.Dec();
                If.True(() => _skipOptionIndex.Equals(255), () => _skipOptionIndex.Set(0));                             //low limit
                GoSub(DrawSkipNum);
            })
                     .True(_gamepad.WasPressed(NES.Button.A), () => {
                _skipOptionIndex.Inc();
                If.True(() => _skipOptionIndex.Equals(_skipOptions.Length), () => _skipOptionIndex.Set(_skipOptions.Length - 1));                               //high limit
                GoSub(DrawSkipNum);
            })
                     );
            Y.Set(0);
            If.True(_gamepad.WasPressed(NES.Button.Select), () => {
                _pattern.Inc();
                If.True(() => _pattern.Equals(3), () => _pattern.Set(0));
            });
            If.True(_gamepad.WasPressed(NES.Button.Start), () => Module <SceneManager>().Queue(Module <Title>()));

            var jx = Temp[1];
            var jy = Temp[2];

            jx.Set(_charX.Subtract(8));
            jy.Set(_charY.Subtract(8));

            NES.PPU.OAM.Object[0].SetPosition(jx, jy);
            NES.PPU.OAM.Object[1].SetPosition(_charX, jy);
            NES.PPU.OAM.Object[2].SetPosition(jx, _charY);
            NES.PPU.OAM.Object[3].SetPosition(_charX, _charY);

            U8 startOffset = 4;

            If.Block(c => c
                     .True(() => _pattern.Equals(0), () => {
                Comment("Single row pattern");
                jx.Set(0x04);
                jy.Set(0x40);

                _processed.Set(0);
                Y.Set(startOffset);

                Loop.Do_old(_ => {
                    var spriteObj = NES.PPU.OAM.Object[Y];
                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_JunkTile);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(jx, jy);
                    Skipterate_Next();

                    jx.Set(z => z.Add(4));
                    _processed.Inc();
                }).While(() => A.Set(_processed).NotEquals(60));
            })
                     .True(() => _pattern.Equals(1), () => {
                Comment("Four rows pattern");
                U8 xStart = 0x30;
                jx.Set(xStart);
                jy.Set(0x30);

                _processed.Set(0);
                Y.Set(startOffset);

                Loop.Do_old(_ => {
                    var spriteObj = NES.PPU.OAM.Object[Y];
                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_JunkTile);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(jx, jy);
                    Skipterate_Next();

                    jx.Set(z => z.Add(8));

                    If.Any(() => _processed.Equals(19), () => _processed.Equals(39)).Then(() => {
                        jy.Set(jy.Add(8));
                        jx.Set(xStart);
                    });
                    _processed.Inc();
                }).While(() => A.Set(_processed).NotEquals(60));
            })
                     .Else(() => {
                Comment("Moving scattered objects pattern");
                Y.Set(startOffset);

                Loop.ForEach(X, _scatterSprites, (face, _) => {
                    var spriteObj = NES.PPU.OAM.Object[Y];
                    jx.Set(face.PosX.Add(8));
                    jy.Set(face.PosY.Add(8));

                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_NPCTile0);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(face.PosX, face.PosY);
                    Skipterate_Next();

                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_NPCTile1);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(jx, face.PosY);
                    Skipterate_Next();

                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_NPCTile2);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(face.PosX, jy);
                    Skipterate_Next();

                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_NPCTile3);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(jx, jy);
                    Skipterate_Next();

                    face.Move();
                });
            })
                     );
            Skipterate_Next();
        }