Skip to content

Commit

Permalink
Allow changing flash select port
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiusbrown committed Mar 14, 2024
1 parent 9c3b8eb commit d162d59
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ Restricts the display scaling to an integral scaling factor. Defaults to false f
#### `c` or `current`
Enables modeling the display row driver current limit. This effectively darkens rows that have many lit pixels. Defaults to false.

#### `fxport`
Sets the port to be used for the flash select. Values:
- `0` or `d1` or `fx`
- `1` or `d2`
- `2` or `e2` or `mini`

## Libraries Used

- [SDL](https://github.com/libsdl-org/SDL) (zlib)
Expand Down
3 changes: 3 additions & 0 deletions src/absim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,9 @@ struct arduboy_t
ssd1306_t display;
w25q128_t fx;

uint8_t fxport_reg;
uint8_t fxport_mask;

uint64_t game_hash;
void update_game_hash();

Expand Down
12 changes: 8 additions & 4 deletions src/absim_arduboy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ void arduboy_t::reset()

if(breakpoints.test(0))
paused = true;

fxport_reg = 0x2b; // PORTD
fxport_mask = 1 << 1; // PORTD1
}

static elf_data_symbol_t const* symbol_for_addr_helper(
Expand Down Expand Up @@ -400,21 +403,22 @@ ARDENS_FORCEINLINE uint32_t arduboy_t::cycle()
assert(cpu.decoded);

bool vsync = false;
uint8_t portd = cpu.data[0x2b];
uint8_t displayport = cpu.data[0x2b];
uint8_t fxport = cpu.data[fxport_reg];
uint32_t cycles = cpu.advance_cycle();

// TODO: model SPI connection more precisely?
// send SPI commands and data to display
fx.set_enabled((portd & (1 << 1)) == 0);
fx.set_enabled((fxport & fxport_mask) == 0);

if(cpu.spi_done_shifting)
{
uint8_t byte = cpu.spi_data_byte;

// display enabled?
if(!(portd & (1 << 6)))
if(!(displayport & (1 << 6)))
{
if(portd & (1 << 4))
if(displayport & (1 << 4))
{
if(frame_bytes_total != 0 && ++frame_bytes >= frame_bytes_total)
{
Expand Down
31 changes: 31 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,19 @@ extern "C" int setparam(char const* name, char const* value)
update_settings();
r = 1;
}
else if(!strcmp(name, "fxport"))
{
if(!strcmp(value, "d1") || !strcmp(value, "fx"))
settings.fxport = FXPORT_D1;
else if(!strcmp(value, "d2") || !strcmp(value, "orig"))
settings.fxport = FXPORT_D2;
else if(!strcmp(value, "32") || !strcmp(value, "mini"))
settings.fxport = FXPORT_E2;
else
settings.fxport = std::clamp<int>(nvalue, 0, FXPORT_NUM - 1);
update_settings();
r = 1;
}
else if(!strcmp(name, "loading"))
{
loading_indicator = bvalue;
Expand Down Expand Up @@ -557,6 +570,24 @@ void frame_logic()
default: arduboy->display.current_limit_slope = 0.f; break;
}

switch(settings.fxport)
{
case FXPORT_D1:
arduboy->fxport_reg = 0x2b;
arduboy->fxport_mask = 1 << 1;
break;
case FXPORT_D2:
arduboy->fxport_reg = 0x2b;
arduboy->fxport_mask = 1 << 2;
break;
case FXPORT_E2:
arduboy->fxport_reg = 0x2e;
arduboy->fxport_mask = 1 << 2;
break;
default:
break;
}

constexpr uint64_t MS_TO_PS = 1000000000ull;
uint64_t dtps = dt * MS_TO_PS * 1000 / simulation_slowdown;
if(gif_recording)
Expand Down
10 changes: 10 additions & 0 deletions src/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ enum
FILTER_MAX = FILTER_MAX_PLUS_ONE - 1,
};

enum
{
FXPORT_D1,
FXPORT_D2,
FXPORT_E2,
FXPORT_NUM,
};

constexpr int RECORDING_ZOOM_MAX = 4;

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

bool open_disassembly = false;
bool open_display = true;
Expand Down
20 changes: 19 additions & 1 deletion src/settings_modal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,27 @@ void modal_settings()
if(SliderInt("##volume", &settings.volume, 0, 200, "%d%%"))
update_settings();

static char const* const FXPORT_ITEMS[] =
{
"D1 (Arduboy FX)",
"D2 (Original)",
"E2 (Arduboy Mini)",
};
constexpr int NUM_FXPORT_ITEMS = sizeof(FXPORT_ITEMS) / sizeof(FXPORT_ITEMS[0]);
static_assert(NUM_FXPORT_ITEMS == FXPORT_NUM);
TableNextRow();
TableSetColumnIndex(0);
AlignTextToFramePadding();
TextUnformatted("FX Chip-Select Port");
TableSetColumnIndex(1);
SetNextItemWidth(-1.f);
if(Combo("##fxport", &settings.fxport,
FXPORT_ITEMS, NUM_FXPORT_ITEMS, NUM_FXPORT_ITEMS))
update_settings();

static char const* const CURRENT_ITEMS[] =
{
"Off", "Subtle", "Normal", "Exaggerated",
"Off", "Subtle", "Normal", "Exaggerated",
};
constexpr int NUM_CURRENT_ITEMS = sizeof(CURRENT_ITEMS) / sizeof(CURRENT_ITEMS[0]);
TableNextRow();
Expand Down

0 comments on commit d162d59

Please sign in to comment.