From 3989ee5b9410024471bb0328bec3927f2eda2473 Mon Sep 17 00:00:00 2001 From: sukhman-sukh Date: Mon, 15 Jan 2024 18:07:19 +0530 Subject: [PATCH] Add Write To Stack Functionality --- src/cpu.cpp | 27 +++++++++++++++++++++++---- src/cpu.h | 7 +++++-- src/gameBoy.cpp | 6 +++++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index 1d2f2ff..85a7830 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -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"); + } + } \ No newline at end of file diff --git a/src/cpu.h b/src/cpu.h index f341942..55368de 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -26,7 +26,6 @@ class CPU { private: - // Accumulator and Flags Register reg_AF; @@ -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; } @@ -1198,5 +1197,9 @@ class CPU // update the timers void updateTimers(int cycles); + // Read memory void printStack(); + + // Write to memory + void writeToMemory(); }; diff --git a/src/gameBoy.cpp b/src/gameBoy.cpp index ab3c139..b8af189 100644 --- a/src/gameBoy.cpp +++ b/src/gameBoy.cpp @@ -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)) @@ -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;