diff --git a/menu.c b/menu.c index 412d7d6..74ffbbb 100644 --- a/menu.c +++ b/menu.c @@ -26,6 +26,7 @@ along with this program. If not, see . //#include "AT91SAM7S256.h" //#include "stdbool.h" #include +#include #include "stdio.h" #include "string.h" #include "errors.h" @@ -47,8 +48,8 @@ along with this program. If not, see . #include "archie.h" #include "usb/joymapping.h" -// test features -#define ALLOW_TEST_MENU 1 //remove to disable in prod version +// test features (not used right now) +// #define ALLOW_TEST_MENU 0 //remove to disable in prod version // other constants @@ -220,6 +221,28 @@ static void substrcpy(char *d, char *s, char idx) { #define HELPTEXT_DELAY 10000 #define FRAME_DELAY 150 +//assumes big endian +void siprintbinary(char* buffer, size_t const size, void const * const ptr) +{ + unsigned char *b = (unsigned char*) ptr; + unsigned char byte; + int i, j; + siprintf(buffer, "%*s", size-1, ""); + for (i=size-1;i>=0;i--) + { + for (j=0;j<8;j++) + { + byte = (b[i] >> j) & 1; + if(byte) + strcat(buffer, "1"); + else + strcat(buffer, "0"); + } + } + return; +} + + void HandleUI(void) { char *p; @@ -235,11 +258,11 @@ void HandleUI(void) /* check joystick status */ char joy_0 = 0; + uint16_t joy_usb=0; char joy_string[16]; char joy_string2[32]; - char joy_string3[16]; + char binary_string[9]="00000000"; - /* build USB id key */ unsigned int usb_vid = OsdUsbVidGet(); unsigned int usb_pid = OsdUsbPidGet(); @@ -590,6 +613,22 @@ void HandleUI(void) menumask = (menumask << 1) | 1; entry++; } + + // check for 'V'ersion strings + if(p && (p[0] == 'V')) { + + // p[1] is not used but kept for future use + char x = p[1]; + + // get version string + substrcpy(s, p, 2); + char l = strlen(s); + + s[0] = ' '; + substrcpy(s+1, p, 1); + OsdCoreNameSet(s); + } + i++; } while(p); @@ -766,7 +805,7 @@ void HandleUI(void) ScrollText(5," MiST by Till Harbaum, based on Minimig and other projects. MiST hardware and software is distributed under the terms of the GNU General Public License version 3. MiST FPGA cores are the work of their respective authors under individual licensing.",0,0,0); // menu key closes menu if (menu) - menustate = MENU_NONE1; + menustate = MENU_NONE1; if(select) { //iprintf("Selected", 0); @@ -805,17 +844,20 @@ void HandleUI(void) case MENU_8BIT_TEST2: memset(joy_string, '\0', sizeof(joy_string)); memset(joy_string2, '\0', sizeof(joy_string2)); - memset(joy_string3, '\0', sizeof(joy_string3)); joy_0 = OsdJoyGet(); strcat(joy_string, " "); strcat(joy_string2, " " ); - strcat(joy_string3, " " ); if(joy_0 & JOY_UP) strcat(joy_string, "\x12"); - if(joy_0 & JOY_DOWN) strcat(joy_string3, "\x13"); if(joy_0 & JOY_LEFT) - strcat(joy_string2, "< \x14 "); + if(joy_0 & JOY_DOWN) + strcat(joy_string2, "< \x13 "); + else + strcat(joy_string2, "< \x14 "); else - strcat(joy_string2, " \x14 "); + if (joy_0 & JOY_DOWN) + strcat(joy_string2, " \x13 "); + else + strcat(joy_string2, " \x14 "); if(joy_0 & JOY_RIGHT) strcat(joy_string2, "> "); //"\x16 "); else @@ -831,51 +873,51 @@ void HandleUI(void) if (joy_0!=0) { OsdWrite(3, joy_string, 0, 0); OsdWrite(4, joy_string2, 0, 0); - OsdWrite(5, joy_string3, 0, 0); + OsdWrite(5, " ", 0, 0); } else { OsdWrite(3, "", 0, 0); OsdWrite(4, JOY_NO_INPUT, 0, 0); OsdWrite(5, "", 0, 0); } - // Disallow to allow testing output - //if (menu) - // menustate = MENU_NONE1; + + // display raw USB input + joy_0 = OsdUsbJoyGet(); + siprintf(s, " USB: "); + siprintbinary(binary_string, sizeof(joy_0), &joy_0); + strcat(s, binary_string); + strcat(s, " "); + joy_0 = OsdUsbJoyGetExtra(); + siprintbinary(binary_string, sizeof(joy_0), &joy_0); + strcat(s, binary_string); + OsdWrite(6, s, 0,0); - /* - if(select) { - //iprintf("Selected", 0); - if (menusub==1) { - menustate = MENU_8BIT_SYSTEM1; - menusub = 0; - } - - }*/ - if(c==KEY_SPACE) { - menustate = MENU_8BIT_SYSTEM1; - menusub = 0; - } + // allow allow exit when hitting space + if(c==KEY_SPACE) { + menustate = MENU_8BIT_SYSTEM1; + menusub = 0; + } - //} - break; - + //} + break; + /******************************************************************/ /* mist main menu */ /******************************************************************/ case MENU_MIST_MAIN1 : - menumask=0xff; - OsdSetTitle("Mist", 0); + menumask=0xff; + OsdSetTitle("Mist", 0); - // most important: main page has setup for floppy A: and screen - strcpy(s, " A: "); - strcat(s, tos_get_disk_name(0)); - if(tos_system_ctrl() & TOS_CONTROL_FDC_WR_PROT_A) strcat(s, " \x17"); - OsdWrite(0, s, menusub == 0,0); + // most important: main page has setup for floppy A: and screen + strcpy(s, " A: "); + strcat(s, tos_get_disk_name(0)); + if(tos_system_ctrl() & TOS_CONTROL_FDC_WR_PROT_A) strcat(s, " \x17"); + OsdWrite(0, s, menusub == 0,0); - strcpy(s, " Screen: "); - if(tos_system_ctrl() & TOS_CONTROL_VIDEO_COLOR) strcat(s, "Color"); - else strcat(s, "Mono"); - OsdWrite(1, s, menusub == 1,0); + strcpy(s, " Screen: "); + if(tos_system_ctrl() & TOS_CONTROL_VIDEO_COLOR) strcat(s, "Color"); + else strcat(s, "Mono"); + OsdWrite(1, s, menusub == 1,0); /* everything else is in submenus */ OsdWrite(2, " Storage \x16", menusub == 2,0); diff --git a/menu.h b/menu.h index 586685e..26492e7 100644 --- a/menu.h +++ b/menu.h @@ -97,10 +97,10 @@ enum MENU MENU_8BIT_MAIN_IMAGE_SELECTED, MENU_8BIT_SYSTEM1, MENU_8BIT_SYSTEM2, - MENU_8BIT_ABOUT1, - MENU_8BIT_ABOUT2, - MENU_8BIT_TEST1, - MENU_8BIT_TEST2 + MENU_8BIT_ABOUT1, + MENU_8BIT_ABOUT2, + MENU_8BIT_TEST1, + MENU_8BIT_TEST2 }; // UI strings, used by boot messages diff --git a/osd.c b/osd.c index dde57f0..0e00876 100644 --- a/osd.c +++ b/osd.c @@ -726,16 +726,27 @@ unsigned char OsdKeyGet() { /* latest joystick state */ static unsigned char osd_joy; - void OsdJoySet(unsigned char c) { //iprintf("OSD joy: %x\n", c); osd_joy = c; } - unsigned char OsdJoyGet() { return osd_joy; } +static uint8_t raw_usb_joy; // four directions and 4 buttons +static uint8_t raw_usb_joy_extra; // eight extra buttons +void OsdUsbJoySet(uint8_t usbjoy, uint8_t usbextra) { + raw_usb_joy = usbjoy; + raw_usb_joy_extra = usbextra; +} +uint8_t OsdUsbJoyGet() { + return raw_usb_joy; +} +uint8_t OsdUsbJoyGetExtra() { + return raw_usb_joy_extra; +} + /* connected HID information */ static unsigned int usb_vid; static unsigned int usb_pid; diff --git a/osd.h b/osd.h index ed6f66f..50c6a2b 100644 --- a/osd.h +++ b/osd.h @@ -95,6 +95,8 @@ #define OSD_ARROW_LEFT 1 #define OSD_ARROW_RIGHT 2 +#include + /*functions*/ void OsdSetTitle(char *s,int arrow); // arrow > 0 = display right arrow in bottom right, < 0 = display left arrow void OsdWrite(unsigned char n, char *s, unsigned char inver, unsigned char stipple); @@ -133,6 +135,10 @@ unsigned char OsdKeyGet(); void OsdJoySet(unsigned char); unsigned char OsdJoyGet(); +void OsdUsbJoySet(uint8_t usbjoy, uint8_t usbextra); +uint8_t OsdUsbJoyGet(); +uint8_t OsdUsbJoyGetExtra(); + void OsdUsbIdSet(unsigned int vid, unsigned int pid); unsigned int OsdUsbVidGet(); unsigned int OsdUsbPidGet(); diff --git a/usb/hid.c b/usb/hid.c index 712cfe2..8ade1c3 100644 --- a/usb/hid.c +++ b/usb/hid.c @@ -734,10 +734,10 @@ static void usb_process_iface (usb_hid_iface_info_t *iface, jmap |= btn << JOY_BTN_SHIFT; // add buttons // report joystick 1 to OSD - if ( iface->jindex==0) + if ( iface->jindex==0) { OsdUsbIdSet( conf->joystick_mouse.vid, conf->joystick_mouse.pid ); - - + OsdUsbJoySet( jmap, btn_extra ); + } // map virtual joypad uint16_t vjoy = jmap; vjoy |= btn_extra << 8;