From aa986eaa87a3e5e697cfaf067073582eb1063d1d Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Mon, 3 Mar 2025 23:22:25 +0100 Subject: [PATCH] feat: expose Z3 mapping mode option in GUI->RAM --- src/osdep/amiberry_mem.cpp | 34 +++++++----------- src/osdep/gui/PanelRAM.cpp | 72 ++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 36 deletions(-) diff --git a/src/osdep/amiberry_mem.cpp b/src/osdep/amiberry_mem.cpp index 53775ddc0..6384e8bea 100644 --- a/src/osdep/amiberry_mem.cpp +++ b/src/osdep/amiberry_mem.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -164,8 +165,6 @@ static int my_getpagesize() #define getpagesize my_getpagesize - -static uae_u32 natmem_size; uae_u32 max_z3fastmem; uae_u32 max_physmem; @@ -258,8 +257,7 @@ bool preinit_shm () // Higher than 2G to support G-REX PCI VRAM max_allowed_mman = 2560; } - if (maxmem > max_allowed_mman) - max_allowed_mman = maxmem; + max_allowed_mman = std::max(maxmem, max_allowed_mman); #ifdef _WIN32 memstats.dwLength = sizeof(memstats); @@ -309,31 +307,26 @@ bool preinit_shm () if (!os_64bit) { if (totalphys64 < 1536 * 1024 * 1024) max_allowed_mman = 256; - if (max_allowed_mman < 256) - max_allowed_mman = 256; + max_allowed_mman = std::max(max_allowed_mman, 256); } } else if (maxmem > 0) { size64 = static_cast(maxmem) * 1024 * 1024; } - if (size64 < 8 * 1024 * 1024) - size64 = 8 * 1024 * 1024; + size64 = std::max(size64, 8 * 1024 * 1024); if (static_cast(max_allowed_mman) * 1024 * 1024 > size64) max_allowed_mman = static_cast(size64 / (1024 * 1024)); uae_u32 natmem_size = (max_allowed_mman + 1) * 1024 * 1024; - if (natmem_size < 17 * 1024 * 1024) - natmem_size = 17 * 1024 * 1024; + natmem_size = std::max(natmem_size, 17 * 1024 * 1024); #if WIN32_NATMEM_TEST natmem_size = WIN32_NATMEM_TEST * 1024 * 1024; #endif - if (natmem_size > 0xc0000000) { - natmem_size = 0xc0000000; - } + natmem_size = std::min(natmem_size, 0xc0000000); write_log (_T("MMAN: Total physical RAM %llu MB, all RAM %llu MB\n"), - totalphys64 >> 20, total64 >> 20); + totalphys64 >> 20, total64 >> 20); write_log(_T("MMAN: Attempting to reserve: %u MB\n"), natmem_size >> 20); #if 1 @@ -386,7 +379,7 @@ bool preinit_shm () } max_physmem = natmem_size; write_log (_T("MMAN: Reserved %p-%p (0x%08x %dM)\n"), - natmem_reserved, (uae_u8 *) natmem_reserved + natmem_reserved_size, + natmem_reserved, natmem_reserved + natmem_reserved_size, natmem_reserved_size, natmem_reserved_size / (1024 * 1024)); clear_shm (); @@ -473,16 +466,14 @@ static int doinit_shm () // Real highram > 0x80000000 && UAE highram <= 0x80000000 && Automatic (expamem_z3_highram_real > 0x80000000 && expamem_z3_highram_uae <= 0x80000000 && p->z3_mapping_mode == Z3MAPPING_AUTO) || // Wanted UAE || Blizzard RAM - p->z3_mapping_mode == Z3MAPPING_UAE || //cpuboard_memorytype(&changed_prefs) == BOARD_MEMORY_BLIZZARD_12xx || + p->z3_mapping_mode == Z3MAPPING_UAE || cpuboard_memorytype(&changed_prefs) == BOARD_MEMORY_BLIZZARD_12xx || // JIT && Automatic && Real does not fit in NATMEM && UAE fits in NATMEM (expamem_z3_highram_real + extra >= natmem_reserved_size && expamem_z3_highram_uae + extra <= natmem_reserved_size && p->z3_mapping_mode == Z3MAPPING_AUTO && jit_direct_compatible_memory)) { changed_prefs.z3autoconfig_start = currprefs.z3autoconfig_start = Z3BASE_UAE; if (p->z3_mapping_mode == Z3MAPPING_AUTO) write_log(_T("MMAN: Selected UAE Z3 mapping mode\n")); set_expamem_z3_hack_mode(Z3MAPPING_UAE); - if (expamem_z3_highram_uae > totalsize_z3) { - totalsize_z3 = expamem_z3_highram_uae; - } + totalsize_z3 = std::max(expamem_z3_highram_uae, totalsize_z3); } else { if (p->z3_mapping_mode == Z3MAPPING_AUTO) write_log(_T("MMAN: Selected REAL Z3 mapping mode\n")); @@ -498,8 +489,7 @@ static int doinit_shm () } write_log(_T("Total %uM Z3 Total %uM, HM %uM\n"), totalsize >> 20, totalsize_z3 >> 20, expamem_highmem_pointer >> 20); - if (totalsize_z3 < expamem_highmem_pointer) - totalsize_z3 = expamem_highmem_pointer; + totalsize_z3 = std::max(totalsize_z3, expamem_highmem_pointer); expansion_scan_autoconfig(&currprefs, true); @@ -581,7 +571,7 @@ static int doinit_shm () write_log (_T("MMAN: No special area could be allocated! err=%d\n"), GetLastError ()); } else { write_log(_T("MMAN: Our special area: %p-%p (0x%08x %dM)\n"), - natmem_offset, (uae_u8*)natmem_offset + totalsize, + natmem_offset, natmem_offset + totalsize, totalsize, totalsize / (1024 * 1024)); canbang = jit_direct_compatible_memory; } diff --git a/src/osdep/gui/PanelRAM.cpp b/src/osdep/gui/PanelRAM.cpp index bb22e6ed4..c4963f102 100644 --- a/src/osdep/gui/PanelRAM.cpp +++ b/src/osdep/gui/PanelRAM.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "SelectorEntry.hpp" @@ -5,6 +6,7 @@ #include "options.h" #include "memory.h" #include "gui_handling.h" +#include "StringListModel.h" #include "target.h" static gcn::Window* grpRAM; @@ -30,68 +32,84 @@ static gcn::Label* lblMbResHighmem; static gcn::Label* lblMbResHighsize; static gcn::Slider* sldMbResHighmem; +static gcn::Window* grpAdvancedRAM; +static gcn::Label* lblZ3Mapping; +static gcn::DropDown* cboZ3Mapping; + +static gcn::StringListModel z3_mapping_mode; + class MemorySliderActionListener : public gcn::ActionListener { public: void action(const gcn::ActionEvent& actionEvent) override { - if (actionEvent.getSource() == sldChipmem) + auto source = actionEvent.getSource(); + + if (source == sldChipmem) { changed_prefs.chipmem.size = memsizes[msi_chip[static_cast(sldChipmem->getValue())]]; if (changed_prefs.chipmem.size > 0x200000 && changed_prefs.fastmem[0].size > 0) changed_prefs.fastmem[0].size = 0; } - else if (actionEvent.getSource() == sldSlowmem) + else if (source == sldSlowmem) { changed_prefs.bogomem.size = memsizes[msi_bogo[static_cast(sldSlowmem->getValue())]]; } - else if (actionEvent.getSource() == sldFastmem) + else if (source == sldFastmem) { changed_prefs.fastmem[0].size = memsizes[msi_fast[static_cast(sldFastmem->getValue())]]; if (changed_prefs.fastmem[0].size > 0 && changed_prefs.chipmem.size > 0x200000) changed_prefs.chipmem.size = 0x200000; } - else if (actionEvent.getSource() == sldZ3mem) + else if (source == sldZ3mem) { changed_prefs.z3fastmem[0].size = memsizes[msi_z3fast[static_cast(sldZ3mem->getValue())]]; - if (changed_prefs.z3fastmem[0].size > max_z3fastmem) - changed_prefs.z3fastmem[0].size = max_z3fastmem; + changed_prefs.z3fastmem[0].size = std::min(changed_prefs.z3fastmem[0].size, max_z3fastmem); } - else if (actionEvent.getSource() == sldZ3chip) + else if (source == sldZ3chip) { changed_prefs.z3chipmem.size = memsizes[msi_z3chip[static_cast(sldZ3chip->getValue())]]; - if (changed_prefs.z3chipmem.size > max_z3fastmem) - changed_prefs.z3chipmem.size = max_z3fastmem; + changed_prefs.z3chipmem.size = std::min(changed_prefs.z3chipmem.size, max_z3fastmem); } - else if (actionEvent.getSource() == sldMbResLowmem) + else if (source == sldMbResLowmem) { changed_prefs.mbresmem_low.size = memsizes[msi_mb[static_cast(sldMbResLowmem->getValue())]]; if (currprefs.mbresmem_low.size != changed_prefs.mbresmem_low.size) disable_resume(); } - else if (actionEvent.getSource() == sldMbResHighmem) + else if (source == sldMbResHighmem) { changed_prefs.mbresmem_high.size = memsizes[msi_mb[static_cast(sldMbResHighmem->getValue())]]; if (currprefs.mbresmem_high.size != changed_prefs.mbresmem_high.size) disable_resume(); } + else if (source == cboZ3Mapping) + { + changed_prefs.z3_mapping_mode = cboZ3Mapping->getSelected(); + } + RefreshPanelRAM(); } }; static MemorySliderActionListener* memorySliderActionListener; - void InitPanelRAM(const config_category& category) { memorySliderActionListener = new MemorySliderActionListener(); + + z3_mapping_mode.clear(); + z3_mapping_mode.add("Automatic (*)"); + z3_mapping_mode.add("UAE (0x10000000)"); + z3_mapping_mode.add("Real (0x40000000)"); + constexpr int sld_width = 150; int marker_length = 20; @@ -233,10 +251,32 @@ void InitPanelRAM(const config_category& category) category.panel->add(grpRAM); + lblZ3Mapping = new gcn::Label("Z3 Mapping Mode:"); + lblZ3Mapping->setSize(200, LABEL_HEIGHT); + + cboZ3Mapping = new gcn::DropDown(&z3_mapping_mode); + cboZ3Mapping->setSize(200, cboZ3Mapping->getHeight()); + cboZ3Mapping->setBaseColor(gui_base_color); + cboZ3Mapping->setBackgroundColor(gui_background_color); + cboZ3Mapping->setForegroundColor(gui_foreground_color); + cboZ3Mapping->setSelectionColor(gui_selection_color); + cboZ3Mapping->addActionListener(memorySliderActionListener); + + grpAdvancedRAM = new gcn::Window("Advanced Memory Settings"); + grpAdvancedRAM->setPosition(DISTANCE_BORDER, grpRAM->getY() + grpRAM->getHeight() + DISTANCE_NEXT_Y); + grpAdvancedRAM->add(lblZ3Mapping, 10, 10); + grpAdvancedRAM->add(cboZ3Mapping, lblZ3Mapping->getX(), lblZ3Mapping->getY() + lblZ3Mapping->getHeight() + 8); + grpAdvancedRAM->setSize(grpRAM->getWidth(), (category.panel->getHeight() / 2) - DISTANCE_NEXT_Y * 2); + grpAdvancedRAM->setMovable(false); + grpAdvancedRAM->setTitleBarHeight(TITLEBAR_HEIGHT); + grpAdvancedRAM->setBaseColor(gui_base_color); + grpAdvancedRAM->setForegroundColor(gui_foreground_color); + + category.panel->add(grpAdvancedRAM); + RefreshPanelRAM(); } - void ExitPanelRAM() { delete lblChipmem; @@ -261,6 +301,9 @@ void ExitPanelRAM() delete sldMbResHighmem; delete lblMbResHighsize; delete grpRAM; + delete lblZ3Mapping; + delete cboZ3Mapping; + delete grpAdvancedRAM; delete memorySliderActionListener; } @@ -377,8 +420,9 @@ void RefreshPanelRAM() break; } } -} + cboZ3Mapping->setSelected(changed_prefs.z3_mapping_mode); +} bool HelpPanelRAM(std::vector& helptext) {