Example #1
0
        private void NewCommandOnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            bool   exit = false;
            string text = "00000000";

            while (!exit)
            {
                try
                {
                    var dialog = new InputDialog();
                    dialog.Title = "Enter gameshark code";
                    dialog.Text  = text;
                    bool?result = dialog.ShowDialog();
                    if (!result.HasValue || !result.Value)
                    {
                        exit = true;
                    }
                    else
                    {
                        text = dialog.Text.Replace(" ", "");

                        if (text.Length != 8)
                        {
                            throw new ArgumentException("Gameshark codes are 8 characters long.");
                        }

                        byte[] rawcode = new byte[4];
                        for (int i = 0; i < 4; i++)
                        {
                            byte value;
                            if (!byte.TryParse(text.Substring(i * 2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value))
                            {
                                throw new ArgumentException("Gameshark codes can only contain hexadecimal representation of bytes.");
                            }

                            rawcode[i] = value;
                        }

                        GamesharkController.Codes.Add(new GamesharkCode(rawcode));
                        exit = true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Invalid gameshark code. " + ex.Message, "Emux", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            }
        }
Example #2
0
        private void RegistersViewOnItemActivate(object sender, EventArgs e)
        {
            var listView = (ListView)sender;

            if (listView.SelectedItem == null)
            {
                return;
            }

            var    item   = (RegisterItem)listView.SelectedItem;
            string text   = item.Value.ToString("X2");
            bool   repeat = true;

            while (repeat)
            {
                var dialog = new InputDialog
                {
                    Title = "Enter new value for " + item.DisplayName,
                    Text  = text
                };
                var result = dialog.ShowDialog();
                repeat = result.HasValue && result.Value;
                if (repeat)
                {
                    byte newValue;
                    text   = dialog.Text;
                    repeat = !byte.TryParse(text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out newValue);

                    if (repeat)
                    {
                        MessageBox.Show("Please enter a valid hexadecimal number between 00 and FF", "Emux",
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        item.Value = newValue;
                        Device.Memory.WriteByte(item.Offset, newValue);
                    }
                }
            }
        }