diff options
Diffstat (limited to 'board/MAI/bios_emulator/scitech/src/pm/linux')
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/linux/event.c | 1319 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/linux/oshdr.h | 1 | ||||
-rw-r--r-- | board/MAI/bios_emulator/scitech/src/pm/linux/pm.c | 1117 |
3 files changed, 1217 insertions, 1220 deletions
diff --git a/board/MAI/bios_emulator/scitech/src/pm/linux/event.c b/board/MAI/bios_emulator/scitech/src/pm/linux/event.c index c2668ceb883..ce387320974 100644 --- a/board/MAI/bios_emulator/scitech/src/pm/linux/event.c +++ b/board/MAI/bios_emulator/scitech/src/pm/linux/event.c @@ -89,7 +89,7 @@ mouse_info mouse_infos[] = { {"BusMouse", STD_FLG, NULL, {0xf8, 0x80, 0x00, 0x00}, 3, 3}, {"MouseMan", CS7 | STD_FLG, _EVT_mouse_init, {0x40, 0x40, 0x40, 0x00}, 3, 1}, {"IntelliMouse", CS7 | STD_FLG, _EVT_pnpmouse_init, {0xc0, 0x40, 0xc0, 0x00}, 4, 1}, - {"IMPS2", CS7 | STD_FLG, NULL, {0xc0, 0x40, 0xc0, 0x00}, 4, 1}, // ? + {"IMPS2", CS7 | STD_FLG, NULL, {0xc0, 0x40, 0xc0, 0x00}, 4, 1}, /* ? */ }; #define NB_MICE (sizeof(mouse_infos)/sizeof(mouse_info)) @@ -109,7 +109,7 @@ typedef struct { int map; } keymap; -// TODO: Fix this and set it up so we can do a binary search! +/* TODO: Fix this and set it up so we can do a binary search! */ keymap keymaps[] = { {96, KB_padEnter}, @@ -249,131 +249,131 @@ static ibool readMouseData( /* Read the first byte to check for the protocol */ drv = &mouse_infos[mouse_driver]; if (read(_EVT_mouse_fd, data, drv->read) != drv->read) { - perror("read"); - return false; - } + perror("read"); + return false; + } if ((data[0] & drv->proto[0]) != drv->proto[1]) - return false; + return false; /* Load a whole protocol packet */ cnt += drv->read; while (cnt < drv->packet_len) { - ret = read(_EVT_mouse_fd, data+cnt, drv->read); - if (ret == drv->read) - cnt += ret; - else { - perror("read"); - return false; - } - } + ret = read(_EVT_mouse_fd, data+cnt, drv->read); + if (ret == drv->read) + cnt += ret; + else { + perror("read"); + return false; + } + } if ((data[1] & drv->proto[2]) != drv->proto[3]) - return false; + return false; /* Now decode the protocol packet */ switch (mouse_driver) { - case EVT_microsoft: - if (data[0] == 0x40 && !(prev|data[1]|data[2])) - *buttons = 2; /* Third button on MS compatible mouse */ - else - *buttons= ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); - prev = *buttons; - *dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); - *dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); - break; - case EVT_ps2: - *buttons = !!(data[0]&1) * 4 + !!(data[0]&2) * 1 + !!(data[0]&4) * 2; - if (data[1] != 0) - *dx = (data[0] & 0x10) ? data[1]-256 : data[1]; - else - *dx = 0; - if (data[2] != 0) - *dy = -((data[0] & 0x20) ? data[2]-256 : data[2]); - else - *dy = 0; - break; - case EVT_mousesystems: case EVT_gpm: - *buttons = (~data[0]) & 0x07; - *dx = (char)(data[1]) + (char)(data[3]); - *dy = -((char)(data[2]) + (char)(data[4])); - break; - case EVT_logitech: - *buttons= data[0] & 0x07; - *dx = (data[0] & 0x10) ? data[1] : - data[1]; - *dy = (data[0] & 0x08) ? - data[2] : data[2]; - break; - case EVT_busmouse: - *buttons= (~data[0]) & 0x07; - *dx = (char)data[1]; - *dy = -(char)data[2]; - break; - case EVT_MMseries: - *buttons = data[0] & 0x07; - *dx = (data[0] & 0x10) ? data[1] : - data[1]; - *dy = (data[0] & 0x08) ? - data[2] : data[2]; - break; - case EVT_intellimouse: - *buttons = ((data[0] & 0x20) >> 3) /* left */ - | ((data[3] & 0x10) >> 3) /* middle */ - | ((data[0] & 0x10) >> 4); /* right */ - *dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); - *dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); - break; - case EVT_intellimouse_ps2: - *buttons = (data[0] & 0x04) >> 1 /* Middle */ - | (data[0] & 0x02) >> 1 /* Right */ - | (data[0] & 0x01) << 2; /* Left */ - *dx = (data[0] & 0x10) ? data[1]-256 : data[1]; - *dy = (data[0] & 0x20) ? -(data[2]-256) : -data[2]; - break; - case EVT_mouseman: { - static int getextra; - static uchar prev=0; - uchar b; - - /* The damned MouseMan has 3/4 bytes packets. The extra byte - * is only there if the middle button is active. - * I get the extra byte as a packet with magic numbers in it. - * and then switch to 4-byte mode. - */ - if (data[1] == 0xAA && data[2] == 0x55) { - /* Got unexpected fourth byte */ - if ((b = (*data>>4)) > 0x3) - return false; /* just a sanity check */ - *dx = *dy = 0; - drv->packet_len=4; - getextra=0; - } - else { - /* Got 3/4, as expected */ - /* Motion is independent of packetlen... */ - *dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); - *dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); - prev = ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); - if (drv->packet_len==4) - b = data[3]>>4; - } - if (drv->packet_len == 4) { - if (b == 0) { - drv->packet_len = 3; - getextra = 1; - } - else { - if (b & 0x2) - prev |= 2; - } - } - *buttons = prev; - - /* This "chord-middle" behaviour was reported by David A. van Leeuwen */ - if (((prev ^ *buttons) & 5) == 5) - *buttons = *buttons ? 2 : 0; - prev = *buttons; - break; - } - case EVT_noMouse: - return false; - break; - } + case EVT_microsoft: + if (data[0] == 0x40 && !(prev|data[1]|data[2])) + *buttons = 2; /* Third button on MS compatible mouse */ + else + *buttons= ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); + prev = *buttons; + *dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); + *dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); + break; + case EVT_ps2: + *buttons = !!(data[0]&1) * 4 + !!(data[0]&2) * 1 + !!(data[0]&4) * 2; + if (data[1] != 0) + *dx = (data[0] & 0x10) ? data[1]-256 : data[1]; + else + *dx = 0; + if (data[2] != 0) + *dy = -((data[0] & 0x20) ? data[2]-256 : data[2]); + else + *dy = 0; + break; + case EVT_mousesystems: case EVT_gpm: + *buttons = (~data[0]) & 0x07; + *dx = (char)(data[1]) + (char)(data[3]); + *dy = -((char)(data[2]) + (char)(data[4])); + break; + case EVT_logitech: + *buttons= data[0] & 0x07; + *dx = (data[0] & 0x10) ? data[1] : - data[1]; + *dy = (data[0] & 0x08) ? - data[2] : data[2]; + break; + case EVT_busmouse: + *buttons= (~data[0]) & 0x07; + *dx = (char)data[1]; + *dy = -(char)data[2]; + break; + case EVT_MMseries: + *buttons = data[0] & 0x07; + *dx = (data[0] & 0x10) ? data[1] : - data[1]; + *dy = (data[0] & 0x08) ? - data[2] : data[2]; + break; + case EVT_intellimouse: + *buttons = ((data[0] & 0x20) >> 3) /* left */ + | ((data[3] & 0x10) >> 3) /* middle */ + | ((data[0] & 0x10) >> 4); /* right */ + *dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); + *dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); + break; + case EVT_intellimouse_ps2: + *buttons = (data[0] & 0x04) >> 1 /* Middle */ + | (data[0] & 0x02) >> 1 /* Right */ + | (data[0] & 0x01) << 2; /* Left */ + *dx = (data[0] & 0x10) ? data[1]-256 : data[1]; + *dy = (data[0] & 0x20) ? -(data[2]-256) : -data[2]; + break; + case EVT_mouseman: { + static int getextra; + static uchar prev=0; + uchar b; + + /* The damned MouseMan has 3/4 bytes packets. The extra byte + * is only there if the middle button is active. + * I get the extra byte as a packet with magic numbers in it. + * and then switch to 4-byte mode. + */ + if (data[1] == 0xAA && data[2] == 0x55) { + /* Got unexpected fourth byte */ + if ((b = (*data>>4)) > 0x3) + return false; /* just a sanity check */ + *dx = *dy = 0; + drv->packet_len=4; + getextra=0; + } + else { + /* Got 3/4, as expected */ + /* Motion is independent of packetlen... */ + *dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); + *dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); + prev = ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); + if (drv->packet_len==4) + b = data[3]>>4; + } + if (drv->packet_len == 4) { + if (b == 0) { + drv->packet_len = 3; + getextra = 1; + } + else { + if (b & 0x2) + prev |= 2; + } + } + *buttons = prev; + + /* This "chord-middle" behaviour was reported by David A. van Leeuwen */ + if (((prev ^ *buttons) & 5) == 5) + *buttons = *buttons ? 2 : 0; + prev = *buttons; + break; + } + case EVT_noMouse: + return false; + break; + } return true; } @@ -389,9 +389,9 @@ static int getKeyMapping( int i; for(i = 0; i < nb; i++) { - if (tab[i].scan == key) - return tab[i].map; - } + if (tab[i].scan == key) + return tab[i].map; + } return key; } @@ -411,21 +411,21 @@ static void makeJoyEvent( { evt->message = 0; if (buts0 && axis0) { - if (buts0[0]) evt->message |= EVT_JOY1_BUTTONA; - if (buts0[1]) evt->message |= EVT_JOY1_BUTTONB; - evt->where_x = axis0[0]; - evt->where_y = axis0[1]; - } + if (buts0[0]) evt->message |= EVT_JOY1_BUTTONA; + if (buts0[1]) evt->message |= EVT_JOY1_BUTTONB; + evt->where_x = axis0[0]; + evt->where_y = axis0[1]; + } else - evt->where_x = evt->where_y = 0; + evt->where_x = evt->where_y = 0; if (buts1 && axis1) { - if (buts1[0]) evt->message |= EVT_JOY2_BUTTONA; - if (buts1[1]) evt->message |= EVT_JOY2_BUTTONB; - evt->where_x = axis1[0]; - evt->where_y = axis1[1]; - } + if (buts1[0]) evt->message |= EVT_JOY2_BUTTONA; + if (buts1[1]) evt->message |= EVT_JOY2_BUTTONB; + evt->where_x = axis1[0]; + evt->where_y = axis1[1]; + } else - evt->where_x = evt->where_y = 0; + evt->where_x = evt->where_y = 0; } /**************************************************************************** @@ -439,39 +439,39 @@ int EVTAPI _EVT_readJoyAxis( int mask = 0; if ((js_version & ~0xffff) == 0) { - /* Old 0.x driver */ - struct JS_DATA_TYPE js; - if (joystick0_fd && read(joystick0_fd, &js, JS_RETURN) == JS_RETURN) { - if (jmask & EVT_JOY_AXIS_X1) - axis[0] = js.x; - if (jmask & EVT_JOY_AXIS_Y1) - axis[1] = js.y; - mask |= EVT_JOY_AXIS_X1|EVT_JOY_AXIS_Y1; - } - if (joystick1_fd && read(joystick1_fd, &js, JS_RETURN) == JS_RETURN) { - if (jmask & EVT_JOY_AXIS_X2) - axis[2] = js.x; - if (jmask & EVT_JOY_AXIS_Y2) - axis[3] = js.y; - mask |= EVT_JOY_AXIS_X2|EVT_JOY_AXIS_Y2; - } - } + /* Old 0.x driver */ + struct JS_DATA_TYPE js; + if (joystick0_fd && read(joystick0_fd, &js, JS_RETURN) == JS_RETURN) { + if (jmask & EVT_JOY_AXIS_X1) + axis[0] = js.x; + if (jmask & EVT_JOY_AXIS_Y1) + axis[1] = js.y; + mask |= EVT_JOY_AXIS_X1|EVT_JOY_AXIS_Y1; + } + if (joystick1_fd && read(joystick1_fd, &js, JS_RETURN) == JS_RETURN) { + if (jmask & EVT_JOY_AXIS_X2) + axis[2] = js.x; + if (jmask & EVT_JOY_AXIS_Y2) + axis[3] = js.y; + mask |= EVT_JOY_AXIS_X2|EVT_JOY_AXIS_Y2; + } + } else { - if (axis0) { - if (jmask & EVT_JOY_AXIS_X1) - axis[0] = axis0[0]; - if (jmask & EVT_JOY_AXIS_Y1) - axis[1] = axis0[1]; - mask |= EVT_JOY_AXIS_X1 | EVT_JOY_AXIS_Y1; - } - if (axis1) { - if (jmask & EVT_JOY_AXIS_X2) - axis[2] = axis1[0]; - if (jmask & EVT_JOY_AXIS_Y2) - axis[3] = axis1[1]; - mask |= EVT_JOY_AXIS_X2 | EVT_JOY_AXIS_Y2; - } - } + if (axis0) { + if (jmask & EVT_JOY_AXIS_X1) + axis[0] = axis0[0]; + if (jmask & EVT_JOY_AXIS_Y1) + axis[1] = axis0[1]; + mask |= EVT_JOY_AXIS_X1 | EVT_JOY_AXIS_Y1; + } + if (axis1) { + if (jmask & EVT_JOY_AXIS_X2) + axis[2] = axis1[0]; + if (jmask & EVT_JOY_AXIS_Y2) + axis[3] = axis1[1]; + mask |= EVT_JOY_AXIS_X2 | EVT_JOY_AXIS_Y2; + } + } return mask; } @@ -484,19 +484,19 @@ int EVTAPI _EVT_readJoyButtons(void) int buts = 0; if ((js_version & ~0xffff) == 0) { - /* Old 0.x driver */ - struct JS_DATA_TYPE js; - if (joystick0_fd && read(joystick0_fd, &js, JS_RETURN) == JS_RETURN) - buts = js.buttons; - if (joystick1_fd && read(joystick1_fd, &js, JS_RETURN) == JS_RETURN) - buts |= js.buttons << 2; - } + /* Old 0.x driver */ + struct JS_DATA_TYPE js; + if (joystick0_fd && read(joystick0_fd, &js, JS_RETURN) == JS_RETURN) + buts = js.buttons; + if (joystick1_fd && read(joystick1_fd, &js, JS_RETURN) == JS_RETURN) + buts |= js.buttons << 2; + } else { - if (buts0) - buts |= EVT_JOY1_BUTTONA*buts0[0] + EVT_JOY1_BUTTONB*buts0[1]; - if (buts1) - buts |= EVT_JOY2_BUTTONA*buts1[0] + EVT_JOY2_BUTTONB*buts1[1]; - } + if (buts0) + buts |= EVT_JOY1_BUTTONA*buts0[0] + EVT_JOY1_BUTTONB*buts0[1]; + if (buts1) + buts |= EVT_JOY2_BUTTONA*buts1[0] + EVT_JOY2_BUTTONB*buts1[1]; + } return buts; } @@ -525,97 +525,97 @@ int EVTAPI EVT_joyIsPresent(void) static ibool inited = false; if (inited) - return mask; + return mask; memset(EVT.joyMin,0,sizeof(EVT.joyMin)); memset(EVT.joyCenter,0,sizeof(EVT.joyCenter)); memset(EVT.joyMax,0,sizeof(EVT.joyMax)); memset(EVT.joyPrev,0,sizeof(EVT.joyPrev)); EVT.joyButState = 0; if ((tmp = getenv(ENV_JOYDEV0)) != NULL) - strcpy(joystick0_dev,tmp); + strcpy(joystick0_dev,tmp); if ((tmp = getenv(ENV_JOYDEV1)) != NULL) - strcpy(joystick1_dev,tmp); + strcpy(joystick1_dev,tmp); if ((joystick0_fd = open(joystick0_dev, O_RDONLY)) < 0) - joystick0_fd = 0; + joystick0_fd = 0; if ((joystick1_fd = open(joystick1_dev, O_RDONLY)) < 0) - joystick1_fd = 0; - if (!joystick0_fd && !joystick1_fd) // No joysticks detected - return 0; + joystick1_fd = 0; + if (!joystick0_fd && !joystick1_fd) /* No joysticks detected */ + return 0; inited = true; if (ioctl(joystick0_fd ? joystick0_fd : joystick1_fd, JSIOCGVERSION, &js_version) < 0) - return 0; + return 0; /* Initialise joystick 0 */ if (joystick0_fd) { - ioctl(joystick0_fd, JSIOCGNAME(sizeof(name0)), name0); - if (js_version & ~0xffff) { - struct js_event js; - - ioctl(joystick0_fd, JSIOCGAXES, &js0_axes); - ioctl(joystick0_fd, JSIOCGBUTTONS, &js0_buttons); - axis0 = PM_calloc((int)js0_axes, sizeof(short)); - buts0 = PM_malloc((int)js0_buttons); - /* Read the initial events */ - while(dataReady(joystick0_fd) - && read(joystick0_fd, &js, sizeof(struct js_event)) == sizeof(struct js_event) - && (js.type & JS_EVENT_INIT) - ) { - if (js.type & JS_EVENT_BUTTON) - buts0[js.number] = js.value; - else if (js.type & JS_EVENT_AXIS) - axis0[js.number] = scaleJoyAxis(js.value,js.number); - } - } - else { - js0_axes = 2; - js0_buttons = 2; - axis0 = PM_calloc((int)js0_axes, sizeof(short)); - buts0 = PM_malloc((int)js0_buttons); - } - } + ioctl(joystick0_fd, JSIOCGNAME(sizeof(name0)), name0); + if (js_version & ~0xffff) { + struct js_event js; + + ioctl(joystick0_fd, JSIOCGAXES, &js0_axes); + ioctl(joystick0_fd, JSIOCGBUTTONS, &js0_buttons); + axis0 = PM_calloc((int)js0_axes, sizeof(short)); + buts0 = PM_malloc((int)js0_buttons); + /* Read the initial events */ + while(dataReady(joystick0_fd) + && read(joystick0_fd, &js, sizeof(struct js_event)) == sizeof(struct js_event) + && (js.type & JS_EVENT_INIT) + ) { + if (js.type & JS_EVENT_BUTTON) + buts0[js.number] = js.value; + else if (js.type & JS_EVENT_AXIS) + axis0[js.number] = scaleJoyAxis(js.value,js.number); + } + } + else { + js0_axes = 2; + js0_buttons = 2; + axis0 = PM_calloc((int)js0_axes, sizeof(short)); + buts0 = PM_malloc((int)js0_buttons); + } + } /* Initialise joystick 1 */ if (joystick1_fd) { - ioctl(joystick1_fd, JSIOCGNAME(sizeof(name1)), name1); - if (js_version & ~0xffff) { - struct js_event js; - - ioctl(joystick1_fd, JSIOCGAXES, &js1_axes); - ioctl(joystick1_fd, JSIOCGBUTTONS, &js1_buttons); - axis1 = PM_calloc((int)js1_axes, sizeof(short)); - buts1 = PM_malloc((int)js1_buttons); - /* Read the initial events */ - while(dataReady(joystick1_fd) - && read(joystick1_fd, &js, sizeof(struct js_event))==sizeof(struct js_event) - && (js.type & JS_EVENT_INIT) - ) { - if (js.type & JS_EVENT_BUTTON) - buts1[js.number] = js.value; - else if (js.type & JS_EVENT_AXIS) - axis1[js.number] = scaleJoyAxis(js.value,js.number<<2); - } - } - else { - js1_axes = 2; - js1_buttons = 2; - axis1 = PM_calloc((int)js1_axes, sizeof(short)); - buts1 = PM_malloc((int)js1_buttons); - } - } + ioctl(joystick1_fd, JSIOCGNAME(sizeof(name1)), name1); + if (js_version & ~0xffff) { + struct js_event js; + + ioctl(joystick1_fd, JSIOCGAXES, &js1_axes); + ioctl(joystick1_fd, JSIOCGBUTTONS, &js1_buttons); + axis1 = PM_calloc((int)js1_axes, sizeof(short)); + buts1 = PM_malloc((int)js1_buttons); + /* Read the initial events */ + while(dataReady(joystick1_fd) + && read(joystick1_fd, &js, sizeof(struct js_event))==sizeof(struct js_event) + && (js.type & JS_EVENT_INIT) + ) { + if (js.type & JS_EVENT_BUTTON) + buts1[js.number] = js.value; + else if (js.type & JS_EVENT_AXIS) + axis1[js.number] = scaleJoyAxis(js.value,js.number<<2); + } + } + else { + js1_axes = 2; + js1_buttons = 2; + axis1 = PM_calloc((int)js1_axes, sizeof(short)); + buts1 = PM_malloc((int)js1_buttons); + } + } #ifdef CHECKED - fprintf(stderr,"Using joystick driver version %d.%d.%d\n", - js_version >> 16, (js_version >> 8) & 0xff, js_version & 0xff); + fprintf(stderr,"Using joystick driver version %d.%d.%d\n", + js_version >> 16, (js_version >> 8) & 0xff, js_version & 0xff); if (joystick0_fd) - fprintf(stderr,"Joystick 1 (%s): %s\n", joystick0_dev, name0); + fprintf(stderr,"Joystick 1 (%s): %s\n", joystick0_dev, name0); if (joystick1_fd) - fprintf(stderr,"Joystick 2 (%s): %s\n", joystick1_dev, name1); + fprintf(stderr,"Joystick 2 (%s): %s\n", joystick1_dev, name1); #endif mask = _EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyCenter); if (mask) { - for (i = 0; i < JOY_NUM_AXES; i++) - EVT.joyMax[i] = EVT.joyCenter[i]*2; - } + for (i = 0; i < JOY_NUM_AXES; i++) + EVT.joyMax[i] = EVT.joyCenter[i]*2; + } return mask; } @@ -634,9 +634,9 @@ All information polled from the joystick will be posted to the event queue for later retrieval. Note: Most analogue joysticks will provide readings that change even - though the joystick has not moved. Hence if you call this routine - you will likely get an EVT_JOYMOVE event every time through your - event loop. + though the joystick has not moved. Hence if you call this routine + you will likely get an EVT_JOYMOVE event every time through your + event loop. SEE ALSO: EVT_getNext, EVT_peekNext, EVT_joySetUpperLeft, EVT_joySetLowerRight, @@ -648,68 +648,68 @@ void EVTAPI EVT_pollJoystick(void) int i,axis[JOY_NUM_AXES],newButState,mask,moved,ps; if ((js_version & ~0xFFFF) == 0 && EVT.joyMask) { - /* Read joystick axes and post movement events if they have - * changed since the last time we polled. Until the events are - * actually flushed, we keep modifying the same joystick movement - * event, so you won't get multiple movement event - */ - mask = _EVT_readJoyAxis(EVT.joyMask,axis); - newButState = _EVT_readJoyButtons(); - moved = false; - for (i = 0; i < JOY_NUM_AXES; i++) { - if (mask & (EVT_JOY_AXIS_X1 << i)) - axis[i] = scaleJoyAxis(axis[i],i); - else - axis[i] = EVT.joyPrev[i]; - if (axis[i] != EVT.joyPrev[i]) - moved = true; - } - if (moved) { - memcpy(EVT.joyPrev,axis,sizeof(EVT.joyPrev)); - ps = _EVT_disableInt(); - if (EVT.oldJoyMove != -1) { - /* Modify the existing joystick movement event */ - EVT.evtq[EVT.oldJoyMove].message = newButState; - EVT.evtq[EVT.oldJoyMove].where_x = EVT.joyPrev[0]; - EVT.evtq[EVT.oldJoyMove].where_y = EVT.joyPrev[1]; - EVT.evtq[EVT.oldJoyMove].relative_x = EVT.joyPrev[2]; - EVT.evtq[EVT.oldJoyMove].relative_y = EVT.joyPrev[3]; - } - else if (EVT.count < EVENTQSIZE) { - /* Add a new joystick movement event */ - EVT.oldJoyMove = EVT.freeHead; - memset(&evt,0,sizeof(evt)); - evt.what = EVT_JOYMOVE; - evt.message = EVT.joyButState; - evt.where_x = EVT.joyPrev[0]; - evt.where_y = EVT.joyPrev[1]; - evt.relative_x = EVT.joyPrev[2]; - evt.relative_y = EVT.joyPrev[3]; - addEvent(&evt); - } - _EVT_restoreInt(ps); - } - - /* Read the joystick buttons, and post events to reflect the change - * in state for the joystick buttons. - */ - if (newButState != EVT.joyButState) { - if (EVT.count < EVENTQSIZE) { - /* Add a new joystick movement event */ - ps = _EVT_disableInt(); - memset(&evt,0,sizeof(evt)); - evt.what = EVT_JOYCLICK; - evt.message = newButState; - EVT.evtq[EVT.oldJoyMove].where_x = EVT.joyPrev[0]; - EVT.evtq[EVT.oldJoyMove].where_y = EVT.joyPrev[1]; - EVT.evtq[EVT.oldJoyMove].relative_x = EVT.joyPrev[2]; - EVT.evtq[EVT.oldJoyMove].relative_y = EVT.joyPrev[3]; - addEvent(&evt); - _EVT_restoreInt(ps); - } - EVT.joyButState = newButState; - } - } + /* Read joystick axes and post movement events if they have + * changed since the last time we polled. Until the events are + * actually flushed, we keep modifying the same joystick movement + * event, so you won't get multiple movement event + */ + mask = _EVT_readJoyAxis(EVT.joyMask,axis); + newButState = _EVT_readJoyButtons(); + moved = false; + for (i = 0; i < JOY_NUM_AXES; i++) { + if (mask & (EVT_JOY_AXIS_X1 << i)) + axis[i] = scaleJoyAxis(axis[i],i); + else + axis[i] = EVT.joyPrev[i]; + if (axis[i] != EVT.joyPrev[i]) + moved = true; + } + if (moved) { + memcpy(EVT.joyPrev,axis,sizeof(EVT.joyPrev)); + ps = _EVT_disableInt(); + if (EVT.oldJoyMove != -1) { + /* Modify the existing joystick movement event */ + EVT.evtq[EVT.oldJoyMove].message = newButState; + EVT.evtq[EVT.oldJoyMove].where_x = EVT.joyPrev[0]; + EVT.evtq[EVT.oldJoyMove].where_y = EVT.joyPrev[1]; + EVT.evtq[EVT.oldJoyMove].relative_x = EVT.joyPrev[2]; + EVT.evtq[EVT.oldJoyMove].relative_y = EVT.joyPrev[3]; + } + else if (EVT.count < EVENTQSIZE) { + /* Add a new joystick movement event */ + EVT.oldJoyMove = EVT.freeHead; + memset(&evt,0,sizeof(evt)); + evt.what = EVT_JOYMOVE; + evt.message = EVT.joyButState; + evt.where_x = EVT.joyPrev[0]; + evt.where_y = EVT.joyPrev[1]; + evt.relative_x = EVT.joyPrev[2]; + evt.relative_y = EVT.joyPrev[3]; + addEvent(&evt); + } + _EVT_restoreInt(ps); + } + + /* Read the joystick buttons, and post events to reflect the change + * in state for the joystick buttons. + */ + if (newButState != EVT.joyButState) { + if (EVT.count < EVENTQSIZE) { + /* Add a new joystick movement event */ + ps = _EVT_disableInt(); + memset(&evt,0,sizeof(evt)); + evt.what = EVT_JOYCLICK; + evt.message = newButState; + EVT.evtq[EVT.oldJoyMove].where_x = EVT.joyPrev[0]; + EVT.evtq[EVT.oldJoyMove].where_y = EVT.joyPrev[1]; + EVT.evtq[EVT.oldJoyMove].relative_x = EVT.joyPrev[2]; + EVT.evtq[EVT.oldJoyMove].relative_y = EVT.joyPrev[3]; + addEvent(&evt); + _EVT_restoreInt(ps); + } + EVT.joyButState = newButState; + } + } } /**************************************************************************** @@ -815,287 +815,287 @@ static void _EVT_pumpMessages(void) /* Poll keyboard events */ while (dataReady(_PM_console_fd) && (numkeys = read(_PM_console_fd, buf, KBDREADBUFFERSIZE)) > 0) { - for (i = 0; i < numkeys; i++) { - c = buf[i]; - release = c & 0x80; - c &= 0x7F; - - // TODO: This is wrong! We need this to be the time stamp at - // ** interrupt ** time!! One solution would be to - // put the keyboard and mouse polling loops into - // a separate thread that can block on I/O to the - // necessay file descriptor. - evt.when = _EVT_getTicks(); - - if (release) { - /* Key released */ - evt.what = EVT_KEYUP; - switch (c) { - case KB_leftShift: - _PM_modifiers &= ~EVT_LEFTSHIFT; - break; - case KB_rightShift: - _PM_modifiers &= ~EVT_RIGHTSHIFT; - break; - case 29: - _PM_modifiers &= ~(EVT_LEFTCTRL|EVT_CTRLSTATE); - break; - case 97: /* Control */ - _PM_modifiers &= ~EVT_CTRLSTATE; - break; - case 56: - _PM_modifiers &= ~(EVT_LEFTALT|EVT_ALTSTATE); - break; - case 100: - _PM_modifiers &= ~EVT_ALTSTATE; - break; - default: - } - evt.modifiers = _PM_modifiers; - evt.message = keyUpMsg[c]; - if (EVT.count < EVENTQSIZE) - addEvent(&evt); - keyUpMsg[c] = 0; - repeatKey[c] = 0; - } - else { - /* Key pressed */ - evt.what = EVT_KEYDOWN; - switch (c) { - case KB_leftShift: - _PM_modifiers |= EVT_LEFTSHIFT; - break; - case KB_rightShift: - _PM_modifiers |= EVT_RIGHTSHIFT; - break; - case 29: - _PM_modifiers |= EVT_LEFTCTRL|EVT_CTRLSTATE; - break; - case 97: /* Control */ - _PM_modifiers |= EVT_CTRLSTATE; - break; - case 56: - _PM_modifiers |= EVT_LEFTALT|EVT_ALTSTATE; - break; - case 100: - _PM_modifiers |= EVT_ALTSTATE; - break; - case KB_capsLock: /* Caps Lock */ - _PM_leds ^= LED_CAP; - ioctl(_PM_console_fd, KDSETLED, _PM_leds); - break; - case KB_numLock: /* Num Lock */ - _PM_leds ^= LED_NUM; - ioctl(_PM_console_fd, KDSETLED, _PM_leds); - break; - case KB_scrollLock: /* Scroll Lock */ - _PM_leds ^= LED_SCR; - ioctl(_PM_console_fd, KDSETLED, _PM_leds); - break; - default: - } - evt.modifiers = _PM_modifiers; - if (keyUpMsg[c]) { - evt.what = EVT_KEYREPEAT; - evt.message = keyUpMsg[c] | (repeatKey[c]++ << 16); - } - else { - int asc; - - evt.message = getKeyMapping(keymaps, NB_KEYMAPS, c) << 8; - ke.kb_index = c; - ke.kb_table = 0; - if ((_PM_modifiers & EVT_SHIFTKEY) || (_PM_leds & LED_CAP)) - ke.kb_table |= K_SHIFTTAB; - if (_PM_modifiers & (EVT_LEFTALT | EVT_ALTSTATE)) - ke.kb_table |= K_ALTTAB; - if (ioctl(_PM_console_fd, KDGKBENT, (unsigned long)&ke)<0) - perror("ioctl(KDGKBENT)"); - if ((_PM_leds & LED_NUM) && (getKeyMapping(keypad, NB_KEYPAD, c)!=c)) { - asc = getKeyMapping(keypad, NB_KEYPAD, c); - } - else { - switch (c) { - case 14: - asc = ASCII_backspace; - break; - case 15: - asc = ASCII_tab; - break; - case 28: - case 96: - asc = ASCII_enter; - break; - case 1: - asc = ASCII_esc; - default: - asc = ke.kb_value & 0xFF; - if (asc < 0x1B) - asc = 0; - break; - } - } - if ((_PM_modifiers & (EVT_CTRLSTATE|EVT_LEFTCTRL)) && isalpha(asc)) - evt.message |= toupper(asc) - 'A' + 1; - else - evt.message |= asc; - keyUpMsg[c] = evt.message; - repeatKey[c]++; - } - if (EVT.count < EVENTQSIZE) - addEvent(&evt); - } - } - } + for (i = 0; i < numkeys; i++) { + c = buf[i]; + release = c & 0x80; + c &= 0x7F; + + /* TODO: This is wrong! We need this to be the time stamp at */ + /* ** interrupt ** time!! One solution would be to */ + /* put the keyboard and mouse polling loops into */ + /* a separate thread that can block on I/O to the */ + /* necessay file descriptor. */ + evt.when = _EVT_getTicks(); + + if (release) { + /* Key released */ + evt.what = EVT_KEYUP; + switch (c) { + case KB_leftShift: + _PM_modifiers &= ~EVT_LEFTSHIFT; + break; + case KB_rightShift: + _PM_modifiers &= ~EVT_RIGHTSHIFT; + break; + case 29: + _PM_modifiers &= ~(EVT_LEFTCTRL|EVT_CTRLSTATE); + break; + case 97: /* Control */ + _PM_modifiers &= ~EVT_CTRLSTATE; + break; + case 56: + _PM_modifiers &= ~(EVT_LEFTALT|EVT_ALTSTATE); + break; + case 100: + _PM_modifiers &= ~EVT_ALTSTATE; + break; + default: + } + evt.modifiers = _PM_modifiers; + evt.message = keyUpMsg[c]; + if (EVT.count < EVENTQSIZE) + addEvent(&evt); + keyUpMsg[c] = 0; + repeatKey[c] = 0; + } + else { + /* Key pressed */ + evt.what = EVT_KEYDOWN; + switch (c) { + case KB_leftShift: + _PM_modifiers |= EVT_LEFTSHIFT; + break; + case KB_rightShift: + _PM_modifiers |= EVT_RIGHTSHIFT; + break; + case 29: + _PM_modifiers |= EVT_LEFTCTRL|EVT_CTRLSTATE; + break; + case 97: /* Control */ + _PM_modifiers |= EVT_CTRLSTATE; + break; + case 56: + _PM_modifiers |= EVT_LEFTALT|EVT_ALTSTATE; + break; + case 100: + _PM_modifiers |= EVT_ALTSTATE; + break; + case KB_capsLock: /* Caps Lock */ + _PM_leds ^= LED_CAP; + ioctl(_PM_console_fd, KDSETLED, _PM_leds); + break; + case KB_numLock: /* Num Lock */ + _PM_leds ^= LED_NUM; + ioctl(_PM_console_fd, KDSETLED, _PM_leds); + break; + case KB_scrollLock: /* Scroll Lock */ + _PM_leds ^= LED_SCR; + ioctl(_PM_console_fd, KDSETLED, _PM_leds); + break; + default: + } + evt.modifiers = _PM_modifiers; + if (keyUpMsg[c]) { + evt.what = EVT_KEYREPEAT; + evt.message = keyUpMsg[c] | (repeatKey[c]++ << 16); + } + else { + int asc; + + evt.message = getKeyMapping(keymaps, NB_KEYMAPS, c) << 8; + ke.kb_index = c; + ke.kb_table = 0; + if ((_PM_modifiers & EVT_SHIFTKEY) || (_PM_leds & LED_CAP)) + ke.kb_table |= K_SHIFTTAB; + if (_PM_modifiers & (EVT_LEFTALT | EVT_ALTSTATE)) + ke.kb_table |= K_ALTTAB; + if (ioctl(_PM_console_fd, KDGKBENT, (unsigned long)&ke)<0) + perror("ioctl(KDGKBENT)"); + if ((_PM_leds & LED_NUM) && (getKeyMapping(keypad, NB_KEYPAD, c)!=c)) { + asc = getKeyMapping(keypad, NB_KEYPAD, c); + } + else { + switch (c) { + case 14: + asc = ASCII_backspace; + break; + case 15: + asc = ASCII_tab; + break; + case 28: + case 96: + asc = ASCII_enter; + break; + case 1: + asc = ASCII_esc; + default: + asc = ke.kb_value & 0xFF; + if (asc < 0x1B) + asc = 0; + break; + } + } + if ((_PM_modifiers & (EVT_CTRLSTATE|EVT_LEFTCTRL)) && isalpha(asc)) + evt.message |= toupper(asc) - 'A' + 1; + else + evt.message |= asc; + keyUpMsg[c] = evt.message; + repeatKey[c]++; + } + if (EVT.count < EVENTQSIZE) + addEvent(&evt); + } + } + } /* Poll mouse events */ if (_EVT_mouse_fd) { - int dx, dy, buts; - static int oldbuts; - - while (dataReady(_EVT_mouse_fd)) { - if (readMouseData(&buts, &dx, &dy)) { - EVT.mx += dx; - EVT.my += dy; - if (EVT.mx < 0) EVT.mx = 0; - if (EVT.my < 0) EVT.my = 0; - if (EVT.mx > range_x) EVT.mx = range_x; - if (EVT.my > range_y) EVT.my = range_y; - evt.where_x = EVT.mx; - evt.where_y = EVT.my; - evt.relative_x = dx; - evt.relative_y = dy; - - // TODO: This is wrong! We need this to be the time stamp at - // ** interrupt ** time!! One solution would be to - // put the keyboard and mouse polling loops into - // a separate thread that can block on I/O to the - // necessay file descriptor. - evt.when = _EVT_getTicks(); - evt.modifiers = _PM_modifiers; - if (buts & 4) - evt.modifiers |= EVT_LEFTBUT; - if (buts & 1) - evt.modifiers |= EVT_RIGHTBUT; - if (buts & 2) - evt.modifiers |= EVT_MIDDLEBUT; - - /* Left click events */ - if ((buts&4) != (oldbuts&4)) { - if (buts&4) - evt.what = EVT_MOUSEDOWN; - else - evt.what = EVT_MOUSEUP; - evt.message = EVT_LEFTBMASK; - EVT.oldMove = -1; - if (EVT.count < EVENTQSIZE) - addEvent(&evt); - } - - /* Right click events */ - if ((buts&1) != (oldbuts&1)) { - if (buts&1) - evt.what = EVT_MOUSEDOWN; - else - evt.what = EVT_MOUSEUP; - evt.message = EVT_RIGHTBMASK; - EVT.oldMove = -1; - if (EVT.count < EVENTQSIZE) - addEvent(&evt); - } - - /* Middle click events */ - if ((buts&2) != (oldbuts&2)) { - if (buts&2) - evt.what = EVT_MOUSEDOWN; - else - evt.what = EVT_MOUSEUP; - evt.message = EVT_MIDDLEBMASK; - EVT.oldMove = -1; - if (EVT.count < EVENTQSIZE) - addEvent(&evt); - } - - /* Mouse movement event */ - if (dx || dy) { - evt.what = EVT_MOUSEMOVE; - evt.message = 0; - if (EVT.oldMove != -1) { - /* Modify existing movement event */ - EVT.evtq[EVT.oldMove].where_x = evt.where_x; - EVT.evtq[EVT.oldMove].where_y = evt.where_y; - } - else { - /* Save id of this movement event */ - EVT.oldMove = EVT.freeHead; - if (EVT.count < EVENTQSIZE) - addEvent(&evt); - } - } - oldbuts = buts; - } - } - } + int dx, dy, buts; + static int oldbuts; + + while (dataReady(_EVT_mouse_fd)) { + if (readMouseData(&buts, &dx, &dy)) { + EVT.mx += dx; + EVT.my += dy; + if (EVT.mx < 0) EVT.mx = 0; + if (EVT.my < 0) EVT.my = 0; + if (EVT.mx > range_x) EVT.mx = range_x; + if (EVT.my > range_y) EVT.my = range_y; + evt.where_x = EVT.mx; + evt.where_y = EVT.my; + evt.relative_x = dx; + evt.relative_y = dy; + + /* TODO: This is wrong! We need this to be the time stamp at */ + /* ** interrupt ** time!! One solution would be to */ + /* put the keyboard and mouse polling loops into */ + /* a separate thread that can block on I/O to the */ + /* necessay file descriptor. */ + evt.when = _EVT_getTicks(); + evt.modifiers = _PM_modifiers; + if (buts & 4) + evt.modifiers |= EVT_LEFTBUT; + if (buts & 1) + evt.modifiers |= EVT_RIGHTBUT; + if (buts & 2) + evt.modifiers |= EVT_MIDDLEBUT; + + /* Left click events */ + if ((buts&4) != (oldbuts&4)) { + if (buts&4) + evt.what = EVT_MOUSEDOWN; + else + evt.what = EVT_MOUSEUP; + evt.message = EVT_LEFTBMASK; + EVT.oldMove = -1; + if (EVT.count < EVENTQSIZE) + addEvent(&evt); + } + + /* Right click events */ + if ((buts&1) != (oldbuts&1)) { + if (buts&1) + evt.what = EVT_MOUSEDOWN; + else + evt.what = EVT_MOUSEUP; + evt.message = EVT_RIGHTBMASK; + EVT.oldMove = -1; + if (EVT.count < EVENTQSIZE) + addEvent(&evt); + } + + /* Middle click events */ + if ((buts&2) != (oldbuts&2)) { + if (buts&2) + evt.what = EVT_MOUSEDOWN; + else + evt.what = EVT_MOUSEUP; + evt.message = EVT_MIDDLEBMASK; + EVT.oldMove = -1; + if (EVT.count < EVENTQSIZE) + addEvent(&evt); + } + + /* Mouse movement event */ + if (dx || dy) { + evt.what = EVT_MOUSEMOVE; + evt.message = 0; + if (EVT.oldMove != -1) { + /* Modify existing movement event */ + EVT.evtq[EVT.oldMove].where_x = evt.where_x; + EVT.evtq[EVT.oldMove].where_y = evt.where_y; + } + else { + /* Save id of this movement event */ + EVT.oldMove = EVT.freeHead; + if (EVT.count < EVENTQSIZE) + addEvent(&evt); + } + } + oldbuts = buts; + } + } + } #ifdef USE_OS_JOYSTICK - // Poll joystick events using the 1.x joystick driver API in the 2.2 kernels + /* Poll joystick events using the 1.x joystick driver API in the 2.2 kernels */ if (js_version & ~0xffff) { - static struct js_event js; - - /* Read joystick axis 0 */ - evt.when = 0; - evt.modifiers = _PM_modifiers; - if (joystick0_fd && dataReady(joystick0_fd) && - read(joystick0_fd, &js, sizeof(js)) == sizeof(js)) { - if (js.type & JS_EVENT_BUTTON) { - if (js.number < 2) { /* Only 2 buttons for now :( */ - buts0[js.number] = js.value; - evt.what = EVT_JOYCLICK; - makeJoyEvent(&evt); - if (EVT.count < EVENTQSIZE) - addEvent(&evt); - } - } - else if (js.type & JS_EVENT_AXIS) { - axis0[js.number] = scaleJoyAxis(js.value,js.number); - evt.what = EVT_JOYMOVE; - if (EVT.oldJoyMove != -1) { - makeJoyEvent(&EVT.evtq[EVT.oldJoyMove]); - } - else if (EVT.count < EVENTQSIZE) { - EVT.oldJoyMove = EVT.freeHead; - makeJoyEvent(&evt); - addEvent(&evt); - } - } - } - - /* Read joystick axis 1 */ - if (joystick1_fd && dataReady(joystick1_fd) && - read(joystick1_fd, &js, sizeof(js))==sizeof(js)) { - if (js.type & JS_EVENT_BUTTON) { - if (js.number < 2) { /* Only 2 buttons for now :( */ - buts1[js.number] = js.value; - evt.what = EVT_JOYCLICK; - makeJoyEvent(&evt); - if (EVT.count < EVENTQSIZE) - addEvent(&evt); - } - } - else if (js.type & JS_EVENT_AXIS) { - axis1[js.number] = scaleJoyAxis(js.value,js.number<<2); - evt.what = EVT_JOYMOVE; - if (EVT.oldJoyMove != -1) { - makeJoyEvent(&EVT.evtq[EVT.oldJoyMove]); - } - else if (EVT.count < EVENTQSIZE) { - EVT.oldJoyMove = EVT.freeHead; - makeJoyEvent(&evt); - addEvent(&evt); - } - } - } - } + static struct js_event js; + + /* Read joystick axis 0 */ + evt.when = 0; + evt.modifiers = _PM_modifiers; + if (joystick0_fd && dataReady(joystick0_fd) && + read(joystick0_fd, &js, sizeof(js)) == sizeof(js)) { + if (js.type & JS_EVENT_BUTTON) { + if (js.number < 2) { /* Only 2 buttons for now :( */ + buts0[js.number] = js.value; + evt.what = EVT_JOYCLICK; + makeJoyEvent(&evt); + if (EVT.count < EVENTQSIZE) + addEvent(&evt); + } + } + else if (js.type & JS_EVENT_AXIS) { + axis0[js.number] = scaleJoyAxis(js.value,js.number); + evt.what = EVT_JOYMOVE; + if (EVT.oldJoyMove != -1) { + makeJoyEvent(&EVT.evtq[EVT.oldJoyMove]); + } + else if (EVT.count < EVENTQSIZE) { + EVT.oldJoyMove = EVT.freeHead; + makeJoyEvent(&evt); + addEvent(&evt); + } + } + } + + /* Read joystick axis 1 */ + if (joystick1_fd && dataReady(joystick1_fd) && + read(joystick1_fd, &js, sizeof(js))==sizeof(js)) { + if (js.type & JS_EVENT_BUTTON) { + if (js.number < 2) { /* Only 2 buttons for now :( */ + buts1[js.number] = js.value; + evt.what = EVT_JOYCLICK; + makeJoyEvent(&evt); + if (EVT.count < EVENTQSIZE) + addEvent(&evt); + } + } + else if (js.type & JS_EVENT_AXIS) { + axis1[js.number] = scaleJoyAxis(js.value,js.number<<2); + evt.what = EVT_JOYMOVE; + if (EVT.oldJoyMove != -1) { + makeJoyEvent(&EVT.evtq[EVT.oldJoyMove]); + } + else if (EVT.count < EVENTQSIZE) { + EVT.oldJoyMove = EVT.freeHead; + makeJoyEvent(&evt); + addEvent(&evt); + } + } + } + } #endif } @@ -1122,7 +1122,7 @@ static int setspeed( { struct termios tty; char *c; - + tcgetattr(fd, &tty); tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; @@ -1131,20 +1131,20 @@ static int setspeed( tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; switch (old) { - case 9600: tty.c_cflag = flags | B9600; break; - case 4800: tty.c_cflag = flags | B4800; break; - case 2400: tty.c_cflag = flags | B2400; break; - case 1200: - default: tty.c_cflag = flags | B1200; break; - } + case 9600: tty.c_cflag = flags | B9600; break; + case 4800: tty.c_cflag = flags | B4800; break; + case 2400: tty.c_cflag = flags | B2400; break; + case 1200: + default: tty.c_cflag = flags | B1200; break; + } tcsetattr(fd, TCSAFLUSH, &tty); switch (new) { - case 9600: c = "*q"; tty.c_cflag = flags | B9600; break; - case 4800: c = "*p"; tty.c_cflag = flags | B4800; break; - case 2400: c = "*o"; tty.c_cflag = flags | B2400; break; - case 1200: - default: c = "*n"; tty.c_cflag = flags | B1200; break; - } + case 9600: c = "*q"; tty.c_cflag = flags | B9600; break; + case 4800: c = "*p"; tty.c_cflag = flags | B4800; break; + case 2400: c = "*o"; tty.c_cflag = flags | B2400; break; + case 1200: + default: c = "*n"; tty.c_cflag = flags | B1200; break; + } write(fd, c, 2); usleep(100000); tcsetattr(fd, TCSAFLUSH, &tty); @@ -1161,7 +1161,7 @@ static void _EVT_mouse_init(void) /* Change from any available speed to the chosen one */ for (i = 9600; i >= 1200; i /= 2) - setspeed(_EVT_mouse_fd, i, opt_baud, mouse_infos[mouse_driver].flags); + setspeed(_EVT_mouse_fd, i, opt_baud, mouse_infos[mouse_driver].flags); } /**************************************************************************** @@ -1173,29 +1173,29 @@ static void _EVT_logitech_init(void) int i; struct stat buf; int busmouse; - + /* is this a serial- or a bus- mouse? */ if (fstat(_EVT_mouse_fd,&buf) == -1) - perror("fstat"); + perror("fstat"); i = MAJOR(buf.st_rdev); if (stat("/dev/ttyS0",&buf) == -1) - perror("stat"); + perror("stat"); busmouse=(i != MAJOR(buf.st_rdev)); - + /* Fix the howmany field, so that serial mice have 1, while busmice have 3 */ mouse_infos[mouse_driver].read = busmouse ? 3 : 1; - + /* Change from any available speed to the chosen one */ for (i = 9600; i >= 1200; i /= 2) - setspeed(_EVT_mouse_fd, i, opt_baud, mouse_infos[mouse_driver].flags); - + setspeed(_EVT_mouse_fd, i, opt_baud, mouse_infos[mouse_driver].flags); + /* This stuff is peculiar of logitech mice, also for the serial ones */ write(_EVT_mouse_fd, "S", 1); setspeed(_EVT_mouse_fd, opt_baud, opt_baud,CS8 |PARENB |PARODD |CREAD |CLOCAL |HUPCL); - + /* Configure the sample rate */ for (i = 0; opt_sample <= sampletab[i].sample; i++) - ; + ; write(_EVT_mouse_fd,sampletab[i].code,1); } @@ -1206,7 +1206,7 @@ Microsoft Intellimouse init code static void _EVT_pnpmouse_init(void) { struct termios tty; - + tcgetattr(_EVT_mouse_fd, &tty); tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; @@ -1240,53 +1240,53 @@ void EVTAPI EVT_init( EVT.mouseMove = mouseMove; initEventQueue(); for (i = 0; i < 256; i++) - keyUpMsg[i] = 0; + keyUpMsg[i] = 0; /* Keyboard initialization */ if (_PM_console_fd == -1) - PM_fatalError("You must first call PM_openConsole to use the EVT functions!"); + PM_fatalError("You must first call PM_openConsole to use the EVT functions!"); _PM_keyboard_rawmode(); fcntl(_PM_console_fd,F_SETFL,fcntl(_PM_console_fd,F_GETFL) | O_NONBLOCK); /* Mouse initialization */ if ((tmp = getenv(ENV_MOUSEDRV)) != NULL) { - for (i = 0; i < NB_MICE; i++) { - if (!strcasecmp(tmp, mouse_infos[i].name)) { - mouse_driver = i; - break; - } - } - if (i == NB_MICE) { - fprintf(stderr,"Unknown mouse driver: %s\n", tmp); - mouse_driver = EVT_noMouse; - _EVT_mouse_fd = 0; - } - } + for (i = 0; i < NB_MICE; i++) { + if (!strcasecmp(tmp, mouse_infos[i].name)) { + mouse_driver = i; + break; + } + } + if (i == NB_MICE) { + fprintf(stderr,"Unknown mouse driver: %s\n", tmp); + mouse_driver = EVT_noMouse; + _EVT_mouse_fd = 0; + } + } if (mouse_driver != EVT_noMouse) { - if (mouse_driver == EVT_gpm) - strcpy(mouse_dev,"/dev/gpmdata"); - if ((tmp = getenv(ENV_MOUSEDEV)) != NULL) - strcpy(mouse_dev,tmp); + if (mouse_driver == EVT_gpm) + strcpy(mouse_dev,"/dev/gpmdata"); + if ((tmp = getenv(ENV_MOUSEDEV)) != NULL) + strcpy(mouse_dev,tmp); #ifdef CHECKED - fprintf(stderr,"Using the %s MGL mouse driver on %s.\n", mouse_infos[mouse_driver].name, mouse_dev); + fprintf(stderr,"Using the %s MGL mouse driver on %s.\n", mouse_infos[mouse_driver].name, mouse_dev); #endif - if ((_EVT_mouse_fd = open(mouse_dev, O_RDWR)) < 0) { - perror("open"); - fprintf(stderr, "Unable to open mouse device %s, dropping mouse support.\n", mouse_dev); - sleep(1); - mouse_driver = EVT_noMouse; - _EVT_mouse_fd = 0; - } - else { - char c; - - /* Init and flush the mouse pending input queue */ - if (mouse_infos[mouse_driver].init) - mouse_infos[mouse_driver].init(); - while(dataReady(_EVT_mouse_fd) && read(_EVT_mouse_fd, &c, 1) == 1) - ; - } - } + if ((_EVT_mouse_fd = open(mouse_dev, O_RDWR)) < 0) { + perror("open"); + fprintf(stderr, "Unable to open mouse device %s, dropping mouse support.\n", mouse_dev); + sleep(1); + mouse_driver = EVT_noMouse; + _EVT_mouse_fd = 0; + } + else { + char c; + + /* Init and flush the mouse pending input queue */ + if (mouse_infos[mouse_driver].init) + mouse_infos[mouse_driver].init(); + while(dataReady(_EVT_mouse_fd) && read(_EVT_mouse_fd, &c, 1) == 1) + ; + } + } } /**************************************************************************** @@ -1318,7 +1318,7 @@ and this function can be used to resume it again later. ****************************************************************************/ void EVT_resume(void) { - // Do nothing for Linux + /* Do nothing for Linux */ } /**************************************************************************** @@ -1328,7 +1328,7 @@ de-install the event handling code. ****************************************************************************/ void EVT_suspend(void) { - // Do nothing for Linux + /* Do nothing for Linux */ } /**************************************************************************** @@ -1340,22 +1340,21 @@ void EVT_exit(void) /* Restore signal handlers */ _PM_restore_kb_mode(); if (_EVT_mouse_fd) { - close(_EVT_mouse_fd); - _EVT_mouse_fd = 0; - } + close(_EVT_mouse_fd); + _EVT_mouse_fd = 0; + } #ifdef USE_OS_JOYSTICK if (joystick0_fd) { - close(joystick0_fd); - free(axis0); - free(buts0); - joystick0_fd = 0; - } + close(joystick0_fd); + free(axis0); + free(buts0); + joystick0_fd = 0; + } if (joystick1_fd) { - close(joystick1_fd); - free(axis1); - free(buts1); - joystick1_fd = 0; - } + close(joystick1_fd); + free(axis1); + free(buts1); + joystick1_fd = 0; + } #endif } - diff --git a/board/MAI/bios_emulator/scitech/src/pm/linux/oshdr.h b/board/MAI/bios_emulator/scitech/src/pm/linux/oshdr.h index 6023dff1098..eadedfb1372 100644 --- a/board/MAI/bios_emulator/scitech/src/pm/linux/oshdr.h +++ b/board/MAI/bios_emulator/scitech/src/pm/linux/oshdr.h @@ -58,4 +58,3 @@ void _PM_keyboard_rawmode(void); /* Linux needs the generic joystick scaling code */ #define NEED_SCALE_JOY_AXIS - diff --git a/board/MAI/bios_emulator/scitech/src/pm/linux/pm.c b/board/MAI/bios_emulator/scitech/src/pm/linux/pm.c index 1d52984a6a6..c12a83500af 100644 --- a/board/MAI/bios_emulator/scitech/src/pm/linux/pm.c +++ b/board/MAI/bios_emulator/scitech/src/pm/linux/pm.c @@ -148,7 +148,7 @@ static inline void port_out(int value, int port) printk("%04X:%04X: outb.%04X <- %02X\n", traceAddr >> 16, traceAddr & 0xFFFF, (ushort)port, (uchar)value); #endif asm volatile ("outb %0,%1" - ::"a" ((unsigned char) value), "d"((unsigned short) port)); + ::"a" ((unsigned char) value), "d"((unsigned short) port)); } static inline void port_outw(int value, int port) @@ -157,7 +157,7 @@ static inline void port_outw(int value, int port) printk("%04X:%04X: outw.%04X <- %04X\n", traceAddr >> 16,traceAddr & 0xFFFF, (ushort)port, (ushort)value); #endif asm volatile ("outw %0,%1" - ::"a" ((unsigned short) value), "d"((unsigned short) port)); + ::"a" ((unsigned short) value), "d"((unsigned short) port)); } static inline void port_outl(int value, int port) @@ -166,15 +166,15 @@ static inline void port_outl(int value, int port) printk("%04X:%04X: outl.%04X <- %08X\n", traceAddr >> 16,traceAddr & 0xFFFF, (ushort)port, (ulong)value); #endif asm volatile ("outl %0,%1" - ::"a" ((unsigned long) value), "d"((unsigned short) port)); + ::"a" ((unsigned long) value), "d"((unsigned short) port)); } static inline unsigned int port_in(int port) { unsigned char value; asm volatile ("inb %1,%0" - :"=a" ((unsigned char)value) - :"d"((unsigned short) port)); + :"=a" ((unsigned char)value) + :"d"((unsigned short) port)); #ifdef TRACE_IO printk("%04X:%04X: inb.%04X -> %02X\n", traceAddr >> 16,traceAddr & 0xFFFF, (ushort)port, (uchar)value); #endif @@ -185,8 +185,8 @@ static inline unsigned int port_inw(int port) { unsigned short value; asm volatile ("inw %1,%0" - :"=a" ((unsigned short)value) - :"d"((unsigned short) port)); + :"=a" ((unsigned short)value) + :"d"((unsigned short) port)); #ifdef TRACE_IO printk("%04X:%04X: inw.%04X -> %04X\n", traceAddr >> 16,traceAddr & 0xFFFF, (ushort)port, (ushort)value); #endif @@ -197,8 +197,8 @@ static inline unsigned int port_inl(int port) { unsigned long value; asm volatile ("inl %1,%0" - :"=a" ((unsigned long)value) - :"d"((unsigned short) port)); + :"=a" ((unsigned long)value) + :"d"((unsigned short) port)); #ifdef TRACE_IO printk("%04X:%04X: inl.%04X -> %08X\n", traceAddr >> 16,traceAddr & 0xFFFF, (ushort)port, (ulong)value); #endif @@ -211,16 +211,16 @@ static int real_mem_init(void) int fd_zero; if (mem_info.ready) - return 1; + return 1; if ((fd_zero = open("/dev/zero", O_RDONLY)) == -1) - PM_fatalError("You must have root privledges to run this program!"); + PM_fatalError("You must have root privledges to run this program!"); if ((m = mmap((void *)REAL_MEM_BASE, REAL_MEM_SIZE, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE, fd_zero, 0)) == (void *)-1) { - close(fd_zero); - PM_fatalError("You must have root privledges to run this program!"); - } + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE, fd_zero, 0)) == (void *)-1) { + close(fd_zero); + PM_fatalError("You must have root privledges to run this program!"); + } mem_info.ready = 1; mem_info.count = 1; mem_info.blocks[0].size = REAL_MEM_SIZE; @@ -231,9 +231,9 @@ static int real_mem_init(void) static void insert_block(int i) { memmove( - mem_info.blocks + i + 1, - mem_info.blocks + i, - (mem_info.count - i) * sizeof(struct mem_block)); + mem_info.blocks + i + 1, + mem_info.blocks + i, + (mem_info.count - i) * sizeof(struct mem_block)); mem_info.count++; } @@ -242,9 +242,9 @@ static void delete_block(int i) mem_info.count--; memmove( - mem_info.blocks + i, - mem_info.blocks + i + 1, - (mem_info.count - i) * sizeof(struct mem_block)); + mem_info.blocks + i, + mem_info.blocks + i + 1, + (mem_info.count - i) * sizeof(struct mem_block)); } static inline void set_bit(unsigned int bit, void *array) @@ -279,35 +279,35 @@ void PMAPI PM_init(void) uint r_seg,r_off; if (inited) - return; + return; /* Map the Interrupt Vectors (0x0 - 0x400) + BIOS data (0x400 - 0x502) * and the physical framebuffer and ROM images from (0xa0000 - 0x100000) */ real_mem_init(); if (!fd_mem && (fd_mem = open("/dev/mem", O_RDWR)) == -1) { - PM_fatalError("You must have root privileges to run this program!"); - } + PM_fatalError("You must have root privileges to run this program!"); + } if ((m = mmap((void *)0, 0x502, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE, fd_mem, 0)) == (void *)-1) { - PM_fatalError("You must have root privileges to run this program!"); - } + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE, fd_mem, 0)) == (void *)-1) { + PM_fatalError("You must have root privileges to run this program!"); + } if ((m = mmap((void *)0xA0000, 0xC0000 - 0xA0000, - PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd_mem, 0xA0000)) == (void *)-1) { - PM_fatalError("You must have root privileges to run this program!"); - } + PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_SHARED, fd_mem, 0xA0000)) == (void *)-1) { + PM_fatalError("You must have root privileges to run this program!"); + } if ((m = mmap((void *)0xC0000, 0xD0000 - 0xC0000, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE, fd_mem, 0xC0000)) == (void *)-1) { - PM_fatalError("You must have root privileges to run this program!"); - } + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE, fd_mem, 0xC0000)) == (void *)-1) { + PM_fatalError("You must have root privileges to run this program!"); + } if ((m = mmap((void *)0xD0000, 0x100000 - 0xD0000, - PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd_mem, 0xD0000)) == (void *)-1) { - PM_fatalError("You must have root privileges to run this program!"); - } + PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_SHARED, fd_mem, 0xD0000)) == (void *)-1) { + PM_fatalError("You must have root privileges to run this program!"); + } inited = 1; /* Allocate a stack */ @@ -356,9 +356,9 @@ void PMAPI PM_backslash(char *s) { uint pos = strlen(s); if (s[pos-1] != '/') { - s[pos] = '/'; - s[pos+1] = '\0'; - } + s[pos] = '/'; + s[pos+1] = '\0'; + } } void PMAPI PM_setFatalErrorCleanup( @@ -370,7 +370,7 @@ void PMAPI PM_setFatalErrorCleanup( void PMAPI PM_fatalError(const char *msg) { if (fatalErrorCleanup) - fatalErrorCleanup(); + fatalErrorCleanup(); fprintf(stderr,"%s\n", msg); fflush(stderr); exit(1); @@ -379,18 +379,18 @@ void PMAPI PM_fatalError(const char *msg) static void ExitVBEBuf(void) { if (VESABuf_ptr) - PM_freeRealSeg(VESABuf_ptr); + PM_freeRealSeg(VESABuf_ptr); VESABuf_ptr = 0; } void * PMAPI PM_getVESABuf(uint *len,uint *rseg,uint *roff) { if (!VESABuf_ptr) { - /* Allocate a global buffer for communicating with the VESA VBE */ - if ((VESABuf_ptr = PM_allocRealSeg(VESABuf_len, &VESABuf_rseg, &VESABuf_roff)) == NULL) - return NULL; - atexit(ExitVBEBuf); - } + /* Allocate a global buffer for communicating with the VESA VBE */ + if ((VESABuf_ptr = PM_allocRealSeg(VESABuf_len, &VESABuf_rseg, &VESABuf_roff)) == NULL) + return NULL; + atexit(ExitVBEBuf); + } *len = VESABuf_len; *rseg = VESABuf_rseg; *roff = VESABuf_roff; @@ -431,7 +431,7 @@ static FILE *open_kb_mode( char *path) { if (!PM_findBPD("graphics.bpd",path)) - return NULL; + return NULL; PM_backslash(path); strcat(path,KBMODE_DAT); return fopen(path,mode); @@ -448,18 +448,18 @@ void _PM_restore_kb_mode(void) char path[PM_MAX_PATH]; if (_PM_console_fd != -1 && (kbmode = open_kb_mode("rb",path)) != NULL) { - if (fread(&mode,1,sizeof(mode),kbmode) == sizeof(mode)) { - if (mode.startup_vc > 0) - ioctl(_PM_console_fd, VT_ACTIVATE, mode.startup_vc); - ioctl(_PM_console_fd, KDSKBMODE, mode.kb_mode); - ioctl(_PM_console_fd, KDSETLED, mode.leds); - tcsetattr(_PM_console_fd, TCSAFLUSH, &mode.termios); - fcntl(_PM_console_fd,F_SETFL,mode.flags); - } - fclose(kbmode); - unlink(path); - in_raw_mode = false; - } + if (fread(&mode,1,sizeof(mode),kbmode) == sizeof(mode)) { + if (mode.startup_vc > 0) + ioctl(_PM_console_fd, VT_ACTIVATE, mode.startup_vc); + ioctl(_PM_console_fd, KDSKBMODE, mode.kb_mode); + ioctl(_PM_console_fd, KDSETLED, mode.leds); + tcsetattr(_PM_console_fd, TCSAFLUSH, &mode.termios); + fcntl(_PM_console_fd,F_SETFL,mode.flags); + } + fclose(kbmode); + unlink(path); + in_raw_mode = false; + } } /**************************************************************************** @@ -488,49 +488,49 @@ void _PM_keyboard_rawmode(void) char path[PM_MAX_PATH]; int i; static int sig_list[] = { - SIGHUP, - SIGINT, - SIGQUIT, - SIGILL, - SIGTRAP, - SIGABRT, - SIGIOT, - SIGBUS, - SIGFPE, - SIGKILL, - SIGSEGV, - SIGTERM, - }; + SIGHUP, + SIGINT, + SIGQUIT, + SIGILL, + SIGTRAP, + SIGABRT, + SIGIOT, + SIGBUS, + SIGFPE, + SIGKILL, + SIGSEGV, + SIGTERM, + }; if ((kbmode = open_kb_mode("rb",path)) == NULL) { - if ((kbmode = open_kb_mode("wb",path)) == NULL) - PM_fatalError("Unable to open kbmode.dat file for writing!"); - if (ioctl(_PM_console_fd, KDGKBMODE, &mode.kb_mode)) - perror("KDGKBMODE"); - ioctl(_PM_console_fd, KDGETLED, &mode.leds); - _PM_leds = mode.leds & 0xF; - _PM_modifiers = 0; - tcgetattr(_PM_console_fd, &mode.termios); - conf = mode.termios; - conf.c_lflag &= ~(ICANON | ECHO | ISIG); - conf.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | BRKINT | PARMRK | INPCK | IUCLC | IXON | IXOFF); - conf.c_iflag |= (IGNBRK | IGNPAR); - conf.c_cc[VMIN] = 1; - conf.c_cc[VTIME] = 0; - conf.c_cc[VSUSP] = 0; - tcsetattr(_PM_console_fd, TCSAFLUSH, &conf); - mode.flags = fcntl(_PM_console_fd,F_GETFL); - if (ioctl(_PM_console_fd, KDSKBMODE, K_MEDIUMRAW)) - perror("KDSKBMODE"); - atexit(_PM_restore_kb_mode); - for (i = 0; i < sizeof(sig_list)/sizeof(sig_list[0]); i++) - signal(sig_list[i], _PM_abort); - mode.startup_vc = startup_vc; - if (fwrite(&mode,1,sizeof(mode),kbmode) != sizeof(mode)) - PM_fatalError("Error writing kbmode.dat!"); - fclose(kbmode); - in_raw_mode = true; - } + if ((kbmode = open_kb_mode("wb",path)) == NULL) + PM_fatalError("Unable to open kbmode.dat file for writing!"); + if (ioctl(_PM_console_fd, KDGKBMODE, &mode.kb_mode)) + perror("KDGKBMODE"); + ioctl(_PM_console_fd, KDGETLED, &mode.leds); + _PM_leds = mode.leds & 0xF; + _PM_modifiers = 0; + tcgetattr(_PM_console_fd, &mode.termios); + conf = mode.termios; + conf.c_lflag &= ~(ICANON | ECHO | ISIG); + conf.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | BRKINT | PARMRK | INPCK | IUCLC | IXON | IXOFF); + conf.c_iflag |= (IGNBRK | IGNPAR); + conf.c_cc[VMIN] = 1; + conf.c_cc[VTIME] = 0; + conf.c_cc[VSUSP] = 0; + tcsetattr(_PM_console_fd, TCSAFLUSH, &conf); + mode.flags = fcntl(_PM_console_fd,F_GETFL); + if (ioctl(_PM_console_fd, KDSKBMODE, K_MEDIUMRAW)) + perror("KDSKBMODE"); + atexit(_PM_restore_kb_mode); + for (i = 0; i < sizeof(sig_list)/sizeof(sig_list[0]); i++) + signal(sig_list[i], _PM_abort); + mode.startup_vc = startup_vc; + if (fwrite(&mode,1,sizeof(mode),kbmode) != sizeof(mode)) + PM_fatalError("Error writing kbmode.dat!"); + fclose(kbmode); + in_raw_mode = true; + } } int PMAPI PM_kbhit(void) @@ -539,9 +539,9 @@ int PMAPI PM_kbhit(void) struct timeval tv = { 0, 0 }; if (console_count == 0) - PM_fatalError("You *must* open a console before using PM_kbhit!"); + PM_fatalError("You *must* open a console before using PM_kbhit!"); if (!in_raw_mode) - _PM_keyboard_rawmode(); + _PM_keyboard_rawmode(); FD_ZERO(&s); FD_SET(_PM_console_fd, &s); return select(_PM_console_fd+1, &s, NULL, NULL, &tv) > 0; @@ -554,62 +554,62 @@ int PMAPI PM_getch(void) static struct kbentry ke; if (console_count == 0) - PM_fatalError("You *must* open a console before using PM_getch!"); + PM_fatalError("You *must* open a console before using PM_getch!"); if (!in_raw_mode) - _PM_keyboard_rawmode(); + _PM_keyboard_rawmode(); while (read(_PM_console_fd, &c, 1) > 0) { - release = c & 0x80; - c &= 0x7F; - if (release) { - switch(c){ - case 42: case 54: // Shift - _PM_modifiers &= ~KB_SHIFT; - break; - case 29: case 97: // Control - _PM_modifiers &= ~KB_CONTROL; - break; - case 56: case 100: // Alt / AltGr - _PM_modifiers &= ~KB_ALT; - break; - } - continue; - } - switch (c) { - case 42: case 54: // Shift - _PM_modifiers |= KB_SHIFT; - break; - case 29: case 97: // Control - _PM_modifiers |= KB_CONTROL; - break; - case 56: case 100: // Alt / AltGr - _PM_modifiers |= KB_ALT; - break; - case 58: // Caps Lock - _PM_modifiers ^= KB_CAPS; - ioctl(_PM_console_fd, KDSETLED, _PM_modifiers & 7); - break; - case 69: // Num Lock - _PM_modifiers ^= KB_NUMLOCK; - ioctl(_PM_console_fd, KDSETLED, _PM_modifiers & 7); - break; - case 70: // Scroll Lock - _PM_modifiers ^= KB_SCROLL; - ioctl(_PM_console_fd, KDSETLED, _PM_modifiers & 7); - break; - case 28: - return 0x1C; - default: - ke.kb_index = c; - ke.kb_table = 0; - if ((_PM_modifiers & KB_SHIFT) || (_PM_modifiers & KB_CAPS)) - ke.kb_table |= K_SHIFTTAB; - if (_PM_modifiers & KB_ALT) - ke.kb_table |= K_ALTTAB; - ioctl(_PM_console_fd, KDGKBENT, (ulong)&ke); - c = ke.kb_value & 0xFF; - return c; - } - } + release = c & 0x80; + c &= 0x7F; + if (release) { + switch(c){ + case 42: case 54: /* Shift */ + _PM_modifiers &= ~KB_SHIFT; + break; + case 29: case 97: /* Control */ + _PM_modifiers &= ~KB_CONTROL; + break; + case 56: case 100: /* Alt / AltGr */ + _PM_modifiers &= ~KB_ALT; + break; + } + continue; + } + switch (c) { + case 42: case 54: /* Shift */ + _PM_modifiers |= KB_SHIFT; + break; + case 29: case 97: /* Control */ + _PM_modifiers |= KB_CONTROL; + break; + case 56: case 100: /* Alt / AltGr */ + _PM_modifiers |= KB_ALT; + break; + case 58: /* Caps Lock */ + _PM_modifiers ^= KB_CAPS; + ioctl(_PM_console_fd, KDSETLED, _PM_modifiers & 7); + break; + case 69: /* Num Lock */ + _PM_modifiers ^= KB_NUMLOCK; + ioctl(_PM_console_fd, KDSETLED, _PM_modifiers & 7); + break; + case 70: /* Scroll Lock */ + _PM_modifiers ^= KB_SCROLL; + ioctl(_PM_console_fd, KDSETLED, _PM_modifiers & 7); + break; + case 28: + return 0x1C; + default: + ke.kb_index = c; + ke.kb_table = 0; + if ((_PM_modifiers & KB_SHIFT) || (_PM_modifiers & KB_CAPS)) + ke.kb_table |= K_SHIFTTAB; + if (_PM_modifiers & KB_ALT) + ke.kb_table |= K_ALTTAB; + ioctl(_PM_console_fd, KDGKBENT, (ulong)&ke); + c = ke.kb_value & 0xFF; + return c; + } + } return 0; } @@ -621,12 +621,12 @@ static void wait_vt_active( int _PM_console_fd) { while (ioctl(_PM_console_fd, VT_WAITACTIVE, tty_vc) < 0) { - if ((errno != EAGAIN) && (errno != EINTR)) { - perror("ioctl(VT_WAITACTIVE)"); - exit(1); - } - usleep(150000); - } + if ((errno != EAGAIN) && (errno != EINTR)) { + perror("ioctl(VT_WAITACTIVE)"); + exit(1); + } + usleep(150000); + } } /**************************************************************************** @@ -641,7 +641,7 @@ static int check_owner( sprintf(fname, "/dev/tty%d", vc); if ((stat(fname, &sbuf) >= 0) && (getuid() == sbuf.st_uid)) - return 1; + return 1; printf("You must be the owner of the current console to use this program.\n"); return 0; } @@ -658,7 +658,7 @@ static void restore_text_console( int console_id) { if (ioctl(console_id, KDSETMODE, KD_TEXT) < 0) - LOGWARN("ioctl(KDSETMODE) failed"); + LOGWARN("ioctl(KDSETMODE) failed"); _PM_restore_kb_mode(); } @@ -682,7 +682,7 @@ PM_HWND PMAPI PM_openConsole( /* Check if we have already opened the console */ if (console_count++) - return _PM_console_fd; + return _PM_console_fd; /* Now, it would be great if we could use /dev/tty and see what it is * connected to. Alas, we cannot find out reliably what VC /dev/tty is @@ -690,26 +690,26 @@ PM_HWND PMAPI PM_openConsole( */ startup_vc = 0; for (_PM_console_fd = 0; _PM_console_fd < 3; _PM_console_fd++) { - if (fstat(_PM_console_fd, &sbuf) < 0) - continue; - if (ioctl(_PM_console_fd, VT_GETMODE, &vtm) < 0) - continue; - if ((sbuf.st_rdev & 0xFF00) != 0x400) - continue; - if (!(sbuf.st_rdev & 0xFF)) - continue; - tty_vc = sbuf.st_rdev & 0xFF; - restore_text_console(_PM_console_fd); - return _PM_console_fd; - } + if (fstat(_PM_console_fd, &sbuf) < 0) + continue; + if (ioctl(_PM_console_fd, VT_GETMODE, &vtm) < 0) + continue; + if ((sbuf.st_rdev & 0xFF00) != 0x400) + continue; + if (!(sbuf.st_rdev & 0xFF)) + continue; + tty_vc = sbuf.st_rdev & 0xFF; + restore_text_console(_PM_console_fd); + return _PM_console_fd; + } if ((_PM_console_fd = open("/dev/console", O_RDWR)) < 0) { - printf("open_dev_console: can't open /dev/console \n"); - exit(1); - } + printf("open_dev_console: can't open /dev/console \n"); + exit(1); + } if (ioctl(_PM_console_fd, VT_OPENQRY, &tty_vc) < 0) - goto Error; + goto Error; if (tty_vc <= 0) - goto Error; + goto Error; sprintf(fname, "/dev/tty%d", tty_vc); close(_PM_console_fd); @@ -718,40 +718,40 @@ PM_HWND PMAPI PM_openConsole( /* We must use RDWR to allow for output... */ if (((_PM_console_fd = open(fname, O_RDWR)) >= 0) && - (ioctl(_PM_console_fd, VT_GETSTATE, &vts) >= 0)) { - if (!check_owner(vts.v_active)) - goto Error; - restore_text_console(_PM_console_fd); - - /* Success, redirect all stdios */ - fflush(stdin); - fflush(stdout); - fflush(stderr); - close(0); - close(1); - close(2); - dup(_PM_console_fd); - dup(_PM_console_fd); - dup(_PM_console_fd); - - /* clear screen and switch to it */ - fwrite("\e[H\e[J", 6, 1, stderr); - fflush(stderr); - if (tty_vc != vts.v_active) { - startup_vc = vts.v_active; - ioctl(_PM_console_fd, VT_ACTIVATE, tty_vc); - wait_vt_active(_PM_console_fd); - } - } + (ioctl(_PM_console_fd, VT_GETSTATE, &vts) >= 0)) { + if (!check_owner(vts.v_active)) + goto Error; + restore_text_console(_PM_console_fd); + + /* Success, redirect all stdios */ + fflush(stdin); + fflush(stdout); + fflush(stderr); + close(0); + close(1); + close(2); + dup(_PM_console_fd); + dup(_PM_console_fd); + dup(_PM_console_fd); + + /* clear screen and switch to it */ + fwrite("\e[H\e[J", 6, 1, stderr); + fflush(stderr); + if (tty_vc != vts.v_active) { + startup_vc = vts.v_active; + ioctl(_PM_console_fd, VT_ACTIVATE, tty_vc); + wait_vt_active(_PM_console_fd); + } + } return _PM_console_fd; Error: if (_PM_console_fd > 2) - close(_PM_console_fd); + close(_PM_console_fd); console_count = 0; PM_fatalError( - "Not running in a graphics capable console,\n" - "and unable to find one.\n"); + "Not running in a graphics capable console,\n" + "and unable to find one.\n"); return -1; } @@ -764,7 +764,7 @@ Returns the size of the console state buffer. int PMAPI PM_getConsoleStateSize(void) { if (!inited) - PM_init(); + PM_init(); return PM_getVGAStateSize() + FONT_C*2; } @@ -778,11 +778,11 @@ void PMAPI PM_saveConsoleState(void *stateBuf,int console_id) /* Save the current console font */ if (ioctl(console_id,GIO_FONT,®s[PM_getVGAStateSize()]) < 0) - perror("ioctl(GIO_FONT)"); + perror("ioctl(GIO_FONT)"); /* Inform the Linux console that we are going into graphics mode */ if (ioctl(console_id, KDSETMODE, KD_GRAPHICS) < 0) - perror("ioctl(KDSETMODE)"); + perror("ioctl(KDSETMODE)"); /* Save state of VGA registers */ PM_saveVGAState(stateBuf); @@ -806,11 +806,11 @@ void PMAPI PM_restoreConsoleState(const void *stateBuf,PM_HWND console_id) /* Inform the Linux console that we are back from graphics modes */ if (ioctl(console_id, KDSETMODE, KD_TEXT) < 0) - LOGWARN("ioctl(KDSETMODE) failed"); + LOGWARN("ioctl(KDSETMODE) failed"); /* Restore the old console font */ if (ioctl(console_id,PIO_FONT,®s[PM_getVGAStateSize()]) < 0) - LOGWARN("ioctl(KDSETMODE) failed"); + LOGWARN("ioctl(KDSETMODE) failed"); /* Coming back from graphics mode on Linux also restored the previous * text mode console contents, so we need to clear the screen to get @@ -830,15 +830,15 @@ void PMAPI PM_closeConsole(PM_HWND _PM_console_fd) { /* Restore console to normal operation */ if (--console_count == 0) { - /* Re-activate the original virtual console */ - if (startup_vc > 0) - ioctl(_PM_console_fd, VT_ACTIVATE, startup_vc); + /* Re-activate the original virtual console */ + if (startup_vc > 0) + ioctl(_PM_console_fd, VT_ACTIVATE, startup_vc); - /* Close the console file descriptor */ - if (_PM_console_fd > 2) - close(_PM_console_fd); - _PM_console_fd = -1; - } + /* Close the console file descriptor */ + if (_PM_console_fd > 2) + close(_PM_console_fd); + _PM_console_fd = -1; + } } void PM_setOSCursorLocation(int x,int y) @@ -855,12 +855,12 @@ void PM_setOSScreenWidth(int width,int height) struct winsize ws; struct vt_sizes vs; - // Resize the software terminal + /* Resize the software terminal */ ws.ws_col = width; ws.ws_row = height; ioctl(_PM_console_fd, TIOCSWINSZ, &ws); - // And the hardware + /* And the hardware */ vs.v_rows = height; vs.v_cols = width; vs.v_scrollsize = 0; @@ -869,18 +869,18 @@ void PM_setOSScreenWidth(int width,int height) ibool PMAPI PM_setRealTimeClockHandler(PM_intHandler ih, int frequency) { - // TODO: Implement this for Linux + /* TODO: Implement this for Linux */ return false; } void PMAPI PM_setRealTimeClockFrequency(int frequency) { - // TODO: Implement this for Linux + /* TODO: Implement this for Linux */ } void PMAPI PM_restoreRealTimeClockHandler(void) { - // TODO: Implement this for Linux + /* TODO: Implement this for Linux */ } char * PMAPI PM_getCurrentPath( @@ -929,7 +929,7 @@ void * PMAPI PM_getBIOSPointer(void) { static uchar *zeroPtr = NULL; if (!zeroPtr) - zeroPtr = PM_mapPhysicalAddr(0,0xFFFFF,true); + zeroPtr = PM_mapPhysicalAddr(0,0xFFFFF,true); return (void*)(zeroPtr + 0x400); } @@ -939,7 +939,7 @@ void * PMAPI PM_getA0000Pointer(void) * address mapping, so we can return the address here. */ if (!inited) - PM_init(); + PM_init(); return (void*)(0xA0000); } @@ -949,11 +949,11 @@ void * PMAPI PM_mapPhysicalAddr(ulong base,ulong limit,ibool isCached) ulong baseAddr,baseOfs; if (!inited) - PM_init(); + PM_init(); if (base >= 0xA0000 && base < 0x100000) - return (void*)base; + return (void*)base; if (!fd_mem && (fd_mem = open("/dev/mem", O_RDWR)) == -1) - return NULL; + return NULL; /* Round the physical address to a 4Kb boundary and the limit to a * 4Kb-1 boundary before passing the values to mmap. If we round the @@ -964,57 +964,57 @@ void * PMAPI PM_mapPhysicalAddr(ulong base,ulong limit,ibool isCached) baseAddr = base & ~4095; limit = ((limit+baseOfs+1+4095) & ~4095)-1; if ((p = mmap(0, limit+1, - PROT_READ | PROT_WRITE, MAP_SHARED, - fd_mem, baseAddr)) == (void *)-1) - return NULL; + PROT_READ | PROT_WRITE, MAP_SHARED, + fd_mem, baseAddr)) == (void *)-1) + return NULL; return (void*)(p+baseOfs); } void PMAPI PM_freePhysicalAddr(void *ptr,ulong limit) { if ((ulong)ptr >= 0x100000) - munmap(ptr,limit+1); + munmap(ptr,limit+1); } ulong PMAPI PM_getPhysicalAddr(void *p) { - // TODO: This function should find the physical address of a linear - // address. + /* TODO: This function should find the physical address of a linear */ + /* address. */ return 0xFFFFFFFFUL; } ibool PMAPI PM_getPhysicalAddrRange(void *p,ulong length,ulong *physAddress) { - // TODO: This function should find a range of physical addresses - // for a linear address. + /* TODO: This function should find a range of physical addresses */ + /* for a linear address. */ return false; } void PMAPI PM_sleep(ulong milliseconds) { - // TODO: Put the process to sleep for milliseconds + /* TODO: Put the process to sleep for milliseconds */ } int PMAPI PM_getCOMPort(int port) { - // TODO: Re-code this to determine real values using the Plug and Play - // manager for the OS. + /* TODO: Re-code this to determine real values using the Plug and Play */ + /* manager for the OS. */ switch (port) { - case 0: return 0x3F8; - case 1: return 0x2F8; - } + case 0: return 0x3F8; + case 1: return 0x2F8; + } return 0; } int PMAPI PM_getLPTPort(int port) { - // TODO: Re-code this to determine real values using the Plug and Play - // manager for the OS. + /* TODO: Re-code this to determine real values using the Plug and Play */ + /* manager for the OS. */ switch (port) { - case 0: return 0x3BC; - case 1: return 0x378; - case 2: return 0x278; - } + case 0: return 0x3BC; + case 1: return 0x378; + case 2: return 0x278; + } return 0; } @@ -1038,7 +1038,7 @@ void * PMAPI PM_mapRealPointer(uint r_seg,uint r_off) * mapping so we can simply return the physical address in here. */ if (!inited) - PM_init(); + PM_init(); return (void*)MK_PHYS(r_seg,r_off); } @@ -1048,24 +1048,24 @@ void * PMAPI PM_allocRealSeg(uint size,uint *r_seg,uint *r_off) char *r = (char *)REAL_MEM_BASE; if (!inited) - PM_init(); + PM_init(); if (!mem_info.ready) - return NULL; + return NULL; if (mem_info.count == REAL_MEM_BLOCKS) - return NULL; + return NULL; size = (size + 15) & ~15; for (i = 0; i < mem_info.count; i++) { - if (mem_info.blocks[i].free && size < mem_info.blocks[i].size) { - insert_block(i); - mem_info.blocks[i].size = size; - mem_info.blocks[i].free = 0; - mem_info.blocks[i + 1].size -= size; - *r_seg = (uint)(r) >> 4; - *r_off = (uint)(r) & 0xF; - return (void *)r; - } - r += mem_info.blocks[i].size; - } + if (mem_info.blocks[i].free && size < mem_info.blocks[i].size) { + insert_block(i); + mem_info.blocks[i].size = size; + mem_info.blocks[i].free = 0; + mem_info.blocks[i + 1].size -= size; + *r_seg = (uint)(r) >> 4; + *r_off = (uint)(r) & 0xF; + return (void *)r; + } + r += mem_info.blocks[i].size; + } return NULL; } @@ -1075,23 +1075,23 @@ void PMAPI PM_freeRealSeg(void *mem) char *r = (char *)REAL_MEM_BASE; if (!mem_info.ready) - return; + return; i = 0; while (mem != (void *)r) { - r += mem_info.blocks[i].size; - i++; - if (i == mem_info.count) - return; - } + r += mem_info.blocks[i].size; + i++; + if (i == mem_info.count) + return; + } mem_info.blocks[i].free = 1; if (i + 1 < mem_info.count && mem_info.blocks[i + 1].free) { - mem_info.blocks[i].size += mem_info.blocks[i + 1].size; - delete_block(i + 1); - } + mem_info.blocks[i].size += mem_info.blocks[i + 1].size; + delete_block(i + 1); + } if (i - 1 >= 0 && mem_info.blocks[i - 1].free) { - mem_info.blocks[i - 1].size += mem_info.blocks[i].size; - delete_block(i); - } + mem_info.blocks[i - 1].size += mem_info.blocks[i].size; + delete_block(i); + } } #define DIRECTION_FLAG (1 << 10) @@ -1104,27 +1104,27 @@ static void em_ins(int size) edi = context.vm.regs.edi & 0xffff; edi += (unsigned int)context.vm.regs.ds << 4; if (context.vm.regs.eflags & DIRECTION_FLAG) { - if (size == 4) - asm volatile ("std; insl; cld" - : "=D" (edi) : "d" (edx), "0" (edi)); - else if (size == 2) - asm volatile ("std; insw; cld" - : "=D" (edi) : "d" (edx), "0" (edi)); - else - asm volatile ("std; insb; cld" - : "=D" (edi) : "d" (edx), "0" (edi)); - } + if (size == 4) + asm volatile ("std; insl; cld" + : "=D" (edi) : "d" (edx), "0" (edi)); + else if (size == 2) + asm volatile ("std; insw; cld" + : "=D" (edi) : "d" (edx), "0" (edi)); + else + asm volatile ("std; insb; cld" + : "=D" (edi) : "d" (edx), "0" (edi)); + } else { - if (size == 4) - asm volatile ("cld; insl" - : "=D" (edi) : "d" (edx), "0" (edi)); - else if (size == 2) - asm volatile ("cld; insw" - : "=D" (edi) : "d" (edx), "0" (edi)); - else - asm volatile ("cld; insb" - : "=D" (edi) : "d" (edx), "0" (edi)); - } + if (size == 4) + asm volatile ("cld; insl" + : "=D" (edi) : "d" (edx), "0" (edi)); + else if (size == 2) + asm volatile ("cld; insw" + : "=D" (edi) : "d" (edx), "0" (edi)); + else + asm volatile ("cld; insb" + : "=D" (edi) : "d" (edx), "0" (edi)); + } edi -= (unsigned int)context.vm.regs.ds << 4; context.vm.regs.edi &= 0xffff0000; context.vm.regs.edi |= edi & 0xffff; @@ -1139,33 +1139,33 @@ static void em_rep_ins(int size) edi = context.vm.regs.edi & 0xffff; edi += (unsigned int)context.vm.regs.ds << 4; if (context.vm.regs.eflags & DIRECTION_FLAG) { - if (size == 4) - asm volatile ("std; rep; insl; cld" - : "=D" (edi), "=c" (ecx) - : "d" (edx), "0" (edi), "1" (ecx)); - else if (size == 2) - asm volatile ("std; rep; insw; cld" - : "=D" (edi), "=c" (ecx) - : "d" (edx), "0" (edi), "1" (ecx)); - else - asm volatile ("std; rep; insb; cld" - : "=D" (edi), "=c" (ecx) - : "d" (edx), "0" (edi), "1" (ecx)); - } + if (size == 4) + asm volatile ("std; rep; insl; cld" + : "=D" (edi), "=c" (ecx) + : "d" (edx), "0" (edi), "1" (ecx)); + else if (size == 2) + asm volatile ("std; rep; insw; cld" + : "=D" (edi), "=c" (ecx) + : "d" (edx), "0" (edi), "1" (ecx)); + else + asm volatile ("std; rep; insb; cld" + : "=D" (edi), "=c" (ecx) + : "d" (edx), "0" (edi), "1" (ecx)); + } else { - if (size == 4) - asm volatile ("cld; rep; insl" - : "=D" (edi), "=c" (ecx) - : "d" (edx), "0" (edi), "1" (ecx)); - else if (size == 2) - asm volatile ("cld; rep; insw" - : "=D" (edi), "=c" (ecx) - : "d" (edx), "0" (edi), "1" (ecx)); - else - asm volatile ("cld; rep; insb" - : "=D" (edi), "=c" (ecx) - : "d" (edx), "0" (edi), "1" (ecx)); - } + if (size == 4) + asm volatile ("cld; rep; insl" + : "=D" (edi), "=c" (ecx) + : "d" (edx), "0" (edi), "1" (ecx)); + else if (size == 2) + asm volatile ("cld; rep; insw" + : "=D" (edi), "=c" (ecx) + : "d" (edx), "0" (edi), "1" (ecx)); + else + asm volatile ("cld; rep; insb" + : "=D" (edi), "=c" (ecx) + : "d" (edx), "0" (edi), "1" (ecx)); + } edi -= (unsigned int)context.vm.regs.ds << 4; context.vm.regs.edi &= 0xffff0000; @@ -1182,27 +1182,27 @@ static void em_outs(int size) esi = context.vm.regs.esi & 0xffff; esi += (unsigned int)context.vm.regs.ds << 4; if (context.vm.regs.eflags & DIRECTION_FLAG) { - if (size == 4) - asm volatile ("std; outsl; cld" - : "=S" (esi) : "d" (edx), "0" (esi)); - else if (size == 2) - asm volatile ("std; outsw; cld" - : "=S" (esi) : "d" (edx), "0" (esi)); - else - asm volatile ("std; outsb; cld" - : "=S" (esi) : "d" (edx), "0" (esi)); - } + if (size == 4) + asm volatile ("std; outsl; cld" + : "=S" (esi) : "d" (edx), "0" (esi)); + else if (size == 2) + asm volatile ("std; outsw; cld" + : "=S" (esi) : "d" (edx), "0" (esi)); + else + asm volatile ("std; outsb; cld" + : "=S" (esi) : "d" (edx), "0" (esi)); + } else { - if (size == 4) - asm volatile ("cld; outsl" - : "=S" (esi) : "d" (edx), "0" (esi)); - else if (size == 2) - asm volatile ("cld; outsw" - : "=S" (esi) : "d" (edx), "0" (esi)); - else - asm volatile ("cld; outsb" - : "=S" (esi) : "d" (edx), "0" (esi)); - } + if (size == 4) + asm volatile ("cld; outsl" + : "=S" (esi) : "d" (edx), "0" (esi)); + else if (size == 2) + asm volatile ("cld; outsw" + : "=S" (esi) : "d" (edx), "0" (esi)); + else + asm volatile ("cld; outsb" + : "=S" (esi) : "d" (edx), "0" (esi)); + } esi -= (unsigned int)context.vm.regs.ds << 4; context.vm.regs.esi &= 0xffff0000; @@ -1218,33 +1218,33 @@ static void em_rep_outs(int size) esi = context.vm.regs.esi & 0xffff; esi += (unsigned int)context.vm.regs.ds << 4; if (context.vm.regs.eflags & DIRECTION_FLAG) { - if (size == 4) - asm volatile ("std; rep; outsl; cld" - : "=S" (esi), "=c" (ecx) - : "d" (edx), "0" (esi), "1" (ecx)); - else if (size == 2) - asm volatile ("std; rep; outsw; cld" - : "=S" (esi), "=c" (ecx) - : "d" (edx), "0" (esi), "1" (ecx)); - else - asm volatile ("std; rep; outsb; cld" - : "=S" (esi), "=c" (ecx) - : "d" (edx), "0" (esi), "1" (ecx)); - } + if (size == 4) + asm volatile ("std; rep; outsl; cld" + : "=S" (esi), "=c" (ecx) + : "d" (edx), "0" (esi), "1" (ecx)); + else if (size == 2) + asm volatile ("std; rep; outsw; cld" + : "=S" (esi), "=c" (ecx) + : "d" (edx), "0" (esi), "1" (ecx)); + else + asm volatile ("std; rep; outsb; cld" + : "=S" (esi), "=c" (ecx) + : "d" (edx), "0" (esi), "1" (ecx)); + } else { - if (size == 4) - asm volatile ("cld; rep; outsl" - : "=S" (esi), "=c" (ecx) - : "d" (edx), "0" (esi), "1" (ecx)); - else if (size == 2) - asm volatile ("cld; rep; outsw" - : "=S" (esi), "=c" (ecx) - : "d" (edx), "0" (esi), "1" (ecx)); - else - asm volatile ("cld; rep; outsb" - : "=S" (esi), "=c" (ecx) - : "d" (edx), "0" (esi), "1" (ecx)); - } + if (size == 4) + asm volatile ("cld; rep; outsl" + : "=S" (esi), "=c" (ecx) + : "d" (edx), "0" (esi), "1" (ecx)); + else if (size == 2) + asm volatile ("cld; rep; outsw" + : "=S" (esi), "=c" (ecx) + : "d" (edx), "0" (esi), "1" (ecx)); + else + asm volatile ("cld; rep; outsb" + : "=S" (esi), "=c" (ecx) + : "d" (edx), "0" (esi), "1" (ecx)); + } esi -= (unsigned int)context.vm.regs.ds << 4; context.vm.regs.esi &= 0xffff0000; @@ -1257,9 +1257,9 @@ static int emulate(void) { unsigned char *insn; struct { - unsigned int size : 1; - unsigned int rep : 1; - } prefix = { 0, 0 }; + unsigned int size : 1; + unsigned int rep : 1; + } prefix = { 0, 0 }; int i = 0; insn = (unsigned char *)((unsigned int)context.vm.regs.cs << 4); @@ -1267,101 +1267,101 @@ static int emulate(void) while (1) { #ifdef TRACE_IO - traceAddr = ((ulong)context.vm.regs.cs << 16) + context.vm.regs.eip + i; + traceAddr = ((ulong)context.vm.regs.cs << 16) + context.vm.regs.eip + i; #endif - if (insn[i] == 0x66) { - prefix.size = 1 - prefix.size; - i++; - } - else if (insn[i] == 0xf3) { - prefix.rep = 1; - i++; - } - else if (insn[i] == 0xf0 || insn[i] == 0xf2 - || insn[i] == 0x26 || insn[i] == 0x2e - || insn[i] == 0x36 || insn[i] == 0x3e - || insn[i] == 0x64 || insn[i] == 0x65 - || insn[i] == 0x67) { - /* these prefixes are just ignored */ - i++; - } - else if (insn[i] == 0x6c) { - if (prefix.rep) - em_rep_ins(1); - else - em_ins(1); - i++; - break; - } - else if (insn[i] == 0x6d) { - if (prefix.rep) { - if (prefix.size) - em_rep_ins(4); - else - em_rep_ins(2); - } - else { - if (prefix.size) - em_ins(4); - else - em_ins(2); - } - i++; - break; - } - else if (insn[i] == 0x6e) { - if (prefix.rep) - em_rep_outs(1); - else - em_outs(1); - i++; - break; - } - else if (insn[i] == 0x6f) { - if (prefix.rep) { - if (prefix.size) - em_rep_outs(4); - else - em_rep_outs(2); - } - else { - if (prefix.size) - em_outs(4); - else - em_outs(2); - } - i++; - break; - } - else if (insn[i] == 0xec) { - *((uchar*)&context.vm.regs.eax) = port_in(context.vm.regs.edx); - i++; - break; - } - else if (insn[i] == 0xed) { - if (prefix.size) - *((ulong*)&context.vm.regs.eax) = port_inl(context.vm.regs.edx); - else - *((ushort*)&context.vm.regs.eax) = port_inw(context.vm.regs.edx); - i++; - break; - } - else if (insn[i] == 0xee) { - port_out(context.vm.regs.eax,context.vm.regs.edx); - i++; - break; - } - else if (insn[i] == 0xef) { - if (prefix.size) - port_outl(context.vm.regs.eax,context.vm.regs.edx); - else - port_outw(context.vm.regs.eax,context.vm.regs.edx); - i++; - break; - } - else - return 0; - } + if (insn[i] == 0x66) { + prefix.size = 1 - prefix.size; + i++; + } + else if (insn[i] == 0xf3) { + prefix.rep = 1; + i++; + } + else if (insn[i] == 0xf0 || insn[i] == 0xf2 + || insn[i] == 0x26 || insn[i] == 0x2e + || insn[i] == 0x36 || insn[i] == 0x3e + || insn[i] == 0x64 || insn[i] == 0x65 + || insn[i] == 0x67) { + /* these prefixes are just ignored */ + i++; + } + else if (insn[i] == 0x6c) { + if (prefix.rep) + em_rep_ins(1); + else + em_ins(1); + i++; + break; + } + else if (insn[i] == 0x6d) { + if (prefix.rep) { + if (prefix.size) + em_rep_ins(4); + else + em_rep_ins(2); + } + else { + if (prefix.size) + em_ins(4); + else + em_ins(2); + } + i++; + break; + } + else if (insn[i] == 0x6e) { + if (prefix.rep) + em_rep_outs(1); + else + em_outs(1); + i++; + break; + } + else if (insn[i] == 0x6f) { + if (prefix.rep) { + if (prefix.size) + em_rep_outs(4); + else + em_rep_outs(2); + } + else { + if (prefix.size) + em_outs(4); + else + em_outs(2); + } + i++; + break; + } + else if (insn[i] == 0xec) { + *((uchar*)&context.vm.regs.eax) = port_in(context.vm.regs.edx); + i++; + break; + } + else if (insn[i] == 0xed) { + if (prefix.size) + *((ulong*)&context.vm.regs.eax) = port_inl(context.vm.regs.edx); + else + *((ushort*)&context.vm.regs.eax) = port_inw(context.vm.regs.edx); + i++; + break; + } + else if (insn[i] == 0xee) { + port_out(context.vm.regs.eax,context.vm.regs.edx); + i++; + break; + } + else if (insn[i] == 0xef) { + if (prefix.size) + port_outl(context.vm.regs.eax,context.vm.regs.edx); + else + port_outw(context.vm.regs.eax,context.vm.regs.edx); + i++; + break; + } + else + return 0; + } context.vm.regs.eip += i; return 1; @@ -1393,7 +1393,7 @@ static void debug_info(int vret) fputs("cs:ip = [ ", stderr); p = (unsigned char *)((context.vm.regs.cs << 4) + (context.vm.regs.eip & 0xffff)); for (i = 0; i < 16; ++i) - fprintf(stderr, "%02x ", (unsigned int)p[i]); + fprintf(stderr, "%02x ", (unsigned int)p[i]); fputs("]\n", stderr); fflush(stderr); } @@ -1403,24 +1403,24 @@ static int run_vm86(void) unsigned int vret; for (;;) { - vret = vm86(&context.vm); - if (VM86_TYPE(vret) == VM86_INTx) { - unsigned int v = VM86_ARG(vret); - if (v == RETURN_TO_32_INT) - return 1; - pushw(context.vm.regs.eflags); - pushw(context.vm.regs.cs); - pushw(context.vm.regs.eip); - context.vm.regs.cs = get_int_seg(v); - context.vm.regs.eip = get_int_off(v); - context.vm.regs.eflags &= ~(VIF_MASK | TF_MASK); - continue; - } - if (VM86_TYPE(vret) != VM86_UNKNOWN) - break; - if (!emulate()) - break; - } + vret = vm86(&context.vm); + if (VM86_TYPE(vret) == VM86_INTx) { + unsigned int v = VM86_ARG(vret); + if (v == RETURN_TO_32_INT) + return 1; + pushw(context.vm.regs.eflags); + pushw(context.vm.regs.cs); + pushw(context.vm.regs.eip); + context.vm.regs.cs = get_int_seg(v); + context.vm.regs.eip = get_int_off(v); + context.vm.regs.eflags &= ~(VIF_MASK | TF_MASK); + continue; + } + if (VM86_TYPE(vret) != VM86_UNKNOWN) + break; + if (!emulate()) + break; + } debug_info(vret); return 0; } @@ -1431,7 +1431,7 @@ static int run_vm86(void) void PMAPI DPMI_int86(int intno, DPMI_regs *regs) { if (!inited) - PM_init(); + PM_init(); memset(&context.vm.regs, 0, sizeof(context.vm.regs)); IND(eax); IND(ebx); IND(ecx); IND(edx); IND(esi); IND(edi); context.vm.regs.eflags = DEFAULT_VM86_FLAGS; @@ -1453,7 +1453,7 @@ void PMAPI DPMI_int86(int intno, DPMI_regs *regs) int PMAPI PM_int86(int intno, RMREGS *in, RMREGS *out) { if (!inited) - PM_init(); + PM_init(); memset(&context.vm.regs, 0, sizeof(context.vm.regs)); IN(eax); IN(ebx); IN(ecx); IN(edx); IN(esi); IN(edi); context.vm.regs.eflags = DEFAULT_VM86_FLAGS; @@ -1474,41 +1474,41 @@ int PMAPI PM_int86x(int intno, RMREGS *in, RMREGS *out, RMSREGS *sregs) { if (!inited) - PM_init(); + PM_init(); if (intno == 0x21) { - time_t today = time(NULL); - struct tm *t; - t = localtime(&today); - out->x.cx = t->tm_year + 1900; - out->h.dh = t->tm_mon + 1; - out->h.dl = t->tm_mday; - } + time_t today = time(NULL); + struct tm *t; + t = localtime(&today); + out->x.cx = t->tm_year + 1900; + out->h.dh = t->tm_mon + 1; + out->h.dl = t->tm_mday; + } else { - unsigned int seg, off; - seg = get_int_seg(intno); - off = get_int_off(intno); - memset(&context.vm.regs, 0, sizeof(context.vm.regs)); - IN(eax); IN(ebx); IN(ecx); IN(edx); IN(esi); IN(edi); - context.vm.regs.eflags = DEFAULT_VM86_FLAGS; - context.vm.regs.cs = seg; - context.vm.regs.eip = off; - context.vm.regs.es = sregs->es; - context.vm.regs.ds = sregs->ds; - context.vm.regs.fs = sregs->fs; - context.vm.regs.gs = sregs->gs; - context.vm.regs.ss = context.stack_seg; - context.vm.regs.esp = context.stack_off; - pushw(DEFAULT_VM86_FLAGS); - pushw(context.ret_seg); - pushw(context.ret_off); - run_vm86(); - OUT(eax); OUT(ebx); OUT(ecx); OUT(edx); OUT(esi); OUT(edi); - sregs->es = context.vm.regs.es; - sregs->ds = context.vm.regs.ds; - sregs->fs = context.vm.regs.fs; - sregs->gs = context.vm.regs.gs; - out->x.cflag = context.vm.regs.eflags & 1; - } + unsigned int seg, off; + seg = get_int_seg(intno); + off = get_int_off(intno); + memset(&context.vm.regs, 0, sizeof(context.vm.regs)); + IN(eax); IN(ebx); IN(ecx); IN(edx); IN(esi); IN(edi); + context.vm.regs.eflags = DEFAULT_VM86_FLAGS; + context.vm.regs.cs = seg; + context.vm.regs.eip = off; + context.vm.regs.es = sregs->es; + context.vm.regs.ds = sregs->ds; + context.vm.regs.fs = sregs->fs; + context.vm.regs.gs = sregs->gs; + context.vm.regs.ss = context.stack_seg; + context.vm.regs.esp = context.stack_off; + pushw(DEFAULT_VM86_FLAGS); + pushw(context.ret_seg); + pushw(context.ret_off); + run_vm86(); + OUT(eax); OUT(ebx); OUT(ecx); OUT(edx); OUT(esi); OUT(edi); + sregs->es = context.vm.regs.es; + sregs->ds = context.vm.regs.ds; + sregs->fs = context.vm.regs.fs; + sregs->gs = context.vm.regs.gs; + out->x.cflag = context.vm.regs.eflags & 1; + } return out->e.eax; } @@ -1518,7 +1518,7 @@ void PMAPI PM_callRealMode(uint seg,uint off, RMREGS *in, RMSREGS *sregs) { if (!inited) - PM_init(); + PM_init(); memset(&context.vm.regs, 0, sizeof(context.vm.regs)); IN(eax); IN(ebx); IN(ecx); IN(edx); IN(esi); IN(edi); context.vm.regs.eflags = DEFAULT_VM86_FLAGS; @@ -1558,32 +1558,32 @@ void PMAPI PM_availableMemory(ulong *physical,ulong *total) void * PMAPI PM_allocLockedMem(uint size,ulong *physAddr,ibool contiguous,ibool below16M) { - // TODO: Implement this for Linux + /* TODO: Implement this for Linux */ return NULL; } void PMAPI PM_freeLockedMem(void *p,uint size,ibool contiguous) { - // TODO: Implement this for Linux + /* TODO: Implement this for Linux */ } void * PMAPI PM_allocPage( ibool locked) { - // TODO: Implement this for Linux + /* TODO: Implement this for Linux */ return NULL; } void PMAPI PM_freePage( void *p) { - // TODO: Implement this for Linux + /* TODO: Implement this for Linux */ } void PMAPI PM_setBankA(int bank) { if (!inited) - PM_init(); + PM_init(); memset(&context.vm.regs, 0, sizeof(context.vm.regs)); context.vm.regs.eax = 0x4F05; context.vm.regs.ebx = 0x0000; @@ -1602,7 +1602,7 @@ void PMAPI PM_setBankA(int bank) void PMAPI PM_setBankAB(int bank) { if (!inited) - PM_init(); + PM_init(); memset(&context.vm.regs, 0, sizeof(context.vm.regs)); context.vm.regs.eax = 0x4F05; context.vm.regs.ebx = 0x0000; @@ -1633,7 +1633,7 @@ void PMAPI PM_setBankAB(int bank) void PMAPI PM_setCRTStart(int x,int y,int waitVRT) { if (!inited) - PM_init(); + PM_init(); memset(&context.vm.regs, 0, sizeof(context.vm.regs)); context.vm.regs.eax = 0x4F07; context.vm.regs.ebx = waitVRT; @@ -1656,14 +1656,14 @@ int PMAPI PM_enableWriteCombine(ulong base,ulong length,uint type) struct mtrr_sentry sentry; if (mtrr_fd < 0) - return PM_MTRR_ERR_NO_OS_SUPPORT; + return PM_MTRR_ERR_NO_OS_SUPPORT; sentry.base = base; sentry.size = length; sentry.type = type; if (ioctl(mtrr_fd, MTRRIOC_ADD_ENTRY, &sentry) == -1) { - // TODO: Need to decode MTRR error codes!! - return PM_MTRR_NOT_SUPPORTED; - } + /* TODO: Need to decode MTRR error codes!! */ + return PM_MTRR_NOT_SUPPORTED; + } return PM_MTRR_ERR_OK; #else return PM_MTRR_ERR_NO_OS_SUPPORT; @@ -1685,15 +1685,15 @@ int PMAPI PM_enumWriteCombine( struct mtrr_gentry gentry; if (mtrr_fd < 0) - return PM_MTRR_ERR_NO_OS_SUPPORT; + return PM_MTRR_ERR_NO_OS_SUPPORT; for (gentry.regnum = 0; ioctl (mtrr_fd, MTRRIOC_GET_ENTRY, &gentry) == 0; - ++gentry.regnum) { - if (gentry.size > 0) { - // WARNING: This code assumes that the types in pmapi.h match the ones - // in the Linux kernel (mtrr.h) - callback(gentry.base, gentry.size, gentry.type); - } + ++gentry.regnum) { + if (gentry.size > 0) { + /* WARNING: This code assumes that the types in pmapi.h match the ones */ + /* in the Linux kernel (mtrr.h) */ + callback(gentry.base, gentry.size, gentry.type); + } } return PM_MTRR_ERR_OK; @@ -1719,13 +1719,13 @@ ibool PMAPI PM_doBIOSPOST( * the secondary BIOS image over the top of the old one. */ if (!inited) - PM_init(); + PM_init(); if ((old_bios = PM_malloc(BIOSLen)) == NULL) - return false; + return false; if (BIOSPhysAddr != 0xC0000) { - memcpy(old_bios,bios_ptr,BIOSLen); - memcpy(bios_ptr,copyOfBIOS,BIOSLen); - } + memcpy(old_bios,bios_ptr,BIOSLen); + memcpy(bios_ptr,copyOfBIOS,BIOSLen); + } /* The interrupt vectors should already be mmap()'ed from 0-0x400 in PM_init */ Current10 = rvec[0x10]; @@ -1742,7 +1742,7 @@ ibool PMAPI PM_doBIOSPOST( /* Restore original BIOS image */ if (BIOSPhysAddr != 0xC0000) - memcpy(bios_ptr,old_bios,BIOSLen); + memcpy(bios_ptr,old_bios,BIOSLen); PM_free(old_bios); return true; } @@ -1774,7 +1774,7 @@ int PMAPI PM_unlockCodePages(void (*p)(),uint len,PM_lockHandle *lh) PM_MODULE PMAPI PM_loadLibrary( const char *szDLLName) { - // TODO: Implement this to load shared libraries! + /* TODO: Implement this to load shared libraries! */ (void)szDLLName; return NULL; } @@ -1783,7 +1783,7 @@ void * PMAPI PM_getProcAddress( PM_MODULE hModule, const char *szProcName) { - // TODO: Implement this! + /* TODO: Implement this! */ (void)hModule; (void)szProcName; return NULL; @@ -1792,19 +1792,18 @@ void * PMAPI PM_getProcAddress( void PMAPI PM_freeLibrary( PM_MODULE hModule) { - // TODO: Implement this! + /* TODO: Implement this! */ (void)hModule; } int PMAPI PM_setIOPL( int level) { - // TODO: Move the IOPL switching into this function!! + /* TODO: Move the IOPL switching into this function!! */ return level; } void PMAPI PM_flushTLB(void) { - // Do nothing on Linux. + /* Do nothing on Linux. */ } - |