more ideomatic use of sizeof

This commit is contained in:
MrWint 2019-05-25 18:27:08 +02:00
parent 289439528d
commit a3ee854022
9 changed files with 25 additions and 25 deletions

View File

@ -22,7 +22,7 @@
<ProjectGuid>{5D630682-7BDA-474D-B387-0EB420DDC199}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>libgambatte</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

View File

@ -75,7 +75,7 @@ void GB::blitTo(gambatte::uint_least32_t *videoBuf, int pitch)
for (int i = 0; i < 144; i++)
{
std::memcpy(dst, src, sizeof(gambatte::uint_least32_t) * 160);
std::memcpy(dst, src, sizeof gambatte::uint_least32_t * 160);
src += 160;
dst += pitch;
}

View File

@ -700,7 +700,7 @@ static void setInitialCgbWram(unsigned char *const wram) {
std::memset(wram + 0x2000, 0, 0x1000);
for (std::size_t i = 0; i < sizeof(cgbWramDumpDiff) / sizeof(cgbWramDumpDiff[0]); ++i)
for (std::size_t i = 0; i < sizeof cgbWramDumpDiff / sizeof cgbWramDumpDiff[0]; ++i)
wram[cgbWramDumpDiff[i].addr] = cgbWramDumpDiff[i].val;
}
@ -972,7 +972,7 @@ static void setInitialDmgWram(unsigned char *const wram) {
std::memcpy(wram + 0x1000, wram, 0x1000);
for (std::size_t i = 0; i < sizeof(dmgWramDumpDiff) / sizeof(dmgWramDumpDiff[0]); ++i)
for (std::size_t i = 0; i < sizeof dmgWramDumpDiff / sizeof dmgWramDumpDiff[0]; ++i)
wram[dmgWramDumpDiff[i].addr] = dmgWramDumpDiff[i].val;
}
@ -1007,7 +1007,7 @@ static void setInitialVram(unsigned char *const vram, const bool cgb) {
std::memset(vram, 0, 0x4000);
for (std::size_t i = 0; i < sizeof(even_numbered_8010_to_81a0_dump) / sizeof(even_numbered_8010_to_81a0_dump[0]); ++i) {
for (std::size_t i = 0; i < sizeof even_numbered_8010_to_81a0_dump; ++i) {
vram[0x0010 + i * 2] = even_numbered_8010_to_81a0_dump[i];
}
@ -1076,8 +1076,8 @@ static void setInitialCgbIoamhram(unsigned char *const ioamhram) {
};
std::memset(ioamhram, 0x00, 0x0A0);
std::memcpy(ioamhram + 0x0A0, feaxDump, sizeof(feaxDump));
std::memcpy(ioamhram + 0x100, ffxxDump, sizeof(ffxxDump));
std::memcpy(ioamhram + 0x0A0, feaxDump, sizeof feaxDump);
std::memcpy(ioamhram + 0x100, ffxxDump, sizeof ffxxDump);
}
static void setInitialDmgIoamhram(unsigned char *const ioamhram) {
@ -1139,9 +1139,9 @@ static void setInitialDmgIoamhram(unsigned char *const ioamhram) {
0x59, 0xEA, 0x39, 0x01, 0x2E, 0x00, 0x69, 0x00
};
std::memcpy(ioamhram , oamDump, sizeof(oamDump));
std::memcpy(ioamhram , oamDump, sizeof oamDump);
std::memset(ioamhram + 0x0A0, 0x00, 0x060);
std::memcpy(ioamhram + 0x100, ffxxDump, sizeof(ffxxDump));
std::memcpy(ioamhram + 0x100, ffxxDump, sizeof ffxxDump);
}
} // anon namespace
@ -1223,7 +1223,7 @@ void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbM
state.ppu.bgpData.ptr[i + 1] = 0x7F;
}
std::memcpy(state.ppu.objpData.ptr, cgbObjpDump, sizeof(cgbObjpDump));
std::memcpy(state.ppu.objpData.ptr, cgbObjpDump, sizeof cgbObjpDump);
if (!cgb) {
state.ppu.bgpData.ptr[0] = state.mem.ioamhram.get()[0x147];
@ -1235,9 +1235,9 @@ void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbM
state.ppu.oamReaderBuf.ptr[pos] = state.mem.ioamhram.ptr[(pos * 2 & ~3) | (pos & 1)];
std::fill_n(state.ppu.oamReaderSzbuf.ptr, 40, false);
std::memset(state.ppu.spAttribList, 0, sizeof(state.ppu.spAttribList));
std::memset(state.ppu.spByte0List, 0, sizeof(state.ppu.spByte0List));
std::memset(state.ppu.spByte1List, 0, sizeof(state.ppu.spByte1List));
std::memset(state.ppu.spAttribList, 0, sizeof state.ppu.spAttribList);
std::memset(state.ppu.spByte0List, 0, sizeof state.ppu.spByte0List);
std::memset(state.ppu.spByte1List, 0, sizeof state.ppu.spByte1List);
state.ppu.videoCycles = 0;
state.ppu.enableDisplayM0Time = state.cpu.cycleCounter;
state.ppu.winYPos = 0xFF;

View File

@ -80,18 +80,18 @@ public:
// first line is default value in converted enum; last line is default value in argument x
#define EBS(x,d) do { int _ttmp = (d); if (isReader) ns->Load(&_ttmp, sizeof(_ttmp), #x); if (0)
#define EBS(x,d) do { int _ttmp = (d); if (isReader) ns->Load(&_ttmp, sizeof _ttmp, #x); if (0)
#define EVS(x,v,n) else if (!isReader && (x) == (v)) _ttmp = (n); else if (isReader && _ttmp == (n)) (x) = (v)
#define EES(x,d) else if (isReader) (x) = (d); if (!isReader) ns->Save(&_ttmp, sizeof(_ttmp), #x); } while (0)
#define EES(x,d) else if (isReader) (x) = (d); if (!isReader) ns->Save(&_ttmp, sizeof _ttmp, #x); } while (0)
#define RSS(x,b) do { if (isReader)\
{ ptrdiff_t _ttmp; ns->Load(&_ttmp, sizeof(_ttmp), #x); (x) = (_ttmp == (ptrdiff_t)0xdeadbeef ? 0 : (b) + _ttmp); }\
{ ptrdiff_t _ttmp; ns->Load(&_ttmp, sizeof _ttmp, #x); (x) = (_ttmp == (ptrdiff_t)0xdeadbeef ? 0 : (b) + _ttmp); }\
else\
{ ptrdiff_t _ttmp = (x) == 0 ? 0xdeadbeef : (x) - (b); ns->Save(&_ttmp, sizeof(_ttmp), #x); } } while (0)
{ ptrdiff_t _ttmp = (x) == 0 ? 0xdeadbeef : (x) - (b); ns->Save(&_ttmp, sizeof _ttmp, #x); } } while (0)
#define PSS(x,s) do { if (isReader) ns->Load((x), (s), #x); else ns->Save((x), (s), #x); } while (0)
#define NSS(x) do { if (isReader) ns->Load(&(x), sizeof(x), #x); else ns->Save(&(x), sizeof(x), #x); } while (0)
#define NSS(x) do { if (isReader) ns->Load(&(x), sizeof x, #x); else ns->Save(&(x), sizeof x, #x); } while (0)
#define SSS(x) do { ns->EnterSection(#x); (x).SyncState<isReader>(ns); ns->ExitSection(#x); } while (0)

View File

@ -85,7 +85,7 @@ void PSG::loadState(const SaveState &state) {
void PSG::accumulate_channels(const unsigned long cycles) {
uint_least32_t *const buf = buffer + bufferPos;
std::memset(buf, 0, cycles * sizeof(uint_least32_t));
std::memset(buf, 0, cycles * sizeof *buf);
ch1.update(buf, soVol, cycles);
ch2.update(buf, soVol, cycles);
ch3.update(buf, soVol, cycles);

View File

@ -57,7 +57,7 @@ LCD::LCD(const unsigned char *const oamram, const unsigned char *const vram, con
std::memset( bgpData, 0, sizeof bgpData);
std::memset(objpData, 0, sizeof objpData);
for (std::size_t i = 0; i < sizeof(dmgColorsRgb32) / sizeof(dmgColorsRgb32[0]); ++i)
for (std::size_t i = 0; i < sizeof dmgColorsRgb32 / sizeof dmgColorsRgb32[0]; ++i)
setDmgPaletteColor(i, (3 - (i & 3)) * 85 * 0x010101);
reset(oamram, vram, false);

View File

@ -149,7 +149,7 @@ namespace M2 {
};
static void f0(PPUPriv &p) {
std::memset(&p.spLut, 0, sizeof(p.spLut));
std::memset(&p.spLut, 0, sizeof p.spLut);
p.reg0 = 0;
p.nextSprite = 0;
p.nextCallPtr = &f1_;
@ -1638,7 +1638,7 @@ void PPU::loadState(const SaveState &ss, const unsigned char *const oamram) {
p_.nextCallPtr = m3loopState;
p_.cycles = -1;
} else if (vcycs < 143 * 456L + static_cast<long>(m3StartLineCycle(p_.cgb)) + MAX_M3START_CYCLES) {
const struct CycleState lineCycleStates[] = {
const CycleState lineCycleStates[] = {
{ &M3Start::f0_, m3StartLineCycle(p_.cgb) },
{ &M3Start::f1_, m3StartLineCycle(p_.cgb) + MAX_M3START_CYCLES },
{ &M2::LyNon0::f0_, weMasterCheckPriorToLyIncLineCycle(p_.cgb) },
@ -1647,7 +1647,7 @@ void PPU::loadState(const SaveState &ss, const unsigned char *const oamram) {
};
const std::size_t pos =
upperBound<sizeof(lineCycleStates) / sizeof(lineCycleStates[0]) - 1>(lineCycleStates, lineCycles);
upperBound<sizeof lineCycleStates / sizeof *lineCycleStates - 1>(lineCycleStates, lineCycles);
p_.cycles = lineCycles - lineCycleStates[pos].cycle;
p_.nextCallPtr = lineCycleStates[pos].state;

View File

@ -107,7 +107,7 @@ void SpriteMapper::OamReader::change(const unsigned long cc) {
void SpriteMapper::OamReader::setStatePtrs(SaveState &state) {
state.ppu.oamReaderBuf.set(buf, sizeof buf);
state.ppu.oamReaderSzbuf.set(szbuf, sizeof(szbuf) / sizeof(bool));
state.ppu.oamReaderSzbuf.set(szbuf, sizeof szbuf / sizeof *szbuf);
}
void SpriteMapper::OamReader::loadState(const SaveState &ss, const unsigned char *const oamram) {
@ -129,7 +129,7 @@ SYNCFUNC(SpriteMapper::OamReader)
}
void SpriteMapper::OamReader::enableDisplay(const unsigned long cc) {
std::memset(buf, 0x00, sizeof(buf));
std::memset(buf, 0x00, sizeof buf);
std::fill(szbuf, szbuf + 40, false);
lu = cc + (80 << lyCounter.isDoubleSpeed());
lastChange = 80;

Binary file not shown.