diff --git a/input.cpp b/input.cpp index 6d7578e..7a91bb2 100644 --- a/input.cpp +++ b/input.cpp @@ -2373,7 +2373,9 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int } } -static struct pollfd pool[NUMDEV + 1]; +#define CMD_FIFO "/dev/MiSTer_cmd" + +static struct pollfd pool[NUMDEV + 2]; int input_test(int getchar) { @@ -2390,6 +2392,12 @@ int input_test(int getchar) signal(SIGINT, INThandler); pool[NUMDEV].fd = set_watch(); pool[NUMDEV].events = POLLIN; + + unlink(CMD_FIFO); + mkfifo(CMD_FIFO, 0666); + + pool[NUMDEV+1].fd = open(CMD_FIFO, O_RDONLY | O_NONBLOCK); + pool[NUMDEV+1].events = POLLIN; state++; } @@ -2606,7 +2614,7 @@ int input_test(int getchar) if (state == 2) { - int return_value = poll(pool, NUMDEV + 1, (is_menu_core() && video_fb_state()) ? 500 : 0); + int return_value = poll(pool, NUMDEV + 2, (is_menu_core() && video_fb_state()) ? 500 : 0); if (return_value < 0) { printf("ERR: poll\n"); @@ -2963,6 +2971,18 @@ int input_test(int getchar) } } } + + if ((pool[NUMDEV + 1].fd >= 0) && (pool[NUMDEV + 1].revents & POLLIN)) + { + static char cmd[1024]; + int len = read(pool[NUMDEV + 1].fd, cmd, sizeof(cmd) - 1); + if (len) + { + cmd[len] = 0; + printf("MiSTer_cmd: %s\n", cmd); + if (!strncmp(cmd, "fb_cmd", 6)) video_cmd(cmd); + } + } } if (cur_leds != leds_state) diff --git a/menu.cpp b/menu.cpp index 1471f0a..fee2479 100644 --- a/menu.cpp +++ b/menu.cpp @@ -820,11 +820,10 @@ void HandleUI(void) case KEY_F1: if (is_menu_core()) { - unsigned long status = ((user_io_8bit_set_status(0, 0) >> 1) & 7) + 1; - status <<= 1; + unsigned long status = (user_io_8bit_set_status(0, 0)+ 2) & 0xE; user_io_8bit_set_status(status, 0xE); FileSaveConfig(user_io_create_config_name(), &status, 4); - video_menu_bg((status >> 1) & 7); + video_menu_bg(status >> 1); } break; diff --git a/video.cpp b/video.cpp index 187ffa9..0688c6c 100644 --- a/video.cpp +++ b/video.cpp @@ -7,6 +7,10 @@ #include #include #include +#include +#include +#include +#include #include "hardware.h" #include "user_io.h" @@ -633,6 +637,7 @@ void video_fb_enable(int enable, int n) } DisableIO(); + if (is_menu_core()) user_io_8bit_set_status((fb_enabled && !fb_num) ? 0x160 : 0, 0x1E0); } } @@ -1022,11 +1027,54 @@ int video_chvt(int num) int fd; if ((fd = open("/dev/tty0", O_RDONLY)) >= 0) { - if (ioctl(fd, VT_ACTIVATE, cur_vt)) printf("ioctl VT_ACTIVATE fails\n"); - if (ioctl(fd, VT_WAITACTIVE, cur_vt)) printf("ioctl VT_WAITACTIVE fails\n"); + if (ioctl(fd, VT_ACTIVATE, cur_vt)) printf("ioctl VT_ACTIVATE fails\n"); + if (ioctl(fd, VT_WAITACTIVE, cur_vt)) printf("ioctl VT_WAITACTIVE fails\n"); close(fd); } } return cur_vt ? cur_vt : 1; } + +void video_cmd(char *cmd) +{ + if (video_fb_state()) + { + int accept = 0; + if (!strncmp(cmd, "fb_cmd0 ", 8)) + { + int fmt, rb, div; + if (sscanf(cmd + 8, "%d %d %d", &fmt, &rb, &div) == 3) + { + if ((fmt == 1555 || fmt == 565 || fmt == 8888) && (rb == 0 || rb == 1) && (div == 1 || div == 2 || div == 4)) + { + int width = v_cur.item[1] / div; + int height = v_cur.item[5] / div; + int stride = ((width * ((fmt == 8888) ? 4 : 2)) + 255) & ~255; + + printf("fb_cmd: new mode: %dx%d color=%d stride=%d\n", width, height, fmt, stride); + + int sc_fmt = (fmt == 1555) ? 0 : (fmt == 565) ? 3 : 2; + + spi_uio_cmd_cont(UIO_SET_FBUF); + spi_w((sc_fmt << 1) | (rb << 3) | 1); // format, enable flag + spi_w((uint16_t)FB_ADDR); // base address low word + spi_w(FB_ADDR >> 16); // base address high word + spi_w(width); // frame width + spi_w(height); // frame height + spi_w(0); // scaled left + spi_w(v_cur.item[1] - 1); // scaled right + spi_w(0); // scaled top + spi_w(v_cur.item[5] - 1); // scaled bottom + DisableIO(); + + sprintf(cmd, "echo %d %d %d %d %d >/sys/module/MiSTer_fb/parameters/mode", fmt, rb, width, height, stride); + system(cmd); + accept = 1; + } + } + } + + if (!accept) printf("video_cmd: unknown command or format."); + } +} diff --git a/video.h b/video.h index b2257a5..6c6647d 100644 --- a/video.h +++ b/video.h @@ -15,5 +15,6 @@ void video_fb_enable(int enable, int n = 0); int video_fb_state(); void video_menu_bg(int n); int video_chvt(int num); +void video_cmd(char *cmd); #endif // VIDEO_H