Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Request for tested improvements #196

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "retro-go-stm32"]
path = retro-go-stm32
url = https://github.com/kbeckmann/retro-go-stm32
url = https://github.com/Nibelheims/retro-go-stm32
[submodule "LCD-Game-Emulator"]
path = LCD-Game-Emulator
url = https://github.com/bzhxx/LCD-Game-Emulator.git
4 changes: 4 additions & 0 deletions Core/Inc/gw_lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#define GW_LCD_WIDTH 320
#define GW_LCD_HEIGHT 240
#define GW_LCD_ORIG_WIDTH 160
#define GW_LCD_ORIG_HEIGHT 144
#define GW_LCD_FIT_WIDTH 266
#define GW_LCD_FIT_HEIGHT 240

#ifdef GW_LCD_MODE_LUT8
extern uint8_t framebuffer1[GW_LCD_WIDTH * GW_LCD_HEIGHT] __attribute__((section (".lcd1"))) __attribute__ ((aligned (16)));
Expand Down
5 changes: 4 additions & 1 deletion Core/Inc/porting/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ extern int16_t pendingSamples;
extern int16_t audiobuffer_emulator[AUDIO_BUFFER_LENGTH] __attribute__((section (".audio")));
extern int16_t audiobuffer_dma[AUDIO_BUFFER_LENGTH * 2] __attribute__((section (".audio")));

extern const uint8_t volume_tbl[ODROID_AUDIO_VOLUME_MAX + 1];
extern const uint8_t *volume_tbl;
extern const uint8_t volume_tbl_normal[ODROID_AUDIO_VOLUME_MAX + 1];
extern const uint8_t volume_tbl_low[ODROID_AUDIO_VOLUME_MAX + 1];
extern const uint8_t volume_tbl_very_low[ODROID_AUDIO_VOLUME_MAX + 1];

bool common_emu_frame_loop(void);
void common_emu_input_loop(odroid_gamepad_state_t *joystick, odroid_dialog_choice_t *game_options);
Expand Down
44 changes: 41 additions & 3 deletions Core/Src/porting/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int16_t audiobuffer_dma[AUDIO_BUFFER_LENGTH * 2] __attribute__((section (".audio
dma_transfer_state_t dma_state;
uint32_t dma_counter;

const uint8_t volume_tbl[ODROID_AUDIO_VOLUME_MAX + 1] = {
const uint8_t volume_tbl_normal[ODROID_AUDIO_VOLUME_MAX + 1] = {
(uint8_t)(UINT8_MAX * 0.00f),
(uint8_t)(UINT8_MAX * 0.06f),
(uint8_t)(UINT8_MAX * 0.125f),
Expand All @@ -46,6 +46,34 @@ const uint8_t volume_tbl[ODROID_AUDIO_VOLUME_MAX + 1] = {
(uint8_t)(UINT8_MAX * 1.00f),
};

const uint8_t volume_tbl_low[ODROID_AUDIO_VOLUME_MAX + 1] = {
(uint8_t)(UINT8_MAX * 0.00f),
(uint8_t)(UINT8_MAX * 0.015f),
(uint8_t)(UINT8_MAX * 0.031f),
(uint8_t)(UINT8_MAX * 0.140f),
(uint8_t)(UINT8_MAX * 0.25f),
(uint8_t)(UINT8_MAX * 0.35f),
(uint8_t)(UINT8_MAX * 0.42f),
(uint8_t)(UINT8_MAX * 0.60f),
(uint8_t)(UINT8_MAX * 0.80f),
(uint8_t)(UINT8_MAX * 1.00f),
};

const uint8_t volume_tbl_very_low[ODROID_AUDIO_VOLUME_MAX + 1] = {
(uint8_t)(UINT8_MAX * 0.00f),
(uint8_t)(UINT8_MAX * 0.004f),
(uint8_t)(UINT8_MAX * 0.008f),
(uint8_t)(UINT8_MAX * 0.015f),
(uint8_t)(UINT8_MAX * 0.031f),
(uint8_t)(UINT8_MAX * 0.140f),
(uint8_t)(UINT8_MAX * 0.25f),
(uint8_t)(UINT8_MAX * 0.35f),
(uint8_t)(UINT8_MAX * 0.42f),
(uint8_t)(UINT8_MAX * 0.60f),
};

const uint8_t *volume_tbl = volume_tbl_normal;

void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai)
{
dma_counter++;
Expand Down Expand Up @@ -501,6 +529,15 @@ static void draw_darken_rectangle(pixel_t *fb, uint16_t x1, uint16_t y1, uint16_
}
}

__attribute__((optimize("unroll-loops")))
static void draw_black_rectangle(pixel_t *fb, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2){
for(uint16_t i=y1; i < y2; i++){
for(uint16_t j=x1; j < x2; j++){
fb[j + GW_LCD_WIDTH * i] = 0;
}
}
}

__attribute__((optimize("unroll-loops")))
static void draw_darken_rounded_rectangle(pixel_t *fb, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2){
// *1 is inclusive, *2 is exclusive
Expand Down Expand Up @@ -594,6 +631,7 @@ static void draw_clear_rounded_rectangle(pixel_t *fb, uint16_t x1, uint16_t y1,
clear_pixel(&fb[ i + GW_LCD_WIDTH * (y2 - j - 1)]);
}

// TODO make those macros calling function which return proper dimensions
#define INGAME_OVERLAY_X 265
#define INGAME_OVERLAY_Y 10
#define INGAME_OVERLAY_BARS_H 128
Expand Down Expand Up @@ -657,7 +695,7 @@ void common_ingame_overlay(void) {
INGAME_OVERLAY_BOX_X + INGAME_OVERLAY_BOX_W,
by + bh);
else
draw_darken_rectangle(fb,
draw_black_rectangle(fb,
INGAME_OVERLAY_BOX_X,
by,
INGAME_OVERLAY_BOX_X + INGAME_OVERLAY_BOX_W,
Expand Down Expand Up @@ -685,7 +723,7 @@ void common_ingame_overlay(void) {
INGAME_OVERLAY_BOX_X + INGAME_OVERLAY_BOX_W,
by + bh);
else
draw_darken_rectangle(fb,
draw_black_rectangle(fb,
INGAME_OVERLAY_BOX_X,
by,
INGAME_OVERLAY_BOX_X + INGAME_OVERLAY_BOX_W,
Expand Down
13 changes: 8 additions & 5 deletions Core/Src/porting/gb/main_gb.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static inline void screen_blit_nn(int32_t dest_width, int32_t dest_height)
printf("Blit: %d us\n", (1000000 * PROFILING_DIFF(t_blit)) / t_blit_t0.SecondFraction);
#endif

common_ingame_overlay();
lcd_swap();
}

Expand Down Expand Up @@ -160,6 +161,7 @@ static void screen_blit_bilinear(int32_t dest_width)
printf("Blit: %d us\n", (1000000 * PROFILING_DIFF(t_blit)) / t_blit_t0.SecondFraction);
#endif

common_ingame_overlay();
lcd_swap();
}

Expand Down Expand Up @@ -304,6 +306,7 @@ static inline void screen_blit_jth(void) {
printf("Blit: %d us\n", (1000000 * PROFILING_DIFF(t_blit)) / t_blit_t0.SecondFraction);
#endif

common_ingame_overlay();
lcd_swap();
}

Expand All @@ -316,7 +319,7 @@ static void blit(void)
switch (scaling) {
case ODROID_DISPLAY_SCALING_OFF:
// Original Resolution
screen_blit_nn(160, 144);
screen_blit_nn(GW_LCD_ORIG_WIDTH, GW_LCD_ORIG_HEIGHT);
break;
case ODROID_DISPLAY_SCALING_FIT:
// Full height, borders on the side
Expand All @@ -325,11 +328,11 @@ static void blit(void)
/* fall-through */
case ODROID_DISPLAY_FILTER_SHARP:
// crisp nearest neighbor scaling
screen_blit_nn(266, 240);
screen_blit_nn(GW_LCD_FIT_WIDTH, GW_LCD_FIT_HEIGHT);
break;
case ODROID_DISPLAY_FILTER_SOFT:
// soft bilinear scaling
screen_blit_bilinear(266);
screen_blit_bilinear(GW_LCD_FIT_WIDTH);
break;
default:
printf("Unknown filtering mode %d\n", filtering);
Expand All @@ -342,15 +345,15 @@ static void blit(void)
switch (filtering) {
case ODROID_DISPLAY_FILTER_OFF:
// crisp nearest neighbor scaling
screen_blit_nn(320, 240);
screen_blit_nn(GW_LCD_WIDTH, GW_LCD_HEIGHT);
break;
case ODROID_DISPLAY_FILTER_SHARP:
// sharp bilinear-ish scaling
screen_blit_v3to5();
break;
case ODROID_DISPLAY_FILTER_SOFT:
// soft bilinear scaling
screen_blit_bilinear(320);
screen_blit_bilinear(GW_LCD_WIDTH);
break;
default:
printf("Unknown filtering mode %d\n", filtering);
Expand Down
10 changes: 5 additions & 5 deletions Core/Src/porting/odroid_overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ static bool filter_update_cb(odroid_dialog_choice_t *option, odroid_dialog_event
odroid_display_set_filter_mode(mode);
}

if (mode == ODROID_DISPLAY_FILTER_OFF) strcpy(option->value, "Off");
if (mode == ODROID_DISPLAY_FILTER_OFF) strcpy(option->value, "Off ");
if (mode == ODROID_DISPLAY_FILTER_SHARP) strcpy(option->value, "Sharp");
if (mode == ODROID_DISPLAY_FILTER_SOFT) strcpy(option->value, "Soft");
if (mode == ODROID_DISPLAY_FILTER_SOFT) strcpy(option->value, "Soft ");

return event == ODROID_DIALOG_ENTER;
}
Expand All @@ -505,9 +505,9 @@ static bool scaling_update_cb(odroid_dialog_choice_t *option, odroid_dialog_even
odroid_display_set_scaling_mode(mode);
}

if (mode == ODROID_DISPLAY_SCALING_OFF) strcpy(option->value, "Off");
if (mode == ODROID_DISPLAY_SCALING_FIT) strcpy(option->value, "Fit");
if (mode == ODROID_DISPLAY_SCALING_FULL) strcpy(option->value, "Full");
if (mode == ODROID_DISPLAY_SCALING_OFF) strcpy(option->value, "Off ");
if (mode == ODROID_DISPLAY_SCALING_FIT) strcpy(option->value, "Fit ");
if (mode == ODROID_DISPLAY_SCALING_FULL) strcpy(option->value, "Full ");
if (mode == ODROID_DISPLAY_SCALING_CUSTOM) strcpy(option->value, "Custom");

return event == ODROID_DIALOG_ENTER;
Expand Down
12 changes: 11 additions & 1 deletion Core/Src/porting/odroid_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct persistent_config {
uint8_t backlight;
uint8_t start_action;
uint8_t volume;
uint8_t sound_profile; // actually a value in ODROID_SOUND_PROFILE
uint8_t font_size;
uint8_t startup_app;
void *startup_file;
Expand All @@ -47,11 +48,12 @@ typedef struct persistent_config {

static const persistent_config_t persistent_config_default = {
.magic = CONFIG_MAGIC,
.version = 4,
.version = 5,

.backlight = ODROID_BACKLIGHT_LEVEL6,
.start_action = ODROID_START_ACTION_RESUME,
.volume = ODROID_AUDIO_VOLUME_MAX / 2, // Too high volume can cause brown out if the battery isn't connected.
.sound_profile = ODROID_SOUND_PROFILE_NORMAL,
.font_size = 8,
.startup_app = 0,
.main_menu_timeout_s = 60 * 10, // Turn off after 10 minutes of idle time in the main menu
Expand Down Expand Up @@ -184,6 +186,14 @@ void odroid_settings_Volume_set(int32_t value)
persistent_config_ram.volume = value;
}

int32_t odroid_settings_SoundProfile_get()
{
return persistent_config_ram.sound_profile;
}
void odroid_settings_SoundProfile_set(int32_t value)
{
persistent_config_ram.sound_profile = value;
}

int32_t odroid_settings_AudioSink_get()
{
Expand Down
9 changes: 0 additions & 9 deletions Core/Src/retro-go/rg_emulators.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,16 @@ void emulator_show_file_menu(retro_emulator_file_t *file)
// char *sram_path = odroid_system_get_path(ODROID_PATH_SAVE_SRAM, emu_get_file_path(file));
// bool has_save = odroid_sdcard_get_filesize(save_path) > 0;
// bool has_sram = odroid_sdcard_get_filesize(sram_path) > 0;
// bool is_fav = favorite_find(file) != NULL;

bool has_save = 1;
bool has_sram = 0;
bool is_fav = 0;

odroid_dialog_choice_t choices[] = {
#if STATE_SAVING == 1
{0, "Resume game ", "", has_save, NULL},
#endif
{1, "New game ", "", 1, NULL},
{0, "------------", "", -1, NULL},
{3, is_fav ? "Del favorite" : "Add favorite", "", 1, NULL},
#if STATE_SAVING == 1
{2, "Delete save ", "", has_save || has_sram, NULL},
#endif
Expand All @@ -363,12 +360,6 @@ void emulator_show_file_menu(retro_emulator_file_t *file)
store_erase(file->save_address, file->save_size);
}
}
else if (sel == 3) {
// if (is_fav)
// favorite_remove(file);
// else
// favorite_add(file);
}

// free(save_path);
// free(sram_path);
Expand Down
Loading
Loading