Sign in to follow this  
Guest

Adventures into MASM

Recommended Posts

Greatings,Finaly I got some corage (although not a lot of time) to experiment MASM to compile scenery.I constructed a model in GMAX which successfully appears in the FS2002 world. But what I realy miss is the possibility of editing the object

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

When I edit my asm files made by GMax, I just compile them with BGLC (the version that came with the effects SDK). That works and you don't need to work with all those include files etc etc.ArnoMember NL2000 Teamhttp://home.wanadoo.nl/arno.gerretsen

Share this post


Link to post
Share on other sites

Hi all.In fact, BGLC is 'drag'n'drop' in nature. From the desktop or explorer, just drag the ASM file over the BGLC icon, drop it, and get a BGL file. Very easy.Also, new ASM macros may be referenced by the 'include filename.inc' command at the top of the ASM text, making BGLC as extensible as MASM itself.Christian Stock has been experimenting with MASM and BGLC, and has developed new macros to create some types of TMF-style flatten and hydro polygons for FS2002.

Share this post


Link to post
Share on other sites

Hi Arno,Thanks for your quick reply!I was using the FS2000 bglc! I didn't remember that a new BGLC was included in the effects SDK!Now it all works!ThanksjmfPS - Now is back to understand what is all this code about!!!

Share this post


Link to post
Share on other sites

Hi there!Any clues on to how to code new macros? I guess that this is to be coded using Microsoft assembler but what confuses me is what has this to do with MSFS scenery engine? What is the approach here? My guess is that BGL macros correspond to certain commands that are coded into the MSFS engine. So what is the nature of these new macros? Is it just a combination of existing macros? Is there any more detailed information about this new (at least for me) language or any tutorial?If it is possible at all what is the approach to understanding all this!CheersjmfThanksjmf

Share this post


Link to post
Share on other sites

I just finished getting comfortable at a beginner level with scasm...then here comes this new language! LOLI'd enjoy finding a good resourse for teaching this bglc language also, so if you run into any good teachings or writings, please let me know.Bob Bernstein

Share this post


Link to post
Share on other sites

Basically the commands are similiar to SCASM, only the names are different. Most parameters given to the commands are the same, etc.But I am also still figuring out how to use them all in BGLC :).ArnoMember NL2000 Teamhttp://home.wanadoo.nl/arno.gerretsen

Share this post


Link to post
Share on other sites

I haven't recognized the lables and how to construct the logic of order of the commands yet. stuff like variable initializing, syntax in commands....I can see some basic familier notions, but its not enough for me to feel comfortable.B

Share this post


Link to post
Share on other sites

Bob,The way I am doing is to model something very simple in gMAX and compile it to BGL but keeping the intermediate asm files. Do the same in FSDS and generate scasm. Then compare both. Most of the SCASM commands may be translated into MASM but as you say the mechanics of it is a bit different. Also the fact of not having the coordinates in LAT LON or meters in meters (not sure about the last one! ) makes life a bit more dificult (well very difficult).Finaly, there is a plugin that allows exporting a FSDS object to dxf. Then you can import it in GMAX. Generate the respective codes (ASM & SCASM) and compare!Hope this helpsjmfPS: It seems that it is not only MASM we need to learn! It is gmax as well! It seams pretty powerfull.

Share this post


Link to post
Share on other sites

If you download my Ryans Creek aerodrome you'll find a small utility called txt2asm. With that you can use real coordinates like this LAT32_E172:22:14.5, run it through txt2asm and then through BGLC. Very handy...Cheers, Christian

Share this post


Link to post
Share on other sites

MASM is the tool from M$ to write programs in assembly code (not what we want though). It has a 'data' and 'code' section. Since we don't want to write any 'code', we only use the 'data' section.The data section works like this:You can basically write out variables in this section (eg into your bgl file). You do this like this:dd 50 , writes a INT32 (4byte int) into the bgl.there are different variables: db (1byte), dw (2bytes), dd (4bytes), df (float). They are shorts, eg dd = DWORD, etc. There is a manual that comes with MASM. Read my MASM howto to find the link to download MASM. one of the packages (the visual studio processor pack) includes a reference manual for masm.You probably have seen how these variables get used in the header section.Now on to macros: in the include files you'll find some macros like:macro whatever arg1, arg2dd arg1dd arg2end macroso if you want to put this into your code:dd 20dd 50you might as well write:whatever 20, 50you can build much more complex macros using other macros and labels, even 'if' commands etc, but these basics should get you going. Have a look in the include files how microsoft did it, you can learn a lot there.Now the neat thing is, because all MASM does is write dd, db, etc variables, we can write our own macros and add macros for all the missing stuff, like I started for the terrain bgls. Even if microsoft would abandon the bgl code and do something completely different, we can again write our own macros and produce the corresponding scenery files...btw, no tutorial, I figured all this out by myself!Cheers, Christian

Share this post


Link to post
Share on other sites

Thanks very much christian,I will follow your sugestions! It seems a bit confusing but at least I know it can be done!I guess that I might be thinking about this in a diferent perspective. This is low level programming! I am not that used to that! My dificulties are in understanding how these bunch of dd, dw or db result in scenery being dsplayed. I will get there .... ;)Thanks for your explanation!jmf

Share this post


Link to post
Share on other sites

Greatings again,I think I will be around for a while now! :)Here is the question! I noticed that the code generated by GMAX (or better, by the plugin) is not very compact. If you are not carefull during the design you end up with a lot more polygons than it's realy necessary. Also I am not sure how to remove non visible poligons. But that is another matter.It would be very usefull if MS issued guidelines and tips in how to use gmax to produce efficient designs in the so expected fs2002 scenery SDK. I am sure that you can't port all the features of gmax into MSFS engine.The other dificulty is my aparent inability of controlling the scale of my design. If for example I want to use 125mm scalling (ie, 8 units for each metre) how do I set it up in gmax? I would like to speed up things by using the equivalent of ScaleX in MASM and I am not convinced that the plugin is optimizing the object for speed!The other thing I would like to know is how to separate the various components of an object? Perhaps a part of an object is repeated over and over and in SCASM I had the chance to define that once and use transformcalls to reproduce as many as I wanted without filling up a BGL with unecessary points. The code produced by gmax is just a compact list of vertexes and draw_tri. I don't even know what belongs to what! The only imediate solution is to select each part individually and export each one separately and then assemble everything manualy in MASM.Some suggestions please!!

Share this post


Link to post
Share on other sites

>Here is the question! I noticed that the code generated by >GMAX (or better, by the plugin) is not very compact. If you >are not carefull during the design you end up with a lot >more polygons than it's realy necessary. Also I am not sure >how to remove non visible poligons. But that is another >matter.I always remove the polygons that are not visible in GMax, just select the polygon you don't want and delete it. Then there are only polygons in the code that you want.And about the code, I think it is very compact. All vertices are collected in one list and then all the polygons are drawn (all the triangles actually, as all polygons are split up in triangles, this make it faster to process by the scenery engine).>It would be very usefull if MS issued guidelines and tips in >how to use gmax to produce efficient designs in the so >expected fs2002 scenery SDK. I am sure that you can't port >all the features of gmax into MSFS engine.It's true that not all features of GMax are supported by the exporter, but I don't hope that the scenery SDK will only be a collection of GMax tips. Just like the MakeMDL SDK, it wouldn't be worth the name SDK in that case. But that is my opinion :). Most of these things can already be found on forums like this one.>The other dificulty is my aparent inability of controlling >the scale of my design. If for example I want to use 125mm >scalling (ie, 8 units for each metre) how do I set it up in >gmax? I would like to speed up things by using the >equivalent of ScaleX in MASM and I am not convinced that the >plugin is optimizing the object for speed! As far as I have seen from the asm files, the scale is always set to 0.5. But the new commands for the vertices allow non integer values, so this doesn't mean your model can't be more detailed then the 0.5 scale. I think you should bother about the scale to much :), I have made a nice little control tower with some stairs to enter it and these had a width of 0.1 meters and they showed up just correct.>The other thing I would like to know is how to separate the >various components of an object?If you leave the optimize tick in the exporter you will see that each part of your object gets his own code (but this make a code even longer and probably less efficient).> Perhaps a part of an object >is repeated over and over and in SCASM I had the chance to >define that once and use transformcalls to reproduce as many >as I wanted without filling up a BGL with unecessary points.I don't now if it is always faster to use the TransformCalls, these commands do require some calculations from the scenery engine and it might be much more efficient to just list a little more points and draw all the objects that way.ArnoMember NL2000 Teamhttp://home.wanadoo.nl/arno.gerretsen

Share this post


Link to post
Share on other sites

I believe the makemdl tools translates your model 1:1 into bgl. This means you are responsible for deleting any non-visible triangles yourself! If you want a framerate friendly model, it's really up to you do make it framerate friendly (ie use as few polygons as possible to get as much detail as possible). It's also up to you to make an efficient texture, ie fit all textures into one texture as small as possible.The reason you have vertices and trilists is very simple. trilists are not just simple triangles, but so called 'tristrips'. They are more efficient as they use less points. For comparison, say you have 3 triangles:triagles: 3 x 3 points = 9 vertices.trilist( joint triangles ): 3 points + 1 point + 1 point = 5 vertices(you have to imagine a simple sketch here, where are the sketching tools in this forum :-lol )It's all about minimizing code and being framerate friendly :)Hope that helps.Christian

Share this post


Link to post
Share on other sites

It's not that complicated really. FS2K2 only reads binary data, and thats what you're producing with the dd, dw, etc.Let's dive straight into the bgl part (this is some pseudo code, not necessarily correct):the scenery engine reads '00 AA' (this is a dw number in hex code). The first number is always a so called 'opcode'. You can look those up in the Scenery SDK are in the bglmac.inc.00 AA stands for NEW_RUNWAY. So, FS2K2 knows that a runway follows. Now, FS2K2 expects some entries to follow, eg location, length, heading, etc (also explained in the Scenery SDK)... For example, something like this:dw 00AAh 'runway opcodedd 563882 'latitudedd 7668092 'longitudedd 176 'altitudedw 5673 'headingdw 765 'magnetic variationdw 1200 'lengthdw 20 'widthdw 01 'runway surface, 01 = grassThis is quite painful, so you can write a macro:macro NEW_RUNWAY lat, long, alt, heading, magvar, length, width, surfacedw 00AAh 'opcodedd latdd longdd altdw headingdw magvardw lengthdw widthdw surfaceend macroAnd then in your code you writeNEW_RUNWAY 563882,7668092,176,5673,765,1200,20,01Of course if you muck this up and write a wrong macro with an argument missing, FS2K2 will get confused and think, ok, next thing is an opcode, but it isn't and FS2K2 may either ignore whats coming or simply crash on you.So they key to remember is that everything is hardcoded, FS2K2 will read an opcode and automatically knows what follows and what to do with it. Then it expects an opcode again. Mess up the order and FS2K2 won't know what to do anymore.Cheers, Christian

Share this post


Link to post
Share on other sites

Hi Arno as most people now have cards that "do"T+L transforms (the "T" in T+L) do not have anyware near the hit that they used to.Thats why T+L is an item that is chooseable in set up. When FS 2002 "sees" ones card can perform T+L then the engine just has the card do the transforms rather than doing it in software. I hope this is of some help Dan http://members.rogers.com/klasik2/danlogo.gifhttp://members.rogers.com/eelvish/flyurl.gif

Share this post


Link to post
Share on other sites

Hi Christian good discrption of how faces (the real basic building blocks of all meshes) are handled by both the hardware and softwaredirX8 and Open G.L. as well. One thing I might add for anyone makeingmeshes is allways keep it simple stupid.(A.K.A K.I.S.S.)there are a couple of things one can do use extruded splines when ever possable all of my building are done as splines and then extruded(I.E. no sticking boxes together!) trust me just that makes a big differancein the number of pollys in a mesh and along with good texturing tricks like cramming will go a long way to keeping frame rates highso everyone can enjoy what we work so hard in creating. I hope this is of some help to everyone Danhttp://members.rogers.com/klasik2/danlogo.gifhttp://members.rogers.com/eelvish/flyurl.gif

Share this post


Link to post
Share on other sites

As far as I have seen from the source code there are 3 vertices for each triangle. So that makes 9 for 3 triangles and not 5 as you say above (maybe I understood it work :)). The texture mapping is added to the vertex and that also makes that the same vertex can not be used on another polygon.ArnoMember NL2000 Teamhttp://home.wanadoo.nl/arno.gerretsen

Share this post


Link to post
Share on other sites

Hi Arno what Christian is refering to is a method more or less combines faces (triangles)by "ignoring" one edge between the two faces that make up a standard polly. However I have found that the above can cause problems with things like mip mapping and it's "texels" when a lower res bit map will not line up with the higher res bit map due to the "missing" edge in the middle. That I have found is one of the causes of blury textures when extended bitmaps like dxt1 etc are used. So in short just use "standard" polly'sin fact the number of polly's with in reason is much less importantthan number and resolution of your textures as buildings are simpleobjects. You have seen pics of our scenery lots of models that lookcomplex but are not because like I said they are all done from splines (no pre-made boxes etc) and the fact that Jim and I are verycarefull when doing up textures and in how they are applied. I am sorry to say it again but forget FSDS use gmax for models.(no macros) And a face ( triangle) has three verticies not 9 in other words a face(triangle) is made up of three points and the three lines(edges)that connect the vertices say AB,BC,CA try it with a pice of paper!!. Dan again I hope this helps everyone to understand the basics of the3D worldhttp://members.rogers.com/klasik2/danlogo.gifhttp://members.rogers.com/eelvish/flyurl.gif

Share this post


Link to post
Share on other sites

I am also using only GMax for my 3D objects now. I make a library bgl from them and can then call them using a macro in GroundMaker. Works great and the framerate is very good.And the considerations you give about the complexity, etc are the same as always :), even in FSDS you had to think about things like that to keep the frames good.ArnoMember NL2000 Teamhttp://home.wanadoo.nl/arno.gerretsen

Share this post


Link to post
Share on other sites

Hi there,I finally got the object optimised! Deleted all the invisible poligons (such as bottoms and tops of cylinders etc ...I can understand that defining all the vertexes and triangles in one go might be faster then using "transformcalls" to the same object!The only disadvantage is that the bgl goes from 14k to 219k!! I wonder what is the impact of this!Anyway, the same object in GMAX/MASM has very similar performance to the one produced with FSDS/SCASM. Maybe it is a bit faster in the former case. Furthermore, on the GMAX case, the autogen does not get excluded as it happen with the SCASM case.The only problem still to solve is the shadow and crash detection.Well crash detection is a problem in this case has the object is quite complex and it seems that each cm of the object is tested for this condition. This is obviously not necessary and it drops the framerate dramatically. What I would like to do is to make crash detection based on same boundaries of the object only as aircraft are supposed to land there (so no crash detection there)! Basically the equivalent to VectorJump would do the trick but I would like to include that in the MASM file to keep everything in the same bgl!The other problem is the shadow. First there is no need to have the whole object casting shadow, only the top polygon would suffice, otherwise things slows down a lot. As I said before in a different post, I am using ADDMTN to force this object to be drawn before the runway which sits on the top. This object is something like a platform with pilars and sits a few metres above sea level. Is there any alternative way of doing this as ADDMTN is being phased out? One cause of using ADDMTN is that the shadow works fine up to a altitude of approx 2500. Beyond that the shadow starts to be visible on the top of the object and runway. I will make a simple version of this object and post the code/image to illustrate the problem.Great discussion! Thanks guys!jmf

Share this post


Link to post
Share on other sites

Hello Dan,Yes I will!However, I made the surface 3 metres thick (as it is in reality I hope)! As you suggested earlier, I always prefer to draw an outline of the shape and then extrude into 3D! That seems to work OK for both FSDS and GMAX.Now the interesting part is that shadows are not supposed to be cast on other 3D objects. However, since it eventually goes on the top of the platform surface, before that it did the same on the supporting pilars (which in this case is truly realistic).I will post the code later on so that this may become THE chalenge!! ;)CheersjmfPS - if the object is not ADDMTN'ed, the shadow works fine. In this case, the runway goes under the object. Well not really has it sits on the top but the object is drawn after so it looks really strange.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this