[futurebasic] Re: [FB] WRITE FILE# and READ FILE #

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2003 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Thu, 01 May 2003 12:22:56 +0200

barrie wrote:
> on 4/30/03 8:24 PM, Alain Pastor at apastor@... wrote:
> 
> 
>>
>>barrie wrote:
>>
>>
>>>>DEF BLOCKFILL works at the byte level. Each of the two bytes that
>>>>constitute the integer variable is set to 1. See:
>>>>
>>>>dim x as int // 2 bytes
>>>>defstr word
>>>>x = 1 // the value you want to store
>>>>print bin$(x) // only one byte is set
>>>>x = 257 // the value you finally get
>>>>print bin$(x) // shows the two bytes are set to 1
>>>>
>>>>
>>>>Alain
>>>
>>>Alain
>>>Does this mean that my BLOCK FILL is working OK? If so, how do I convert the
>>>array to real numbers?
>>
>>
>>No, it is not OK, if the value to set is 1 and you work with integers.
>>The number of bytes to fill and the starting address should be OK, but
>>I guess you can only clear the array with 0, in your case.
>>What do you mean by real numbers?
>>
>>Alain
> 
> I should have said original numbers. I originally put 1's into the array and
> got 257's out of the array..... I am clearly out of my depth here so I will
> be content with just using BLOCK FILL to clear arrays with 0.
> Many thanks for your help

Barrie,

here is another attempt to explain what's going on, with a possible 
solution to your problem.
Use the following in the Console:


/*
      Another way to explain what DEF BLOCKFILL
      does. We will force the storage location of
      a few variables using the semicolon syntax
*/
dim L as long;0,¬
     I1 as int;0,¬
     B1 as byte,B2 as byte,I2 as int;0,¬
                           B3 as byte,B4 as byte
/*
      A bit clumsy, but sometimes useful.
      L is declared as a LONG. The semicolon
      tells the compiler to declare the next
      variable at a given offset in memory
      (here zero) from the start of the variable that
      is just being declared.
      That means, in the above statement, that the
      I1 variable will start in memory at the same
      address as L.
      The I1 variable is also declared with the semicolon,
      so, same pattern, same punishment here : B1 will
      start at the memory location of I1 which
      is also the L variable's location, they all
      share the same address like shown below:
*/
print "L  address",@L
print "I1 address",@I1
print "B1 address",@B1
print
/*
      Same thing for I2 and B3
*/
print "I2 address",@I2
print "B3 address",@B3
print
/*
      DEF BLOCKFILL(startAddress, numberOfBytes, value)
      sets numberOfBytes, starting from startAddress,
      with value.
      The following statements are equivalent:

      DEF BLOCKFILL( @L , SIZEOF(LONG)  , 1 )
      DEF BLOCKFILL( @I1, SIZEOF(INT) *2, 1 )
      DEF BLOCKFILL( @B1, SIZEOF(BYTE)*4, 1 )

      In this snippet of code, the same thing
      can be achieved like so (you can replace
      the four statements below with one of the
      above):
*/
B1 = 1
B2 = 1
B3 = 1
B4 = 1
/*
      Setting the 4 individual byte variables
      alters also the 2 integer and the long variables,
      since all the smala is squatting the same area
      in memory.
      Below, is how they now look like in decimal format.
*/
print L
print I1,I2
print B1,B2,B3,B4
/*
      We can examine the internal arrangement
      of the bits in memory with the binary format.
*/
defstr long
print bin$(L)

defstr word
print bin$(I1);bin$(I2)

defstr byte
print bin$(B1);bin$(B2);bin$(B3);bin$(B4)

/*
      For arrays that don't require too much memory
      you can set first a default array, then when
      you need to reinitialize the array with values
      other than zero (in the latter case DEF BLOCKFILL
      is OK) you can copy the values of your default array
      into your working array. A silly example:
*/

_maxItems = 10 // set to your liking
dim gWorkingArray(_maxItems) as int
dim gDefaultArray(_maxItems) as int
dim i


local fn InitDefaultArray
   dim item
// setting the default array
   for item = 1 to _maxItems
     gDefaultArray(item) = item
   next
end fn


local fn ShowWorkingArray
   dim item
// show items in working array
   for item = 1 to _maxItems
     print gWorkingArray(item)
   next
end fn


local fn InitWorkingArray
// fill working array with default array"s contents
   blockmove  @gDefaultArray(0),¬
              @gWorkingArray(0), ¬
              sizeof(gWorkingArray(0))*(_maxItems + 1)
end fn


local fn DoWork
   dim item
// alter working array
   for item = 1 to _maxItems
     gWorkingArray(item) = rnd(_maxItems)
   next
end fn

print "Init DEFAULT array"
fn InitDefaultArray

print "Show items in WORKING array at startup"
fn ShowWorkingArray

print "Init WORKING array with default values"
fn InitWorkingArray

print "Show items in WORKING array after init"
fn ShowWorkingArray

print "Work with WORKING array"
fn DoWork
fn ShowWorkingArray

print "Reinit WORKING array with default values"
fn InitWorkingArray

print "Show items in WORKING array after reinit"
fn ShowWorkingArray

/*
      Note:
      Of course, you could also use a FOR/NEXT
      loop to fill the working array, however
      BLOCKMOVE is faster and it is a single
      statement.
*/


Alain