Ejemplo n.º 1
0
 private void HighlightPanel_KeyUp(object sender, KeyEventArgs e)
 {
     if (mem.X != -1)
     {
         String rawAddress = mem.X.ToString("X6");
         String address    = "$" + rawAddress.Substring(0, 2) + ":" + rawAddress.Substring(2);
         if (HighlightPanel.Text != "")
         {
             // The result may be a hexadecimal value
             try
             {
                 byte intResult = Convert.ToByte(HighlightPanel.Text, 16);
                 // Check that the value was changed
                 if (intResult != mem.Y)
                 {
                     Memory.WriteByte(mem.X, intResult);
                     //HighlightPanel.Text = intResult.ToString("X2");
                     RefreshMemoryView();
                 }
             }
             catch
             {
             }
         }
     }
 }
Ejemplo n.º 2
0
        public static void Load(IMappable memory, string Filename)
        {
            int bank    = 0;
            int address = 0;

            if (!System.IO.File.Exists(Filename))
            {
                throw new System.IO.FileNotFoundException("Could not find Hex file \"" + Filename + "\"");
            }

            string[] lines = System.IO.File.ReadAllLines(Filename);

            foreach (string l in lines)
            {
                string mark     = l.Substring(0, 1);
                string reclen   = l.Substring(1, 2);
                string offset   = l.Substring(3, 4);
                string rectype  = l.Substring(7, 2);
                string data     = l.Substring(9, l.Length - 11);
                string checksum = l.Substring(l.Length - 2);

                switch (rectype)
                {
                // data row. The next n bytes are data to be loaded into memory
                case "00":
                    address = GetByte(offset, 0, 2);
                    for (int i = 0; i < data.Length; i += 2)
                    {
                        int b = GetByte(data, i, 1);
                        memory.WriteByte(bank + address, (byte)b);
                        address++;
                    }
                    break;

                // end of file - just ignore
                case "01":
                    break;

                // extended linear address
                // lower byte will populate the bank number.
                case "04":
                    bank = GetByte(data, 0, 2) << 16;
                    break;

                // extended linear start address
                // set the initial bank register value. Not used in the simulator.
                case "05":
                    break;

                default:
                    throw new NotImplementedException("Record type not implemented: " + rectype);
                }
            }
        }
Ejemplo n.º 3
0
        private void StoreButton_Click(object sender, EventArgs e)
        {
            StoreButton.Enabled = false;
            string extension = Path.GetExtension(FileNameTextBox.Text).ToLower();
            bool   binFile   = !extension.Equals("bmp");

            if (!binFile)
            {
                // TODO: determine what to do with the control register
                controlByte = (byte)((LUTCombo.SelectedIndex << 1) + 1);
                Memory.WriteByte(controlRegisterAddress, controlByte); // enable
            }
            // Store the address in the pointer address - little endian - 24 bits
            string strAddress   = LoadAddressTextBox.Text.Replace(":", "");
            int    videoAddress = 0;

            if (strAddress != String.Empty)
            {
                int.TryParse(strAddress, System.Globalization.NumberStyles.HexNumber, System.Globalization.NumberFormatInfo.CurrentInfo, out videoAddress);
            }
            int writeVideoAddress = videoAddress;

            ResourceChecker.Resource res = new ResourceChecker.Resource
            {
                StartAddress = videoAddress,
                SourceFile   = FileNameTextBox.Text,
                Name         = Path.GetFileNameWithoutExtension(FileNameTextBox.Text)
            };

            if (!binFile)
            {
                // Store the bitmap at the user's determined address
                // The method below simply takes the file and writes it in memory.
                // What we want is the actual pixels.
                ImageConverter converter   = new ImageConverter();
                byte[]         data        = (byte[])converter.ConvertTo(bitmap, typeof(byte[]));
                int            startOffset = BitConverter.ToInt32(data, 10);
                int            fileLength  = BitConverter.ToInt32(data, 2);
                res.Length = bitmap.Height * bitmap.Width;
                if (ResChecker.Add(res))
                {
                    // The addresses in Vicky a offset by $B0:0000
                    videoAddress = videoAddress - 0xB0_0000;
                    Memory.WriteByte(pointerAddress, LowByte(videoAddress));
                    Memory.WriteByte(pointerAddress + 1, MidByte(videoAddress));
                    Memory.WriteByte(pointerAddress + 2, HighByte(videoAddress));

                    // Store the strides in the strideX and strideY
                    Memory.WriteByte(strideXAddress, LowByte(strideX));
                    Memory.WriteByte(strideXAddress + 1, MidByte(strideX));
                    Memory.WriteByte(strideYAddress, LowByte(strideY));
                    Memory.WriteByte(strideYAddress + 1, MidByte(strideY));



                    int numberOfColors = BitConverter.ToInt32(data, 46);
                    int lutOffset      = 0xAF_2000 + LUTCombo.SelectedIndex * 1024;
                    if (numberOfColors == 0)
                    {
                        // we need to create a LUT - each LUT only accepts 256 entries - 0 is black
                        TransformBitmap(data, startOffset, Int32.Parse(PixelDepthValueLabel.Text), lutOffset, writeVideoAddress, bitmap.Width, bitmap.Height);
                    }
                    else
                    {
                        for (int offset = 54; offset < 1024 + 54; offset = offset + 4)
                        {
                            int color = BitConverter.ToInt32(data, offset);
                            Memory.WriteByte(lutOffset, LowByte(color));
                            Memory.WriteByte(lutOffset + 1, MidByte(color));
                            Memory.WriteByte(lutOffset + 2, HighByte(color));
                            Memory.WriteByte(lutOffset + 3, 0xFF); // Alpha
                            lutOffset = lutOffset + 4;
                        }
                        for (int line = 0; line < bitmap.Height; line++)
                        {
                            for (int i = 0; i < bitmap.Width; i++)
                            {
                                Memory.WriteByte(writeVideoAddress + (bitmap.Height - line + 1) * bitmap.Width + i, data[startOffset + line * bitmap.Width + i]);
                            }
                        }
                    }
                    if (BitmapTypesCombo.SelectedIndex > 0 && BitmapTypesCombo.SelectedIndex < 5)
                    {
                        int layer = BitmapTypesCombo.SelectedIndex - 1;
                        OnTileLoaded?.Invoke(layer);
                    }
                    MessageBox.Show("Transfer successful!", "Bitmap Storage", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    StoreButton.Enabled = true;
                }
            }
            else
            {
                byte[] data = File.ReadAllBytes(FileNameTextBox.Text);
                for (int i = 0; i < data.Length; i++)
                {
                    Memory.WriteByte(videoAddress + i, data[i]);
                }
                StoreButton.Enabled = true;
            }
        }
Ejemplo n.º 4
0
        private void StoreButton_Click(object sender, EventArgs e)
        {
            StoreButton.Enabled = false;

            // Store the address in the pointer address - little endian - 24 bits
            int destAddress = Convert.ToInt32(LoadAddressTextBox.Text.Replace(":", ""), 16);

            byte[] data = File.ReadAllBytes(FileNameTextBox.Text);
            for (int i = 0; i < data.Length; i++)
            {
                Memory.WriteByte(destAddress + i, data[i]);
            }

            // Determine which addresses to store the bitmap into.
            if (FileTypesCombo.SelectedIndex == 0)
            {
                // Raw
            }
            else if (FileTypesCombo.SelectedIndex < 5)
            {
                // Tilemaps 4
                int  tilemapIndex = FileTypesCombo.SelectedIndex - 1;
                int  baseAddress  = MemoryLocations.MemoryMap.TILE_CONTROL_REGISTER_ADDR + tilemapIndex * 12;
                byte lutValue     = (byte)LUTCombo.SelectedIndex;
                // enable the tilemap
                Memory.WriteByte(baseAddress, (byte)(1 + (lutValue << 1)));
                // write address offset by bank $b0
                int offsetAddress = destAddress - 0xB0_0000;
                Memory.WriteByte(baseAddress + 1, (byte)(offsetAddress & 0xFF));
                Memory.WriteByte(baseAddress + 2, (byte)((offsetAddress & 0xFF00) >> 8));
                Memory.WriteByte(baseAddress + 3, (byte)((offsetAddress & 0xFF_0000) >> 16));
                // TODO: Need to write the size of the tilemap
            }
            else if (FileTypesCombo.SelectedIndex < 13)
            {
                // Tilesets 8
                int  tilesetIndex = FileTypesCombo.SelectedIndex - 5;
                int  baseAddress  = MemoryLocations.MemoryMap.TILESET_BASE_ADDR + tilesetIndex * 4;
                byte lutValue     = (byte)LUTCombo.SelectedIndex;

                // write address offset by bank $b0
                int offsetAddress = destAddress - 0xB0_0000;
                Memory.WriteByte(baseAddress, (byte)(offsetAddress & 0xFF));
                Memory.WriteByte(baseAddress + 1, (byte)((offsetAddress & 0xFF00) >> 8));
                Memory.WriteByte(baseAddress + 2, (byte)((offsetAddress & 0xFF_0000) >> 16));
                Memory.WriteByte(baseAddress + 3, lutValue);  // TODO: Add the stride 256 bit 3.
            }
            else
            {
                // Sprites 64
                int  spriteIndex = FileTypesCombo.SelectedIndex - 13;
                int  baseAddress = MemoryLocations.MemoryMap.SPRITE_CONTROL_REGISTER_ADDR + spriteIndex * 8;
                byte lutValue    = (byte)LUTCombo.SelectedIndex;

                // enable the tilemap
                Memory.WriteByte(baseAddress, (byte)(1 + (lutValue << 1)));  // TODO: Add sprite depth

                // write address offset by bank $b0
                int offsetAddress = destAddress - 0xB0_0000;
                Memory.WriteByte(baseAddress + 1, (byte)(offsetAddress & 0xFF));
                Memory.WriteByte(baseAddress + 2, (byte)((offsetAddress & 0xFF00) >> 8));
                Memory.WriteByte(baseAddress + 3, (byte)((offsetAddress & 0xFF_0000) >> 16));
                // TODO: set the position of the sprite
            }

            ResourceChecker.Resource res = new ResourceChecker.Resource
            {
                StartAddress = destAddress,
                SourceFile   = FileNameTextBox.Text,
                Name         = Path.GetFileNameWithoutExtension(FileNameTextBox.Text),
                FileType     = FileTypesCombo.SelectedIndex
            };

            StoreButton.Enabled = true;

            //// Store the bitmap at the user's determined address
            //// The method below simply takes the file and writes it in memory.
            //// What we want is the actual pixels.
            //ImageConverter converter = new ImageConverter();
            //byte[] data = (byte[])converter.ConvertTo(bitmap, typeof(byte[]));
            //int startOffset = BitConverter.ToInt32(data, 10);
            //int fileLength = BitConverter.ToInt32(data, 2);
            //res.Length = bitmap.Height * bitmap.Width;
            //if (ResChecker.Add(res))
            //{

            //    // The addresses in Vicky a offset by $B0:0000
            //    videoAddress = videoAddress - 0xB0_0000;
            //    Memory.WriteByte(pointerAddress, LowByte(videoAddress));
            //    Memory.WriteByte(pointerAddress + 1, MidByte(videoAddress));
            //    Memory.WriteByte(pointerAddress + 2, HighByte(videoAddress));

            //    // Store the strides in the strideX and strideY
            //    Memory.WriteByte(strideXAddress, LowByte(strideX));
            //    Memory.WriteByte(strideXAddress + 1, MidByte(strideX));
            //    Memory.WriteByte(strideYAddress, LowByte(strideY));
            //    Memory.WriteByte(strideYAddress + 1, MidByte(strideY));



            //    int numberOfColors = BitConverter.ToInt32(data, 46);
            //    int lutOffset = 0xAF_2000 + LUTCombo.SelectedIndex * 1024;
            //    if (numberOfColors == 0)
            //    {
            //        // we need to create a LUT - each LUT only accepts 256 entries - 0 is black
            //        TransformBitmap(data, startOffset, Int32.Parse(PixelDepthValueLabel.Text), lutOffset, writeVideoAddress, bitmap.Width, bitmap.Height);
            //    }
            //    else
            //    {
            //        for (int offset = 54; offset < 1024 + 54; offset = offset + 4)
            //        {
            //            int color = BitConverter.ToInt32(data, offset);
            //            Memory.WriteByte(lutOffset, LowByte(color));
            //            Memory.WriteByte(lutOffset + 1, MidByte(color));
            //            Memory.WriteByte(lutOffset + 2, HighByte(color));
            //            Memory.WriteByte(lutOffset + 3, 0xFF); // Alpha
            //            lutOffset = lutOffset + 4;
            //        }
            //        for (int line = 0; line < bitmap.Height; line++)
            //        {
            //            for (int i = 0; i < bitmap.Width; i++)
            //            {
            //                Memory.WriteByte(writeVideoAddress + (bitmap.Height - line + 1) * bitmap.Width + i, data[startOffset + line * bitmap.Width + i]);
            //            }
            //        }
            //    }
            //    if (FileTypesCombo.SelectedIndex > 0 && FileTypesCombo.SelectedIndex < 5)
            //    {
            //        int layer = FileTypesCombo.SelectedIndex - 1;
            //        OnTileLoaded?.Invoke(layer);
            //    }
            //    MessageBox.Show("Transfer successful!", "Bitmap Storage", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    this.Close();
            //}
            //else
            //{
            //    StoreButton.Enabled = true;
            //}
        }