Emulator core geared towards emulating ZZT and Super ZZT.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

render_software.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Copyright (c) 2018, 2019 Adrian Siekierka
  3. *
  4. * This file is part of Zeta.
  5. *
  6. * Zeta is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Zeta is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Zeta. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include "render_software.h"
  22. #define POS_MUL (scr_width <= 40 ? 2 : 1)
  23. void render_software_rgb(u32 *buffer, int scr_width, int row_length, int flags, u8 *video, u8 *charset, int char_width, int char_height, u32 *palette) {
  24. int pos_mul = POS_MUL;
  25. int pos = 0;
  26. if (row_length < 0) {
  27. row_length = scr_width * char_width * pos_mul;
  28. }
  29. for (int y = 0; y < 25; y++) {
  30. for (int x = 0; x < scr_width; x++, pos += 2) {
  31. u8 chr = video[pos];
  32. u8 col = video[pos + 1];
  33. if (col >= 0x80 && !(flags & RENDER_BLINK_OFF)) {
  34. col &= 0x7F;
  35. if (flags & RENDER_BLINK_PHASE) {
  36. col = (col >> 4) * 0x11;
  37. }
  38. }
  39. u8 bg = col >> 4;
  40. u8 fg = col & 0xF;
  41. u8 *co = charset + (chr * char_height);
  42. for (int cy = 0; cy < char_height; cy++, co++) {
  43. int line = *co;
  44. for (int cx = 0; cx < char_width; cx++, line <<= 1) {
  45. int bpos = ((y * char_height + cy) * row_length) + ((x * char_width + cx) * pos_mul);
  46. int col = palette[(line & 0x80) ? fg : bg];
  47. buffer[bpos] = col;
  48. if (pos_mul == 2) buffer[bpos+1] = col;
  49. }
  50. }
  51. }
  52. }
  53. }
  54. void render_software_paletted(u8 *buffer, int scr_width, int row_length, int flags, u8 *video, u8 *charset, int char_width, int char_height) {
  55. int pos_mul = POS_MUL;
  56. int pos = 0;
  57. if (row_length < 0) {
  58. row_length = scr_width * char_width * pos_mul;
  59. }
  60. for (int y = 0; y < 25; y++) {
  61. for (int x = 0; x < scr_width; x++, pos += 2) {
  62. u8 chr = video[pos];
  63. u8 col = video[pos + 1];
  64. if (col >= 0x80 && !(flags & RENDER_BLINK_OFF)) {
  65. col &= 0x7F;
  66. if (flags & RENDER_BLINK_PHASE) {
  67. col = (col >> 4) * 0x11;
  68. }
  69. }
  70. u8 bg = col >> 4;
  71. u8 fg = col & 0xF;
  72. u8 *co = charset + (chr * char_height);
  73. for (int cy = 0; cy < char_height; cy++, co++) {
  74. int line = *co;
  75. for (int cx = 0; cx < char_width; cx++, line <<= 1) {
  76. int bpos = ((y * char_height + cy) * row_length) + ((x * char_width + cx) * pos_mul);
  77. buffer[bpos] = (line & 0x80) ? fg : bg;
  78. if (pos_mul == 2) {
  79. buffer[bpos+1] = (line & 0x80) ? fg : bg;
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }