public screen_data copy() { screen_data data = new screen_data(m_width, m_height); Array.Copy(m_arr, data.m_arr, length); return(data); }
public void reset() { m_name = null; if (m_data != null) { m_data.reset(); m_data = null; } }
public static screen_data load(BinaryReader _br, byte _ver) { int width; int height; if (_ver < 5) { width = _br.ReadByte(); height = _br.ReadByte(); } else { width = _br.ReadInt32(); height = _br.ReadInt32(); } screen_data data = new screen_data(width, height); data.load(_br, _ver, -1, -1); return(data); }
public pattern_data(string _name, screen_data _data) { m_name = _name; m_data = _data; }
public bool equal(screen_data _scr) { return(System.Linq.Enumerable.SequenceEqual(m_arr, _scr.m_arr)); }
private void blocks_to_tiles() { tiles_data data; pattern_data pattern; screen_data new_pattern; screen_data new_scr; int ptrn_width; int ptrn_height; int i; int scr_n; int data_n; int ptrn_n; int tile_n; int tile_x; int tile_y; int tile_offs; ulong tile; ulong tile_mask; ushort tile_ind; ushort tile_val0; ushort tile_val1; ushort tile_val2; ushort tile_val3; bool tiles_arr_overflow = false; bool valid_x_pos; string ptrn_invalid_size_str = ""; string ptrn_invalid_tile_str = ""; List <screen_data> screens; ulong[] tiles; int half_tile_x = platform_data.get_half_tile_x(); int half_tile_y = platform_data.get_half_tile_y(); Dictionary <int, List <screen_data> > bank_id_screens = new Dictionary <int, List <screen_data> >(tiles_data_cnt); Dictionary <int, ulong[]> bank_id_tiles = new Dictionary <int, ulong[]>(tiles_data_cnt); for (data_n = 0; data_n < tiles_data_cnt; data_n++) { data = get_tiles_data(data_n); screens = new List <screen_data>(data.screen_data_cnt()); tiles = new ulong[platform_data.get_max_tiles_cnt()]; Array.Clear(tiles, 0, tiles.Length); tile_ind = 0; // convert screens and fill tile arrays for (scr_n = 0; scr_n < data.screen_data_cnt(); scr_n++) { new_scr = new screen_data(EScreenDataType.sdt_Tiles4x4); for (tile_n = 0; tile_n < platform_data.get_screen_tiles_cnt(); tile_n++) { tile_mask = 0xffffffffffffffff; tile_x = tile_n % platform_data.get_screen_tiles_width(); tile_y = tile_n / platform_data.get_screen_tiles_width(); tile_offs = (tile_x << 1) + ((tile_y << 1) * platform_data.get_screen_blocks_width()); tile_val0 = data.get_screen_tile(scr_n, tile_offs); valid_x_pos = ((tile_x << 1) + 1) < platform_data.get_screen_blocks_width(); tile_val1 = valid_x_pos ? data.get_screen_tile(scr_n, tile_offs + 1):( ushort )0; if (((half_tile_y >= 0) && (tile_y < half_tile_y)) || (half_tile_y < 0)) { tile_val2 = data.get_screen_tile(scr_n, tile_offs + platform_data.get_screen_blocks_width()); tile_val3 = valid_x_pos ? data.get_screen_tile(scr_n, tile_offs + platform_data.get_screen_blocks_width() + 1):( ushort )0; } else { tile_val2 = tile_val3 = 0; tile_mask &= 0xffffffff00000000; } if (tile_x == platform_data.get_half_tile_x()) { tile_val1 = tile_val3 = 0; tile_mask &= 0xffff0000ffff0000; } tile = tiles_data.set_tile_data(tile_val0, tile_val1, tile_val2, tile_val3); // check new tile for (i = 0; i < tile_ind; i++) { if ((tiles[i] & tile_mask) == (tile & tile_mask)) { break; } } if (i == tile_ind) { if (tile_ind == platform_data.get_max_tiles_cnt()) { tiles_arr_overflow = true; goto free_data; } new_scr.set_tile(tile_x + tile_y * platform_data.get_screen_tiles_width(), tile_ind); tiles[tile_ind++] = tile; } else { new_scr.set_tile(tile_x + tile_y * platform_data.get_screen_tiles_width(), ( ushort )i); } } screens.Add(new_scr); } bank_id_screens[data_n] = screens; bank_id_tiles[data_n] = tiles; // convert tiles patterns foreach (string key in data.patterns_data.Keys) { List <pattern_data> pattrn_list = data.patterns_data[key] as List <pattern_data>; for (ptrn_n = 0; ptrn_n < pattrn_list.Count; ptrn_n++) { pattern = pattrn_list[ptrn_n]; if ((pattern.width & 0x01) != 0 || (pattern.height & 0x01) != 0) { ptrn_invalid_size_str += pattern.name + " / CHR bank: " + data_n + "\n"; pattern.name = "BAD~" + pattern.name; } else { ptrn_width = pattern.width >> 1; ptrn_height = pattern.height >> 1; new_pattern = new screen_data(ptrn_width, ptrn_height); for (tile_n = 0; tile_n < new_pattern.length; tile_n++) { tile_x = tile_n % ptrn_width; tile_y = tile_n / ptrn_width; tile_offs = (tile_x << 1) + ((tile_y << 1) * pattern.width); tile_val0 = pattern.data.get_tile(tile_offs); tile_val1 = pattern.data.get_tile(tile_offs + 1); tile_val2 = pattern.data.get_tile(tile_offs + pattern.width); tile_val3 = pattern.data.get_tile(tile_offs + pattern.width + 1); tile = tiles_data.set_tile_data(tile_val0, tile_val1, tile_val2, tile_val3); // get tile index for (i = 0; i < tile_ind; i++) { if (tiles[i] == tile) { break; } } if (i == tile_ind) { ptrn_invalid_tile_str += pattern.name + " / CHR bank: " + data_n + "\n"; pattern.name = "BAD~" + pattern.name; } else { new_pattern.set_tile(tile_x + tile_y * ptrn_width, ( ushort )i); } } pattrn_list[ptrn_n] = new pattern_data(pattern.name, new_pattern); pattern.reset(); } } } if (ptrn_invalid_size_str.Length > 0 || ptrn_invalid_tile_str.Length > 0) { MainForm.message_box((ptrn_invalid_size_str.Length > 0 ? "Invalid size:\n\n" + ptrn_invalid_size_str + "\n":"") + (ptrn_invalid_tile_str.Length > 0 ? "Invalid data:\n\n" + ptrn_invalid_tile_str + "\n":"") + "Invalid pattern(s) will be market as 'BAD~'", "Invalid Tiles Patterns Detected", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } // commit new data for (data_n = 0; data_n < tiles_data_cnt; data_n++) { data = get_tiles_data(data_n); // update tiles & screens Array.Copy(bank_id_tiles[data_n] as ulong[], data.tiles, platform_data.get_max_tiles_cnt()); for (scr_n = 0; scr_n < data.screen_data_cnt(); scr_n++) { data.screen_data_replace(scr_n, bank_id_screens[data_n][scr_n]); bank_id_screens[data_n][scr_n] = null; } bank_id_screens[data_n].Clear(); } free_data: { foreach (var key in bank_id_screens.Keys) { (bank_id_screens[key] as List <screen_data>).Clear(); } ; bank_id_screens.Clear(); bank_id_tiles.Clear(); } if (tiles_arr_overflow) { throw new Exception("Tiles array overflow!\nCHR bank: " + data_n); } }
private void tiles_to_blocks() { tiles_data data = null; screen_data new_pattern = null; pattern_data pattern = null; screen_data new_scr; int data_n; int ptrn_n; int scr_n; int tile_n; int block_n; int x_pos; int y_pos; for (data_n = 0; data_n < tiles_data_cnt; data_n++) { data = get_tiles_data(data_n); // convert screens for (scr_n = 0; scr_n < data.screen_data_cnt(); scr_n++) { new_scr = new screen_data(EScreenDataType.sdt_Blocks2x2); for (tile_n = 0; tile_n < platform_data.get_screen_tiles_cnt(); tile_n++) { for (block_n = 0; block_n < utils.CONST_BLOCK_SIZE; block_n++) { x_pos = ((tile_n % platform_data.get_screen_tiles_width()) << 1) + (block_n & 0x01); y_pos = ((tile_n / platform_data.get_screen_tiles_width()) << 1) + ((block_n & 0x02) >> 1); if ((y_pos < platform_data.get_screen_blocks_height()) && (x_pos < platform_data.get_screen_blocks_width())) { new_scr.set_tile((y_pos * platform_data.get_screen_blocks_width()) + x_pos, utils.get_ushort_from_ulong(data.tiles[data.get_screen_tile(scr_n, tile_n)], block_n)); } } } data.screen_data_replace(scr_n, new_scr); } // convert tiles patterns foreach (string key in data.patterns_data.Keys) { List <pattern_data> pattrn_list = data.patterns_data[key] as List <pattern_data>; for (ptrn_n = 0; ptrn_n < pattrn_list.Count; ptrn_n++) { pattern = pattrn_list[ptrn_n]; new_pattern = new screen_data(pattern.width << 1, pattern.height << 1); for (tile_n = 0; tile_n < pattern.data.length; tile_n++) { for (block_n = 0; block_n < utils.CONST_BLOCK_SIZE; block_n++) { new_pattern.set_tile(((((tile_n / pattern.width) << 1) + ((block_n & 0x02) >> 1)) * (pattern.width << 1)) + ((tile_n % pattern.width) << 1) + (block_n & 0x01), utils.get_ushort_from_ulong(data.tiles[pattern.data.get_tile(tile_n)], block_n)); } } pattrn_list[ptrn_n] = new pattern_data(pattern.name, new_pattern); pattern.reset(); } } Array.Clear(data.tiles, 0, data.tiles.Length); } }