From d948ef8a19c0972d82cb570ca75f323060a5d218 Mon Sep 17 00:00:00 2001 From: BearOso Date: Thu, 23 Mar 2023 19:02:23 -0500 Subject: [PATCH] Make SRAM and GFX.Screen dynamic again. --- gfx.cpp | 1 + gfx.h | 3 ++- memmap.cpp | 6 ++++-- memmap.h | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gfx.cpp b/gfx.cpp index 142c70a2..6303aed2 100644 --- a/gfx.cpp +++ b/gfx.cpp @@ -54,6 +54,7 @@ bool8 S9xGraphicsInit (void) S9xFixColourBrightness(); S9xBuildDirectColourMaps(); + GFX.ScreenBuffer.resize(MAX_SNES_WIDTH * (MAX_SNES_HEIGHT + 64)); GFX.Screen = &GFX.ScreenBuffer[GFX.RealPPL * 32]; GFX.ZERO = (uint16 *) malloc(sizeof(uint16) * 0x10000); GFX.SubScreen = (uint16 *) malloc(GFX.ScreenSize * sizeof(uint16)); diff --git a/gfx.h b/gfx.h index 91678813..80e76cf6 100644 --- a/gfx.h +++ b/gfx.h @@ -8,13 +8,14 @@ #define _GFX_H_ #include "port.h" +#include struct SGFX { const uint32 Pitch = sizeof(uint16) * MAX_SNES_WIDTH; const uint32 RealPPL = MAX_SNES_WIDTH; // true PPL of Screen buffer const uint32 ScreenSize = MAX_SNES_WIDTH * MAX_SNES_HEIGHT; - uint16 ScreenBuffer[MAX_SNES_WIDTH * (MAX_SNES_HEIGHT + 64)]; + std::vector ScreenBuffer; uint16 *Screen; uint16 *SubScreen; uint8 *ZBuffer; diff --git a/memmap.cpp b/memmap.cpp index 65018fd3..02628725 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -929,10 +929,12 @@ bool8 CMemory::Init (void) } ROMStorage.resize(MAX_ROM_SIZE + 0x200 + 0x8000); + std::fill(ROMStorage.begin(), ROMStorage.end(), 0); + SRAMStorage.resize(0x80000); + std::fill(SRAMStorage.begin(), SRAMStorage.end(), 0); + SRAM = &SRAMStorage[0]; memset(RAM, 0, sizeof(RAM)); - memset(SRAM, 0, sizeof(SRAM)); memset(VRAM, 0, sizeof(VRAM)); - memset(ROMStorage.data(), 0, ROMStorage.size()); memset(IPPU.TileCache[TILE_2BIT], 0, MAX_2BIT_TILES * 64); memset(IPPU.TileCache[TILE_4BIT], 0, MAX_4BIT_TILES * 64); diff --git a/memmap.h b/memmap.h index 279fb49c..92a82b38 100644 --- a/memmap.h +++ b/memmap.h @@ -59,7 +59,8 @@ struct CMemory uint8 RAM[0x20000]; std::vector ROMStorage; uint8 *ROM; - uint8 SRAM[0x80000]; + std::vector SRAMStorage; + uint8 *SRAM; uint8 VRAM[0x10000]; uint8 *FillRAM; uint8 *BWRAM;