diff -ruN pmars-0.9.2/doc/SOUND pmars-0.9.2-s/doc/SOUND --- pmars-0.9.2/doc/SOUND Thu Jan 1 01:00:00 1970 +++ pmars-0.9.2-s/doc/SOUND Mon Jun 11 00:24:39 2001 @@ -0,0 +1,86 @@ + 2001.06.10, by Hermann Samso + + Sound for pmars v0.9.2 + ====================== + + Ok, this is a little presentation of my + contribution to this great program: pmars. + + + 1.Introduction. + + Having many supports for many different graphics + systems, including text based curses, I used to look at + the different patterns and sweeps that form in MARS at + battle time. So, I wondered what it would sound like in + the middle of a Core War conflagration, transforming the + arena's spurs into a sound wave. + I have patched the program under Linux and gcc, to spit a + file that resembles the war at sound level. + + + 2.Description. + + Till yet the sound support is kept to a minimum, + avoiding direct output, and writing to a raw-wave file + called "music.raw". There are three different output + options, depending on the parameters that form the base + of the composition (if you can call it that way ;-) + Most of the times, the output sound will resemble some + noisy modem, or those old 8-bit home computer cassette + loading sessions. But sometimes, and depending of the + warriors you use, interesting sounds are discovered. + The first one -w 1, bases its output in the arena's + form. It normally produces high pitched strings, or + repetitive drums that reflect those common coloured assault + strips. This option may be tweaked with the sample step + option: -W . Note that this step or size + doesn't have anything to do with the output sample format. + This just specifies from which portion of the mars will the + sample value be calculated. This means that for long arenas + or long cycles, you probably want a bigger step size, to + avoid too much flat samples and also to avoid that output + doesn't explode in size. + The second output type: -w 2, bases its samples on + the position of each warrior's primary task. It waits till + every warrior's PC has been updated, before their task + position as a sample. This type of sound is probably more + interesting than type 1. + At least I added a third type: -w 3, which is ideal for + 2 warriors' war stereo sound exam. + + + 3.Installation. + + This is as simple as editing the "makefile" and + adding -DSOUNDOUT option to compilation flags. Read the + makefile for further details. + If you don't like the name of the output file, you may + change in config.h DEFAULTSNDOUT to your prefered name. + + + 4.Implementation Notes. + + This patches should be pretty compatible with any + computer as they don't care about sound drivers or direct + sound output, and relies on Hard Disk file output. + Your computer may slow down considerably when using this + option, specially when using -w 1, or if you use a 286 :) + You may listen to music.raw with any frequency you may + agree, but you have to consider that samples are 16 bits + and Little Endian. + + + 5.ToDos. + + Ok, options for file format output: 8/16 bits, + Big/Little Endian, and also for output file name, as it + is more or less hard coded by now. + + + 6.Contact. + + For any further information, comments, beer or + kisses, contact: + + Hermann Samso (samso@studserv.stud.uni-hannover) diff -ruN pmars-0.9.2/src/Makefile pmars-0.9.2-s/src/Makefile --- pmars-0.9.2/src/Makefile Sun Dec 24 13:53:39 2000 +++ pmars-0.9.2-s/src/Makefile Mon Jun 11 00:33:32 2001 @@ -15,10 +15,13 @@ # (5) -DSMALLMEM 16-bit addresses, less memory # (6) -DXWINGRAPHX 1 X-Windows graphics (UNIX) # (7) -DPERMUTATE enables -P switch - -CFLAGS = -O -DEXT94 -DXWINGRAPHX -DPERMUTATE +# (8) -DSOUNDOUT Music Sample output to disk. + +CFLAGS = -O -DEXT94 -DXWINGRAPHX -DPERMUTATE -DSOUNDOUT +#CFLAGS = -O -DEXT94 -DCURSESGRAPHX -DPERMUTATE -DSOUNDOUT LFLAGS = -x -# LIB = -lcurses -ltermlib # enable this one for curses display +#LIB = -lcurses -ltermcap # enable this one for curses display +#LIB = -lncurses # LIB = -lvgagl -lvga # enable this one for Linux/SVGA LIB = -L/usr/X11R6/lib -lX11 # enable this one for X11 diff -ruN pmars-0.9.2/src/clparse.c pmars-0.9.2-s/src/clparse.c --- pmars-0.9.2/src/clparse.c Mon Dec 25 01:49:08 2000 +++ pmars-0.9.2-s/src/clparse.c Sun Jun 10 05:06:51 2001 @@ -1,6 +1,9 @@ /* pMARS -- a portable Memory Array Redcode Simulator * Copyright (C) 1993-1996 Albert Ma, Na'ndor Sieben, Stefan Strack and Mintardjo Wangsawidjaja * Copyright (C) 2000 Ilmari Karonen + * + * Other contributors: + * Hermann Samso (samso@studserv.stud.uni-hannover.de) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,6 +77,12 @@ *outOfMemory, *badScoreFormula, *optPSpaceSize, *pSpaceTooBig, *optPermutate, *permutateMultiWarrior; +#ifdef SOUNDOUT +/* HSJ 2001 */ +extern char *optSound, *optStep, *wSoundType, *wSampleStep; +/* HSJ 2001 */ +#endif + #if defined(XWINGRAPHX) extern char *badArgumentForXSwitch, *optXOpt[]; #endif @@ -503,6 +512,14 @@ 0, optFixedPosition); record('o', clp_bool, &SWITCH_o, 0, 1, 0, optSort); + +#ifdef SOUNDOUT +/* HSJ 2001 */ + record('w', clp_int, &SWITCH_w, 1, 3, 0, optSound); + record('W', clp_int, &SWITCH_W, 1, MAXCORESIZE, 200, optStep); +/* HSJ 2001 */ +#endif + #if defined(PSPACE) record('S', clp_addr, &pSpaceSize, 1, MAXCORESIZE, 0, optPSpaceSize); @@ -580,6 +597,20 @@ errout(FLessThand); result = CLP_NOGOOD; } +#ifdef SOUNDOUT +/* HSJ 2001 */ + if ((SWITCH_w) && (3 < SWITCH_w)) { + print_usage(options); + errout(wSoundType); + result = CLP_NOGOOD; + } + if ((SWITCH_W) && (coreSize < SWITCH_W)) { + print_usage(options); + errout(wSampleStep); + result = CLP_NOGOOD; + } +/* HSJ 2001 */ +#endif set_reg('W', (long) warriors); for (i = 1; i <= warriors; ++i) { set_reg('S', (long) i); diff -ruN pmars-0.9.2/src/config.h pmars-0.9.2-s/src/config.h --- pmars-0.9.2/src/config.h Sun Aug 20 15:29:30 2000 +++ pmars-0.9.2-s/src/config.h Sun Jun 10 05:08:21 2001 @@ -1,6 +1,9 @@ /* pMARS -- a portable Memory Array Redcode Simulator * Copyright (C) 1993-1996 Albert Ma, Na'ndor Sieben, Stefan Strack and Mintardjo Wangsawidjaja * + * Other Contributors: + * Hermann Samso (samso@studserv.stud.uni-hannover.de) + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -261,6 +264,9 @@ /* 'l' or 'L' is required if the number is bigger than 32767 */ #define DEFAULTCYCLES 80000L #define DEFAULTSCORE "(W*W-1)/S"/* formula used for score calculation */ +/* HSJ 2001 */ +#define DEFAULTSNDFILE "music.raw" /* music file output name */ +/* HSJ 2001 */ /* ******************************************************************** Do not alter the next sections. They mainly ensure consistency. diff -ruN pmars-0.9.2/src/global.c pmars-0.9.2-s/src/global.c --- pmars-0.9.2/src/global.c Mon Dec 25 01:49:08 2000 +++ pmars-0.9.2-s/src/global.c Sun Jun 10 05:09:37 2001 @@ -2,6 +2,9 @@ * Copyright (C) 1993-1996 Albert Ma, Na'ndor Sieben, Stefan Strack and Mintardjo Wangsawidjaja * Copyright (C) 2000 Ilmari Karonen * + * Other Contributors: + * Hermann Samso (samso@studserv.stud.uni-hannover.de) + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -53,6 +56,12 @@ int SWITCH_o; int SWITCH_Q = -1; /* not set */ char *SWITCH_eq = DEFAULTSCORE; +#ifdef SOUNDOUT +/* HSJ 2001 */ +int SWITCH_w = 0; /* default music output */ +int SWITCH_W = 200; /* default sample step */ +/* HSJ 2001 */ +#endif #ifdef VMS int SWITCH_D; #endif diff -ruN pmars-0.9.2/src/global.h pmars-0.9.2-s/src/global.h --- pmars-0.9.2/src/global.h Mon Dec 25 01:56:41 2000 +++ pmars-0.9.2-s/src/global.h Sun Jun 10 05:11:14 2001 @@ -2,6 +2,9 @@ * Copyright (C) 1993-1996 Albert Ma, Na'ndor Sieben, Stefan Strack and Mintardjo Wangsawidjaja * Copyright (C) 2000 Ilmari Karonen * + * Other Contributors: + * Hermann Samso (samso@studserv.stud.uni-hannover.de) + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -322,6 +325,12 @@ extern int SWITCH_o; extern int SWITCH_Q; extern char *SWITCH_eq; +#ifdef SOUNDOUT +/* HSJ 2001 */ +extern int SWITCH_w; +extern int SWITCH_W; +/* HSJ 2001 */ +#endif #ifdef VMS extern int SWITCH_D; #endif diff -ruN pmars-0.9.2/src/sim.c pmars-0.9.2-s/src/sim.c --- pmars-0.9.2/src/sim.c Mon Dec 25 01:49:08 2000 +++ pmars-0.9.2-s/src/sim.c Sun Jun 10 05:17:30 2001 @@ -2,6 +2,9 @@ * Copyright (C) 1993-1996 Albert Ma, Na'ndor Sieben, Stefan Strack and Mintardjo Wangsawidjaja * Copyright (C) 2000 Ilmari Karonen * + * Other Contributors: + * Hermann Samso (samso@studserv.stud.uni-hannover.de) + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -184,6 +187,17 @@ warrior_struct *endWar; /* end of the warriors array */ +#ifdef SOUNDOUT +/* HSJ, 2001 */ +long mem_idx1; +long mem_idx2; +long war_idx; +long smp; +long snd_cycles = 0; +FILE* output_file; /* output file */ +/* HSJ, 2001 */ +#endif + /*--------------------*/ #ifdef NEW_STYLE S32_T @@ -250,6 +264,18 @@ endWar = warrior + warriors; +#ifdef SOUNDOUT +/* HSJ 2001 open file for raw music output */ + if (SWITCH_w) { + output_file = fopen(DEFAULTSNDFILE, "wb"); + if (!output_file) { + printf("Error creating output file \"%s\".\n", DEFAULTSNDFILE); + exit(-1); + } + } +/* HSJ 2001 */ +#endif + #ifdef PERMUTATE if (SWITCH_P) { permbuf = (int *) malloc((size_t)(warriors * positions * sizeof(int))); @@ -382,6 +408,55 @@ /* the inner loop of execution */ do { /* each cycle */ display_cycle(); + +#ifdef SOUNDOUT +/* HSJ 2001 */ + if (snd_cycles == warriors) { + smp = 0; + if (SWITCH_w == 1) { + for (mem_idx1 = 0; mem_idx1 < coreSize; mem_idx1 = mem_idx1+SWITCH_W) { + for (mem_idx2 = 0; mem_idx2 < SWITCH_W && mem_idx2 < coreSize; mem_idx2++) { + smp = smp+ + (memory[mem_idx1+mem_idx2].A_value+ + memory[mem_idx1+mem_idx2].B_value)/2; + } + smp = smp/SWITCH_W; + smp = (smp*65535)/coreSize; + fputc(smp&0xFF, output_file); + fputc((smp>8)&0xFF, output_file); +/* beware: 1. most values are zero, 2. values > 256, 3. 7999 peak */ + } + } + else if (SWITCH_w == 2) { + W = starter; + for (war_idx = 0; war_idx < warriors; war_idx++) { + smp = smp + *(W->taskHead); + W = W->nextWarrior; + } + smp = smp/warriors; + smp = (smp*65535)/coreSize; + fputc(smp&0xFF, output_file); + fputc((smp>8)&0xFF, output_file); + } + else if (SWITCH_w == 3) { + W = starter; + for (war_idx = 0; war_idx < warriors; war_idx++) { + smp = smp + *(W->taskHead); + smp = (smp*65535)/coreSize; + fputc(smp&0xFF, output_file); + fputc((smp>8)&0xFF, output_file); + W = W->nextWarrior; + } + } + + snd_cycles = 1; + } + else + snd_cycles++; +/* HSJ 2001 */ +#endif + + // progCnt = *(W->taskHead++); // IR = memory[progCnt]; /* copy instruction into register */ IR = memory[(progCnt= *(W->taskHead++))]; diff -ruN pmars-0.9.2/src/str_eng.c pmars-0.9.2-s/src/str_eng.c --- pmars-0.9.2/src/str_eng.c Mon Dec 25 01:49:08 2000 +++ pmars-0.9.2-s/src/str_eng.c Sun Jun 10 05:22:56 2001 @@ -2,6 +2,9 @@ * Copyright (C) 1993-1996 Albert Ma, Na'ndor Sieben, Stefan Strack and Mintardjo Wangsawidjaja * Copyright (C) 2000 Philip Kendall and Ilmari Karonen * + * Other Contributors: + * Hermann Samso (samso@studserv.stud.uni-hannover.de) + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -403,6 +406,12 @@ char *optFixedSeries = "Fixed position series"; char *optFixedPosition = "Fixed position of warrior #2"; char *optSort = "Sort result output by score"; +#ifdef SOUNDOUT +/* HSJ 2001 */ +char *optSound = "Write sound [1,3]"; +char *optStep = "Sample step size [1,CORESIZE]"; +/* HSJ 2001 */ +#endif #if defined(DOSTXTGRAPHX) || defined(DOSGRXGRAPHX) || defined(LINUXGRAPHX)\ || defined(XWINGRAPHX) char *optView = "Coreview mode [103]"; @@ -430,6 +439,12 @@ char *dLessThanl = "\nWarrior distance cannot be smaller than warrior length\n"; char *FLessThand = "\nPosition of warrior #2 cannot be smaller than warrior distance\n"; char *badScoreFormula = "\nBad score formula\n"; +#ifdef SOUNDOUT +/* HSJ 2001 */ +char *wSoundType = "\nWrong sound type, must be number in range [1,3]\n"; +char *wSampleStep = "\nWrong sample step size, must be in range [1,CORESIZE]\n"; +/* HSJ 2001 */ +#endif #ifdef PSPACE char *pSpaceTooBig = "\nP-space is bigger than core\n"; #endif