private void BuildBanks() { SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Building banks", OutputMessageType.Information); ProjectModel projectModel = ModelManager.Get <ProjectModel>(); string outputPath = Path.GetFullPath(projectModel.Build.OutputFilePath); List <FileModelVO> bankModelVOs = ProjectFiles.GetModels <BankModel>(); const int cellSizeInBytes = 128; // 16 bytes each cell foreach (FileModelVO vo in bankModelVOs) { BankModel bank = vo.Model as BankModel; int cellsCount = 0; switch (bank.BankSize) { case BankSize.Size4Kb: cellsCount = 16 * 16; break; case BankSize.Size2Kb: cellsCount = 16 * 8; break; case BankSize.Size1Kb: cellsCount = 16 * 4; break; } Dictionary <string, WriteableBitmap> bitmapCache = new Dictionary <string, WriteableBitmap>(); BitArray outputBits = new BitArray(cellSizeInBytes * cellsCount); outputBits.SetAll(false); int currentIndex = 0; WriteableBitmap bitmap = BanksUtils.CreateImage(bank, ref bitmapCache, false); using (bitmap.GetBitmapContext()) { WriteIntoBitArray(bank, bitmap, ref outputBits, ref currentIndex); } for (int i = 0; i < cellSizeInBytes * cellsCount;) { Reverse(ref outputBits, i, 8); i += 8; } byte[] bytes = new byte[outputBits.Length / 8]; outputBits.CopyTo(bytes, 0); string fullPath = Path.Combine(outputPath, vo.Name.ToLower() + ".bin"); File.WriteAllBytes(fullPath, bytes); } SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Finishing building banks", OutputMessageType.Information); }
private void LoadBankImage() { if (DataContext is MapViewModel viewModel) { if (viewModel.Banks.Length == 0) { return; } if (!(viewModel.Banks[viewModel.SelectedBank].Model is BankModel model)) { return; } bankViewer.BankImage = BanksUtils.CreateImage(model, ref bankViewer.BitmapCache); } }