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 9e57d94 commit 3989ee5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
27 changes: 23 additions & 4 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7899,15 +7899,34 @@ void CPU::printStack()
scanf("%c", &choice);
} while (choice != 'q' && choice != 'x');


if (choice == 'x')
{
{
printf("Exiting Stack\n");
break;
} else{
count = 0;
}
else
{
count = 0;
continue;
}
}
}
}

// Write to memory specified in debugger
void CPU::writeToMemory()
{
Word address;
Byte value;
printf("Address: ");
scanf("%hx", &address);
if (address >= 0x8000)
{
printf("Value: ");
scanf("%hhx", &value);
mMap->writeMemory(address, value);
} else {
printf("Can't Write to Addresses less than 0x8000\n");
}

}
7 changes: 5 additions & 2 deletions src/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class CPU
{

private:

// Accumulator and Flags
Register reg_AF;

Expand Down Expand Up @@ -1163,7 +1162,7 @@ class CPU
// Register reg_DE;

// get value of A
Byte get_reg_A(){ return reg_AF.hi; }
Byte get_reg_A() { return reg_AF.hi; }

// get register B
Byte get_reg_B() { return reg_BC.hi; }
Expand Down Expand Up @@ -1198,5 +1197,9 @@ class CPU
// update the timers
void updateTimers(int cycles);

// Read memory
void printStack();

// Write to memory
void writeToMemory();
};
6 changes: 5 additions & 1 deletion src/gameBoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ void GBE::debug_int()
// enter l for L
// press left ctrl to open V-Ram debugger window
// enter p to print the stack
// enter e to exit info mode
// enter w to write to memory
// enter x to exit info mode
while (infoMode)
{
while (SDL_PollEvent(event))
Expand Down Expand Up @@ -281,6 +282,9 @@ void GBE::debug_int()
case SDLK_p:
gbe_cpu->printStack();
break;
case SDLK_w:
gbe_cpu->writeToMemory();
break;
case SDLK_x:
infoMode = false;
break;
Expand Down

0 comments on commit 3989ee5

Please sign in to comment.