BLOAD: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[BLOAD]] loads a binary graphics file created by [[BSAVE]] to an array.  
[[BLOAD]] loads a binary graphics file created by [[BSAVE]] to an array.
 


{{PageSyntax}}
{{PageSyntax}}
: [[BLOAD]] {{Parameter|fileName$}}, [[VARPTR]]({{Parameter|imageArray%({{Parameter|index}})}})
: [[BLOAD]] {{Parameter|fileName$}}, [[VARPTR]]({{Parameter|imageArray%({{Parameter|index}})}})


 
=== Legacy support ===
===Legacy support===
* '''QB64''' can load larger arrays directly from binary files using [[PUT]] # and [[GET]] # without '''BLOAD'''. For that reason, '''BLOAD''' isn't recommended practice anymore and is supported to maintain compatibility with legacy code.
* '''QB64''' can load larger arrays directly from binary files using [[PUT]] # and [[GET]] # without '''BLOAD'''. For that reason, '''BLOAD''' isn't recommended practice anymore and is supported to maintain compatibility with legacy code.




{{Parameters}}
{{PageParameters}}
* {{Parameter|fileName$}} is the name of the file that the image should be [[BSAVE]]d to.
* {{Parameter|fileName$}} is the name of the file that the image should be [[BSAVE]]d to.
* {{Parameter|imageArray%(index)}} is the [[INTEGER]] [[arrays|array]] start index to store the image loaded.
* {{Parameter|imageArray%(index)}} is the [[INTEGER]] [[arrays|array]] start index to store the image loaded.
Line 19: Line 19:
* {{Parameter|index}} is the starting image element of the Array. Can also include RGB color settings at the start index.
* {{Parameter|index}} is the starting image element of the Array. Can also include RGB color settings at the start index.
* Fullscreen images in [[SCREEN]] 12 require 3 file BLOADs. A 26K array can hold 1/3 of screen.
* Fullscreen images in [[SCREEN]] 12 require 3 file BLOADs. A 26K array can hold 1/3 of screen.
* Custom RGB color settings can be embedded(indexed) at the start of the image array.  
* Custom RGB color settings can be embedded(indexed) at the start of the image array.
* BLOAD can be used to load any array that was saved with [[BSAVE]], not just graphics.
* BLOAD can be used to load any array that was saved with [[BSAVE]], not just graphics.
* Array sizes are limited to 32767 Integer elements due to use of [[VARPTR]] in QBasic and '''QB64''''s emulated conventional memory.
* Array sizes are limited to 32767 Integer elements due to use of [[VARPTR]] in QBasic and '''QB64''''s emulated conventional memory.
Line 26: Line 26:
{{PageExamples}}
{{PageExamples}}
''Example 1:'' Loading data to an array from a BSAVED file.
''Example 1:'' Loading data to an array from a BSAVED file.
{{CodeStart}} '' ''
{{CodeStart}}
  {{Cl|DEF SEG}} = {{Cl|VARSEG}}(Array(0))
  {{Cl|DEF SEG}} = {{Cl|VARSEG}}(Array(0))
   {{Cl|BLOAD}} filename$, {{Cl|VARPTR}}(Array({{Cl|LBOUND}}(Array))) ' changeable index
   {{Cl|BLOAD}} filename$, {{Cl|VARPTR}}(Array({{Cl|LBOUND}}(Array))) ' changeable index
  {{Cl|DEF SEG}} '' ''
  {{Cl|DEF SEG}}
{{CodeEnd}}
{{CodeEnd}}
:''Explanation:'' Referance any type of array that matches the data saved. Can work with Integer, Single, Double, Long, fixed length Strings or [[TYPE]] arrays. [[LBOUND]] determines the starting offset of the array or another index could be used.
:''Explanation:'' Referance any type of array that matches the data saved. Can work with Integer, Single, Double, Long, fixed length Strings or [[TYPE]] arrays. [[LBOUND]] determines the starting offset of the array or another index could be used.




''Example 2:'' Using a QB default colored image.
''Example 2:'' Using a QB default colored image.
{{CodeStart}} '' ''
{{CodeStart}}
  {{Cl|DEF SEG}} = {{Cl|VARSEG}}(Image%(0)) ' pointer to first image element of an array
  {{Cl|DEF SEG}} = {{Cl|VARSEG}}(Image%(0)) ' pointer to first image element of an array
   {{Cl|BLOAD}} FileName$, {{Cl|VARPTR}}(Image%(0)) ' place data into array at index position 0
   {{Cl|BLOAD}} FileName$, {{Cl|VARPTR}}(Image%(0)) ' place data into array at index position 0
   {{Cl|PUT (graphics statement)|PUT}}(Col, Row), Image%(0), PSET ' Put the image on the screen from index 0
   {{Cl|PUT (graphics statement)|PUT}}(Col, Row), Image%(0), PSET ' Put the image on the screen from index 0
  {{Cl|DEF SEG}} '' ''
  {{Cl|DEF SEG}}
{{CodeEnd}}
{{CodeEnd}}
: ''Note:'' [[PSET]] is used as a [[PUT (graphics statement)|PUT]] action that places the image over any background objects.
: ''Note:'' [[PSET]] is used as a [[PUT (graphics statement)|PUT]] action that places the image over any background objects.
Line 46: Line 46:
{{PageSeeAlso}}
{{PageSeeAlso}}
* [[BSAVE]], [[OPEN]], [[BINARY]]
* [[BSAVE]], [[OPEN]], [[BINARY]]
* [[PUT]], [[GET]] {{text|(file statement)}}
* [[PUT]], [[GET]] {{Text|(file statement)}}
* [[GET (graphics statement)]], [[PUT (graphics statement)]]
* [[GET (graphics statement)]], [[PUT (graphics statement)]]
* [[VARSEG]], [[VARPTR]]
* [[VARSEG]], [[VARPTR]]

Latest revision as of 22:15, 11 February 2023

BLOAD loads a binary graphics file created by BSAVE to an array.


Syntax

BLOAD fileName$, VARPTR(imageArray%(index))

Legacy support

  • QB64 can load larger arrays directly from binary files using PUT # and GET # without BLOAD. For that reason, BLOAD isn't recommended practice anymore and is supported to maintain compatibility with legacy code.


Parameters

  • fileName$ is the name of the file that the image should be BSAVEd to.
  • imageArray%(index) is the INTEGER array start index to store the image loaded.


Description

  • There must be an INTEGER array of adequate size (up to 26K) to hold the graphic data.
  • A DEF SEG pointing to the array is required. DEF SEG = VARSEG(imageArray%(index))
  • index is the starting image element of the Array. Can also include RGB color settings at the start index.
  • Fullscreen images in SCREEN 12 require 3 file BLOADs. A 26K array can hold 1/3 of screen.
  • Custom RGB color settings can be embedded(indexed) at the start of the image array.
  • BLOAD can be used to load any array that was saved with BSAVE, not just graphics.
  • Array sizes are limited to 32767 Integer elements due to use of VARPTR in QBasic and QB64's emulated conventional memory.


Examples

Example 1: Loading data to an array from a BSAVED file.

 DEF SEG = VARSEG(Array(0))
   BLOAD filename$, VARPTR(Array(LBOUND(Array))) ' changeable index
 DEF SEG
Explanation: Referance any type of array that matches the data saved. Can work with Integer, Single, Double, Long, fixed length Strings or TYPE arrays. LBOUND determines the starting offset of the array or another index could be used.


Example 2: Using a QB default colored image.

 DEF SEG = VARSEG(Image%(0)) ' pointer to first image element of an array
   BLOAD FileName$, VARPTR(Image%(0)) ' place data into array at index position 0
   PUT(Col, Row), Image%(0), PSET ' Put the image on the screen from index 0
 DEF SEG
Note: PSET is used as a PUT action that places the image over any background objects.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link