Ejemplo n.º 1
0
        public static byte[] GetReply(byte[] data)
        {
            // We don't care about these kind of packages, need to improve in case comes with lot of delay etc.
            if (data.Length <= 3)
            {
                return(new byte[0]);
            }
            Debug.WriteLine("Package: " + JvsHelper.ByteArrayToString(data));
            if (data.Length > 1 && data[1] != 0xFF)
            {
                if (!DualJvsEmulation)
                {
                    if (data[1] > 0x01)
                    {
                        return(new byte[0]);
                    }
                }
                else
                {
                    if (data[1] > 0x02)
                    {
                        return(new byte[0]);
                    }
                }
            }

            // Weird request to Type X
            if (data[0] == 0xE0 && data[1] == 0x00 && data[2] == 0x04 && data[3] == 0x01 && data[4] == 0x01 &&
                data[5] == 0x08 && data[6] == 0x0E)
            {
                counta++;
                if (counta == 0 && counta == 1 && counta == 2 && counta == 3)
                {
                    return(JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { 0x01 }));
                }
                else
                {
                    return(JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { 0x00 }));
                }
            }

            switch (data[3])
            {
            // E0FF03F0D9CB
            case (byte)JVSPacket.OP_RESET:
            {
                JvsHelper.StateView?.Write(0, 0);
                return(new byte[0]);
            }

            default:
            {
                var reply = JvsHelper.CraftJvsPackageWithStatusAndReport(0, AdnvacedJvs(data));
                Debug.WriteLine("Reply: " + JvsHelper.ByteArrayToString(reply));
                return(reply);
            }
            }
        }
        /// <summary>
        /// THIS CODE IS BEYOND RETARTED AND FOR HACKY TESTS ONLY!!!
        /// For proper JVS handling: must code proper detection of packages, multiple requests in one package and proper responses!
        /// Now we just know what SEGA asks and return back like bunch of monkey boys.
        /// Feel free to improve.
        /// </summary>
        /// <param name="data">Input data from the com port.</param>
        /// <returns>"proper" response.</returns>
        public static byte[] GetReply(byte[] data)
        {
            // We don't care about these kind of packages, need to improve in case comes with lot of delay etc.
            if (data.Length <= 3)
            {
                return(new byte[0]);
            }
            Debug.WriteLine("Package: " + JvsHelper.ByteArrayToString(data));
            if (data.Length > 1 && data[1] != 0xFF)
            {
                if (!EnableDualJvsEmulation)
                {
                    if (data[1] > 0x01)
                    {
                        return(new byte[0]);
                    }
                }
                else
                {
                    if (data[1] > 0x02)
                    {
                        return(new byte[0]);
                    }
                }
            }

            switch (data[3])
            {
            // E0FF03F0D9CB
            case JvsHelper.JVS_OP_RESET:
            {
                JvsHelper.StateView?.Write(0, 0);
                return(new byte[0]);
            }

            default:
            {
                var reply = JvsHelper.CraftJvsPackageWithStatusAndReport(0, AdnvacedJvs(data));
                Debug.WriteLine("Reply: " + JvsHelper.ByteArrayToString(reply));
                return(reply);
            }
            }
        }
        private static byte[] AdnvacedJvs(byte[] data)
        {
            // Disect package (take out unwanted data)
            var byteLst      = new List <byte>();
            var multiPackage = false;
            var replyBytes   = new List <byte>();
            var packageSize  = data[2] - 1; // Reduce CRC as we don't need that

            for (int i = 0; i < data.Length; i++)
            {
                if (i == 0 || i == 1 || i == 2 || i == data.Length - 1)
                {
                    continue;
                }
                byteLst.Add(data[i]);
            }
            for (var i = 0; i < packageSize;)
            {
                var reply = ParsePackage(byteLst.ToArray(), multiPackage, data[1]);
                if (!EnableNamco)
                {
                    if (reply.Error)
                    {
                        Console.WriteLine($"Error full package: {JvsHelper.ByteArrayToString(data)}");
                        return(null);
                    }
                }
                for (int x = 0; x < reply.LengthReduction; x++)
                {
                    if (byteLst.Count != 0)
                    {
                        byteLst.RemoveAt(0);
                    }
                }
                i += reply.LengthReduction;
                replyBytes.AddRange(reply.Bytes);
                multiPackage = true;
            }
            _lastPackage = replyBytes.ToArray();
            return(replyBytes.ToArray());
        }
Ejemplo n.º 4
0
        private static JvsReply JvsGetAddress(byte[] bytesLeft, JvsReply reply)
        {
            if (!DualJvsEmulation)
            {
                JvsHelper.StateView?.Write(0, 1);
            }
            else
            {
                if (bytesLeft[1] == 0x02)
                {
                    JvsHelper.StateView?.Write(0, 1);
                }
            }

            if (bytesLeft[1] == 0x01 || bytesLeft[1] == 0x02)
            {
                reply.Bytes           = new byte[] { };
                reply.LengthReduction = 2;
                return(reply);
            }

            Debug.WriteLine($"Unsupported JVS_OP_ADDRESS package, contact Reaver! Package: {JvsHelper.ByteArrayToString(bytesLeft)}");
            throw new NotSupportedException();
        }
Ejemplo n.º 5
0
        public static JvsReply ParsePackage(byte[] bytesLeft, bool multiPackage, byte node)
        {
            JvsReply reply = new JvsReply();

            // We take first byte of the package
            switch (bytesLeft[0])
            {
            case (byte)JVSPacket.OP_ADDRESS:
                return(JvsGetAddress(bytesLeft, reply));

            case 0x01:
                return(JvsTaito01(reply));

            case 0x03:
                return(JvsTaito03(reply));

            case 0x04:
                return(JvsTaito04(reply));

            case 0x05:
                return(JvsTaito05(reply));

            case 0x65:
                return(JvsTaito65(reply, multiPackage));

            case 0x6A:
                return(JvsTaito6A(reply));

            case 0x6B:
                return(JvsTaito6B(reply));

            case 0x6D:
                return(JvsTaito6D(reply));

            case 0x23:
                return(JvsTaito23(reply));

            case 0x34:
                return(JvsTaito34(bytesLeft, reply));

            case 0x10:
                return(JvsGetIdentifier(reply));

            case 0x11:
                return(JvsGetCommandRev(reply, multiPackage));

            case 0x12:
                return(JvsGetJvsVersion(reply, multiPackage));

            case 0x13:
                return(JvsGetCommunicationVersion(reply, multiPackage));

            case 0x14:
                return(JvsGetSlaveFeatures(reply, multiPackage));

            case 0x15:
                return(JvsConveyMainBoardId(bytesLeft, reply));

            case 0x20:
                if (InvertMaiMaiButtons)
                {
                    return(JvsGetDigitalReplyInvertMaiMai(bytesLeft, reply, multiPackage, node));
                }
                else
                {
                    return(JvsGetDigitalReply(bytesLeft, reply, multiPackage, node));
                }

            case 0x21:
                return(JvsGetCoinReply(bytesLeft, reply, multiPackage));

            case 0x22:
                return(JvsGetAnalogReply(bytesLeft, reply, multiPackage, node));

            case 0x2E:
                return(JvsGetHopperReply(reply, multiPackage));

            case 0x2F:
                return(JvsReTransmitData(reply));

            case 0x30:
            case 0x31:
                return(JvsGetCoinReduce(bytesLeft, reply, multiPackage));

            case 0x32:
                return(JvsGeneralPurposeOutput(bytesLeft, reply, multiPackage));

            case 0x33:
                return(JvsAnalogOutput(bytesLeft, reply, multiPackage));

            case 0x36:
                return(JvsPayoutSubtractionOutput(reply, multiPackage));

            case 0x37:
                return(JvsGeneralPurposeOutput2(reply, multiPackage));

            case 0x70:
                if (Taito || TaitoStick || TaitoBattleGear)
                {
                    return(JvsTaito70(reply));
                }
                else
                {
                    return(JvsGetNamcoCustomCommands(bytesLeft, reply, multiPackage));
                }

            case 0x78:
            case 0x79:
            case 0x7A:
            case 0x7B:
            case 0x7C:
            case 0x7D:
            case 0x7E:
            case 0x7F:
            case 0x80:
                return(SkipNamcoUnknownCustom(reply));
            }
            if (TaitoBattleGear)
            {
                if (ProMode)
                {
                    switch (bytesLeft[0])
                    {
                    case 0x00:
                        return(JvsTaito00(reply));

                    case 0x02:
                        return(JvsTaito02(reply));

                    case 0x40:
                        return(JvsTaito40(reply));

                    case 0x66:
                        return(JvsTaito66(reply));

                    case 0x6F:
                        return(JvsTaito6F(reply));

                    case 0x26:
                        return(JvsTaito26(reply));

                    case 0xFF:
                        return(JvsTaitoFF(reply));
                    }
                }
            }
            if (Namco)
            {
                reply.LengthReduction = 1;
                reply.Bytes           = new byte[0];
            }
            else
            {
                Debug.WriteLine($"Unknown package, contact Reaver! Package: {JvsHelper.ByteArrayToString(bytesLeft)}");
                reply.Error = true;
            }
            return(reply);
        }
Ejemplo n.º 6
0
        private static JvsReply JvsGetDigitalReply(byte[] bytesLeft, JvsReply reply, bool multiPackage, byte node)
        {
            var baseAddr = 0;

            if (node == 2)
            {
                baseAddr = 2;
            }
            var byteLst     = new List <byte>();
            var players     = bytesLeft[1];
            var bytesToRead = bytesLeft[2];

            if (multiPackage)
            {
                byteLst.Add(0x01);
            }
            byteLst.Add(GetSpecialBits(0));
            if (players > 2)
            {
                Debug.WriteLine($"Why would you have more than 2 players? Package: {JvsHelper.ByteArrayToString(bytesLeft)}");
                throw new NotSupportedException();
            }
            if (TaitoStick)
            {
                byteLst.Add(GetPlayerControls(baseAddr));
                byteLst.Add(GetPlayerControlsExt(baseAddr));
                byteLst.Add(GetPlayerControls(baseAddr + 1));
                byteLst.Add(GetPlayerControlsExt(baseAddr + 1));
                reply.LengthReduction = 3;
                reply.Bytes           = byteLst.ToArray();
                return(reply);
            }
            if (players != 0)
            {
                byteLst.Add(GetPlayerControls(baseAddr));
                bytesToRead--;
                if (bytesToRead != 0)
                {
                    byteLst.Add(GetPlayerControlsExt(baseAddr));
                    bytesToRead--;
                }
                if (bytesToRead != 0)
                {
                    byteLst.Add(GetPlayerControlsExt2(baseAddr));
                    bytesToRead--;
                }
                if (bytesToRead != 0)
                {
                    byteLst.Add(GetPlayerControlsExt3(baseAddr));
                    bytesToRead--;
                }
                while (bytesToRead != 0)
                {
                    byteLst.Add(0x00);
                    bytesToRead--;
                }
                if (players == 2)
                {
                    bytesToRead = bytesLeft[2];
                    byteLst.Add(GetPlayerControls(baseAddr + 1));
                    bytesToRead--;
                    if (bytesToRead != 0)
                    {
                        byteLst.Add(GetPlayerControlsExt(baseAddr + 1));
                        bytesToRead--;
                    }
                    if (bytesToRead != 0)
                    {
                        byteLst.Add(GetPlayerControlsExt2(baseAddr + 1));
                        bytesToRead--;
                    }
                    if (bytesToRead != 0)
                    {
                        byteLst.Add(GetPlayerControlsExt3(baseAddr + 1));
                        bytesToRead--;
                    }
                    while (bytesToRead != 0)
                    {
                        byteLst.Add(0x00);
                        bytesToRead--;
                    }
                }
            }
            reply.LengthReduction = 3;
            reply.Bytes           = byteLst.ToArray();
            return(reply);
        }
Ejemplo n.º 7
0
        private static JvsReply JvsGetDigitalReplyInvertMaiMai(byte[] bytesLeft, JvsReply reply, bool multiPackage, byte node)
        {
            var baseAddr = 0;

            if (node == 2)
            {
                baseAddr = 2;
            }
            var byteLst     = new List <byte>();
            var players     = bytesLeft[1];
            var bytesToRead = bytesLeft[2];

            if (multiPackage)
            {
                byteLst.Add(0x01);
            }
            byteLst.Add(GetSpecialBits(0));
            if (players > 2)
            {
                MessageBox.Show($"Why would you have more than 2 players?  Package: {JvsHelper.ByteArrayToString(bytesLeft)}", "Contact Reaver asap!",
                                MessageBoxButtons.OK, MessageBoxIcon.Question);
                throw new NotSupportedException();
            }
            if (TaitoStick)
            {
                byteLst.Add(GetPlayerControlsInvertMaiMai(baseAddr));
                byteLst.Add(GetPlayerControlsExtInvertMaiMai(baseAddr));
                byteLst.Add(GetPlayerControlsInvertMaiMai(baseAddr + 1));
                byteLst.Add(GetPlayerControlsExtInvertMaiMai(baseAddr + 1));
                reply.LengthReduction = 3;
                reply.Bytes           = byteLst.ToArray();
                return(reply);
            }
            if (players != 0)
            {
                byteLst.Add(GetPlayerControlsInvertMaiMai(baseAddr));
                bytesToRead--;
                if (bytesToRead != 0)
                {
                    byteLst.Add(GetPlayerControlsExtInvertMaiMai(baseAddr));
                    bytesToRead--;
                }
                if (bytesToRead != 0)
                {
                    byteLst.Add(GetPlayerControlsExt2(baseAddr));
                    bytesToRead--;
                }
                if (bytesToRead != 0)
                {
                    byteLst.Add(GetPlayerControlsExt3(baseAddr));
                    bytesToRead--;
                }
                while (bytesToRead != 0)
                {
                    byteLst.Add(0x00);
                    bytesToRead--;
                }
                if (players == 2)
                {
                    bytesToRead = bytesLeft[2];
                    byteLst.Add(GetPlayerControlsInvertMaiMai(baseAddr + 1));
                    bytesToRead--;
                    if (bytesToRead != 0)
                    {
                        byteLst.Add(GetPlayerControlsExtInvertMaiMai(baseAddr + 1));
                        bytesToRead--;
                    }
                    if (bytesToRead != 0)
                    {
                        byteLst.Add(GetPlayerControlsExt2(baseAddr + 1));
                        bytesToRead--;
                    }
                    if (bytesToRead != 0)
                    {
                        byteLst.Add(GetPlayerControlsExt3(baseAddr + 1));
                        bytesToRead--;
                    }
                    while (bytesToRead != 0)
                    {
                        byteLst.Add(0x00);
                        bytesToRead--;
                    }
                }
            }
            reply.LengthReduction = 3;
            reply.Bytes           = byteLst.ToArray();
            return(reply);
        }