User Tools

Site Tools


swapping_20the_20contents_20of_20two_20areas_20of_20memory

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

swapping_20the_20contents_20of_20two_20areas_20of_20memory [2018/03/31 13:19]
127.0.0.1 external edit
swapping_20the_20contents_20of_20two_20areas_20of_20memory [2018/04/17 19:02] (current)
tbest3112 Added syntax highlighting
Line 2: Line 2:
  
 //by Jon Ripley, August 2006//\\ \\  The Windows API provides several functions for manipulating blocks of memory but is missing a function to swap the contents of two areas of memory. \\ \\  This function can be added to your programs by adding following routine:\\ \\  //by Jon Ripley, August 2006//\\ \\  The Windows API provides several functions for manipulating blocks of memory but is missing a function to swap the contents of two areas of memory. \\ \\  This function can be added to your programs by adding following routine:\\ \\ 
 +<code bb4w>
         REM Call as: PROC_SwapMemory(addr1%,​ addr2%, size%)         REM Call as: PROC_SwapMemory(addr1%,​ addr2%, size%)
         DEF PROC_SwapMemory(B%,​ D%, C%)         DEF PROC_SwapMemory(B%,​ D%, C%)
Line 21: Line 22:
         CALL memswap         CALL memswap
         ENDPROC         ENDPROC
 +</​code>​
 \\  To call this routine use the following code:\\ \\  \\  To call this routine use the following code:\\ \\ 
 +<code bb4w>
         PROC_SwapMemory(addr1%,​ addr2%, size%)         PROC_SwapMemory(addr1%,​ addr2%, size%)
 +</​code>​
 Here **addr1%** and **addr2%** are the addresses of the two blocks of memory to be swapped and **size%** is the number of bytes to swap.\\ \\  Here **addr1%** and **addr2%** are the addresses of the two blocks of memory to be swapped and **size%** is the number of bytes to swap.\\ \\ 
 ==== SYS SwapMemory ==== ==== SYS SwapMemory ====
 \\ //This section is provided for advanced users and demonstrates techniques that may be of interest.//​\\ \\  To provide a similar interface to other Windows API functions memory management functions it may be desirable to rewrite the SwapMemory function to be called using SYS. To do this add this alternative code to your program:\\ \\  \\ //This section is provided for advanced users and demonstrates techniques that may be of interest.//​\\ \\  To provide a similar interface to other Windows API functions memory management functions it may be desirable to rewrite the SwapMemory function to be called using SYS. To do this add this alternative code to your program:\\ \\ 
 +<code bb4w>
         DIM SwapMemory 27         DIM SwapMemory 27
         P% = SwapMemory         P% = SwapMemory
Line 51: Line 56:
         ret 12             ; return from the function, clearing the stack         ret 12             ; return from the function, clearing the stack
         ]         ]
 +</​code>​
 \\  To call this routine from BASIC use the following code:\\ \\  \\  To call this routine from BASIC use the following code:\\ \\ 
 +<code bb4w>
         SYS SwapMemory, addr1%, addr2%, size%         SYS SwapMemory, addr1%, addr2%, size%
 +</​code>​
 \\  Here **addr1%** and **addr2%** are the addresses of the two blocks of memory to be swapped and **size%** is the number of bytes to swap.\\ \\  To call this routine from assembler use the following code:\\ \\  \\  Here **addr1%** and **addr2%** are the addresses of the two blocks of memory to be swapped and **size%** is the number of bytes to swap.\\ \\  To call this routine from assembler use the following code:\\ \\ 
 +<code bb4w>
         push size%         push size%
         push addr2%         push addr2%
         push addr1%         push addr1%
         call SwapMemory         call SwapMemory
 +</​code>​
 \\  \\ 
 ===== References ===== ===== References =====
 \\  Core code suggested by Richard Russell on the BB4W Yahoo! Group. ([[http://​groups.yahoo.com/​group/​bb4w/​message/​2608|Message]]) \\  Core code suggested by Richard Russell on the BB4W Yahoo! Group. ([[http://​groups.yahoo.com/​group/​bb4w/​message/​2608|Message]])
swapping_20the_20contents_20of_20two_20areas_20of_20memory.txt ยท Last modified: 2018/04/17 19:02 by tbest3112