/* ============================================================================= oneovern.c -- calculate a table of 1/(n * m) for m = 0.25, n = 0..maxn Version 10 -- 1989-05-25 -- D.N. Lynx Crowe This program does the same thing as oneover.c as far as calulation goes, what's different is the output format. This one also lets you change the number of entries in the table from the command line (default = 512). This output format is for the TI TMS320C25 COFF assembler. Other assembler formats can be accomodated by changing the define statements. ============================================================================= */ #include "stdio.h" /* standard I/O definintions */ #include "stddefs.h" /* miscellaneous standard definitions */ #define SINGLE FALSE /* define TRUE for 1 value per line */ #define OUTFILE "ovnm.cpy" /* table output file name format */ #define TABNAME "OVNM" /* table name base string */ #define DATADEF ".word" /* assembler data definition statement */ #define NOTE ";" /* assembler leading comment symbol */ #define COMMENT ";" /* assembler trailing comment symbol */ #define MAXL 8 /* number of values per line */ #define MAXN 512 /* default number of table elements */ #define NV 32767 /* normalized 1 value */ extern double atof(); /* ascii to double */ extern char *now(); /* system date and time */ extern int atoi(); /* ascii to integer */ char dtg[22]; /* date and time the table was made */ char outfile[64]; /* output file name */ /* */ /* ============================================================================= Calculate a table of 1 / (n * m) ============================================================================= */ main(argc, argv) int argc; char *argv[]; { short k, n, maxn, t, nol, maxl; FILE *fp; double m; m = 1.0; maxn = MAXN; maxl = MAXL; switch (argc) { case 3: maxn = atoi(argv[2]); case 2: m = atof(argv[1]); case 1: break; default: printf("usage: oneovern [m [maxn]]\n"); printf("calculates: 1 / (n * m) for n = 0..maxn\n"); printf("defaults: m = 1.0, n = 512\n"); exit(1); } k = 0; sprintf(outfile, OUTFILE); printf("Creating \"%s\" ...\n", outfile); if ((FILE *)NULL EQ (fp = fopen(outfile, "w"))) { printf("ERROR -- Unable to open \"%s\" for output\n", OUTFILE); exit(1); } fprintf(fp, "%s\n%s %s -- Table of 1/(n * %f) for n = 0..%d\n", NOTE, NOTE, outfile, m, maxn-1); fprintf(fp, "%s Version 0 -- %s -- Generated by \"movern\"\n%s\n", NOTE, now(dtg), NOTE); fprintf(fp, "%s Normalized value of 1 = %d = 0x%04x\n%s\n", NOTE, NV, NV, NOTE); fprintf(fp, "%s Table has %d entries\n%s\n", NOTE, maxn, NOTE); fprintf(fp, "%s%", TABNAME); nol = 0; for (n = 0; n < maxn; n++) { if (n) t = (int)(NV / (double)(n * m)); else t = 0; #if SINGLE fprintf(fp, "\t%s\t%d\t%s %d\n", DATADEF, t, COMMENT, n); #else if (0 EQ (n % maxl)) fprintf(fp, "\t%s\t%d", DATADEF, t); else fprintf(fp, ",%d", t); ++nol; if ((maxl - 1) EQ (n % maxl)) { fprintf(fp, "\n"); nol = 0; } #endif } if (nol) fprintf(fp, "\n"); fprintf(fp, "%s\n%s End of table %s (file: %s)\n%s\n", NOTE, NOTE, TABNAME, outfile, NOTE); fclose(fp); printf("Table \"%s\" written to \"%s\". End of program.\n", TABNAME, outfile); exit(0); }