Esempio n. 1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            tcpc = new TcpClient(txtHost.Text, 9393);
            tcpc.NoDelay = true;
            ns = tcpc.GetStream();

            Message msg = new Message();
            msg.Recv(ns);

            msg.type = MessageType.Message_Ack;
            msg.Send(ns);

            btnConnect.Enabled = false;
            btnConnect.Text = "connected";
            txtHost.ReadOnly = true;

            nds = new NDS(ns);
            nds.BasicTextured3DCnt();

            SendTestList();
            AcquireScreen();
        }
Esempio n. 2
0
        unsafe void AcquireScreen()
        {
            Message msg = new Message();
            msg.type = MessageType.Message_DisplayCapture;
            msg.Send(ns);

            msg.Recv(ns);
            int zipped_size = msg.dispcap_size;
            BinaryReader br = new BinaryReader(ns);
            byte[] zipbuf = new byte[zipped_size];
            for (int i = 0; i < zipped_size; i++)
                zipbuf[i] = br.ReadByte();

            var inf = new ICSharpCode.SharpZipLib.Zip.Compression.Inflater();
            inf.SetInput(zipbuf);
            byte[] bscreen = new byte[256 * 192 * 2];
            inf.Inflate(bscreen);

            var bmp = new Bitmap(256, 192, PixelFormat.Format32bppArgb);
            BitmapData bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, 256, 192), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            byte* bp = (byte*)bmpdata.Scan0.ToPointer();
            for (int i = 0; i < 256 * 192; i++)
            {
                int r = bscreen[i * 2] & 0x1F;
                int g = ((bscreen[i * 2] & 0xE0)>>5) | ((bscreen[i*2+1] & 3)<<3);
                int b = (bscreen[i * 2 + 1] >> 2) & 0x1F;
                int a = bscreen[i * 2 + 1] >> 7;

                //todo - use same color conversion as desmume (whatever that is)
                r <<= 3;
                g <<= 3;
                b <<= 3;

                bp[i * 4 + 0] = (byte)b;
                bp[i * 4 + 1] = (byte)g;
                bp[i * 4 + 2] = (byte)r;
                bp[i * 4 + 3] = 255;
            }
            bmp.UnlockBits(bmpdata);

            if (lastScreen != null) lastScreen.Dispose();
            lastScreen = bmp;
            SetViewport(lastScreen);
        }