MEMGET: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "{{DISPLAYTITLE:_MEMGET}} The _MEMGET statement reads a portion of a memory block at an OFFSET position into a variable, array or user defined type. {{PageSyntax}} : _MEMGET {{Parameter|memoryBlock}}, {{Parameter|bytePosition}}, {{Parameter|destinationVariable}} * {{Parameter|memoryBlock}} is a _MEM variable type memory block name created by _MEMNEW or the _MEM function. * {{Parameter|bytePosition}} is the {{Parameter|memoryBlock}}....") |
No edit summary |
||
Line 8: | Line 8: | ||
* {{Parameter|memoryBlock}} is a [[_MEM]] variable type memory block name created by [[_MEMNEW]] or the [[_MEM (function)|_MEM]] function. | * {{Parameter|memoryBlock}} is a [[_MEM]] variable type memory block name created by [[_MEMNEW]] or the [[_MEM (function)|_MEM]] function. | ||
* {{Parameter|bytePosition}} is the {{Parameter|memoryBlock}}.[[OFFSET]] memory start position plus any bytes to move into the block. | * {{Parameter|bytePosition}} is the {{Parameter|memoryBlock}}.[[OFFSET]] memory start position plus any bytes to move into the block. | ||
* {{Parameter|destinationVariable}} is the variable assigned to hold the data. The number of bytes read is determined by the variable [[type]] used. | * {{Parameter|destinationVariable}} is the variable assigned to hold the data. The number of bytes read is determined by the variable [[type]] used. | ||
Line 15: | Line 15: | ||
* The [[_MEMGET]] statement is similar to the [[GET]] statement used in files, but the position is required. | * The [[_MEMGET]] statement is similar to the [[GET]] statement used in files, but the position is required. | ||
* The memory block name.[[OFFSET]] returns the starting byte position of the block. Add bytes to move into the block. | * The memory block name.[[OFFSET]] returns the starting byte position of the block. Add bytes to move into the block. | ||
* The variable type held in the memory block can determine the next {{Parameter|bytePosition}} to read. | * The variable type held in the memory block can determine the next {{Parameter|bytePosition}} to read. | ||
* [[LEN]] can be used to determine the byte size of numerical or user defined variable [[type]]s regardless of the value held. | * [[LEN]] can be used to determine the byte size of numerical or user defined variable [[type]]s regardless of the value held. | ||
* [[STRING]] values should be of a defined length. Variable length strings can actually move around in memory and not be found. | * [[STRING]] values should be of a defined length. Variable length strings can actually move around in memory and not be found. | ||
Line 22: | Line 22: | ||
{{PageExamples]] | {{PageExamples]] | ||
''Example:'' Shows how to read the PSET color values from a program's [[SCREEN]] memory to an array. | ''Example:'' Shows how to read the PSET color values from a program's [[SCREEN]] memory to an array. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} 13 | {{Cl|SCREEN}} 13 | ||
{{Cl|PSET}} (0, 0), 123 | {{Cl|PSET}} (0, 0), 123 | ||
Line 37: | Line 37: | ||
'here's the proof | 'here's the proof | ||
{{Cl|PRINT}} screen_array(0, 0) 'print 123 | {{Cl|PRINT}} screen_array(0, 0) 'print 123 | ||
{{Cl|PRINT}} screen_array(1, 0) 'print 222 | {{Cl|PRINT}} screen_array(1, 0) 'print 222 | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
Revision as of 02:04, 23 January 2023
The _MEMGET statement reads a portion of a memory block at an OFFSET position into a variable, array or user defined type.
Syntax
- _MEMGET memoryBlock, bytePosition, destinationVariable
- memoryBlock is a _MEM variable type memory block name created by _MEMNEW or the _MEM function.
- bytePosition is the memoryBlock.OFFSET memory start position plus any bytes to move into the block.
- destinationVariable is the variable assigned to hold the data. The number of bytes read is determined by the variable type used.
Description
- The _MEMGET statement is similar to the GET statement used in files, but the position is required.
- The memory block name.OFFSET returns the starting byte position of the block. Add bytes to move into the block.
- The variable type held in the memory block can determine the next bytePosition to read.
- LEN can be used to determine the byte size of numerical or user defined variable types regardless of the value held.
- STRING values should be of a defined length. Variable length strings can actually move around in memory and not be found.
{{PageExamples]]
Example: Shows how to read the PSET color values from a program's SCREEN memory to an array.
SCREEN 13 PSET (0, 0), 123 PSET (1, 0), 222 'create screen image 'here is an array DIM screen_array(319, 199) AS _UNSIGNED _BYTE 'use screen dimensions from 0 'here's how we can copy the screen to our array DIM m AS _MEM m = _MEMIMAGE '0 or no handle necessary when accessing the current program screen _MEMGET m, m.OFFSET, screen_array() 'here's the proof PRINT screen_array(0, 0) 'print 123 PRINT screen_array(1, 0) 'print 222 END |
See also