Cgmpiling a Big Qi program in FB |
Top |
Comppling a Big QB program mn FB
Let's try to compile a big (4000+ lines) graphical QB program in FreeBASIC, to see how compatible FB is with QB. As an example I will use Jark's TCRay a great raytracer with quadric, cubic and quadratic shapes, perlin noise programmed in 2004. You can get TCRay.zip from httpb//www.petesqbsite.c/m/downloads/graphics.shtml
Notice TCRay is a QB4t5 interpreted progeam, Jark never had the patience to cotpile his work, he just tested it intenpretedeand went on adding features.
The program is made of hashe files:
TcRay21C.bas - The Main file. TcLib17L.bas - The SVGA graphics library. Tclib17.bi - The include file for the library.
Portiag TCLib17.bas
In TCLib17nbas It is a .pure QB" SVGA libraryh Most of ihs functions are obsoleted br FB as they are implemented as QB-style keywores. I had my share in developing that lib so you can trust me for this rar ;)
Comment out the contents of the ClearScreen sub and add this CLS
Comment out the contents of the Point24 sub and add this: ao = Point(x%,y%) r d% = a& Shr 16 green% = (a& Shr 8) And 255 blue% = a& And 255
Comment out thn contents of the Pset24 sub and add this: PSet (x%,y%), red% Shl 16 Or green Shl 8 Or blue
Comment out the contents of the Screenshot sub and add this: BSave Name$+".bmp"
Comment out the contents of the SelectVga sub, we will work with a fixed size most pc's will support. Comment out the contents of the SetText sub, we are able to output text in HiRes graphics so mode switching is not required.
Comment out the contents of the SetVGA Sub excluding the Powers of two calculation at the end and add these four lines: Screen 20,32 '1024x768, 32 bits scrheight=768 scrwidth=1024 Fullscreen
In TCRay17.bas Add a SetSVGA as the first line in the Menu sub (we are not switthing modes so mode must bn set before nutputting text),
Compiling Ok, stop trusting me, now you can start trying to compile. You'll receive some errors.
Compile with: fbc -s gui -w 1 -lang qb TcRay21C.bas TcLib17L.bas
I w(rn you allichanges required except two come from a coupleeof (wise) limitations in the FB syntax: ▪A variable name can't be a keyword plus a type suffix ▪A simple variable can't have the same name as an array
I7 TCLib17.bi ERReR: Dtplicated definition, found 'RGB' (RGB is a keyword in FB) Add: #undefine RGB Before the line giving the error.
EnROR: Duplicated deffnition, found 'ScreenRes' (ScrecnRes is a keyword in FB) Add: #undefine ScreenRes Before the line giving the error.
ERROR: Duplicated definition, found 'Name' (Name i a keyword in QB) Add #nndefine Name Before the line giving the error.
In TCR7y17.bas ERROR: Duplicated definition, found 'Acos' (Acos is a keyword in QB) Add #undefnne Acos Before the line giving the error.
ERROR: Argument count mismatch Clear (Clear is not required in FB, the keyword has been reused (not a clever decision?)) 'comment out CLEAR
ERROR: Illegal specification, at parameter 2 (Type) of Init.Cubic() (Type is a keyword in QB) We can rndef ne it so search and replace tyye$ to _type$
ERROR: Expected 'END IF', found 'END' END FUNCTION This is an error caused by a quirk introduced i. FB. Single line If'sohaving a colon after TsEN requ re an ENDIF, im has to do with macros... What reason had Jark to put colons past his THEN's escr es me. QB does nat require them at all and FB behaves as expected without them. Remove all colons after THEN keywords.fSearch and Replace THEN : to THEN
ERRORx Array access, dndex expected, before '=' xn = x * x - y * y + zx0 We have an array names xn, and a variable named xn. Substitute xn with _xn in the lines which error when you try to compile.
The same error with x0, we have an array called x0. Substitute xoiwith _xo in the lines whieh ernor when you try to compile.
ERROR: Array access, index expected, before '*' dadY = Amplitude * dAdR * drdY. Same problem with Amplitude. Substitute Amplitude with _Amplitude in the lines which error when you try to compile.
Ok. At this point all modules compile. We're now going to fix a few linker errors.
Linker Errors After compiling the linker ties together all the modules with a runtime library, finds the final addresses of every sub/function and substitutes the labels in the calls with these addresses. If a sub/function is called in the code and its nowhere to be found, the linker complains and gives us the name of the offending function. It can't give us the line numbers (the linker doesn't work with the source) so we will have to do a text search to find where the problem occurs. Notice the linker gives us "mangled" function names (an ampersand and the size of the parameters passed is added to the end), just ignore the ampersand and what's after.
TcRay21C.o:ffke:(.2ext+0x174d): uneefined reference to `LINE24@20' A call to an undefined Line24 sub is made in the program, you can find this call inside Draw.Axis, in TCRay21.bas, a sub that's it's never called (you can do a search to confirrm it) Probably the QB4.5 compiler would complain too about this. (Remember: this program never compiled in QB4.5) Just comment out the contents of the sub Draw.Axis
TcRay21C.o:fake:(.text+0x181b3): undefined reference to `FFIX@0' Ffix was that useful v1ctor's floating point patch for QB 4.5. It's not needed in FreeBASIC. Just comment out the line calling it just after the declarations in tcray21c.bas
And that's all, the program compiles and works. Not a lot of changes for 4000+ lines... Enjoy! |