apparently when you set an out-of-bounds address for EEPROM, it should wrap around

TODO: check if it also happens with Flash

also fix shit that could have later turned into memory leaks
This commit is contained in:
StapleButter 2017-02-05 17:45:17 +01:00
parent ff3b60bc93
commit e88cf1b43d
3 changed files with 11 additions and 12 deletions

View File

@ -289,7 +289,7 @@ void Reset()
// test // test
//LoadROM(); //LoadROM();
//LoadFirmware(); //LoadFirmware();
NDSCart::LoadROM("rom/peach.nds"); NDSCart::LoadROM("rom/sonic.nds");
Running = true; // hax Running = true; // hax
} }

View File

@ -56,6 +56,7 @@ void Write_Discover(u8 val, bool islast);
void Init() void Init()
{ {
SRAM = NULL; SRAM = NULL;
Discover_Buffer = NULL;
} }
void Reset() void Reset()
@ -66,6 +67,7 @@ void Reset()
void LoadSave(char* path) void LoadSave(char* path)
{ {
if (SRAM) delete[] SRAM; if (SRAM) delete[] SRAM;
if (Discover_Buffer) delete[] Discover_Buffer;
strncpy(SRAMPath, path, 255); strncpy(SRAMPath, path, 255);
SRAMPath[255] = '\0'; SRAMPath[255] = '\0';
@ -181,6 +183,8 @@ void SetMemoryType()
} }
CurCmd = prev_cmd; CurCmd = prev_cmd;
delete[] Discover_Buffer;
} }
void Write_Discover(u8 val, bool islast) void Write_Discover(u8 val, bool islast)
@ -272,9 +276,7 @@ void Write_EEPROM(u8 val, bool islast)
} }
else else
{ {
if (Addr < SRAMLength) SRAM[Addr & (SRAMLength-1)] = val;
SRAM[Addr] = val;
Addr++; Addr++;
} }
break; break;
@ -288,11 +290,7 @@ void Write_EEPROM(u8 val, bool islast)
} }
else else
{ {
if (Addr >= SRAMLength) Data = SRAM[Addr & (SRAMLength-1)];
Data = 0;
else
Data = SRAM[Addr];
Addr++; Addr++;
} }
break; break;
@ -321,6 +319,7 @@ void Write_Flash(u8 val, bool islast)
} }
else else
{ {
// CHECKME: does Flash also wraparound when the address is out of bounds?
if (Addr >= SRAMLength) if (Addr >= SRAMLength)
Data = 0; Data = 0;
else else

View File

@ -10,7 +10,7 @@
1481161027 c:\documents\sources\melonds\types.h 1481161027 c:\documents\sources\melonds\types.h
1486310027 source:c:\documents\sources\melonds\nds.cpp 1486312246 source:c:\documents\sources\melonds\nds.cpp
<stdio.h> <stdio.h>
<string.h> <string.h>
"NDS.h" "NDS.h"
@ -24,7 +24,7 @@
"RTC.h" "RTC.h"
"Wifi.h" "Wifi.h"
1486310306 source:c:\documents\sources\melonds\arm.cpp 1486310992 source:c:\documents\sources\melonds\arm.cpp
<stdio.h> <stdio.h>
"NDS.h" "NDS.h"
"ARM.h" "ARM.h"
@ -137,7 +137,7 @@
1485980863 c:\documents\sources\melonds\ndscart.h 1485980863 c:\documents\sources\melonds\ndscart.h
"types.h" "types.h"
1486309588 source:c:\documents\sources\melonds\ndscart.cpp 1486312231 source:c:\documents\sources\melonds\ndscart.cpp
<stdio.h> <stdio.h>
<string.h> <string.h>
"NDS.h" "NDS.h"