source: buchla-68k/orig/LATTICE/MOVERN.C@ b8080f6

Last change on this file since b8080f6 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

  • Property mode set to 100755
File size: 3.4 KB
Line 
1/*
2 =============================================================================
3 oneovern.c -- calculate a table of 1/(n * m) for m = 0.25, n = 0..maxn
4 Version 10 -- 1989-05-25 -- D.N. Lynx Crowe
5
6 This program does the same thing as oneover.c as far as calulation goes,
7 what's different is the output format. This one also lets you change
8 the number of entries in the table from the command line (default = 512).
9
10 This output format is for the TI TMS320C25 COFF assembler.
11
12 Other assembler formats can be accomodated by changing the define
13 statements.
14 =============================================================================
15*/
16
17#include "stdio.h" /* standard I/O definintions */
18#include "stddefs.h" /* miscellaneous standard definitions */
19
20#define SINGLE FALSE /* define TRUE for 1 value per line */
21
22#define OUTFILE "ovnm.cpy" /* table output file name format */
23#define TABNAME "OVNM" /* table name base string */
24
25#define DATADEF ".word" /* assembler data definition statement */
26#define NOTE ";" /* assembler leading comment symbol */
27#define COMMENT ";" /* assembler trailing comment symbol */
28
29#define MAXL 8 /* number of values per line */
30
31#define MAXN 512 /* default number of table elements */
32
33#define NV 32767 /* normalized 1 value */
34
35extern double atof(); /* ascii to double */
36extern char *now(); /* system date and time */
37extern int atoi(); /* ascii to integer */
38
39char dtg[22]; /* date and time the table was made */
40char outfile[64]; /* output file name */
41
42/*
43
44*/
45
46/*
47 =============================================================================
48 Calculate a table of 1 / (n * m)
49 =============================================================================
50*/
51
52main(argc, argv)
53int argc;
54char *argv[];
55{
56 short k, n, maxn, t, nol, maxl;
57 FILE *fp;
58 double m;
59
60 m = 1.0;
61 maxn = MAXN;
62 maxl = MAXL;
63
64 switch (argc) {
65
66 case 3:
67
68 maxn = atoi(argv[2]);
69
70 case 2:
71
72 m = atof(argv[1]);
73
74 case 1:
75 break;
76
77 default:
78
79 printf("usage: oneovern [m [maxn]]\n");
80 printf("calculates: 1 / (n * m) for n = 0..maxn\n");
81 printf("defaults: m = 1.0, n = 512\n");
82 exit(1);
83 }
84
85 k = 0;
86
87 sprintf(outfile, OUTFILE);
88
89 printf("Creating \"%s\" ...\n", outfile);
90
91 if ((FILE *)NULL EQ (fp = fopen(outfile, "w"))) {
92
93 printf("ERROR -- Unable to open \"%s\" for output\n",
94 OUTFILE);
95
96 exit(1);
97 }
98
99 fprintf(fp, "%s\n%s %s -- Table of 1/(n * %f) for n = 0..%d\n",
100 NOTE, NOTE, outfile, m, maxn-1);
101
102 fprintf(fp, "%s Version 0 -- %s -- Generated by \"movern\"\n%s\n",
103 NOTE, now(dtg), NOTE);
104
105 fprintf(fp, "%s Normalized value of 1 = %d = 0x%04x\n%s\n",
106 NOTE, NV, NV, NOTE);
107
108 fprintf(fp, "%s Table has %d entries\n%s\n",
109 NOTE, maxn, NOTE);
110
111 fprintf(fp, "%s%",
112 TABNAME);
113
114 nol = 0;
115
116 for (n = 0; n < maxn; n++) {
117
118 if (n)
119 t = (int)(NV / (double)(n * m));
120 else
121 t = 0;
122
123#if SINGLE
124
125 fprintf(fp, "\t%s\t%d\t%s %d\n", DATADEF, t, COMMENT, n);
126
127#else
128
129 if (0 EQ (n % maxl))
130 fprintf(fp, "\t%s\t%d", DATADEF, t);
131 else
132 fprintf(fp, ",%d", t);
133
134 ++nol;
135
136 if ((maxl - 1) EQ (n % maxl)) {
137
138 fprintf(fp, "\n");
139 nol = 0;
140 }
141#endif
142 }
143
144 if (nol)
145 fprintf(fp, "\n");
146
147 fprintf(fp, "%s\n%s End of table %s (file: %s)\n%s\n",
148 NOTE, NOTE, TABNAME, outfile, NOTE);
149
150 fclose(fp);
151
152 printf("Table \"%s\" written to \"%s\". End of program.\n",
153 TABNAME, outfile);
154
155 exit(0);
156}
Note: See TracBrowser for help on using the repository browser.