home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / pcw_c.zip / MSINTR.ASM < prev    next >
Assembly Source File  |  1991-12-16  |  8KB  |  157 lines

  1.               Page ,132
  2. ;****************************************************************
  3. ;* File Id.                       MSINTR.ASM.                   *
  4. ;* Author.                        Stan Milam.                   *
  5. ;* Date Written.                  7 Dec 89.                     *
  6. ;*                                                              *
  7. ;*            (c) Copyright 1989, 1990 by Stan Milam            *
  8. ;*                                                              *
  9. ;* Comments: Routines are the Microsoft C version of Turbo &    *
  10. ;* Power C version of intr().                                   *
  11. ;*                                                              *
  12. ;****************************************************************
  13. ;
  14.               Dosseg
  15. IFDEF POWERC
  16.               .Model    Large
  17. ELSE
  18.               .Model    Large,C
  19. ENDIF
  20.               .Data
  21. ;
  22. ;********************************************************************
  23. ;* This data will be copied onto the stack and modified at runtime  *
  24. ;* to generate the correct interrupt.                               *
  25. ;********************************************************************
  26. ;
  27. IntStart      Label     Byte
  28.               Int       21h
  29.               Retf
  30. IntLen        Equ       ($-IntStart)+1
  31. ;
  32. ;********************************************************************
  33. ;* Start the code segment by declaring some space to save the Bp    *
  34. ;* register while we modify the stack at runtime.                   *
  35. ;********************************************************************
  36.               .Code
  37. BpSave        Dw        ?
  38. ;
  39. ;********************************************************************
  40. ;*                               DoInt                              *
  41. ;*                                                                  *
  42. ;* This code will create a far return address of the code in the    *
  43. ;* stack and then return to it.                                     *
  44. ;*                                                                  *
  45. ;********************************************************************
  46.  
  47. DoInt         Proc      Near
  48.               Xchg      Bp,Cs:Word Ptr[BpSave]   ;Get Offset of code in Bp
  49.               Push      Ss                       ;Push Segment address of code
  50.               Sub       Bp,IntLen                ;Adjust for length of code
  51.               Push      Bp                       ;Push offset on stack
  52.               Add       Bp,IntLen                ;Restore Bp
  53.               Xchg      Bp,Cs:Word Ptr[BpSave]   ;And get Bp back
  54.               Retf                               ;Return to address on stack
  55. DoInt         Endp
  56. ;
  57. ;****************************************************************
  58. ;*                             Intr()                           *
  59. ;*                                                              *
  60. ;* MSC version of intr(), useful for interrupts and such. Used  *
  61. ;* mainly because we need to pass values in Bp and get values   *
  62. ;* from flags for keyboard routines.                            *
  63. ;*                                                              *
  64. ;* Now used with Turbo C also because the intr() function in    *
  65. ;* Turbo C has terrible bug and will trash your program if not  *
  66. ;* careful.                                                     *
  67. ;*                                                              *
  68. ;* struct REGPACK {                                             *
  69. ;*     unsigned  r_ax, r_bx, r_cx, r_dx, r_bp;                  *
  70. ;*     unsigned  r_si, r_di, r_ds, r_es, r_flags;               *
  71. ;* };                                                           *
  72. ;* void far Intr(int intno, struct REGPACK far *regp);          *
  73. ;****************************************************************
  74. ;
  75.               Public    Intr
  76. IFDEF POWERC
  77. Intr          Proc      Far
  78. intrno        Equ       [Bp + 6]
  79. regs          Equ       [Bp + 8]
  80.               Push      Bp
  81.               Mov       Bp,Sp
  82. ELSE
  83. Intr          Proc      intrno:word, regs:ptr
  84. ENDIF
  85.               Sub       Sp,IntLen           ;Reserve space on stack for code
  86.               Push      Ds
  87.               Push      Es
  88.               Push      Di
  89.               Push      Si
  90.               Mov       Ax,intrno           ;Get interrupt number
  91.               Mov       [IntStart + 1],Al   ;Use correct interrupt number
  92.               Mov       Cx,IntLen           ;# of bytes to copy onto stack
  93.               Push      Ss                  ;Set Es:Di to point into
  94.               Pop       Es                  ;the stack where we will
  95.               Mov       Di,Bp               ;copy the code and modify it
  96.               Sub       Di,IntLen           ;Move to beginning of reserve mem
  97.               Mov       Si,Offset IntStart  ;Get address of code to copy
  98.               Cld
  99.               Rep       Movsb               ;Copy Code onto Stack
  100.               Push      Bp                  ;Save Bp for later use
  101.               Pop       Cs:Word Ptr[BpSave] ;In the code segment.
  102.               Les       Bx,regs             ;Es:Bx points to regs structure
  103.               Mov       Cx,Word Ptr Es:[Bx + 4h]   ;Get Cx
  104.               Mov       Dx,Word Ptr Es:[Bx + 6h]   ; '' Dx
  105.               Mov       Bp,Word Ptr Es:[Bx + 8h]   ; '' Bp
  106.               Mov       Si,Word Ptr Es:[Bx + 10]
  107.               Mov       Di,Word Ptr Es:[Bx + 12]
  108.               Mov       Ds,Word Ptr Es:[Bx + 14]
  109.               Mov       Ax,Word Ptr Es:[Bx + 2h]   ;This is Bx-later on
  110.               Push      Bx                         ;Save Bx           
  111.               Push      Es                         ;and Es for later after
  112.                                                    ;the interrupt
  113.               Push      Ax                         ;Save val for Bx   
  114.               Mov       Ax,Word Ptr Es:[Bx + 0h]   ;Get Real Ax       
  115.               Mov       Es,Word Ptr Es:[Bx + 16]   ;Get Es               
  116.               Pop       Bx                         ;Get in Bx finally    
  117.               Push      Cs                         ;Do this for Power C
  118.               Call      DoInt                      ;Make near call       
  119. CodeRet:                                           ;Return from INT here 
  120.               Push      Es                         ;Must save these to get
  121.               Push      Bx                         ;  Return values back in
  122.               Push      Bp                         ;  Regs structure
  123.               Mov       Bp,Sp                                            
  124.               Mov       Bx,[Bp + 8]                ;Get Bx & Es 
  125.               Mov       Es,[Bp + 6]                ;From up above
  126.               Pop       Bp
  127.               Mov       Word Ptr Es:[Bx + 0h],Ax
  128.               Pop       Ax                         ;Pop of Bx
  129.               Mov       Word Ptr Es:[Bx + 2h],Ax   ;Store it
  130.               Mov       Word Ptr Es:[Bx + 4h],Cx
  131.               Mov       Word Ptr Es:[Bx + 6h],Dx
  132.               Mov       Word Ptr Es:[Bx + 8h],Bp
  133.               Mov       Word Ptr Es:[Bx + 10],Si
  134.               Mov       Word Ptr Es:[Bx + 12],Di
  135.               Mov       Word Ptr Es:[Bx + 14],Ds
  136.               Pushf                                ;Push the flags
  137.               Pop       Ax                         ;Get them in Ax
  138.               Mov       Word Ptr Es:[Bx + 18],Ax   ;Get Flag into Regs struct
  139.               Pop       Ax                         ;Get Real Ax
  140.               Mov       Word Ptr Es:[Bx + 16],Ax   ;Store it in Regs struct
  141.               Add       Sp,4                       ;Remove Saved Regs
  142.               Pop       Si
  143.               Pop       Di
  144.               Pop       Es
  145.               Pop       Ds
  146.               Add       Sp,IntLen
  147. IFDEF POWERC
  148.               Pop       Bp
  149. ENDIF
  150.               Ret
  151. Intr          Endp
  152.               End
  153.             
  154.  
  155.  
  156. 
  157.