home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / PCOINT86.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-29  |  3.2 KB  |  132 lines

  1. ; pcoint86.asm
  2. ;
  3. ; 12/13/88 by Ted
  4. ;
  5. ; Dos/Bios interrupt function.
  6. ;
  7. ; Copyright (c) 1988, 1989 Oakland Group Inc.
  8. ; ALL RIGHTS RESERVED
  9. ;
  10. ;------------------------REVISION HISTORY--------------------------------------;
  11. ;  1/29/90 ted    Changed from self-modifying code method to stack games method.
  12. ;  5/29/90 ted    Added ds option in esdsin variable.
  13. ;------------------------------------------------------------------------------;
  14. include PCDECL.MAC
  15.  
  16. regstruc struc
  17.     rax dw 0
  18.     rbx dw 0
  19.     rcx dw 0
  20.     rdx dw 0
  21.     res dw 0
  22.     rds dw 0
  23.     rsi dw 0
  24.     rdi dw 0
  25. regstruc ends
  26.  
  27.     PSEG
  28. ;------------------------------------------------------------------------------;
  29. ;
  30. ; unsigned _oakint86(unsigned intno, regstruc *regs, boolean esdsin);
  31. ;    Puts the values from regstruc into the registers and executes the specified
  32. ;    interrupt. Fills the structure up again with the outgoing register values.
  33. ; NOTE: es and ds are returned in the regs structure, but on input they are
  34. ;    ignored if esdsin is 0. If esdsin is 1, es is used as input; if esdsin is 2,
  35. ;    ds is used as input.
  36.  
  37. pubproc DIGPRIV _oakint86 <intno, regs, dptr, esdsin>
  38.     push bp
  39.     mov bp,sp
  40.     sub sp, 6            ; make room on stack for auto vars for bx and es and ds.
  41.     pushm <ds, es, si, di>
  42.  
  43.     mov bx, [bp].regs    ;get source registers
  44. IF FAR_DATA
  45.     mov ds, [bp].regs+2    ;get regs segment
  46. ELSE
  47.     mov [bp-6], ds        ; save ds in auto var
  48. ENDIF
  49.     mov si, [bx].rsi
  50.     mov di, [bx].rdi
  51.     mov dx, [bx].rdx
  52.     mov cx, [bx].rcx
  53. test word ptr [bp].esdsin, 1
  54. jz noes
  55.     mov es, [bx].res
  56. noes:
  57. test word ptr [bp].esdsin, 2
  58. jz nods
  59.     mov ax, [bx].rds
  60.     push ax
  61.     mov ax, [bx].rax
  62.     mov bx, [bx].rbx
  63.     pop ds
  64.     jmp ldend
  65. nods:
  66.     mov ax, [bx].rax
  67.     mov bx, [bx].rbx
  68. ldend:
  69.  
  70.     push bp                ; save bp
  71.  
  72. ; Prepare to do the interrupt
  73.     mov [bp-2], es        ; stash es in auto var
  74.     mov [bp-4], bx        ; stash bx in auto var
  75.  
  76.     pushf                ; push flags for return
  77.     push cs                ; push return address segment
  78.     mov bx, offset back_from_future
  79.     push bx                ; push return address offset
  80.  
  81.     mov bx, DOS_IVECSEG
  82.     mov es, bx            ; set es to 0 seg for reading int vector
  83.     mov    bx, [bp].intno    ; get interrupt #
  84.     shl bx, 1
  85.     shl bx, 1            ; multiply intno by 4 to get address of vector
  86. IF (RATL)
  87.     shl bx, 1            ; multiply intno by 8 to get address of vector
  88. ENDIF
  89.  
  90.     pushf                ; push flags on stack
  91.     push es:[bx+2]        ; push interrupt address segment
  92.     push es:[bx]        ; push interrupt address offset
  93.  
  94.     mov es, ss:[bp-2]    ; get es out from auto var where we stashed it
  95.     mov bx, ss:[bp-4]    ; get bx out from auto var where we stashed it
  96.  
  97.     iret        ; DO THE INTERRUPT NOW.
  98. back_from_future:
  99. ; Interrupt accomplished
  100.     pop bp                ; restore bp
  101.  
  102.     pushf
  103.     push ds
  104.     push bx
  105.     mov bx, [bp].regs    ; get source registers
  106. IF FAR_DATA
  107.     mov ds, [bp].regs+2    ; get regs segment
  108. ELSE
  109.     mov ds, [bp-6]
  110. ENDIF
  111.     pop [bx].rbx
  112.     pop [bx].rds
  113.     mov [bx].rax, ax
  114.     mov [bx].res, es
  115.     pop ax                ; get flags into ax for return
  116.  
  117.     mov [bx].rcx, cx
  118.     mov [bx].rdx, dx
  119.     mov [bx].rdi, di
  120.     mov [bx].rsi, si
  121.  
  122.     popm <di, si, es, ds>
  123.     add sp, 6            ; get auto vars off stack
  124.     pop bp
  125.     ret
  126. endproc _oakint86
  127. ; ---------------------------------------------------------------- ;
  128.     ENDPS
  129.     end
  130. ; ---------------------------------------------------------------- ;
  131.  
  132.