home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CSWITCH.ZIP / SMTC.ASM < prev    next >
Assembly Source File  |  1990-08-07  |  6KB  |  311 lines

  1. ;
  2. ; assembly language functions for C programs to use the
  3. ; multi-tasking features of Cswitch
  4. ; small memory model
  5. ;
  6.  
  7. _DATA SEGMENT WORD PUBLIC 'DATA'
  8. _DATA ENDS
  9.  
  10. _TEXT SEGMENT WORD PUBLIC 'CODE'
  11.   ASSUME CS:_TEXT
  12.   ASSUME DS:_DATA
  13.  
  14.  
  15. p1 = 4
  16. p2 = 6
  17. p3 = 8
  18. p4 = 10
  19.  
  20. ;
  21. ; Cswitch function codes (int62)
  22. ;
  23. ; 1  = relinqush rest of our time slice
  24. ; 2  = wait for semaphore
  25. ; 3  = check semaphore
  26. ; 4  = trigger semaphore
  27. ; 5  = sleep
  28. ; 6  = suspend
  29. ; 7  = spawn
  30. ; 8  = wake up a task
  31. ; 10 = test message queue
  32. ; 11 = send message
  33. ; 12 = read message
  34. ; 13 = don't allow task to be swapped out
  35. ; 14 = allow swapping again
  36. ; 15 = load and run a program from disk
  37. ; 16 = terminate a spawned program
  38. ; 17 = get tcb information
  39. ; 18 = get tcb address
  40. ; 19 = check status of previous load_task
  41. ;
  42.  
  43.     public _relinq
  44.     public _spawn
  45.     public _loadtask
  46.     public _sleep
  47.     public _send_md_msg
  48.     public _testmsg
  49.     public _recvmsg
  50.     public _sem_attach
  51.     public _sem_release
  52.     public _sem_test
  53.     public _setpri
  54.     public _suspend
  55.     public _wakeup
  56.     public _hog
  57.     public _nohog
  58.     public _spawn_exit
  59.     public _get_tcb_info
  60.     public _get_tcb_address
  61.     public _get_load_status
  62.     
  63. _relinq  proc    near
  64.     mov ah,1
  65.     int 62h
  66.     ret
  67. _relinq endp
  68.  
  69. _get_load_status  proc    near
  70.     mov ah,19
  71.     int 62h
  72.     ret
  73. _get_load_status endp
  74.  
  75. _spawn_exit proc near
  76.     mov ah,16
  77.     int 62h
  78.     ret
  79. _spawn_exit endp
  80.  
  81. _hog  proc    near
  82.     mov ah,13
  83.     int 62h
  84.     ret
  85. _hog endp
  86.  
  87. _nohog  proc    near
  88.     mov ah,14
  89.     int 62h
  90.     ret
  91. _nohog endp
  92.  
  93. _spawn  proc    near
  94.     push    bp
  95.     mov     bp,sp
  96.     push    es
  97.     push    bx
  98.     push    cx
  99.     mov     bx,[bp+4]   ;offset
  100.     mov     ax,cs   ;segment
  101.     mov     es,ax
  102.     mov     cx,[bp+6]   ;priority
  103.     mov     ah,7
  104.     int     62h
  105.     pop     cx
  106.     pop     bx
  107.     pop     es
  108.     pop     bp
  109.     ret
  110. _spawn  endp
  111.  
  112. _get_tcb_info  proc    near
  113.     push    bp
  114.     mov     bp,sp
  115.     push    es
  116.     push    bx
  117.     mov     bx,[bp+4]   ;offset
  118.     mov     ax,ds       ;segment
  119.     mov     es,ax
  120.     mov     ah,17
  121.     int     62h
  122.     pop     bx
  123.     pop     es
  124.     pop     bp
  125.     ret
  126. _get_tcb_info  endp
  127.  
  128. _get_tcb_address  proc    near
  129.     push    bp
  130.     mov     bp,sp
  131.     push    es
  132.     push    bx
  133.     mov     bx,[bp+4]   ;offset
  134.     mov     ax,ds       ;segment
  135.     mov     es,ax
  136.     mov     ah,18
  137.     int     62h
  138.     pop     bx
  139.     pop     es
  140.     pop     bp
  141.     ret
  142. _get_tcb_address  endp
  143.  
  144.  
  145. _loadtask  proc    near
  146.     push    bp
  147.     mov     bp,sp
  148.     push    es
  149.     push    bx
  150.     push    cx
  151.     push    dx
  152.     mov     bx,[bp+4]   ;offset of command line
  153.     mov     ax,ds   ;segment
  154.     mov     es,ax
  155.     mov     cx,[bp+6]   ;priority
  156.     mov     dx,[bp+8]  ;background flag - if non-0, allows loading to ems
  157.     mov     ah,15
  158.     int     62h
  159.     pop     dx
  160.     pop     cx
  161.     pop     bx
  162.     pop     es
  163.     pop     bp
  164.     ret
  165. _loadtask  endp
  166.  
  167. ; params = how many ticks
  168. _sleep  proc    near
  169.     push    bp
  170.     mov     bp,sp
  171.     push    bx
  172.     mov     bx,[bp+4]
  173.     mov     ah,5
  174.     int     62h
  175.     pop     bx
  176.     pop     bp
  177.     ret
  178. _sleep   endp
  179.  
  180.  
  181. _suspend  proc    near
  182.     mov     ah,6
  183.     int     62h
  184.     ret
  185. _suspend   endp
  186.  
  187. ;params = task to wake up
  188. _wakeup  proc    near
  189.     push    bp
  190.     mov     bp,sp
  191.     push    bx
  192.     mov     bx,[bp+4]
  193.     mov     ah,8
  194.     int     62h
  195.     pop     bx
  196.     pop     bp
  197.     ret
  198. _wakeup   endp
  199.  
  200.  
  201. ; params = new priority
  202. _setpri  proc    near
  203.     push    bp
  204.     mov     bp,sp
  205.     push    bx
  206.     mov     bx,[bp+4]
  207.     mov     ah,9
  208.     int     62h
  209.     pop     bx
  210.     pop     bp
  211.     ret
  212. _setpri   endp
  213.  
  214. _sem_attach    proc near
  215.     push    bp
  216.     mov     bp,sp
  217.     push    dx
  218.     mov     dx,[bp+4]
  219.     mov     ah,2
  220.     int     62h
  221.     pop     dx
  222.     pop     bp
  223.     ret
  224. _sem_attach    endp
  225.  
  226. _sem_test    proc near
  227.     push    bp
  228.     mov     bp,sp
  229.     push    dx
  230.     mov     dx,[bp+4]
  231.     mov     ah,3
  232.     int     62h
  233.     pop     dx
  234.     pop     bp
  235.     ret
  236. _sem_test    endp
  237.  
  238. _sem_release    proc near
  239.     push    bp
  240.     mov     bp,sp
  241.     push    dx
  242.     mov     dx,[bp+4]
  243.     mov     ah,4
  244.     int     62h
  245.     pop     dx
  246.     pop     bp
  247.     ret
  248. _sem_release    endp
  249.  
  250. _testmsg  proc near
  251.     push    bp
  252.     mov     bp,sp
  253.     push    dx
  254.     mov     dx,[bp+4]   ;queue number to check
  255.     mov     ah,10
  256.     int     62h
  257.     pop     dx
  258.     pop     bp
  259.     ret
  260. _testmsg      endp
  261.  
  262. _send_md_msg    proc near
  263.     push    bp
  264.     mov     bp,sp
  265.     push    dx
  266.     push    ds
  267.     push    si
  268.     push    cx
  269.     mov     si,[bp+6]  ;offset for data buffer
  270.                        ;ds already must point to data
  271.     mov     cx,[bp+8]  ;length
  272.     mov     dx,[bp+4]   ;queue number to read from
  273.     mov     ah,11
  274.     int     62h
  275.     pop     cx
  276.     pop     si
  277.     pop     ds
  278.     pop     dx
  279.     pop     bp
  280.     ret
  281. _send_md_msg    endp
  282.  
  283. _recvmsg    proc near
  284.     push    bp
  285.     mov     bp,sp
  286.     push    dx
  287.     push    ds
  288.     push    si
  289.     push    cx
  290.     mov     si,[bp+6]  ;offset for data buffer
  291.     mov     cx,[bp+8]  ;length
  292.     mov     dx,[bp+4]   ;queue number to read from
  293. read2:
  294.     mov     ah,12
  295.     int     62h
  296.     cmp     ax,0fffeh   ;if -2 (0fffeh) is returned, then we have been
  297.                         ;triggered by something arriving on queue, and we
  298.                         ;must make the 'read' call again to retrieve it
  299.     jz      read2
  300.     pop     cx
  301.     pop     si
  302.     pop     ds
  303.     pop     dx
  304.     pop     bp
  305.     ret
  306. _recvmsg    endp
  307.  
  308. _TEXT ENDS
  309.         end
  310.     
  311.