home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / PUTC.ASM < prev    next >
Assembly Source File  |  1990-06-20  |  3KB  |  150 lines

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4. ;
  5. PutcAdrs    dd    sl_putcstdout
  6. PutcStkIndx    dw    0
  7. PutcStk        dd    16 dup (sl_putcstdout)
  8. PSIsize        =    $-PutcStk
  9. ;
  10. ;
  11. ; Putc- Sends the character in AL to the current output routine.
  12. ;    By default, this is "putstdout".  PutcAdrs contains the address of the
  13. ;    current output routine.
  14. ;
  15.         public    sl_putc
  16. sl_putc        proc    far
  17.         jmp    dword ptr cs:PutcAdrs
  18. sl_putc        endp
  19. ;
  20. ;
  21. ;
  22. ;
  23. ; PutCR-    Prints a new line to the standard output device.
  24. ;
  25.         public    sl_putcr
  26. sl_putcr    proc    far
  27.         push    ax
  28.         mov    al, 13        ;Carriage return
  29.         call    dword ptr cs:PutcAdrs
  30.         mov    al, 10        ;Line feed
  31.         call    dword ptr cs:PutcAdrs
  32.         pop    ax
  33.         ret
  34. sl_putcr    endp
  35. ;
  36. ;
  37. ;
  38. ; PutStdOut- Prints the character in AL to the standard output device by
  39. ;         calling DOS to print the character.
  40. ;
  41.         public    sl_putcstdout
  42. sl_putcstdout    proc    far
  43.         push    ax
  44.         push    dx
  45.         mov    dl, al
  46.         mov    ah, 2
  47.         int    21h
  48.         pop    dx
  49.         pop    ax
  50.         ret
  51. sl_putcstdout    endp
  52. ;
  53. ;
  54. ; PutcBIOS-    Prints the character in AL by calling the BIOS output routine.
  55. ;
  56.         public    sl_PutcBIOS
  57. sl_PutcBIOS    proc    far
  58.         push    ax
  59.         mov    ah, 14
  60.         int    10h
  61.         pop    ax
  62.         ret
  63. sl_PutcBIOS    endp
  64. ;
  65. ;
  66. ; GetOutAdrs-    Returns the address of the current output routine in ES:DI.
  67. ;
  68.         public    sl_GetOutAdrs
  69. sl_GetOutAdrs    proc    far
  70.         les    di, cs:PutcAdrs
  71.         ret
  72. sl_GetOutAdrs    endp
  73. ;
  74. ;
  75. ; SetOutAdrs-    Stores the address in ES:DI into PutcAdrs.  This must be the
  76. ;        address of a valid output routine which outputs the character
  77. ;        in the AL register.  This routine must preserve all registers.
  78. ;
  79.         public    sl_SetOutAdrs
  80. sl_SetOutAdrs    proc    far
  81.         mov    word ptr cs:PutcAdrs, di
  82.         mov    word ptr cs:PutcAdrs+2, es
  83.         ret
  84. sl_SetOutAdrs    endp
  85. ;
  86. ;
  87. ;
  88. ; PushOutAdrs-    Pushes the current output address onto the output stack
  89. ;        and then stores the address in es:di into the output address
  90. ;        pointer.  Returns carry clear if no problems.  Returns carry
  91. ;        set if there is an address stack overflow.  Does NOT modify
  92. ;        anything if the stack is full.
  93. ;
  94.         public    sl_PushOutAdrs
  95. sl_PushOutAdrs    proc    far
  96.         push    ax
  97.         push    di
  98.         cmp    cs:PutcStkIndx, PSIsize
  99.         jae    BadPush
  100.         mov    di, cs:PutcStkIndx
  101.         add    cs:PutcStkIndx, 4
  102.         mov    ax, word ptr cs:PutcAdrs
  103.         mov    word ptr cs:PutcStk[di], ax
  104.         mov    ax, word ptr cs:PutcAdrs+2
  105.         mov    word ptr cs:PutcStk+2[di], ax
  106.         pop    di
  107.         mov    word ptr cs:PutcAdrs, di
  108.         mov    word ptr cs:PutcAdrs+2, es
  109.         pop    ax
  110.         clc
  111.         ret
  112. ;
  113. BadPush:    pop    di
  114.         pop    ax
  115.         stc
  116.         ret
  117. sl_PushOutAdrs    endp
  118. ;
  119. ;
  120. ; PopOutAdrs-    Pops an output address off of the stack and stores it into
  121. ;        the PutcAdrs variable.
  122. ;
  123.         public    sl_PopOutAdrs
  124. sl_PopOutAdrs    proc    far
  125.         push    ax
  126.         mov    di, cs:PutcStkIndx
  127.         sub    di, 4
  128.         jns    GoodPop
  129. ;
  130. ; If this guy just went negative, set it to zero and push the address
  131. ; of the stdout routine onto the stack.
  132. ;
  133.         xor    di, di            
  134.         mov    word ptr cs:PutcStk, offset sl_PutcStdOut
  135.         mov    word ptr cs:PutcStk+2, seg sl_PutcStdOut
  136. ;
  137. GoodPop:    mov    cs:PutcStkIndx, di
  138.         mov    es, word ptr PutcAdrs+2
  139.         mov    ax, word ptr cs:PutcStk+2[di]
  140.         mov    word ptr cs:PutcAdrs+2, ax
  141.         mov    ax, word ptr cs:PutcStk[di]
  142.         xchg    word ptr cs:PutcAdrs, ax
  143.         mov    di, ax
  144.         pop    ax
  145.         ret
  146. sl_PopOutAdrs    endp
  147. ;
  148. stdlib        ends
  149.         end
  150.