Science 版 (精华区)
发信人: qpcwth (独翅鸟), 信区: Science
标 题: 《分形艺术》70
发信站: 哈工大紫丁香 (2001年11月03日18:33:16 星期六), 站内信件
第十章 分形图形软件Fractint 19.5简介
10.5 Fractint 19.5全部源代码
如果你对编程序感兴趣,可以参考Fractint 19.5的全部源代码。我们是从Interne
t上如下 地址获取这些代码的:
http://spanky.triumf.ca/www/fractint/getting.html
文件名是FRASR195.ZIP,压缩格式占1M多些。Fractint 19.5主要用C语言编写,部分子
程序 用汇编语言编写。同时还可以得到Windows版本的Fractint,只找到18.21版,全部
源代码压 缩存贮在WINS1821.ZIP,共占700K左右。
用PKUNZIP.EXE解压FRASR195.ZIP,得到一系列C语言源程序*.C和汇编语言程序*.A
SM(为了 便于使用,同时给出了目标码*.OBJ),还有一些说明文件*.DOC等。其中READ.
ME中写道:
Fractint 19.5 complete C and ASM source for the DOS-based fractal generator.
Re quires Microsoft C/C++ 7.0 or later or Borland C/C++ 3.1 or later.
Object code of ASM modules supplied so an assembler is not required.
Copyrighted freeware.
文件FRACTSRC.DOC说明了对待FRACTINT源代码的一些有价值的事项,我们抄录如下
:
The source code for Fractint is freely available.
Enhancements to it are appreciated. If you want to add something to Frac
tint and join the Stone Soup Group, please do! To submit changes, see "Conta
cting the Authors" in Fractint's online help.
1.版权信息(Copyright Information)
Some parts of the source are from the public domain and are not copyrigh
ted.
Some parts of the source bear explicit copyright notices from the author
and are subject to the conditions listed there by the author.
The remainder of the source (not already public domain, no explicit auth
ors co pyright notice) is Copyright 1990, 1991 by the Stone Soup Group(a l
oosely associ ated and ever-growing group of fanatic programmers).
The source code may be copied freely and may be used in other programs u
nder the following conditions:
It may not be used in a commercial program which produces fractal images
.
Please credit the author (in general, credit Fractint and the Stone Soup Gro
up) as the source of the code.
2.Fractint修订版的分发(Distribution of modified versions of Fractint)
If you enhance Fractint and want to distribute the results to others, the pr
efer red approach is to join the Stone Soup Group--send us your enhancements
and get your name in lights in future versions of Fractint.
We prefer that a modified Fractint executable program not be distributed to
others, but understand that you might want to give copies to friends. This i
s p ermitted, under the following conditions:
○The modified executable has a different name than "fractint.exe".
○The distribution includes a full unmodified copy of the corresponding orig
inal version of fraint.exe. (The easiest way is to copy fraint.exe to your
new .exe, then "pkzip -a fraint.exe newfract.exe" to add your version, and p
erhaps add a read.me file to describe it.)
○The heading displayed by the modified program clearly indicates that it is
a non-standard release. E.g. you might change the heading to say “Non-sta
n dard Fractint, Modified by John Doe”.
○All author credits and distribution information in the online help are unc
han ged (adding lines for your work is of course ok.)
The source code for a modified version of Fractint may not be distributed.(T
his is because we dont want any chance of confusion over which version of
a source file is the official release.)
3.编译Fractint(Compiling Fractint)
FRASRC.EXE includes the complete source code for FRACTINT (.C and .ASM).Reco
gniz ing that not everyone HAS (or even wants) an assembler, much less eithe
r MASM 5. 1 or Turbo-ASM, which are the only two assemblers that the authors
are aware of that can handle these particular files, it also contains a com
plete set of .OBJ files from the assembler code.
The distributed source will not compile to exactly match the Fractint releas
e - it compiles with a different version number and heading.
The Microsoft 6.00A C compiler and Microsoft 5.1 assembler are used for Frac
tint releases, so that is the one combination of compiler/assembler which is
pretty much guaranteed to handle FRACTINT in all of its various mutations.
Given that several of FRACTINT's co-authors now prefer (or only have!) alter
nate combinations, we have re-arranged the code to (usually) handle several
popular alternatives. In particular:
Microsoft C 7/8 and MASM 6.x:
Just run MAKEFRAC.BAT, which invokes the Microsoft NMK utility using the fil
es F RACHELP.MAK, FRACTINT.MAK, and FRACTINT.LN7. Note that the assembler .O
BJ files have been included in the .ZIP file, so that you dont really need
MASM unless you are going to modify one or more of them. If you ARE going t
o modify one of the assembler files, note that the distributed versions rely
on some nifty featu res added to version 6.0 (like the ’.model medium,c’
option) and will not asse mble under older versions of MASM without a LOT of
work.
Warning: FRACTINT.MAK uses the most aggressive optimizations that we *think*
are safe. Every time Microsoft comes out with a new compiler, something usu
ally bre aks, and we have to back of of our optimizations a little.
Borland C++ 3.0 and 3.1 Users:
Procedures to compile Fractint using Borland C++ 3.1 are contained in bcfrac
t.doc. No attempt has been made to compile with later versions of Borland; u
sers of these versions are encouraged to submit appropriate project or make
fi les to the authors.
4.帮助系统(Help System)
You'll need to set up the help files to get any online help from a modified
version of Fractint.
For MSC users the MAKEFRAC.BAT file contains the necessary steps, you don't
need to do anything special.
TC++ users should:
start by creating HC.EXE using the supplied HC.PRJ file run "hc /c" to creat
e the file FRACTINT.HLP each time you create a new fractint.exe, afterward r
un "hc /a" to append FRACTINT.HLP to the new FRACTINT.EXE
You don't need to understand the rest of this section unless you have a prob
lem .
The source for Fractint's help is in the files HELP.SRC, HELP2.SRC, HELP3.SR
C, HELP4.SRC, and HELP5.SRC. The format of these files is described in HC.DO
C.
The program HC.C ("help compiler") is used to convert the help text into the
form Fractint uses at run time.
Running "hc /c" compiles HELPx.SRC. It produces the file HELPDEFS.H for use
when compiling Fractint, and the file FRACTINT.HLP.
Running "hc /a" appends the FRACTINT.HLP file to FRACTINT.EXE to make the co
mpiled help info available at run time.
5.覆盖(Overlays)
Note: generally you won't have to worry about this!
Only the addition of huge code (new overlays), or work which changes the rel
atio nship between major components of Fractint, are likely to affect the ov
erlay str ucture.
Fractint uses the new Microsoft Link overlay feature, to reduce the runtime
memo ry required (which would otherwise exceed what DOS can give it.) Some c
aution is required with overlays. Those source modules which are part of an
overlay have a comment to indicate this at the start. See the fractint.def f
ile for the cur rent overlay structure.
Some notes about overlays:
○The obvious one: control should not switch to different overlays frequentl
y, e lse Fractint will become sluggish. If the overlay structure changes, a
test fro m floppy disk with no disk caching is a good idea.
○ The overlay manager logic (inserted by the linker) does handle calls from
wit hin one overlay to another - the new overlay is brought in from disk (d
isplaci ng the old one in memory), when the subroutine finishes the old over
lay is br ought back into memory.
○To save memory, Fractint overlays data. The FCODE type accomplishes this.
Make sure that overlayed data is used immediately. If a pointer to overlayed
data i s passed to a routine in a different overlay, and the first overlay
swaps out, t he data with be trashed.
6.吸引人之处何在(Where the Goodies are)?
It has come to our attention that people who have no interest in fractals at
all have been wandering through the FRACTINT source code just to get at som
e of the neat tricks buried therein. Here are a few hints as to where to loo
k:
FRACTINT.C——The main routine. Nothing special here.
FRAMAIN2.C
FRACTINT.H——General Include file. Nothing special here, either.
FRACTYPE.H——Fractal type-specific Include file.
PROMPTS1.C——The full-screen prompting code (using support routines in VI D
EO.ASM)
PROMPTS2.C
CMDFILES.C——Command line and sstools.ini parsing.
FRACTALS.C——Most of the fractal-specific code. If you want to know how a f
ractal is calculated, look in here. Specific speed-em-up support for special
fractal types is in
FRASETUP.C
CALCFRAC.C
FRACSUBR.C
FRACSUBA.ASM
FRACTALB.C——Arbitrary precision fractal implementations
FRACTALP.C——El Grande fractalspecific structure
ANT.C——Ant automaton
CALCMAND.ASM——Mandelbrot/Julia set calculations
NEWTON.ASM——Newton calculations
LORENZ.C——Attractor fractals and IFS
JB.C——“Julibrot” fractal type calculations
TESTPT.C——“Roll-your-own” fractal routine
JIIM.C——Inverse julia and orbits window code
LSYS.C——Lsystems code
LSYS.H
LSYSA.ASM
LSYSAF.ASM
LSYSF.C
LYAPUNOV.ASM——Lyapunov speedup code
MPMATH_C.C——Mark Petersons “fast-math” support routines
MPMATH_A.ASM——(this stuff puts some of the routines supplied by your fav o
rite “C” compiler to shame!)
FPU387.ASM
FPU087.ASM
FMATH.H
MPMATH.H
CMPLX.H——Complex math defines
HCMPLX.C——4D Hypercomplex math
PARSER.C——The “type=formula” formula parser routines
BIGFLT.C——Wes Loewers arbitrary precision library. All ASM code exists a
s C also for portability.
BIG.H
BIGINIT.H
BIGPORT.H
BIGFLT.C
BIGINIT.C
BIGNUM.C
BIGNUMC.C
BIGNUMA.ASM
BIG.INC
BIGPORT.INC
VIDEO.ASM——Assembler code containing all of the video routines (setting up
t he video, reading/writing pixels, zoom-box code, color-cycling, graphics-
to -text “help” switch, ... with help from the routines below for special
adapte rs:
LOADMAP.C——Load *.map files
TARGA.C——TARGA Video Routines
TARGA.H
FR8514A.ASM——8514/A Routines
TPLUS.C——Targa+ video routines
TPLUS.H
TPLUS_A.ASM
HGCFRA.ASM——Hercules Video Routines
DISKVID.C——“DISK/RAM” video routines
YOURVID.C——“Roll-your-own” video routines
GENERAL.ASM——General assembler code having nothing to do with fractals. Lo
ts of the tricky stuff is in here, and many of the “C” routines that perf
orm t ricky functions rely on support code buried in here. In particular, th
is routin e has the:
CPU, FPU Detectors
Keyboard routines
Mouse routines
Expanded memory routines
32-bit scaled integer multiply and divide routines
ENCODER.C——GIF Encoder routines
GIFVIEW.C——GIF Decoder routines
DECODER.C
TGAVIEW.C——(including a TARGA-format decoder currently used only for loadi
n gobsolete .tga format “Continuous Potential” files)
F16.C,
TARGA_LC.H
LOADFILE.C——Loads the Fractint parameter info from a GIF file.subroutines
for DOS Fractint only
LOADFDOS.C
LINE3D.C——3D manipulation routines
3D.C
PLOT3D——3D subroutines for LINE3D.C and LORENZ.C
STEREO.C——RDS stereo module
ROTATE.C——routines which “spin” the VGA video-DAC.
EDITPAL.C——palette-editing mode
HELP.C——HELP support title screen
INTRO.C
ZOOM.C——Zoombox manipulation
PRINTER.C——The Printer Routines.Data used by PRINTER.C
PRINTERA.ASM
MISCRES.C——Miscellaneous resident subroutines; nothing special.
MISCOVL.C——Miscellaneous overlayed subroutines; includes 〈B〉atch command
.
REALDOS.C——Some subroutines isolated from Windows development work;nothi n
g special in here.
SLIDESHW.C——Autokey interpreter
PORT.H——Some portability stuff, nothing special here.
EXTERNS.H——All external variable declarations
PROTOTYP.H——All function prototypes
7.如何组织起来的(How things are set up)?
I've had to go through a lot of the code to figure out how things are setup.
T hese are my rough notes, which Im including in case they can help someo
ne else .
----Ken Shirriff
The control flow is very confusing. Here are some details:
Each fractal type has an entry in the fractal specific table in fractalp.c.
Entr ies that are not displayed are marked with an asterisk. Each entry isma
rked as int or not int, and either has a pointer to another entry(tofloat) o
r NOFRACTAL. If you select float and the type is int or vice versa, you will
end up with th e tofloat type. (e.g. If you select entry MANDEL, and select
floating point, yo u will get entry MANDELFP). There are also pointers toju
lia and tomandel, which allow you to switch between mandel and julia. The fo
ur functions listed are cu rfractalspecific→orbitcalc,curfractalspecific→p
er_pixel, curfractalspecific→p er_image, and curfractalspecific→calctype.
main calls calcfracinit.
calcfractint: this sets up curfractalspecific, which is the appropriate entr
y fr om the fractalspecific table. This routine does the int/float conversio
n.
main calls calcfract, which calls timer, which calls perform_worklist perfor
m_wo rklist calls curfractalspecific→per_image, which is eg. MandelSetup Ma
ndelS etup: sets calctype to curfractalspecific→calctype, or for special ca
ses (eg. decomposition) to StandardFractal perform_worklist calls solidguess
(or whateve r drawing system) solidguess calls *calctype for each pixel; ca
lctype is eg. Sta ndardFractal StandardFractal calls curfractalspecific→per
_pixel once, and then loops over each iteration calling curfractalspecific→
orbitcalc. These routines are eg. mandel_per_pixel and JuliaFractal.
Here is the structure of the main routine. For overlay reasons a lot of this
log ic is now in FRAMAIN2.C.
main()
{
initialize things
restorestart:
if loading, look after specifying image
imagestart:
while (adapter<0) {
process keys from short main menu
}
while (1) {
if (calc_status != 2 || showfile==0) {
initialize videoentry from videotable[adapter]
initialize size, color, etc. from videoentry
setvideomode()
}
if (showfile==0) {
load file
}
calcfracinit();
save corners, zoom data
if (showfile != 0) {
calcfract(); /* calculates the fractal until interrupted */
}
resumeloop:
if (no key pressed) {
set keypress = 13 to continue
} else if (key pressed) {
check input key
} else if (batch mode) {
look after batch key
}
process key from long menu
}
}
8.显示方式如何管理(How the video entries are managed)?
get_video_mode(fractal_info): This routine is used to select a video mode to
mat ch a picture we're loading. It loads vidtbl and then tries to find a vi
deo m ode that matches that in fractal_info. Asks the user to select one if
there's no good match. Figures out how to reduce the image to fit the screen
.
select_video_mode(curmode): This is the main-menu routine for the user to pi
ck a video mode. picks default video mode, lets user select mode from menu,
copies entry to videoentry, puts entry in videotable if not there, calls upd
ate_fracti nt_cfg if key reassigned, returns key corresponding to mode.
check_vidmode_key(option, keypress): if keypress corresponds to a videomode
in videotable (for option 0) or vidtbl (for option 1) return the videomode i
ndex, else -1.
check_vidmode_keyname: converts ascii key name into key number.
adapter_detect: checks for type of video (ega, cga, etc) and set video_type,
mode 7text, textsafe.
load_videotable:reads the entries in fractint.cfg into vidtbl copies entries
wit h an associatedfunction key into videotable.
load_fractint_cfg:reads video modes in fractint.cfg into vidtbl (or copies f
rom videotable) if fractint.cfg missing or bad.
update_fractint_cfg:writes the entry in videoentry into the fractint.cfg fil
e. vidtbl:contains the video modes from fractint.cfg
videotable: contains video modes with function keys; initialized in video.as
m
video_type: contains type: hgc, egc, cga, mcga
Here is how the floating point modes are set up. parser.c uses the MathTypes
:
D_MATH: uses double precision routines, such as dStkMul, and FPUsincos. This
is used if we have a fpu.
M_MATH: uses MP type (mantissa, exponent). These routines such as mStkAdd ca
ll MPCadd, which call pMPadd, which calls MPadd086 or MPadd386.
The MP routines work on multiple precision, MPC works on complex pairs of mu
ltiple precision.
L_MATH: uses integer math. Routines such as lStkAdd.
无疑,FRACTINT 19.5的源代码是非常有价值的,我们从中可以学到许多编程技巧。
Fractin t 19.5软件是免费的并且公开全部源代码,所以我们也拟收入,但考虑到内容
太多(约80万 字),只好放在与本书配套的光盘上。购买了该光盘的读者,可从中找到所
有源代码。当 然,如果有条件,你也可以从网上再找。应当说明的是,这些源代码极其
复杂,其编写者都 是高手,所以一般读者别指望都能读懂它们。如果你恰好对C语言十
分熟悉,这些源程序还 是很值得你参考的。由于这些源代码几乎涉及了IBM PC所有硬件
和软件编程技巧,了解这些 源代码的好处是非常明显的,你可以将其中的思想吸收过来
,用到自己的程序中去。即使你 对分形丝毫不关心,这些源代码也有参考价值。
再提醒你一句,在Internet上,用Yahoo!引擎输入 关键词“fractal”、“graphics”
、“FRACTINT”一定能找到你感兴趣的无数东西。 您可以先看一下这里!
--
心事浩茫连广宇,于无声处听惊雷
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.229.154]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:203.200毫秒