Skip to content

Commit

Permalink
feat: expose Z3 mapping mode option in GUI->RAM
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Mar 3, 2025
1 parent c6603a2 commit aa986ea
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 36 deletions.
34 changes: 12 additions & 22 deletions src/osdep/amiberry_mem.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <cstdlib>
#include <cstring>

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<uae_u32>(maxmem, max_allowed_mman);

#ifdef _WIN32
memstats.dwLength = sizeof(memstats);
Expand Down Expand Up @@ -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<uae_u32>(max_allowed_mman, 256);
}
} else if (maxmem > 0) {
size64 = static_cast<uae_u64>(maxmem) * 1024 * 1024;
}
if (size64 < 8 * 1024 * 1024)
size64 = 8 * 1024 * 1024;
size64 = std::max<uae_u64>(size64, 8 * 1024 * 1024);
if (static_cast<uae_u64>(max_allowed_mman) * 1024 * 1024 > size64)
max_allowed_mman = static_cast<uae_u32>(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<uae_u32>(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
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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"));
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
72 changes: 58 additions & 14 deletions src/osdep/gui/PanelRAM.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <algorithm>
#include <guisan.hpp>
#include <guisan/sdl.hpp>
#include "SelectorEntry.hpp"
#include "sysdeps.h"
#include "options.h"
#include "memory.h"
#include "gui_handling.h"
#include "StringListModel.h"
#include "target.h"

static gcn::Window* grpRAM;
Expand All @@ -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<int>(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<int>(sldSlowmem->getValue())]];
}

else if (actionEvent.getSource() == sldFastmem)
else if (source == sldFastmem)
{
changed_prefs.fastmem[0].size = memsizes[msi_fast[static_cast<int>(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<int>(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<int>(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<int>(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<int>(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;

Expand Down Expand Up @@ -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;
Expand All @@ -261,6 +301,9 @@ void ExitPanelRAM()
delete sldMbResHighmem;
delete lblMbResHighsize;
delete grpRAM;
delete lblZ3Mapping;
delete cboZ3Mapping;
delete grpAdvancedRAM;
delete memorySliderActionListener;
}

Expand Down Expand Up @@ -377,8 +420,9 @@ void RefreshPanelRAM()
break;
}
}
}

cboZ3Mapping->setSelected(changed_prefs.z3_mapping_mode);
}

bool HelpPanelRAM(std::vector<std::string>& helptext)
{
Expand Down

0 comments on commit aa986ea

Please sign in to comment.