FOR i
= 1 TO 25 'draw an original screen
ScreenSave 0, 10, 10, 20, 20, Array() 'save a portion of it
ScreenRestore 0, 10, 10, Array() 'restore it exactly where it was
ScreenRestore 0, 10, 10, Array() 'restore it to that larger screen
ScreenRestore 0, 45, 7, Array() 'And to showcase that we can move this text elsewhere...
SUB ScreenSave
(Image
, X1
, Y1
, X2
, Y2
, Array
() AS STRING) 'coordinates of the screen to copy IF X1
> X2
THEN SWAP X1
, X2
'go from left to right, not right to left IF Y1
> Y2
THEN SWAP Y1
, Y2
'and from top yo bottom, not bottom to top
E = ConvertOffset(M.ELEMENTSIZE) 'How many bytes per pixel are in memory? Screen 0 uses 2 bytes, 256 color screens use 1, 32-bit screens use 4
Length = (X2 - X1 + 1) * E 'Width of stored area * bytes per pixel
Rows = (Y2 - Y1 + 1) 'Number of rows to store
Array
(i
) = SPACE$(Length
) 'Set the array to the proper length to store each row of data
count = 0
FOR y
= Y1
- 1 TO Y2
- 1 'for text screens, we need to change the coordinates from using text locations ' (starting at 1,1), and convert them to memory locations starting at 0,0.
count = count + 1
_MEMGET M
, M.OFFSET
+ (y
* _WIDTH + X1
) * E
, Array
(count
) 'get the rows into memory starting from the proper offset count = count + 1
_MEMGET M
, M.OFFSET
+ (y
* _WIDTH + X1
) * E
, Array
(count
) 'get the rows into memory starting from the proper offset
SUB ScreenRestore
(Image
, X1
, Y1
, Array
() AS STRING) 'coordinates of the screen to copy
E = ConvertOffset(M.ELEMENTSIZE) 'How many bytes per pixel are in memory? Screen 0 uses 2 bytes, 256 color screens use 1, 32-bit screens use 4
Rows = (y2 - Y1 + 1) 'Number of rows to store
count = 0
count = count + 1
_MEMPUT M
, M.OFFSET
+ (y
* _WIDTH + X1
) * E
, Array
(count
) 'get the rows into memory starting from the proper offset count = count + 1
_MEMPUT M
, M.OFFSET
+ (y
* _WIDTH + X1
) * E
, Array
(count
) 'get the rows into memory starting from the proper offset
m
= _MEM(value
) 'Point it to use value 'On 64 bit OSes, an OFFSET is 8 bytes in size. We can put it directly into an Integer64
_MEMGET m
, m.OFFSET
, ConvertOffset&&
'Get the contents of the memblock and put the values there directly into ConvertOffset&& 'However, on 32 bit OSes, an OFFSET is only 4 bytes. We need to put it into a LONG variable first
_MEMGET m
, m.OFFSET
, temp&
'Like this ConvertOffset&& = temp& 'And then assign that long value to ConvertOffset&&