analog-firmware/vga/render_dgr.c
David Kuder 08ba4e7911 Unified mono_rendering flag
In preparation for Video7 monochrome mode, add unified flag for mono rendering
2023-04-25 16:20:29 -04:00

188 lines
7.4 KiB
C

#include <pico/stdlib.h>
#include "common/config.h"
#include "vga/vgabuf.h"
#include "vga/render.h"
#include "vga/vgaout.h"
//#define PAGE2SEL (!(soft_switches & SOFTSW_80STORE) && (soft_switches & SOFTSW_PAGE_2))
#define PAGE2SEL ((soft_switches & (SOFTSW_80STORE | SOFTSW_PAGE_2)) == SOFTSW_PAGE_2)
extern uint16_t dhgr_palette[16];
uint8_t DELAYED_COPY_DATA(dgr_dot_pattern)[32] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x08, 0x19, 0x2A, 0x3B, 0x4C, 0x5D, 0x6E, 0x7F,
0x00, 0x44, 0x08, 0x4C, 0x11, 0x55, 0x19, 0x5D,
0x22, 0x66, 0x2A, 0x6E, 0x33, 0x77, 0x3B, 0x7F,
};
static void render_dgr_line(bool p2, uint line);
void DELAYED_COPY_CODE(render_dgr)() {
for(uint line=0; line < 24; line++) {
render_dgr_line(PAGE2SEL, line);
}
}
void DELAYED_COPY_CODE(render_mixed_dgr)() {
for(uint line=0; line < 20; line++) {
render_dgr_line(PAGE2SEL, line);
}
for(uint line=20; line < 24; line++) {
if(soft_switches & SOFTSW_80COL) {
render_text80_line(PAGE2SEL, line);
} else {
render_text40_line(PAGE2SEL, line);
}
}
}
static void DELAYED_COPY_CODE(render_dgr_line)(bool p2, uint line) {
// Construct two scanlines for the two different colored cells at the same time
struct vga_scanline *sl1 = vga_prepare_scanline();
struct vga_scanline *sl2 = vga_prepare_scanline();
uint sl_pos = 0;
uint i, j;
uint32_t color1, color2;
uint_fast8_t dotc = 0;
uint32_t pixeldata;
const uint8_t *line_bufa = (const uint8_t *)((p2 ? text_p2 : text_p1) + ((line & 0x7) << 7) + (((line >> 3) & 0x3) * 40));
const uint8_t *line_bufb = (const uint8_t *)((p2 ? text_p4 : text_p3) + ((line & 0x7) << 7) + (((line >> 3) & 0x3) * 40));
// Pad 40 pixels on the left to center horizontally
sl1->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 16 pixels per word
sl2->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 16 pixels per word
sl_pos++;
sl1->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 16 pixels per word
sl2->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 16 pixels per word
sl_pos++;
sl1->data[sl_pos] = (text_border|THEN_EXTEND_3) | ((text_border|THEN_EXTEND_3) << 16); // 8 pixels per word
sl2->data[sl_pos] = (text_border|THEN_EXTEND_3) | ((text_border|THEN_EXTEND_3) << 16); // 8 pixels per word
sl_pos++;
i = 0;
if(mono_rendering) {
while(i < 40) {
while((dotc <= 18) && (i < 40)) {
color1 |= dgr_dot_pattern[((i & 1) << 4) | (line_bufb[i] & 0xf)] << dotc;
color2 |= dgr_dot_pattern[((i & 1) << 4) | ((line_bufb[i] >> 4) & 0xf)] << dotc;
dotc += 7;
color1 |= dgr_dot_pattern[((i & 1) << 4) | (line_bufa[i] & 0xf)] << dotc;
color2 |= dgr_dot_pattern[((i & 1) << 4) | ((line_bufa[i] >> 4) & 0xf)] << dotc;
dotc += 7;
i++;
}
// Consume pixels
while(dotc >= 2) {
pixeldata = ((color1 & 1) ? (text_fore) : (text_back));
pixeldata |= (((color1 & 2) ? (text_fore) : (text_back))) << 16;
sl1->data[sl_pos] = pixeldata;
pixeldata = ((color2 & 1) ? (text_fore) : (text_back));
pixeldata |= (((color2 & 2) ? (text_fore) : (text_back))) << 16;
sl2->data[sl_pos] = pixeldata;
color1 >>= 2;
color2 >>= 2;
sl_pos++;
dotc -= 2;
}
}
} else {
// Preload the first 14 subpixels
color1 = dgr_dot_pattern[line_bufb[i] & 0xf] << dotc;
color2 = dgr_dot_pattern[(line_bufb[i] >> 4) & 0xf] << dotc;
dotc += 7;
color1 |= dgr_dot_pattern[(line_bufa[i] & 0xf)] << dotc;
color2 |= dgr_dot_pattern[((line_bufa[i] >> 4) & 0xf)] << dotc;
dotc += 7;
i++;
// First two pixels
pixeldata = dhgr_palette[0];
pixeldata |= ((dhgr_palette[color1 & 0xf] >> 1) & _RGBHALF) << 16;
sl1->data[sl_pos] = pixeldata;
pixeldata = dhgr_palette[0];
pixeldata |= ((dhgr_palette[color1 & 0xf] >> 1) & _RGBHALF) << 16;
sl2->data[sl_pos] = pixeldata;
sl_pos++;
while(i < 40) {
// Load in as many subpixels as possible
while((dotc <= 18) && (i < 40)) {
color1 |= dgr_dot_pattern[((i & 1) << 4) | (line_bufb[i] & 0xf)] << dotc;
color2 |= dgr_dot_pattern[((i & 1) << 4) | ((line_bufb[i] >> 4) & 0xf)] << dotc;
dotc += 7;
color1 |= dgr_dot_pattern[((i & 1) << 4) | (line_bufa[i] & 0xf)] << dotc;
color2 |= dgr_dot_pattern[((i & 1) << 4) | ((line_bufa[i] >> 4) & 0xf)] << dotc;
dotc += 7;
i++;
}
// Consume pixels
while(dotc >= 8) {
pixeldata = (dhgr_palette[color1 & 0xf]);
pixeldata |= ((dhgr_palette[color1 & 0xf] >> 1) & _RGBHALF) << 16;
sl1->data[sl_pos] = pixeldata;
pixeldata = (dhgr_palette[color2 & 0xf]);
pixeldata |= ((dhgr_palette[color2 & 0xf] >> 1) & _RGBHALF) << 16;
sl2->data[sl_pos] = pixeldata;
sl_pos++;
pixeldata = (dhgr_palette[(color1 & 0xc) | ((color1 & 0x30) >> 4)]);
pixeldata |= ((dhgr_palette[(color1 & 0xf0) >> 4] >> 1) & _RGBHALF) << 16;
sl1->data[sl_pos] = pixeldata;
pixeldata = (dhgr_palette[(color2 & 0xc) | ((color2 & 0x30) >> 4)]);
pixeldata |= ((dhgr_palette[(color2 & 0xf0) >> 4] >> 1) & _RGBHALF) << 16;
sl2->data[sl_pos] = pixeldata;
sl_pos++;
color1 >>= 4;
color2 >>= 4;
dotc -= 4;
}
}
// Last two pixels
pixeldata = (dhgr_palette[color1 & 0xf]);
pixeldata |= ((dhgr_palette[color1 & 0xf] >> 1) & _RGBHALF) << 16;
sl1->data[sl_pos] = pixeldata;
pixeldata = (dhgr_palette[color2 & 0xf]);
pixeldata |= ((dhgr_palette[color2 & 0xf] >> 1) & _RGBHALF) << 16;
sl2->data[sl_pos] = pixeldata;
sl_pos++;
}
// Pad 40 pixels on the right to center horizontally
sl1->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 16 pixels per word
sl2->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 16 pixels per word
sl_pos++;
sl1->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 16 pixels per word
sl2->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 16 pixels per word
sl_pos++;
sl1->data[sl_pos] = (text_border|THEN_EXTEND_3) | ((text_border|THEN_EXTEND_3) << 16); // 8 pixels per word
sl2->data[sl_pos] = (text_border|THEN_EXTEND_3) | ((text_border|THEN_EXTEND_3) << 16); // 8 pixels per word
sl_pos++;
sl1->length = sl_pos;
sl1->repeat_count = 7;
vga_submit_scanline(sl1);
sl2->length = sl_pos;
sl2->repeat_count = 7;
vga_submit_scanline(sl2);
}