home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / clock.zip / CSYSINT.LST < prev    next >
File List  |  1986-12-20  |  7KB  |  166 lines

  1.  The IBM Personal Computer MACRO Assembler 12-20-86        PAGE    1-1
  2.  
  3.  
  4.  
  5. 1                        PAGE   54,130
  6. 2                        ; CSYSINT  - Lattice "C" interface to the world
  7. 3                        ;
  8. 4                        ; This program was adapted from PSYSINT, a program listed
  9. 5                        ; and described by Will Fastie in SOFTALK Magazine, which
  10. 6                        ; provided access to system calls from IBM Pascal programs.
  11. 7                        ; It in turn was taken from George Eberhart's version for the
  12. 8                        ; Computer Inovations C86 Compiler, with permission.
  13. 9                        ;
  14. 10                        ; Modified by T. Cox to match the Microsoft C Compiler
  15. 11                        ; assembly language interface call conventions, and renamed
  16. 12                        ; to CSYSINT.
  17. 13                        ;
  18. 14                        ; C calling sequence:
  19. 15                        ;
  20. 16                        ;     flags = csysint(interrupt,&sreg,&rreg);
  21. 17                        ;
  22. 18                        ; Where sreg and rreg are structures of four words each representing
  23. 19                        ; the 8088 registers AX, BX, CX, and DX.  "regsetT is a structure
  24. 20                        ; defining these as all the half-register names (e.g.,AL,AH).
  25. 21                        ;
  26. 22                        ; interrupt is the number of the system interrupt desired.
  27. 23                        ;
  28. 24                        ; The return value is a 16-bit unsigned integer. It contains
  29. 25                        ; the machine status register.
  30. 26                        ;
  31. 27                        ; This C function calling sequence passes the interrupt code as a value
  32. 28                        ; and the two register sets as pointers to their respective structures.
  33. 29                        ;
  34. 30                        ; The incoming stack looks like this in memory locations "mem".  Note
  35. 31                        ; that the call is a NEAR call (page 1-36 of the Microsoft C manual),
  36. 32                        ; so only the return address (and not the segment address) is pushed.
  37. 33                        ;
  38. 34                        ;   High                         <-- Caller's BP
  39. 35                        ;         mem + 06:     interrupt code value
  40. 36                        ;         mem + 04:     SREG address
  41. 37                        ;         mem + 02:     RREG address
  42. 38                        ;         mem + 00:     caller's saved BP
  43. 39                        ;   Low                          <-- BP, SP
  44. 40                        ;
  45. 41                        PGROUP    GROUP  PROG
  46. 42                        PARAMS    STRUC
  47. 43     0000  ????              OLD_BP    DW     ?            ; Caller's BP Save
  48. 44     0002  ????              RETN    DW     ?            ; Return address from call
  49. 45     0004  ????              ARG1    DW     ?            ; First arguement
  50. 46     0006  ????              ARG2    DW     ?            ; Second arguement
  51. 47     0008  ????              ARG3    DW     ?            ; Third arguement
  52. 48     000A                   PARAMS    ENDS
  53. 49                        ;
  54.  The IBM Personal Computer MACRO Assembler 12-20-86        PAGE    1-2
  55.  
  56.  
  57.  
  58. 50     0000                   PROG    SEGMENT BYTE PUBLIC 'PROG'
  59. 51                             ASSUME CS:PGROUP
  60. 52                             PUBLIC CSYSINT
  61. 53                        ;
  62. 54     0000                   CSYSINT PROC   NEAR
  63. 55     0000  55                   PUSH   BP            ; save caller's frame pointer
  64. 56     0001  8B EC                   MOV    BP,SP            ; set up our frame pointer
  65. 57                        ;
  66. 58     0003  E8 0006 R              CALL   DUMMY            ; trick - push the IP
  67. 59     0006                   DUMMY:
  68. 60     0006  58                   POP    AX            ; get it
  69. 61     0007  2D 0006 R              SUB    AX,OFFSET DUMMY       ; calculate the address of the INT
  70. 62     000A  05 001A R              ADD    AX,OFFSET PINT
  71. 63     000D  8B F8                   MOV    DI,AX            ; move it to the index register
  72. 64     000F  8B 46 04                   MOV    AX,[BP].ARG1       ; get the desired interrupt number
  73. 65     0012  2E: 88 45 01              MOV    CS:[DI+1],AL       ; put it in the INT instruction
  74. 66     0016  E8 0024 R              CALL   REGSIN            ; get the registers from SREG
  75. 67     0019  55                   PUSH   BP            ; we'll need our own BP later
  76. 68     001A  CD 00              PINT:    INT    00H            ; perform the requested interrupt
  77. 69     001C  5D                   POP    BP            ; get our BP back
  78. 70     001D  9C                   PUSHF                 ; hang onto the flags for the return
  79. 71     001E  E8 0035 R              CALL   REGSOUT            ; put the registers into RREG
  80. 72     0021  58                   POP    AX            ; flags are the return value
  81. 73     0022  5D                   POP    BP            ; restore the caller's frame pointer
  82. 74     0023  C3                   RET                 ; return to caller
  83. 75     0024                   CSYSINT ENDP
  84. 76                        ;
  85. 77                        ; ---------------------------------
  86. 78                        ; Subroutines to move the registers in and out
  87. 79                        ;
  88. 80     = 0004                   NRREGS    EQU    4            ; this version supports only four regs
  89. 81                        ;
  90. 82     0024                   REGSIN    PROC   NEAR            ; -- Move Registers In
  91. 83     0024  8B 5E 06                   MOV    BX,[BP].ARG2       ; get address of register set SREG
  92. 84     0027  B9 0004                   MOV    CX,NRREGS       ; ...and how many registers to move
  93. 85     002A                   INLOOP:
  94. 86     002A  FF 37                   PUSH   WORD PTR [BX]       ; push one
  95. 87     002C  43                   INC    BX            ; point to the next one
  96. 88     002D  43                   INC    BX
  97. 89     002E  E2 FA                   LOOP   INLOOP            ; ..do it some more
  98. 90     0030  5A                   POP    DX            ; now pop them into their proper places
  99. 91     0031  59                   POP    CX
  100. 92     0032  5B                   POP    BX
  101. 93     0033  58                   POP    AX
  102. 94     0034  C3                   RET                 ; all done
  103. 95     0035                   REGSIN    ENDP
  104. 96                        ;
  105. 97     0035                   REGSOUT PROC   NEAR            ;--Move Registers Out
  106. 98     0035  52                   PUSH   DX            ; push all the registers in reverse order
  107.  The IBM Personal Computer MACRO Assembler 12-20-86        PAGE    1-3
  108.  
  109.  
  110.  
  111. 99     0036  51                   PUSH   CX
  112. 100     0037  53                   PUSH   BX
  113. 101     0038  50                   PUSH   AX
  114. 102     0039  8B 5E 08                   MOV    BX,[BP].ARG3       ; get the address of RREG
  115. 103     003C  B9 0004                   MOV    CX,NRREGS       ; ...and how many registers to move
  116. 104     003F                   LOOPOUT:
  117. 105     003F  8F 07                   POP    WORD PTR [BX]       ; recover the register
  118. 106     0041  43                   INC    BX            ; point to the next
  119. 107     0042  43                   INC    BX
  120. 108     0043  E2 FA                   LOOP   LOOPOUT            ; do it again
  121. 109     0045  C3                   RET
  122. 110     0046                   REGSOUT ENDP
  123. 111                        ;
  124. 112     0046                   PROG    ENDS
  125. 113                             END
  126.  
  127.  The IBM Personal Computer MACRO Assembler 12-20-86        PAGE    Symbols-1
  128.  
  129.  
  130.  
  131. Structures and records:
  132.  
  133.          N a m e              Width    # fields
  134.                         Shift    Width    Mask    Initial
  135.  
  136. PARAMS . . . . . . . . . . . . .    000A    0005
  137.   OLD_BP . . . . . . . . . . . . .    0000
  138.   RETN . . . . . . . . . . . . . .    0002
  139.   ARG1 . . . . . . . . . . . . . .    0004
  140.   ARG2 . . . . . . . . . . . . . .    0006
  141.   ARG3 . . . . . . . . . . . . . .    0008
  142.  
  143. Segments and groups:
  144.  
  145.          N a m e              Size    align    combine    class
  146.  
  147. PGROUP . . . . . . . . . . . . .    GROUP
  148.   PROG . . . . . . . . . . . . . .    0046    BYTE      PUBLIC    'PROG'
  149.  
  150. Symbols:            
  151.  
  152.          N a m e              Type    Value    Attr         
  153.  
  154. CSYSINT. . . . . . . . . . . . .    N PROC    0000    PROG    Global    Length =0024
  155. DUMMY. . . . . . . . . . . . . .    L NEAR     0006    PROG
  156. INLOOP . . . . . . . . . . . . .    L NEAR     002A    PROG
  157. LOOPOUT. . . . . . . . . . . . .    L NEAR     003F    PROG
  158. NRREGS . . . . . . . . . . . . .    Number    0004    
  159. PINT . . . . . . . . . . . . . .    L NEAR     001A    PROG
  160. REGSIN . . . . . . . . . . . . .    N PROC    0024    PROG    Length =0011
  161. REGSOUT. . . . . . . . . . . . .    N PROC    0035    PROG    Length =0011
  162.  
  163. Warning Severe
  164. Errors    Errors 
  165. 0    0
  166.