Retro - 40 best procedures: Copying data in memory.

ZX Review #7-8-9-10
    8.4. Copying Data

            in memory


  Length: 33

  Number of variables: 3

  Checksum: 4022

  Purpose: This program copies the memory from one
place to another.

  Variables:

     Name: start

     Length: 2

     Cell: 23296

     Comment: The source address to copy.

     Name: destination

     Length: 2

     Cell: 23298

     Comment: address, which is copied.

     Name: length

     Length: 2

     Cell: 23300

     Comment: The length of the block,
to be copied.

     Calling the program:

     RANDOMIZE USR address

  Error Check: No

  Comment: this subroutine
can be used to create an "animation" using the following method:

  - Creation of the first screen of information;

  - Copy the screen above RAMTOP;

  - Repeat for the other screens;

  - Copy of screens in the opposite direction one by one in 
quick succession. 


   LISTING machine code
Assembly label number to VVODA147.


       LD HL, (23296) 42 0 91

       LD DE, (23298) 237 91 February 1991

       LD BC, (23300) 235 75 April 1991

       LD A, B 120

       OR C 177

       RET Z 200

       AND A 167

       SBC HL, DE 237 82

       RET Z 200

       ADD HL, DE 25

       JR C, COPY 56 3

       LDIR 237,176

       RET 201
COPY EX DE, HL 235

       ADD HL, BC 9

       EX DE, HL 235

       ADD HL, BC 9

       DEC HL 1943

       DEC DE 1927

       LDDR 237,184

       RET 201
2

  How it works:

  In a couple of registers HL loaded address of the first byte 
of memory for copying, DE loads the address to copy

memory, and a BC loaded the number of bytes to copy.
If BC = 0 or HL = DE, then the routine returns to BASIC. If
HL is greater than DE, part of the memory
copied, using the instructions LDIR and the program returns to 
BASIC. 

  If DE is greater than the HL, then
to both pairs of registers is added to BC-1 and the memory is 
copied using the instructions LDDR, then the program returns to 
BASIC.