1. extended mem_copy()
- Posted by Michael Bolin <michaeltom at GEOCITIES.COM> Jul 10, 1997
- 627 views
- Last edited Jul 11, 1997
Hi all, I have just finished a routine that may be useful to people developing graphic engines, etc. It is an extended form of mem_copy(). Here are the specifications for use: After including the .E file, but before using the routine, you must call the function set_up_emc(). It will return 1 if successful, 0 if it fails. The basic routine is called like this: se_mem_copy( kind , source_address, dest_address, width, height, source_add, dest_add ) KIND is the type of copy to perform. A 1 is an ordinary memory move, the same as mem_copy(). A 2 will copy all bytes from the source EXCEPT those that equal 0. The last type, 3, will write bytes to the destination ONLY if the byte already there is a 0. Type 1 is the fastest, and should be used whenever possible. SOURCE_ADDRESS is the address of the first byte to copy. DEST_ADDRESS is the address of the first byte to begin writing to. WIDTH is the number of bytes to copy in one "run". After one run of bytes is copied, the value of SOURCE_ADD is added to the source address, and the value of DEST_ADD is added to the destination address. HEIGHT is the total number of "runs" to copy. Using this routine, entire blocks of memory can be copied with one single procedure call. As an example, the following command (in graphics mode 19) will copy the upperleft quarter of the screen to the bottom right, with only one command: se_mem_copy (1, #A0000, #A0000+32160, 160, 100, 320-160, 320-160) Try changing the first parameter to 2 or 3, to see the different effects you can perform. There is one other way this routine can be used. It has the capability of copying an entire group of blocks at once. You can allocate a memory area and poke in the arguments above in order. (Note: the first parameter must occupy only one byte, while the other five require four bytes each, and must be poked using the function int_to_bytes().) If you place another group of parameters immediately following the first, you can complete two copy operations at once, or three, etc. You can make as long a list in memory as you like, but the list must be terminated by a 0-byte. Place it where the copy type would be, if you were adding another operation instead of the end of the list. When you have made a list like this, call the procedure: set_emc_address( ADDRESS ) Give the address of the first byte of your list of parameters. To complete the operation, call e_mem_copy(). Note that it is NOT preceded by the letter 's', as the single operation above is. You must set the address before using the multi-move for the first time, and then whenever you want to use a different address. ---------------------------- Regards, Michael Bolin ----------------------------------------- Begin Ememcopy.e include machine.e sequence code atom copy_address,single_ad global function set_up_emc() copy_address=allocate(length(code)) single_ad=allocate(26) if copy_address and single_ad then poke(copy_address,code) poke(single_ad,repeat(0,26)) return 1 else return 0 end if end function global procedure set_emc_address(atom address) poke(copy_address+2,{address,address/256,address/65536,address/16777216}) end procedure global procedure e_mem_copy() call(copy_address) end procedure global procedure se_mem_copy(integer kind,atom src,atom dest,atom width, atom height,atom src_add,atom dest_add) sequence old old=peek({copy_address+2,4}) set_emc_address(single_ad) poke(single_ad,kind) poke(single_ad+1,{src,src/256,src/65536,src/16777216}) poke(single_ad+5,{dest,dest/256,dest/65536,dest/16777216}) poke(single_ad+9,{width,width/256,width/65536,width/16777216}) poke(single_ad+13,{height,height/256,height/65536,height/16777216}) poke(single_ad+17,{src_add,src_add/256,src_add/65536,src_add/16777216}) poke(single_ad+21,{dest_add,dest_add/256,dest_add/65536,dest_add/16777216}) call(copy_address) end procedure code={ #60,#B8,#00,#00,#00,#00,#8A,#18,#80,#FB,#00,#74,#45,#50,#8B,#50,#05, #8B,#48,#09,#89,#0D,#2A,#02,#00,#00,#8B,#48,#0D,#89,#0D,#2E,#02,#00, #00,#8B,#48,#11,#89,#0D,#32,#02,#00,#00,#8B,#48,#15,#89,#0D,#36,#02, #00,#00,#8B,#40,#01,#80,#FB,#01,#74,#17,#80,#FB,#02,#74,#22,#E8,#47, #01,#00,#00,#58,#05,#19,#00,#00,#00,#E9,#B4,#FF,#FF,#FF,#61,#C3,#E8, #1B,#00,#00,#00,#58,#05,#19,#00,#00,#00,#E9,#A2,#FF,#FF,#FF,#E8,#CE, #00,#00,#00,#58,#05,#19,#00,#00,#00,#E9,#92,#FF,#FF,#FF,#8B,#2D,#2E, #02,#00,#00,#39,#D0,#7C,#4C,#8B,#0D,#2A,#02,#00,#00,#81,#F9,#04,#00, #00,#00,#7C,#23,#81,#E9,#04,#00,#00,#00,#8B,#18,#05,#04,#00,#00,#00, #89,#1A,#81,#C2,#04,#00,#00,#00,#81,#E9,#04,#00,#00,#00,#79,#E9,#81, #C1,#04,#00,#00,#00,#74,#09,#8A,#18,#40,#88,#1A,#42,#49,#75,#F7,#03, #05,#32,#02,#00,#00,#03,#15,#36,#02,#00,#00,#4D,#75,#B5,#C3,#E8,#16, #01,#00,#00,#2D,#03,#00,#00,#00,#81,#EA,#03,#00,#00,#00,#8B,#0D,#2A, #02,#00,#00,#81,#F9,#04,#00,#00,#00,#7C,#23,#81,#E9,#04,#00,#00,#00, #8B,#18,#2D,#04,#00,#00,#00,#89,#1A,#81,#EA,#04,#00,#00,#00,#81,#E9, #04,#00,#00,#00,#79,#E9,#81,#C1,#04,#00,#00,#00,#05,#03,#00,#00,#00, #81,#C2,#03,#00,#00,#00,#81,#F9,#00,#00,#00,#00,#74,#09,#8A,#18,#48, #88,#1A,#4A,#49,#75,#F7,#2B,#05,#32,#02,#00,#00,#2B,#15,#36,#02,#00, #00,#4D,#75,#99,#C3,#8B,#2D,#2E,#02,#00,#00,#39,#D0,#7C,#24,#8B,#0D, #2A,#02,#00,#00,#8A,#18,#40,#80,#FB,#00,#74,#02,#88,#1A,#42,#49,#75, #F2,#03,#05,#32,#02,#00,#00,#03,#15,#36,#02,#00,#00,#4D,#75,#DD,#C3, #E8,#7B,#00,#00,#00,#8B,#0D,#2A,#02,#00,#00,#8A,#18,#48,#80,#FB,#00, #74,#02,#88,#1A,#4A,#49,#75,#F2,#2B,#05,#32,#02,#00,#00,#2B,#15,#36, #02,#00,#00,#4D,#75,#DD,#C3,#8B,#2D,#2E,#02,#00,#00,#39,#D0,#7C,#24, #8B,#0D,#2A,#02,#00,#00,#80,#3A,#00,#75,#04,#8A,#18,#88,#1A,#42,#40, #49,#75,#F2,#03,#05,#32,#02,#00,#00,#03,#15,#36,#02,#00,#00,#4D,#75, #DD,#C3,#E8,#24,#00,#00,#00,#8B,#0D,#2A,#02,#00,#00,#80,#3A,#00,#75, #04,#8A,#18,#88,#1A,#4A,#48,#49,#75,#F2,#2B,#05,#32,#02,#00,#00,#2B, #15,#36,#02,#00,#00,#4D,#75,#DD,#C3,#89,#C6,#A1,#2A,#02,#00,#00,#03, #05,#32,#02,#00,#00,#8B,#3D,#2E,#02,#00,#00,#4F,#52,#F7,#E7,#5A,#03, #05,#2A,#02,#00,#00,#48,#01,#F0,#50,#A1,#2A,#02,#00,#00,#03,#05,#36, #02,#00,#00,#8B,#3D,#2E,#02,#00,#00,#4F,#52,#F7,#E7,#5A,#03,#05,#2A, #02,#00,#00,#48,#01,#D0,#89,#C2,#58,#C3,#00,#00,#00,#00,#00,#00,#00, #00,#00,#00,#00,#00,#00,#00,#00,#00 } ------------------------------------------------------------------
2. Re: extended mem_copy()
- Posted by Lee woo seob <wslee at HHI.CO.KR> Jul 14, 1997
- 682 views
Michael Bolin wrote: >Here's some code that you can either put in a separate include file >or add to the end of ememcopy.e. It doesn't handle lists of images, >instead only a single one, like se_mem_copy(). Thanks again! I haven't tested your routines yet, but I will do it soon. Only if your routine has enough speed, I can forget all the complicate matters about sprite manipulation, at least in 320*200*256 mode. Just before i saw your routine, i had completed my own sprite routine (i already sent a poor demo to Robert). However, i think it's better to rewrite using your routines... Regards, from your fan, Lee woo seob...