This file is indexed.

/usr/share/faumachine/experiments/test-pci-vhdl-con/test.c is in faumachine-data 20110812-1.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * $Id: test.c,v 1.21 2011-01-25 12:24:12 potyra Exp $
 *
 * Copyright (C) 2010 FAUmachine Team <info@faumachine.org>.
 * This program is free software. You can redistribute it and/or modify it
 * under the terms of the GNU General Public License, either version 2 of
 * the License, or (at your option) any later version. See COPYING.
 */

#include <unistd.h>
#include <sys/io.h>
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <inttypes.h>

static unsigned int base_port = 0xe800;

static void
play_note(
	char note, 
	unsigned short divisor, 
	unsigned short octave, 
	unsigned short volume
)
{
	int16_t w;
	const int usec_full_note = 1800000;
	const float inter_note_delay_percent = 0.05;

	switch (note) {
	case 'c': w = 0; break;
	case 'd': w = 1; break;
	case 'e': w = 2; break;
	case 'f': w = 3; break;
	case 'g': w = 4; break;
	case 'a': w = 5; break;
	case 'h': w = 6; break;
	default: return;
	}

	fprintf(stderr, "playing %c %d %d\n", note, octave, divisor);

	assert(octave <= 3);
	w |= octave << 4;

	assert(volume <= 3);
	w |= volume << 8;
	
	/* enable out signal */
	w |= 1 << 6;
	/* enable generator */
	w |= 1 << 7;

	outw(w, base_port);

	/* delay */
	usleep(usec_full_note * (1 - inter_note_delay_percent) / divisor);

	/* disable out */
	w &= ~(1 << 6);
	/* disable generator */
	w &= ~(1 << 5);
	/* disable volume */
	w &= ~((1 << 8) | (1 << 9));

	outw(w, base_port);
	/* delay */
	usleep(usec_full_note * inter_note_delay_percent);
}


/* Note: "Die Gedanken sind frei" is in the public domain, since the
 *       copyright expired a long time ago.
 */
static void
play_dgsf(void)
{
	play_note('g', 8, 1, 3);
	play_note('g', 8, 1, 2);

	play_note('c', 4, 2, 3);
	play_note('c', 4, 2, 3);
	play_note('e', 8, 2, 3);
	play_note('c', 8, 2, 3);

	play_note('g', 2, 1, 3);
	play_note('g', 4, 1, 3);

	play_note('f', 4, 1, 3);
	play_note('d', 4, 1, 3);
	play_note('g', 4, 1, 3);

	play_note('e', 4, 1, 3);
	play_note('c', 4, 1, 3);
	play_note('g', 8, 1, 3);
	play_note('g', 8, 1, 3);

	play_note('c', 4, 2, 3);
	play_note('c', 4, 2, 3);
	play_note('e', 8, 2, 3);
	play_note('c', 8, 2, 3);

	play_note('g', 2, 1, 3);
	play_note('g', 4, 1, 3);

	play_note('f', 4, 1, 3);
	play_note('d', 4, 1, 3);
	play_note('g', 4, 1, 3);

	play_note('e', 4, 1, 3);
	play_note('c', 4, 1, 3);
	play_note('c', 4, 2, 3);

	play_note('h', 4, 1, 3);
	play_note('d', 4, 2, 3);
	play_note('d', 4, 2, 3);

	play_note('c', 4, 2, 3);
	play_note('e', 4, 2, 3);
	play_note('e', 4, 2, 3);

	play_note('h', 4, 1, 3);
	play_note('d', 4, 2, 3);
	play_note('d', 4, 2, 3);

	play_note('c', 4, 2, 3);
	play_note('e', 4, 2, 3);
	play_note('c', 4, 2, 3);

	play_note('a', 4, 1, 3);
	play_note('a', 4, 1, 3);
	play_note('c', 8, 2, 3);
	play_note('a', 8, 1, 3);

	play_note('g', 2, 1, 3);
	play_note('g', 8, 1, 3);
	play_note('e', 8, 2, 3);

	play_note('e', 8, 2, 3);
	play_note('d', 8, 2, 3);
	play_note('c', 4, 2, 3);
	play_note('h', 4, 1, 3);

	play_note('c', 2, 2, 3);
}

static int
self_test(void)
{
	int i;
	int ret;

	/* test only low byte, and avoid bits 6 and 7 since these enable sound
	 * generation */
	for (i = 0; i < 63; i++) {
		outw(i, base_port);
		ret = inw(base_port);

		if (ret != i) {
			fprintf(stderr, "Register value error i=%d, ret=%d\n",
				i, ret);
			return 1;
		}
	}

	fprintf(stderr, "self-test completed successfully\n");
	return 0;
}

int
main(int argc, char **argv)
{
	int ret;
	int do_self_test = 0;

	if (1 < argc) {
		sscanf(argv[1], "%x", &base_port);
		argc--;
		argv++;
	}
	if (1 < argc) {
		if (strcmp(argv[1], "--self-test") == 0) {
			do_self_test = 1;

			argc--;
			argv++;
		}
	}

	fprintf(stderr, "Using %x as base port.\n", base_port);

	ret = iopl(3);
	if (ret < 0) {
		perror("Could not obtain IO-Permisisions");
		return 1;
	}

	if (do_self_test) {
		ret = self_test();
		return ret;
	}

	play_dgsf();
	fprintf(stderr, "Playing done.\n");
	return 0;
}