home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l320 / 2.img / EXAMPLES / DISPTTY.F < prev    next >
Encoding:
Text File  |  1989-08-23  |  4.4 KB  |  140 lines

  1. C
  2. C DISPTTY.F
  3. C Purpose: demonstrate calling int386 subroutine
  4. C Copyright (C) MicroWay, Inc., 1989
  5. C
  6.  
  7. C BRIGHT - intense attribute for screen chars 
  8. C BLINKON - blinking attribute on for screen chars 
  9. C BLINKOFF - blinking attribute off for screen chars 
  10. C DEFAULT - leave attribute bits as they were 
  11.  
  12.       integer BRIGHT, BLINKON, BLINKOFF, DEFAULT
  13.       parameter (BRIGHT=8,BLINKON=128,BLINKOFF=127,DEFAULT=255)
  14.  
  15.       WRITE (*,100) 
  16.   100 FORMAT(' A horse that can count to 10 is a remarkable ',$)
  17.       CALL DISPLAY_TTY (BRIGHT,DEFAULT,'horse')
  18.       WRITE (*,101)
  19.   101 FORMAT(1X)
  20.       WRITE (*,102)
  21.   102 FORMAT (' not a remarkable ',$)
  22.       CALL DISPLAY_TTY (BRIGHT,DEFAULT,'mathematician.')
  23.       WRITE (*,103)
  24.   103 FORMAT (1X,' - Dr. Samuel Johnson')
  25. C end of main program
  26.       END
  27.  
  28. C ************************************************************
  29. C DISPLAY_TTY
  30. C This subroutine displays a string of characters on the screen
  31. C with a given attribute, and advances the cursor. Since there
  32. C is no single ROM BIOS video service that does both, it
  33. C combines the functionality of two of them:
  34. C       Service 9, Write Character and Attribute
  35. C       Service 2, Set Cursor Position
  36. C The three explicit parameters are:
  37. C       The attribute(s) to be added
  38. C       The attribute(s) to be deleted
  39. C       String of one or more characters
  40. C A fourth parameter is passed implicitly by the compiler
  41. C       Length of the string
  42. C The coding of the attribute byte:
  43. C            Bit
  44. C       7 6 5 4 3 2 1 0
  45. C       1 . . . . . . .    Blinking of foreground character
  46. C       . 1 . . . . . .    Red component of background color
  47. C       . . 1 . . . . .    Green component of background color
  48. C       . . . 1 . . . .    Blue component of background color
  49. C       . . . . 1 . . .    Intensity of foreground color
  50. C       . . . . . 1 . .    Red component of foreground color
  51. C       . . . . . . 1 .    Green component of foreground color
  52. C       . . . . . . . 1    Blue component of foreground color
  53. C
  54. C The current attribute byte ANDed with the attribute(s)
  55. C to be removed and OR'd with the attribute(s) to be added.
  56.  
  57.       SUBROUTINE DISPLAY_TTY(ADD_ATTR, DEL_ATTR, STRING) 
  58. C new attribute(s) to be added 
  59.       INTEGER   ADD_ATTR
  60. C attribute(s) to be removed 
  61.       INTEGER   DEL_ATTR
  62. C character(s) to be displayed 
  63.       CHARACTER*(*) STRING
  64.  
  65. C VIDEO_IO is the interrupt # for ROM BIOS video services
  66.       integer VIDEO_IO
  67.       parameter (VIDEO_IO=16)
  68.  
  69.       INTEGER*1 CURRENT_ATTR
  70.       INTEGER*1 ACTIVE_PAGE     
  71.       INTEGER*1 ROW, COL
  72.       INTEGER*1 MAXCOL
  73. C Length of string
  74.       INTEGER L
  75.  
  76.       INCLUDE "DOS.FH"
  77.  
  78.       INTEGER INTNUM
  79.  
  80.       INTNUM = VIDEO_IO
  81.  
  82. C get current video mode. ah = 15.
  83.       BINREGS(2) = 15
  84.       CALL INT386 (INTNUM, INREGS(1), OUTREGS(1))
  85. C Active page returned in bh, screen width returned in ah
  86.       ACTIVE_PAGE = BOUTREGS(6)
  87.       MAXCOL = BOUTREGS(2)
  88.  
  89. C get current attribute. ah = 8.
  90.       BINREGS(2) = 8
  91.       CALL INT386 (INTNUM, INREGS(1), OUTREGS(1))
  92. C Current attribute returned in ah
  93.       CURRENT_ATTR = BOUTREGS(2)
  94.  
  95. C read cursor position. ah = 3, bh = active page.
  96.       BINREGS(2) = 3
  97.       BINREGS(6) = ACTIVE_PAGE
  98.       CALL INT386 (INTNUM, INREGS(1), OUTREGS(1))
  99. C Current row returned in dh, column in dl
  100.       ROW = BOUTREGS(14)
  101.       COL = BOUTREGS(13)
  102.  
  103. C Set cx = 1, for only one char, attr at a time
  104.       WINREGS(5) = 1
  105. C Get new attribute value into bl
  106.       INREGS(2) = IAND(CURRENT_ATTR,DEL_ATTR)
  107.       INREGS(2) = IOR(INREGS(2),ADD_ATTR)
  108.  
  109.       I = 1
  110.       L = LEN (STRING)
  111. C Beginning of loop to output characters
  112. C If current char is null byte, or we are past end of string, quit
  113.  1000 IF ((STRING(I:I).EQ.CHAR(0)) .OR. (I.GT.L)) GOTO 2000
  114.  
  115. C  output char, attr. ah = 9, al = character
  116.           BINREGS(2) = 9
  117.           BINREGS(1) = ICHAR (STRING(I:I))
  118.           I = I + 1
  119.           CALL INT386 (INTNUM, INREGS(1), OUTREGS(1))
  120.  
  121.           COL = COL + 1
  122.           IF (COL .GE. MAXCOL) THEN
  123.                   COL = 0
  124.                   ROW = ROW + 1
  125.                   IF (ROW .EQ. 25) THEN
  126.                       ROW = 0
  127.                   ENDIF
  128.           ENDIF
  129.  
  130. C Advance cursor. ah = 2, dh = row, dl = column
  131.           BINREGS(2) = 2
  132.           BINREGS(14) = ROW
  133.           BINREGS(13) = COL
  134.           CALL INT386 (INTNUM, INREGS(1), OUTREGS(1))
  135.       GOTO 1000
  136. C end of loop to output characters
  137. 2000    RETURN
  138. C end of DISPLAY_TTY
  139.       END
  140.