home *** CD-ROM | disk | FTP | other *** search
- program CreateFxFile;
-
- {This program will create a file containing a function table [ f(x) table ] }
- {which can be read into a function device in a UniSon circuit. The function}
- { F can be any function for which -1<=f(x)<=1 when -1<=x<=1.}
- { After it is created, use ResEdit or some other utility to change the}
- {file's type to 'UnFx' and its creator to 'UnSn' if you want it to have the}
- {proper file icon, and be recognized properly by UniSon.}
-
- const
- HalfTable = 128;
- TwoPower23 = 8388608;
- type
- IndexType = -HalfTable..HalfTable;
- DataTable = array[IndexType] of longint;
- var
- TheDataTable: DataTable;
- i: IndexType;
-
- function F (x: double): double;
- begin
- F := 2.0 * sqr(x) - 1.0
- end;
-
- procedure WriteToFile (var TheData: DataTable);
- var
- TheFile: file of DataTable;
- TheName: str255;
- begin
- TheName := NewFileName('Save Function as...');
- if length(TheName) <> 0 then
- begin
- rewrite(TheFile, TheName);
- write(TheFile, TheData);
- close(TheFile)
- end
- end;
-
- begin {main}
- for i := -HalfTable to HalfTable do
- begin
- TheDataTable[i] := round(TwoPower23 * F(i / HalfTable));
- if TheDataTable[i] > TwoPower23 then
- TheDataTable[i] := TwoPower23;
- if TheDataTable[i] < -TwoPower23 then
- TheDataTable[i] := -TwoPower23;
- end;
- WriteToFile(TheDataTable)
- end. {main}