Tidyup: screen adapter layer update code

This commit is contained in:
Ernest Wong 2018-01-16 17:49:09 +13:00 committed by Fabian
parent 2397608a2b
commit eaa90a8c89
2 changed files with 42 additions and 25 deletions

View file

@ -65,6 +65,7 @@ function ScreenAdapter(screen_container, bus)
text_mode_height;
var layers = [];
var layers_has_changed = false;
var screen = this;
@ -171,7 +172,8 @@ function ScreenAdapter(screen_container, bus)
bus.register("screen-update-layers", function(data)
{
this.layers = data;
layers = data;
layers_has_changed = true;
}, this);
bus.register("screen-set-size-text", function(data)
@ -180,15 +182,6 @@ function ScreenAdapter(screen_container, bus)
}, this);
bus.register("screen-set-size-graphical", function(data)
{
if(DEBUG_SCREEN_LAYERS)
{
data[0] = data[3];
data[1] = data[4];
}
if(!data[0]) data[0] = 1;
if(!data[1]) data[1] = 1;
if(!data[3]) data[3] = data[0];
if(!data[4]) data[4] = data[1];
this.set_size_graphical(data[0], data[1], data[3], data[4]);
}, this);
@ -312,6 +305,15 @@ function ScreenAdapter(screen_container, bus)
this.set_size_graphical = function(width, height, buffer_width, buffer_height)
{
if(DEBUG_SCREEN_LAYERS)
{
// Draw the entire buffer. Useful for debugging
// panning / page flipping / screen splitting code for both
// v86 developers and os developers
width = buffer_width;
height = buffer_height;
}
graphic_screen.style.display = "block";
graphic_screen.width = width;
@ -330,7 +332,7 @@ function ScreenAdapter(screen_container, bus)
graphical_mode_width = width;
graphical_mode_height = height;
this.layers =
layers =
[{
screen_x: 0, screen_y: 0,
buffer_x: 0, buffer_y: 0,
@ -510,31 +512,29 @@ function ScreenAdapter(screen_container, bus)
this.update_buffer = function(min, max)
{
/*if(max < min)
if(max < min && !layers_has_changed)
{
return;
}
var min_y = min / graphical_mode_width | 0;
var max_y = max / graphical_mode_width | 0;
layers_has_changed = false;
graphic_context.putImageData(
graphic_image_data,
0, 0,
0, min_y,
graphical_mode_width, max_y - min_y + 1
);
*/
this.clear_screen();
if(DEBUG_SCREEN_LAYERS)
{
// Draw the entire buffer. Useful for debugging
// panning / page flipping / screen splitting code for both
// v86 developers and os developers
graphic_context.putImageData(
graphic_image_data,
0, 0
);
// For each visible layer that would've been drawn, draw a
// rectangle to visualise the layer instead.
graphic_context.strokeStyle = "#0F0";
graphic_context.lineWidth = 4;
this.layers.forEach((layer) =>
layers.forEach((layer) =>
{
graphic_context.strokeRect(
layer.buffer_x,
@ -546,7 +546,7 @@ function ScreenAdapter(screen_container, bus)
graphic_context.lineWidth = 1;
return;
}
this.layers.forEach((layer) =>
layers.forEach((layer) =>
{
graphic_context.putImageData(
graphic_image_data,

View file

@ -1254,6 +1254,13 @@ VGAScreen.prototype.update_vga_size = function()
var vertical_scans = Math.min(1 + this.vertical_display_enable_end,
this.vertical_blank_start);
if(!horizontal_characters || !vertical_scans)
{
// Don't update if width or height is zero.
// These happen when registers are not fully configured yet.
return;
}
if(this.graphical_mode)
{
this.svga_width = horizontal_characters << 3;
@ -2461,7 +2468,7 @@ VGAScreen.prototype.screen_fill_buffer = function()
if(!this.graphical_mode)
{
// text mode
// Update anyway - programs waiting for signal before
// Update retrace behaviour anyway - programs waiting for signal before
// changing to graphical mode
this.update_vertical_retrace();
return;
@ -2470,7 +2477,17 @@ VGAScreen.prototype.screen_fill_buffer = function()
if(!this.dest_buffer)
{
dbg_log("Cannot fill buffer: No destination buffer", LOG_VGA);
// Update anyway
// Update retrace behaviour anyway
this.update_vertical_retrace();
return;
}
if(this.diff_addr_max < this.diff_addr_min &&
this.diff_plot_max < this.diff_plot_min &&
!this.dac_changed_colors.length)
{
// No pixels to update
this.bus.send("screen-fill-buffer-end", [1, 0]);
this.update_vertical_retrace();
return;
}