예제 #1
0
static void ps2ms_int_handler( void *arg )
{
    (void) arg;

    static int inbytepos = 0;

    signed char mousedata = inb( PS2_DATA_ADDR );

    SHOW_FLOW( 10 ,"%2X ", mousedata & 0xFFu );

    switch(inbytepos)
    {
    case 0:

        // first byte has one in this pos
        if(1 && ! (0x8 & mousedata) )
        {
            //inbytepos = -1; break;
            inbytepos = 0; return;
        }

        ps2ms_state_buttons = 0x7 & mousedata;
        xsign = 0x10 & mousedata;
        ysign = 0x20 & mousedata;
        break;

    case 1:     xval = mousedata; break;
    case 2:     yval = mousedata; break;
    case 3:     break;
    case 4:     break;
    }

    inbytepos++;
    inbytepos %= 3;
    //inbytepos %= 4;

    if(inbytepos != 0)
        return;

    xval = insert_bit9( xval, xsign );
    yval = insert_bit9( yval, ysign );

    ps2ms_state_xpos += xval;
    ps2ms_state_ypos += yval;

    if( ps2ms_state_xpos < 0 ) ps2ms_state_xpos = 0;
    if( ps2ms_state_ypos < 0 ) ps2ms_state_ypos = 0;

    if( ps2ms_state_xpos > video_drv->xsize ) ps2ms_state_xpos = video_drv->xsize;
    if( ps2ms_state_ypos > video_drv->ysize ) ps2ms_state_ypos = video_drv->ysize;


    //printf("ms %d %d %x\n", ps2ms_state_xpos, ps2ms_state_ypos, ps2ms_state_buttons );

    if(NULL != video_drv)
    {
        video_drv->mouse_x = ps2ms_state_xpos;
        video_drv->mouse_y = ps2ms_state_ypos;

        struct ui_event e;
        e.type = UI_EVENT_TYPE_MOUSE;
        e.time = fast_time();
        e.focus= 0;

        e.m.buttons = ps2ms_state_buttons;
        e.abs_x = ps2ms_state_xpos;
        e.abs_y = ps2ms_state_ypos;

        put_buf(&e);
        hal_sem_release( &mouse_sem );
    }

}
예제 #2
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
    HDC hDC;
    PAINTSTRUCT lpPaint;


    switch(iMessage)
    {
    case WM_CLOSE:
    case WM_DESTROY:
        exit(0);
        if(MessageBox(hWnd, "Do you really want to quit?", "Message", MB_YESNO) == IDYES)
            PostQuitMessage(0);
        break;

    case WM_ERASEBKGND:
        return 1; // Done

    case WM_PAINT:
        GdiFlush();
        hDC = BeginPaint( hWnd, &lpPaint);

        // Assume hPaintDC is a variable of type HDC, and the dc we're rendering to
        HDC hBitmapDC = CreateCompatibleDC(hDC);
        HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBitmapDC, screenBitmap);
        //HPALETTE hOldPalette = SelectPalette(hPaintDC, hPalette, FALSE);
        GdiFlush();
        if( !BitBlt(hDC, 0, 0, VSCREEN_WIDTH, VSCREEN_HEIGHT, hBitmapDC, 0, 0, SRCCOPY) )
        {
            DWORD err = GetLastError();
            //FormatMessage();
            printf("Win error %d", (int)err);

            LPVOID lpMsgBuf;
            FormatMessage(
                          FORMAT_MESSAGE_ALLOCATE_BUFFER |
                          FORMAT_MESSAGE_FROM_SYSTEM |
                          FORMAT_MESSAGE_IGNORE_INSERTS,

                          NULL,
                          err,
                          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                          (LPTSTR) &lpMsgBuf,
                          0, NULL );

            printf("WinErr: %s\n", (const char *)lpMsgBuf );

        }
        GdiFlush();
        //SelectPalette(hPaintDC, hOldPalette, TRUE);
        SelectObject(hBitmapDC, hOldBitmap);
        DeleteDC(hBitmapDC);


        /*if(eline)
         {
         MoveToEx(hDC, 60, 20, NULL);
         LineTo(hDC, 264, 122);
         }*/

        // TODO: paint OS mouse cursor

        EndPaint( hWnd, &lpPaint);

        break;

#if HOVER
    case WM_MOUSEHOVER:
        {
            int xPos = (short)(0x0FFFF & lParam);//GET_X_LPARAM(lParam);
            int yPos = VSCREEN_HEIGHT - (short)(0x0FFFF & (lParam>>16));//GET_Y_LPARAM(lParam);

            printf("%d,%d\n", xPos, yPos );
            TrackMouseEvent(&eventTrack);
        }
        break;
#endif


    //case WM_KEYDOWN:
    //case WM_KEYUP:        TranslateMessage(  __in  const MSG *lpMsg );

    case WM_CHAR:
        {
            printf("-%x-", (int)lParam );
        }
        break;

    case WM_MOUSEMOVE:
        {
            int xPos = (short)(0x0FFFF & lParam);//GET_X_LPARAM(lParam);
            int yPos = VSCREEN_HEIGHT - (short)(0x0FFFF & (lParam>>16));//GET_Y_LPARAM(lParam);

            //	printf("%d,%d\n", xPos, yPos );

            drv_video_win32.mouse_x = xPos;
            drv_video_win32.mouse_y = yPos;
            drv_video_win32.mouse_flags = wParam;
            drv_video_win32.mouse();
#if 1
            struct ui_event e;
            e.type = UI_EVENT_TYPE_MOUSE;
            e.time = fast_time();
            e.focus= 0;

            e.m.buttons = wParam;
            e.abs_x = xPos;
            e.abs_y = VSCREEN_HEIGHT - yPos - 1;

            ev_q_put_any( &e );
            //printf("-ms-");            printf("%d,%d\n", xPos, yPos );
#endif
        }
        break;

    default:
        return DefWindowProc(hWnd, iMessage, wParam, lParam);
    }
    return 0;
}