void Area_Display( tiled_area_ptr area, unsigned char far *buffer ) { int y_map_offset, x_map_offset, y_tile_offset, x_tile_offset, x_buffer_offset, y_buffer_offset, win_x, win_y, win_width, win_height, map_index, map_width, tile_height, tile_width, y_tile_offset_multiplied, x_threshold; unsigned char far * map; map = area->map; // set the global tile width and transparency for Draw_Tile tile_true_width = area->tile_width; tile_transparent = area->transparent; // alias tile size; tile_height = area->tile_height; tile_width = area->tile_width; // alias window coordinates win_x = area->window_x; win_y = area->window_y; win_width = area->window_width; win_height = area->window_height; map_width = area->map_width; // alias map coordinates of upper left hand tile y_map_offset = area->y; x_map_offset = area->x; // alias offsets into upper lefthand tile y_tile_offset = area->y_off; x_tile_offset = area->x_off; // compute unclipped upper left corner of visible area->tiles y_buffer_offset = win_y - y_tile_offset; x_buffer_offset = win_x - x_tile_offset; x_threshold = win_x + win_width - tile_width; // draw the first row, following rows will not need to be top-clipped if(y_buffer_offset < win_y) { // precompute pointer to destination data tile_dest_buffer = buffer + ((win_y << 8) + (win_y << 6) + win_x); // precompute starting map location map_index = y_map_offset * map_width + x_map_offset; // precompute height of row tile_draw_height = tile_height - y_tile_offset; // precompute y offset into tile buffer y_tile_offset_multiplied = y_tile_offset * tile_width; // draw the left-clipped first tile, following area->tiles will need no left clipping if(x_buffer_offsettiles[map[map_index]]) != NULL) { tile_source_buffer += x_tile_offset + y_tile_offset_multiplied; // draw the tile Draw_Tile(); } // move to next column in buffer and in map tile_dest_buffer += tile_draw_width; x_buffer_offset += tile_width; map_index++; } // compute the width of the clipped tile tile_draw_width = tile_width; // draw the unclipped area->tiles in the middle of the row while(x_buffer_offset<=x_threshold) // do computation outside whiles { // point to source tile data, checking for null tile if((tile_source_buffer = area->tiles[map[map_index]]) != NULL) { tile_source_buffer += y_tile_offset_multiplied; // draw the tile Draw_Tile(); } // move to next column in buffer and in map tile_dest_buffer += tile_width; x_buffer_offset += tile_width; map_index++; } // draw the final right-clipped tile if(x_buffer_offset < win_x+win_width) { // point to source tile data, checking for null tile if((tile_source_buffer = area->tiles[map[map_index]]) != NULL) { // compute width tile_draw_width = win_x + win_width - x_buffer_offset; // index into source tile tile_source_buffer += y_tile_offset_multiplied; // draw the tile Draw_Tile(); } } // move to next row in buffer and in map y_buffer_offset += tile_height; y_map_offset++; } // end draw clipped top row //////////////////////////////////////////////////// while(y_buffer_offset <= win_y + win_height-tile_height) { // move x back to left side of screen x_buffer_offset = win_x - x_tile_offset; // precompute pointer to destination data tile_dest_buffer = buffer + (y_buffer_offset << 8) + (y_buffer_offset << 6) + win_x; // precompute starting map location map_index = y_map_offset * map_width + x_map_offset; // precompute height of row tile_draw_height = tile_height; // draw the left-clipped first tile, following area->tiles will need no left clipping if(x_buffer_offsettiles[map[map_index]]) != NULL) { tile_source_buffer += x_tile_offset; // draw the tile Draw_Tile(); } // move to next column in buffer and in map tile_dest_buffer += tile_draw_width; x_buffer_offset += tile_width; map_index++; } // compute the width of the clipped tile tile_draw_width = tile_width; // draw the unclipped area->tiles in the middle of the row while(x_buffer_offset<=x_threshold) // do computation outside whiles { // point to source tile data, checking for null tile if((tile_source_buffer = area->tiles[map[map_index]]) != NULL) // draw the tile Draw_Tile(); // move to next column in buffer and in map tile_dest_buffer += tile_width; x_buffer_offset += tile_width; map_index++; } // draw the final right-clipped tile if(x_buffer_offset < win_x+win_width) { // compute width of last tile tile_draw_width = win_x + win_width - x_buffer_offset; // point to source tile data, checking for null tile if((tile_source_buffer = area->tiles[map[map_index]]) != NULL) // draw the tile Draw_Tile(); } // move to next row in buffer and in map y_buffer_offset += tile_height; y_map_offset++; } // end draw middle rows ////////////////////////////////////////////////////// // draw the final row, bottom clipped if(y_buffer_offset tiles will need no left clipping if(x_buffer_offsettiles[map[map_index]]) != NULL) { tile_source_buffer += x_tile_offset; // draw the tile Draw_Tile(); } // move to next column in buffer and in map tile_dest_buffer += tile_draw_width; x_buffer_offset += tile_width; map_index++; } // compute the width of the clipped tile tile_draw_width = tile_width; // draw the unclipped area->tiles in the middle of the row while(x_buffer_offset<=x_threshold) // do computation outside whiles { // point to source tile data, checking for null tile if((tile_source_buffer = area->tiles[map[map_index]]) != NULL) // draw the tile Draw_Tile(); // move to next column in buffer and in map tile_dest_buffer += tile_width; x_buffer_offset += tile_width; map_index++; } // draw the final right-clipped tile if(x_buffer_offset < win_x+win_width) { // compute width of last tile tile_draw_width = win_x + win_width - x_buffer_offset; // point to source tile data, checking for null tile if((tile_source_buffer = area->tiles[map[map_index]]) != NULL) /// draw the tile Draw_Tile(); } } // end draw bottom row } // end Area_Display