home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / MISC.ASM < prev    next >
Assembly Source File  |  1995-04-17  |  5KB  |  131 lines

  1.         page    ,132
  2.         title   Assorted Assembler Routines
  3.         subttl  Copyright (C) 1988 by IBM (Written 11/87 by Jim Christensen)
  4.         name    MISC
  5.  
  6.         .386
  7.  
  8.         extrn   KBD16FLUSHBUFFER:FAR      ;routine flushes key stroke buffer
  9.         extrn   KBD16CHARIN:FAR
  10.  
  11. _TEXT   SEGMENT  DWORD USE32 PUBLIC 'CODE'
  12. _TEXT      ENDS
  13. _DATA   SEGMENT  DWORD USE32 PUBLIC 'DATA'
  14.         align 4
  15. _DATA      ENDS
  16.         ASSUME   CS: FLAT, DS: FLAT, SS: FLAT, ES: FLAT
  17. PUBLIC  utoa
  18. _TEXT   SEGMENT  DWORD USE32 PUBLIC 'CODE'
  19. Int3    PROC    NEAR
  20.         int     3
  21.         ret 0
  22. Int3    endp
  23.  
  24. if 0
  25. ;------------------------------------------------------------------------------;
  26. ; name          akeycod - addresses our stubbed in key code for user's screen
  27. ;                         group.
  28. ;
  29. ; synopsis      p = akeycod( &codlen );
  30. ;
  31. ;               uchar *p;               /* ->address of code to stub in      */
  32. ;               uchar codlen;           /* length of code to stub in         */
  33. ;
  34. ; description   This routine sets up instructions that will get a key stroke
  35. ;               in the user's screen group putting that key stroke in his data
  36. ;               area.  We will stub this code in at his current ExecCSIP.
  37. ;------------------------------------------------------------------------------;
  38.  
  39. Func    akeycod addrclen, 4
  40.         push    bp                      ;save bp register
  41.         mov     bp, sp                  ;bp address stack
  42.         sub     sp, 4                   ;allocate work area
  43.         jmp     skpstb                  ;do not execute the stub code!
  44.  
  45. stub:   push    0                       ;for keyboard handle 0
  46.         call    KBD16FLUSHBUFFER        ;flush key stroke buffer (handle 0)
  47.         push    ds                      ;push ds:0 == where key is to be stored
  48.         push    0                       ;  in user's data area
  49.         push    0                       ;0=>wait until a char is available
  50.         push    0                       ;for keyboard handle 0
  51.         call    KBD16CHARIN             ;get a keystroke (handle 0)
  52.         int     3                       ;gets us back to SD86 from app scr grp
  53. stublen EQU     $-stub                  ;length of stub code
  54.  
  55. skpstb: push    di                      ;protect di register
  56.         les     di, [bp+addrclen]       ;es:di->code length variable (uchar)
  57.         mov     byte ptr es:[di], stublen ;store length of code in codlen
  58.         pop     di                      ;restore di register
  59.  
  60.         lea     ax, stub                ;offset of code stub
  61.         mov     dx, cs                  ;segment of code stub (p == dx:ax)
  62.         add     sp, 4                   ;get rid of work area
  63.         pop     bp                      ;restore bp register
  64. eFunc   akeycod ret                     ;return to caller
  65. endif
  66.  
  67. ;------------------------------------------------------------------------------;
  68. ; name          utoa -- Unsigned to ASCII
  69. ;
  70. ; synopsis      n = utoa( num, buf );
  71. ;
  72. ;               uint n;                 /* # of bytes in ASCII result */
  73. ;               uint num;               /* unsigned number to be formatted */
  74. ;               uchar *buf;             /* buffer for ASCII string */
  75. ;
  76. ; description   This routine converts a binary, unsigned number into an ASCII
  77. ;               string.  The length of the ASCII string is returned.
  78. ;------------------------------------------------------------------------------;
  79.  
  80. num    = 8
  81. buf    = 12
  82.  
  83. utoa    PROC    NEAR
  84.         push    EBP
  85.         mov     EBP,ESP
  86.         push    EDI
  87.         push    EBX
  88.         push    ECX
  89.         push    EDX
  90.  
  91.         sub     ESP, 12                  ;allocate work area
  92.         mov     EDI,ESP
  93.         push    ss
  94.         pop     es                       ;es:edi -> work area
  95.         mov     ECX, 10
  96.         mov     EAX, [EBP+num]
  97. ut10:
  98.         xor     EDX, EDX
  99.         div     ECX
  100.         xchg    EAX, EDX
  101.         add     al, '0'
  102.         stosb
  103.         xchg    EAX, EDX
  104.         or      EAX, EAX
  105.         jnz     ut10
  106.  
  107.         mov     EBX, EDI
  108.         mov     ECX, EDI
  109.         sub     ECX, ESP                 ;ECX = # of chars in string
  110.         push    ECX
  111. ;       les     EDI, [EBP+buf]           ;es:EDI -> buf
  112.         mov     EDI, [EBP+buf]           ;es:EDI -> buf
  113. ut20:
  114.         dec     EBX
  115.         mov     al, ss:[EBX]
  116.         stosb
  117.         loop    ut20
  118.  
  119.         pop     EAX
  120.         add     ESP, 12
  121.         pop     EDX
  122.         pop     ECX
  123.         pop     EBX
  124.         pop     EDI
  125.         pop     EBP
  126.         ret
  127. utoa    endp
  128.  
  129. _TEXT   ends
  130.         end
  131.