Skip to content

Commit

Permalink
fix copy & paste in 16 bit mode and select all
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Aug 21, 2024
1 parent b79e012 commit fb34cf3
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 12 deletions.
4 changes: 4 additions & 0 deletions platforms/shared/desktop/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ static void sdl_shortcuts_gui(const SDL_Event* event)

switch (key)
{
case SDL_SCANCODE_A:
if (event->key.keysym.mod & KMOD_CTRL)
gui_shortcut(gui_ShortcutDebugSelectAll);
break;
case SDL_SCANCODE_C:
if (event->key.keysym.mod & KMOD_CTRL)
gui_shortcut(gui_ShortcutDebugCopy);
Expand Down
3 changes: 3 additions & 0 deletions platforms/shared/desktop/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ void gui_shortcut(gui_ShortCutEvent event)
case gui_ShortcutDebugPaste:
gui_debug_paste_memory();
break;
case gui_ShortcutDebugSelectAll:
gui_debug_select_all();
break;
case gui_ShortcutShowMainMenu:
config_emulator.show_menu = !config_emulator.show_menu;
break;
Expand Down
1 change: 1 addition & 0 deletions platforms/shared/desktop/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum gui_ShortCutEvent
gui_ShortcutDebugBreakpoint,
gui_ShortcutDebugCopy,
gui_ShortcutDebugPaste,
gui_ShortcutDebugSelectAll,
gui_ShortcutShowMainMenu
};

Expand Down
36 changes: 31 additions & 5 deletions platforms/shared/desktop/gui_debug_memeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ void MemEditor::Draw(uint8_t* mem_data, int mem_size, int base_display_addr, int
m_mem_size = mem_size;
m_mem_base_addr = base_display_addr;
m_mem_word = word;
if (m_mem_word > 2)
m_mem_word = 2;

if ((m_mem_word > 1) && ((m_preview_data_type < 2) || (m_preview_data_type > 3)))
m_preview_data_type = 2;
Expand Down Expand Up @@ -635,15 +637,15 @@ void MemEditor::Copy(uint8_t** data, int* size)
int start = m_selection_start;
int end = m_selection_end;

*size = end - start + 1;
*data = m_mem_data + start;
*size = (end - start + 1) * m_mem_word;
*data = m_mem_data + (start * m_mem_word);
}

void MemEditor::Paste(uint8_t* data, int size)
{
int selection = m_selection_end - m_selection_start + 1;
int start = m_selection_start;
int end = m_selection_start + (size < selection ? size : selection);
int selection_size = (m_selection_end - m_selection_start + 1) * m_mem_word;
int start = m_selection_start * m_mem_word;
int end = start + std::min(size, selection_size);

for (int i = start; i < end; i++)
{
Expand All @@ -654,4 +656,28 @@ void MemEditor::Paste(uint8_t* data, int size)
void MemEditor::JumpToAddress(int address)
{
m_jump_to_address = address - m_mem_base_addr;
}

void MemEditor::SelectAll()
{
m_selection_start = 0;
m_selection_end = m_mem_size - 1;
}

void MemEditor::ClearSelection()
{
m_selection_start = m_selection_end = 0;
}

void MemEditor::SetValueToSelection(int value)
{
int selection_size = (m_selection_end - m_selection_start + 1) * m_mem_word;
int start = m_selection_start * m_mem_word;
int end = start + selection_size;
int mask = m_mem_word == 1 ? 0xFF : 0xFFFF;

for (int i = start; i < end; i++)
{
m_mem_data[i] = value & mask;
}
}
3 changes: 3 additions & 0 deletions platforms/shared/desktop/gui_debug_memeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class MemEditor
void Copy(uint8_t** data, int* size);
void Paste(uint8_t* data, int size);
void JumpToAddress(int address);
void SelectAll();
void ClearSelection();
void SetValueToSelection(int value);

private:
bool IsColumnSeparator(int current_column, int column_count);
Expand Down
37 changes: 30 additions & 7 deletions platforms/shared/desktop/gui_debug_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
static MemEditor mem_edit[MEMORY_EDITOR_MAX];
static int mem_edit_select = -1;
static int current_mem_edit = 0;
static char set_value_buffer[5] = {0};

static void memory_editor_menu(void);

Expand Down Expand Up @@ -183,6 +184,11 @@ void gui_debug_paste_memory(void)
SDL_free(clipboard);
}

void gui_debug_select_all(void)
{
mem_edit[current_mem_edit].SelectAll();
}

void gui_debug_memory_goto(int editor, int address)
{
mem_edit_select = editor;
Expand Down Expand Up @@ -222,24 +228,41 @@ static void memory_editor_menu(void)
{
if (ImGui::MenuItem("Select All", "Ctrl+A"))
{
//mem_edit[current_mem_edit].SelectAll();
mem_edit[current_mem_edit].SelectAll();
}

if (ImGui::MenuItem("Clear Selection"))
{
mem_edit[current_mem_edit].ClearSelection();
}

if (ImGui::BeginMenu("Set value"))
{
char buffer[5];
buffer[0]=0;
if (ImGui::InputTextWithHint("##set_value", "XXXX", buffer, IM_ARRAYSIZE(buffer), ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase))
ImGui::SetNextItemWidth(50);
if (ImGui::InputTextWithHint("##set_value", "XXXX", set_value_buffer, IM_ARRAYSIZE(set_value_buffer), ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase))
{

try
{
mem_edit[current_mem_edit].SetValueToSelection((int)std::stoul(set_value_buffer, 0, 16));
set_value_buffer[0] = 0;
}
catch(const std::invalid_argument&)
{
}
}
ImGui::SameLine();
if (ImGui::Button("Set!", ImVec2(40, 0)))
{

try
{
mem_edit[current_mem_edit].SetValueToSelection((int)std::stoul(set_value_buffer, 0, 16));
set_value_buffer[0] = 0;
}
catch(const std::invalid_argument&)
{
}
}
ImGui::EndMenu();

}

ImGui::EndMenu();
Expand Down
1 change: 1 addition & 0 deletions platforms/shared/desktop/gui_debug_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum Memory_Editor_Tabs
EXTERN void gui_debug_window_memory(void);
EXTERN void gui_debug_copy_memory(void);
EXTERN void gui_debug_paste_memory(void);
EXTERN void gui_debug_select_all(void);
EXTERN void gui_debug_memory_goto(int editor, int address);

#undef GUI_DEBUG_MEMORY_IMPORT
Expand Down

0 comments on commit fb34cf3

Please sign in to comment.