dummy_screen.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. "use strict";
  2. /**
  3. * @constructor
  4. *
  5. * @param {BusConnector} bus
  6. */
  7. function DummyScreenAdapter(bus)
  8. {
  9. var
  10. graphic_image_data,
  11. /** @type {number} */
  12. cursor_row,
  13. /** @type {number} */
  14. cursor_col,
  15. graphical_mode_width,
  16. graphical_mode_height,
  17. // are we in graphical mode now?
  18. is_graphical = false,
  19. // Index 0: ASCII code
  20. // Index 1: Background color
  21. // Index 2: Foreground color
  22. text_mode_data,
  23. // number of columns
  24. text_mode_width,
  25. // number of rows
  26. text_mode_height;
  27. this.bus = bus;
  28. bus.register("screen-set-mode", function(data)
  29. {
  30. this.set_mode(data);
  31. }, this);
  32. bus.register("screen-fill-buffer-end", function(data)
  33. {
  34. var min = data[0];
  35. var max = data[1];
  36. this.update_buffer(min, max);
  37. }, this);
  38. bus.register("screen-put-char", function(data)
  39. {
  40. //console.log(data);
  41. this.put_char(data[0], data[1], data[2], data[3], data[4]);
  42. }, this);
  43. bus.register("screen-text-scroll", function(rows)
  44. {
  45. console.log("scroll", rows);
  46. }, this);
  47. bus.register("screen-update-cursor", function(data)
  48. {
  49. this.update_cursor(data[0], data[1]);
  50. }, this);
  51. bus.register("screen-update-cursor-scanline", function(data)
  52. {
  53. this.update_cursor_scanline(data[0], data[1]);
  54. }, this);
  55. bus.register("screen-set-size-text", function(data)
  56. {
  57. this.set_size_text(data[0], data[1]);
  58. }, this);
  59. bus.register("screen-set-size-graphical", function(data)
  60. {
  61. this.set_size_graphical(data[0], data[1]);
  62. }, this);
  63. this.put_char = function(row, col, chr, bg_color, fg_color)
  64. {
  65. if(row < text_mode_height && col < text_mode_width)
  66. {
  67. var p = 3 * (row * text_mode_width + col);
  68. text_mode_data[p] = chr;
  69. text_mode_data[p + 1] = bg_color;
  70. text_mode_data[p + 2] = fg_color;
  71. }
  72. };
  73. this.destroy = function()
  74. {
  75. };
  76. this.set_mode = function(graphical)
  77. {
  78. is_graphical = graphical;
  79. };
  80. this.clear_screen = function()
  81. {
  82. };
  83. /**
  84. * @param {number} cols
  85. * @param {number} rows
  86. */
  87. this.set_size_text = function(cols, rows)
  88. {
  89. if(cols === text_mode_width && rows === text_mode_height)
  90. {
  91. return;
  92. }
  93. text_mode_data = new Int32Array(cols * rows * 3);
  94. text_mode_width = cols;
  95. text_mode_height = rows;
  96. };
  97. this.set_size_graphical = function(width, height)
  98. {
  99. graphical_mode_width = width;
  100. graphical_mode_height = height;
  101. };
  102. this.set_scale = function(s_x, s_y)
  103. {
  104. };
  105. this.update_cursor_scanline = function(start, end)
  106. {
  107. };
  108. this.update_cursor = function(row, col)
  109. {
  110. if(row !== cursor_row || col !== cursor_col)
  111. {
  112. cursor_row = row;
  113. cursor_col = col;
  114. }
  115. };
  116. this.update_buffer = function(min, max)
  117. {
  118. if(max < min)
  119. {
  120. return;
  121. }
  122. var min_y = min / graphical_mode_width | 0;
  123. var max_y = max / graphical_mode_width | 0;
  124. };
  125. this.get_text_screen = function()
  126. {
  127. var screen = [];
  128. for(var i = 0; i < text_mode_height; i++)
  129. {
  130. screen.push(this.get_text_row(i));
  131. }
  132. return screen;
  133. };
  134. this.get_text_row = function(i)
  135. {
  136. var row = "";
  137. var offset = 3 * i * text_mode_width;
  138. for(var j = 0; j < text_mode_width; j++)
  139. {
  140. row += String.fromCharCode(text_mode_data[offset + 3 * j]);
  141. }
  142. return row;
  143. };
  144. }