From b1a520a587b7c9d658b21f8d928b0f88aadc1060 Mon Sep 17 00:00:00 2001 From: sinamas Date: Fri, 24 Aug 2007 05:05:38 +0000 Subject: [PATCH] Remove potentially undefined memcpy. git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@12 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24 --- gambatte_qt/src/scalebuffer.h | 4 ++-- libgambatte/src/memory.cpp | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/gambatte_qt/src/scalebuffer.h b/gambatte_qt/src/scalebuffer.h index 6ce0e471..c3e0ce68 100644 --- a/gambatte_qt/src/scalebuffer.h +++ b/gambatte_qt/src/scalebuffer.h @@ -32,8 +32,8 @@ for (unsigned h = srcH; h--;) { \ ++s; \ } \ \ - std::memcpy(d, d - dstW, dstW * (scale - 1) * sizeof(T)); \ - d += dstW * (scale - 1); \ + for (unsigned n = scale; --n; d += dstW) \ + std::memcpy(d, d - dstW, dstW * sizeof(T)); \ } diff --git a/libgambatte/src/memory.cpp b/libgambatte/src/memory.cpp index d7800ab4..cb87cebb 100644 --- a/libgambatte/src/memory.cpp +++ b/libgambatte/src/memory.cpp @@ -143,18 +143,20 @@ void Memory::init() { memset(disabled_ram, 0xFF, 0x1000); memset(vram, 0, 0x4000); - memset(memory + 0xC000 + 0x00, 0xFF, 0x08); - memset(memory + 0xC000 + 0x08, 0x00, 0x08); - memcpy(memory + 0xC000 + 0x10, memory + 0xC000, 0x800 - 0x10); + for (unsigned addr = 0xC000; addr < 0xC800; addr += 0x10) { + memset(memory + addr + 0x00, 0xFF, 0x08); + memset(memory + addr + 0x08, 0x00, 0x08); + } - memset(memory + 0xC800 + 0x00, 0x00, 0x08); - memset(memory + 0xC800 + 0x08, 0xFF, 0x08); - memcpy(memory + 0xC800 + 0x10, memory + 0xC800, 0x600); - - memory[0xCE00 + 0x02] = 0xFF; - memory[0xCE00 + 0x0A] = 0x00; - memcpy(memory + 0xCE00 + 0x10, memory + 0xCE00, 0x200 - 0x10); + for (unsigned addr = 0xC800; addr < 0xD000; addr += 0x10) { + memset(memory + addr + 0x00, 0x00, 0x08); + memset(memory + addr + 0x08, 0xFF, 0x08); + } + for (unsigned addr = 0xCE00; addr < 0xD000; addr += 0x10) { + memory[addr + 0x02] = 0xFF; + memory[addr + 0x0A] = 0x00; + } memcpy(memory + 0xD000, memory + 0xC000, 0x1000); @@ -184,9 +186,10 @@ void Memory::init() { mem[0xE] = mem[0xC]; mem[0xF] = &memory[0xF000]; - cgb_bgp_data[0x00] = 0xFF; - cgb_bgp_data[0x01] = 0x7F; - memcpy(cgb_bgp_data + 0x02, cgb_bgp_data, 0x40 - 0x02); + for (unsigned i = 0x00; i < 0x40; i += 0x02) { + cgb_bgp_data[i] = 0xFF; + cgb_bgp_data[i + 1] = 0x7F; + } memcpy(cgb_objp_data, cgbObjpDump, sizeof(cgbObjpDump)); }