home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CTASK22.ZIP / TSKSEC.ASM < prev    next >
Assembly Source File  |  1990-10-12  |  3KB  |  156 lines

  1. ;
  2. ;    --- Version 2.2 90-10-12 10:46 ---
  3. ;
  4. ;    CTask - Support modules for DOS handler, plus keyboard routines.
  5. ;
  6. ;    Public Domain Software written by
  7. ;        Thomas Wagner
  8. ;        Ferrari electronic Gmbh
  9. ;        Beusselstrasse 27
  10. ;        D-1000 Berlin 21
  11. ;        Germany
  12. ;
  13. ;    This file is new with Version 2.1. Those routines which are
  14. ;    needed in both primary and secondary kernels were moved here
  15. ;    from tskdos.asm and tskkbd.asm.
  16. ;
  17. ;    This avoids linking unneeded modules for secondary kernels.
  18. ;
  19. ;---------------------------------------------------------------------------
  20. ;
  21.     name    tsksec
  22. ;
  23.     include    tsk.mac
  24. ;
  25.     .tsk_model
  26. ;
  27.     Pubfunc    tsk_free_mem
  28.     Pubfunc    tsk_getpsp
  29. ;
  30.     Pubfunc    t_read_key
  31.     Pubfunc    t_wait_key
  32.     Pubfunc    t_keyhit
  33. ;
  34. ;
  35. ; Structure of a DOS MCB (Memory Control Block)
  36. ;
  37. mcbstruc    struc
  38. ;
  39. mcb_id        db    ?
  40. mcb_owner    dw    ?
  41. mcb_len        dw    ?
  42. ;
  43. mcbstruc    ends
  44. ;
  45.     .tsk_code
  46. ;
  47. Localfunc tsk_free_mem,<owner: word>
  48. ;
  49.     mov    ah,51h
  50.     int    21h
  51.     push    bx            ; save current PSP
  52.     mov    bx,owner
  53.     mov    ah,50h
  54.     int    21h            ; set new PSP
  55. ;
  56. free_beg:
  57.     mov    ah,52h
  58.     int    21h            ; get DOS invars
  59.     mov    dx,es:[bx-2]        ; start of MCB chain
  60.     mov    bx,owner
  61. ;
  62. free_loop:
  63.     mov    es,dx
  64.     cmp    es:[mcb_owner],bx
  65.     jne    free_next
  66. ;
  67. ;    If we have released a block, we restart at the beginning of the
  68. ;    MCB chain, since DOS might merge blocks, thereby invalidating
  69. ;    our pointers. In the current versions of DOS, this seems to be
  70. ;    an unneccessary precaution, but you never know...
  71. ;
  72.     inc    dx
  73.     mov    es,dx
  74.     mov    ah,49h            ; free memory block
  75.     int    21h
  76.     jmp    free_beg
  77. ;
  78. free_next:
  79.     cmp    es:[mcb_id],'Z'        ; end of chain ?
  80.     je    free_end        ; then exit
  81.     add    dx,es:[mcb_len]
  82.     inc    dx            ; point to next
  83.     jmp    free_loop
  84. ;
  85. free_end:
  86.     pop    bx
  87.     mov    ah,50h
  88.     int    21h            ; restore PSP
  89.     ret
  90. ;
  91. tsk_free_mem    endp
  92. ;
  93. ;---------------------------------------------------------------------------
  94. ;---------------------------------------------------------------------------
  95. ;
  96. ;    int t_read_key (void)
  97. ;
  98. ;    Waits for key from keyboard. Returns char in lower byte,
  99. ;    Scan-Code in upper byte.
  100. ;
  101. Globalfunc t_read_key
  102. ;
  103.     mov    ax,4112h
  104.     int    16h
  105.     ret
  106. ;    
  107. t_read_key    endp
  108. ;
  109. ;
  110. ;    int t_wait_key (dword timeout)
  111. ;
  112. ;    Waits for key from keyboard. Returns char in lower byte,
  113. ;    Scan-Code in upper byte.
  114. ;
  115. Globalfunc t_wait_key,<tout: dword>
  116. ;
  117.     mov    cx,word ptr (tout+2)
  118.     mov    dx,word ptr (tout)
  119.     mov    ax,4012h
  120.     int    16h
  121.     ret
  122. ;    
  123. t_wait_key    endp
  124. ;
  125. ;
  126. ;    int t_keyhit (void)
  127. ;
  128. ;    Checks if char is available. Returns -1 if not, else the
  129. ;    character value. The character remains in the buffer.
  130. ;
  131. Globalfunc t_keyhit
  132. ;
  133.     mov    ax,4212h
  134.     int    16h
  135.     jnz    t_kh_ok
  136.     mov    ax,-1
  137. t_kh_ok:
  138.     ret
  139. ;
  140. t_keyhit    endp
  141. ;
  142. ;-------------------------------------------------------------------------
  143. ;
  144. Localfunc tsk_getpsp
  145. ;
  146.     mov    ah,51h
  147.     int    21h
  148.     mov    ax,bx
  149.     ret
  150. ;
  151. tsk_getpsp    endp
  152. ;
  153.     .tsk_ecode
  154.         end
  155.  
  156.