home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / pcw_c.zip / PCINTR.ASM < prev    next >
Assembly Source File  |  1991-12-16  |  7KB  |  147 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.               Dosseg
  14. IFDEF POWERC
  15.               .Model    Large
  16. ELSE
  17.               .Model    Large,C
  18. ENDIF
  19.               .Data
  20. ;
  21. ;********************************************************************
  22. ;* This data will be copied onto the stack and modified at runtime  *
  23. ;* to generate the correct interrupt.                               *
  24. ;********************************************************************
  25. ;
  26. IntStart      Label     Byte
  27.               Int       21h
  28.               Retf
  29. IntLen        Equ       ($-IntStart)+1
  30. ;
  31. ;********************************************************************
  32. ;* Start the code segment by declaring some space to save the Bp    *
  33. ;* register while we modify the stack at runtime.                   *
  34. ;********************************************************************
  35.               .Code
  36. BpSave        Dw        ?
  37. ;
  38.  
  39. DoInt         Proc      Near
  40.               Xchg      Bp,Cs:Word Ptr[BpSave]
  41.               Push      Ss
  42.               Sub       Bp,IntLen
  43.               Push      Bp
  44.               Add       Bp,IntLen
  45.               Xchg      Bp,Cs:Word Ptr[BpSave]
  46.               Retf
  47. DoInt         Endp
  48. ;
  49. ;****************************************************************
  50. ;*                             Intr()                           *
  51. ;*                                                              *
  52. ;* MSC version of intr(), useful for interrupts and such. Used  *
  53. ;* mainly because we need to pass values in Bp and get values   *
  54. ;* from flags for keyboard routines.                            *
  55. ;*                                                              *
  56. ;* Now used with Turbo C also because the intr() function in    *
  57. ;* Turbo C has terrible bug and will trash your program if not  *
  58. ;* careful.                                                     *
  59. ;*                                                              *
  60. ;* struct REGPACK {                                             *
  61. ;*     unsigned  r_ax, r_bx, r_cx, r_dx, r_bp;                  *
  62. ;*     unsigned  r_si, r_di, r_ds, r_es, r_flags;               *
  63. ;* };                                                           *
  64. ;* void intr(int intno, struct REGPACK far *regp);              *
  65. ;****************************************************************
  66. ;
  67.               Public    Intr
  68. IFDEF POWERC
  69. Intr          Proc      Far
  70. intrno        Equ       [Bp + 6]
  71. regs          Equ       [Bp + 8]
  72.               Push      Bp
  73.               Mov       Bp,Sp
  74. ELSE
  75. Intr          Proc      intrno:word, regs:ptr
  76. ENDIF
  77.               Sub       Sp,IntLen
  78.               Push      Ds
  79.               Push      Es
  80.               Push      Di
  81.               Push      Si
  82.               Mov       Ax,intrno
  83.               Mov       [IntStart + 1],Al   ;Use correct interrupt number
  84.               Mov       Cx,IntLen
  85.               Push      Ss                  ;Set Es:Di to point into
  86.               Pop       Es                  ;the stack where we will
  87.               Mov       Di,Bp               ;copy the code and modify it
  88.               Sub       Di,IntLen
  89.               Mov       Si,Offset IntStart
  90.               Cld
  91.               Rep       Movsb                           ;Copy Code onto Stack
  92.               Push      Bp                              ;Save Bp for later use
  93.               Pop       Cs:Word Ptr[BpSave]             ;In the code segment.
  94.               Les       Bx,regs                         ;Es:Bx points to regs
  95.               Mov       Cx,Word Ptr Es:[Bx + 4h]        ;Get Cx
  96.               Mov       Dx,Word Ptr Es:[Bx + 6h]
  97.               Mov       Bp,Word Ptr Es:[Bx + 8h]
  98.               Mov       Si,Word Ptr Es:[Bx + 10]
  99.               Mov       Di,Word Ptr Es:[Bx + 12]
  100.               Mov       Ds,Word Ptr Es:[Bx + 14]
  101.               Mov       Ax,Word Ptr Es:[Bx + 2h]        ;This is Bx-later
  102.               Push      Bx                              ;Save Bx
  103.               Push      Es                              ;and Es for later
  104.               Push      Ax                              ;Save val for Bx
  105.               Mov       Ax,Word Ptr Es:[Bx + 0h]        ;Get Real Ax
  106.               Mov       Es,Word Ptr Es:[Bx + 16]        ;Get Es
  107.               Pop       Bx                              ;Get in Bx finally
  108.               Push      Cs                              ;Do this for Powerc
  109.               Call      DoInt                           ;Make near call
  110. CodeRet:                                                ;Return from Int here
  111.               Push      Es
  112.               Push      Bx
  113.               Push      Bp
  114.               Mov       Bp,Sp
  115.               Mov       Bx,[Bp + 8]                     ;Get Bx & Es 
  116.               Mov       Es,[Bp + 6]                     ;From up above
  117.               Pop       Bp
  118.               Mov       Word Ptr Es:[Bx + 0h],Ax
  119.               Pop       Ax                              ;Pop of Bx
  120.               Mov       Word Ptr Es:[Bx + 2h],Ax        ;Store it
  121.               Mov       Word Ptr Es:[Bx + 4h],Cx
  122.               Mov       Word Ptr Es:[Bx + 6h],Dx
  123.               Mov       Word Ptr Es:[Bx + 8h],Bp
  124.               Mov       Word Ptr Es:[Bx + 10],Si
  125.               Mov       Word Ptr Es:[Bx + 12],Di
  126.               Mov       Word Ptr Es:[Bx + 14],Ds
  127.               Pushf                                     ;Push the flags
  128.               Pop       Ax                              ;Get them in Ax
  129.               Mov       Word Ptr Es:[Bx + 18],Ax        ;Get Flag into pgm
  130.               Pop       Ax                              ;Get Real Ax
  131.               Mov       Word Ptr Es:[Bx + 16],Ax        ;Store it
  132.               Add       Sp,4                            ;Remove Saved Regs
  133.               Pop       Si
  134.               Pop       Di
  135.               Pop       Es
  136.               Pop       Ds
  137.               Add       Sp,IntLen
  138. IFDEF POWERC
  139.               Pop       Bp
  140. ENDIF
  141.               Ret
  142. Intr          Endp
  143.               End
  144.             
  145.  
  146.  
  147.