Compiling a Big QB program in 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
http://www.mandelbrot-dazibao.com/Programs/Programs.htm

Notice TCRay is a QB4.5 interpreted program, Jark never had the patience to compile his work,
he just tested it interpreted and went on adding features.


The program is made of has 3 files:

TcRay21C.bas - The Main file.
TcLib17L.bas - The SVGA graphics library.
Tclib17.bi - The include file for the library.

Porting TCLib17.bas

In TCLib17.bas
It is a "pure QB" SVGA library. Most of its functions are obsoleted by FB as they are implemented as QB-style keywords. I had my share in developing that lib so you can trust me for this part ;)

Comment out the contents of the ClearScreen sub and add this
CLS

Comment out the contents of the Point24 sub and add this:
a& = Point(x%,y%)
red% = a& Shr 16
green% = (a& Shr 8) And 255
blue% = a& And 255


Comment out the 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 switching modes so mode must be set before outputting 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 warn you all changes required except two come from a couple of (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

In TCLib17.bi
ERROR: Duplicated definition, found 'RGB' (RGB is a keyword in FB)
Add:
#undefine RGB
Before the line giving the error.

ERROR: Duplicated definition, found 'ScreenRes' (ScreenRes is a keyword in FB)
Add:
#undefine ScreenRes
Before the line giving the error.

ERROR: Duplicated definition, found 'Name' (Name is a keyword in QB)
Add
#undefine Name
Before the line giving the error.

In TCRay17.bas
ERROR: Duplicated definition, found 'Acos' (Acos is a keyword in QB)
Add
#undefine 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 undefine it so search and replace type$ to _type$

ERROR: Expected 'END IF', found 'END' END FUNCTION
This is an error caused by a quirk introduced in FB. Single line If's having a colon after THEN require an ENDIF, it has to do with macros... What reason had Jark to put colons past his THEN's escapes me. QB does not require them at all and FB behaves as expected without them. Remove all colons after THEN keywords. Search and Replace THEN : to THEN

ERROR: Array access, index 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 xo with _xo in the lines which error 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:fake:(.text+0x174d): undefined 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!

Сайт ПДСНПСР. Если ты патриот России - жми сюда!


Знаете ли Вы, что такое мысленный эксперимент, gedanken experiment?
Это несуществующая практика, потусторонний опыт, воображение того, чего нет на самом деле. Мысленные эксперименты подобны снам наяву. Они рождают чудовищ. В отличие от физического эксперимента, который является опытной проверкой гипотез, "мысленный эксперимент" фокуснически подменяет экспериментальную проверку желаемыми, не проверенными на практике выводами, манипулируя логикообразными построениями, реально нарушающими саму логику путем использования недоказанных посылок в качестве доказанных, то есть путем подмены. Таким образом, основной задачей заявителей "мысленных экспериментов" является обман слушателя или читателя путем замены настоящего физического эксперимента его "куклой" - фиктивными рассуждениями под честное слово без самой физической проверки.
Заполнение физики воображаемыми, "мысленными экспериментами" привело к возникновению абсурдной сюрреалистической, спутанно-запутанной картины мира. Настоящий исследователь должен отличать такие "фантики" от настоящих ценностей.

Релятивисты и позитивисты утверждают, что "мысленный эксперимент" весьма полезный интрумент для проверки теорий (также возникающих в нашем уме) на непротиворечивость. В этом они обманывают людей, так как любая проверка может осуществляться только независимым от объекта проверки источником. Сам заявитель гипотезы не может быть проверкой своего же заявления, так как причина самого этого заявления есть отсутствие видимых для заявителя противоречий в заявлении.

Это мы видим на примере СТО и ОТО, превратившихся в своеобразный вид религии, управляющей наукой и общественным мнением. Никакое количество фактов, противоречащих им, не может преодолеть формулу Эйнштейна: "Если факт не соответствует теории - измените факт" (В другом варианте " - Факт не соответствует теории? - Тем хуже для факта").

Максимально, на что может претендовать "мысленный эксперимент" - это только на внутреннюю непротиворечивость гипотезы в рамках собственной, часто отнюдь не истинной логики заявителя. Соответсвие практике это не проверяет. Настоящая проверка может состояться только в действительном физическом эксперименте.

Эксперимент на то и эксперимент, что он есть не изощрение мысли, а проверка мысли. Непротиворечивая внутри себя мысль не может сама себя проверить. Это доказано Куртом Гёделем.

Понятие "мысленный эксперимент" придумано специально спекулянтами - релятивистами для шулерской подмены реальной проверки мысли на практике (эксперимента) своим "честным словом". Подробнее читайте в FAQ по эфирной физике.

НОВОСТИ ФОРУМАФорум Рыцари теории эфира
Рыцари теории эфира
 10.11.2021 - 12:37: ПЕРСОНАЛИИ - Personalias -> WHO IS WHO - КТО ЕСТЬ КТО - Карим_Хайдаров.
10.11.2021 - 12:36: СОВЕСТЬ - Conscience -> РАСЧЕЛОВЕЧИВАНИЕ ЧЕЛОВЕКА. КОМУ ЭТО НАДО? - Карим_Хайдаров.
10.11.2021 - 12:36: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от д.м.н. Александра Алексеевича Редько - Карим_Хайдаров.
10.11.2021 - 12:35: ЭКОЛОГИЯ - Ecology -> Биологическая безопасность населения - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> Проблема государственного терроризма - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> ПРАВОСУДИЯ.НЕТ - Карим_Хайдаров.
10.11.2021 - 12:34: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вадима Глогера, США - Карим_Хайдаров.
10.11.2021 - 09:18: НОВЫЕ ТЕХНОЛОГИИ - New Technologies -> Волновая генетика Петра Гаряева, 5G-контроль и управление - Карим_Хайдаров.
10.11.2021 - 09:18: ЭКОЛОГИЯ - Ecology -> ЭКОЛОГИЯ ДЛЯ ВСЕХ - Карим_Хайдаров.
10.11.2021 - 09:16: ЭКОЛОГИЯ - Ecology -> ПРОБЛЕМЫ МЕДИЦИНЫ - Карим_Хайдаров.
10.11.2021 - 09:15: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Екатерины Коваленко - Карим_Хайдаров.
10.11.2021 - 09:13: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вильгельма Варкентина - Карим_Хайдаров.
Bourabai Research Institution home page

Боровское исследовательское учреждение - Bourabai Research Bourabai Research Institution