From 1ea75a50e07b5add4d38f62bc7b099a3b053fd4e Mon Sep 17 00:00:00 2001 From: Shaun Inman Date: Tue, 21 Mar 2023 08:05:19 -0400 Subject: [PATCH] removed hdmi-related code --- src/clock/clock.c | 3 +- src/common/api.c | 34 +++---------------- src/common/api.h | 7 ---- src/keymon/keymon.c | 16 --------- src/libmsettings/msettings.c | 31 +---------------- src/libmsettings/msettings.h | 3 -- src/minarch/minarch.c | 64 +++++++++--------------------------- src/minui/minui.c | 3 +- 8 files changed, 22 insertions(+), 139 deletions(-) diff --git a/src/clock/clock.c b/src/clock/clock.c index 6509228..fd8f7eb 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -232,11 +232,10 @@ int main(int argc , char* argv[]) { POW_update(&dirty, &show_setting, NULL,NULL); - int resized = GFX_autosize(&screen, &dirty); if (dirty) { validate(); - if (!resized) GFX_clear(screen); // resizing clears the screen + GFX_clear(screen); GFX_blitHardwareGroup(screen, show_setting); diff --git a/src/common/api.c b/src/common/api.c index 176b789..889b1d2 100644 --- a/src/common/api.c +++ b/src/common/api.c @@ -515,21 +515,6 @@ void GFX_setNearestNeighbor(int enabled) { DE_setScaleCoef(gfx.de_mem, 2, scale_coef); DE_setScaleCoef(gfx.de_mem, 3, scale_coef); } -int GFX_autosize(SDL_Surface** screen, int* dirty) { - // TODO: remove this entirely? - return 0; - - // static int had_hdmi = -1; - // int has_hdmi = GetHDMI(); - // if (had_hdmi==has_hdmi) return 0; - // - // *dirty = 1; - // if (has_hdmi) *screen = GFX_resize(HDMI_MENU_WIDTH,FIXED_HEIGHT,HDMI_MENU_WIDTH*FIXED_BPP); - // else *screen = GFX_resize(FIXED_WIDTH,FIXED_HEIGHT,FIXED_PITCH); - // had_hdmi = has_hdmi; - // - // return 1; -} static void POW_flipOverlay(void); void GFX_flip(SDL_Surface* screen) { gfx.de_mem[DE_OVL_BA0(0)/4] = gfx.de_mem[DE_OVL_BA0(2)/4] = (uintptr_t)(gfx.fb_info.padd + gfx.page * PAGE_SIZE); @@ -1124,16 +1109,6 @@ static void SND_selectResampler(void) { // plat_sound_select_resampler size_t SND_batchSamples(const SND_Frame* frames, size_t frame_count) { // plat_sound_write / plat_sound_write_resample if (snd.frame_count==0) return 0; - // static int had_hdmi = -1; - // int has_hdmi = GetHDMI(); - // if (had_hdmi<0) had_hdmi = has_hdmi; - // if (has_hdmi!=had_hdmi) { - // had_hdmi = has_hdmi; - // if (has_hdmi) sleep(2); - // SND_quit(); - // SND_init(snd.sample_rate_in, snd.frame_rate); - // } - SDL_LockAudio(); int consumed = 0; @@ -1163,8 +1138,6 @@ size_t SND_batchSamples(const SND_Frame* frames, size_t frame_count) { // plat_s void SND_init(double sample_rate, double frame_rate) { // plat_sound_init LOG_info("SND_init\n"); - // SDL_putenv(GetHDMI()?"AUDIODEV=plughw:0,1":"default"); - SDL_InitSubSystem(SDL_INIT_AUDIO); snd.frame_rate = frame_rate; @@ -1417,6 +1390,8 @@ static void POW_quitOverlay(void) { static void POW_updateBatteryStatus(void) { pow.is_charging = getInt("/sys/class/power_supply/battery/charger_online"); + + // TODO: newer batteries have a different range, ???-420 int i = getInt("/sys/class/power_supply/battery/voltage_now") / 10000; // 310-410 i -= 310; // ~0-100 @@ -1467,7 +1442,6 @@ void POW_warn(int enable) { void POW_update(int* _dirty, int* _show_setting, POW_callback_t before_sleep, POW_callback_t after_sleep) { int dirty = _dirty ? *_dirty : 0; int show_setting = _show_setting ? *_show_setting : 0; - int has_hdmi = GetHDMI(); static uint32_t cancel_start = 0; static uint32_t power_start = 0; @@ -1528,10 +1502,10 @@ void POW_update(int* _dirty, int* _show_setting, POW_callback_t before_sleep, PO } #define MENU_DELAY 250 // also in PAD_tappedMenu() - if (PAD_justRepeated(BTN_PLUS) || PAD_justRepeated(BTN_MINUS) || (PAD_isPressed(BTN_MENU) && now-menu_start>=MENU_DELAY && !has_hdmi)) { + if (PAD_justRepeated(BTN_PLUS) || PAD_justRepeated(BTN_MINUS) || (PAD_isPressed(BTN_MENU) && now-menu_start>=MENU_DELAY)) { setting_start = now; if (PAD_isPressed(BTN_MENU)) { - if (!has_hdmi) show_setting = 1; + show_setting = 1; } else { show_setting = 2; diff --git a/src/common/api.h b/src/common/api.h index 77e38a3..12471fa 100644 --- a/src/common/api.h +++ b/src/common/api.h @@ -27,12 +27,6 @@ void LOG_note(int level, const char* fmt, ...); #define FIXED_PITCH (FIXED_WIDTH * FIXED_BPP) #define FIXED_SIZE (FIXED_PITCH * FIXED_HEIGHT) -#define HDMI_WIDTH 1280 -#define HDMI_HEIGHT 720 -#define HDMI_PITCH HDMI_WIDTH * FIXED_BPP -#define HDMI_SIZE HDMI_HEIGHT * HDMI_PITCH -#define HDMI_MENU_WIDTH 856 // FIXED_WIDTH * FIXED_HEIGHT / HDMI_HEIGHT rounded up to nearest 8 - #define PAGE_COUNT 2 #define PAGE_SCALE 3 #define PAGE_WIDTH (FIXED_WIDTH * PAGE_SCALE) @@ -101,7 +95,6 @@ SDL_Surface* GFX_init(int mode); SDL_Surface* GFX_resize(int width, int height, int pitch); void GFX_setScaleClip(int x, int y, int width, int height); void GFX_setNearestNeighbor(int enabled); -int GFX_autosize(SDL_Surface** screen, int* dirty); void GFX_setMode(int mode); void GFX_clear(SDL_Surface* screen); void GFX_clearAll(void); diff --git a/src/keymon/keymon.c b/src/keymon/keymon.c index 14ca0bc..6515dbf 100644 --- a/src/keymon/keymon.c +++ b/src/keymon/keymon.c @@ -31,7 +31,6 @@ static int jack_fd; static pthread_t ports_pt; #define JACK_STATE_PATH "/sys/class/switch/h2w/state" -#define HDMI_STATE_PATH "/sys/class/switch/hdmi/state" #define BACKLIGHT_PATH "/sys/class/backlight/backlight.2/bl_power" int getInt(char* path) { @@ -44,16 +43,12 @@ int getInt(char* path) { return i; } -// TODO: test HDMI connect/disconnect // TODO: still resetting between launches static void* watchPorts(void *arg) { int has_headphones,had_headphones; - int has_hdmi,had_hdmi; has_headphones = had_headphones = getInt(JACK_STATE_PATH); - has_hdmi = had_hdmi = getInt(HDMI_STATE_PATH); SetJack(has_headphones); - SetHDMI(has_hdmi); while(1) { sleep(1); @@ -63,17 +58,6 @@ static void* watchPorts(void *arg) { had_headphones = has_headphones; SetJack(has_headphones); } - - has_hdmi = getInt(HDMI_STATE_PATH); - if (had_hdmi!=has_hdmi) { - had_hdmi = has_hdmi; - SetHDMI(has_hdmi); - } - else if (has_hdmi && !getInt(BACKLIGHT_PATH)) { - SetHDMI(has_hdmi); - } - - } return 0; diff --git a/src/libmsettings/msettings.c b/src/libmsettings/msettings.c index 931b6ea..9f7a4fc 100644 --- a/src/libmsettings/msettings.c +++ b/src/libmsettings/msettings.c @@ -22,7 +22,6 @@ typedef struct Settings { int unused[2]; // for future use // NOTE: doesn't really need to be persisted but still needs to be shared int jack; - int hdmi; } Settings; static Settings DefaultSettings = { .version = SETTINGS_VERSION, @@ -30,7 +29,6 @@ static Settings DefaultSettings = { .headphones = 4, .speaker = 8, .jack = 0, - .hdmi = 0, }; static Settings* settings; @@ -43,7 +41,6 @@ static int shm_size = sizeof(Settings); #define BACKLIGHT_PATH "/sys/class/backlight/backlight.2/bl_power" #define BRIGHTNESS_PATH "/sys/class/backlight/backlight.2/brightness" #define VOLUME_PATH "/sys/class/volume/value" -#define MIRROR_PATH "/sys/class/graphics/fb0/mirror_to_hdmi" void InitSettings(void) { // sprintf(SettingsPath, "%s/msettings.bin", getenv("USERDATA_PATH")); @@ -74,12 +71,11 @@ void InitSettings(void) { // these shouldn't be persisted // settings->jack = 0; - // settings->hdmi = 0; } printf("brightness: %i\nspeaker: %i \n", settings->brightness, settings->speaker); SetVolume(GetVolume()); - SetBrightness(GetBrightness()); // also sets HDMI + SetBrightness(GetBrightness()); } void QuitSettings(void) { munmap(settings, shm_size); @@ -98,8 +94,6 @@ int GetBrightness(void) { // 0-10 return settings->brightness; } void SetBrightness(int value) { - if (settings->hdmi) return; - int raw; switch (value) { case 0: raw=16; break; // 0 @@ -132,8 +126,6 @@ void SetVolume(int value) { } void SetRawBrightness(int val) { // 0 - 1024 - if (settings->hdmi) return; - // printf("SetRawBrightness(%i)\n", val); fflush(stdout); int fd = open(BRIGHTNESS_PATH, O_WRONLY); if (fd>=0) { @@ -159,24 +151,3 @@ void SetJack(int value) { settings->jack = value; SetVolume(GetVolume()); } - -int GetHDMI(void) { - // printf("GetHDMI() %i\n", settings->hdmi); fflush(stdout); - return settings->hdmi; -} -void SetHDMI(int value) { - // printf("SetHDMI(%i)\n", value); fflush(stdout); - - settings->hdmi = value; - int fd = open(MIRROR_PATH, O_WRONLY); - if (fd>=0) { - dprintf(fd,"%d",value); - close(fd); - } - - fd = open(BACKLIGHT_PATH, O_WRONLY); - if (fd>=0) { - dprintf(fd,"%d",value ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK); - close(fd); - } -} diff --git a/src/libmsettings/msettings.h b/src/libmsettings/msettings.h index 77b84cf..e8276ee 100644 --- a/src/libmsettings/msettings.h +++ b/src/libmsettings/msettings.h @@ -16,7 +16,4 @@ void SetVolume(int value); // 0-20 int GetJack(void); void SetJack(int value); // 0-1 -int GetHDMI(void); -void SetHDMI(int value); // 0-1 - #endif // __msettings_h__ diff --git a/src/minarch/minarch.c b/src/minarch/minarch.c index 400a9a2..3d6b369 100644 --- a/src/minarch/minarch.c +++ b/src/minarch/minarch.c @@ -2441,10 +2441,9 @@ static void scaleNN_text_scanline(void* __restrict src, void* __restrict dst, ui static SDL_Surface* scaler_surface; static void selectScaler_PAR(int width, int height, int pitch) { - int has_hdmi = GetHDMI(); - int device_width = has_hdmi ? HDMI_WIDTH : SCREEN_WIDTH; - int device_height = has_hdmi ? HDMI_HEIGHT : SCREEN_HEIGHT; - int device_pitch = has_hdmi ? HDMI_PITCH : SCREEN_PITCH; + int device_width = SCREEN_WIDTH; + int device_height = SCREEN_HEIGHT; + int device_pitch = SCREEN_PITCH; renderer.scaler = scaleNull; renderer.dst_p = device_pitch; @@ -2603,9 +2602,8 @@ static void selectScaler_AR(int width, int height, int pitch) { int src_w = width; int src_h = height; - int has_hdmi = GetHDMI(); - int scale_x = CEIL_DIV(has_hdmi ? HDMI_WIDTH : SCREEN_WIDTH, src_w); - int scale_y = CEIL_DIV(has_hdmi ? HDMI_HEIGHT: SCREEN_HEIGHT,src_h); + int scale_x = CEIL_DIV(SCREEN_WIDTH, src_w); + int scale_y = CEIL_DIV(SCREEN_HEIGHT,src_h); int scale = MAX(scale_x, scale_y); // TODO: this "logic" is a disaster @@ -2628,14 +2626,13 @@ static void selectScaler_AR(int width, int height, int pitch) { char scaler_name[8]; #define FOUR_THREE 4.0f / 3 -#define SIXTEEN_NINE 16.0 / 9 - double target_ratio = has_hdmi ? SIXTEEN_NINE : FOUR_THREE; + double target_ratio = FOUR_THREE; // TODO: sotn moon is busted 512x240 ends up 2x but targeting 864x480 if (screen_scaling==1) { - sprintf(scaler_name, "AR_%iX%s", scale, has_hdmi?"W":"R"); + sprintf(scaler_name, "AR_%iX%s", scale, "R"); if (core.aspect_ratio==target_ratio) { LOG_info("already correct ratio\n"); } @@ -2643,10 +2640,10 @@ static void selectScaler_AR(int width, int height, int pitch) { // TODO: is this ignoring the core's desired aspect ratio? // see snes or SotN // I think it's acting more like PAR - sprintf(scaler_name, "AR_%iX%sR", scale, has_hdmi?"W":"R"); + sprintf(scaler_name, "AR_%iX%sR", scale, "R"); - int ratio_left = target_ratio==SIXTEEN_NINE ? 16 : 4; - int ratio_right = target_ratio==SIXTEEN_NINE ? 9 : 3; + int ratio_left = 4; + int ratio_right = 3; // TODO: why do these use CEIL_DIV? if (core.aspect_ratiow,screen->h-SCALE1(PILL_SIZE+PADDING)}); GFX_blitButtonGroup(pairs, screen, 1); @@ -3583,10 +3568,7 @@ static int Menu_options(MenuList* list) { POW_update(&dirty, &show_settings, Menu_beforeSleep, Menu_afterSleep); - int resized = GFX_autosize(&screen, &dirty); if (dirty) { - if (!resized) GFX_clear(screen); // resizing clears the screen - GFX_clear(screen); GFX_blitHardwareGroup(screen, show_settings); @@ -3835,7 +3817,6 @@ static void downsample(void* __restrict src, void* __restrict dst, uint32_t w, u static void Menu_loop(void) { // current screen is on the previous buffer - // TODO: can we use renderer.src_w/h to reverse the stretch regardless of HDMI status? // because we need an undeformed copy for save state screenshots SDL_Surface* backing = GFX_getBufferCopy(); SDL_Surface* snapshot = SDL_CreateRGBSurface(SDL_SWSURFACE, FIXED_WIDTH,FIXED_HEIGHT,FIXED_DEPTH,0,0,0,0); @@ -3847,25 +3828,14 @@ static void Menu_loop(void) { downsample(backing->pixels,snapshot->pixels,backing->w,backing->h,backing->pitch,snapshot->pitch); } - // TODO: move this to right before if (dirty) {} like in minui.elf - // TODO: could move to a GFX_autosize(&dirty) -> has_hdmi - int has_hdmi = GetHDMI(); - - int target_w = has_hdmi ? HDMI_MENU_WIDTH : FIXED_WIDTH; // 640 * 480 / 720 rounded up to nearest 8 + int target_w = FIXED_WIDTH; // 640 * 480 / 720 rounded up to nearest 8 int target_h = FIXED_HEIGHT; int target_p = target_w * FIXED_BPP; - LOG_info("hdmi: %i %ix%i (%i)\n", has_hdmi,target_w,target_h,target_p); - - if (has_hdmi && (screen->w!=target_w || screen->h!=target_h)) { - screen = GFX_resize(target_w,target_h,target_p); - } - else if (screen->w!=SCREEN_WIDTH || screen->h!=SCREEN_HEIGHT) { + if (screen->w!=SCREEN_WIDTH || screen->h!=SCREEN_HEIGHT) { screen = GFX_resize(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_PITCH); } - // TODO: attempt to draw menu in center of screen when in hdmi - POW_warn(0); POW_setCPUSpeed(CPU_SPEED_MENU); // set Hz directly GFX_setVsync(VSYNC_STRICT); @@ -4077,9 +4047,8 @@ static void Menu_loop(void) { POW_update(&dirty, &show_setting, Menu_beforeSleep, Menu_afterSleep); - int resized = GFX_autosize(&screen, &dirty); if (dirty) { - if (!resized) GFX_clear(screen); // resizing clears the screen + GFX_clear(screen); SDL_BlitSurface(snapshot, NULL, screen, NULL); SDL_BlitSurface(menu.overlay, NULL, screen, NULL); @@ -4227,10 +4196,7 @@ static void Menu_loop(void) { GFX_clearAll(); if (!quit) { - if (GetHDMI() && screen_scaling==SCALE_NATIVE) { - screen = GFX_resize(HDMI_WIDTH,HDMI_HEIGHT, HDMI_PITCH); - } - else if (backing->w!=FIXED_WIDTH || backing->h!=FIXED_HEIGHT) { + if (backing->w!=FIXED_WIDTH || backing->h!=FIXED_HEIGHT) { screen = GFX_resize(renderer.dst_w,renderer.dst_h, renderer.dst_p); } diff --git a/src/minui/minui.c b/src/minui/minui.c index 258493f..77890f6 100644 --- a/src/minui/minui.c +++ b/src/minui/minui.c @@ -1320,9 +1320,8 @@ int main (int argc, char *argv[]) { POW_update(&dirty, &show_setting, NULL, NULL); - int resized = GFX_autosize(&screen, &dirty); if (dirty) { - if (!resized) GFX_clear(screen); // resizing clears the screen + GFX_clear(screen); int ox; int oy;