public pCpu(pRom romOffset, Level level) : this(level.CreatePointer(romOffset).Value) { }
/// <summary> /// /// </summary> /// <param name="changeInOffset">The distance the beginning data should be written to, relative to the current location.</param> private void ApplyItemData(int changeInOffset) { SortScreenData(); int currentRow = -1; bool lastRow = false; //int currentOffset = originalData.GetFirstRowOffset(); int currentOffset = (int)OffsetItemPointer(changeInOffset); byte[] data = level.Rom.data; // Each row has a pointer to next row. This can't be written until we actually get // to the next row, so we remember where the pointer is so that when we start next // row we can go back and set the pointer. int pendingPointerOffset = -1; for (int i = 0; i < Screens.Count; i++) { Point location = Screens[i].MapLocation; bool lastScreenInRow = (i == Screens.Count - 1) || (Screens[i + 1].MapLocation.Y != Screens[i].MapLocation.Y); if (location.Y != currentRow) { Debug.Assert(currentRow < location.Y); currentRow = location.Y; // Write pointer to this new row: if (pendingPointerOffset != -1) { var pointer = level.CreatePointer((pRom)currentOffset); data[pendingPointerOffset] = pointer.Byte1; data[pendingPointerOffset + 1] = pointer.Byte2; } // Specify map Y data[currentOffset] = (byte)currentRow; currentOffset++; // Mark pointer to next row, and seek past it pendingPointerOffset = currentOffset; currentOffset += 2; } var items = Screens[i].Data.Items; int screenBytes = 3; // 2 for header [mapX, size], 1 for footer [$00] // Calculate size of screen data for (int iItem = 0; iItem < items.Count; iItem++) { screenBytes += items[iItem].Size; } // Write screen header data[currentOffset] = (byte)location.X; currentOffset++; data[currentOffset] = (byte)(lastScreenInRow ? 0xFF : screenBytes); currentOffset++; // Write item data for (int iItem = 0; iItem < items.Count; iItem++) { items[iItem].WriteData(data, ref currentOffset); } data[currentOffset] = 0; currentOffset++; } // Last row has 0xFFFF for a pointer data[pendingPointerOffset] = 0xFF; data[pendingPointerOffset + 1] = 0xFF; }