Reformat all C files.

I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
This commit is contained in:
Sean Hunt
2015-05-09 13:43:16 -04:00
parent 167800afdf
commit 97d6fade74
270 changed files with 182649 additions and 173878 deletions
+197 -165
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 sound.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 sound.c $NHDT-Date: 1431192781 2015/05/09 17:33:01 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
/* NetHack 3.6 sound.c $Date: 2009/05/06 10:49:43 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)sound.c 3.5 1996/02/19 */
/* Copyright (c) NetHack PC Development Team 1993,1995 */
@@ -23,40 +23,40 @@
#ifndef TESTING
#define printf pline
#define printf pline
int
assign_soundcard(sopt)
char *sopt;
{
iflags.hassound = 0;
#ifdef PCMUSIC
iflags.usepcspeaker = 0;
#endif
iflags.hassound = 0;
# ifdef PCMUSIC
iflags.usepcspeaker = 0;
# endif
if (strncmpi(sopt,"def",3) == 0) { /* default */
/* do nothing - default */
}
# ifdef PCMUSIC
else if (strncmpi(sopt,"speaker",7) == 0) { /* pc speaker */
iflags.usepcspeaker = 1;
}
# endif
else if (strncmpi(sopt,"auto",4) == 0) { /* autodetect */
/*
* Auto-detect Priorities (arbitrary for now):
* Just pcspeaker
*/
if (0) ;
# ifdef PCMUSIC
else iflags.usepcspeaker = 1;
# endif
} else {
return 0;
}
return 1;
if (strncmpi(sopt, "def", 3) == 0) { /* default */
/* do nothing - default */
}
#ifdef PCMUSIC
else if (strncmpi(sopt, "speaker", 7) == 0) { /* pc speaker */
iflags.usepcspeaker = 1;
}
#endif
else if (strncmpi(sopt, "auto", 4) == 0) { /* autodetect */
/*
* Auto-detect Priorities (arbitrary for now):
* Just pcspeaker
*/
if (0)
;
#ifdef PCMUSIC
else
iflags.usepcspeaker = 1;
#endif
} else {
return 0;
}
return 1;
}
#endif
@@ -64,78 +64,80 @@ char *sopt;
/* 8254/3 Control Word Defines */
#define CTR0SEL (0<<6)
#define CTR1SEL (1<<6)
#define CTR2SEL (2<<6)
#define RDBACK (3<<6)
#define CTR0SEL (0 << 6)
#define CTR1SEL (1 << 6)
#define CTR2SEL (2 << 6)
#define RDBACK (3 << 6)
#define LATCH (0<<4)
#define RW_LSB (1<<4)
#define RW_MSB (2<<4) /* If both LSB and MSB are read, LSB is done first */
#define LATCH (0 << 4)
#define RW_LSB (1 << 4)
#define RW_MSB (2 << 4) /* If both LSB and MSB are read, LSB is done first \
*/
#define MODE0 (0<<1) /* Interrupt on terminal count */
#define MODE1 (1<<1) /* Hardware One-Shot */
#define MODE2 (2<<1) /* Pulse Generator */
#define MODE3 (3<<1) /* Square Wave Generator */
#define MODE4 (4<<1) /* Software Triggered Strobe */
#define MODE5 (5<<1) /* Hardware Triggered Strobe */
#define MODE0 (0 << 1) /* Interrupt on terminal count */
#define MODE1 (1 << 1) /* Hardware One-Shot */
#define MODE2 (2 << 1) /* Pulse Generator */
#define MODE3 (3 << 1) /* Square Wave Generator */
#define MODE4 (4 << 1) /* Software Triggered Strobe */
#define MODE5 (5 << 1) /* Hardware Triggered Strobe */
#define BINARY (0<<0) /* Binary counter (16 bits) */
#define BCD (1<<0) /* Binary Coded Decimal (BCD) Counter (4 Decades) */
#define BINARY (0 << 0) /* Binary counter (16 bits) */
#define BCD (1 << 0) /* Binary Coded Decimal (BCD) Counter (4 Decades) */
/* Misc 8254/3 Defines */
#define TIMRFRQ (1193180UL) /* Input frequency to the clock (Hz) */
#define TIMRFRQ (1193180UL) /* Input frequency to the clock (Hz) */
/* Speaker Defines */
#define TIMER (1<<0) /* Timer 2 Output connected to Speaker */
#define SPKR_ON (1<<1) /* Turn on/off Speaker */
#define TIMER (1 << 0) /* Timer 2 Output connected to Speaker */
#define SPKR_ON (1 << 1) /* Turn on/off Speaker */
/* Port Definitions */
/* 8254/3 Ports */
#define CTR0 0x40
#define CTR1 0x41
#define CTR2 0x42
#define CTRL 0x43
#define CTR0 0x40
#define CTR1 0x41
#define CTR2 0x42
#define CTRL 0x43
/* Speaker Port */
#define SPEAKER 0x61
#define SPEAKER 0x61
void
startsound (unsigned freq)
startsound(unsigned freq)
{
/* To start a sound on the PC:
*
* First, set the second counter to have the correct frequency:
*/
/* To start a sound on the PC:
*
* First, set the second counter to have the correct frequency:
*/
unsigned count;
unsigned count;
if (freq == 0) freq = 523;
if (freq == 0)
freq = 523;
count = TIMRFRQ / freq; /* Divide frequencies to get count. */
count = TIMRFRQ / freq; /* Divide frequencies to get count. */
#ifdef TESTING
printf ("freq = %u, count = %u\n", freq, count);
printf("freq = %u, count = %u\n", freq, count);
#endif
outportb (CTRL, CTR2SEL|RW_LSB|RW_MSB|MODE3|BINARY);
outportb (CTR2, count & 0x0FF);
outportb (CTR2, count / 0x100);
outportb(CTRL, CTR2SEL | RW_LSB | RW_MSB | MODE3 | BINARY);
outportb(CTR2, count & 0x0FF);
outportb(CTR2, count / 0x100);
/* Next, turn on the speaker */
/* Next, turn on the speaker */
outportb (SPEAKER, inportb(SPEAKER)|TIMER|SPKR_ON);
outportb(SPEAKER, inportb(SPEAKER) | TIMER | SPKR_ON);
}
void
stopsound (void)
stopsound(void)
{
outportb (SPEAKER, inportb(SPEAKER) & ~(TIMER|SPKR_ON));
outportb(SPEAKER, inportb(SPEAKER) & ~(TIMER | SPKR_ON));
}
static unsigned tempo, length, octave, mtype;
@@ -154,97 +156,117 @@ static unsigned tempo, length, octave, mtype;
* number.
*/
unsigned long notefactors[12] = { 483852, 456695, 431063, 406869, 384033,
362479, 342135, 322932, 304808, 287700, 271553, 256312 };
unsigned long notefactors[12] = { 483852, 456695, 431063, 406869,
384033, 362479, 342135, 322932,
304808, 287700, 271553, 256312 };
void
note (long notenum)
note(long notenum)
{
startsound ((unsigned) (4050816000UL / notefactors[notenum % 12]
>> (7 - notenum / 12)));
startsound((unsigned) (4050816000UL / notefactors[notenum % 12]
>> (7 - notenum / 12)));
}
int notes[7] = { 9, 11, 0, 2, 4, 5, 7 };
char *
startnote (char *c)
startnote(char *c)
{
long n;
long n;
n = notes[toupper(*c++) - 'A'] + octave * 12;
if (*c == '#' || *c == '+') { n++; c++; }
else if (*c == '-') { if (n) n--; c++; }
n = notes[toupper(*c++) - 'A'] + octave * 12;
if (*c == '#' || *c == '+') {
n++;
c++;
} else if (*c == '-') {
if (n)
n--;
c++;
}
note (n);
note(n);
return --c;
return --c;
}
void
delaytime (unsigned time)
delaytime(unsigned time)
{
/* time and twait are in units of milliseconds */
/* time and twait are in units of milliseconds */
unsigned twait;
unsigned twait;
switch (toupper (mtype)) {
case 'S': twait = time / 4; break;
case 'L': twait = 0; break;
default: twait = time / 8; break;
}
switch (toupper(mtype)) {
case 'S':
twait = time / 4;
break;
case 'L':
twait = 0;
break;
default:
twait = time / 8;
break;
}
msleep (time - twait);
stopsound ();
msleep (twait);
msleep(time - twait);
stopsound();
msleep(twait);
}
char *
delaynote (char *c)
delaynote(char *c)
{
unsigned time = 0;
unsigned time = 0;
while (isdigit(*c)) time = time * 10 + (*c++ - '0');
while (isdigit(*c))
time = time * 10 + (*c++ - '0');
if (!time) time = length;
if (!time)
time = length;
time = (unsigned)(240000 / time / tempo);
time = (unsigned) (240000 / time / tempo);
while (*c == '.') { time = time * 3 / 2; c++; }
while (*c == '.') {
time = time * 3 / 2;
c++;
}
delaytime (time);
delaytime(time);
return c;
return c;
}
void
initspeaker (void)
initspeaker(void)
{
tempo = 120, length = 4, octave = 3, mtype = 'N';
tempo = 120, length = 4, octave = 3, mtype = 'N';
}
void
play (char *tune)
play(char *tune)
{
char *c, *n;
unsigned num;
char *c, *n;
unsigned num;
for (c = tune; *c; ) {
sscanf (c + 1, "%u", &num);
for (n = c + 1; isdigit(*n); n++) /* do nothing */;
if (isspace(*c)) c++;
else switch (toupper(*c)) {
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
c = startnote (c);
case 'P':
c = delaynote (++c);
break;
for (c = tune; *c;) {
sscanf(c + 1, "%u", &num);
for (n = c + 1; isdigit(*n); n++) /* do nothing */
;
if (isspace(*c))
c++;
else
switch (toupper(*c)) {
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
c = startnote(c);
case 'P':
c = delaynote(++c);
break;
#if 0
case 'M': c++; mtype = *c; c++; break;
case 'T':
@@ -270,62 +292,72 @@ play (char *tune)
case '>': if (octave < 7) octave++; c++; break;
case '<': if (octave) octave--; c++; break;
#endif
case ' ': c++; break;
default:
printf ("Unrecognized play value (%s)!\n", c);
return;
}
}
case ' ':
c++;
break;
default:
printf("Unrecognized play value (%s)!\n", c);
return;
}
}
}
#ifndef TESTING
void
pc_speaker (struct obj *instr, char *tune)
pc_speaker(struct obj *instr, char *tune)
{
if (!iflags.usepcspeaker) return;
initspeaker ();
switch (instr->otyp)
{
case WOODEN_FLUTE:
case MAGIC_FLUTE:
octave = 5; /* up one octave */
break;
case TOOLED_HORN:
case FROST_HORN:
case FIRE_HORN:
octave = 2; /* drop two octaves */
break;
case BUGLE:
break;
case WOODEN_HARP:
case MAGIC_HARP:
length = 8;
mtype = 'L'; /* fast, legato */
break;
if (!iflags.usepcspeaker)
return;
initspeaker();
switch (instr->otyp) {
case WOODEN_FLUTE:
case MAGIC_FLUTE:
octave = 5; /* up one octave */
break;
case TOOLED_HORN:
case FROST_HORN:
case FIRE_HORN:
octave = 2; /* drop two octaves */
break;
case BUGLE:
break;
case WOODEN_HARP:
case MAGIC_HARP:
length = 8;
mtype = 'L'; /* fast, legato */
break;
}
play (tune);
play(tune);
}
#else
main ()
main()
{
char s[80];
int tool;
char s[80];
int tool;
initspeaker();
printf ("1) flute\n2) horn\n3) harp\n4) other\n");
fgets (s, 80, stdin);
sscanf (s, "%d", &tool);
switch (tool) {
case 1: octave = 5; break;
case 2: octave = 2; break;
case 3: length = 8; mtype = 'L'; break;
default: break;
}
printf ("Enter tune:");
fgets(s, 80, stdin);
play (s);
initspeaker();
printf("1) flute\n2) horn\n3) harp\n4) other\n");
fgets(s, 80, stdin);
sscanf(s, "%d", &tool);
switch (tool) {
case 1:
octave = 5;
break;
case 2:
octave = 2;
break;
case 3:
length = 8;
mtype = 'L';
break;
default:
break;
}
printf("Enter tune:");
fgets(s, 80, stdin);
play(s);
}
#endif