From c10370ed571d57032f435ddd69877318e7d5bd4b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 30 Oct 2014 23:55:51 +0100 Subject: Code readability - turn ZeroMemory into memset(a, 0, b) --- libretro.c | 2 +- source/apu.c | 4 ++-- source/cpu.c | 4 ++-- source/gfx.c | 14 +++++++------- source/memmap.c | 18 +++++++++--------- source/port.h | 2 -- source/ppu.c | 24 ++++++++++++------------ source/spc7110.c | 6 +++--- source/srtc.c | 4 ++-- 9 files changed, 38 insertions(+), 40 deletions(-) diff --git a/libretro.c b/libretro.c index 92acc8d..26bd0fa 100644 --- a/libretro.c +++ b/libretro.c @@ -286,7 +286,7 @@ const char* S9xGetFilename(const char* ex) void init_sfc_setting(void) { - ZeroMemory(&Settings, sizeof(Settings)); + memset(&Settings, 0, sizeof(Settings)); Settings.JoystickEnabled = FALSE; Settings.SoundPlaybackRate = 44100; // -> ds2sound.h for defs Settings.SoundBufferSize = 512; diff --git a/source/apu.c b/source/apu.c index 56749ce..41fcfaa 100644 --- a/source/apu.c +++ b/source/apu.c @@ -133,7 +133,7 @@ void S9xResetAPU() Settings.APUEnabled = Settings.NextAPUEnabled; - ZeroMemory(IAPU.RAM, 0x100); + memset(IAPU.RAM, 0, 0x100); memset(IAPU.RAM + 0x20, 0xFF, 0x20); memset(IAPU.RAM + 0x60, 0xFF, 0x20); memset(IAPU.RAM + 0xA0, 0xFF, 0x20); @@ -142,7 +142,7 @@ void S9xResetAPU() for (i = 1; i < 256; i++) memcpy(IAPU.RAM + (i << 8), IAPU.RAM, 0x100); - ZeroMemory(APU.OutPorts, 4); + memset(APU.OutPorts, 0, 4); IAPU.DirectPage = IAPU.RAM; // memmove converted: Different mallocs [Neb] // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb] diff --git a/source/cpu.c b/source/cpu.c index 0bc9d6c..1109a4e 100644 --- a/source/cpu.c +++ b/source/cpu.c @@ -167,7 +167,7 @@ void S9xReset(void) if (Settings.SuperFX) S9xResetSuperFX(); - ZeroMemory(Memory.FillRAM, 0x8000); + memset(Memory.FillRAM, 0, 0x8000); memset(Memory.VRAM, 0x00, 0x10000); memset(Memory.RAM, 0x55, 0x20000); @@ -196,7 +196,7 @@ void S9xSoftReset(void) if (Settings.SuperFX) S9xResetSuperFX(); - ZeroMemory(Memory.FillRAM, 0x8000); + memset(Memory.FillRAM, 0, 0x8000); memset(Memory.VRAM, 0x00, 0x10000); // memset (Memory.RAM, 0x55, 0x20000); diff --git a/source/gfx.c b/source/gfx.c index ad5ef23..bb9a132 100644 --- a/source/gfx.c +++ b/source/gfx.c @@ -423,8 +423,8 @@ bool8 S9xGraphicsInit() } } } - ZeroMemory(GFX.ZERO, 0x10000 * sizeof(uint16)); - ZeroMemory(GFX.ZERO_OR_X2, 0x10000 * sizeof(uint16)); + memset(GFX.ZERO, 0, 0x10000 * sizeof(uint16)); + memset(GFX.ZERO_OR_X2, 0, 0x10000 * sizeof(uint16)); // Build a lookup table that if the top bit of the color value is zero // then the value is zero, otherwise multiply the value by 2. Used by // the color subtraction code. @@ -3643,8 +3643,8 @@ void S9xUpdateScreen() uint32 y; for (y = starty; y <= endy; y++) { - ZeroMemory(GFX.SubZBuffer + y * GFX.ZPitch, IPPU.RenderedScreenWidth); - ZeroMemory(GFX.ZBuffer + y * GFX.ZPitch, IPPU.RenderedScreenWidth); + memset(GFX.SubZBuffer + y * GFX.ZPitch, 0, IPPU.RenderedScreenWidth); + memset(GFX.ZBuffer + y * GFX.ZPitch, 0, IPPU.RenderedScreenWidth); if (IPPU.Clip [0].Count [5]) { @@ -3685,7 +3685,7 @@ void S9xUpdateScreen() uint32 y; for (y = starty; y <= endy; y++) { - ZeroMemory(GFX.ZBuffer + y * GFX.ZPitch, IPPU.RenderedScreenWidth); + memset(GFX.ZBuffer + y * GFX.ZPitch, 0, IPPU.RenderedScreenWidth); memset(GFX.SubZBuffer + y * GFX.ZPitch, 1, IPPU.RenderedScreenWidth); if (IPPU.Clip [0].Count [5]) @@ -4018,7 +4018,7 @@ void S9xUpdateScreen() { uint32 y; for (y = starty; y <= endy; y++) - ZeroMemory(GFX.ZBuffer + y * GFX.ZPitch, IPPU.RenderedScreenWidth); + memset(GFX.ZBuffer + y * GFX.ZPitch, 0, IPPU.RenderedScreenWidth); GFX.DB = GFX.ZBuffer; RenderScreen(GFX.Screen, FALSE, TRUE, SUB_SCREEN_DEPTH); } @@ -4032,7 +4032,7 @@ void S9xUpdateScreen() { if (PPU.BGMode != 5 && PPU.BGMode != 6 && IPPU.DoubleWidthPixels) { - // Mixure of background modes used on screen - scale width + // Mixture of background modes used on screen - scale width // of all non-mode 5 and 6 pixels. register uint32 y; for (y = starty; y <= endy; y++) diff --git a/source/memmap.c b/source/memmap.c index 0dfeddf..09149f2 100644 --- a/source/memmap.c +++ b/source/memmap.c @@ -471,13 +471,13 @@ bool8 Init() SuperFX.nRomBanks = (2 * 1024 * 1024) / (32 * 1024); SuperFX.pvRom = (uint8*) Memory.ROM; - ZeroMemory(IPPU.TileCache [TILE_2BIT], MAX_2BIT_TILES * 128); - ZeroMemory(IPPU.TileCache [TILE_4BIT], MAX_4BIT_TILES * 128); - ZeroMemory(IPPU.TileCache [TILE_8BIT], MAX_8BIT_TILES * 128); + memset(IPPU.TileCache [TILE_2BIT], 0, MAX_2BIT_TILES * 128); + memset(IPPU.TileCache [TILE_4BIT], 0, MAX_4BIT_TILES * 128); + memset(IPPU.TileCache [TILE_8BIT], 0, MAX_8BIT_TILES * 128); - ZeroMemory(IPPU.TileCached [TILE_2BIT], MAX_2BIT_TILES); - ZeroMemory(IPPU.TileCached [TILE_4BIT], MAX_4BIT_TILES); - ZeroMemory(IPPU.TileCached [TILE_8BIT], MAX_8BIT_TILES); + memset(IPPU.TileCached [TILE_2BIT], 0, MAX_2BIT_TILES); + memset(IPPU.TileCached [TILE_4BIT], 0, MAX_4BIT_TILES); + memset(IPPU.TileCached [TILE_8BIT], 0, MAX_8BIT_TILES); Memory.SDD1Data = NULL; Memory.SDD1Index = NULL; @@ -672,7 +672,7 @@ again: } Memory.CalculatedSize = TotalFileSize & ~0x1FFF; // round down to lower 0x2000 - ZeroMemory(Memory.ROM + Memory.CalculatedSize, + memset(Memory.ROM + Memory.CalculatedSize, 0, MAX_ROM_SIZE - Memory.CalculatedSize); if (Memory.CalculatedSize > 0x400000 && @@ -1307,8 +1307,8 @@ void InitROM(bool8 Interleaved) } } - ZeroMemory(Memory.BlockIsRAM, MEMMAP_NUM_BLOCKS); - ZeroMemory(Memory.BlockIsROM, MEMMAP_NUM_BLOCKS); + memset(Memory.BlockIsRAM, 0, MEMMAP_NUM_BLOCKS); + memset(Memory.BlockIsROM, 0, MEMMAP_NUM_BLOCKS); Memory.SRAM = Memory.SRAM; memset(Memory.ROMId, 0, 5); diff --git a/source/port.h b/source/port.h index 2d33513..952aebf 100644 --- a/source/port.h +++ b/source/port.h @@ -212,8 +212,6 @@ typedef __int64 int64; #define _MAX_EXT PATH_MAX #define _MAX_PATH PATH_MAX -#define ZeroMemory(a,b) memset((a),0,(b)) - void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext); void _splitpath(const char* path, char* drive, char* dir, char* fname, diff --git a/source/ppu.c b/source/ppu.c index c9fe82e..a0e0f55 100644 --- a/source/ppu.c +++ b/source/ppu.c @@ -2299,7 +2299,7 @@ static void CommonPPUReset() PPU.OBJAddition = FALSE; PPU.OAMReadFlip = 0; PPU.BGnxOFSbyte = 0; - ZeroMemory(PPU.OAMData, 512 + 32); + memset(PPU.OAMData, 0, 512 + 32); PPU.VTimerEnabled = FALSE; PPU.HTimerEnabled = FALSE; @@ -2332,9 +2332,9 @@ static void CommonPPUReset() IPPU.DisplayedRenderedFrameCount = 0; IPPU.SkippedFrames = 0; IPPU.FrameSkip = 0; - ZeroMemory(IPPU.TileCached [TILE_2BIT], MAX_2BIT_TILES); - ZeroMemory(IPPU.TileCached [TILE_4BIT], MAX_4BIT_TILES); - ZeroMemory(IPPU.TileCached [TILE_8BIT], MAX_8BIT_TILES); + memset(IPPU.TileCached [TILE_2BIT], 0, MAX_2BIT_TILES); + memset(IPPU.TileCached [TILE_4BIT], 0, MAX_4BIT_TILES); + memset(IPPU.TileCached [TILE_8BIT], 0, MAX_8BIT_TILES); #ifdef CORRECT_VRAM_READS IPPU.VRAMReadBuffer = 0; // XXX: FIXME: anything better? #else @@ -2397,11 +2397,11 @@ void S9xResetPPU() } } - ZeroMemory(&Memory.FillRAM [0x2100], 0x100); - ZeroMemory(&Memory.FillRAM [0x4200], 0x100); - ZeroMemory(&Memory.FillRAM [0x4000], 0x100); + memset(&Memory.FillRAM [0x2100], 0, 0x100); + memset(&Memory.FillRAM [0x4200], 0, 0x100); + memset(&Memory.FillRAM [0x4000], 0, 0x100); // For BS Suttehakkun 2... - ZeroMemory(&Memory.FillRAM [0x1000], 0x1000); + memset(&Memory.FillRAM [0x1000], 0, 0x1000); Memory.FillRAM[0x4201] = Memory.FillRAM[0x4213] = 0xFF; } @@ -2424,11 +2424,11 @@ void S9xSoftResetPPU() for (c = 0; c < 0x8000; c += 0x100) memset(&Memory.FillRAM [c], c >> 8, 0x100); - ZeroMemory(&Memory.FillRAM [0x2100], 0x100); - ZeroMemory(&Memory.FillRAM [0x4200], 0x100); - ZeroMemory(&Memory.FillRAM [0x4000], 0x100); + memset(&Memory.FillRAM [0x2100], 0, 0x100); + memset(&Memory.FillRAM [0x4200], 0, 0x100); + memset(&Memory.FillRAM [0x4000], 0, 0x100); // For BS Suttehakkun 2... - ZeroMemory(&Memory.FillRAM [0x1000], 0x1000); + memset(&Memory.FillRAM [0x1000], 0, 0x1000); Memory.FillRAM[0x4201] = Memory.FillRAM[0x4213] = 0xFF; } diff --git a/source/spc7110.c b/source/spc7110.c index 007231f..b2181d9 100644 --- a/source/spc7110.c +++ b/source/spc7110.c @@ -1713,7 +1713,7 @@ void SPC7110Load(char* dirname) getcwd(temp_path, PATH_MAX); #endif - ZeroMemory(decompack, sizeof(Pack7110)); + memset(decompack, 0, sizeof(Pack7110)); #ifndef _XBOX if (-1 == chdir(dirname)) @@ -1774,7 +1774,7 @@ void SPC7110Open(char* dirname) getcwd(temp_path, PATH_MAX); #endif - ZeroMemory(decompack, sizeof(Pack7110)); + memset(decompack, 0, sizeof(Pack7110)); #ifndef _XBOX if (-1 == chdir(dirname)) @@ -1821,7 +1821,7 @@ void SPC7110Grab(char* dirname) int32 buffer_size = 1024 * 1024 * cacheMegs; //*some setting - ZeroMemory(decompack, sizeof(Pack7110)); + memset(decompack, 0, sizeof(Pack7110)); #ifndef _XBOX if (-1 == chdir(dirname)) diff --git a/source/srtc.c b/source/srtc.c index ba221d4..fb2165a 100644 --- a/source/srtc.c +++ b/source/srtc.c @@ -149,7 +149,7 @@ void S9xResetSRTC() void S9xHardResetSRTC() { - ZeroMemory(&rtc, sizeof(rtc)); + memset(&rtc, 0, sizeof(rtc)); rtc.index = -1; rtc.mode = MODE_READ; rtc.count_enable = FALSE; @@ -436,7 +436,7 @@ void S9xSetSRTC(uint8 data, uint16 Address) // Disable RTC counter rtc.count_enable = FALSE; - ZeroMemory(rtc.data, MAX_RTC_INDEX + 1); + memset(rtc.data, 0, MAX_RTC_INDEX + 1); rtc.index = -1; rtc.mode = MODE_COMMAND_DONE; break; -- cgit v1.2.3