int CHRs_optimization(tiles_data _data, bool _check) { int deleted_CHRs_cnt = 0; int CHR_data_sum; byte[] img_buff = new byte[utils.CONST_SPR8x8_TOTAL_PIXELS_CNT]; int size_offs; int size = _data.get_first_free_spr8x8_id(false); for (int CHR_n = 0; CHR_n < size; CHR_n++) { if (check_blocks_CHR(CHR_n, _data) == false) { CHR_data_sum = _data.spr8x8_sum(CHR_n); if (CHR_data_sum != 0) { ++deleted_CHRs_cnt; } if (_check == true) { continue; } // delete useless CHR { size_offs = platform_data.get_CHR_bank_max_sprites_cnt() - 1; for (int i = CHR_n; i < size_offs; i++) { _data.from_CHR_bank_to_spr8x8(i + 1, img_buff, 0); _data.from_spr8x8_to_CHR_bank(i, img_buff); } } // the last CHR is an empty space { #if DEF_ZX for (int i = 0; i < img_buff.Length; i++) { img_buff[i] = utils.CONST_ZX_DEFAULT_PAPER_COLOR; } #else Array.Clear(img_buff, 0, utils.CONST_SPR8x8_TOTAL_PIXELS_CNT); #endif _data.from_spr8x8_to_CHR_bank(platform_data.get_CHR_bank_max_sprites_cnt() - 1, img_buff); } shift_CHRs_data(CHR_n, _data); --CHR_n; --size; } } return(deleted_CHRs_cnt); }
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); }