home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 3,019 of 4,675   
   Jens Kallup to All   
   Re: programming on PS2 mouse controller    
   11 Oct 17 15:27:33   
   
   From: kallup.jens@nospicedham.web.de   
      
   Hello,   
      
   I use following code...   
   But the mouse is doing random things   
      
      
   #include    
   #include    
      
   static unsigned short * VideoMem = (unsigned short *)0xb8000;   
      
   #define CURRENT_YEAR        2017        // Change this each year!   
      
   int century_register = 0x00;            // Set by ACPI table parsing   
   code if possible   
      
   unsigned char second;   
   unsigned char minute;   
   unsigned char hour;   
   unsigned char day;   
   unsigned char month;   
   unsigned int  year;   
      
   unsigned char  CrtColor;        // text mode color   
   unsigned char  CrtBuffer;       // sign   
      
   unsigned short CrtXpos;   
   unsigned short CrtYpos;   
      
   unsigned char  CrtMenuFlagOk = 0;   
      
   enum {   
        cmos_address = 0x70,   
        cmos_data    = 0x71   
   };   
      
   enum {   
        CMDKEY_F1 = 0x0100,   
        CMDKEY_F2 = 0x0200,   
        CMDKEY_F3 = 0x0300   
   };   
      
   void ListLicense(void);   
   typedef void (*list_func)(void);   
   struct listbox_items {   
        char name[20];   
        short key_cmd;   
        list_func func;   
   } listbox_items[] = {   
        { "Lizenz      ", CMDKEY_F1, ListLicense },   
        { "Windows 2017", CMDKEY_F2, ListLicense },   
        { "DOS     2017", CMDKEY_F3, ListLicense },   
   };   
      
   struct listbox_items listitems;   
      
   int get_update_in_progress_flag()   
   {   outportb(cmos_address, 0x0a);   
        return (inportb(cmos_data) & 0x80);   
   }   
      
   unsigned char get_RTC_register(int reg)   
   {   outportb(cmos_address, reg);   
        return inportb(cmos_data);   
   }   
      
   void read_rtc() {   
        unsigned char century;   
        unsigned char last_second;   
        unsigned char last_minute;   
        unsigned char last_hour;   
        unsigned char last_day;   
        unsigned char last_month;   
        unsigned char last_year;   
        unsigned char last_century;   
        unsigned char registerB;   
      
        // Note: This uses the "read registers until you get the same   
   values twice in a row" technique   
        //       to avoid getting dodgy/inconsistent values due to RTC updates   
      
        while (get_update_in_progress_flag());   // Make sure an update   
   isn't in progress   
      
        second  = get_RTC_register(0x00);   
        minute  = get_RTC_register(0x02);   
        hour    = get_RTC_register(0x04);   
        day     = get_RTC_register(0x07);   
        month   = get_RTC_register(0x08);   
        year    = get_RTC_register(0x09);   
      
        if (century_register != 0) {   
            century = get_RTC_register(century_register);   
        }   
      
        do {   
            last_second = second;   
            last_minute = minute;   
            last_hour = hour;   
            last_day = day;   
            last_month = month;   
            last_year = year;   
            last_century = century;   
      
            while (get_update_in_progress_flag());           // Make sure   
   an update isn't in progress   
      
            second = get_RTC_register(0x00);   
            minute = get_RTC_register(0x02);   
            hour   = get_RTC_register(0x04);   
            day    = get_RTC_register(0x07);   
            month  = get_RTC_register(0x08);   
            year   = get_RTC_register(0x09);   
      
            if (century_register != 0) {   
                century = get_RTC_register(century_register);   
            }   
        } while ( (last_second != second)   
                ||(last_minute != minute)   
                ||(last_hour   != hour)   
                ||(last_day    != day)   
                ||(last_month  != month)   
                ||(last_year   != year)   
                ||(last_century != century) );   
      
        registerB = get_RTC_register(0x0B);   
      
        // Convert BCD to binary values if necessary   
      
        if (!(registerB & 0x04))   
        {   second = (second & 0x0F) + ((second / 16) * 10);   
            minute = (minute & 0x0F) + ((minute / 16) * 10);   
            hour   = ( (hour & 0x0F) + (((hour & 0x70) / 16) * 10) ) |   
   (hour & 0x80);   
            day    =   ( day & 0x0F) + ((day / 16) * 10);   
            month  =  (month & 0x0F) + ((month / 16) * 10);   
            year   =  ( year & 0x0F) + ((year / 16) * 10);   
      
            if (century_register != 0) {   
                century = (century & 0x0F) + ((century / 16) * 10);   
            }   
        }   
      
        // Convert 12 hour clock to 24 hour clock if necessary   
        if (!(registerB & 0x02) && (hour & 0x80)) {   
            hour = ((hour & 0x7F) + 12) % 24;   
        }   
      
        // Calculate the full (4-digit) year   
        if (century_register != 0) {   
            year += century * 100; } else {   
            year += ( CURRENT_YEAR / 100) * 100;   
            if(year < CURRENT_YEAR) year += 100;   
        }   
   }   
      
      
   void   
   CrtSetCursor(int col, int row)   
   {   
        unsigned short position = (row*80) + col;   
      
        // cursor HIGH port to vga INDEX register   
        outportb(0x3D4, 0x0E);   
        outportb(0x3D5, (unsigned char)((position>>8)&0xFF));   
      
        // cursor LOW port to vga INDEX register   
        outportb(0x3D4, 0x0F);   
        outportb(0x3D5, (unsigned char)(position&0xFF));   
      
        CrtXpos = col;   
        CrtYpos = row;   
   };   
      
   unsigned char CrtGetColor (void) { return CrtColor ; }   
   unsigned char CrtGetBuffer(void) { return CrtBuffer; }   
      
   unsigned short CrtGetXpos(void) { return CrtXpos; }   
   unsigned short CrtGetYpos(void) { return CrtYpos; }   
      
   void CrtSetColor (unsigned char color) { CrtColor  = color; }   
   void CrtSetBuffer(unsigned char buffr) { CrtBuffer = buffr; }   
      
   void   
   draw_box(int x, int y, int w, int h)   
   {   
        unsigned int cnt  = 0;   
        unsigned int oldx = 0;   
        unsigned int oldy = 0;   
      
        oldx = _mouse_x;   
        oldy = _mouse_y;   
      
        CrtSetCursor(x,y);   
        for (cnt=x;cnt 0)   
        CrtSetCursor(oldx,oldy);   
   }   
      
   void   
   draw_background(void)   
   {   
        short cnty = 0;   
        short cntx = 0;   
      
        for (cnty=1;cnty<24;cnty++)   
        for (cntx=0;cntx<80;cntx++)   
        VideoMem[ (cnty*80) + cntx] = 0xb0b0;   
   }   
      
   void draw_menu(void)   
   {   
        unsigned short pos  = 0;   
        unsigned int   oldx = 0;   
        unsigned int   oldy = 0;   
      
        char txt[81] =   
   "                               ReactOS - Version 0.4.6   
            ";   
        oldx = _mouse_x;   
        oldy = _mouse_y;   
      
        CrtSetCursor(0,0);   
        CrtSetColor(0x3f);   
      
        for (pos=0;pos 0)   
        CrtSetCursor(oldx,oldy);   
   }   
      
   void   
   draw_status(void)   
   {   
        unsigned short pos  = 0;   
        unsigned int   oldx = 0;   
        unsigned int   oldy = 0;   
      
        char txt[80] =   
   "   Forked @paule32  -  2017-10-01  Notice: The source codes are for   
   ReactOs     ";   
      
        oldx = _mouse_x;   
        oldy = _mouse_y;   
      
        CrtSetCursor(0,24);   
        CrtSetColor(0x3f);   
      
        for (pos=0;pos

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca