9
function ScreenAdapter(screen_container, bus) {
10
console.assert(screen_container, "1st argument must be a DOM container");
13
graphic_screen = screen_container.getElementsByTagName("canvas")[0],
14
graphic_context = graphic_screen.getContext("2d", {
32
graphic_context["imageSmoothingEnabled"] = false;
34
graphic_screen.style.display = "block";
38
bus.register("screen-set-mode", function(data) {
42
bus.register("screen-fill-buffer-end", function(data) {
43
this.update_buffer(data);
46
bus.register("screen-clear", function() {
49
bus.register("screen-set-size-graphical", function(data) {
50
this.set_size_graphical(data[0], data[1], data[2], data[3]);
54
this.init = function() {
58
this.make_screenshot = function() {
60
const image = new Image();
61
image.src = graphic_screen.toDataURL("image/png");
62
const w = window.open("");
63
w.document.write(image.outerHTML);
67
this.put_char = function(row, col, chr, bg_color, fg_color) {
68
if (row < text_mode_height && col < text_mode_width) {
69
var p = 3 * (row * text_mode_width + col);
71
dbg_assert(chr >= 0 && chr < 0x100);
72
text_mode_data[p] = chr;
73
text_mode_data[p + 1] = bg_color;
74
text_mode_data[p + 2] = fg_color;
76
changed_rows[row] = 1;
80
this.timer = function() {
82
requestAnimationFrame(update_graphical);
86
var update_graphical = function() {
88
this.bus.send("screen-fill-buffer");
92
this.destroy = function() {
96
this.set_mode = function(graphical) {
97
is_graphical = graphical;
100
this.clear_screen = function() {
101
graphic_context.fillStyle = "#000";
102
graphic_context.fillRect(0, 0, graphic_screen.width, graphic_screen.height);
105
this.set_size_graphical = function(width, height, buffer_width, buffer_height) {
106
graphic_screen.style.display = "block";
108
graphic_screen.width = width;
109
graphic_screen.height = height;
112
this.update_buffer = function(layers) {
113
layers.forEach(layer => {
114
graphic_context.putImageData(
116
layer.screen_x - layer.buffer_x,
117
layer.screen_y - layer.buffer_y,