home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / mscwattc / src / intr.asm < prev    next >
Encoding:
Assembly Source File  |  1992-01-13  |  3.4 KB  |  171 lines

  1. ;    TITLE    intr.asm   C. J. Kent
  2. ;    page    64,130
  3. ;
  4. ;    BUILD: Microsoft masm 5.1:
  5. ;    masm /ML intr.asm;
  6.  
  7.     .MODEL    LARGE, c
  8.  
  9. ;  IMPORTS:
  10.  
  11.  
  12. ;  EXPORTS:
  13.  
  14. ; MACROS
  15. ;
  16. ;struct REGPACK
  17. ;       unsigned int r_ax;
  18. ;       unsigned int r_bx;
  19. ;       unsigned int r_cx;
  20. ;       unsigned int r_dx;
  21. ;       unsigned int r_bp;
  22. ;       unsigned int r_si;
  23. ;       unsigned int r_di;
  24. ;       unsigned int r_ds;
  25. ;       unsigned int r_es;
  26. ;       unsigned int r_flags;
  27.  
  28. OFFAX    =    0
  29. OFFBX    =    2
  30. OFFCX    =    4
  31. OFFDX    =    6
  32. OFFBP    =    8
  33. OFFSI    =    10
  34. OFFDI    =    12
  35. OFFDS    =    14
  36. OFFES    =    16
  37. OFFC    =    18
  38.  
  39.  
  40. ; DEFINES:
  41.  
  42.  
  43.  
  44.     .CODE
  45.  
  46. ;***
  47. ;int int86x(intno, inregs, outregs, segregs) - do 8086 interrupt
  48. ;
  49. ;Purpose:
  50. ;    calls the sepcified DOS interrupt with the registers as specified
  51. ;    in inregs and ES and DS from segregs; copies the registers, ES,
  52. ;    and DS into outregs and segregs on return.
  53. ;
  54. ;Entry:
  55. ;    int intno - interrupt to execute
  56. ;    union REGS *inregs - registers on entry to interrupt
  57. ;    union REGS *outregs - registers on exit from interrupt
  58. ;    struct SREGS *segregs - seg register: input and output
  59. ;                (only ES and DS are used)
  60. ;
  61. ;Exit:
  62. ;    returns value in AX after interrupt
  63. ;
  64. ;Uses:
  65. ;
  66. ;Exceptions:
  67. ;
  68. ;*******************************************************************************
  69. intr PROC USES di si ds, intno:WORD, pRegs:DWORD
  70.  
  71. ;
  72. ; the stack is made to look like this:
  73. ;
  74. ;    -------------------
  75. ;    |     pRegs        |  (arg2)
  76. ;    -------------------
  77. ;    |     intno      |  (arg1)
  78. ;    -------------------
  79. ;    |    ret addr      |
  80. ;    -------------------
  81. ;  bp-> |     old bp      |
  82. ;    -------------------
  83. ;    |     old di      |
  84. ;    -------------------
  85. ;    |     old si      |
  86. ;    -------------------
  87. ;    |     old ds      |
  88. ;    -------------------
  89. ;    | 'retf'|      |
  90. ;    -------------------
  91. ;    | 'inc sp inc sp' |  <- only in if int 25 or int 26
  92. ;    -------------------
  93. ;    | 'int'  | intno  |  <- we do a long call to 'int' opcode
  94. ;    -------------------
  95. ;    |    ss      |
  96. ;    -------------------
  97. ; (bp)->| offset of 'int' |
  98. ;    -------------------
  99. ;
  100.     sub    sp,10        ; room for 5 words
  101.     mov    byte ptr [bp-12],0cdh ; an 'int' opcode
  102.     mov    ax,intno
  103.     mov    [bp-11],al    ; the interrupt number
  104.     cmp    al,25h
  105.     je    abnorm
  106.     cmp    al,26h
  107.     je    abnorm
  108.     mov    byte ptr [bp-10],0cbh ; a 'retf' opcode
  109.     jmp    short continue
  110.  
  111. abnorm:
  112.     mov    byte ptr [bp-8],0cbh ; a 'retf' opcode
  113.     mov    byte ptr [bp-9],044h ; a 'inc sp' opcode for flags on stack
  114.     mov    byte ptr [bp-10],044h ; a 'inc sp' opcode for flags on stack
  115.  
  116. continue:
  117.  
  118.     mov    [bp-14],ss    ; seg part of far call addr
  119.  
  120.     lea    ax,[bp-12]    ; offset part of far call addr
  121.     mov    [bp-16],ax    ; we're going to jump onto the stack
  122.  
  123.     lds    di,pRegs    ; get struct REGPACK addr
  124.  
  125.  
  126.     mov    ax,[di+OFFAX]
  127.     mov    bx,[di+OFFBX]
  128.     mov    cx,[di+OFFCX]
  129.     mov    dx,[di+OFFDX]
  130.     mov    si,[di+OFFSI]
  131.     push    [di+OFFDI]    ; save di, need it for indexing
  132.  
  133.     mov    es,[di+OFFES]
  134.     mov    ds,[di+OFFDS]
  135.     pop    di        ; restore di
  136.     push    bp
  137.     call    dword ptr [bp-10h] ; execute interrupt
  138.  
  139.     pop    bp        ; bp points to old bp
  140.     cld            ; ensure that direction is "up"
  141.     push    di        ; save di
  142.     push    ds
  143.  
  144.     lds    di,pRegs    ; get struct REGPACK addr
  145.  
  146.     mov    [di+OFFES],es
  147.     pop    [di+OFFDS]
  148.  
  149.     mov    [di+OFFAX],ax
  150.     mov    [di+OFFBX],bx
  151.     mov    [di+OFFCX],cx
  152.     mov    [di+OFFDX],dx
  153.     mov    [di+OFFSI],si
  154.     pop    [di+OFFDI]    ; restore di
  155.     jc    carry
  156.  
  157.     xor    si,si
  158.     jmp    short toend
  159.  
  160. carry:
  161.     mov    si,1
  162.  
  163. toend:
  164.     mov    [di+OFFC],si    ; set carry/no carry flag
  165.     add    sp,10        ; to get back to old sp
  166.     ret
  167. intr ENDP
  168.     END
  169. ; intr.asm
  170.  
  171.