/* pk-copy.pk - `copy' command.  */

/* Copyright (C) 2020, 2021, 2022, 2023, 2024 Jose E. Marchesi */

/* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* The operation of `copy' can be configured by the user by
customizing the following variables.  */

var pk_copy_from = 0#B;
var pk_copy_size = 0#B;

pk_help_add_topic
  :entry Poke_HelpEntry {
          category = "commands",
          topic = "copy",
          summary = "copy a range of memory",
          description = format ("
Copy a range of bytes from a given offset at the given IO space to
another given offset in the same or another IO space.

Synopsis:

  copy [:from OFFSET] [:to OFFSET] [:size OFFSET] \\
       [:from_ios IOS] [:to_ios IOS]

Arguments:

  :from (offset)
         Beginning of the range to copy.  Defaults to %v.

  :size (offset)
         Size of the range to copy.  The offset provided in this
         argument is truncated to bytes.  Defaults to %v.

  :to (offset)
         Offset where to copy the specified range.  Defaults to
         :from.

  :from_ios (int)
         Origin IO space.  Defaults to the current IO space.

  :to_ios (int)
         Destination IO space.  Defaults to the current IO space.

If there is not a current IO space available, or any of the specified
IO spaces don't exist, `copy' raises an E_no_ios exception.

See `.doc copy' for more information.",
                                pk_copy_from, pk_copy_size)
         };

fun copy = (int<32> from_ios = get_ios,
            int<32> to_ios = get_ios,
            offset<int<64>,b> from = pk_copy_from,
            offset<int<64>,b> to = from,
            offset<int<64>,b> size = pk_copy_size) void:
{
  ios_copy_bytes :from_ios from_ios :to_ios to_ios
                 :from from :to (to) :size size;
}
