· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
¸¶¿ì½º ´Ù·ç±â

Linux¿¡¼­ ¸¶¿ì½º ´Ù·ç±â

  • ÀÌ ¼Ò½º´Â ¸¶¿ì½º¸¦ Á÷Á¢ ó¸®ÇÒ¶§ »ç¿ëÇÒ¼ö ÀÖ°ÚÁÒ? X°¡ ¾øÀÌ ¸¶¿ì½º¸¦ ¾î¶»°Ô ÀÔ·Â ¹Þ´ÂÁö¿¡ ´ëÇÑ ¿¹Á¦ÀÔ´Ï´Ù.
  • ¸¶¿ì½º´Â °ÅÀÇ ´ëºÎºÐ Æú¸µ ¹æ½Ä ¿Ü¿¡´Â »ÏÁ·ÇÑ ¼ö°¡ ¾øÀ»°Å °°½À´Ï´Ù¸¸ RTS¿Í ¿¬µ¿Çϸé Á» ³´°Ú±º¿ä.
  • ÀÏ¹Ý PS/2 ÀÇ 3¹öÆ° ¸¶¿ì½º(¶Ç´Â 2¹öÆ° ¸¶¿ì½º)ÀÇ °æ¿ì ´ÙÀ½°ú °°Àº 3¹ÙÀÌÆ® ´ÜÀ§±¸Á¶ÀÇ µ¥ÀÌÅÍÀÔ·ÂÀ» ó¸®ÇÏ¸é µË´Ï´Ù.

OFFSET ³»¿ë
0 Button Á¤º¸ (1=¿ÞÂÊ, 2=¿À¸¥ÂÊ, 3=°¡¿îµ¥ ¶Ç´Â ¿ÞÂÊ°ú ¿À¸¥ÂÊÀÇ µ¿½Ã Ŭ¸¯, ±× ¹Û¿¡ ÈÙ±¸Á¶ Á¤º¸)
1 XÃàÀÇ Áõ°¨°ª (ºÎÈ£ÀÖ´Â ¹ÙÀÌÆ® charÇü)
2 YÃàÀÇ Áõ°¨°ª (¼öÇÐÁÂÇ¥°è·Î¼­ ±×·¡ÇÈ ÁÂÇ¥°è·Î º¯È¯ÇÏ·Á¸é ¿ª¼ö¸¦ ÃëÇÔ)
  • ´©±º°¡ ¸¶¿ì½ºÀÇ ÀÔ·Â ±¸Á¶¿¡ ´ëÇؼ­ ÈäÀ» º» ±ÛÀÌ ±â¾ï³³´Ï´Ù. ¿ì¼± 3¹ÙÀÌÆ® alignÀ» ÃëÇØ¾ß ÇÑ´Ù´Â Á¡°ú °è¼Ó °¨½Ã¸¦ ÇØ¾ß ÇÑ´Ù´Â Á¡¶§¹®ÀÌ¸ç ±×·¸´Ù°í ´õ »ÏÁ·ÇÑ ¼ö´Â ¾ø¾îº¸ÀÔ´Ï´Ù.
  • 16ºñÆ® ¸¶¿ì½º Ä¿¼­ ºñÆ®¸Ê Çѹø ±×·ÁºÃ½À´Ï´Ù. À̸¦ ó¸®ÇÒ¶§ bit 0ÀÎ °÷Àº Åõ¸í 󸮸¦ ÇÊ¿ä·Î ÇÏ¸ç °¢ ºñÆ®¸ÊÀº ÃÖ¼ÒÇÑÀÇ ±¸¼ºÀ¸·Î ¸¸µé¾îÁö¸ç ÀÌ°ÍÀ»ÀÌ ¼­·Î or¿¬»êÀ¸·Î ÇϳªÀÇ Ä¿¼­¸¦ ¿Ï¼ºÇÕ´Ï´Ù. ¶§¹®¿¡ ¸¶¿ì½º Ä¿¼­¸¦ ó¸®ÇÒ¶§ ¶Ç ´Ù¸¥ ÇϳªÀÇ ÀÛ¾÷¿µ¿ªÀÇ ºñÆ®¸Ê ¸Þ¸ð¸®¸¦ °®´Â°ÍÀÌ º¸ÅëÀ̸ç or¿¬»êÀ¸·Î ¸¸µé¾îÁø ºñÆ®¸ÊÀ» cacheÇÏ´Â °æ¿ìµµ ÀÖ½À´Ï´Ù. ¸¶¿ì½º¿¡ CPUÁ¡À¯¸¦ ÀüºÎ ÇÒ¾ÖÇÒ¼ö´Â ¾ø±â ¶§¹®ÀÌ°ÚÁÒ.

unsigned short g_MouseCursorBitmap[5][16]={
                {0xc000,0xa000,0x9000,0x8800,0x8400,0x8200,0x8100,0x8080,
                 0x8040,0x8020,0x83e0,0xb900,0xe980,0x0c80,0x0480,0x0780},
                {0x0000,0x4000,0x6000,0x7000,0x7800,0x7c00,0x7e00,0x7f00,
                 0x7f80,0x7fc0,0x7c00,0x4600,0x0600,0x0300,0x0300,0x0000},
                {0x0c00,0x1200,0x1200,0x1200,0x1200,0x13b6,0x1249,0x7249,
                 0x9249,0x9001,0x9001,0x8001,0x4002,0x4002,0x2004,0x1ff8},
                {0x0000,0x0c00,0x0c00,0x0c00,0x0c00,0x0c00,0x0db6,0x0db6,
                 0x6db6,0x6ffe,0x6ffe,0x7ffe,0x3ffc,0x3ffc,0x1ff8,0x0000},
                {0x0000,0x0012,0x001a,0x0016,0x0012,0x0000,0x0000,0x0000,
                 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}
               };


/*
 [ GPL ]
 Code by JaeHyuk Cho <mailto:minzkn@infoeq.com>
 http://minzkn.pe.ky
*/

#include <sys/types.h>
#include <sys/select.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>

/* MouseÇϳª¸¦ ó¸®Çϱâ À§Çؼ­ ´ÙÀ½°ú °°Àº ±¸Á¶°¡ ÇÊ¿äÇÕ´Ï´Ù. */
typedef struct ts_MZ_Mouse
{
 int Handle;
 int GridX, GridY, PreButton, Button;
 int PrePositionX, PrePositionY, PositionX, PositionY;
 int Window[ 4 ];
}t_MZ_Mouse;

t_MZ_Mouse *MZ_OpenMouse(const char *s_DeviceName)
{
 const char *c_DeviceTable[] = { /* ¸¶¿ì½º ÀåÄ¡¸¦ ¿©±â¿¡ Áö¿øÇÒ¼ö ÀÖ´Â °æ¿ì ¿­°ÅÇÕ´Ï´Ù. */
  "/dev/mouse", "/dev/psaux", (char *)0
 };
 int s_Handle, s_Index;
 t_MZ_Mouse *s_Return;
 if(s_DeviceName)s_Handle = open(s_DeviceName, O_RDONLY);
 else s_Handle = (-1);
 s_Index = 0;
 while(s_Handle == (-1) && c_DeviceTable[s_Index])s_Handle = open(c_DeviceTable[s_Index++], O_RDONLY);
 if(s_Handle != (-1))
 {
  s_Return = (t_MZ_Mouse *)malloc(sizeof(t_MZ_Mouse));
  if(s_Return)
  {
   s_Return->Handle = s_Handle;
   s_Return->GridX = s_Return->GridY = 0;
   s_Return->PreButton = s_Return->Button = 0;
   s_Return->PrePositionX = s_Return->PrePositionY = s_Return->PositionX = s_Return->PositionY = 0;
   s_Return->Window[0] = s_Return->Window[1] = s_Return->Window[2] = s_Return->Window[3] = (-1);
  }
  else close(s_Handle);
 }
 else s_Return = (t_MZ_Mouse *)0;
 return(s_Return);
}

t_MZ_Mouse *MZ_CloseMouse(t_MZ_Mouse *s_Handle)
{
 if(s_Handle)
 {
  if(s_Handle->Handle != (-1))close(s_Handle->Handle);
  free(s_Handle);
  s_Handle = (t_MZ_Mouse *)0;
 }
 return(s_Handle);
}

void MZ_SetupMouse(t_MZ_Mouse *s_Handle, int s_Left, int s_Top, int s_Right, int s_Bottom)
{
 if(s_Handle)
 { /* ¸¶¿ì½ºÀÇ Çൿ¹üÀ§¸¦ Á¦ÇÑÇϱâ À§ÇÑ ¿µ¿ª º¯¼öÀÔ´Ï´Ù. */
  s_Handle->Window[0] = s_Left , s_Handle->Window[1] = s_Top;
  s_Handle->Window[2] = s_Right, s_Handle->Window[3] = s_Bottom;
 }
}

int MZ_DoMouse(t_MZ_Mouse *s_Handle)
{
 int s_Return = 0, s_Check, s_ReadBytes;
 fd_set s_FD_Read;
 struct timeval s_LocalTimeVal;
 char s_Buffer[ 3 ]; /* ¸¶¿ì½º µ¥ÀÌÅÍ ¹öÆÛ */
 if(s_Handle)
 {
  if(s_Handle->Handle != (-1))
  {
   s_ReadBytes = 0;
   /* Ã³À½ ÇѹøÀº Non-blocking¼öÁØÀ¸·Î select¸¦ °Éµµ·Ï ÇÕ´Ï´Ù. */
   s_LocalTimeVal.tv_sec = 0, s_LocalTimeVal.tv_usec = 1;
   do
   { /* ¸¶¿ì½º´Â 3¹ÙÀÌÆ® ´ÜÀ§ÀÇ µ¥ÀÌÅ͸¦ ¼ö½ÅÇÏ°Ô µË´Ï´Ù.
     ÇÏÁö¸¸ ¸ðµç ¸¶¿ì½º°¡ ±×·¯ÇÑ °ÍÀÌ ¾Æ´Ï¹Ç·Î ÇØ´ç ¸¶¿ì½ºÀÇ spec¸¦ ÂüÁ¶Çϼ¼¿ä. */
    FD_ZERO(&s_FD_Read);
    FD_SET(s_Handle->Handle, &s_FD_Read);
    s_Check = select(s_Handle->Handle + 1,
               (fd_set *)(&s_FD_Read),
               (fd_set *)0,
               (fd_set *)0,
               (struct timeval *)(&s_LocalTimeVal));

    /* ÀÌ °ªÀ» Á¶ÀýÇÏ¸é ¸¶¿ì½º°¡ ¹ÌÄ¥Áöµµ ¸ð¸¨´Ï´Ù. ^^ */
    s_LocalTimeVal.tv_sec = 0, s_LocalTimeVal.tv_usec = 100 * 1000;
    if(s_Check > 0)
    {
     s_Check = read(s_Handle->Handle, &s_Buffer[s_ReadBytes], sizeof(s_Buffer) - s_ReadBytes);
     if(s_Check > 0)s_ReadBytes += s_Check;
    }
   }while(s_ReadBytes < sizeof(s_Buffer) && s_Check > 0);
   if(s_ReadBytes >= sizeof(s_Buffer))
   {
    s_Handle->PreButton     =  s_Handle->Button;
    s_Handle->Button        =  ((int)s_Buffer[ 0 ]); /* ¹öÆ° Á¤º¸ */
    s_Handle->GridX         =  ((int)s_Buffer[ 1 ]); /* XÃà */
    s_Handle->GridY         = -((int)s_Buffer[ 2 ]); /* YÃà ¿ª¹æÇâ¼ö (±×·¡ÇÈ ÁÂÇ¥°èÀÇ Y) */

    /* ¸¶¿ì½º °¡¼Óó¸® :
       4Çȼ¿ ÀÌ»ó ¿òÁ÷ÀÌ¸é ±×¿¡ 2¹è¼ö¸¦ °öÇÑ À̵¿ÁÂÇ¥°è·Î ¹Ù²ß´Ï´Ù.
       ÀÌ ÀÛ¾÷ÀÌ ¾øÀ¸¸é ¸¶¿ì½º ¿òÁ÷ÀÌ´Â°Ô ´ä´äÇÕ´Ï´Ù.
       Áï, Àú °°Àº ÅÍÄ¡ÆÐµå »ç¿ëÀڵ鿡°Ô´Â ´õ¿í ¼ÓÅÍÁö´Â ÀÏÀÌ µÉ°Ì´Ï´Ù. */
    if(s_Handle->GridX > 4 || s_Handle->GridX < (-4))s_Handle->GridX *= 2;
    if(s_Handle->GridY > 4 || s_Handle->GridY < (-4))s_Handle->GridY *= 2;

    s_Handle->PrePositionX  = s_Handle->PositionX;
    s_Handle->PositionX    += s_Handle->GridX;
    s_Handle->PrePositionY  = s_Handle->PositionY;
    s_Handle->PositionY    += s_Handle->GridY;
    if(s_Handle->Window[0] >= 0 &&
       s_Handle->PositionX < s_Handle->Window[0])s_Handle->PositionX = s_Handle->Window[0];
    if(s_Handle->Window[1] >= 0 &&
       s_Handle->PositionY < s_Handle->Window[1])s_Handle->PositionY = s_Handle->Window[1];
    if(s_Handle->Window[2] >= 0 &&
       s_Handle->PositionX > s_Handle->Window[2])s_Handle->PositionX = s_Handle->Window[2];
    if(s_Handle->Window[3] >= 0 &&
       s_Handle->PositionY > s_Handle->Window[3])s_Handle->PositionY = s_Handle->Window[3];
    s_Return = 1;
   }
  }
 }
 return(s_Return);
}

int main(void)
{
 int s_Return = 0, s_KeepData = 0;
 t_MZ_Mouse *s_Mouse;
 s_Mouse = MZ_OpenMouse((char *)0);
 if(s_Mouse)
 {
  MZ_SetupMouse(s_Mouse, 0, 0, 640, 480);
  fprintf(stdout, "Left + Right button on exit.\n");
  do
  {
   if(MZ_DoMouse(s_Mouse) > 0)
   {
    s_KeepData = 1;
    fprintf(stdout, "\rx=%3d, y=%3d, gridx=%3d, gridy=%3d, button=0x%02x",
            s_Mouse->PositionX, s_Mouse->PositionY, s_Mouse->GridX, s_Mouse->GridY, s_Mouse->Button);
    fflush(stdout);
   }
   else
   {
    if(s_KeepData == 1)
    {
     s_KeepData = 0;
     fprintf(stdout, "\n");
    }
    fprintf(stdout, "\rWait mouse%20s", "");
    fflush(stdout);
   }
  }while((s_Mouse->Button & 0x03) != 0x03);
  fprintf(stdout, "\nEnd of mouse\n");
  s_Mouse = MZ_CloseMouse(s_Mouse);
 }
 else fprintf(stdout, "Can not open mouse !\n");
 return(s_Return);
}

/* End of source */


  • ¾Æ·¡ÀÇ ÇÔ¼ö´Â ¸¶¿ì½º Ä¿¼­ºñÆ®¸ÊÀ» ±×¸±¶§ »ç¿ëÇß´ø °Ì´Ï´Ù. ¹°·Ð ½ÇÁ¦ ºñÆ®¸Ê »Ó¸¸ ¾Æ´Ï¶ó ´Ù¾çÇÑ Ã³¸®·çƾÀÌ ÇÊ¿äÇÏÁö¸¸ ±âº»·çƾÀº ÀÌ°ÍÀ¸·Î ÃæºÐÇÕ´Ï´Ù.

static void MZ_DFB_BitmapXx16(t_DFB *s_HANDLE_DFB, int s_nBit, void *s_Buffer, int s_Color, int s_BackColor, i
nt s_x, int s_y)
{
 unsigned int s_Bit, s_CountY, s_CountX;
 unsigned long s_Blit;
 for(s_CountY = s_y;s_CountY < (s_y + 16);s_CountY++, ((unsigned long *)s_Buffer)++)
 {
  s_Blit = *((unsigned long *)s_Buffer);
  if(s_Blit == 0lu)
  {
   if(s_BackColor != (-1))MZ_DFB_DrawHLine(s_HANDLE_DFB, s_BackColor, s_x, s_x + (s_nBit - 1), s_CountY);
  }
  else
  {
   for(s_Bit = 0, s_CountX = (s_x + (s_nBit - 1));s_Bit < s_nBit;s_Bit++, s_CountX--)
   {
    if(*((unsigned long *)s_Buffer) & (1lu << s_Bit))
    {
     if(s_Color != (-1))MZ_DFB_DrawPixel(s_HANDLE_DFB, s_Color, s_CountX, s_CountY);
    }
    else if(s_BackColor != (-1))MZ_DFB_DrawPixel(s_HANDLE_DFB, s_BackColor, s_CountX, s_CountY);
   }
  }
 }
}



ID
Password
Join
It is better to wear out than to rust out.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2005-03-18 09:12:07
Processing time 0.0079 sec