Ejemplo n.º 1
0
        public static void ReadI2CWorker(object data)
        {
            WiiReaderV1 reader = ((WiiReaderV1)data);

            while (!reader.inShutdown)
            {
                I2CPacket packet = reader.packetPool[reader.currentPacketInPool];
                reader.currentPacketInPool += 1;
                reader.currentPacketInPool %= 100;

                uint  status         = 0;
                ulong timeSop        = 0;
                ulong timeDuration   = 0;
                uint  timeDataOffset = 0;

                packet.Length = BeagleApi.bg_i2c_read(
                    ((WiiReaderV1)data).hBeagle, ref status, ref timeSop,
                    ref timeDuration, ref timeDataOffset, 1024, packet.Data);

                if (packet.Length >= 1)
                {
                    reader.packetsToBeProcessed.Enqueue(packet);
                }
            }
        }
Ejemplo n.º 2
0
        public WiiReaderV1(int controllerId)
        {
            if (!Environment.Is64BitProcess)
            {
                throw new IOException("WiiReaderV1 is only support in 64 bit RetroSpy!");
            }

            wm_rand = new byte[10];
            wm_key  = new byte[6];
            wm_ft   = new byte[8];
            wm_sb   = new byte[8];

            // Setup the Beagle
            hBeagle = BeagleApi.bg_open(controllerId);
            if (hBeagle <= 0)
            {
                throw new IOException(String.Format("WiiReaderV1 could not find Beagle USB Protocol Analyzer on port {0}.", controllerId));
            }

            isOpened = true;

            int samplerate = 10000;

            samplerate = BeagleApi.bg_samplerate(hBeagle, samplerate);
            if (samplerate < 0)
            {
                Finish();
                throw new IOException(String.Format("WiiReaderV1 error: {0:s}\n", BeagleApi.bg_status_string(samplerate)));
            }

            BeagleApi.bg_timeout(hBeagle, milliseconds: 500);
            BeagleApi.bg_latency(hBeagle, milliseconds: 0);
            BeagleApi.bg_target_power(hBeagle, BeagleApi.BG_TARGET_POWER_OFF);
            BeagleApi.bg_i2c_pullup(hBeagle, BeagleApi.BG_I2C_PULLUP_OFF);

            if (BeagleApi.bg_enable(hBeagle, BeagleProtocol.BG_PROTOCOL_I2C) != (int)BeagleStatus.BG_OK)
            {
                Finish();
                throw new IOException("WiiReaderV1 error: could not enable I2C capture\n");
            }
            isEnabled = true;

            packetPool = new I2CPacket[1024];

            for (int i = 0; i < 100; ++i)
            {
                packetPool[i] = new I2CPacket();
            }

            Thread usbParsingThread = new Thread(ProcessPacketWorker);
            Thread usbReadingThread = new Thread(ReadI2CWorker);

            usbParsingThread.Start(this);
            usbReadingThread.Start(this);
        }