public int block_reserve_CHRs(int _block_ind, data_sets_manager _data_manager) { int CHR_pos = 0; ushort block_data = 0; if (_block_ind >= 0) { tiles_data data = _data_manager.get_tiles_data(_data_manager.tiles_data_pos); if (data.block_sum(_block_ind) != 0) { if (MainForm.message_box("All the block's CHR links will be replaced!", "Reserve CHRs", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { return(-1); } } // reset block's links for (int i = 0; i < utils.CONST_BLOCK_SIZE; i++) { data.blocks[(_block_ind << 2) + i] = 0; } int ff_block_ind = data.get_first_free_block_id(false) << 2; ff_block_ind = ff_block_ind < 4 ? 4:ff_block_ind; int block_n; for (int CHR_n = 1; CHR_n < platform_data.get_CHR_bank_max_sprites_cnt(); CHR_n++) { if (data.spr8x8_sum(CHR_n) == 0) { for (block_n = 4; block_n < ff_block_ind; block_n++) { if (tiles_data.get_block_CHR_id(data.blocks[block_n]) == CHR_n) { break; } } if (block_n == ff_block_ind || ff_block_ind == 4) { data.blocks[(_block_ind << 2) + CHR_pos++] = tiles_data.set_block_CHR_id(CHR_n, block_data); if (CHR_pos == utils.CONST_BLOCK_SIZE) { m_block_editor.set_selected_block(_block_ind, data); MainForm.set_status_msg(String.Format("Block Editor: Block #{0:X2} data reserved", _block_ind)); return(1); } } } } MainForm.message_box("Block Editor: CHR bank is full!", "Reserve Blocks", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(-1); }
public int tile_reserve_blocks(data_sets_manager _data_manager) { int block_pos = 0; int sel_tile = get_selected_tile(); if (sel_tile >= 0) { tiles_data data = _data_manager.get_tiles_data(_data_manager.tiles_data_pos); if (data.tiles[sel_tile] != 0) { if (MainForm.message_box("All the tile's block links will be replaced!", "Reserve Blocks", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { return(-1); } } bool reserve_blocks_CHRs = false; if (MainForm.message_box("Reserve CHRs?", "Reserve Blocks", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { reserve_blocks_CHRs = true; } // reset tile's links if (reserve_blocks_CHRs) { int block_data_offs; for (int i = 0; i < utils.CONST_BLOCK_SIZE; i++) { block_data_offs = data.get_tile_block(sel_tile, i) << 2; data.blocks[block_data_offs] = 0; data.blocks[block_data_offs + 1] = 0; data.blocks[block_data_offs + 2] = 0; data.blocks[block_data_offs + 3] = 0; } } data.tiles[sel_tile] = 0; int ff_tile_ind = data.get_first_free_tile_id(false); int tile_n; int block_pos_n; for (int block_n = 1; block_n < platform_data.get_max_blocks_cnt(); block_n++) { if (data.block_sum(block_n) == 0) { // check if 'zero' block is busy for (tile_n = 1; tile_n < ff_tile_ind; tile_n++) { for (block_pos_n = 0; block_pos_n < utils.CONST_TILE_SIZE; block_pos_n++) { if (data.get_tile_block(tile_n, block_pos_n) == block_n) { // 'zero' block is busy break; } } if (block_pos_n != utils.CONST_TILE_SIZE) { // 'zero' block is busy break; } } // 'zero' block isn't in use OR tiles list is empty if (tile_n == ff_tile_ind || ff_tile_ind == 0) { data.set_tile_block(sel_tile, block_pos++, ( ushort )block_n); if (reserve_blocks_CHRs) { block_reserve_CHRs(block_n, _data_manager); } if (block_pos == utils.CONST_TILE_SIZE) { m_tile_editor.set_selected_tile(sel_tile, data); MainForm.set_status_msg(String.Format("Tile Editor: Tile #{0:X2} data reserved", sel_tile)); return(data.get_tile_block(sel_tile, m_tile_editor.get_selected_block_pos())); } } } } MainForm.message_box("Tile Editor: Block list is full!", "Reserve Blocks", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(-1); }