display.c
3.22 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* display.c - display texture output
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "display.h"
#include "test_image.h"
#include "rdp_opts.h"
#define DEFAULT_NAME "rdp.rgb"
#define MAXX 320
#define MAXY 240
#define POSEDGE (save_clk && !save_clk_old)
#define NEGEDGE (!save_clk && save_clk_old)
/*
* G l o b a l s
*/
static char *Fname = DEFAULT_NAME;
static int MaxX = MAXX;
static int MaxY = MAXY;
static Image FrameBuf;
static int VisualOutput = 0;
/*
* Quick and dirty display routine to write a frame buffer
* with blender outputs
*/
void
display(display_t **pp0, display_t **pp1)
{
unsigned char *pixel;
/* pointers to memory structure */
display_t *p0, *p1;
int i;
int save_clk;
int save_clk_old;
/* get pointers */
p0 = *pp0;
p1 = *pp1;
save_clk = p0->gclk;
save_clk_old = p1->gclk_old;
if(POSEDGE)
{
/* transfer all next-clock register values to register outputs. */
*pp0 = p1; /* swap */
*pp1 = p0;
p0 = *pp0; /* fix pointers */
p1 = *pp1;
}
if(NEGEDGE)
{
/* driver asserts wr_fb when ready to exit */
if(p1->wr_fb)
{
save_image(Fname, &FrameBuf);
printf("Display exit, saving %s\n", Fname);
if (VisualOutput) {
printf("hit ^c to exit\n");
fflush(stdout);
pause();
}
p0->exit = 1;
}
else
p0->exit = 0;
/* delay start address */
p0->adrs_d1 = p1->ms_addr;
/* get address */
if(p1->st_span)
{
p0->addr[0] = p1->adrs_d1;
}
else if (p1->left)
p0->addr[0] = p1->addr[0] + 1; /* left major, assume one-cycle mode */
else
p0->addr[0] = p1->addr[0] - 1; /* right major, assume one-cycle mode */
/* delay address until pixel shows up */
for(i = 1; i < DISP_ADDR_DELAY; i++)
p0->addr[i] = p1->addr[i-1];
if(p1->clr_we)
{
/* write to frame buffer */
if(p1->addr[DISP_ADDR_DELAY-1] >= (MAXY * MAXX))
{
fprintf(stderr,"Error, address (%d) out of range (%d)\n",
p1->addr[DISP_ADDR_DELAY-1], MAXX* MAXY);
}
else
{
pixel = FrameBuf.base + (p1->addr[DISP_ADDR_DELAY-1] * 4);
pixel[0] = (unsigned char) p1->bl_r;
pixel[1] = (unsigned char) p1->bl_g;
pixel[2] = (unsigned char) p1->bl_b;
pixel[3] = (unsigned char) p1->bl_a;
}
}
} /* negedge */
/* save last clock state */
p0->gclk_old = p1->gclk_old = save_clk;
}
/*
* Display init
*/
void
display_init(display_t *p0, display_t *p1)
{
int c, i;
extern char *optarg;
extern int optind, opterr, optopt;
optind = 1;
opterr = 0;
p0->gclk = p1->gclk = 0;
p0->gclk_old = p1->gclk_old = 0;
p0->addr[0] = p1->addr[0] = 0;
while((c = getopt(p1->argc, p1->argv, OPTARG)) != EOF)
{
switch(c)
{
case 'v':
VisualOutput = 1;
break;
case 'h':
fprintf(stderr," -h, this usage message\n");
fprintf(stderr," -v, visual output\n");
return;
}
}
/*
* Init Frame Buffer
*/
FrameBuf.xsize = MaxX;
FrameBuf.ysize = MaxY;
FrameBuf.lsize = MaxX * 4; /* 32 bit pixels */
FrameBuf.base = (unsigned char *) calloc(FrameBuf.ysize * FrameBuf.lsize, sizeof(unsigned char));
}