From 5ee8b6a446c8bc6db0aee4325ae0a34ea16d77f1 Mon Sep 17 00:00:00 2001 From: openshwprojects Date: Tue, 29 Nov 2022 17:52:48 +0100 Subject: [PATCH] sim: display separate modified status for flash and schematic --- src/sim/Simulator.cpp | 18 ++++++++++++++++-- src/sim/Simulator.h | 4 ++++ src/sim/Tool_Copy.cpp | 2 ++ src/sim/Tool_Delete.cpp | 1 + src/sim/Tool_Move.cpp | 2 ++ src/sim/Tool_Wire.cpp | 1 + src/sim/sim_import.h | 1 + src/win32/stubs/win_flash_stub.c | 13 +++++++++++-- 8 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/sim/Simulator.cpp b/src/sim/Simulator.cpp index 643c0781b..d156ef8d9 100644 --- a/src/sim/Simulator.cpp +++ b/src/sim/Simulator.cpp @@ -48,6 +48,19 @@ void CSimulator::setTool(Tool_Base *tb) { } void CSimulator::drawWindow() { + char buffer[256]; + const char *projectPathDisp = projectPath.c_str(); + if (*projectPathDisp == 0) + projectPathDisp = "none"; + sprintf(buffer, "OpenBeken Simulator - %s", projectPathDisp); + if (SIM_IsFlashModified()) { + strcat(buffer, " (FLASH MODIFIED)"); + } + if (bSchematicModified) { + strcat(buffer, " (SCHEMATIC MODIFIED)"); + } + SDL_SetWindowTitle(Window, buffer); + SDL_Event Event; while (SDL_PollEvent(&Event)) { @@ -199,6 +212,7 @@ bool CSimulator::loadSimulation(const char *s) { SIM_ClearOBK(); SIM_SetupFlashFileReading(memPath.c_str()); SIM_DoFreshOBKBoot(); + bSchematicModified = false; return false; } @@ -220,13 +234,13 @@ bool CSimulator::saveSimulationAs(const char *s) { saveLoad->saveProjectToFile(project, projectPath.c_str()); saveLoad->saveSimulationToFile(sim, simPath.c_str()); SIM_SaveFlashData(memPath.c_str()); - + bSchematicModified = false; return false; } void CSimulator::createWindow() { - Window = SDL_CreateWindow("OpenGL Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WinWidth, WinHeight, WindowFlags); + Window = SDL_CreateWindow("OpenBeken Simulator", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WinWidth, WinHeight, WindowFlags); assert(Window); winMenu = new CWinMenuBar(); winMenu->setSimulator(this); diff --git a/src/sim/Simulator.h b/src/sim/Simulator.h index 9a8eae4f8..bb5085a62 100644 --- a/src/sim/Simulator.h +++ b/src/sim/Simulator.h @@ -20,6 +20,7 @@ class CSimulator { class PrefabManager *prefabs; class CSaveLoad *saveLoad; class CProject *project; + bool bSchematicModified; void onKeyDown(int keyCode); void setTool(Tool_Base *tb); @@ -46,6 +47,9 @@ public: bool saveSimulationAs(const char *s); bool saveSimulation(); + void markAsModified() { + bSchematicModified = true; + } bool hasProjectPath() const { if (projectPath.size() > 0) return true; diff --git a/src/sim/Tool_Copy.cpp b/src/sim/Tool_Copy.cpp index b75deaf5b..53778f5bb 100644 --- a/src/sim/Tool_Copy.cpp +++ b/src/sim/Tool_Copy.cpp @@ -27,6 +27,7 @@ void Tool_Copy::onMouseDown(const Coord &pos, int button) { } } else { + sim->markAsModified(); copyingObject->snapToGrid(); sim->getSim()->addObject(copyingObject); copyingObject = 0; @@ -40,6 +41,7 @@ void Tool_Copy::drawTool() { if (copyingObject) { copyingObject->translate(delta); copyingObject->drawWithChildren(0); + sim->markAsModified(); } prevMousePos = nowMousePos; } diff --git a/src/sim/Tool_Delete.cpp b/src/sim/Tool_Delete.cpp index 1ce59ccdd..17a4885c4 100644 --- a/src/sim/Tool_Delete.cpp +++ b/src/sim/Tool_Delete.cpp @@ -10,6 +10,7 @@ Tool_Delete::Tool_Delete() { } void Tool_Delete::onMouseDown(const Coord &pos, int button) { if (currentTarget != 0) { + sim->markAsModified(); sim->destroyObject(currentTarget); } } diff --git a/src/sim/Tool_Move.cpp b/src/sim/Tool_Move.cpp index d10c864b8..1960d9c9a 100644 --- a/src/sim/Tool_Move.cpp +++ b/src/sim/Tool_Move.cpp @@ -43,6 +43,7 @@ void Tool_Move::onMouseDown(const Coord &pos, int button) { } if (button == SDL_BUTTON_RIGHT) { if (currentTarget) { + sim->markAsModified(); currentTarget->rotateDegreesAroundSelf(90); } } @@ -57,6 +58,7 @@ void Tool_Move::drawTool() { Coord delta = nowPos - prevPos; if (delta.isNonZero()) { prevPos = nowPos; + sim->markAsModified(); currentTarget->translate(delta); sim->getSim()->matchJunctionsOf_r(currentTarget); } diff --git a/src/sim/Tool_Wire.cpp b/src/sim/Tool_Wire.cpp index bd3427d8d..0d6c118ab 100644 --- a/src/sim/Tool_Wire.cpp +++ b/src/sim/Tool_Wire.cpp @@ -24,6 +24,7 @@ void Tool_Wire::onMouseDown(const Coord &pos, int button) { Coord curPos = roundToGrid(GetMousePos()); if (bActive) { #if 1 + sim->markAsModified(); CWire *newWireOld = sim->getSim()->addWire(a, b); newWire = sim->getSim()->addWire(b, c); if (newWire != 0) { diff --git a/src/sim/sim_import.h b/src/sim/sim_import.h index eda01ca20..6e4d16f97 100644 --- a/src/sim/sim_import.h +++ b/src/sim/sim_import.h @@ -13,4 +13,5 @@ extern "C" { void SIM_SetupEmptyFlashModeNoFile(); void SIM_DoFreshOBKBoot(); void SIM_ClearOBK(); + bool SIM_IsFlashModified(); }; diff --git a/src/win32/stubs/win_flash_stub.c b/src/win32/stubs/win_flash_stub.c index 68f08c4ea..4851c52eb 100644 --- a/src/win32/stubs/win_flash_stub.c +++ b/src/win32/stubs/win_flash_stub.c @@ -10,7 +10,11 @@ void doNothing() { char fname[512] = { 0 }; byte *g_flash = 0; bool g_flashLoaded = false; +bool g_bFlashModified = false; +bool SIM_IsFlashModified() { + return g_bFlashModified; +} void allocFlashIfNeeded() { if (g_flash != 0) { return; @@ -35,6 +39,7 @@ void SIM_SaveFlashData(const char *targetPath) { f = fopen(fname, "wb"); fwrite(g_flash, FLASH_SIZE, 1, f); fclose(f); + g_bFlashModified = false; } } void SIM_SetupFlashFileReading(const char *flashPath) { @@ -48,12 +53,14 @@ void SIM_SetupFlashFileReading(const char *flashPath) { printf("SIM_SetupFlashFileReading: failed to read whole memory\n"); } fclose(f); + g_bFlashModified = false; } } void SIM_SetupNewFlashFile(const char *flashPath) { allocFlashIfNeeded(); strcpy(fname, flashPath); SIM_SaveFlashData(fname); + g_bFlashModified = false; } @@ -75,8 +82,10 @@ int bekken_hal_flash_read(const uint32_t addr, uint8_t *dst, const uint32_t size UINT32 flash_write(char *user_buf, UINT32 count, UINT32 address) { allocFlashIfNeeded(); - - memcpy(g_flash + address, user_buf, count); + if (memcmp(g_flash + address, user_buf, count)) { + g_bFlashModified = true; + memcpy(g_flash + address, user_buf, count); + } return 0; } UINT32 flash_ctrl(UINT32 cmd, void *parm) {