Пример #1
0
        public ChannelCapture GetChannel(byte channelNumber)
        {
            ChannelCapture channel = channels.Where(c => c.ChannelNumber == channelNumber).FirstOrDefault();

            if (channel == null)
            {
                //didn't exist, make a new one..
                channel = new ChannelCapture(channelNumber);
                channels.Add(channel);
            }
            return(channel);
        }
Пример #2
0
        private void buttonParse_Click(object sender, EventArgs e)
        {
            if (File.Exists(textBoxLogFile.Text))
            {
                Cursor.Current = Cursors.WaitCursor;
                captures.Clear();

                string[] logLines = File.ReadAllLines(textBoxLogFile.Text);
                int      pos      = 0;
                bool     started  = false;

                SoundCapture capture     = null;
                int          totalTicks  = 0;
                int          tickCounter = 0;

                foreach (string line in logLines)
                {
                    string cleanLine = CleanLine(line);
                    if (cleanLine.StartsWith("SoundID: " + textBoxFirstSoundID.Text))
                    {
                        byte soundId = GetSoundId(cleanLine);
                        if (!started)
                        {
                            started     = true;
                            capture     = new SoundCapture(soundId);
                            tickCounter = 0;
                            totalTicks  = 0;
                            //UpdateUI();
                        }
                    }
                    else if (started)
                    {
                        if (cleanLine.StartsWith("SoundID: "))
                        {
                            byte soundId = GetSoundId(cleanLine);
                            //we already started, this means we have a new SoundCapture
                            if (capture != null)
                            {
                                //save it
                                capture.TotalTicks = totalTicks;
                                captures.Add(capture);
                                capture     = new SoundCapture(soundId);
                                tickCounter = 0;
                                totalTicks  = 0;
                                //UpdateUI();
                            }
                        }
                        if (cleanLine == "TICK")
                        {
                            tickCounter++;
                            totalTicks++;
                            if (capture != null)
                            {
                                capture.Tick();
                            }
                        }
                        else if (cleanLine.StartsWith("[:] Pokey Config:"))
                        {
                            //skip config lines for now
                        }
                        else if (cleanLine.StartsWith("[:] Pokey "))
                        {
                            //pokey data here...
                            string type           = cleanLine.Replace("[:] Pokey ", "").Substring(0, 4);
                            int    pokeyNumber    = int.Parse(cleanLine.Replace(("[:] Pokey " + type + ": "), "").Substring(0, 1));
                            int    registerNumber = int.Parse(cleanLine.Replace("[:] Pokey " + type + ": " + pokeyNumber.ToString() + " Register:  ", "").Substring(0, 1));
                            byte   channelNumber  = (byte)((pokeyNumber << 2) + (registerNumber / 2));
                            //[:] Pokey FREQ: 1 Register:  6 Data:
                            string hexDataString = cleanLine.Substring(37, 2);
                            byte   data          = byte.Parse(hexDataString, System.Globalization.NumberStyles.HexNumber);

                            ChannelCapture channel = capture.GetChannel(channelNumber);
                            switch (type)
                            {
                            case "CONT":
                                channel.ControlBytes.Add(data);
                                break;

                            case "FREQ":
                                channel.FrequencyBytes.Add(data);
                                break;
                            }
                        }
                    }
                }
                if (capture != null)
                {
                    capture.TotalTicks = totalTicks;
                    captures.Add(capture);
                }

                UpdateUI();

                Cursor.Current = Cursors.Default;
            }
            else
            {
                MessageBox.Show("File not found: " + textBoxLogFile.Text);
            }
        }