Jump to content

Recommended Posts

Hello,

 

I have question - when I want to load data from disk to my code I have to specify location of memory where it will start loading. Question is - how I know what locations of RAM are free so I can load there data ? 

 

Another question - how to create binary file with level data on PC so I can load it up in FastBasic code ? I mean I can convert decimal numbers to binary and paste it for example to notepad but how convert for example PC text file with binary data to binary file ready to load up in FastBasic?

Edited by Materion

Share this post


Link to post
Share on other sites

The topic of free memory is complicated, generally speaking though everything between the top of the DOS you have loaded ($2000 is a safe bet) and the bottom of the screen data (depends on you and how you set up your screen)/OS code. There's a couple of memory locations that track the low memory top and one for the high memory top, although that one is somewhat flexible).

For your purposes, its probably not the right idea to think 'Now I have to squirrel away my level data somewhere safe'. I would suggest rather you make an area big enough in fast basic via an array or dim or whatever, and then just load your data to that address.

 

For the file you may have to take care of items such as "endianness" (which byte is most significant in a two-byte word). You would probably have to write a converter that swapped bytes, for instance. Depending on how you loaded your data in your original program (raw bytes? cr/lf terminated lines? etc.) you may need to do other things. Actually loading the data is a matter of using the fastbasic facilities for IO (if there are any, I don't know) or use the OS IO routines, which is a matter of setting up a few addresses and calling 3-4 OS routines.

Share this post


Link to post
Share on other sites
17 minutes ago, danwinslow said:

The topic of free memory is complicated, generally speaking though everything between the top of the DOS you have loaded ($2000 is a safe bet)

Not sure this would be safe, FB is compiled so what address space does it take, during compile, does it work out the size and set

the load address accordingly, if it does, then it's likely to be loaded just above $2000, I think after loading you would need to 

inspect LOMEM to see what's free, alternatively put you data in high memory below the screen as @danwinslow says, that's generally

a safer bet.

Share this post


Link to post
Share on other sites

Yes, I was not including the size of any compiled programs he loaded himself - that is definitely part of the equation, but also partly why I recommended he just set up his own data area in fastbasic and load into it. If you really need to store outside of fbasic, then lowering the top memory pointer by the amount you need (after screen is established, depending on how you do that), is usually what's done. That will sort of protect it from other things. You then binary load to to that address and above, taking care that you've left enough space so you don't blow you screen/dlist info, again, depending on how you've done the screen. If you let the OS do your screen via like a 'graphics 7' call, then it will be packed nicely above everything at the high end of memory, if I recall correctly.

Edited by danwinslow

Share this post


Link to post
Share on other sites
1 hour ago, TGB1718 said:

FB is compiled

Fastbasic is not compiled, but it looks like because the executable has both the runtime and the bytecodes (tokenized program) together.

 

2 hours ago, Materion said:

I have question - when I want to load data from disk to my code I have to specify location of memory where it will start loading. Question is - how I know what locations of RAM are free so I can load there data ?

Executables always start at $2000 and the lenght depends on the program, but running from the IDE (the editor) would leave about 6K less than the "compiled" version for the FastBasic internals and some extra space less from your own source code. If you use the cross-compiler, then you can set the starting address to whatever you want. If you don't need DOS, you can start at $700 if you want (and have the right loader).

 

If you need to load into a fixed memory address, your best bet is to use high memory below the screen as it was said.

 

2 hours ago, Materion said:

Another question - how to create binary file with level data on PC so I can load it up in FastBasic code ? I mean I can convert decimal numbers to binary and paste it for example to notepad but how convert for example PC text file with binary data to binary file ready to load up in FastBasic?

Simply create Fastbasic DATA statements and let the compiler assign the memory to it, which you can point to by reading the ADR of the data array. From the manual:

Quote
  DATA big() byte = $12,$23,$45,
  DATA       byte = $08,$09,$15

Of course, you can assign decimal, hexa or strings (with constraints), and all those lines could be copied and pasted into your source code.

 

Another way is to create raw files with your data and let the cross-compiler to load it automagically for you into the executable... Also from the manual:

Quote

Loading data from a file

The cross-compiler also supports loading data from a file directly into the program, using the BYTEFILE (abbreviated BYTEF.) and WORDFILE (abbreviated WORDF. or simply F.) types and a file name enclosed in double quotes.

Example:

  DATA img() bytefile "img.raw"
  DATA pos() wordfile "pos.bin"

The compiler will search the file in the same folder than the current basic source.

I guess that you could also convert your data into an assembly listing (.WORD, .BYTE, .CDATA, etc.) and let the cross-compiler read that and include in the XEX binary file, probably allowing you to assign fixed addresses using ORG opcode... Disclaimer: I've never used the cross-compiler, so I don't know how it really works the compilation and optimization it performs for Fastbasic.

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...