forked from markadev/AppleII-VGA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_testpat.c
113 lines (95 loc) · 4.11 KB
/
render_testpat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "render.h"
#include <pico/stdlib.h>
#include "vga.h"
#define _PIXPAIR(p1, p2) ((uint32_t)(p1) | (((uint32_t)p2) << 16))
// Render a test pattern for testing the VGA output directly
void render_vga_testpattern() {
vga_prepare_frame();
for(uint line = 0; line < VGA_HEIGHT;) {
struct vga_scanline *sl = vga_prepare_scanline();
uint sl_pos = 0;
if((line == 0) || (line == VGA_HEIGHT - 1)) {
// A white line across the top & bottom of the screen
for(; sl_pos < VGA_WIDTH / 16; sl_pos++) {
sl->data[sl_pos] = _PIXPAIR(0x1ff | THEN_EXTEND_7, 0x1ff | THEN_EXTEND_7);
}
sl->length = sl_pos;
} else if((line == 1) || (line == VGA_HEIGHT - 32 - 1)) {
// An alternating pattern of vertical white & black lines
for(uint i = 0; i < VGA_WIDTH / 4; i++, sl_pos++) {
sl->data[sl_pos] = _PIXPAIR(0x1ff, 0);
}
for(uint i = 0; i < VGA_WIDTH / 4; i++, sl_pos++) {
sl->data[sl_pos] = _PIXPAIR(0, 0x1ff);
}
sl->length = sl_pos;
sl->repeat_count = 31;
} else if((line >= 44) && (line < 44 + 128)) {
// The first row of color squares
for(uint i = 0; i < 7; i++) {
sl->data[sl_pos++] = _PIXPAIR(0 | THEN_EXTEND_7, 0 | THEN_EXTEND_7);
}
sl->data[sl_pos++] = _PIXPAIR(0 | THEN_EXTEND_6, 0 | THEN_EXTEND_6);
const uint g = (line - 44) / 16;
for(uint b = 0; b < 3; b++) {
for(uint r = 0; r < 8; r++) {
const uint rgb = (r << 6) | (g << 3) | b;
sl->data[sl_pos++] = _PIXPAIR(rgb | THEN_EXTEND_7, rgb | THEN_EXTEND_7);
}
sl->data[sl_pos++] = _PIXPAIR(0, 0);
}
sl->length = sl_pos;
sl->repeat_count = 15;
} else if((line >= 174) && (line < 174 + 128)) {
// The second row of color squares
for(uint i = 0; i < 7; i++) {
sl->data[sl_pos++] = _PIXPAIR(0 | THEN_EXTEND_7, 0 | THEN_EXTEND_7);
}
sl->data[sl_pos++] = _PIXPAIR(0 | THEN_EXTEND_6, 0 | THEN_EXTEND_6);
const uint g = (line - 174) / 16;
// center-left square
uint b = 3;
for(uint r = 0; r < 8; r++) {
const uint rgb = (r << 6) | (g << 3) | b;
sl->data[sl_pos++] = _PIXPAIR(rgb | THEN_EXTEND_7, rgb | THEN_EXTEND_7);
}
sl->data[sl_pos++] = _PIXPAIR(0, 0);
// center square (black)
for(uint i = 0; i < 8; i++) {
sl->data[sl_pos++] = _PIXPAIR(0 | THEN_EXTEND_7, 0 | THEN_EXTEND_7);
}
sl->data[sl_pos++] = _PIXPAIR(0, 0);
// center-right square
b = 4;
for(uint r = 0; r < 8; r++) {
const uint rgb = (r << 6) | (g << 3) | b;
sl->data[sl_pos++] = _PIXPAIR(rgb | THEN_EXTEND_7, rgb | THEN_EXTEND_7);
}
sl->data[sl_pos++] = _PIXPAIR(0, 0);
sl->length = sl_pos;
sl->repeat_count = 15;
} else if((line >= 304) && (line < 304 + 128)) {
// The third row of color squares
for(uint i = 0; i < 7; i++) {
sl->data[sl_pos++] = _PIXPAIR(0 | THEN_EXTEND_7, 0 | THEN_EXTEND_7);
}
sl->data[sl_pos++] = _PIXPAIR(0 | THEN_EXTEND_6, 0 | THEN_EXTEND_6);
const uint g = (line - 304) / 16;
for(uint b = 5; b < 8; b++) {
for(uint r = 0; r < 8; r++) {
const uint rgb = (r << 6) | (g << 3) | b;
sl->data[sl_pos++] = _PIXPAIR(rgb | THEN_EXTEND_7, rgb | THEN_EXTEND_7);
}
sl->data[sl_pos++] = _PIXPAIR(0, 0);
}
sl->length = sl_pos;
sl->repeat_count = 15;
} else {
// All other lines are just black
sl->data[sl_pos] = _PIXPAIR(0, 0);
sl_pos++;
}
line += sl->repeat_count + 1;
vga_submit_scanline(sl);
}
}