Пример #1
0
 private static JvsReply JvsGetAddress(byte[] bytesLeft, JvsReply reply)
 {
     if (bytesLeft[1] != 0x01)
     {
         MessageBox.Show($"Unsupported JVS_OP_ADDRESS package, contact Reaver! Package: {ByteArrayToString(bytesLeft)}");
         throw new NotSupportedException();
     }
     reply.Bytes           = new byte[] {};
     reply.LengthReduction = 2;
     return(reply);
 }
Пример #2
0
        public static JvsReply ParsePackage(byte[] bytesLeft, bool multiPackage)
        {
            JvsReply reply = new JvsReply();

            // We take first byte of the package
            switch (bytesLeft[0])
            {
            case JVS_OP_ADDRESS:
                return(JvsGetAddress(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:
                return(JvsGetDigitalReply(bytesLeft, reply, multiPackage));

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

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

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

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

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

            case 0x37:
                return(JvsGeneralPurposeOutput2(bytesLeft, reply, multiPackage));
            }
            Console.WriteLine($"Unknown package, contact Reaver! Package: {ByteArrayToString(bytesLeft)}");
            reply.Error = true;
            return(reply);
        }
Пример #3
0
        private static JvsReply JvsGetDigitalReply(byte[] bytesLeft, JvsReply reply, bool multiPackage)
        {
            var byteLst     = new List <byte>();
            var players     = bytesLeft[1];
            var bytesToRead = bytesLeft[2];

            if (multiPackage)
            {
                byteLst.Add(0x01);
            }
            byteLst.Add(GetSpecialBits());
            if (players > 2)
            {
                MessageBox.Show($"Why would you have more than 2 players?  Package: {ByteArrayToString(bytesLeft)}", "Contact Reaver asap!",
                                MessageBoxButtons.OK, MessageBoxIcon.Question);
                throw new NotSupportedException();
            }
            if (players != 0)
            {
                byteLst.Add(GetPlayer1Controls());
                bytesToRead--;
                if (bytesToRead != 0)
                {
                    byteLst.Add(GetPlayer1ControlsExt());
                    bytesToRead--;
                }
                while (bytesToRead != 0)
                {
                    byteLst.Add(0x00);
                    bytesToRead--;
                }
                if (players == 2)
                {
                    bytesToRead = bytesLeft[2];
                    byteLst.Add(GetPlayer2Controls());
                    bytesToRead--;
                    if (bytesToRead != 0)
                    {
                        byteLst.Add(GetPlayer2ControlsExt());
                        bytesToRead--;
                    }
                    while (bytesToRead != 0)
                    {
                        byteLst.Add(0x00);
                        bytesToRead--;
                    }
                }
            }
            reply.LengthReduction = 3;
            reply.Bytes           = byteLst.ToArray();
            return(reply);
        }
Пример #4
0
        private static JvsReply JvsGeneralPurposeOutput(byte[] bytesLeft, JvsReply reply, bool multiPackage)
        {
            var byteCount = bytesLeft[1];

            reply.LengthReduction = byteCount + 2; // Command Code + Size + Outputs

            // Special invalid package from Virtua-R Limit
            //if(bytesLeft.Length > 4)
            //    if (bytesLeft[byteCount + 2] == 0x00)
            //        reply.LengthReduction++;

            reply.Bytes = !multiPackage ? new byte[] { } : new byte[] { 0x01 };
            return(reply);
        }
Пример #5
0
 private static JvsReply JvsGetSlaveFeatures(JvsReply reply, bool multiPackage)
 {
     reply.LengthReduction = 1;
     reply.Bytes           = multiPackage
         ? new byte[]
     {
         0x01, 0x01, 0x02, 0x0E, 0x00, 0x02, 0x02, 0x00, 0x00, 0x03, 0x08, 0x0A, 0x00, 0x12, 0x14, 0x00,
         0x00, 0x00
     }
         : new byte[]
     {
         0x01, 0x02, 0x0E, 0x00, 0x02, 0x02, 0x00, 0x00, 0x03, 0x08, 0x0A, 0x00, 0x12, 0x14, 0x00, 0x00, 0x00
     };
     return(reply);
 }
Пример #6
0
 private static JvsReply JvsConveyMainBoardId(byte[] bytesLeft, JvsReply reply)
 {
     for (var i = 0; i < bytesLeft.Length; i++)
     {
         if (i == 0x00)
         {
             break;
         }
         reply.LengthReduction++;
     }
     reply.LengthReduction++;
     reply.Bytes = new byte[]
     {
         0x01, 0x01, 0x05
     };
     return(reply);
 }
Пример #7
0
        private static JvsReply JvsGetAnalogReply(byte[] bytesLeft, JvsReply reply, bool multiPackage)
        {
            var byteLst      = new List <byte>();
            int channelCount = 0;

            channelCount          = bytesLeft.Length == 1 ? 8 : bytesLeft[1]; // Stupid hack for Virtua-R Limit
            reply.LengthReduction = 2;

            if (multiPackage)
            {
                byteLst.Add(0x01);
            }
            for (int i = 0; i < channelCount; i++)
            {
                byteLst.Add(InputCode.AnalogBytes[(i * 2)]);
                byteLst.Add(InputCode.AnalogBytes[(i * 2) + 1]);
            }
            reply.Bytes = byteLst.ToArray();
            return(reply);
        }
Пример #8
0
        private static JvsReply JvsGetCoinReply(byte[] bytesLeft, JvsReply reply, bool multiPackage)
        {
            var slotCount = bytesLeft[1];

            reply.LengthReduction = 2;
            if (slotCount == 0)
            {
                reply.Bytes = !multiPackage ? new byte[] { } : new byte[] { 0x01 };
            }
            else if (slotCount == 1)
            {
                reply.Bytes = !multiPackage ? new byte[] { 0x00, 0x00 } : new byte[] { 0x01, 0x00, 0x00 };
            }
            else if (slotCount == 2)
            {
                reply.Bytes = !multiPackage ? new byte[] { 0x00, 0x00, 0x00, 0x00 } : new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00 };
            }
            else
            {
                MessageBox.Show($"Unknown READ_COIN_INPUTS package, contact Reaver!  Package: {ByteArrayToString(bytesLeft)}");
                throw new NotSupportedException();
            }
            return(reply);
        }
Пример #9
0
 private static JvsReply JvsGetCommandRev(JvsReply reply, bool multiPackage)
 {
     reply.LengthReduction = 1;
     reply.Bytes           = multiPackage ? new byte[] { 0x01, 0x13 } : new byte[] { 0x13 };
     return(reply);
 }
Пример #10
0
 private static JvsReply JvsGetJvsVersion(JvsReply reply, bool multiPackage)
 {
     reply.LengthReduction = 1;
     reply.Bytes           = multiPackage ? new byte[] { 0x01, 0x20 } : new byte[] { 0x20 };
     return(reply);
 }
Пример #11
0
 private static JvsReply JvsGetIdentifier(JvsReply reply)
 {
     reply.LengthReduction = 1;
     reply.Bytes           = Encoding.ASCII.GetBytes(JVS_IDENTIFIER_Sega2005Jvs14572);
     return(reply);
 }
Пример #12
0
 private static JvsReply JvsGeneralPurposeOutput2(byte[] bytesLeft, JvsReply reply, bool multiPackage)
 {
     reply.LengthReduction = 3; // Command Code + Size + Outputs
     reply.Bytes           = !multiPackage ? new byte[] { } : new byte[] { 0x01 };
     return(reply);
 }
Пример #13
0
 private static JvsReply JvsGetCoinReduce(JvsReply reply, bool multiPackage)
 {
     reply.LengthReduction = 4;
     reply.Bytes           = !multiPackage ? new byte[] { } : new byte[] { 0x03 };
     return(reply);
 }
Пример #14
0
 private static JvsReply JvsReTransmitData(JvsReply reply)
 {
     reply.LengthReduction = 1;
     reply.Bytes           = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00 };
     return(reply);
 }