home *** CD-ROM | disk | FTP | other *** search
/ Big Blue Disk 1 / bbd01.zip / BITSNPCS.TXT < prev    next >
Text File  |  1986-09-25  |  7KB  |  140 lines

  1.                                   ------------
  2.                                   BITS 'N PC'S
  3.                                   ------------
  4.  
  5. In this series, we will give various hints, tips, and tricks, to let you
  6. make the best use of your personal computer.  Whether you are a "hacker,"
  7. or a non-technical user, you should be able to find information here that will 
  8. help your PC perform at its best.  
  9.  
  10.                 ----------------------------------------------
  11.                 GETTING COLOR IN HIGH-RESOLUTION GRAPHICS MODE
  12.                 ----------------------------------------------
  13.  
  14. IBM's documentation of the PC's graphics modes states that the High Resolution
  15. mode supports only black-and-white graphics.  Since most people tend to
  16. believe what the manufacturer of a computer says about its capabilities, this
  17. is seldom challenged.  Certainly, for users of BASIC, there is no reason to
  18. believe otherwise; black and white are the colors that come up when you invoke
  19. this mode, and BASIC offers no command to change it.  Trying to use the COLOR
  20. statement while in high-resolution mode yields only an error message.
  21.  
  22. But in fact, black and white are ^Bnot^N the only colors available in this graphic
  23. mode.  Actually, you have a choice of sixteen colors.  The catch is that only
  24. one color can be visible at once, other than the background, which is always
  25. black.
  26.  
  27. In BASIC, you can change the color of Hi-Res graphics with the following line:
  28.  
  29.                               ^1OUT &H3D9, color^0
  30.  
  31. where ^1color^0 is the number (from 0 to 15) of the color you wish; these
  32. numbers correspond to the color numbers used in text mode.
  33.  
  34. This command tells your graphics adapter to switch the color for High-
  35. Resolution plotting to the given color, if you are in High-Resolution mode
  36. when you type this command.  If you are instead in text or Low-Resolution
  37. mode, this same command will set the border color to the given value; in
  38. Medium-Resolution mode, this command will set the background color.
  39.  
  40. Since only one color can be on the screen at once, all previously-plotted
  41. graphics will change to the most recently selected color.
  42.  
  43. As for the background, it's sort of like the original Model T Ford; it's
  44. available in any color you like, so long as what you like is black.  There's
  45. no way of changing this color; sorry.
  46.  
  47. What you are actually doing is sending a value to an output port.  Your PC
  48. has 65,536 such ports, and they are used for a number of purposes we will
  49. not get into right now.  BASIC uses the OUT command for port output, as shown
  50. above -- other languages and assemblers generally have equivalent features.
  51. Consult your reference manual to find out how to do it in whatever language
  52. you are using; all you have to do is send the number corresponding to the
  53. color you want to port number 3D9 (in Hexadecimal).
  54.  
  55. In Turbo Pascal, you can use the ^1Port^0 system array to do this, but it's
  56. unnecessary:  Borland International, the creators of Turbo Pascal, showed more
  57. sense than IBM, and provided a direct command to change the color in High-
  58. Resolution mode.  Just use the command
  59.  
  60.                              ^1HiResColor(color)^0
  61.  
  62. and it will be changed.  In other languages, check for such a command in
  63. your manual before you resort to direct port access.  Your code will be much 
  64. easier to understand and more portable to other systems if you refrain whenever 
  65. possible from direct PEEKing, POKEing, port access, et cetera.  
  66.  
  67.  
  68.                   --------------------------------------------
  69.                   PREVENTING CONFIRMATION LINES IN BATCH FILES
  70.                   --------------------------------------------
  71.  
  72. If you make regular use of .BATch files to get your PC to perform a series
  73. of DOS commands without human intervention, you probably know that the command
  74. ECHO OFF is used to prevent DOS from echoing all the command lines back to
  75. you.  This is commonly used so that you don't have to see all these ugly
  76. commands scrolling by, spoiling whatever screen format you may have set up,
  77. and confusing the user.
  78.  
  79. However, if your file includes a COPY command to copy files around on your
  80. disks, then even in ECHO OFF mode a confirmation line will still be output
  81. as each file is copied, and yet another line will show how many files have
  82. been copied.
  83.  
  84. But there's a way of suppressing these lines, too.  Simply append to each
  85. COPY command, or other command which generates unwanted confirmation lines,
  86. the sequence ^1>NUL^0.  This causes all output that would have gone to the
  87. console during execution of the command to go instead to the null device,
  88. which simply means it is "thrown away."
  89.  
  90. For example:
  91.  
  92.                         ^1COPY \dir1\*.bas \dir2 >nul^0
  93.  
  94. would copy all BASIC programs in the subdirectory ^1dir1^0 to the subdirectory
  95. ^1dir2^0, without echoing any confirmation.
  96.  
  97. This trick will work in immediate mode as well as in .BATch files.
  98.  
  99.  
  100.                         -------------------------------
  101.                         WAITING FOR A KEYPRESS IN BASIC
  102.                         -------------------------------
  103.  
  104. Here is a tip for you if you are writing a BASIC program which needs to wait 
  105. for a keypress, such as when you say "Hit Any Key To Continue," or you ask a 
  106. question and wait for a Y or N response.
  107.  
  108. There are several commands you might think of using for such a thing.  The 
  109. plain old INPUT command is not very good; it requires the user to press ENTER 
  110. before it returns control back to BASIC; it also allows the user to press all 
  111. sorts of cursor-movement keys which might mess up your screen format.
  112.  
  113. Many programmers use a loop with the INKEY$ function.  When INKEY$ has a value 
  114. other than CHR$(0), a key has been pressed.  Thus, this function can be used to 
  115. check for a keypress and return its value.
  116.  
  117. However, this is very inefficient.  Every iteration of such a loop causes a new 
  118. string value to be created, even if it is only a null character.  Due to the 
  119. way BASIC handles strings, the old values of a string that is repeatedly 
  120. reasigned stick around wasting memory, until BASIC does a garbage collect.  
  121. Such garbage collections slow down the execution of your program.
  122.  
  123. There's a better way, though.  Use the ^1INPUT$(n)^0 function.  The parameter 
  124. ^1n^0 indicates how many characters you wish to input, usually 1.  ^1INPUT$^0 
  125. returns the input character(s) as its result.  
  126.  
  127. Thus, the following BASIC line will wait for one keypress, and return its value 
  128. as the variable I$:
  129.  
  130.                                ^1I$ = INPUT$(1)^0
  131.  
  132.  
  133.                       ------------------------------------
  134.  
  135. That's all for now; next month we'll be back with more hints and tips for you 
  136. and your PC.  Please write to us (on paper, through feedback text files created 
  137. with the BlueLine editor, or through our Bulletin Board System) and tell us any 
  138. hints you have discovered, or any areas you'd like some tips on.  
  139.  
  140.