diff --git a/menu.c b/menu.c index c16cc74..560d07c 100644 --- a/menu.c +++ b/menu.c @@ -3543,6 +3543,12 @@ void InfoMessage(char *message) menustate = MENU_INFO; } +void InfoMessageEx(char *message, int timeout) +{ + InfoMessage(message); + menu_timer = GetTimer(timeout); +} + void EjectAllFloppies() { char i; diff --git a/menu.h b/menu.h index 211c4bc..2789869 100644 --- a/menu.h +++ b/menu.h @@ -19,6 +19,7 @@ void PrintDirectory(void); void ScrollLongName(void); void ErrorMessage(const char *message, unsigned char code); void InfoMessage(char *message); +void InfoMessageEx(char *message, int timeout); void ShowSplash(); void HideSplash(); void EjectAllFloppies(); diff --git a/user_io.c b/user_io.c index 34d231c..631398c 100644 --- a/user_io.c +++ b/user_io.c @@ -29,6 +29,9 @@ #define BREAK 0x8000 +uint8_t vol_att = 0; +unsigned long vol_set_timeout = 0; + fileTYPE sd_image[4] = { 0 }; // mouse and keyboard emulation state @@ -365,6 +368,9 @@ void user_io_init() MiSTer_ini_parse(); parse_video_mode(); + FileLoadConfig("Volume.dat", &vol_att, 1); + vol_att &= 0x1F; + spi_uio_cmd8(UIO_AUDVOL, vol_att); user_io_send_buttons(1); switch (core_type) @@ -1520,6 +1526,12 @@ void user_io_poll() { reboot(1); } + + if (vol_set_timeout && CheckTimer(vol_set_timeout)) + { + vol_set_timeout = 0; + FileSaveConfig("Volume.dat", &vol_att, 1); + } } char user_io_dip_switch1() @@ -1786,8 +1798,56 @@ static char key_used_by_osd(uint32_t s) return osd_is_visible; } +void set_volume() +{ + vol_set_timeout = GetTimer(1000); + + spi_uio_cmd8(UIO_AUDVOL, vol_att); + if (vol_att & 0x10) + { + InfoMessageEx("\n\n Audio muted", 1000); + } + else + { + char str[64]; + memset(str, 0, sizeof(str)); + + int vol = vol_att & 0xf; + sprintf(str, "\n\n Volume %ddb\n ", -3*vol); + if(vol<15) memset(str + strlen(str), 0x7f, 15-vol); + InfoMessageEx(str, 1000); + } +} + void user_io_kbd(uint16_t key, int press) { + if (key == KEY_MUTE) + { + if (press == 1 && !is_menu_core()) + { + vol_att ^= 0x10; + set_volume(); + } + } + else + if (key == KEY_VOLUMEDOWN) + { + if (press && !is_menu_core()) + { + if((vol_att & 0xF) < 15 && !(vol_att & 0x10)) vol_att += 1; + set_volume(); + } + } + else + if (key == KEY_VOLUMEUP) + { + if (press && !is_menu_core()) + { + if(vol_att & 0xF && !(vol_att & 0x10)) vol_att -= 1; + set_volume(); + } + } + else if ((core_type == CORE_TYPE_MINIMIG2) || (core_type == CORE_TYPE_MIST) || (core_type == CORE_TYPE_ARCHIE) || diff --git a/user_io.h b/user_io.h index db4e592..55bc28b 100644 --- a/user_io.h +++ b/user_io.h @@ -58,6 +58,7 @@ #define UIO_GET_VRES 0x23 // get video resolution #define UIO_TIMESTAMP 0x24 // transmit seconds since Unix epoch #define UIO_LEDS 0x25 // control on-board LEDs +#define UIO_AUDVOL 0x26 // Digital volume as a number of bits to shift to the right // codes as used by 8bit for file loading from OSD #define UIO_FILE_TX 0x53