Skip to content

Commit

Permalink
Add Write To Stack Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhman-sukh committed Jan 15, 2024
1 parent 3989ee5 commit 581fb2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7920,13 +7920,22 @@ void CPU::writeToMemory()
Byte value;
printf("Address: ");
scanf("%hx", &address);
if (address >= 0x8000)
printf("Value: ");
scanf("%hhx", &value);
if (address >= 0x0000 && address <= 0x3FFF)
{
mMap->debugWriteMemory(address, value);
}
else if (address >= 0x4000 && address <= 0x7FFF)
{
mMap->writeRomBank1(address, value);
}
else if (address >= 0x8000)
{
printf("Value: ");
scanf("%hhx", &value);
mMap->writeMemory(address, value);
} else {
printf("Can't Write to Addresses less than 0x8000\n");
}

else
{
printf("Can't Write to specified addresses \n");
}
}
5 changes: 5 additions & 0 deletions src/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ void MemoryMap::debugWriteMemory(Word address, Byte value)
romBank0[address] = value;
}

void MemoryMap::writeRomBank1(Word address, Byte value)
{
romBank1[address] = value;
}

Byte MemoryMap::readMemory(Word address)
{
if (address < 0x4000)
Expand Down
4 changes: 4 additions & 0 deletions src/mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ class MemoryMap

// Writes a byte to the memory address
bool writeMemory(Word address, Byte value);

void debugWriteMemory(Word address, Byte value);

// write to RomBank1
void writeRomBank1(Word address, Byte value);

// Reads a byte from the memory address
Byte readMemory(Word address);

Expand Down

0 comments on commit 581fb2f

Please sign in to comment.