// args: Ynew DEFINE_PATCH_FUNCTION shrink_mos_top BEGIN READ_SHORT 0x0A height height += ( 64 - ( height - Ynew ) ) & 63 EXTEND_MOS TOP height // align new top edge to tile boundry READ_SHORT 0x0C cols READ_SHORT 0x0E rows READ_LONG 0x14 pal_off new_row_cnt = ( ( Ynew + 63 ) >> 6 ) blocks_to_delete = ( ( rows - new_row_cnt ) * cols ) DELETE_BYTES ( pal_off + rows * cols * 1024 ) ( blocks_to_delete * 4 ) // delete leading tile offsets DELETE_BYTES pal_off ( blocks_to_delete * 1024 ) // delete leading palettes WRITE_SHORT 0x0A Ynew WRITE_SHORT 0x0E new_row_cnt END // args: Ynew DEFINE_PATCH_FUNCTION shrink_mos_bottom BEGIN READ_SHORT 0x0A height READ_SHORT 0x0C cols READ_SHORT 0x0E rows READ_LONG 0x14 pal_off new_row_cnt = ( ( Ynew + 63 ) >> 6 ) blocks_to_delete = ( ( rows - new_row_cnt ) * cols ) DELETE_BYTES ( pal_off + new_row_cnt * cols * 1024 ) ( blocks_to_delete * 1024 ) // delete trailing palettes DELETE_BYTES ( pal_off + new_row_cnt * cols * 1028 ) ( blocks_to_delete * 4 ) // delete trailing tile offsets WRITE_SHORT 0x0A Ynew WRITE_SHORT 0x0E new_row_cnt END // args: Ynew DEFINE_PATCH_FUNCTION shrink_mos_vcent BEGIN READ_SHORT 0x0A height LAUNCH_PATCH_FUNCTION shrink_mos_bottom INT_VAR Ynew = ( height - ( ( height - Ynew ) >> 1 ) ) END LAUNCH_PATCH_FUNCTION shrink_mos_top END END // args: Xnew DEFINE_PATCH_FUNCTION shrink_mos_left BEGIN READ_SHORT 0x08 width width += ( ( 64 - ( width - Xnew ) ) & 63 ) EXTEND_MOS LEFT width // align new left edge to tile boundry READ_SHORT 0x0C cols READ_SHORT 0x0E rows new_col_cnt = ( ( Xnew + 63 ) >> 6 ) trim_bytes_pal = ( cols - new_col_cnt ) * 1024 trim_bytes_tile = ( cols - new_col_cnt ) * 4 step_pal = new_col_cnt * 1024 step_tile = ( new_col_cnt * 4 ) - trim_bytes_pal READ_LONG 0x14 pal_off tile_off = pal_off + ( ( rows * cols * 1024 ) - trim_bytes_pal ) FOR( i = 0; i < rows; i += 1 ) BEGIN DELETE_BYTES pal_off trim_bytes_pal pal_off += step_pal DELETE_BYTES tile_off trim_bytes_tile tile_off += step_tile END WRITE_SHORT 0x08 Xnew WRITE_SHORT 0x0C new_col_cnt END // arg: Xnew DEFINE_PATCH_FUNCTION shrink_mos_right BEGIN READ_SHORT 0x08 width READ_SHORT 0x0A height READ_SHORT 0x0C cols READ_SHORT 0x0E rows READ_LONG 0x14 pal_off new_col_cnt = ( ( Xnew + 63 ) >> 6 ) trim_bytes_pal = ( cols - new_col_cnt ) * 1024 trim_bytes_tile = ( cols - new_col_cnt ) * 4 step_pal = new_col_cnt * 1024 step_tile = ( new_col_cnt * 4 ) - trim_bytes_pal step_data = 0 - ( cols - new_col_cnt ) * 1028 tile_off = pal_off + ( rows * cols * 1024 ) data_off = pal_off + ( rows * cols * 1028 ) PATCH_IF( ( width >> 6 ) != ( Xnew >> 6 ) ) BEGIN old_tile_width = 64 END ELSE BEGIN old_tile_width = width & 63 END new_tile_width = Xnew & 63 INSERT_BYTES BUFFER_LENGTH ( rows * new_tile_width * 64 ) FOR( r = 1; r <= rows; r += 1 ) BEGIN pal_off += step_pal DELETE_BYTES pal_off trim_bytes_pal tile_off += step_tile DELETE_BYTES tile_off trim_bytes_tile data_off += step_data PATCH_IF( new_tile_width != 0 ) BEGIN new_tile_data_off = BUFFER_LENGTH - ( 64 * new_tile_width * r ) READ_LONG ( tile_off - 4 ) colorindex_off WRITE_LONG ( tile_off - 4 ) ( new_tile_data_off - data_off ) PATCH_IF( r < ( height >> 6 ) ) BEGIN tile_height = 64 END ELSE BEGIN tile_height = height & 63 END FOR( y = 0; y < tile_height; y += 1 ) BEGIN READ_ASCII (data_off + colorindex_off + (y * old_tile_width)) color_index_array (new_tile_width) WRITE_ASCIIE (new_tile_data_off + (y * new_tile_width)) ~%color_index_array%~ (new_tile_width) END END END WRITE_SHORT 0x08 Xnew WRITE_SHORT 0x0C new_col_cnt END // args: Xnew DEFINE_PATCH_FUNCTION shrink_mos_hcent BEGIN READ_SHORT 0x08 width LAUNCH_PATCH_FUNCTION shrink_mos_right INT_VAR Xnew = ( width - ( ( width - Xnew ) >> 1 ) ) END LAUNCH_PATCH_FUNCTION shrink_mos_left END END // args: Xnew, Ynew DEFINE_PATCH_FUNCTION resize_mos_canvas BEGIN READ_SHORT 0x08 width READ_SHORT 0x0A height PATCH_IF( width < Xnew ) BEGIN EXTEND_MOS HCENT Xnew END PATCH_IF( width > Xnew ) BEGIN LAUNCH_PATCH_FUNCTION shrink_mos_hcent END END PATCH_IF( height < Ynew ) BEGIN EXTEND_MOS VCENT Ynew END PATCH_IF( height > Ynew ) BEGIN LAUNCH_PATCH_FUNCTION shrink_mos_vcent END END END