Skip to content

Commit

Permalink
Add UI scaling and begin display type adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiusbrown committed Mar 14, 2024
1 parent d162d59 commit a7fef85
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ set(ARDENS_SOURCES
src/absim_cpu_data.cpp

src/absim_arduboy.cpp
src/absim_ssd1306.hpp
src/absim_display.hpp
src/absim_atmega32u4.hpp
src/absim_w25q128.hpp

Expand Down
4 changes: 2 additions & 2 deletions src/absim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ struct atmega32u4_t
void update_all();
};

struct ssd1306_t
struct display_t
{
std::array<uint8_t, 8192> filtered_pixels;
std::array<uint16_t, 8192> filtered_pixel_counts;
Expand Down Expand Up @@ -777,7 +777,7 @@ struct savedata_t
struct arduboy_t
{
atmega32u4_t cpu;
ssd1306_t display;
display_t display;
w25q128_t fx;

uint8_t fxport_reg;
Expand Down
2 changes: 1 addition & 1 deletion src/absim_arduboy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <bitsery/traits/vector.h>

#include "absim_atmega32u4.hpp"
#include "absim_ssd1306.hpp"
#include "absim_display.hpp"

namespace absim
{
Expand Down
18 changes: 9 additions & 9 deletions src/absim_ssd1306.hpp → src/absim_display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace absim
{

void ssd1306_t::send_command(uint8_t byte)
void display_t::send_command(uint8_t byte)
{
if(!processing_command)
{
Expand Down Expand Up @@ -242,7 +242,7 @@ void ssd1306_t::send_command(uint8_t byte)
++command_byte_index;
}

void ssd1306_t::send_data(uint8_t byte)
void display_t::send_data(uint8_t byte)
{
uint8_t mapped_col = segment_remap ? 127 - data_col : data_col;
size_t i = data_page * 128 + mapped_col;
Expand Down Expand Up @@ -289,7 +289,7 @@ void ssd1306_t::send_data(uint8_t byte)
}
}

void ARDENS_FORCEINLINE ssd1306_t::update_pixels_row()
void ARDENS_FORCEINLINE display_t::update_pixels_row()
{
uint8_t ram_row = row;
ram_row += display_start;
Expand Down Expand Up @@ -384,7 +384,7 @@ void ARDENS_FORCEINLINE ssd1306_t::update_pixels_row()
filter_pixels();
}

void ssd1306_t::filter_pixels()
void display_t::filter_pixels()
{
memset(&filtered_pixel_counts, 0, sizeof(filtered_pixel_counts));
static constexpr uint8_t C[4] = { 42, 84, 84, 42 };
Expand All @@ -398,7 +398,7 @@ void ssd1306_t::filter_pixels()
filtered_pixels[i] = uint8_t(filtered_pixel_counts[i] / 256);
}

bool ARDENS_FORCEINLINE ssd1306_t::advance(uint64_t ps)
bool ARDENS_FORCEINLINE display_t::advance(uint64_t ps)
{
vsync = false;
ps += ps_rem;
Expand Down Expand Up @@ -430,13 +430,13 @@ constexpr std::array<double, 16> FOSC =
392, 416, 440, 464, 488, 512, 536, 570,
};

void ARDENS_FORCEINLINE ssd1306_t::update_clocking()
void ARDENS_FORCEINLINE display_t::update_clocking()
{
cycles_per_row = phase_1 + phase_2 + 50;
ps_per_clk = (uint64_t)std::round(1e12 * (divide_ratio + 1) / fosc());
}

void ssd1306_t::reset()
void display_t::reset()
{
memset(&ram, 0, sizeof(ram));
memset(&pixels, 0, sizeof(pixels));
Expand Down Expand Up @@ -493,12 +493,12 @@ void ssd1306_t::reset()
update_clocking();
}

double ssd1306_t::fosc() const
double display_t::fosc() const
{
return FOSC[fosc_index % 16] * 1000.0;
}

double ssd1306_t::refresh_rate() const
double display_t::refresh_rate() const
{
int D = divide_ratio + 1;
int K = phase_1 + phase_2 + 50;
Expand Down
1 change: 1 addition & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ extern "C" void postsyncfs()
bool update_pixel_ratio()
{
float ratio = platform_pixel_ratio();
ratio *= (settings.uiscale * 0.25f + 0.5f);
bool changed = (ratio != pixel_ratio);
pixel_ratio = ratio;
return changed;
Expand Down
2 changes: 2 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static void settings_read_line(
ARDENS_INT_SETTING(recording_downsample, 1, 4);
ARDENS_INT_SETTING(recording_zoom, 1, 4);
ARDENS_INT_SETTING(recording_orientation, 0, 3);
ARDENS_INT_SETTING(uiscale, 0, 6);
ARDENS_INT_SETTING(volume, 0, 200);

#undef ARDENS_BOOL_SETTING
Expand Down Expand Up @@ -148,6 +149,7 @@ static void settings_write_all(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
ARDENS_INT_SETTING(recording_downsample, 1, 4);
ARDENS_INT_SETTING(recording_zoom, 1, 4);
ARDENS_INT_SETTING(recording_orientation, 0, 3);
ARDENS_INT_SETTING(uiscale, 0, 6);
ARDENS_INT_SETTING(volume, 0, 200);

#undef ARDENS_BOOL_SETTING
Expand Down
12 changes: 12 additions & 0 deletions src/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ enum
FXPORT_NUM,
};

enum
{
DISPLAY_SSD1306,
DISPLAY_SSD1309,
DISPLAY_SH1106,
DISPLAY_NUM,
};

constexpr int RECORDING_ZOOM_MAX = 4;

struct settings_t
{
// Non-persistent settings
int fxport = FXPORT_D1;
int display = DISPLAY_SSD1306;

bool open_disassembly = false;
bool open_display = true;
Expand Down Expand Up @@ -99,6 +108,9 @@ struct settings_t
int recording_zoom = 1;
int recording_orientation = 0;

// 50%, 75%, 100%, 125%, 150%, 175%, 200%
int uiscale = 2;

int volume = 100;

bool recording_sameasdisplay = true;
Expand Down
60 changes: 51 additions & 9 deletions src/settings_modal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ void modal_settings()
{
if(settings_begin_table())
{
TableNextRow();
TableSetColumnIndex(0);
AlignTextToFramePadding();
TextUnformatted("Audio Volume");
TableSetColumnIndex(1);
SetNextItemWidth(-1.f);
if(SliderInt("##volume", &settings.volume, 0, 200, "%d%%"))
update_settings();

static char const* const FXPORT_ITEMS[] =
{
"D1 (Arduboy FX)",
Expand All @@ -95,6 +86,24 @@ void modal_settings()
FXPORT_ITEMS, NUM_FXPORT_ITEMS, NUM_FXPORT_ITEMS))
update_settings();

static char const* const DISPLAY_ITEMS[] =
{
"SSD1306 (Official)",
"SSD1309",
"SH1106",
};
constexpr int NUM_DISPLAY_ITEMS = sizeof(DISPLAY_ITEMS) / sizeof(DISPLAY_ITEMS[0]);
static_assert(NUM_DISPLAY_ITEMS == DISPLAY_NUM);
TableNextRow();
TableSetColumnIndex(0);
AlignTextToFramePadding();
TextUnformatted("Display Type");
TableSetColumnIndex(1);
SetNextItemWidth(-1.f);
if(Combo("##displaytype", &settings.display,
DISPLAY_ITEMS, NUM_DISPLAY_ITEMS, NUM_DISPLAY_ITEMS))
update_settings();

static char const* const CURRENT_ITEMS[] =
{
"Off", "Subtle", "Normal", "Exaggerated",
Expand All @@ -117,6 +126,39 @@ void modal_settings()
TableSetColumnIndex(1);
if(Checkbox("##nondeterminism", &settings.nondeterminism))
update_settings();

EndTable();
}
EndTabItem();
}
if(BeginTabItem("Interface"))
{
if(settings_begin_table())
{
static char const* const UISCALE_ITEMS[] =
{
"50%", "75%", "100%", "125%", "150%", "175%", "200%",
};
constexpr int NUM_UISCALE_ITEMS = sizeof(UISCALE_ITEMS) / sizeof(UISCALE_ITEMS[0]);
TableNextRow();
TableSetColumnIndex(0);
AlignTextToFramePadding();
TextUnformatted("UI Scale");
TableSetColumnIndex(1);
SetNextItemWidth(-1.f);
if(Combo("##uiscale", &settings.uiscale,
UISCALE_ITEMS, NUM_UISCALE_ITEMS, NUM_UISCALE_ITEMS))
update_settings();

TableNextRow();
TableSetColumnIndex(0);
AlignTextToFramePadding();
TextUnformatted("Audio Volume");
TableSetColumnIndex(1);
SetNextItemWidth(-1.f);
if(SliderInt("##volume", &settings.volume, 0, 200, "%d%%"))
update_settings();

EndTable();
}
EndTabItem();
Expand Down

0 comments on commit a7fef85

Please sign in to comment.