home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c329 / 2.img / EXAMPLES / DISPTTYC.S < prev    next >
Encoding:
Text File  |  1989-12-15  |  4.2 KB  |  122 lines

  1.  
  2.         NAME DISPTTYC.S
  3.         .387
  4.         assume  cs:codeseg
  5.         assume  ds:dataseg
  6. codeseg segment dword er use32 public 'code'
  7. ; Purpose: Demonstrate interface between NDP C and
  8. ; assembly language calls to system services (DOS and ROM BIOS)
  9. ; Assembly language equivalent of using int386() function
  10. ; Copyright (C) MicroWay, Inc., 1989
  11.  
  12. dataseg segment dword rw use32 public 'data'
  13.         current_attr    db ?
  14.         active_page     db ?
  15.         row             db ?
  16.         col             db ?
  17.         maxcol          db ?
  18. dataseg ends
  19.  
  20. VIDEO_IO equ 10h
  21.  
  22. ; ************************************************************
  23. ; _display_tty
  24. ; This function displays a string of characters on the screen
  25. ; with a given attribute, and advances the cursor. Since there
  26. ; is no single ROM BIOS video service that does both, it
  27. ; combines the functionality of two of them:
  28. ;       Service 9, Write Character and Attribute
  29. ;       Service 2, Set Cursor Position
  30. ; The three parameters are:
  31. ;       The attribute(s) to be added
  32. ;       The attribute(s) to be deleted
  33. ;       Pointer to a null-terminated string of characters
  34. ; The coding of the attribute byte:
  35. ;            Bit
  36. ;       7 6 5 4 3 2 1 0
  37. ;       1 . . . . . . .    Blinking of foreground character
  38. ;       . 1 . . . . . .    Red component of background color
  39. ;       . . 1 . . . . .    Green component of background color
  40. ;       . . . 1 . . . .    Blue component of background color
  41. ;       . . . . 1 . . .    Intensity of foreground color
  42. ;       . . . . . 1 . .    Red component of foreground color
  43. ;       . . . . . . 1 .    Green component of foreground color
  44. ;       . . . . . . . 1    Blue component of foreground color
  45. ;
  46. ; The current attribute byte is ANDed with the attribute(s)
  47. ; to be removed and OR'd with the new attribute(s) to be added.
  48.  
  49.  
  50.         align   4
  51. _display_tty  proc      near
  52. public _display_tty
  53. PARM1 = 4
  54. IRP reg,<ebp,ebx,ecx,edx,esi>
  55.         push    reg
  56.         PARM1 = PARM1 + 4
  57. ENDM
  58.         mov     ebp,esp
  59.  
  60. PARM2 equ PARM1+4
  61. PARM3 equ PARM2+4
  62.  
  63. ADD_ATTR equ [esp+PARM1]   ; integer - new attribute(s) to be added 
  64. DEL_ATTR equ [esp+PARM2]   ; integer - attribute(s) to be removed 
  65. PSTRING  equ [esp+PARM3]   ; pointer to null-terminated string
  66.  
  67.         mov     ah,15           ; get current video mode
  68.         int     VIDEO_IO
  69.         mov     active_page, bh
  70.         mov     maxcol,ah
  71.  
  72.         mov     ah,8            ; get current attribute 
  73.         int     VIDEO_IO
  74.         mov     current_attr,ah
  75.  
  76.         mov     ah,3            ; read cursor position 
  77.         mov     bh,active_page;
  78.         int     VIDEO_IO
  79.         mov     row,dh
  80.         mov     col,dl
  81.  
  82.                                 ; put new attribute value into bl
  83.         mov     eax,ADD_ATTR    ; bit pattern to be added -> eax
  84.         mov     edx,DEL_ATTR    ; bit pattern to be deleted -> edx
  85.         mov     bl,current_attr
  86.         and     bl,dl           ; remove unwanted attribute(s)
  87.         or      bl,al           ; add new attribute(s)
  88.  
  89.         mov     esi,PSTRING     ; esi points to string
  90.         mov     ecx,1           ; only one char, attr at a time 
  91. next_char:
  92.         lodsb                   ; get the next character
  93.         or      al,al           ; if 0, we are done
  94.         jz      done
  95.         mov     ah,9            ; output char, attr
  96.         int     VIDEO_IO
  97.         mov     dl,col          ; current column -> dl
  98.         inc     dl              ; point at next column
  99.         mov     col,dl          ; save the new value
  100.         cmp     dl,maxcol       ; do we need to wrap around?
  101.         jb      no_wrap         ; if not, don't reinit col
  102.         mov     col,0           ; else reinit col
  103.         inc     row             ; go to next row
  104.         cmp     row,25          ; are we at last row?
  105.         jb      no_wrap         ; if not, don't reinit row
  106.         mov     row,0           ; else, reinit row
  107. no_wrap:
  108.         mov     ah,2            ; advance cursor 
  109.         mov     dh,row
  110.         mov     dl,col
  111.         int     VIDEO_IO
  112.         jmp     next_char
  113. done:
  114. IRP reg,<esi,edx,ecx,ebx,ebp>
  115.         pop     reg
  116. ENDM
  117.         ret     
  118. _display_tty endp
  119. codeseg ends
  120.         end
  121.  
  122.