OXYGENHUB
◆ main openmsx / src / EmptyPatch.cc
805 B · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "EmptyPatch.hh"
2
3
#include "ranges.hh"
4
5
#include <algorithm>
6
#include <cassert>
7
8
namespace openmsx {
9
10
void EmptyPatch::copyBlock(size_t src, std::span<uint8_t> dst) const
11
{
12
	auto size = block.size();
13
	if ((src + dst.size()) > size) {
14
		// past end
15
		if (size <= src) {
16
			// start past size, only fill block
17
			std::ranges::fill(dst, 0);
18
		} else {
19
			auto part1 = size - src;
20
			auto part2 = dst.size() - part1;
21
			assert(dst.data() != &block[src]);
22
			copy_to_range(block.subspan(src, part1), dst);
23
			std::ranges::fill(dst.subspan(part1, part2), 0);
24
		}
25
	} else {
26
		if (dst.data() != &block[src]) {
27
			// copy_to_range cannot handle overlapping regions, but in
28
			// that case we don't need to copy at all
29
			copy_to_range(block.subspan(src, dst.size()), dst);
30
		}
31
	}
32
}
33
34
} // namespace openmsx