Re[3]: мышь в dos
От: Plague Россия 177230800
Дата: 16.05.03 15:14
Оценка: 1 (1)
Здравствуйте, Доброжелатель, Вы писали:

Д>Все бы хорошо, но я, наверное, не сформулировал нормально вопрос, какие функции c(си) есть для работы с мышью под дос?...


Roman_M прав в С нет никаких функций работы с мышью
но если под дос то следует использовать досовый драйвер, который вешается на Int 33h
использовать не обязательно асмом, можно используя библиотеки поставляемые с различными компиляторами...
пример под Watcom C/C++ под DOS4GW экстендер:

      /*
          MOUSE.C - The following program demonstrates how
          to use the mouse interrupt (0x33) with DOS/4GW.

          Compile and link: wcl386 /l=dos4g mouse
      */
      #include <stdio.h>
      #include <dos.h>
      #include <i86.h>

      int right_button = 0;
      int mouse_event = 0;
      int mouse_code = 0;
      int mouse_cx = 0;
      int mouse_dx = 0;

      /* Set up data buffer for mouse cursor bitmap */
      unsigned short cursor[] =
      {
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000,
          0x0001, 0x0200, 0x0000, 0x0000
      };

      #pragma off (check_stack)
      void _loadds far click_handler (int max, int mcx, int mdx)
      {
      #pragma aux click_handler parm [EAX] [ECX] [EDX]
              mouse_event = 1;
              mouse_code = max;
              mouse_cx = mcx;
              mouse_dx = mdx;
              if( mouse_code & 8 ) right_button = 1;
      }
      #pragma on (check_stack)

      void main( void )
      {
          struct SREGS sregs;
          union REGS inregs, outregs;
          int installed = 0;
          int orig_mode = 0;
          unsigned short far *ptr;
          int (far *function_ptr)();

          segread(&sregs);

          /* get original video mode */

          inregs.w.ax = 0x0f00;
          int386( 0x10, &inregs, &outregs );

          printf( "Current Mode = %u\n",
                  orig_mode=outregs.h.al );

          /* check for mouse driver */

          inregs.w.ax = 0;
          int386 (0x33, &inregs, &outregs);
          if( installed = (outregs.w.ax == -1) )
              printf( "Mouse installed...\n" );
          else
              printf( "Mouse NOT installed...\n" );

          if( installed ) {

              /* goto graphics mode */

              inregs.h.ah = 0x00;
              inregs.h.al = 0x4;
              int386( 0x10, &inregs, &outregs );

              /* show mouse cursor */

              inregs.w.ax = 0x1;
              int386( 0x33, &inregs, &outregs );

              /* set mouse cursor form */

              inregs.w.ax = 0x9;
              inregs.w.bx = 0x0;
              inregs.w.cx = 0x0;
              ptr = cursor;
              inregs.x.edx = FP_OFF( ptr );
              sregs.es     = FP_SEG( ptr );
              int386x( 0x33, &inregs, &outregs, &sregs );

              /* install click watcher */

              inregs.w.ax = 0xC;
              inregs.w.cx = 0x0002 + 0x0008;
              function_ptr = click_handler;
              inregs.x.edx = FP_OFF( function_ptr );
              sregs.es     = FP_SEG( function_ptr );
              int386x( 0x33, &inregs, &outregs, &sregs );

              while( !right_button ) {
                  if( mouse_event ) {
                      printf( "Event = %x : CX = %u DX = %u\n",
                               mouse_code, mouse_cx, mouse_dx );
                      mouse_event = 0;
                  }
              }
          }

          /* check installation again (to clear watcher) */

          inregs.w.ax = 0;
          int386( 0x33, &inregs, &outregs );
          if( outregs.w.ax == -1 )
              printf( "DONE : Mouse still installed...\n" );
          else
              printf( "DONE : Mouse NOT installed...\n" );

          inregs.h.ah = 0x00;
          inregs.h.al = orig_mode;
          int386( 0x10, &inregs, &outregs );
    }
... << RSDN@Home 1.0 beta 7a >>
Re: мышь в dos
От: rastoman  
Дата: 28.05.03 08:35
Оценка: 1 (1)
Основные функ-ции работают, остальные не тестил пока, давно писал....

#include <dos.h>
#include <bios.h>
#include <iostream.h>
#include "cursor.h" — содержит матрицы курсоров

#define LeftButton 1
#define RightButton 2
#define CenterButton 4
#define AnyButton 7

#define TextRatioX 8
#define TextRatioY 8

#define true 1
#define false 0


struct MouseItemType
{
int X1,Y1,X2,Y2;
unsigned int Button;
unsigned int Key;
};

class mouse_c
{

public:


/* Инициация мыши */
char Is(void); // Возвращает истину если мышь доступна
char Init(void); // Инициализация мыши
void SetPage(char page); // Устанавливает страницу для мыши
char GetPage(void); // Возвращает страницу мыши
void SetStepToPixel(int hor, int ver); // Чувствительность мыши
void GetStepToPixel(int* hor, int* ver);// Возвращает чувствительность
void SetDoubleSpeed(unsigned int speed); // Устанавливает порог удвоения скорости
unsigned int GetDoubleSpeed(void); // Возвращает порог удвоения скорости
void Destroit(void);
void Info(unsigned char *verh,unsigned char *verl,unsigned char *type,unsigned char *inter);

/* Координаты */
char TextCooX(int x); // Возвращает текстовую к-у по вертик.
char TextCooY(int y); // Возвращает текстовую к-у по вертик.
int GraphCooX(char x); // Возвращает вирт к-ту по текстовой
int GraphCooY(char y); // Возвращает вирт к-ту по текстовой
void WhereXY(int* x,int* y); // Возвращает в-е к-ты указателя
void GotoXY(int x,int y); // Переводит указатель — вирт-е коорд.
char WhereX(void); // Возвращает текстовую коод-ту
char WhereY(void); // Возвращает текстовую коод-ту
char In(int x1,int y1,int x2,int y2); //True, если указатель в прямоуг-ке

/* Состояния кнопок */
unsigned int NumButton(void); // Количество кнопок мыши
void GetState(unsigned int* butt,unsigned int* x,unsigned int* y); // Состояние мыши
// butt — флаг состояния кнопок
// x,y — текущие вирт-е коорд-ты
char Pressed(void); // True, если нажата любая кнопка
void ButtPressed(int butt,int* stat,int* count,int* x, int* y);
// Возвращает инфо о нажатой клавише
// stat — состояние клавиш
// count — количество нажатий
// x,y — координаты
void ButtReleased(int butt,int* stat,int* count,int* x, int* y);
// Возвращает инфо о отпущенной клавише
// stat — состояние клавиш
// count — количество нажатий
// x,y — координаты

/* Окна */
void Window(int x1,int y1,int x2,int y2); // окно для мыши
void Screen(void); // окно во весь экран

/* Форма указателя */
void Show(void);
void Hide(void);
void TextCursor(unsigned int scrmask,unsigned int curmask);
void Blink(int yup,int ydn);
void GraphCursor(unsigned int far* scrcurmask,int x,int y);

/* Сохранение/восстановление состояния */
unsigned int BuffSize(void);
void Save(unsigned char far* Buff);
void Restore(unsigned char far* Buff);

/* Эмуляция клавы */
void SetItem(char NItem,MouseItemType* It); // Устанавливает эл-ты для выбора мышью
// NItem — Количество элементов
// Items — массив
void AddItem(MouseItemType *Item); // Добавляет ещё один элемент
void ClearItems(void);
void GetItem(char* NItem,MouseItemType* Items);
char KeyOrMousePressed(void); // Истина если нажата клавиша или мышь
unsigned int ReadKeyOrMouse(void); // Символ наж-й клавиши или выбр-й опции

private:
void activ(void);
MouseItemType *PItems;
char Present;
char NItem;
char Visible;
unsigned int NButton;
int x1m;
int x2m;
int y1m;
int y2m;
unsigned int speed2;
int VerRat;
int HorRat;
}Mouse;

void mouse_c::activ(void)
{
Present=false;
NItem=0;
Visible=0;
x1m=0;
x2m=639;
y1m=0;
y2m=199;
speed2=128;
VerRat=8;
HorRat=8;
NButton=0;
}

char mouse_c::Is(void)
{
if (Present) return true;
else
return false;
}

char mouse_c::Init(void)
{
activ();
asm mov ax,0
asm int 33h
NButton=_BL;
if (_AX!=0)
{
Present=true;
ClearItems();
SetPage(0);
Hide();
Screen();
return true;
}
return false;
}

void mouse_c::Destroit(void)
{
if (Present)
{
asm mov ax,0x1F;
asm int 33h;
Present=false;
}
}

void mouse_c::Info(unsigned char *verh,unsigned char *verl,unsigned char *type,unsigned char *inter)
{
if (Present)
{
asm mov ax,24h;
asm int 33h;
*verh=_BH;
*verl=_BL;
*type=_CH;
// 1 — Bus Mouse;
// 2 — Serial Mouse;
// 3 — Inport Mouse;
// 4 — PS/2 Mouse;
// 5 — HP Mouse;
*inter=_CL;
// 0 — IBM PS/2;
// 2,3,4,5,7 — IBM PC.
}
else
{
*verh=0;
*verl=0;
*type=0;
*inter=-1;
}
}

void mouse_c::SetPage(char page)
{
asm mov ax,1Dh
_BL=page;
asm mov bh,0
asm int 33h
}

char mouse_c::GetPage(void)
{
asm mov ax,1Eh
asm int 33h
return _BL;
}

void mouse_c::SetStepToPixel(int hor, int ver)
{
if (Present)
{
asm mov ax,0Fh
HorRat=_CX=hor&0x7FFF;
VerRat=_DX=ver&0x7FFF;
asm int 33h
}
}

void mouse_c::GetStepToPixel(int* hor, int* ver)
{
if (Present)
{
*hor=HorRat;
*ver=VerRat;
}
}

void mouse_c::SetDoubleSpeed(unsigned int speed)
{
if (Present)
{
asm mov ax,13h
_DX=speed;
asm int 33h
speed2=speed;
}
}

unsigned int mouse_c::GetDoubleSpeed(void)
{
return speed2;
}

char mouse_c::TextCooX(int x)
{
return (unsigned char)(x/TextRatioX);
}

char mouse_c::TextCooY(int y)
{
return (unsigned char)(y/TextRatioY);
}

int mouse_c::GraphCooX(char x)
{
return (int)x*TextRatioX;
}

int mouse_c::GraphCooY(char y)
{
return (int)y*TextRatioY;
}

void mouse_c::WhereXY(int* x,int* y)
{
if (Present)
{
asm mov ax,3
asm int 33h
*x=_CX;
*y=_DX;
}
else
{
*x=-1;
*y=-1;
}
}

void mouse_c::GotoXY(int x,int y)
{
if (Present)
{
asm mov ax,4
_CX=x;
_DX=y;
asm int 33h
}
}

char mouse_c::WhereX(void)
{
if (Present)
{
asm mov ax,3
asm int 33h
return TextCooX(_CX);
}
else
return -1;
}

char mouse_c::WhereY(void)
{
if (Present)
{
asm mov ax,3
asm int 33h
return TextCooX(_DX);
}
else
return -1;
}

char mouse_c::In(int x1,int y1,int x2,int y2)
{
if (Present)
{
asm mov ax,3
asm int 33h
if ((_CX>=x1)&&(_CX<=x2)&&(_DX<=y2)&&(_DX>=y1))
return true;
}
return false;
}

unsigned int mouse_c::NumButton(void)
{
return NButton;
}

void mouse_c::GetState(unsigned int* butt,unsigned int* x,unsigned int* y)
{
if (Present)
{
asm mov ax,3
asm int 33h
*butt=(int)_BL;
*x=_CX;
*y=_DX;
}
else
{
*butt=11999;
*x=10000;
*y=10000;
}
}

char mouse_c::Pressed(void)
{
if (Present)
{
asm mov ax,3
asm int 33h
if (_BX!=0) return true; else return false;
}
else return false;

}

void mouse_c::ButtPressed(int butt,int* stat,int* count,int* x, int* y)
{
if (Present)
{
asm mov ax,5
_BX=butt;
asm int 33h
*count=_BX;
*x=_CX;
*y=_DX;
*stat=_AX;
}
}

void mouse_c::ButtReleased(int butt,int* stat,int* count,int* x, int* y)
{
if (Present)
{
asm mov ax,6
_BX=butt;
asm int 33h
*count=_BX;
*x=_CX;
*y=_DX;
*stat=_AX;
}
}

void mouse_c::Window(int x1,int y1,int x2,int y2)
{
if (Present)
{
x1m=x1;x2m=x2;y1m=y1;y2m=y2;
asm mov ax,7
_CX=x1;
_DX=x2;
asm int 33h
asm mov ax,8
_CX=y1;
_DX=y2;
asm int 33h
}
}

void mouse_c::Screen(void)
{
int x2,y2;
if (Present)
{
asm mov ah,0xF
asm int 10
switch (_AL)
{
case 1,4,5,13: x2=319; y2=199; break;
case 15,16: x2=639; y2=349; break;
case 17,18: x2=639; y2=479; break;
default: x2=639; y2=199;
}

}
Window(0,0,x2,y2);
}

void mouse_c::Show(void)
{
if ((Present)&&(Visible!=1))
{
asm mov ax,1
asm int 33h
Visible=1;
}
}

void mouse_c::Hide(void)
{
if ((Present)&&(Visible==1))
{
asm mov ax,2
asm int 33h
Visible=0;
}
}

void mouse_c::TextCursor(unsigned int scrmask, unsigned int curmask)
{
if (Present)
{
asm mov ax,0xA
asm mov bx,0
_CX=scrmask;
_DX=curmask;
asm int 33h
}
}

void mouse_c::Blink(int yup,int ydn)
{
if (Present)
{
asm mov ax,0xA
asm mov bx,1
_CX=yup;
_DX=ydn;
asm int 33h
}
}

void mouse_c::GraphCursor(unsigned int far* scrcurmask,int x,int y)
{
if (Present)
{
asm mov ax,9
_BX=x;
_CX=y;
_ES=FP_SEG(scrcurmask);
_DX=FP_OFF(scrcurmask);
asm int 33h
}
}

unsigned int mouse_c::BuffSize(void)
{
if (Present)
{
asm mov ax,15h
asm mov bx,0
asm int 33h
return _BX;
}
return false;
}

void mouse_c::Save(unsigned char far* Buff)
{
if (Present)
{
asm mov ax,16h
_ES=FP_SEG(Buff);
_DX=FP_OFF(Buff);
asm int 33h
}
}

void mouse_c::Restore(unsigned char far* Buff)
{
if (Present)
{
asm mov ax,17h
_ES=FP_SEG(Buff);
_DX=FP_OFF(Buff);
asm int 33h
}
}


void mouse_c::SetItem(char NItem_,MouseItemType* It)
{
if (Present)
{
ClearItems();
PItems=new MouseItemType[NItem_];
memcpy(PItems,It,NItem_*sizeof(MouseItemType));
NItem=NItem_;
}
}

void mouse_c::AddItem(MouseItemType *Item)
{
MouseItemType *ptr,*ptr1;
int k;
if (Present)
{
k=NItem;
ptr=new MouseItemType[k+1];
ptr1=ptr+1;
memcpy(ptr,PItems,k*sizeof(MouseItemType));
memcpy(ptr1,Item,sizeof(MouseItemType));
PItems=ptr;
NItem=k+1;
delete ptr;
}
}


void mouse_c::ClearItems(void)
{
PItems=new MouseItemType[1];
delete PItems;
NItem=0;
}


void mouse_c::GetItem(char* NItem_,MouseItemType* Items)
{
if (Present)
{
*NItem_=NItem;
memcpy(Items,PItems,NItem*sizeof(MouseItemType));
}
}


char mouse_c::KeyOrMousePressed(void)
{
int b,k;
char MouseActive;
if (bioskey(1)!=0) return true;
else
{
asm mov ax,3
asm int 33h
b=_BX;
if ((_BX!=0)&&(NItem!=0))
{
MouseActive=false;
for (k=0;k<=NItem-1;k++)
{
if (MouseActive==false)
if ((In(GraphCooX(PItems[k].X1),GraphCooX(PItems[k].Y1),
GraphCooY(PItems[k].X2),GraphCooX(PItems[k].Y2))==true)&&
(b==PItems[k].Button)) MouseActive=true;
} // for
return MouseActive;
} //if
else return false;
}
}


unsigned int mouse_c::ReadKeyOrMouse(void)
{
unsigned char k;
unsigned int b,bb;
char MouseActive;
unsigned int result=-1;

if (Present)
{
loop:
if (bioskey(1)!=0) return bioskey(0);
else
if (NItem!=0)
{
MouseActive=false;
asm mov ax,3
asm int 33h
bb=_BX;
if (bb!=0)
for (k=0;k<=NItem-1;k++)
{
if (MouseActive==false)
{
if ((bb==PItems[k].Button)&&In(GraphCooX(PItems[k].X1),GraphCooX(PItems[k].Y1),
GraphCooX(PItems[k].X2),GraphCooX(PItems[k].Y2)))
{
MouseActive=true;
result=(unsigned int)(PItems[k].Key);
}
}//if
}//for
if (MouseActive==0) goto loop;
}//NItem

else result=bioskey(0);
}
return result;
}

"cursor.h" — содержит матрицы курсоров
к примеру:
static unsigned CurDefault[] =
{
0x3FFF, /* 0011111111111111 */
0x1FFF, /* 0001111111111111 */
0x0FFF, /* 0000111111111111 */
0x07FF, /* 0000011111111111 */
0x03FF, /* 0000001111111111 */
0x01FF, /* 0000000111111111 */
0x00FF, /* 0000000011111111 */
0x007F, /* 0000000001111111 */
0x003F, /* 0000000000111111 */
0x001F, /* 0000000000011111 */
0x01FF, /* 0000000111111111 */
0x10FF, /* 0001000011111111 */
0x30FF, /* 0011000011111111 */
0x787F, /* 0111100001111111 */
0xF87F, /* 1111100001111111 */
0xFC7F, /* 1111110001111111 */

0x0000, /* 0000000000000000 */
0x4000, /* 0100000000000000 */
0x6000, /* 0110000000000000 */
0x7000, /* 0111000000000000 */
0x7800, /* 0111100000000000 */
0x7C00, /* 0111110000000000 */
0x7E00, /* 0111111000000000 */
0x7F00, /* 0111111100000000 */
0x7F80, /* 0111111110000000 */
0x7C00, /* 0111110000000000 */
0x6C00, /* 0110110000000000 */
0x4600, /* 0100011000000000 */
0x0600, /* 0000011000000000 */
0x0300, /* 0000001100000000 */
0x0300, /* 0000001100000000 */
0x0000 /* 0000000000000000 */
};
мышь в dos
От: Доброжелатель Россия  
Дата: 15.05.03 08:36
Оценка:
Кто может подскажите, какие функции припас Microsoft, для работы с мышью в досе?
Не все в этом мире можно выразить с помощью нулей и единиц...
Re: мышь в dos
От: Кодт Россия  
Дата: 15.05.03 08:58
Оценка:
Здравствуйте, Доброжелатель, Вы писали:

Д>Кто может подскажите, какие функции припас Microsoft, для работы с мышью в досе?


mouse.com

Обслуживает прерывание 33h (кажется) — набор функций.

Мониторит ком-порт на предмет посылок от мыши, и считает координаты.

Могу уточнить если ОЧЕНЬ надо.
(=^.^=) Neko ... << RSDN@Home 1.0 beta 7a >>

15.05.03 14:21: Перенесено модератором из 'C/C++' — ПК
Перекуём баги на фичи!
Re: мышь в dos
От: Plague Россия 177230800
Дата: 15.05.03 09:45
Оценка:
Здравствуйте, Доброжелатель, Вы писали:

Д>Кто может подскажите, какие функции припас Microsoft, для работы с мышью в досе?

ээ.. помниться интеррупты были... ээ
int 33h помоему... вот функции, номер в AL регистре:


Это если правильно понял ты пишешь досовую прогу а не "консольную"...
В консольной лучше через Win32API...
... << RSDN@Home 1.0 beta 7a >>
Re[2]: мышь в dos
От: Доброжелатель Россия  
Дата: 15.05.03 10:34
Оценка:
Все бы хорошо, но я, наверное, не сформулировал нормально вопрос, какие функции c(си) есть для работы с мышью под дос?...
Не все в этом мире можно выразить с помощью нулей и единиц...
Re[3]: мышь в dos
От: Roman_M rgmroman.narod.ru
Дата: 16.05.03 06:09
Оценка:
Здравствуйте, Доброжелатель, Вы писали:

Д>Все бы хорошо, но я, наверное, не сформулировал нормально вопрос, какие функции c(си) есть для работы с мышью под дос?...


В стандартном C — никаких.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.