home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / clock.zip / CSYSINT.ASM < prev    next >
Assembly Source File  |  1984-07-29  |  4KB  |  114 lines

  1. PAGE   54,130
  2. ; CSYSINT  - Lattice "C" interface to the world
  3. ;
  4. ; This program was adapted from PSYSINT, a program listed
  5. ; and described by Will Fastie in SOFTALK Magazine, which
  6. ; provided access to system calls from IBM Pascal programs.
  7. ; It in turn was taken from George Eberhart's version for the
  8. ; Computer Inovations C86 Compiler, with permission.
  9. ;
  10. ; Modified by T. Cox to match the Microsoft C Compiler
  11. ; assembly language interface call conventions, and renamed
  12. ; to CSYSINT.
  13. ;
  14. ; C calling sequence:
  15. ;
  16. ;     flags = csysint(interrupt,&sreg,&rreg);
  17. ;
  18. ; Where sreg and rreg are structures of four words each representing
  19. ; the 8088 registers AX, BX, CX, and DX.  "regsetT is a structure
  20. ; defining these as all the half-register names (e.g.,AL,AH).
  21. ;
  22. ; interrupt is the number of the system interrupt desired.
  23. ;
  24. ; The return value is a 16-bit unsigned integer. It contains
  25. ; the machine status register.
  26. ;
  27. ; This C function calling sequence passes the interrupt code as a value
  28. ; and the two register sets as pointers to their respective structures.
  29. ;
  30. ; The incoming stack looks like this in memory locations "mem".  Note
  31. ; that the call is a NEAR call (page 1-36 of the Microsoft C manual),
  32. ; so only the return address (and not the segment address) is pushed.
  33. ;
  34. ;   High                      <-- Caller's BP
  35. ;         mem + 06:     interrupt code value
  36. ;         mem + 04:     SREG address
  37. ;         mem + 02:     RREG address
  38. ;         mem + 00:     caller's saved BP
  39. ;   Low                       <-- BP, SP
  40. ;
  41. PGROUP    GROUP  PROG
  42. PARAMS    STRUC
  43. OLD_BP    DW     ?           ; Caller's BP Save
  44. RETN    DW     ?           ; Return address from call
  45. ARG1    DW     ?           ; First arguement
  46. ARG2    DW     ?           ; Second arguement
  47. ARG3    DW     ?           ; Third arguement
  48. PARAMS    ENDS
  49. ;
  50. PROG    SEGMENT BYTE PUBLIC 'PROG'
  51.     ASSUME CS:PGROUP
  52.     PUBLIC CSYSINT
  53. ;
  54. CSYSINT PROC   NEAR
  55.     PUSH   BP           ; save caller's frame pointer
  56.     MOV    BP,SP           ; set up our frame pointer
  57. ;
  58.     CALL   DUMMY           ; trick - push the IP
  59. DUMMY:
  60.     POP    AX           ; get it
  61.     SUB    AX,OFFSET DUMMY       ; calculate the address of the INT
  62.     ADD    AX,OFFSET PINT
  63.     MOV    DI,AX           ; move it to the index register
  64.     MOV    AX,[BP].ARG1       ; get the desired interrupt number
  65.     MOV    CS:[DI+1],AL       ; put it in the INT instruction
  66.     CALL   REGSIN           ; get the registers from SREG
  67.     PUSH   BP           ; we'll need our own BP later
  68. PINT:    INT    00H           ; perform the requested interrupt
  69.     POP    BP           ; get our BP back
  70.     PUSHF               ; hang onto the flags for the return
  71.     CALL   REGSOUT           ; put the registers into RREG
  72.     POP    AX           ; flags are the return value
  73.     POP    BP           ; restore the caller's frame pointer
  74.     RET               ; return to caller
  75. CSYSINT ENDP
  76. ;
  77. ; ---------------------------------
  78. ; Subroutines to move the registers in and out
  79. ;
  80. NRREGS    EQU    4           ; this version supports only four regs
  81. ;
  82. REGSIN    PROC   NEAR           ; -- Move Registers In
  83.     MOV    BX,[BP].ARG2       ; get address of register set SREG
  84.     MOV    CX,NRREGS       ; ...and how many registers to move
  85. INLOOP:
  86.     PUSH   WORD PTR [BX]       ; push one
  87.     INC    BX           ; point to the next one
  88.     INC    BX
  89.     LOOP   INLOOP           ; ..do it some more
  90.     POP    DX           ; now pop them into their proper places
  91.     POP    CX
  92.     POP    BX
  93.     POP    AX
  94.     RET               ; all done
  95. REGSIN    ENDP
  96. ;
  97. REGSOUT PROC   NEAR           ;--Move Registers Out
  98.     PUSH   DX           ; push all the registers in reverse order
  99.     PUSH   CX
  100.     PUSH   BX
  101.     PUSH   AX
  102.     MOV    BX,[BP].ARG3       ; get the address of RREG
  103.     MOV    CX,NRREGS       ; ...and how many registers to move
  104. LOOPOUT:
  105.     POP    WORD PTR [BX]       ; recover the register
  106.     INC    BX           ; point to the next
  107.     INC    BX
  108.     LOOP   LOOPOUT           ; do it again
  109.     RET
  110. REGSOUT ENDP
  111. ;
  112. PROG    ENDS
  113.     END
  114.