Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. /*
  2.         OS LAB assignment 1
  3. */
  4. #include <stdio.h>
  5. #include<stdlib.h>
  6. #include<conio.h>
  7. #include <dos.h>
  8.  
  9. void interrupt(*Int9Save) (void);
  10. void interrupt(*Int8Save) (void);
  11. void interrupt(*Int1Save) (void);   /* Pointer to function to store TRAP interrupt */
  12.  
  13. // Variables
  14. volatile unsigned int secISR;
  15. volatile unsigned int secISR_rec;
  16. volatile unsigned int secGLOBAL;
  17. int ISR[256];
  18. int reqISR;
  19. int IP;
  20. int count;
  21.  
  22. //Override deafult interrupt
  23. void interrupt h1(void){
  24.    
  25.     int idx;
  26.    
  27.       asm {
  28.         push ax
  29.         mov ax,[BP+2]
  30.         mov IP,ax
  31.         pop ax
  32.       }
  33.          
  34.       idx=IP/4;
  35.       ISR[idx]++;
  36.      
  37.       if(count==4){
  38.           if(reqISR>=0 && reqISR<=255)
  39.                 printf("ISR[%d] = %d",reqISR,ISR[reqISR]);
  40.            
  41.         count=0;
  42.         reqISR= -1;      
  43.       }
  44. }
  45.  
  46. void interrupt h8(void){
  47.    
  48.     asm{
  49.         PUSHF
  50.         CALL DWORD PTR Int8Save
  51.     }//asm
  52.     printf("DEBUGGGG\n");
  53.     secGLOBAL--; /*counter*/
  54.     secISR_rec--;
  55.    
  56.     if (secISR_rec<=0){ // if secISR_rec passed, start again
  57.         secISR_rec=secISR;
  58.        
  59.         count=0;
  60.         reqISR= -1;    
  61.     }
  62. }
  63.  
  64. void interrupt h9(void) {
  65.    
  66.     unsigned char c1;
  67.    
  68.     asm{
  69.         PUSH AX
  70.         MOV AH,0
  71.         INT 16h
  72.         MOV c1,AL
  73.         POP AX
  74.     }/* reading the button*/
  75.        
  76.             if(c1=='i' && count==0){
  77.                 count++;
  78.             }
  79.             else if(count==1 && c1<='2' && c1>='0'){
  80.                 count++;
  81.                 c1=(c1-'0')*100;
  82.                 reqISR=c1;
  83.             }
  84.             else if(count==2 && c1<='9' && c1>='0'){
  85.                 count++;
  86.                 c1=(c1-'0')*10;
  87.                 reqISR=reqISR+c1;
  88.             }
  89.             else if(count==3 && c1<='9' && c1>='0'){
  90.                 count++;
  91.                 c1=(c1-'0');
  92.                 reqISR=reqISR+c1;
  93.             }
  94. }
  95.  
  96. void interrupt_counter(int intTime, int time) {
  97.    
  98.     // give first values
  99.     secISR = intTime*182 / 10;
  100.     secGLOBAL = time*182 / 10;
  101.     secISR_rec=secISR;
  102.    
  103.    
  104.     Int9Save = getvect(9); // save old func
  105.     Int8Save = getvect(8); // save old func
  106.     Int1Save = getvect(1); // save old func
  107.    
  108.     setvect(9, h9);    // new func 
  109.     setvect(8, h8);    // new func 
  110.     setvect(1, h1);    // new func
  111.    
  112.         asm{//turn on the trap flag                                    
  113.                 pushf
  114.                 pop ax
  115.                 or ax,100000000B
  116.                 push ax
  117.                 popf
  118.         }
  119. }
  120. void main()
  121. {
  122.     int i;
  123.     count=0;
  124.     reqISR=-1;
  125.    
  126.     for(i=0;i<256;i++)
  127.         ISR[i]=0;
  128.        
  129.     interrupt_counter(5,20);
  130.    
  131.     while (secGLOBAL>0);
  132.    
  133.     for(i=0;i<256;i++)
  134.         printf("%d \n",ISR[i]);
  135.    
  136.     setvect(9, Int9Save);  // return to old func
  137.     setvect(8, Int8Save);  // return to old func
  138.     setvect(1, Int1Save);  // return to old func
  139.    
  140.         asm{
  141.             pushf
  142.             pop ax
  143.             and ax,1111111011111111B
  144.             push ax
  145.             popf
  146.         }
  147.    
  148.     system("PAUSE");
  149.    
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement