display.c
2.35 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
/*
* display.c - display texture output
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "display.h"
#include "test_image.h"
#define DEFAULT_NAME "tctm.rgb"
#define MAXX 320
#define MAXY 240
/*
* G l o b a l s
*/
static char *Fname = DEFAULT_NAME;
static int MaxX = MAXX;
static int MaxY = MAXY;
static Image FrameBuf;
/*
*
*/
void
display(display_t **pp0, display_t **pp1)
{
unsigned char *pixel;
/* pointers to memory structure */
display_t *p0, *p1;
int save_clock;
/* get pointers */
p0 = *pp0;
p1 = *pp1;
save_clock = p0->gclk;
if(p0->gclk && !p1->gclk_old) /* posedge(gclk) */
{
/* transfer all next-clock register values to register outputs. */
*pp0 = p1; /* swap */
*pp1 = p0;
p0 = *pp0; /* fix pointers */
p1 = *pp1;
if(p1->exit1)
{
save_image(Fname, &FrameBuf);
p0->exit = 1;
printf("Display exit, saving %s\n", Fname);
}
else
p0->exit = 0;
if(p1->dv && p1->y < MaxY && p1->x < MaxX)
{
/* average 4 texels */
/* write to frame buffer */
pixel = FrameBuf.base + p1->y * FrameBuf.lsize + p1->x * 4;
pixel[0] = (unsigned char) p1->ra;
pixel[1] = (unsigned char) p1->ga;
pixel[2] = (unsigned char) p1->ba;
pixel[3] = (unsigned char) p1->aa;
}
} /* posedge */
/* save last clock state */
p1->gclk_old = save_clock;
}
/*
*
*/
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->exit1 = p1->exit1 = 0;
p0->exit = p1->exit = 0;
while((c = getopt(p1->argc, p1->argv, "d:f:i:t:s:x:y:h")) != EOF)
{
switch(c)
{
case 'f':
Fname = optarg;
break;
case 'x':
MaxX = atoi(optarg);
break;
case 'y':
MaxY = atoi(optarg);
break;
case 'h':
fprintf(stderr,"Usage for display:\n");
fprintf(stderr," -f <rgb output file>\n");
fprintf(stderr," -x <max_x>\n");
fprintf(stderr," -y <max_y>\n");
p0->exit = 1;
return;
default:
break;
}
}
/*
* Create Frame Buffer
*/
FrameBuf.xsize = MaxX;
FrameBuf.ysize = MaxY;
FrameBuf.lsize = MaxX * 4; /* 32 bit pixels */
FrameBuf.base = (unsigned char *) malloc(FrameBuf.ysize * FrameBuf.lsize);
}