Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: Emil_halim on April 11, 2013, 09:38:27 AM

Title: IncBin instruction
Post by: Emil_halim on April 11, 2013, 09:38:27 AM
Hi Charles'

does Oxygen basic has something like 'incBin' include binary that will load a file and put it with exe file while
compilation , giving the user the start address of memory containing the file and the length?  
Title: Re: IncBin instruction
Post by: Charles Pegge on April 11, 2013, 10:21:59 AM
Yes you can use embedfile to embed any kind of file (within the includepath spec)

Supposing you had a file: t.txt containing ABC

sys p

embedfile "t.txt",p

byte b at p

print b[3] '67

I haven't got a formal parameter for length but, since it is stored as a pseudo-bstring, you can recover the length like this:

dword le at (p-4)
print le '3
Title: Re: IncBin instruction
Post by: Emil_halim on April 11, 2013, 10:41:21 AM

Ok , thanks Charles,

for the length , i have an idea .

can we put a label before and after embedfile instruction , then we can subtract this label to get the length.

so what do you think?
Title: Re: IncBin instruction
Post by: Charles Pegge on April 11, 2013, 11:14:45 AM
Embedded data is stored in dataspace, which is curently unlabelled. All refernces are assigned to pointer variables (also string variables)

PS: Just realised you can also refer to embedded data as a bstring constant

bstring p
embedfile "t.txt",p
print p
print len p
Title: Re: IncBin instruction
Post by: Aurel on April 11, 2013, 01:02:46 PM
Charles ..
I never ask about this but this looks to me like command bind
so do i can bind any file to already created exe ?
Title: Re: IncBin instruction
Post by: Charles Pegge on April 11, 2013, 07:41:40 PM
The bind keyword is used for low level linkage to DLLs. EmbedFile is more like embedding resources.
Title: Re: IncBin instruction
Post by: Emil_halim on April 12, 2013, 03:50:39 AM
Hi Charles,

what about Bin file that may contains many text terminator char.

does the len get it correctly?
Title: Re: IncBin instruction
Post by: Charles Pegge on April 12, 2013, 04:53:52 AM
Yes, it stores the whole file content as a binary string of specified byte count.
Title: Re: IncBin instruction
Post by: Emil_halim on April 12, 2013, 05:16:29 AM
so deos len get the correct length?
Title: Re: IncBin instruction
Post by: Charles Pegge on April 12, 2013, 05:43:35 AM
Yes, if you map a bstring onto the data
sys p
embedfile "t.something",p
bstring s at p
print len s

You can also map any type or structure to p at the same time

byte b at p
image img at p

or at any offset of p

rgba pixel at (p+256)

print pixel[10].blue



Title: Re: IncBin instruction
Post by: Emil_halim on April 12, 2013, 06:00:09 AM

that's great Charles.

one more thing , Sphinx C-- also support including a specific part of the file as well.

what do you think? 
Title: Re: IncBin instruction
Post by: Charles Pegge on April 12, 2013, 06:12:30 AM
Could add offset and length as optional parameters. Does Sphinx do it this way?
Title: Re: IncBin instruction
Post by: Emil_halim on April 12, 2013, 06:17:18 AM

No , it is only include the needed part of the file.

something like this
Code: [Select]
sys p
embedfile "t.something",p , optional offset ,optional  len