Subversion Repositories pentevo

Rev

Rev 119 | Rev 151 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3.  
  4. #include <util/delay.h>
  5.  
  6. #include "mytypes.h"
  7. #include "pins.h"
  8. #include "main.h"
  9. #include "ps2.h"
  10. #include "rs232.h"
  11. #include "zx.h"
  12. #include "spi.h"
  13. #include "atx.h"
  14. #include "rtc.h"
  15.  
  16. ISR(TIMER2_OVF_vect)
  17. {
  18.         static UBYTE counter=0x00;
  19.         static BYTE dir=0x01;
  20.         static BYTE ocr=0x00;
  21.         static BYTE scankbd=0;
  22.         static BYTE cskey=0xff;
  23.  
  24.         counter++; // just fucking shit to fadein-fadeout LED :-)))
  25.         if( counter&128 )
  26.         {
  27.                 counter=0;
  28.  
  29.                 ocr += dir;
  30.                 if( (ocr==(-1)) && (dir==(-1)) )
  31.                 {
  32.                         dir = -dir;
  33.                         ocr = 1;
  34.                 } else if( (ocr==0) && (dir==1) )
  35.                 {
  36.                         dir = -dir;
  37.                         ocr = 0xFF;
  38.                 }
  39.  
  40.                 OCR2 = ocr;
  41.         }
  42.  
  43.         // PS/2 keyboard timeout tracking
  44.         if( (ps2keyboard_count<11) && (ps2keyboard_count!=0) ) // track timeout for PS/2 keyboard
  45.         {
  46.                 if( ps2keyboard_timeout ) ps2keyboard_timeout--;
  47.  
  48.                 if( !ps2keyboard_timeout )
  49.                 {
  50.                         ps2keyboard_count = 11;
  51.                 }
  52.         }
  53.  
  54.         // pause for keyboard CS|SS
  55.         if( shift_pause )
  56.                 shift_pause--;
  57.  
  58.         // PS/2 mouse timeout tracking
  59.         if( (ps2mouse_count<12) && (ps2mouse_count!=0) )
  60.         {
  61.                 if( ps2mouse_timeout ) ps2mouse_timeout--;
  62.                 else
  63.                 {
  64.                         ps2mouse_count = 12;
  65.                 }
  66.         }
  67.  
  68.         //check soft reset
  69.         if ( SOFTRES_PIN & (1<<SOFTRES) )
  70.         {
  71.                 //not pressed
  72.                 atx_counter = 0;
  73.         }
  74.         else
  75.         {
  76.                 //pressed
  77.                 atx_counter++;
  78.         }
  79.  
  80.         if ( scankbd==0 )
  81.         {
  82.                 UBYTE tmp;
  83.                 tmp = PINA;
  84.                 zx_realkbd[5] = tmp & cskey;
  85.                 cskey = tmp | 0xfe;
  86.                 DDRC  = 0b00010000;
  87.                 PORTC = 0b11001111;
  88.                 zx_realkbd[10] = 4;
  89.                 scankbd=4;
  90.         }
  91.         else if ( scankbd==1 )
  92.         {
  93.                 zx_realkbd[6] = PINA;
  94.                 DDRC  = 0b00000001;
  95.                 PORTC = 0b11011110;
  96.                 scankbd=0;
  97.         }
  98.         else if ( scankbd==2 )
  99.         {
  100.                 zx_realkbd[7] = PINA;
  101.                 DDRC  = 0b00000010;
  102.                 PORTC = 0b11011101;
  103.                 scankbd=1;
  104.         }
  105.         else if ( scankbd==3 )
  106.         {
  107.                 zx_realkbd[8] = PINA;
  108.                 DDRC  = 0b00000100;
  109.                 PORTC = 0b11011011;
  110.                 scankbd=2;
  111.         }
  112.         else if ( scankbd==4 )
  113.         {
  114.                 zx_realkbd[9] = PINA;
  115.                 DDRC  = 0b00001000;
  116.                 PORTC = 0b11010111;
  117.                 scankbd=3;
  118.         }
  119. }
  120.  
  121.  
  122. ISR(INT4_vect) // receive PS/2 keyboard data. TODO: sending mode...
  123. {
  124.         ps2keyboard_shifter >>= 1;
  125.         if( (PS2KBDAT_PIN&(1<<PS2KBDAT)) ) ps2keyboard_shifter |= 0x8000;
  126.  
  127.         if( !(--ps2keyboard_count) )
  128.         {
  129.                 PS2KBCLK_PORT &= ~(1<<PS2KBCLK);
  130.                                 PS2KBCLK_DDR  |= (1<<PS2KBCLK);
  131.  
  132.                                 EIFR = (1<<INTF4); // clr any additional int which can happen when we pulldown clock pin
  133.         }
  134.  
  135.         ps2keyboard_timeout = PS2KEYBOARD_TIMEOUT;
  136.  
  137.         //
  138.         EIFR = (1<<INTF4);
  139. }
  140.  
  141.  // receive/send PS/2 mouse data
  142. ISR(INT5_vect)
  143. {
  144.         if( (flags_register&FLAG_PS2MOUSE_DIRECTION) != 0 )
  145.         {
  146.                 //send mode
  147.                 if( --ps2mouse_count )
  148.                 {
  149.                         if ( ps2mouse_shifter&1 ) PS2MSDAT_PORT |= (1<<PS2MSDAT);
  150.                         else PS2MSDAT_PORT &= ~(1<<PS2MSDAT);
  151.  
  152.                         ps2mouse_shifter >>= 1;
  153.  
  154.                         if( ps2mouse_count == 11 )
  155.                         {
  156.                                 //first interrupt is programmed
  157.                                 PS2MSDAT_DDR |= (1<<PS2MSDAT);   //ps2mouse data pin to output mode
  158.                                 _delay_us(200);  //hold ps2mouse clk pin ~200us
  159.                                 PS2MSCLK_PORT |= (1<<PS2MSCLK);  //release ps2mouse clk pin
  160.                                 PS2MSCLK_DDR  &= ~(1<<PS2MSCLK);
  161.                         }
  162.                         else if( ps2mouse_count == 1)
  163.                         {
  164.                                 PS2MSDAT_DDR &= ~(1<<PS2MSDAT); //ps2mouse data pin to input mode
  165.                         }
  166.                 }
  167.                 else
  168.                 {
  169.                         //ack received
  170.                         PS2MSCLK_PORT &= ~(1<<PS2MSCLK);
  171.                         PS2MSCLK_DDR  |= (1<<PS2MSCLK);
  172.                 }
  173.         }
  174.         else
  175.         {
  176.                 //receive mode
  177.                 ps2mouse_shifter >>= 1;
  178.                 if( (PS2MSDAT_PIN&(1<<PS2MSDAT)) ) ps2mouse_shifter |= 0x8000;
  179.  
  180.                 if( (--ps2mouse_count) == 1 )
  181.                 {
  182.                         PS2MSCLK_PORT &= ~(1<<PS2MSCLK);
  183.                         PS2MSCLK_DDR  |= (1<<PS2MSCLK);
  184.                         ps2mouse_count = 0;
  185.                 }
  186.         }
  187.  
  188.         EIFR = (1<<INTF5);
  189.  
  190.         //set timeout
  191.         ps2mouse_timeout = PS2MOUSE_TIMEOUT;
  192. }
  193.  
  194.  // SPI_INT
  195. ISR(INT6_vect)
  196. {
  197.         flags_register |= FLAG_SPI_INT;
  198.         EIFR = (1<<INTF6);
  199. }
  200.  
  201.  // RTC up data
  202. ISR(INT7_vect)
  203. {
  204.         gluk_inc();
  205.  
  206.         EIFR = (1<<INTF7);
  207. }
  208.  
  209.