-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Map NROM cartridge into memory, set the PC to the reset vector at the…
… beginning of the emulation
- Loading branch information
Showing
8 changed files
with
163 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include "Memory.h" | ||
|
||
#include <assert.h> | ||
#include "Cartridge.h" | ||
|
||
|
||
Memory::Memory( Cartridge *cartridge ) | ||
{ | ||
map = new byte[ 0x10000 ]; | ||
memset( map, 0, 0x10000 ); | ||
|
||
MapCartridge( cartridge ); | ||
} | ||
|
||
Memory::~Memory() | ||
{ | ||
delete map; | ||
} | ||
|
||
byte Memory::Read( word address ) const | ||
{ | ||
return map[ address ]; | ||
} | ||
|
||
void Memory::Write( word address, byte data ) | ||
{ | ||
map[ address ] = data; | ||
} | ||
|
||
void Memory::MapCartridge( Cartridge *cartridge ) | ||
{ | ||
assert( cartridge != nullptr ); | ||
|
||
/* For now only support NROM with PRG ROM of 16KB and no ram */ | ||
Cartridge::Header header = cartridge->GetHeader(); | ||
assert( header.mapper == 0x00 && header.prgRomSizeKB == 16 && !header.hasPRGRam); | ||
|
||
const byte * const rom = cartridge->GetRom(); | ||
|
||
/* Map the PRG ROM to 0x8000 */ | ||
memcpy(&map[0x8000], &rom[0x0010], 16_KB ); | ||
|
||
/* Mirror the PRG ROM in 0xC000 */ | ||
memcpy(&map[0xC000], &rom[0x0010], 16_KB ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "Types.h" | ||
|
||
|
||
/* | ||
* MEMORY MAP | ||
* | ||
* 0x0000 - 0x07FF ( 2KB internal RAM ) | ||
* 0x0800 - 0x0FFF ( Mirrors of RAM ) | ||
* 0x1000 - 0x17FF ( Mirrors of RAM ) | ||
* 0x1800 - 0x1FFF ( Mirrors of RAM ) | ||
* 0x2000 - 0x2007 ( NES PPU registers ) | ||
* 0x2008 - 0x3FFF ( Mirrors of PPU registers, repeat every 8 bytes ) | ||
* 0x4000 - 0x4017 ( NES APU & IO registers ) | ||
* 0x4018 - 0x401F ( APU and UI Functionality that is usually disabled ) | ||
* 0x4020 - 0xFFFF ( Cartridge and mapper registers ) | ||
*/ | ||
|
||
|
||
class Cartridge; | ||
|
||
class Memory | ||
{ | ||
public: | ||
|
||
Memory( Cartridge *cartridge ); | ||
~Memory(); | ||
|
||
byte Read( word address ) const; | ||
void Write( word address, byte data ); | ||
|
||
private: | ||
|
||
byte *map; | ||
|
||
void MapCartridge( Cartridge *cartridge ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters