Skip to content

Commit

Permalink
swap r and b bits in artifact processing
Browse files Browse the repository at this point in the history
  • Loading branch information
IanSB committed Mar 9, 2022
1 parent 7a7347c commit bd11b81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
42 changes: 13 additions & 29 deletions src/capture_line_ntsc_8bpp.S
Expand Up @@ -1320,56 +1320,40 @@ loop_8bppd_auto:
.macro CAPTURE_SIX_BITS_16BPP_0 reg
// Pixel 0 in GPIO 7.. 2 -> 7.. 0
// Pixel 1 in GPIO 13.. 8 -> 15.. 8
mov \reg, #0
tst r8, #(0x01 << PIXEL_BASE)
orrne \reg, #0x04
tst r8, #(0x02 << PIXEL_BASE)
orrne \reg, #0x02
tst r8, #(0x04 << PIXEL_BASE)
orrne \reg, #0x01
and r9, r8, #(0x07 << PIXEL_BASE)
tst r8, #(0x10 << PIXEL_BASE)
orrne \reg, #0x08
orrne r9, r9, #(0x08 << PIXEL_BASE)
mov \reg, r9, lsr #PIXEL_BASE
.endm

.macro CAPTURE_SIX_BITS_16BPP_1 reg
// Pixel 2 in GPIO 7.. 2 -> 23..16
// Pixel 3 in GPIO 13.. 8 -> 31..24
tst r8, #(0x01 << (PIXEL_BASE + 6))
orrne \reg, #0x0400
tst r8, #(0x02 << (PIXEL_BASE + 6))
orrne \reg, #0x0200
tst r8, #(0x04 << (PIXEL_BASE + 6))
orrne \reg, #0x0100
and r9, r8, #(0x07 << (PIXEL_BASE + 6))
tst r8, #(0x10 << (PIXEL_BASE + 6))
orrne \reg, #0x0800
orrne r9, r9, #(0x08 << (PIXEL_BASE + 6))
orr \reg, \reg, r9, lsl #(8 - (PIXEL_BASE + 6))
.endm

.macro CAPTURE_SIX_BITS_16BPP_2 reg
// Pixel 0 in GPIO 7.. 2 -> 7.. 0
// Pixel 1 in GPIO 13.. 8 -> 15.. 8
tst r8, #(0x01 << PIXEL_BASE)
orrne \reg, #0x040000
tst r8, #(0x02 << PIXEL_BASE)
orrne \reg, #0x020000
tst r8, #(0x04 << PIXEL_BASE)
orrne \reg, #0x010000
and r9, r8, #(0x07 << PIXEL_BASE)
tst r8, #(0x10 << PIXEL_BASE)
orrne \reg, #0x080000
orrne r9, r9, #(0x08 << PIXEL_BASE)
orr \reg, \reg, r9, lsl #(16 - PIXEL_BASE)
.endm

.macro CAPTURE_SIX_BITS_16BPP_3 reg
// Pixel 2 in GPIO 7.. 2 -> 23..16
// Pixel 3 in GPIO 13.. 8 -> 31..24
tst r8, #(0x01 << (PIXEL_BASE + 6))
orrne \reg, #0x04000000
tst r8, #(0x02 << (PIXEL_BASE + 6))
orrne \reg, #0x02000000
tst r8, #(0x04 << (PIXEL_BASE + 6))
orrne \reg, #0x01000000
and r9, r8, #(0x07 << (PIXEL_BASE + 6))
tst r8, #(0x10 << (PIXEL_BASE + 6))
orrne \reg, #0x08000000
orrne r9, r9, #(0x08 << (PIXEL_BASE + 6))
orr \reg, \reg, r9, lsl #(24 - (PIXEL_BASE + 6))
.endm


.global cga_process_artifact
.global cga_render_words

Expand Down
15 changes: 11 additions & 4 deletions src/vid_cga_comp.c
Expand Up @@ -76,6 +76,13 @@ double max_v;
int video_ri, video_rq, video_gi, video_gq, video_bi, video_bq;
static int ntsc_type;

unsigned int swap_R_B(int IRGB) {
//r & b are swapped in RGBtoHDMI so rearrange to match
int r_new = (IRGB & 0x04) >> 2;
int ig_new = (IRGB & 0x0a);
int b_new = (IRGB & 0x01) << 2;
return b_new | ig_new | r_new;
}

void update_cga16_color() {
int x;
Expand Down Expand Up @@ -155,8 +162,8 @@ void update_cga16_color() {

for (x = 0; x < 1024; ++x) {
int phase = (x + ntsc_pixel_phase) & 3;
int right = (x >> 2) & 15;
int left = (x >> 6) & 15;
int right = swap_R_B((x >> 2) & 0x0f);
int left = swap_R_B((x >> 6) & 0x0f);
int rc = right;
int lc = left;
//if ((cgamode & 4) != 0) {
Expand All @@ -176,8 +183,8 @@ void update_cga16_color() {
CGA_Composite_Table[x] = (int) (v*mode_contrast + mode_brightness);
}

i = CGA_Composite_Table[6*68] - CGA_Composite_Table[6*68 + 2];
q = CGA_Composite_Table[6*68 + 1] - CGA_Composite_Table[6*68 + 3];
i = CGA_Composite_Table[3*68] - CGA_Composite_Table[3*68 + 2];
q = CGA_Composite_Table[3*68 + 1] - CGA_Composite_Table[3*68 + 3];

a = tau*(33 + 90 + hue_offset + mode_hue)/360.0;
c = cos(a);
Expand Down

0 comments on commit bd11b81

Please sign in to comment.